Show a bounding box around all the blocks that are going to be broken.
Also fixes some slight issues.
This commit is contained in:
parent
b5707b144e
commit
ec1ae17134
3 changed files with 57 additions and 7 deletions
|
@ -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<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
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(final World world, final PlayerEntity player, final Hand hand) {
|
||||
|
|
|
@ -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<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
|
||||
@Override
|
||||
public float getMiningSpeedMultiplier(ItemStack stack, BlockState state) {
|
||||
|
|
|
@ -79,16 +79,35 @@ public class ToolsUtil {
|
|||
* @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) {
|
||||
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)) {
|
||||
return ImmutableSet.of();
|
||||
}
|
||||
Set<BlockPos> targetBlocks = new HashSet<>();
|
||||
PlayerEntity playerIn = (PlayerEntity) entityLiving;
|
||||
|
||||
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);
|
||||
|
||||
if (placeDummyBlocks) {
|
||||
worldIn.setBlockState(pos, Blocks.AIR.getDefaultState());
|
||||
}
|
||||
|
||||
if (!(hitResult instanceof BlockHitResult)) {
|
||||
return Collections.emptySet();
|
||||
|
|
Loading…
Reference in a new issue