superb-warfare/src/main/java/com/atsuishio/superbwarfare/item/Crowbar.java
2025-04-12 19:30:28 +08:00

82 lines
2.8 KiB
Java

package com.atsuishio.superbwarfare.item;
import com.atsuishio.superbwarfare.init.ModBlocks;
import com.atsuishio.superbwarfare.init.ModItems;
import net.minecraft.ChatFormatting;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.*;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.items.ItemHandlerHelper;
import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.List;
public class Crowbar extends SwordItem {
public static final Tier TIER = new Tier() {
public int getUses() {
return 400;
}
public float getSpeed() {
return 4f;
}
public float getAttackDamageBonus() {
return 3.5f;
}
@Override
public @NotNull TagKey<Block> getIncorrectBlocksForDrops() {
return BlockTags.INCORRECT_FOR_IRON_TOOL;
}
public int getLevel() {
return 1;
}
public int getEnchantmentValue() {
return 9;
}
public @NotNull Ingredient getRepairIngredient() {
return Ingredient.of(new ItemStack(Items.IRON_INGOT));
}
};
public Crowbar() {
super(TIER, new Properties().stacksTo(1).attributes(SwordItem.createAttributes(TIER, 2, -2f)));
}
@Override
public boolean isRepairable(@NotNull ItemStack itemstack) {
return true;
}
@Override
public @NotNull InteractionResult useOn(@NotNull UseOnContext context) {
super.useOn(context);
if ((context.getLevel().getBlockState(BlockPos.containing(context.getClickedPos().getX(), context.getClickedPos().getY(), context.getClickedPos().getZ()))).getBlock() == ModBlocks.JUMP_PAD.get()) {
context.getLevel().setBlock(BlockPos.containing(context.getClickedPos().getX(), context.getClickedPos().getY(), context.getClickedPos().getZ()), Blocks.AIR.defaultBlockState(), 3);
if (context.getPlayer() != null) {
ItemHandlerHelper.giveItemToPlayer(context.getPlayer(), new ItemStack(ModItems.JUMP_PAD.get()));
}
}
return InteractionResult.SUCCESS;
}
@Override
@ParametersAreNonnullByDefault
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
tooltipComponents.add(Component.translatable("des.superbwarfare.crowbar").withStyle(ChatFormatting.GRAY));
}
}