From ca5f69a4762377aadcbe98e300e354a18159969d Mon Sep 17 00:00:00 2001 From: gnembon Date: Sun, 12 Oct 2025 14:04:36 +0200 Subject: [PATCH] fix return value of run not captured --- .../fakes/CommandSourceStackInterface.java | 10 +++++++ .../CommandSourceStack_scarpetMixin.java | 29 +++++++++++++++++++ .../script/utils/SnoopyCommandSource.java | 4 +++ src/main/resources/carpet.accesswidener | 3 -- src/main/resources/carpet.mixins.json | 1 + 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/main/java/carpet/fakes/CommandSourceStackInterface.java create mode 100644 src/main/java/carpet/mixins/CommandSourceStack_scarpetMixin.java diff --git a/src/main/java/carpet/fakes/CommandSourceStackInterface.java b/src/main/java/carpet/fakes/CommandSourceStackInterface.java new file mode 100644 index 00000000..7e846dbd --- /dev/null +++ b/src/main/java/carpet/fakes/CommandSourceStackInterface.java @@ -0,0 +1,10 @@ +package carpet.fakes; + +import net.minecraft.commands.CommandResultCallback; +import net.minecraft.commands.CommandSigningContext; +import net.minecraft.commands.arguments.EntityAnchorArgument; +import net.minecraft.util.TaskChainer; + +public interface CommandSourceStackInterface { + void setupPrivates(boolean bl, CommandResultCallback commandResultCallback, EntityAnchorArgument.Anchor anchor, CommandSigningContext commandSigningContext, TaskChainer taskChainer); +} diff --git a/src/main/java/carpet/mixins/CommandSourceStack_scarpetMixin.java b/src/main/java/carpet/mixins/CommandSourceStack_scarpetMixin.java new file mode 100644 index 00000000..26b33865 --- /dev/null +++ b/src/main/java/carpet/mixins/CommandSourceStack_scarpetMixin.java @@ -0,0 +1,29 @@ +package carpet.mixins; + +import carpet.fakes.CommandSourceStackInterface; +import net.minecraft.commands.CommandResultCallback; +import net.minecraft.commands.CommandSigningContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.arguments.EntityAnchorArgument; +import net.minecraft.util.TaskChainer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CommandSourceStack.class) +public class CommandSourceStack_scarpetMixin implements CommandSourceStackInterface { + @Mutable @Shadow private boolean silent; + @Mutable @Shadow private CommandResultCallback resultCallback; + @Mutable @Shadow private EntityAnchorArgument.Anchor anchor; + @Mutable @Shadow private CommandSigningContext signingContext; + @Mutable @Shadow private TaskChainer chatMessageChainer; + + @Override + public void setupPrivates(boolean bl, CommandResultCallback commandResultCallback, EntityAnchorArgument.Anchor anchor, CommandSigningContext commandSigningContext, TaskChainer taskChainer) { + this.silent = bl; + this.resultCallback = commandResultCallback; + this.anchor = anchor; + this.signingContext = commandSigningContext; + this.chatMessageChainer = taskChainer; + } +} diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index d100b6ec..ef3ee096 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -1,5 +1,6 @@ package carpet.script.utils; +import carpet.fakes.CommandSourceStackInterface; import carpet.script.external.Vanilla; import net.minecraft.commands.CommandResultCallback; import net.minecraft.commands.CommandSigningContext; @@ -66,6 +67,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.chatOutput = chatOutput; this.signingContext = original.getSigningContext(); this.taskChainer = TaskChainer.immediate(original.getServer()); + ((CommandSourceStackInterface) this).setupPrivates(false, (b, i) -> returnValue[0] = OptionalLong.of(i), EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer())); } public SnoopyCommandSource(ServerPlayer player, Component[] error, List output, int [] result) @@ -89,6 +91,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.chatOutput = output; this.signingContext = CommandSigningContext.ANONYMOUS; this.taskChainer = TaskChainer.immediate(player.level().getServer()); + ((CommandSourceStackInterface) this).setupPrivates(false, (b, i) -> result[0] = i, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(player.level().getServer())); } private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, PermissionSet level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, @@ -114,6 +117,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.chatOutput = chatOutput; this.signingContext = context; this.taskChainer = chainer; + ((CommandSourceStackInterface) this).setupPrivates(false, consumer, entityAnchor, context, chainer); } @Override diff --git a/src/main/resources/carpet.accesswidener b/src/main/resources/carpet.accesswidener index b5c8fd8a..23c54edf 100644 --- a/src/main/resources/carpet.accesswidener +++ b/src/main/resources/carpet.accesswidener @@ -8,11 +8,8 @@ accessible class net/minecraft/world/level/border/WorldBorder$StaticBorderExtent accessible class net/minecraft/server/MinecraftServer$ReloadableResources accessible class net/minecraft/world/level/biome/Biome$ClimateSettings accessible class net/minecraft/world/level/block/entity/SculkSensorBlockEntity$VibrationUser -#accessible class net/minecraft/commands/CommandSourceStack #TODO fields and methods should be fetched via interfaces unless there is a good reason not to -#accessible method net/minecraft/commands/CommandSourceStack (Lnet/minecraft/commands/CommandSource;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec2;Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/server/permissions/PermissionSet;Ljava/lang/String;Lnet/minecraft/network/chat/Component;Lnet/minecraft/server/MinecraftServer;Lnet/minecraft/world/entity/Entity;BLnet/minecraft/commands/CommandResultCallback;Lnet/minecraft/commands/arguments/EntityAnchorArgument$Anchor;Lnet/minecraft/commands/CommandSigningContext;Lnet/minecraft/util/TaskChainer;)V accessible method net/minecraft/world/level/border/WorldBorder getListeners ()Ljava/util/List; accessible method net/minecraft/world/level/redstone/DefaultRedstoneWireEvaluator calculateTargetStrength (Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)I - accessible field net/minecraft/world/level/block/state/BlockBehaviour UPDATE_SHAPE_ORDER [Lnet/minecraft/core/Direction; diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index df0cb888..5341d9b2 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -148,6 +148,7 @@ "CommandNode_scarpetCommandsMixin", "CommandDispatcher_scarpetCommandsMixin", "FoodData_scarpetMixin", + "CommandSourceStack_scarpetMixin", "BlockInput_scarpetMixin", "BlockPredicate_scarpetMixin",