Jump to content

Zkera

Members
  • Posts

    1
  • Joined

  • Last visited

Zkera's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Hello, I'm trying to make my first mod. Now I'm trying to make an item that would save the type of animal that I right-clicked on with the item and display it in the lore of the item. I thought that this should be implemented through NBT tags and started looking at methods. In all the guides that I looked at and in the mods from GitHub, the setTag method was used to install new tags, but my IDE highlights this method in red, and when assembling, it gives an error. Same with hasTag and getOrCreateTag(). I use VS Code, 47.3.1 forge version, tried to update to 47.3.5. Sorry for bad English, I use Google translator. package net.zkera.genetic_horror.Item.Custom; import java.util.List; import javax.annotation.Nullable; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.level.Level; import net.zkera.genetic_horror.Item.ModItems; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.nbt.CompoundTag; public class SyringeItem extends Item { public SyringeItem(Properties pProperties) { super(pProperties); } private EntityType<?> storedGen = null; public static final EntityType[] permitteGenes = {EntityType.COW, EntityType.SQUID}; private static final String NBT_KEY_FOR_GEN = "Gen"; @Override public InteractionResult interactLivingEntity(ItemStack pStack, Player pPlayer, LivingEntity Target, InteractionHand pUsedHand) { if (CanFillSyringe(Target.getType())) { storedGen = Target.getType(); CompoundTag sharedGenTag = pStack.getOrCreateTag(); sharedGenTag.putString(NBT_KEY_FOR_GEN, storedGen.toString()); pStack.setTag(sharedGenTag); } return InteractionResult.SUCCESS; } @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if (pPlayer.getItemInHand(InteractionHand.OFF_HAND).getItem() == ModItems.FLASK.get()) { ItemStack toHand = new ItemStack(ModItems.PIECE.get(), 1); pPlayer.setItemInHand(InteractionHand.MAIN_HAND, toHand); pPlayer.setItemInHand(InteractionHand.OFF_HAND, ItemStack.EMPTY); } return InteractionResultHolder.success(pPlayer.getItemInHand(pUsedHand)); } @Override public void appendHoverText(ItemStack pStack, @Nullable Level p_41422_, List<Component> pTooltipComponents, TooltipFlag pTooltipFlag) { super.appendHoverText(pStack, p_41422_, pTooltipComponents, pTooltipFlag); if (pStack.hasTag()) { String sharedGenString = "item.genetic_horror.syringe.tooltip." + pStack.getTag().getString(NBT_KEY_FOR_GEN); sharedGenString = sharedGenString.replace("entity.minecraft.", ""); pTooltipComponents.add(Component.translatable(sharedGenString)); } } private boolean CanFillSyringe(EntityType<?> type) { if (storedGen != null) return false; for (var i : permitteGenes) { if (type == i) return true; } return false; } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.