player modules

This commit is contained in:
gnembon committed 2019-07-15 08:50:27 -03:00
1 parent 5ea299b7ef
commit 99229280c2
3 files changed
+21 -6

No files matched your search

@@ -15,6 +15,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode;
import net.minecraft.client.network.packet.ChunkDataS2CPacket;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
@@ -34,6 +35,7 @@ public class CarpetScriptServer
//make static for now, but will change that later:
public ScriptHost globalHost;
public Map<String, ScriptHost> modules;
public Map<Pair<String, PlayerEntity>, ScriptHost> playerModules;
long tickStart;
public boolean stopAll;
Set<String> holyMoly;
@@ -45,7 +47,7 @@ public class CarpetScriptServer
public CarpetScriptServer()
{
globalHost = createMinecraftScriptHost(null);
globalHost = createMinecraftScriptHost(null, null);
events = new CarpetEventServer();
modules = new HashMap<>();
tickStart = 0L;
@@ -113,7 +115,7 @@ public class CarpetScriptServer
}
private static ScriptHost createMinecraftScriptHost(String name)
private static ScriptHost createMinecraftScriptHost(String name, ModuleInterface code)
{
ScriptHost host = new ScriptHost(name);
host.globalVariables.put("_x", (c, t) -> Value.ZERO);
@@ -122,11 +124,13 @@ public class CarpetScriptServer
return host;
}
public boolean addScriptHost(ServerCommandSource source, String name)
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer)
{
name = name.toLowerCase(Locale.ROOT);
ScriptHost newHost = createMinecraftScriptHost(name);
ModuleInterface module = getModule(name);
ScriptHost newHost = createMinecraftScriptHost(name, module);
// move to host constructor.....
.....
if (module == null)
{
Messenger.m(source, "r Unable to locate the package, but created empty host "+name+" instead");
+12 -1
View File
@@ -1,6 +1,7 @@
package carpet.script;
import carpet.CarpetServer;
import carpet.script.bundled.ModuleInterface;
import carpet.settings.CarpetSettings;
import carpet.script.exception.ExpressionException;
import carpet.script.exception.InvalidCallbackException;
@@ -30,9 +31,14 @@ public class ScriptHost
private String name;
public String getName() {return name;}
ScriptHost(String name)
private ModuleInterface myCode;
ScriptHost(String name) { this(name, null);}
ScriptHost(String name, ModuleInterface code)
{
this.name = name;
this.myCode = code;
globalVariables.put("euler", (c, t) -> Expression.euler);
globalVariables.put("pi", (c, t) -> Expression.PI);
globalVariables.put("null", (c, t) -> Value.NULL);
@@ -44,6 +50,11 @@ public class ScriptHost
globalVariables.put("_i", (c, t) -> Value.ZERO);
globalVariables.put("_a", (c, t) -> Value.ZERO);
}
public boolean replicable() { return myCode != null; }
public ScriptHost replicate() { return new ScriptHost(name, myCode); }
public Expression getExpressionForFunction(String name)
{
return globalFunctions.get(name).getExpression();