fix run position, fixes #866

This commit is contained in:
gnembon committed 2021-05-18 21:18:53 -03:00
1 parent 482170e49d
commit edc90133b2
2 files changed
+11 -10

No files matched your search

@@ -600,16 +600,15 @@ public class Auxiliary {
return new FormattedTextValue(Messenger.c(values.stream().map(Value::getString).toArray())); return new FormattedTextValue(Messenger.c(values.stream().map(Value::getString).toArray()));
}); });
expression.addContextFunction("run", 1, (c, t, lv) -> { 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);
ServerCommandSource s = ((CarpetContext)c).s; ServerCommandSource s = ((CarpetContext)c).s;
try try
{ {
Text[] error = {null}; Text[] error = {null};
List<Text> output = new ArrayList<>(); List<Text> output = new ArrayList<>();
Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute( Value retval = new NumericValue(s.getMinecraftServer().getCommandManager().execute(
new SnoopyCommandSource(s, posf, error, output), new SnoopyCommandSource(s, error, output),
lv.get(0).getString()) lv.get(0).getString())
); );
return ListValue.of( 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; ServerCommandSource s = ((CarpetContext)c).s;
s.getMinecraftServer().getPlayerManager().saveAllPlayerData(); s.getMinecraftServer().getPlayerManager().saveAllPlayerData();
s.getMinecraftServer().save(true,true,true); s.getMinecraftServer().save(true,true,true);
@@ -38,13 +38,13 @@ public class SnoopyCommandSource extends ServerCommandSource
private final Text[] error; private final Text[] error;
private final List<Text> chatOutput; private final List<Text> chatOutput;
public SnoopyCommandSource(ServerCommandSource original, Vec3d pos, Text[] error, List<Text> chatOutput) public SnoopyCommandSource(ServerCommandSource original, Text[] error, List<Text> 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, original.getName(), original.getDisplayName(), original.getMinecraftServer(), original.getEntity(), false,
(ctx, succ, res) -> { }, EntityAnchorArgumentType.EntityAnchor.FEET); (ctx, succ, res) -> { }, EntityAnchorArgumentType.EntityAnchor.FEET);
this.output = CommandOutput.DUMMY; this.output = CommandOutput.DUMMY;
this.position = pos; this.position = original.getPosition();
this.world = original.getWorld(); this.world = original.getWorld();
this.level = CarpetSettings.runPermissionLevel; this.level = CarpetSettings.runPermissionLevel;
this.simpleName = original.getName(); this.simpleName = original.getName();
@@ -53,7 +53,7 @@ public class SnoopyCommandSource extends ServerCommandSource
this.entity = original.getEntity(); this.entity = original.getEntity();
this.resultConsumer = (ctx, succ, res) -> { }; this.resultConsumer = (ctx, succ, res) -> { };
this.entityAnchor = original.getEntityAnchor(); this.entityAnchor = original.getEntityAnchor();
this.rotation = Vec2f.ZERO; this.rotation = original.getRotation();
this.error = error; this.error = error;
this.chatOutput = chatOutput; this.chatOutput = chatOutput;
} }
@@ -73,7 +73,7 @@ public class SnoopyCommandSource extends ServerCommandSource
this.entity = player; this.entity = player;
this.resultConsumer = (ctx, succ, res) -> { }; this.resultConsumer = (ctx, succ, res) -> { };
this.entityAnchor = EntityAnchorArgumentType.EntityAnchor.FEET; this.entityAnchor = EntityAnchorArgumentType.EntityAnchor.FEET;
this.rotation = Vec2f.ZERO; this.rotation = player.getRotationClient(); // not a client call really
this.error = error; this.error = error;
this.chatOutput = output; 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); return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, resultConsumer, entityAnchor, error, chatOutput);
} }
@Override
public ServerCommandSource withLookingAt(Vec3d position) throws CommandSyntaxException { public ServerCommandSource withLookingAt(Vec3d position) throws CommandSyntaxException {
Vec3d vec3d = this.entityAnchor.positionAt(this); Vec3d vec3d = this.entityAnchor.positionAt(this);
double d = position.x - vec3d.x; double d = position.x - vec3d.x;