package de.jottyfan.quickiemod.item; import java.util.List; import com.google.common.collect.Lists; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.LeavesBlock; import net.minecraft.item.AxeItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ToolMaterial; import net.minecraft.registry.tag.BlockTags; /** * * @author jotty * */ public abstract class ToolRangeableAxe extends AxeItem implements ToolRangeable { protected ToolRangeableAxe(ToolMaterial material, float attackDamage, float attackSpeed, Item.Settings settings) { super(material, attackDamage, attackSpeed, settings); } @Override public HarvestRange getRange(ItemStack stack) { // TODO: get the range from the stack return new HarvestRange(16, 32, 16); } /** * check if the block is a leaves block * * @param blockIn the block * @return true or false */ private boolean isLeavesBlock(BlockState blockIn) { boolean vanillaLeaves = blockIn.getBlock() instanceof LeavesBlock; boolean terrestriaLeaves = false; try { Class extendedLeavesBlock = Class.forName("com.terraformersmc.terraform.leaves.block.ExtendedLeavesBlock"); terrestriaLeaves = extendedLeavesBlock.isInstance(blockIn.getBlock()); } catch (ClassNotFoundException e) { // no terrestria mod available, so ignore this // using this approach instead of the instanceof functionality, we don't need to refer to terrestria // and omit a crash on installations that do not have or want terrestria available } boolean blockTagLeaves = blockIn.isIn(BlockTags.LEAVES); return vanillaLeaves || terrestriaLeaves || blockTagLeaves; } @Override public boolean canBreakNeighbors(BlockState blockIn) { return new ItemStack(this).isSuitableFor(blockIn) || isLeavesBlock(blockIn) || blockIn.isIn(BlockTags.LOGS); } @Override public List getBlockList(Block block) { return Lists.newArrayList(block); } }