From 8346e3f81dedcfce79a9eb3d9577016981f01c33 Mon Sep 17 00:00:00 2001 From: ManInMyVan Date: Sun, 15 Sep 2024 16:07:10 -0600 Subject: [PATCH 1/2] fix ascending rail hitbox in 1.10 --- .../block/MixinAbstractRailBlock.java | 59 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 1 + 2 files changed, 60 insertions(+) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java new file mode 100644 index 00000000..38691e7c --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java @@ -0,0 +1,59 @@ +/* + * 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.*; +import net.minecraft.block.enums.RailShape; +import net.minecraft.state.property.Property; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(AbstractRailBlock.class) +public abstract class MixinAbstractRailBlock extends Block { + + public MixinAbstractRailBlock(Settings settings) { + super(settings); + } + + @Shadow public abstract Property getShapeProperty(); + + @Unique + private static final VoxelShape viaFabricPlus$ascending_shape_r1_10_x = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); + + @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) + private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + // https://bugs.mojang.com/browse/MC-102638 + if (ProtocolTranslator.getTargetVersion().equalTo(ProtocolVersion.v1_10)) { + final RailShape shape = state.isOf(this) ? state.get(getShapeProperty()) : null; + if (shape != null && shape.isAscending()) { + cir.setReturnValue(viaFabricPlus$ascending_shape_r1_10_x); + } + } + } +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index cdd058fd..54112e1b 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -67,6 +67,7 @@ "fixes.minecraft.MixinWorldRenderer", "fixes.minecraft.block.MixinAbstractBlock", "fixes.minecraft.block.MixinAbstractBlock_AbstractBlockState", + "fixes.minecraft.block.MixinAbstractRailBlock", "fixes.minecraft.block.MixinAbstractSignBlock", "fixes.minecraft.block.MixinAnvilBlock", "fixes.minecraft.block.MixinBedBlock", From 59833371d35449f6ac74f034db0204138d76a968 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Mon, 16 Sep 2024 17:25:38 +0200 Subject: [PATCH 2/2] Cleanup, use Redirect instead --- .../block/MixinAbstractRailBlock.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java index 38691e7c..5d934e65 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/block/MixinAbstractRailBlock.java @@ -22,38 +22,37 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.block.*; -import net.minecraft.block.enums.RailShape; -import net.minecraft.state.property.Property; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.shape.VoxelShape; -import net.minecraft.world.BlockView; +import net.minecraft.util.shape.VoxelShapes; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(AbstractRailBlock.class) public abstract class MixinAbstractRailBlock extends Block { + @Shadow + @Final + protected static VoxelShape ASCENDING_SHAPE; + + @Unique + private static final VoxelShape viaFabricPlus$ascending_shape_r1_10_x = VoxelShapes.fullCube(); + public MixinAbstractRailBlock(Settings settings) { super(settings); } - @Shadow public abstract Property getShapeProperty(); - - @Unique - private static final VoxelShape viaFabricPlus$ascending_shape_r1_10_x = Block.createCuboidShape(0.0D, 0.0D, 0.0D, 16.0D, 16.0D, 16.0D); - - @Inject(method = "getOutlineShape", at = @At("HEAD"), cancellable = true) - private void changeOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, CallbackInfoReturnable cir) { + @Redirect(method = "getOutlineShape", at = @At(value = "FIELD", target = "Lnet/minecraft/block/AbstractRailBlock;ASCENDING_SHAPE:Lnet/minecraft/util/shape/VoxelShape;")) + private VoxelShape changeOutlineShape() { // https://bugs.mojang.com/browse/MC-102638 if (ProtocolTranslator.getTargetVersion().equalTo(ProtocolVersion.v1_10)) { - final RailShape shape = state.isOf(this) ? state.get(getShapeProperty()) : null; - if (shape != null && shape.isAscending()) { - cir.setReturnValue(viaFabricPlus$ascending_shape_r1_10_x); - } + return viaFabricPlus$ascending_shape_r1_10_x; + } else { + return ASCENDING_SHAPE; } } + }