diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index d51cb75c..a6c728bc 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -2826,6 +2826,9 @@ Number indicating remaining entity health, or `null` if not applicable. Retrieves player hunger related information. For non-players, returns `null`. +### `query(e, 'air')` + +Number indicating remaining entity health, or `null` if not applicable. ### `query(e, 'holds', slot?)` @@ -3118,6 +3121,10 @@ Will set entity on fire for `ticks` ticks. Set to 0 to extinguish. Modifies directly player raw hunger components. Has no effect on non-players +### `modify(e, 'air', ticks)` + +Modifies entity air + ### `modify(e, 'add_exhaustion', value)` adds exhaustion value to the current player exhaustion level - that's the method you probably want to use @@ -3692,13 +3699,18 @@ Example usages: // not a problem in apps -### `logger(expr)` +### `logger(msg), logger(type, msg)` -Prints the message to system logs, and not to chat. +Prints the message to system logs, and not to chat. By default prints an info, unless you specify otherwise in the `type` parameter. -### read_file(resource, type) -### delete_file(resource, type) -### write_file(resource, type, data, ...) +Available output types: + +`'debug'`, `'warn'`, `'fatal'`, `'info'` and `'error'` + + +### `read_file(resource, type)` +### `delete_file(resource, type)` +### `write_file(resource, type, data, ...)` With the specified `resource` in the scripts folder, of a specific `type`, writes/appends `data` to it, reads its content, or deletes the resource. diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 8091997d..76bc349d 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -245,13 +245,18 @@ Example usages: // not a problem in apps -### `logger(expr)` +### `logger(msg), logger(type, msg)` -Prints the message to system logs, and not to chat. +Prints the message to system logs, and not to chat. By default prints an info, unless you specify otherwise in the `type` parameter. -### read_file(resource, type) -### delete_file(resource, type) -### write_file(resource, type, data, ...) +Available output types: + +`'debug'`, `'warn'`, `'fatal'`, `'info'` and `'error'` + + +### `read_file(resource, type)` +### `delete_file(resource, type)` +### `write_file(resource, type, data, ...)` With the specified `resource` in the scripts folder, of a specific `type`, writes/appends `data` to it, reads its content, or deletes the resource. diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index aee2f2fd..009294f6 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -361,6 +361,10 @@ Number indicating remaining entity health, or `null` if not applicable. Retrieves player hunger related information. For non-players, returns `null`. +### `query(e, 'air')` + +Number indicating remaining entity health, or `null` if not applicable. + ### `query(e, 'holds', slot?)` Returns triple of short name, stack count, and NBT of item held in `slot`, or `null` if nothing or not applicable. Available options for `slot` are: @@ -654,7 +658,11 @@ Will set entity on fire for `ticks` ticks. Set to 0 to extinguish. ### `modify(e, 'saturation', value)` ### `modify(e, 'exhaustion', value)` -Modifies player raw hunger components. Has no effect on non-players. +Modifies directly player raw hunger components. Has no effect on non-players + +### `modify(e, 'air', ticks)` + +Modifies entity air ### `modify(e, 'add_exhaustion', value)` diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index fb661ec9..0b69c55c 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -3381,7 +3381,7 @@ public class CarpetExpression return (c_, t_) -> Value.TRUE; }); - this.expr.addLazyFunction("logger", 1, (c, t, lv) -> + this.expr.addLazyFunction("logger", -1, (c, t, lv) -> { //CarpetSettings.LOG.error("Standard Structures:"); //CarpetSettings.LOG.error(Registry.STRUCTURE_FEATURE.getIds().stream().map(i -> "`'"+NBTSerializableValue.nameFromRegistryId(i)+"'`").sorted(). collect(Collectors.joining(", "))); @@ -3399,8 +3399,29 @@ public class CarpetExpression //CarpetSettings.LOG.error(FeatureGenerator.featureMap.keySet().stream().map(i -> "`'"+i+"'`").sorted().collect(Collectors.joining(", "))); //CarpetSettings.LOG.error(Registry.ENTITY_TYPE.getIds().stream().sorted().map(ValueConversions::simplify).collect(Collectors.joining("`, `"))); - Value res = lv.get(0).evalValue(c); - CarpetSettings.LOG.error(res.getString()); + + Value res; + + if(lv.size()==1){ + res = lv.get(0).evalValue(c); + CarpetSettings.LOG.info(res.getString()); + } + else if(lv.size()==2){ + String level = lv.get(0).evalValue(c).toString(); + res = lv.get(1).evalValue(c); + + switch(level){ + case "error":CarpetSettings.LOG.error(res.getString()); break; + case "warn":CarpetSettings.LOG.warn(res.getString()); break; + case "debug":CarpetSettings.LOG.debug(res.getString()); break; + case "fatal":CarpetSettings.LOG.fatal(res.getString()); break; + case "info":CarpetSettings.LOG.info(res.getString()); break; + default: throw new InternalExpressionException("Unknown error type: "+level); + } + } + + else throw new InternalExpressionException("logger only takes 1 or 2 arguments"); + return (_c, _t) -> res; // pass through for variables }); diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 4d4fe964..3fcdbe19 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -343,6 +343,7 @@ public class EntityValue extends Value put("sneaking", (e, a) -> e.isSneaking()?Value.TRUE:Value.FALSE); put("sprinting", (e, a) -> e.isSprinting()?Value.TRUE:Value.FALSE); put("swimming", (e, a) -> e.isSwimming()?Value.TRUE:Value.FALSE); + put("air", (e, a) -> return new NumericValue(e.getAir())); put("persistence", (e, a) -> { if (e instanceof MobEntity) return new NumericValue(((MobEntity) e).isPersistent()); return Value.NULL; @@ -1107,6 +1108,8 @@ public class EntityValue extends Value if(e instanceof PlayerEntity) ((PlayerEntity) e).getHungerManager().setSaturationLevelClient((float)NumericValue.asNumber(v).getLong()); }); + put("air", (e, v) -> e.setAir(NumericValue.asNumber(v).getLong())); + put("breaking_progress", (e, a) -> { if (e instanceof ServerPlayerEntity) {