fixes
This commit is contained in:
1 parent
e617008930
commit
b90db6954e
4 files changed
+21
-21
No files matched your search
@@ -26,7 +26,7 @@ but obviously using UUIDs takes more memory and compute.
|
||||
|
||||
### `entity_list(descriptor)`
|
||||
|
||||
Returns global lists of entities in the current dimension matches specified descriptor.
|
||||
Returns global lists of entities in the current dimension matching specified descriptor.
|
||||
Calls to `entity_list` always fetch entities from the current world that the script executes.
|
||||
|
||||
### `entity_types(descriptor)`
|
||||
@@ -42,11 +42,12 @@ entities in the `valid` category. matches all entity types. `!valid` matches all
|
||||
* `living` - all entities that resemble a creature of some sort
|
||||
* `projectile` - all entities or types that are not living that can be throw or projected, `!projectile` matches all types that
|
||||
are not living, but cannot the thrown or projected.
|
||||
* `minecarts` matches all minecart types. `!minecart` matches all types that are not live, but also not minecarts.
|
||||
* `minecarts` matches all minecart types. `!minecarts` matches all types that are not live, but also not minecarts. Using plural
|
||||
since `minecart` is a proper entity type on its own.
|
||||
* `undead`, `arthropod`, `aquatic`, `regular`, `illager` - all entities / types that belong to any of these groups. All
|
||||
living entities belong to one and only one of these. Corresponding negative (e.g. `!undead`) corresponds to all mobs that are
|
||||
living but don't belong to that group. Entity groups are used in interaction / battle mechanics like smite for undead, or impaling
|
||||
for aquatic. Also certain mobs interact with groups, like bell with illagers. ALl mobs that don't have any of these traits belong
|
||||
for aquatic. Also certain mechanics interact with groups, like ringing a bell with illagers. All other mobs that don't have any of these traits belong
|
||||
to the `regular` group.
|
||||
* `monster`, `creature`, `ambient`, `water_creature`, `water_ambient`, `misc` - another categorization of
|
||||
living entities based on their spawn group. Negative descriptor resolves to all living types that don't belong to that
|
||||
@@ -744,10 +745,10 @@ when you attach an inapplicable event to it.
|
||||
|
||||
Attaches a callback to when any entity matching the following type / types is loaded in the game, allowing to grab a handle
|
||||
to an entity right when it is loaded to the world without querying them every tick. Callback expects one parameter - the entity.
|
||||
If callback is `null` current entity handler, if present is removed. Consecutive calls to `entity_load_handler` will add / subtract
|
||||
of the currenty targetted entity types pool.
|
||||
If callback is `null`, then the current entity handler, if present, is removed. Consecutive calls to `entity_load_handler` will add / subtract
|
||||
of the currently targeted entity types pool.
|
||||
|
||||
Like other global events, calls to `entity_load_handler` can only be attached in apps with global scope. Player scope make so
|
||||
Like other global events, calls to `entity_load_handler` can only be attached in apps with global scope. Player scope makes so
|
||||
that it is not clear which player to use run the load call.
|
||||
|
||||
```
|
||||
@@ -759,8 +760,6 @@ entity_load_handler('zombie', _(e) -> schedule(0, _(outer(e)) -> modify(e, 'remo
|
||||
entity_load_handler('zombie', _(e) -> entity_event(e, 'on_tick', _(e) -> modify(e, 'motion', 1.2*e~'motion')))
|
||||
```
|
||||
|
||||
|
||||
|
||||
### `entity_event(e, event, function)`, `entity_event(e, event, call_name, ... args?)`
|
||||
|
||||
Attaches specific function from the current package to be called upon the `event`, with extra `args` carried to the
|
||||
|
||||
@@ -56,6 +56,7 @@ public class CarpetEventServer
|
||||
{
|
||||
public final List<ScheduledCall> scheduledCalls = new LinkedList<>();
|
||||
public final MinecraftServer server;
|
||||
private static final List<Value> NOARGS = Collections.emptyList();
|
||||
|
||||
public static class Callback
|
||||
{
|
||||
@@ -63,23 +64,22 @@ public class CarpetEventServer
|
||||
public final FunctionValue function;
|
||||
public final List<Value> parametrizedArgs;
|
||||
|
||||
|
||||
public Callback(String host, FunctionValue function, List<Value> parametrizedArgs)
|
||||
{
|
||||
this.host = host;
|
||||
this.function = function;
|
||||
this.parametrizedArgs = parametrizedArgs;
|
||||
this.parametrizedArgs = parametrizedArgs==null?NOARGS:parametrizedArgs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in entity events
|
||||
* Used also in entity events
|
||||
* @param asSource - entity command source
|
||||
* @param runtimeArgs = options
|
||||
*/
|
||||
public boolean execute(ServerCommandSource asSource, List<Value> runtimeArgs)
|
||||
{
|
||||
//!CarpetServer.scriptServer.runas(source, call.host, call.function, argv)
|
||||
//CarpetServer.scriptServer.runas(source, call.host, call.function, argv)
|
||||
if (this.parametrizedArgs == null || this.parametrizedArgs.isEmpty())
|
||||
if (this.parametrizedArgs.isEmpty())
|
||||
return CarpetServer.scriptServer.runas(
|
||||
asSource.withLevel(CarpetSettings.runPermissionLevel),
|
||||
host, function, runtimeArgs);
|
||||
@@ -181,7 +181,7 @@ public class CarpetEventServer
|
||||
}
|
||||
public boolean addEventCallInternal(ScriptHost host, FunctionValue function, List<Value> args)
|
||||
{
|
||||
if (function == null || (function.getArguments().size() - (args==null?0:args.size())) != reqArgs)
|
||||
if (function == null || (function.getArguments().size() - args.size()) != reqArgs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -668,7 +668,7 @@ public class CarpetEventServer
|
||||
public void onEntityAction(Entity entity)
|
||||
{
|
||||
handler.call(
|
||||
() -> Collections.singletonList((new EntityValue(entity))),
|
||||
() -> Collections.singletonList(new EntityValue(entity)),
|
||||
() -> CarpetServer.minecraft_server.getCommandSource().withWorld((ServerWorld) entity.world).withLevel(CarpetSettings.runPermissionLevel)
|
||||
);
|
||||
}
|
||||
@@ -773,7 +773,7 @@ public class CarpetEventServer
|
||||
Event ev = Event.byName.get(event);
|
||||
if (!canAddEvent(ev, host))
|
||||
throw new InternalExpressionException("Global event "+event+" can only be added to apps with global scope");
|
||||
boolean success = ev.handler.addEventCallInternal(host, function, args);
|
||||
boolean success = ev.handler.addEventCallInternal(host, function, args==null?NOARGS:args);
|
||||
if (!success) throw new InternalExpressionException("Global event "+event+" requires "+ev.handler.reqArgs+", not "+(function.getNumParams()-((args==null)?0:args.size())));
|
||||
}
|
||||
|
||||
|
||||
@@ -264,13 +264,13 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
||||
|
||||
public void assertArgsOk(List<?> list, Consumer<Boolean> feedback)
|
||||
{
|
||||
int size = list==null?0:list.size();
|
||||
if (varArgs == null && args.size() != size) // wrong number of args for fixed args
|
||||
int size = list.size();
|
||||
if (varArgs == null && args.size() != size) // wrong number of args for fixed args
|
||||
{
|
||||
feedback.accept(true);
|
||||
|
||||
}
|
||||
else if (varArgs != null && args.size() > size) // too few args for varargs
|
||||
else if (varArgs != null && args.size() > size) // too few args for varargs
|
||||
{
|
||||
feedback.accept(false);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ public class NumericValue extends Value
|
||||
{
|
||||
private final Double value;
|
||||
private Long longValue;
|
||||
final static double epsilon = 32*((7*0.1)*10-7);
|
||||
private final static double epsilon = 32*((7*0.1)*10-7);
|
||||
private final static MathContext displayRounding = new MathContext(12, RoundingMode.HALF_EVEN);
|
||||
|
||||
public static NumericValue asNumber(Value v1, String id)
|
||||
{
|
||||
@@ -49,7 +50,7 @@ public class NumericValue extends Value
|
||||
if (value.isInfinite()) return "INFINITY";
|
||||
if (value.isNaN()) return "NaN";
|
||||
// dobules have 16 point precision, 12 is plenty to display
|
||||
return BigDecimal.valueOf(value).round(new MathContext(12, RoundingMode.HALF_EVEN)).stripTrailingZeros().toPlainString();
|
||||
return BigDecimal.valueOf(value).round(displayRounding).stripTrailingZeros().toPlainString();
|
||||
}
|
||||
catch (NumberFormatException exc)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user