package de.ellpeck.naturesaura.items.tools; import de.ellpeck.naturesaura.Helper; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.blocks.tiles.TileEntityWoodStand; import de.ellpeck.naturesaura.data.ItemModelGenerator; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.reg.ICustomItemModel; import de.ellpeck.naturesaura.reg.IModItem; import de.ellpeck.naturesaura.reg.ModRegistry; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.AxeItem; import net.minecraft.item.IItemTier; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tags.BlockTags; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.capabilities.ICapabilityProvider; import javax.annotation.Nullable; public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel { private final String baseName; public ItemAxe(String baseName, IItemTier material, float damage, float speed) { super(material, damage, speed, new Properties().group(NaturesAura.CREATIVE_TAB)); this.baseName = baseName; ModRegistry.add(this); } @Override public String getBaseName() { return this.baseName; } @Override public float getDestroySpeed(ItemStack stack, BlockState state) { if (state.getMaterial() == Material.LEAVES) { return this.efficiency; } else { return super.getDestroySpeed(stack, state); } } @Override public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, PlayerEntity player) { if (itemstack.getItem() == ModItems.SKY_AXE) { if (player.world.getBlockState(pos).getBlock().getTags().contains(BlockTags.LOGS.getName())) { TileEntityWoodStand.recurseTreeDestruction(player.world, pos, pos, false, true); return true; } } return false; } @Nullable @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return Helper.makeRechargeProvider(stack, true); } @Override public void generateCustomItemModel(ItemModelGenerator generator) { generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName()); } }