diff --git a/src/main/java/carpet/script/argument/Vector3Argument.java b/src/main/java/carpet/script/argument/Vector3Argument.java index bb35eac8..bb61b98f 100644 --- a/src/main/java/carpet/script/argument/Vector3Argument.java +++ b/src/main/java/carpet/script/argument/Vector3Argument.java @@ -91,4 +91,51 @@ public class Vector3Argument extends Argument throw new InternalExpressionException("Position argument should be defined either by three coordinates (a triple or by three arguments), or a positioned block value"); } } + + public static Vector3Argument findIn(List params, int offset, boolean optionalDirection) + { + try + { + Value v1 = params.get(0 + offset); + if (v1 instanceof BlockValue) + { + return (new Vector3Argument(new Vec3d(((BlockValue) v1).getPos()).add(0.5,0.5,0.5), 1+offset)).fromBlock(); + } + if (v1 instanceof ListValue) + { + List args = ((ListValue) v1).getItems(); + Vec3d pos = new Vec3d( + NumericValue.asNumber(args.get(0)).getDouble(), + NumericValue.asNumber(args.get(1)).getDouble(), + NumericValue.asNumber(args.get(2)).getDouble()); + double yaw = 0.0D; + double pitch = 0.0D; + if (args.size()>3 && optionalDirection) + { + yaw = NumericValue.asNumber(args.get(3)).getDouble(); + pitch = NumericValue.asNumber(args.get(4)).getDouble(); + } + return new Vector3Argument(pos,offset+1, yaw, pitch); + } + Vec3d pos = new Vec3d( + NumericValue.asNumber(v1).getDouble(), + NumericValue.asNumber(params.get(1 + offset)).getDouble(), + NumericValue.asNumber(params.get(2 + offset)).getDouble()); + double yaw = 0.0D; + double pitch = 0.0D; + int eatenLength = 3; + if (params.size()>3+offset && optionalDirection) + { + yaw = NumericValue.asNumber(params.get(3 + offset)).getDouble(); + pitch = NumericValue.asNumber(params.get(4 + offset)).getDouble(); + eatenLength = 5; + } + + return new Vector3Argument(pos,offset+eatenLength, yaw, pitch); + } + catch (IndexOutOfBoundsException e) + { + throw new InternalExpressionException("Position argument should be defined either by three coordinates (a triple or by three arguments), or a positioned block value"); + } + } } diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 224d356a..783025a6 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -8,6 +8,7 @@ import carpet.helpers.Tracer; import carpet.patches.EntityPlayerMPFake; import carpet.script.CarpetContext; import carpet.script.EntityEventsGroup; +import carpet.script.argument.Vector3Argument; import carpet.script.exception.InternalExpressionException; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -789,26 +790,12 @@ public class EntityValue extends Value else if (v instanceof ListValue) { List lv = ((ListValue) v).getItems(); - if (lv.get(0) instanceof BlockValue) + Vector3Argument locator = Vector3Argument.findIn(lv, 0, false); + pos = new BlockPos(locator.vec.x, locator.vec.y, locator.vec.z); + if (lv.size() > locator.offset) { - pos = ((BlockValue) lv.get(0)).getPos(); - if (lv.size()>1) - { - distance = (int) NumericValue.asNumber(lv.get(1)).getLong(); - } + distance = (int) NumericValue.asNumber(lv.get(locator.offset)).getLong(); } - else if (lv.size()>=3) - { - pos = new BlockPos(NumericValue.asNumber(lv.get(0)).getLong(), - NumericValue.asNumber(lv.get(1)).getLong(), - NumericValue.asNumber(lv.get(2)).getLong()); - if (lv.size()>3) - { - distance = (int) NumericValue.asNumber(lv.get(4)).getLong(); - } - } - else throw new InternalExpressionException("'home' requires at least one position argument, and optional distance"); - } else throw new InternalExpressionException("'home' requires at least one position argument, and optional distance");