diff --git a/src/main/java/techreborn/items/tool/advanced/AdvancedJackhammerItem.java b/src/main/java/techreborn/items/tool/advanced/AdvancedJackhammerItem.java index 31aab9f1e..0ccf29a36 100644 --- a/src/main/java/techreborn/items/tool/advanced/AdvancedJackhammerItem.java +++ b/src/main/java/techreborn/items/tool/advanced/AdvancedJackhammerItem.java @@ -38,6 +38,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import reborncore.common.misc.MultiBlockBreakingTool; import reborncore.common.util.ItemUtils; import team.reborn.energy.EnergyTier; import techreborn.config.TechRebornConfig; @@ -47,9 +48,12 @@ import techreborn.utils.MessageIDs; import techreborn.utils.ToolsUtil; import javax.annotation.Nullable; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; -public class AdvancedJackhammerItem extends JackhammerItem { +public class AdvancedJackhammerItem extends JackhammerItem implements MultiBlockBreakingTool { public AdvancedJackhammerItem() { super(ToolMaterials.DIAMOND, TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost, MiningLevel.DIAMOND); @@ -66,7 +70,7 @@ public class AdvancedJackhammerItem extends JackhammerItem { // JackhammerItem @Override public boolean postMine(ItemStack stack, World worldIn, BlockState stateIn, BlockPos pos, LivingEntity entityLiving) { - if (!ItemUtils.isActive(stack)) { + if (!ItemUtils.isActive(stack) || !stack.getItem().isEffectiveOn(stateIn)) { return super.postMine(stack, worldIn, stateIn, pos, entityLiving); } for (BlockPos additionalPos : ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, 1)) { @@ -78,6 +82,17 @@ public class AdvancedJackhammerItem extends JackhammerItem { return super.postMine(stack, worldIn, stateIn, pos, entityLiving); } + @Override + public Set getBlocksToBreak(ItemStack stack, World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving) { + if (!stack.getItem().isEffectiveOn(worldIn.getBlockState(pos))) { + return Collections.emptySet(); + } + return ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, 1, false) + .stream() + .filter((blockPos -> shouldBreak(worldIn, pos, blockPos, stack))) + .collect(Collectors.toSet()); + } + // Item @Override public TypedActionResult use(final World world, final PlayerEntity player, final Hand hand) { diff --git a/src/main/java/techreborn/items/tool/industrial/IndustrialJackhammerItem.java b/src/main/java/techreborn/items/tool/industrial/IndustrialJackhammerItem.java index 434fe5405..f61c8c4d1 100644 --- a/src/main/java/techreborn/items/tool/industrial/IndustrialJackhammerItem.java +++ b/src/main/java/techreborn/items/tool/industrial/IndustrialJackhammerItem.java @@ -42,6 +42,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import reborncore.common.misc.MultiBlockBreakingTool; import reborncore.common.util.ChatUtils; import reborncore.common.util.ItemUtils; import team.reborn.energy.Energy; @@ -53,9 +54,12 @@ import techreborn.utils.MessageIDs; import techreborn.utils.ToolsUtil; import javax.annotation.Nullable; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; -public class IndustrialJackhammerItem extends JackhammerItem { +public class IndustrialJackhammerItem extends JackhammerItem implements MultiBlockBreakingTool { public IndustrialJackhammerItem() { super(ToolMaterials.DIAMOND, TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost, MiningLevel.DIAMOND); @@ -98,7 +102,7 @@ public class IndustrialJackhammerItem extends JackhammerItem { // JackhammerItem @Override public boolean postMine(ItemStack stack, World worldIn, BlockState stateIn, BlockPos pos, LivingEntity entityLiving) { - if (!ItemUtils.isActive(stack)) { + if (!ItemUtils.isActive(stack) || !stack.getItem().isEffectiveOn(stateIn)) { return super.postMine(stack, worldIn, stateIn, pos, entityLiving); } int radius = isAOE5(stack) ? 2 : 1; @@ -111,6 +115,18 @@ public class IndustrialJackhammerItem extends JackhammerItem { return super.postMine(stack, worldIn, stateIn, pos, entityLiving); } + @Override + public Set getBlocksToBreak(ItemStack stack, World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving) { + if (!stack.getItem().isEffectiveOn(worldIn.getBlockState(pos))) { + return Collections.emptySet(); + } + int radius = isAOE5(stack) ? 2 : 1; + return ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, radius, false) + .stream() + .filter((blockPos -> shouldBreak(worldIn, pos, blockPos, stack))) + .collect(Collectors.toSet()); + } + // PickaxeItem @Override public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) { diff --git a/src/main/java/techreborn/utils/ToolsUtil.java b/src/main/java/techreborn/utils/ToolsUtil.java index 99670aa5b..4f5557abc 100644 --- a/src/main/java/techreborn/utils/ToolsUtil.java +++ b/src/main/java/techreborn/utils/ToolsUtil.java @@ -79,16 +79,35 @@ public class ToolsUtil { * @return Set of BlockPos to process by tool block break logic */ public static Set getAOEMiningBlocks(World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving, int radius) { + return getAOEMiningBlocks(worldIn, pos, entityLiving, radius, true); + } + + /** + * Fills in set of BlockPos which should be broken by AOE mining + * + * @param worldIn World reference + * @param pos BlockPos Position of originally broken block + * @param entityLiving LivingEntity Player who broke block + * @param radius int Radius of additional blocks to include. E.g. for 3x3 mining radius will be 1 + * @return Set of BlockPos to process by tool block break logic + */ + public static Set getAOEMiningBlocks(World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving, int radius, boolean placeDummyBlocks) { if (!(entityLiving instanceof PlayerEntity)) { return ImmutableSet.of(); } Set targetBlocks = new HashSet<>(); PlayerEntity playerIn = (PlayerEntity) entityLiving; - //Put a dirt block down to raytrace with to stop it raytracing past the intended block - worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState()); + if (placeDummyBlocks) { + //Put a dirt block down to raytrace with to stop it raytracing past the intended block + worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState()); + } + HitResult hitResult = playerIn.rayTrace(20D, 0F, false); - worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); + + if (placeDummyBlocks) { + worldIn.setBlockState(pos, Blocks.AIR.getDefaultState()); + } if (!(hitResult instanceof BlockHitResult)) { return Collections.emptySet();