From e9a17eb2f8b22cfca8d6140f049f00db3d9114a2 Mon Sep 17 00:00:00 2001 From: attackeight Date: Tue, 7 May 2024 20:25:30 -0400 Subject: [PATCH 1/2] Guard against chunk protections --- build.gradle | 4 ++++ .../simibubi/create/content/equipment/wrench/IWrenchable.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a203b1be0..99a6f1965 100644 --- a/build.gradle +++ b/build.gradle @@ -206,6 +206,10 @@ dependencies { // runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge") //runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924") //runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212") + // implementation fg.deobf("curse.maven:ftb-chunks-forge-314906:4494633") + // implementation fg.deobf("curse.maven:architectury-api-419699:4521465") + // implementation fg.deobf("curse.maven:ftb-library-forge-404465:4396792") + // implementation fg.deobf("curse.maven:ftb-teams-forge-404468:4579981") // https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497 // Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings diff --git a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java index 73e61afc2..1e7286060 100644 --- a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java @@ -55,13 +55,14 @@ public interface IWrenchable { BlockPos pos = context.getClickedPos(); Player player = context.getPlayer(); if (world instanceof ServerLevel) { + if (!world.destroyBlock(pos, false)) + return InteractionResult.PASS; if (player != null && !player.isCreative()) Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) .forEach(itemStack -> { player.getInventory().placeItemBackInInventory(itemStack); }); state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY); - world.destroyBlock(pos, false); playRemoveSound(world, pos); } return InteractionResult.SUCCESS; From 4e51df3f8109953bf479a655745b317087445cb1 Mon Sep 17 00:00:00 2001 From: attackeight Date: Tue, 7 May 2024 20:25:30 -0400 Subject: [PATCH 2/2] Guard against chunk protections --- build.gradle | 4 ++++ .../content/equipment/wrench/IWrenchable.java | 23 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index a203b1be0..99a6f1965 100644 --- a/build.gradle +++ b/build.gradle @@ -206,6 +206,10 @@ dependencies { // runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge") //runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924") //runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212") + // implementation fg.deobf("curse.maven:ftb-chunks-forge-314906:4494633") + // implementation fg.deobf("curse.maven:architectury-api-419699:4521465") + // implementation fg.deobf("curse.maven:ftb-library-forge-404465:4396792") + // implementation fg.deobf("curse.maven:ftb-teams-forge-404468:4579981") // https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497 // Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings diff --git a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java index 73e61afc2..232a9dd5e 100644 --- a/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java +++ b/src/main/java/com/simibubi/create/content/equipment/wrench/IWrenchable.java @@ -22,6 +22,8 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.BlockEvent; public interface IWrenchable { @@ -55,14 +57,19 @@ public interface IWrenchable { BlockPos pos = context.getClickedPos(); Player player = context.getPlayer(); if (world instanceof ServerLevel) { - if (player != null && !player.isCreative()) - Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) - .forEach(itemStack -> { - player.getInventory().placeItemBackInInventory(itemStack); - }); - state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY); - world.destroyBlock(pos, false); - playRemoveSound(world, pos); + BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, pos, world.getBlockState(pos), player); + MinecraftForge.EVENT_BUS.post(event); + if (!event.isCanceled()) { + if (player != null && !player.isCreative()) { + Block.getDrops(state, (ServerLevel) world, pos, world.getBlockEntity(pos), player, context.getItemInHand()) + .forEach(itemStack -> { + player.getInventory().placeItemBackInInventory(itemStack); + }); + } + state.spawnAfterBreak((ServerLevel) world, pos, ItemStack.EMPTY); + world.destroyBlock(pos, false); + playRemoveSound(world, pos); + } } return InteractionResult.SUCCESS; }