Show a bounding box around all the blocks that are going to be broken.

Also fixes some slight issues.
This commit is contained in:
modmuss50 2020-07-26 17:04:45 +01:00
parent b5707b144e
commit ec1ae17134
3 changed files with 57 additions and 7 deletions

View file

@ -38,6 +38,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import reborncore.common.misc.MultiBlockBreakingTool;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import team.reborn.energy.EnergyTier; import team.reborn.energy.EnergyTier;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
@ -47,9 +48,12 @@ import techreborn.utils.MessageIDs;
import techreborn.utils.ToolsUtil; import techreborn.utils.ToolsUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List; 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() { public AdvancedJackhammerItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost, MiningLevel.DIAMOND); super(ToolMaterials.DIAMOND, TechRebornConfig.advancedJackhammerCharge, EnergyTier.EXTREME, TechRebornConfig.advancedJackhammerCost, MiningLevel.DIAMOND);
@ -66,7 +70,7 @@ public class AdvancedJackhammerItem extends JackhammerItem {
// JackhammerItem // JackhammerItem
@Override @Override
public boolean postMine(ItemStack stack, World worldIn, BlockState stateIn, BlockPos pos, LivingEntity entityLiving) { 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); return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
} }
for (BlockPos additionalPos : ToolsUtil.getAOEMiningBlocks(worldIn, pos, entityLiving, 1)) { 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); return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
} }
@Override
public Set<BlockPos> 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 // Item
@Override @Override
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) { public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {

View file

@ -42,6 +42,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import reborncore.common.misc.MultiBlockBreakingTool;
import reborncore.common.util.ChatUtils; import reborncore.common.util.ChatUtils;
import reborncore.common.util.ItemUtils; import reborncore.common.util.ItemUtils;
import team.reborn.energy.Energy; import team.reborn.energy.Energy;
@ -53,9 +54,12 @@ import techreborn.utils.MessageIDs;
import techreborn.utils.ToolsUtil; import techreborn.utils.ToolsUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List; 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() { public IndustrialJackhammerItem() {
super(ToolMaterials.DIAMOND, TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost, MiningLevel.DIAMOND); super(ToolMaterials.DIAMOND, TechRebornConfig.industrialJackhammerCharge, EnergyTier.INSANE, TechRebornConfig.industrialJackhammerCost, MiningLevel.DIAMOND);
@ -98,7 +102,7 @@ public class IndustrialJackhammerItem extends JackhammerItem {
// JackhammerItem // JackhammerItem
@Override @Override
public boolean postMine(ItemStack stack, World worldIn, BlockState stateIn, BlockPos pos, LivingEntity entityLiving) { 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); return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
} }
int radius = isAOE5(stack) ? 2 : 1; int radius = isAOE5(stack) ? 2 : 1;
@ -111,6 +115,18 @@ public class IndustrialJackhammerItem extends JackhammerItem {
return super.postMine(stack, worldIn, stateIn, pos, entityLiving); return super.postMine(stack, worldIn, stateIn, pos, entityLiving);
} }
@Override
public Set<BlockPos> 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 // PickaxeItem
@Override @Override
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) { public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {

View file

@ -79,16 +79,35 @@ public class ToolsUtil {
* @return Set of BlockPos to process by tool block break logic * @return Set of BlockPos to process by tool block break logic
*/ */
public static Set<BlockPos> getAOEMiningBlocks(World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving, int radius) { public static Set<BlockPos> 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<BlockPos> getAOEMiningBlocks(World worldIn, BlockPos pos, @Nullable LivingEntity entityLiving, int radius, boolean placeDummyBlocks) {
if (!(entityLiving instanceof PlayerEntity)) { if (!(entityLiving instanceof PlayerEntity)) {
return ImmutableSet.of(); return ImmutableSet.of();
} }
Set<BlockPos> targetBlocks = new HashSet<>(); Set<BlockPos> targetBlocks = new HashSet<>();
PlayerEntity playerIn = (PlayerEntity) entityLiving; PlayerEntity playerIn = (PlayerEntity) entityLiving;
//Put a dirt block down to raytrace with to stop it raytracing past the intended block if (placeDummyBlocks) {
worldIn.setBlockState(pos, Blocks.DIRT.getDefaultState()); //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); 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)) { if (!(hitResult instanceof BlockHitResult)) {
return Collections.emptySet(); return Collections.emptySet();