From f8f397560040c813367a7b9a088a6ca63dc49f6a Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 23 Sep 2023 17:50:44 +0200 Subject: [PATCH] Implemented sign block interactions in <= 1.20.1 --- .../block/MixinAbstractSignBlock.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractSignBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractSignBlock.java index 733f761c..160fb2b2 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractSignBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractSignBlock.java @@ -15,13 +15,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.raphimc.vialoader.util.VersionEnum; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; 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(AbstractSignBlock.class) -public class MixinAbstractSignBlock { +public abstract class MixinAbstractSignBlock { + + @Shadow protected abstract ActionResult getActionResult(boolean usedSignChanger); @Redirect(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/SignBlockEntity;isWaxed()Z", ordinal = 1)) public boolean removeCondition(SignBlockEntity instance) { @@ -42,4 +45,20 @@ public class MixinAbstractSignBlock { cir.setReturnValue(!((item.isOf(Items.GLOW_INK_SAC) || item.isOf(Items.INK_SAC) || item.getItem() instanceof DyeItem) && player.canModifyBlocks()) && !signBlockEntity.isWaxed() ? ActionResult.CONSUME : ActionResult.SUCCESS); } } + + @Redirect(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractSignBlock;getActionResult(Z)Lnet/minecraft/util/ActionResult;", ordinal = 0)) + public ActionResult returnStaticResult_Pass(AbstractSignBlock instance, boolean usedSignChanger) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { + return ActionResult.PASS; + } + return getActionResult(usedSignChanger); + } + + @Redirect(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractSignBlock;getActionResult(Z)Lnet/minecraft/util/ActionResult;", ordinal = 1)) + public ActionResult returnStaticResult_Success(AbstractSignBlock instance, boolean usedSignChanger) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) { + return ActionResult.SUCCESS; + } + return getActionResult(usedSignChanger); + } }