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;
|
2021-11-14 00:20:29 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.IActuallyItem;
|
2024-03-02 21:23:08 +01:00
|
|
|
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;
|
|
|
|
import net.minecraftforge.common.ToolAction;
|
|
|
|
import net.minecraftforge.common.ToolActions;
|
|
|
|
|
|
|
|
public class AllInOneTool extends DiggerItem implements IActuallyItem {
|
|
|
|
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)
|
|
|
|
.tab(ActuallyAdditions.GROUP)
|
|
|
|
);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|