From 9914dd992c0c4a095e4ac5de2387634e3b94d606 Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 25 Jan 2020 01:22:09 -0400 Subject: [PATCH] fixes to 'effect' and 'trace' --- .../java/carpet/script/CarpetExpression.java | 13 ++++++----- .../java/carpet/script/value/EntityValue.java | 22 ++++++++++++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index 29c3d8c4..7ec510d4 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -2070,11 +2070,12 @@ public class CarpetExpression *

query(e,'trace', reach?, options?...)

*

Returns the result of ray tracing from entity perspective, indicating what it is looking at. Default reach is 4.5 * blocks (5 for creative players), and by default it traces for blocks and entities, identical to player attack tracing action. - * This can be customized with options, use 'blocks' to trace for blocks only, 'liquids' to include liquid blocks - * as possible results, and 'entities' to trace entities as well.

+ * This can be customized with options, use 'blocks' to trace for blocks, 'liquids' to include liquid blocks + * as possible results, and 'entities' to trace entities. Any combination of the above is possible. When tracing + * entities and blocks, blocks will take over the priority even if transparent or non-colliding (aka fighting chickens + * in tall grass).

*

Regardless of the options selected, the result could be null if nothing is in reach, entity, if look - * targets an antity, and block value if block is in reach. Tracing always hits blocks. Even if an entity tracing is requested - * and there is a block in the way - the block will be returned.

+ * targets an entity, and block value if block is in reach.

*

query(e,'nbt',path?)

*

Returns full NBT of the entity. If path is specified, it fetches only that portion of the NBT, * that corresponds to the path. For specification of path attribute, consult @@ -2131,9 +2132,9 @@ public class CarpetExpression *

modify(e, 'no_clip', boolean)

*

Sets if the entity obeys any collisions, including collisions with the terrain and basic physics. * Not affecting players, since they are controlled client side

- *

modify(e, 'effect', name, duration, amplifier?, show_particles?, show_icon?)

+ *

modify(e, 'effect', name, duration?, amplifier?, show_particles?, show_icon?)

*

Applies status effect to the living entity. Takes several optional parameters, which default to 0, - * true and true.

+ * true and true. If no duration is specified, or it is null or 0, the effect is removed.

*

modify(e, 'home', null), modify(e, 'home', block, distance?), modify(e, 'home', x, y, z, distance?)

*

Sets AI to stay around the home position, within distance blocks from it. distance * defaults to 16 blocks. null removes it. May not work fully with mobs that have this AI built in, like diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index f81e6f3d..cd326155 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -385,6 +385,7 @@ public class EntityValue extends Value float reach = 4.5f; boolean entities = true; boolean liquids = false; + boolean blocks = true; if (a!=null) { @@ -401,12 +402,14 @@ public class EntityValue extends Value if (args.size() > 1) { entities = false; + blocks = false; for (int i = 1; i < args.size(); i++) { String what = args.get(i).getString(); if (what.equalsIgnoreCase("entities")) entities = true; - else if (what.equalsIgnoreCase("blocks")) {} + else if (what.equalsIgnoreCase("blocks")) + blocks = true; else if (what.equalsIgnoreCase("liquids")) liquids = true; else throw new InternalExpressionException("Incorrect tracing: "+what); @@ -420,11 +423,14 @@ public class EntityValue extends Value } HitResult hitres; - if (entities) + if (entities && !blocks) + hitres = Tracer.rayTraceEntities(e, 1, reach, reach*reach); + else if (entities) hitres = Tracer.rayTrace(e, 1, reach, liquids); else hitres = Tracer.rayTraceBlocks(e, 1, reach, liquids); + if (hitres == null) return Value.NULL; switch (hitres.getType()) { case MISS: return Value.NULL; @@ -796,13 +802,23 @@ public class EntityValue extends Value else if (v instanceof ListValue) { List lv = ((ListValue) v).getItems(); - if (lv.size() >= 2 && lv.size() <= 5) + if (lv.size() >= 1 && lv.size() <= 5) { String effectName = lv.get(0).getString(); StatusEffect effect = Registry.STATUS_EFFECT.get(new Identifier(effectName)); if (effect == null) throw new InternalExpressionException("Wrong effect name: "+effectName); + if (lv.size() == 1) + { + le.removeStatusEffect(effect); + return; + } int duration = (int)NumericValue.asNumber(lv.get(1)).getLong(); + if (duration <= 0) + { + le.removeStatusEffect(effect); + return; + } int amplifier = 0; if (lv.size() > 2) amplifier = (int)NumericValue.asNumber(lv.get(2)).getLong();