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

@ -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;
//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();