diff --git a/src/main/java/carpet/fakes/BlockBehaviourInterface.java b/src/main/java/carpet/fakes/BlockBehaviourInterface.java deleted file mode 100644 index 289c0743..00000000 --- a/src/main/java/carpet/fakes/BlockBehaviourInterface.java +++ /dev/null @@ -1,20 +0,0 @@ -package carpet.fakes; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockState; - -public interface BlockBehaviourInterface { - - /** - * @return whether this block is sticky in any way when moved by pistons - */ - public boolean isSticky(BlockState state); - - /** - * @return whether the neighboring block is pulled along if this block is moved by pistons - */ - public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir); - -} diff --git a/src/main/java/carpet/fakes/BlockPistonBehaviourInterface.java b/src/main/java/carpet/fakes/BlockPistonBehaviourInterface.java new file mode 100644 index 00000000..d65ea525 --- /dev/null +++ b/src/main/java/carpet/fakes/BlockPistonBehaviourInterface.java @@ -0,0 +1,28 @@ +package carpet.fakes; + +import carpet.mixins.PistonStructureResolver_customStickyMixin; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.piston.PistonStructureResolver; +import net.minecraft.world.level.block.state.BlockState; + +/** + * Opt-in Interface that allows for more control on a blocks interaction within the {@link PistonStructureResolver} via {@link PistonStructureResolver_customStickyMixin} + */ +public interface BlockPistonBehaviourInterface { + + /** + * @return whether this block is sticky in any way when moved by pistons + */ + default boolean isSticky(BlockState state) { + return false; + } + + /** + * @return whether the neighboring block is pulled along if this block is moved by pistons + */ + default boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { + return false; + } +} diff --git a/src/main/java/carpet/mixins/BlockBehaviour_customStickyMixin.java b/src/main/java/carpet/mixins/BlockBehaviour_customStickyMixin.java deleted file mode 100644 index 55fc78b4..00000000 --- a/src/main/java/carpet/mixins/BlockBehaviour_customStickyMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package carpet.mixins; - -import org.spongepowered.asm.mixin.Mixin; - -import carpet.fakes.BlockBehaviourInterface; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; - -@Mixin(BlockBehaviour.class) -public class BlockBehaviour_customStickyMixin implements BlockBehaviourInterface { - - @Override - public boolean isSticky(BlockState state) { - return false; - } - - @Override - public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { - return false; - } -} diff --git a/src/main/java/carpet/mixins/ChainBlock_customStickyMixin.java b/src/main/java/carpet/mixins/ChainBlock_customStickyMixin.java index 9cad0aea..c7e3d727 100644 --- a/src/main/java/carpet/mixins/ChainBlock_customStickyMixin.java +++ b/src/main/java/carpet/mixins/ChainBlock_customStickyMixin.java @@ -1,10 +1,10 @@ package carpet.mixins; +import carpet.fakes.BlockPistonBehaviourInterface; import org.spongepowered.asm.mixin.Mixin; import carpet.CarpetSettings; import carpet.CarpetSettings.ChainStoneMode; -import carpet.fakes.BlockBehaviourInterface; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -17,7 +17,7 @@ import net.minecraft.world.level.block.EndRodBlock; import net.minecraft.world.level.block.state.BlockState; @Mixin(ChainBlock.class) -public class ChainBlock_customStickyMixin implements BlockBehaviourInterface { +public class ChainBlock_customStickyMixin implements BlockPistonBehaviourInterface { @Override public boolean isSticky(BlockState state) { diff --git a/src/main/java/carpet/mixins/ChestBlock_customStickyMixin.java b/src/main/java/carpet/mixins/ChestBlock_customStickyMixin.java index 6b98c1f8..271a3b1c 100644 --- a/src/main/java/carpet/mixins/ChestBlock_customStickyMixin.java +++ b/src/main/java/carpet/mixins/ChestBlock_customStickyMixin.java @@ -1,9 +1,9 @@ package carpet.mixins; +import carpet.fakes.BlockPistonBehaviourInterface; import org.spongepowered.asm.mixin.Mixin; import carpet.CarpetSettings; -import carpet.fakes.BlockBehaviourInterface; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -16,7 +16,7 @@ import net.minecraft.world.level.block.state.properties.ChestType; import static net.minecraft.world.level.block.ChestBlock.getConnectedDirection; @Mixin(ChestBlock.class) -public class ChestBlock_customStickyMixin implements BlockBehaviourInterface { +public class ChestBlock_customStickyMixin implements BlockPistonBehaviourInterface { @Override public boolean isSticky(BlockState state) { @@ -35,6 +35,7 @@ public class ChestBlock_customStickyMixin implements BlockBehaviourInterface { if (type == ChestType.SINGLE || neighborType == ChestType.SINGLE) { return false; } + return getConnectedDirection(state) == dir; } } diff --git a/src/main/java/carpet/mixins/HoneyBlock_customStickyMixin.java b/src/main/java/carpet/mixins/HoneyBlock_customStickyMixin.java deleted file mode 100644 index d103e399..00000000 --- a/src/main/java/carpet/mixins/HoneyBlock_customStickyMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package carpet.mixins; - -import org.spongepowered.asm.mixin.Mixin; - -import carpet.fakes.BlockBehaviourInterface; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.HoneyBlock; -import net.minecraft.world.level.block.state.BlockState; - -@Mixin(HoneyBlock.class) -public class HoneyBlock_customStickyMixin implements BlockBehaviourInterface { - - @Override - public boolean isSticky(BlockState state) { - return true; - } - - @Override - public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { - return !neighborState.is(Blocks.SLIME_BLOCK); - } -} diff --git a/src/main/java/carpet/mixins/PistonStructureResolver_customStickyMixin.java b/src/main/java/carpet/mixins/PistonStructureResolver_customStickyMixin.java index 13abaec9..9d868980 100644 --- a/src/main/java/carpet/mixins/PistonStructureResolver_customStickyMixin.java +++ b/src/main/java/carpet/mixins/PistonStructureResolver_customStickyMixin.java @@ -3,13 +3,14 @@ package carpet.mixins; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import carpet.fakes.BlockBehaviourInterface; +import carpet.fakes.BlockPistonBehaviourInterface; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -18,11 +19,13 @@ import net.minecraft.world.level.block.piston.PistonStructureResolver; import net.minecraft.world.level.block.state.BlockState; @Mixin(PistonStructureResolver.class) -public class PistonStructureResolver_customStickyMixin { +public abstract class PistonStructureResolver_customStickyMixin { @Shadow @Final private Level level; @Shadow @Final private Direction pushDirection; + @Shadow private static boolean canStickToEachOther(BlockState blockState, BlockState blockState2) { return false; } + @Inject( method = "isSticky", cancellable = true, @@ -31,12 +34,14 @@ public class PistonStructureResolver_customStickyMixin { ) ) private static void isSticky(BlockState state, CallbackInfoReturnable cir) { - cir.setReturnValue(((BlockBehaviourInterface)state.getBlock()).isSticky(state)); + if(state.getBlock() instanceof BlockPistonBehaviourInterface behaviourInterface){ + cir.setReturnValue(behaviourInterface.isSticky(state)); + } } // fields that are needed because @Redirects cannot capture locals - private BlockPos pos_addBlockLine; - private BlockPos behindPos_addBlockLine; + @Unique private BlockPos pos_addBlockLine; + @Unique private BlockPos behindPos_addBlockLine; @Inject( method = "addBlockLine", @@ -60,12 +65,16 @@ public class PistonStructureResolver_customStickyMixin { ) ) private boolean onAddBlockLineCanStickToEachOther(BlockState state, BlockState behindState) { - return ((BlockBehaviourInterface)state.getBlock()).isStickyToNeighbor(level, pos_addBlockLine, state, behindPos_addBlockLine, behindState, pushDirection.getOpposite(), pushDirection); + if (state.getBlock() instanceof BlockPistonBehaviourInterface behaviourInterface) { + return behaviourInterface.isStickyToNeighbor(level, pos_addBlockLine, state, behindPos_addBlockLine, behindState, pushDirection.getOpposite(), pushDirection); + } + + return canStickToEachOther(state, behindState); } // fields that are needed because @Redirects cannot capture locals - private Direction dir_addBranchingBlocks; - private BlockPos neighborPos_addBranchingBlocks; + @Unique private Direction dir_addBranchingBlocks; + @Unique private BlockPos neighborPos_addBranchingBlocks; @Inject( method = "addBranchingBlocks", @@ -89,6 +98,10 @@ public class PistonStructureResolver_customStickyMixin { ) ) private boolean onAddBranchingBlocksCanStickToEachOther(BlockState neighborState, BlockState state, BlockPos pos) { - return ((BlockBehaviourInterface)state.getBlock()).isStickyToNeighbor(level, pos, state, neighborPos_addBranchingBlocks, neighborState, dir_addBranchingBlocks, pushDirection); + if (state.getBlock() instanceof BlockPistonBehaviourInterface behaviourInterface) { + return behaviourInterface.isStickyToNeighbor(level, pos, state, neighborPos_addBranchingBlocks, neighborState, dir_addBranchingBlocks, pushDirection); + } + + return canStickToEachOther(neighborState, state); } } diff --git a/src/main/java/carpet/mixins/SlimeBlock_customStickyMixin.java b/src/main/java/carpet/mixins/SlimeBlock_customStickyMixin.java deleted file mode 100644 index 38b35089..00000000 --- a/src/main/java/carpet/mixins/SlimeBlock_customStickyMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package carpet.mixins; - -import org.spongepowered.asm.mixin.Mixin; - -import carpet.fakes.BlockBehaviourInterface; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.SlimeBlock; -import net.minecraft.world.level.block.state.BlockState; - -@Mixin(SlimeBlock.class) -public class SlimeBlock_customStickyMixin implements BlockBehaviourInterface { - - @Override - public boolean isSticky(BlockState state) { - return true; - } - - @Override - public boolean isStickyToNeighbor(Level level, BlockPos pos, BlockState state, BlockPos neighborPos, BlockState neighborState, Direction dir, Direction moveDir) { - return !neighborState.is(Blocks.HONEY_BLOCK); - } -} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index 2594ed21..72dc6392 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -178,13 +178,11 @@ "SculkSensorBlockEntityVibrationConfig_sculkSensorRangeMixin", "CollectingNeighborUpdaterAccessor", - "BlockBehaviour_customStickyMixin", "BlockBehaviourBlockStateBase_mixin", "ChainBlock_customStickyMixin", "ChestBlock_customStickyMixin", - "HoneyBlock_customStickyMixin", - "PistonStructureResolver_customStickyMixin", - "SlimeBlock_customStickyMixin" + "PistonStructureResolver_customStickyMixin" + ], "client": [ "ClientLevel_tickSpeedMixin",