Fixed the chainsaw bug (#2943)
* Fixed the chainsaw bug * Fixed bugged solution, works now, tested :)
This commit is contained in:
parent
e4f56abdaa
commit
71b438acca
1 changed files with 24 additions and 3 deletions
|
@ -50,15 +50,30 @@ import techreborn.utils.ToolsUtil;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class IndustrialChainsawItem extends ChainsawItem {
|
||||
|
||||
private static final Direction[] SEARCH_ORDER = new Direction[]{Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP};
|
||||
|
||||
private BlockState lastCheckedBlockState;
|
||||
|
||||
public IndustrialChainsawItem() {
|
||||
super(TRToolMaterials.INDUSTRIAL_CHAINSAW, TechRebornConfig.industrialChainsawCharge, RcEnergyTier.EXTREME, TechRebornConfig.industrialChainsawCost, 20F, 1.0F, Items.DIAMOND_AXE);
|
||||
}
|
||||
|
||||
private boolean isValidLog(BlockState state) {
|
||||
return state.isIn(BlockTags.LOGS);
|
||||
}
|
||||
|
||||
private boolean isValidLeaves(BlockState state) {
|
||||
return state.isIn(BlockTags.LEAVES) || state.isIn(BlockTags.WART_BLOCKS) || state.isOf(Blocks.SHROOMLIGHT);
|
||||
}
|
||||
|
||||
private boolean isValidStartBlock(BlockState state) {
|
||||
return isValidLog(state) || isValidLeaves(state);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -73,10 +88,10 @@ public class IndustrialChainsawItem extends ChainsawItem {
|
|||
if (!wood.contains(checkPos) && !leaves.contains(checkPos)) {
|
||||
BlockState state = world.getBlockState(checkPos);
|
||||
|
||||
if (state.isIn(BlockTags.LOGS)) {
|
||||
if (isValidLog(state)) {
|
||||
wood.add(checkPos);
|
||||
findWood(world, checkPos, wood, leaves);
|
||||
} else if (state.isIn(BlockTags.LEAVES) || state.isIn(BlockTags.WART_BLOCKS) || state.isOf(Blocks.SHROOMLIGHT)) {
|
||||
} else if (isValidLeaves(state)) {
|
||||
leaves.add(checkPos);
|
||||
findWood(world, checkPos, wood, leaves);
|
||||
}
|
||||
|
@ -84,12 +99,18 @@ public class IndustrialChainsawItem extends ChainsawItem {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMine(BlockState state, World world, BlockPos pos, PlayerEntity miner) {
|
||||
lastCheckedBlockState = state;
|
||||
return super.canMine(state, world, pos, miner);
|
||||
}
|
||||
|
||||
//ChainsawItem
|
||||
@Override
|
||||
public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) {
|
||||
List<BlockPos> wood = new ArrayList<>();
|
||||
List<BlockPos> leaves = new ArrayList<>();
|
||||
if (ItemUtils.isActive(stack)) {
|
||||
if (ItemUtils.isActive(stack) && (lastCheckedBlockState == null || isValidStartBlock(lastCheckedBlockState))) {
|
||||
findWood(worldIn, pos, wood, leaves);
|
||||
wood.remove(pos);
|
||||
wood.stream()
|
||||
|
|
Loading…
Reference in a new issue