entity actions

This commit is contained in:
gnembon committed 2020-10-29 11:26:59 -03:00
1 parent 11818e3d57
commit 15ac7a4621
10 files changed
+136 -12

No files matched your search

@@ -640,7 +640,7 @@ public class Auxiliary {
throw new InternalExpressionException("'schedule' should have at least 2 arguments, delay and call name");
long delay = NumericValue.asNumber(lv.get(0).evalValue(c)).getLong();
FunctionArgument functionArgument = FunctionArgument.findIn(c, expression.module, lv, 1, true);
FunctionArgument functionArgument = FunctionArgument.findIn(c, expression.module, lv, 1, true, false);
CarpetServer.scriptServer.events.scheduleCall(
(CarpetContext) c,
@@ -1,8 +1,10 @@
package carpet.script.api;
import carpet.script.CarpetContext;
import carpet.script.CarpetScriptHost;
import carpet.script.Expression;
import carpet.script.LazyValue;
import carpet.script.argument.FunctionArgument;
import carpet.script.argument.Vector3Argument;
import carpet.script.exception.InternalExpressionException;
import carpet.script.value.EntityValue;
@@ -266,6 +268,16 @@ public class Entities {
return (cc, tt) -> v;
});
expression.addLazyFunction("entity_load_handler", -1, (c, t, lv) ->
{
if (lv.size() < 3) throw new InternalExpressionException("'entity_load_handler' required the entity type, and a function to call");
String entityString = lv.get(0).evalValue(c).getString();
FunctionArgument funArg = FunctionArgument.findIn(c, expression.module, lv, 2, true, true);
((CarpetScriptHost)c.host).getScriptServer().events.addEventDirectly(entityString, c.host, funArg.function);
};
// or update
expression.addLazyFunction("entity_event", -1, (c, t, lv) ->
{
@@ -275,6 +287,7 @@ public class Entities {
if (!(v instanceof EntityValue))
throw new InternalExpressionException("First argument to entity_event should be an entity");
String what = lv.get(1).evalValue(c).getString();
Value functionValue = lv.get(2).evalValue(c);
if (functionValue instanceof NullValue)
functionValue = null;