From 7fc57b1090afe0623707b705e5d922ac7bf1f065 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sun, 27 Oct 2024 16:02:44 +0100 Subject: [PATCH] Disable hand swinging in some blocks in <= 1.21.1 --- .../fixes/minecraft/block/MixinBedBlock.java | 11 +++++ .../block/MixinDecoratedPotBlock.java | 10 +++++ .../minecraft/block/MixinVaultBlock.java | 42 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 3 +- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinVaultBlock.java diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinBedBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinBedBlock.java index 0e815ba8..14671df0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinBedBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinBedBlock.java @@ -24,9 +24,13 @@ import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.block.*; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.BlockView; +import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -47,6 +51,13 @@ public abstract class MixinBedBlock extends HorizontalFacingBlock { @Unique private boolean viaFabricPlus$requireOriginalShape; + @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) + private void dontSwingHand(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + cir.setReturnValue(ActionResult.CONSUME); + } + } + @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { if (ViaFabricPlusMixinPlugin.MORE_CULLING_PRESENT && viaFabricPlus$requireOriginalShape) { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinDecoratedPotBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinDecoratedPotBlock.java index 3ce2f30c..5930b798 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinDecoratedPotBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinDecoratedPotBlock.java @@ -33,11 +33,21 @@ import net.minecraft.world.World; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(DecoratedPotBlock.class) public abstract class MixinDecoratedPotBlock { + @Redirect(method = "onUseWithItem", at = @At(value = "FIELD", target = "Lnet/minecraft/util/ActionResult;SUCCESS:Lnet/minecraft/util/ActionResult$Success;", ordinal = 0)) + private ActionResult.Success dontSwingHand() { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + return ActionResult.CONSUME; + } else { + return ActionResult.SUCCESS; + } + } + @Inject(method = "onUseWithItem", at = @At("HEAD"), cancellable = true) private void alwaysPass(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_2)) { diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinVaultBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinVaultBlock.java new file mode 100644 index 00000000..7bf49f1b --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinVaultBlock.java @@ -0,0 +1,42 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC + * Copyright (C) 2023-2024 contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.block; + +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; +import net.minecraft.block.VaultBlock; +import net.minecraft.util.ActionResult; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(VaultBlock.class) +public abstract class MixinVaultBlock { + + @Redirect(method = "onUseWithItem", at = @At(value = "FIELD", target = "Lnet/minecraft/util/ActionResult;SUCCESS_SERVER:Lnet/minecraft/util/ActionResult$Success;")) + private ActionResult.Success dontSwingHand() { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + return ActionResult.CONSUME; + } else { + return ActionResult.SUCCESS_SERVER; + } + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index c777d158..8b560a7d 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -210,7 +210,8 @@ "fixes.viaversion.MixinWorldPacketRewriter1_19", "viabedrock.MixinJoinPackets", "vialegacy.MixinExtensionProtocolMetadataStorage", - "vialegacy.MixinViaLegacyConfig" + "vialegacy.MixinViaLegacyConfig", + "fixes.minecraft.block.MixinVaultBlock" ], "injectors": { "defaultRequire": 1