player modules
This commit is contained in:
1 parent
5ea299b7ef
commit
99229280c2
3 files changed
+21
-6
No files matched your search
@@ -206,7 +206,7 @@ public class ScriptCommand
|
|||||||
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(),bb)).
|
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(),bb)).
|
||||||
executes((cc) ->
|
executes((cc) ->
|
||||||
{
|
{
|
||||||
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "package"));
|
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "package"), false);
|
||||||
return success?1:0;
|
return success?1:0;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
import net.minecraft.client.network.packet.ChunkDataS2CPacket;
|
import net.minecraft.client.network.packet.ChunkDataS2CPacket;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -34,6 +35,7 @@ public class CarpetScriptServer
|
|||||||
//make static for now, but will change that later:
|
//make static for now, but will change that later:
|
||||||
public ScriptHost globalHost;
|
public ScriptHost globalHost;
|
||||||
public Map<String, ScriptHost> modules;
|
public Map<String, ScriptHost> modules;
|
||||||
|
public Map<Pair<String, PlayerEntity>, ScriptHost> playerModules;
|
||||||
long tickStart;
|
long tickStart;
|
||||||
public boolean stopAll;
|
public boolean stopAll;
|
||||||
Set<String> holyMoly;
|
Set<String> holyMoly;
|
||||||
@@ -45,7 +47,7 @@ public class CarpetScriptServer
|
|||||||
|
|
||||||
public CarpetScriptServer()
|
public CarpetScriptServer()
|
||||||
{
|
{
|
||||||
globalHost = createMinecraftScriptHost(null);
|
globalHost = createMinecraftScriptHost(null, null);
|
||||||
events = new CarpetEventServer();
|
events = new CarpetEventServer();
|
||||||
modules = new HashMap<>();
|
modules = new HashMap<>();
|
||||||
tickStart = 0L;
|
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);
|
ScriptHost host = new ScriptHost(name);
|
||||||
host.globalVariables.put("_x", (c, t) -> Value.ZERO);
|
host.globalVariables.put("_x", (c, t) -> Value.ZERO);
|
||||||
@@ -122,11 +124,13 @@ public class CarpetScriptServer
|
|||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addScriptHost(ServerCommandSource source, String name)
|
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer)
|
||||||
{
|
{
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
name = name.toLowerCase(Locale.ROOT);
|
||||||
ScriptHost newHost = createMinecraftScriptHost(name);
|
|
||||||
ModuleInterface module = getModule(name);
|
ModuleInterface module = getModule(name);
|
||||||
|
ScriptHost newHost = createMinecraftScriptHost(name, module);
|
||||||
|
// move to host constructor.....
|
||||||
|
.....
|
||||||
if (module == null)
|
if (module == null)
|
||||||
{
|
{
|
||||||
Messenger.m(source, "r Unable to locate the package, but created empty host "+name+" instead");
|
Messenger.m(source, "r Unable to locate the package, but created empty host "+name+" instead");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package carpet.script;
|
package carpet.script;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
import carpet.CarpetServer;
|
||||||
|
import carpet.script.bundled.ModuleInterface;
|
||||||
import carpet.settings.CarpetSettings;
|
import carpet.settings.CarpetSettings;
|
||||||
import carpet.script.exception.ExpressionException;
|
import carpet.script.exception.ExpressionException;
|
||||||
import carpet.script.exception.InvalidCallbackException;
|
import carpet.script.exception.InvalidCallbackException;
|
||||||
@@ -30,9 +31,14 @@ public class ScriptHost
|
|||||||
private String name;
|
private String name;
|
||||||
public String getName() {return 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.name = name;
|
||||||
|
this.myCode = code;
|
||||||
globalVariables.put("euler", (c, t) -> Expression.euler);
|
globalVariables.put("euler", (c, t) -> Expression.euler);
|
||||||
globalVariables.put("pi", (c, t) -> Expression.PI);
|
globalVariables.put("pi", (c, t) -> Expression.PI);
|
||||||
globalVariables.put("null", (c, t) -> Value.NULL);
|
globalVariables.put("null", (c, t) -> Value.NULL);
|
||||||
@@ -44,6 +50,11 @@ public class ScriptHost
|
|||||||
globalVariables.put("_i", (c, t) -> Value.ZERO);
|
globalVariables.put("_i", (c, t) -> Value.ZERO);
|
||||||
globalVariables.put("_a", (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)
|
public Expression getExpressionForFunction(String name)
|
||||||
{
|
{
|
||||||
return globalFunctions.get(name).getExpression();
|
return globalFunctions.get(name).getExpression();
|
||||||
|
|||||||
Reference in new issue
Block a user