NaturesAura/src/main/java/de/ellpeck/naturesaura/items/tools/ItemAxe.java

71 lines
2.4 KiB
Java
Raw Normal View History

2018-10-19 18:32:20 +02:00
package de.ellpeck.naturesaura.items.tools;
2018-10-20 21:19:08 +02:00
import de.ellpeck.naturesaura.Helper;
2019-11-04 19:08:49 +01:00
import de.ellpeck.naturesaura.NaturesAura;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityWoodStand;
2020-01-29 00:40:28 +01:00
import de.ellpeck.naturesaura.data.ItemModelGenerator;
2018-10-20 00:54:33 +02:00
import de.ellpeck.naturesaura.items.ModItems;
2020-01-29 00:40:28 +01:00
import de.ellpeck.naturesaura.reg.ICustomItemModel;
2018-10-19 18:32:20 +02:00
import de.ellpeck.naturesaura.reg.IModItem;
2020-01-22 01:32:26 +01:00
import de.ellpeck.naturesaura.reg.ModRegistry;
2021-12-04 19:17:21 +01:00
import net.minecraft.core.BlockPos;
2021-12-04 15:40:09 +01:00
import net.minecraft.nbt.CompoundTag;
2020-09-22 03:17:02 +02:00
import net.minecraft.tags.BlockTags;
2021-12-04 19:17:21 +01:00
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
2018-10-20 21:19:08 +02:00
import net.minecraftforge.common.capabilities.ICapabilityProvider;
2018-10-19 18:32:20 +02:00
2018-10-20 21:19:08 +02:00
import javax.annotation.Nullable;
2020-01-29 00:40:28 +01:00
public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
2021-12-04 19:17:21 +01:00
2018-10-19 18:32:20 +02:00
private final String baseName;
2021-12-04 19:17:21 +01:00
public ItemAxe(String baseName, Tier material, float damage, float speed) {
super(material, damage, speed, new Properties().tab(NaturesAura.CREATIVE_TAB));
2018-10-19 18:32:20 +02:00
this.baseName = baseName;
2020-01-22 01:32:26 +01:00
ModRegistry.add(this);
2018-10-19 18:32:20 +02:00
}
@Override
public String getBaseName() {
return this.baseName;
}
2018-10-20 00:54:33 +02:00
@Override
2019-10-20 22:30:49 +02:00
public float getDestroySpeed(ItemStack stack, BlockState state) {
2020-05-13 17:57:31 +02:00
if (state.getMaterial() == Material.LEAVES) {
2021-12-04 19:17:21 +01:00
return this.speed;
2018-10-20 00:54:33 +02:00
} else {
return super.getDestroySpeed(stack, state);
}
}
2018-10-20 21:19:08 +02:00
2020-05-13 17:57:31 +02:00
@Override
2021-12-04 15:40:09 +01:00
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
2020-05-13 17:57:31 +02:00
if (itemstack.getItem() == ModItems.SKY_AXE) {
2022-03-04 15:59:04 +01:00
if (player.level.getBlockState(pos).is(BlockTags.LOGS)) {
2021-12-04 15:40:09 +01:00
BlockEntityWoodStand.recurseTreeDestruction(player.level, pos, pos, false, true);
2020-05-13 17:57:31 +02:00
return true;
}
}
return false;
}
2018-10-20 21:19:08 +02:00
@Nullable
@Override
2021-12-04 15:40:09 +01:00
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag nbt) {
2020-05-13 17:57:31 +02:00
return Helper.makeRechargeProvider(stack, true);
2018-10-20 21:19:08 +02:00
}
2020-01-29 00:40:28 +01:00
@Override
public void generateCustomItemModel(ItemModelGenerator generator) {
generator.withExistingParent(this.getBaseName(), "item/handheld").texture("layer0", "item/" + this.getBaseName());
}
2018-10-19 18:32:20 +02:00
}