Much better wood searching, should now handle large and complex trees well, closes #1680
This commit is contained in:
parent
76c81c9e90
commit
99d4350428
1 changed files with 35 additions and 7 deletions
|
@ -30,6 +30,7 @@ import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.NonNullList;
|
import net.minecraft.util.NonNullList;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -40,8 +41,14 @@ import reborncore.common.powerSystem.forge.ForgePowerItemManager;
|
||||||
import techreborn.config.ConfigTechReborn;
|
import techreborn.config.ConfigTechReborn;
|
||||||
import techreborn.init.ModItems;
|
import techreborn.init.ModItems;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ItemAdvancedChainsaw extends ItemChainsaw {
|
public class ItemAdvancedChainsaw extends ItemChainsaw {
|
||||||
|
|
||||||
|
//Done to search for blocks in this order
|
||||||
|
private static final EnumFacing[] SEARCH_ORDER = new EnumFacing[]{EnumFacing.NORTH, EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.WEST, EnumFacing.UP};
|
||||||
|
|
||||||
public ItemAdvancedChainsaw() {
|
public ItemAdvancedChainsaw() {
|
||||||
super(ToolMaterial.DIAMOND, "techreborn.advancedChainsaw", ConfigTechReborn.AdvancedChainsawCharge,
|
super(ToolMaterial.DIAMOND, "techreborn.advancedChainsaw", ConfigTechReborn.AdvancedChainsawCharge,
|
||||||
1.0F);
|
1.0F);
|
||||||
|
@ -66,16 +73,37 @@ public class ItemAdvancedChainsaw extends ItemChainsaw {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) {
|
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) {
|
||||||
for (int i = 1; i < 10; i++) {
|
List<BlockPos> wood = new ArrayList<>();
|
||||||
BlockPos nextPos = pos.up(i);
|
findWood(worldIn, pos, wood, new ArrayList<>());
|
||||||
IBlockState nextState = worldIn.getBlockState(nextPos);
|
wood.forEach(pos1 -> breakBlock(pos1, stack, worldIn, entityLiving, pos));
|
||||||
if(nextState.getBlock().isWood(worldIn, nextPos)){
|
|
||||||
breakBlock(nextPos, stack, worldIn, entityLiving, pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving);
|
return super.onBlockDestroyed(stack, worldIn, blockIn, pos, entityLiving);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findWood(World world, BlockPos pos, List<BlockPos> wood, List<BlockPos> leaves){
|
||||||
|
//Limit the amount of wood to be broken to 64 blocks.
|
||||||
|
if(wood.size() >= 64){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Search 150 leaves for wood
|
||||||
|
if(leaves.size() >= 150){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(EnumFacing facing : SEARCH_ORDER){
|
||||||
|
BlockPos checkPos = pos.offset(facing);
|
||||||
|
if(!wood.contains(checkPos) && !leaves.contains(checkPos)){
|
||||||
|
IBlockState state = world.getBlockState(checkPos);
|
||||||
|
if( state.getBlock().isWood(world, checkPos)){
|
||||||
|
wood.add(checkPos);
|
||||||
|
findWood(world, checkPos, wood, leaves);
|
||||||
|
} else if(state.getBlock().isLeaves(state, world, checkPos)){
|
||||||
|
leaves.add(checkPos);
|
||||||
|
findWood(world, checkPos, wood, leaves);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canHarvestBlock(IBlockState blockIn) {
|
public boolean canHarvestBlock(IBlockState blockIn) {
|
||||||
return Items.DIAMOND_AXE.canHarvestBlock(blockIn);
|
return Items.DIAMOND_AXE.canHarvestBlock(blockIn);
|
||||||
|
|
Loading…
Reference in a new issue