From f3b6a684f929c713c3d4e5c50a23d711bbd2a5ec Mon Sep 17 00:00:00 2001 From: s0127943 Date: Sun, 7 Feb 2021 01:01:48 +0100 Subject: [PATCH 1/2] Added check to see if a user is allowed to place blocks in the given position to counteract issues with FTBChunks --- .../zapper/blockzapper/BlockzapperItem.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java index 21d555b6b..c4f6d1d07 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java @@ -109,7 +109,7 @@ public class BlockzapperItem extends ZapperItem { continue; if (!selectedState.isValidPosition(world, placed)) continue; - if (!player.isCreative() && !canBreak(stack, world.getBlockState(placed), world, placed)) + if (!player.isCreative() && !canBreak(stack, world.getBlockState(placed), world, placed,player)) continue; if (!player.isCreative() && BlockHelper.findAndRemoveInInventory(selectedState, player, 1) == 0) { player.getCooldownTracker() @@ -278,10 +278,13 @@ public class BlockzapperItem extends ZapperItem { return list; } - public static boolean canBreak(ItemStack stack, BlockState state, World world, BlockPos pos) { + public static boolean canBreak(ItemStack stack, BlockState state, World world, BlockPos pos,PlayerEntity player) { ComponentTier tier = getTier(Components.Body, stack); float blockHardness = state.getBlockHardness(world, pos); - + //If we can't change the block (e.g chunk protection) + if (!isAllowedToPlace(world,pos,player)){ + return false; + } if (blockHardness == -1) return false; if (tier == ComponentTier.None) @@ -294,6 +297,15 @@ public class BlockzapperItem extends ZapperItem { return false; } + public static boolean isAllowedToPlace(World world, BlockPos pos,PlayerEntity player){ + BlockSnapshot blocksnapshot = BlockSnapshot.getBlockSnapshot(world, pos); + if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) { + blocksnapshot.restore(true, false); + return false; + } + return true; + } + public static int getMaxAoe(ItemStack stack) { ComponentTier tier = getTier(Components.Amplifier, stack); if (tier == ComponentTier.None) From d8054775d5cb28db9bfe2f92512d2deb985a5c74 Mon Sep 17 00:00:00 2001 From: s0127943 Date: Sun, 7 Feb 2021 01:03:53 +0100 Subject: [PATCH 2/2] Removed unnecessary blocksnapshot.restore --- .../content/curiosities/zapper/blockzapper/BlockzapperItem.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java index c4f6d1d07..416a7c597 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/blockzapper/BlockzapperItem.java @@ -300,7 +300,6 @@ public class BlockzapperItem extends ZapperItem { public static boolean isAllowedToPlace(World world, BlockPos pos,PlayerEntity player){ BlockSnapshot blocksnapshot = BlockSnapshot.getBlockSnapshot(world, pos); if (ForgeEventFactory.onBlockPlace(player, blocksnapshot, Direction.UP)) { - blocksnapshot.restore(true, false); return false; } return true;