From 09b34b3a2381dd75bf53e4028888c52d0cba2938 Mon Sep 17 00:00:00 2001 From: DragonEggBedrockBreaking <68545280+DragonEggBedrockBreaking@users.noreply.github.com> Date: Fri, 17 Mar 2023 19:22:57 +0000 Subject: [PATCH] Fix five broken mixins In four mixins, ModifyReturnValue doesn't work properly, so we need Inject + CallbackInfoReturnable instead In one mixin, ModifyExpressionValue doesn't work properly, so we need Redirect --- .../mixin/blocks/MixinBlockStateBase.java | 8 ++++---- .../vanilla_disable/mixin/commands/MixinCommands.java | 10 +++++----- .../mixin/mobs/MixinDragonStrafePlayerPhase.java | 10 ++++++---- .../mixin/redstone/MixinPistonBaseBlock.java | 10 +++++----- .../mixin/worldgen/MixinStructureCheck.java | 10 +++++----- src/main/resources/vanilla_disable.aw | 5 ----- 6 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/main/java/uk/debb/vanilla_disable/mixin/blocks/MixinBlockStateBase.java b/src/main/java/uk/debb/vanilla_disable/mixin/blocks/MixinBlockStateBase.java index 908e2de1..da8b00d2 100644 --- a/src/main/java/uk/debb/vanilla_disable/mixin/blocks/MixinBlockStateBase.java +++ b/src/main/java/uk/debb/vanilla_disable/mixin/blocks/MixinBlockStateBase.java @@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import uk.debb.vanilla_disable.util.gamerules.Gamerules; import uk.debb.vanilla_disable.util.maps.Maps; @@ -18,13 +19,12 @@ public abstract class MixinBlockStateBase implements Maps { @Shadow public abstract Block getBlock(); - @ModifyReturnValue(method = "use", at = @At("RETURN")) - private InteractionResult modifyUse(InteractionResult original) { + @Inject(method = "use", at = @At("HEAD"), cancellable = true) + private void modifyUse(CallbackInfoReturnable cir) { Gamerules gameRule = blockStateBaseBlockMap.get(this.getBlock()); if (gameRule != null && !gameRule.getBool()) { - return InteractionResult.FAIL; + cir.setReturnValue(InteractionResult.FAIL); } - return original; } @ModifyReturnValue(method = "getMenuProvider", at = @At("RETURN")) diff --git a/src/main/java/uk/debb/vanilla_disable/mixin/commands/MixinCommands.java b/src/main/java/uk/debb/vanilla_disable/mixin/commands/MixinCommands.java index b318ec63..1c9ba60b 100644 --- a/src/main/java/uk/debb/vanilla_disable/mixin/commands/MixinCommands.java +++ b/src/main/java/uk/debb/vanilla_disable/mixin/commands/MixinCommands.java @@ -1,6 +1,5 @@ package uk.debb.vanilla_disable.mixin.commands; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.mojang.brigadier.ParseResults; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSourceStack; @@ -9,13 +8,15 @@ import net.minecraft.server.MinecraftServer; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import uk.debb.vanilla_disable.util.gamerules.Gamerules; import uk.debb.vanilla_disable.util.maps.Maps; @Mixin(Commands.class) public abstract class MixinCommands implements Maps { - @ModifyReturnValue(method = "performCommand", at = @At(value = "RETURN")) - private int performCommand(int original, ParseResults parseResults, String command) { + @Inject(method = "performCommand", at = @At(value = "HEAD"), cancellable = true) + private void performCommand(ParseResults parseResults, String command, CallbackInfoReturnable cir) { String commandName = command.split(" ")[0]; Gamerules commandGamerule = commandsStringMap.get(commandName); Gamerules dedicatedCommandGamerule = commandsStringMapDedicated.get(commandName); @@ -24,8 +25,7 @@ private int performCommand(int original, ParseResults parseR (commandGamerule != null && !commandGamerule.getBool()) || (server.isDedicatedServer() && dedicatedCommandGamerule != null && !dedicatedCommandGamerule.getBool())) { server.getPlayerList().broadcastSystemMessage(Component.translatable("commands.disabled.by.vd").withStyle(ChatFormatting.RED), false); - return 0; + cir.setReturnValue(0); } - return original; } } diff --git a/src/main/java/uk/debb/vanilla_disable/mixin/mobs/MixinDragonStrafePlayerPhase.java b/src/main/java/uk/debb/vanilla_disable/mixin/mobs/MixinDragonStrafePlayerPhase.java index 02479c4e..b45cbdde 100644 --- a/src/main/java/uk/debb/vanilla_disable/mixin/mobs/MixinDragonStrafePlayerPhase.java +++ b/src/main/java/uk/debb/vanilla_disable/mixin/mobs/MixinDragonStrafePlayerPhase.java @@ -1,24 +1,26 @@ package uk.debb.vanilla_disable.mixin.mobs; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.boss.enderdragon.phases.DragonStrafePlayerPhase; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; import uk.debb.vanilla_disable.util.gamerules.Gamerules; @Mixin(DragonStrafePlayerPhase.class) public abstract class MixinDragonStrafePlayerPhase { - @ModifyExpressionValue( + @Redirect( method = "doServerTick", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z" ) ) - private boolean spawnFreshEntity(boolean original) { + private boolean spawnFreshEntity(Level instance, Entity entity) { if (!Gamerules.DRAGON_FIREBALLS.getBool()) { return false; } - return original; + return instance.addFreshEntity(entity); } } \ No newline at end of file diff --git a/src/main/java/uk/debb/vanilla_disable/mixin/redstone/MixinPistonBaseBlock.java b/src/main/java/uk/debb/vanilla_disable/mixin/redstone/MixinPistonBaseBlock.java index 36fa02e1..373b6f33 100644 --- a/src/main/java/uk/debb/vanilla_disable/mixin/redstone/MixinPistonBaseBlock.java +++ b/src/main/java/uk/debb/vanilla_disable/mixin/redstone/MixinPistonBaseBlock.java @@ -1,18 +1,18 @@ package uk.debb.vanilla_disable.mixin.redstone; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.world.level.block.piston.PistonBaseBlock; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import uk.debb.vanilla_disable.util.gamerules.Gamerules; @Mixin(PistonBaseBlock.class) public abstract class MixinPistonBaseBlock { - @ModifyReturnValue(method = "triggerEvent", at = @At("RETURN")) - private boolean cancelTriggeringEvent(boolean original) { + @Inject(method = "triggerEvent", at = @At("HEAD"), cancellable = true) + private void cancelTriggeringEvent(CallbackInfoReturnable cir) { if (!Gamerules.PISTON_ENABLED.getBool()) { - return false; + cir.setReturnValue(false); } - return original; } } \ No newline at end of file diff --git a/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/MixinStructureCheck.java b/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/MixinStructureCheck.java index e3703231..42d5c349 100644 --- a/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/MixinStructureCheck.java +++ b/src/main/java/uk/debb/vanilla_disable/mixin/worldgen/MixinStructureCheck.java @@ -1,6 +1,5 @@ package uk.debb.vanilla_disable.mixin.worldgen; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureCheck; @@ -8,13 +7,15 @@ import net.minecraft.world.level.levelgen.structure.structures.JigsawStructure; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import uk.debb.vanilla_disable.util.gamerules.Gamerules; import uk.debb.vanilla_disable.util.maps.Maps; @Mixin(StructureCheck.class) public abstract class MixinStructureCheck implements Maps { - @ModifyReturnValue(method = "checkStart", at = @At("RETURN")) - private StructureCheckResult cancelCheckingStart(StructureCheckResult original, ChunkPos chunkPos, Structure structure, boolean bl) { + @Inject(method = "checkStart", at = @At("HEAD"), cancellable = true) + private void cancelCheckingStart(ChunkPos chunkPos, Structure structure, boolean bl, CallbackInfoReturnable cir) { Gamerules gameRule; if (structure instanceof JigsawStructure jigsawStructure) { gameRule = structureCheckStringMap.get(jigsawStructure.startPool.unwrap().orThrow().location().toString()); @@ -22,8 +23,7 @@ private StructureCheckResult cancelCheckingStart(StructureCheckResult original, gameRule = structureCheckStructureTypeMap.get(structure.type()); } if (gameRule != null && !gameRule.getBool()) { - return StructureCheckResult.START_NOT_PRESENT; + cir.setReturnValue(StructureCheckResult.START_NOT_PRESENT); } - return original; } } \ No newline at end of file diff --git a/src/main/resources/vanilla_disable.aw b/src/main/resources/vanilla_disable.aw index 7560dc10..7fd5cfab 100644 --- a/src/main/resources/vanilla_disable.aw +++ b/src/main/resources/vanilla_disable.aw @@ -1,10 +1,5 @@ accessWidener v2 named -accessible field net/minecraft/world/level/DataPackConfig enabled Ljava/util/List; -accessible field net/minecraft/world/level/DataPackConfig disabled Ljava/util/List; -mutable field net/minecraft/world/level/DataPackConfig enabled Ljava/util/List; -mutable field net/minecraft/world/level/DataPackConfig disabled Ljava/util/List; - accessible class net/minecraft/world/entity/animal/Bee$BeeAttackGoal accessible class net/minecraft/world/entity/animal/Bee$BaseBeeGoal accessible class net/minecraft/world/entity/animal/Bee$BeeEnterHiveGoal