Skip to content

Commit

Permalink
Fix five broken mixins
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DragonEggBedrockBreaking committed Mar 17, 2023
1 parent 9206bc9 commit 09b34b3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<InteractionResult> 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"))
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<CommandSourceStack> parseResults, String command) {
@Inject(method = "performCommand", at = @At(value = "HEAD"), cancellable = true)
private void performCommand(ParseResults<CommandSourceStack> parseResults, String command, CallbackInfoReturnable<Integer> cir) {
String commandName = command.split(" ")[0];
Gamerules commandGamerule = commandsStringMap.get(commandName);
Gamerules dedicatedCommandGamerule = commandsStringMapDedicated.get(commandName);
Expand All @@ -24,8 +25,7 @@ private int performCommand(int original, ParseResults<CommandSourceStack> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> cir) {
if (!Gamerules.PISTON_ENABLED.getBool()) {
return false;
cir.setReturnValue(false);
}
return original;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
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;
import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
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<StructureCheckResult> cir) {
Gamerules gameRule;
if (structure instanceof JigsawStructure jigsawStructure) {
gameRule = structureCheckStringMap.get(jigsawStructure.startPool.unwrap().orThrow().location().toString());
} else {
gameRule = structureCheckStructureTypeMap.get(structure.type());
}
if (gameRule != null && !gameRule.getBool()) {
return StructureCheckResult.START_NOT_PRESENT;
cir.setReturnValue(StructureCheckResult.START_NOT_PRESENT);
}
return original;
}
}
5 changes: 0 additions & 5 deletions src/main/resources/vanilla_disable.aw
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 09b34b3

Please sign in to comment.