62 lines
2.2 KiB
Java
62 lines
2.2 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.tags.ItemTags;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.network.chat.Component;
|
|
import java.util.List;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraft.world.level.block.DispenserBlock;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
public class ShieldItem extends Item {
|
|
public ShieldItem(final Properties a) {
|
|
super(a);
|
|
this.addProperty(new ResourceLocation("blocking"), (bek, bjt, akw) -> (akw != null && akw.isUsingItem() && akw.getUseItem() == bek) ? 1.0f : 0.0f);
|
|
DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
|
|
}
|
|
|
|
@Override
|
|
public String getDescriptionId(final ItemStack bek) {
|
|
if (bek.getTagElement("BlockEntityTag") != null) {
|
|
return this.getDescriptionId() + '.' + getColor(bek).getName();
|
|
}
|
|
return super.getDescriptionId(bek);
|
|
}
|
|
|
|
@Override
|
|
public void appendHoverText(final ItemStack bek, @Nullable final Level bjt, final List<Component> list, final TooltipFlag bft) {
|
|
BannerItem.appendHoverTextFromBannerBlockEntityTag(bek, list);
|
|
}
|
|
|
|
@Override
|
|
public UseAnim getUseAnimation(final ItemStack bek) {
|
|
return UseAnim.BLOCK;
|
|
}
|
|
|
|
@Override
|
|
public int getUseDuration(final ItemStack bek) {
|
|
return 72000;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
|
|
final ItemStack bek5 = ayg.getItemInHand(ajh);
|
|
ayg.startUsingItem(ajh);
|
|
return InteractionResultHolder.<ItemStack>consume(bek5);
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidRepairItem(final ItemStack bek1, final ItemStack bek2) {
|
|
return ItemTags.PLANKS.contains(bek2.getItem()) || super.isValidRepairItem(bek1, bek2);
|
|
}
|
|
|
|
public static DyeColor getColor(final ItemStack bek) {
|
|
return DyeColor.byId(bek.getOrCreateTagElement("BlockEntityTag").getInt("Base"));
|
|
}
|
|
}
|