61 lines
2 KiB
Java
61 lines
2 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import java.util.List;
|
|
import net.minecraft.core.component.DataComponents;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.tags.ItemTags;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.entity.EquipmentSlot;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.DispenserBlock;
|
|
|
|
public class ShieldItem extends Item implements Equipable {
|
|
public static final int EFFECTIVE_BLOCK_DELAY = 5;
|
|
public static final float MINIMUM_DURABILITY_DAMAGE = 3.0F;
|
|
|
|
public ShieldItem(Item.Properties properties) {
|
|
super(properties);
|
|
DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
|
|
}
|
|
|
|
@Override
|
|
public String getDescriptionId(ItemStack stack) {
|
|
DyeColor dyeColor = stack.get(DataComponents.BASE_COLOR);
|
|
return dyeColor != null ? this.getDescriptionId() + "." + dyeColor.getName() : super.getDescriptionId(stack);
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
|
BannerItem.appendHoverTextFromBannerBlockEntityTag(stack, tooltipComponents);
|
|
}
|
|
|
|
@Override
|
|
public UseAnim getUseAnimation(ItemStack stack) {
|
|
return UseAnim.BLOCK;
|
|
}
|
|
|
|
@Override
|
|
public int getUseDuration(ItemStack stack, LivingEntity entity) {
|
|
return 72000;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
|
|
ItemStack itemStack = player.getItemInHand(usedHand);
|
|
player.startUsingItem(usedHand);
|
|
return InteractionResultHolder.consume(itemStack);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidRepairItem(ItemStack stack, ItemStack repairCandidate) {
|
|
return repairCandidate.is(ItemTags.PLANKS) || super.isValidRepairItem(stack, repairCandidate);
|
|
}
|
|
|
|
@Override
|
|
public EquipmentSlot getEquipmentSlot() {
|
|
return EquipmentSlot.OFFHAND;
|
|
}
|
|
}
|