diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index b3a95b65..70a34283 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -600,16 +600,15 @@ public class Auxiliary { return new FormattedTextValue(Messenger.c(values.stream().map(Value::getString).toArray())); }); - expression.addContextFunction("run", 1, (c, t, lv) -> { - BlockPos target = ((CarpetContext)c).origin; - Vec3d posf = new Vec3d((double)target.getX()+0.5D, target.getY(),(double)target.getZ()+0.5D); + expression.addContextFunction("run", 1, (c, t, lv) -> + { ServerCommandSource s = ((CarpetContext)c).s; try { Text[] error = {null}; List output = new ArrayList<>(); Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute( - new SnoopyCommandSource(s, posf, error, output), + new SnoopyCommandSource(s, error, output), lv.get(0).getString()) ); return ListValue.of( @@ -624,7 +623,8 @@ public class Auxiliary { } }); - expression.addContextFunction("save", 0, (c, t, lv) -> { + expression.addContextFunction("save", 0, (c, t, lv) -> + { ServerCommandSource s = ((CarpetContext)c).s; s.getMinecraftServer().getPlayerManager().saveAllPlayerData(); s.getMinecraftServer().save(true,true,true); diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 3242f91d..5092c371 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -38,13 +38,13 @@ public class SnoopyCommandSource extends ServerCommandSource private final Text[] error; private final List chatOutput; - public SnoopyCommandSource(ServerCommandSource original, Vec3d pos, Text[] error, List chatOutput) + public SnoopyCommandSource(ServerCommandSource original, Text[] error, List chatOutput) { - super(CommandOutput.DUMMY, pos, Vec2f.ZERO, original.getWorld(), CarpetSettings.runPermissionLevel, + super(CommandOutput.DUMMY, original.getPosition(), original.getRotation(), original.getWorld(), CarpetSettings.runPermissionLevel, original.getName(), original.getDisplayName(), original.getMinecraftServer(), original.getEntity(), false, (ctx, succ, res) -> { }, EntityAnchorArgumentType.EntityAnchor.FEET); this.output = CommandOutput.DUMMY; - this.position = pos; + this.position = original.getPosition(); this.world = original.getWorld(); this.level = CarpetSettings.runPermissionLevel; this.simpleName = original.getName(); @@ -53,7 +53,7 @@ public class SnoopyCommandSource extends ServerCommandSource this.entity = original.getEntity(); this.resultConsumer = (ctx, succ, res) -> { }; this.entityAnchor = original.getEntityAnchor(); - this.rotation = Vec2f.ZERO; + this.rotation = original.getRotation(); this.error = error; this.chatOutput = chatOutput; } @@ -73,7 +73,7 @@ public class SnoopyCommandSource extends ServerCommandSource this.entity = player; this.resultConsumer = (ctx, succ, res) -> { }; this.entityAnchor = EntityAnchorArgumentType.EntityAnchor.FEET; - this.rotation = Vec2f.ZERO; + this.rotation = player.getRotationClient(); // not a client call really this.error = error; this.chatOutput = output; } @@ -158,6 +158,7 @@ public class SnoopyCommandSource extends ServerCommandSource return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput); } + @Override public ServerCommandSource withLookingAt(Vec3d position) throws CommandSyntaxException { Vec3d vec3d = this.entityAnchor.positionAt(this); double d = position.x - vec3d.x;