ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/AllInOneTool.java

58 lines
1.9 KiB
Java
Raw Normal View History

2021-11-14 00:20:29 +01:00
package de.ellpeck.actuallyadditions.mod.items;
2024-03-02 21:23:08 +01:00
import de.ellpeck.actuallyadditions.api.ActuallyTags;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.enchantment.Enchantment;
2024-03-04 20:21:48 +01:00
import net.neoforged.neoforge.common.ToolAction;
import net.neoforged.neoforge.common.ToolActions;
2024-03-02 21:23:08 +01:00
public class AllInOneTool extends DiggerItem {
2024-03-02 21:23:08 +01:00
private final Tier tier;
public AllInOneTool(Tier tier) {
2021-11-14 00:20:29 +01:00
super(
4.0f,
-2f,
tier,
2024-03-02 21:23:08 +01:00
ActuallyTags.Blocks.MINEABLE_WITH_AIO,
2021-11-14 00:20:29 +01:00
new Properties()
.durability(tier.getUses() * 4)
2024-03-03 01:20:53 +01:00
2021-11-14 00:20:29 +01:00
);
this.tier = tier;
}
@Override
2024-03-02 21:23:08 +01:00
public boolean canPerformAction(ItemStack stack, ToolAction toolAction) {
if (toolAction == ToolActions.AXE_DIG || toolAction == ToolActions.HOE_DIG || toolAction == ToolActions.PICKAXE_DIG || toolAction == ToolActions.SHOVEL_DIG)
return true;
return super.canPerformAction(stack, toolAction);
}
@Override
public InteractionResult useOn(UseOnContext context) {
2021-11-14 00:20:29 +01:00
// How, no idea, possible, most likely :cry:
if (context.getPlayer() == null) {
2024-03-02 21:23:08 +01:00
return InteractionResult.FAIL;
2021-11-14 00:20:29 +01:00
}
// Player not sneaking? Act as a Hoe to the block, else, Act as a shovel
if (!context.getPlayer().isCrouching()) {
return Items.IRON_HOE.useOn(context);
}
return Items.IRON_SHOVEL.useOn(context);
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return super.canApplyAtEnchantingTable(stack, enchantment) || enchantment.category.canEnchant(Items.DIAMOND_SWORD);
}
}