Jump to content

NBT Tag Help


Babelincoln1809

Recommended Posts

3 hours ago, Babelincoln1809 said:

Anyone know where a guide for NBT Tags are for 1.14? Some videos are a bit outdated and stuff.

NBT tags for what, items, entities? Be more specific.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

Quick guide on NBT: (note: using 1.15, but all is the same for 1.14)


NBT (Named Binary Tag) is the format used by Minecraft mostly for keeping internal data, such as player data, world data, etc.

NBT has different tags, which define what type of data they store. All tags implement INBT.

  • Compound tags holds a combination of other tags, which can all be the same or different type. Represented by CompoundNBT.
  • Number tags holds different types of number, corresponding to Java number primitives. All number tags extend NumberNBT.
    • byte = ByteNBT, short = ShortNBT, int = IntNBT, float = FloatNBT, long = LongNBT, double = DoubleNBT
  • String tags hold a string, corresponding to String. Represented by StringNBT.
  • Array or collection tags holds either 0+ tags of the same type, depending on what the tag allows. All array tags extend CollectionNBT.
    • List tags may hold any amount of one type of tags. Represented by ListNBT.
    • Number-specific array tags: byte[] = ByteArrayNBT, int[] = IntArrayNBT, long[] = LongArrayNBT.
  • End tags are special. They have no representation in-game; they represent an end of an array or compound tag when stored. Represented by EndNBT.

Classes are in net.minecraft.nbt. CompressedStreamTools for reading and writing NBT to files. NBTUtil for reading/writing GameProfile, UUID, BlockPos, BlockState. JsonToNBT for converting JSON to NBT.

See the Minecraft wiki page on NBT for the technical details.

Edited by sciwhiz12
Added source to MC Wiki
Link to comment
Share on other sites

Items by themselves don't hold NBT data, but ItemStacks do.

{ Item: "minecraft:stone", Count:1b, tag: { "CustomData": 3s, "display": { "Name": "rock" } } }

The ItemStack's NBT tag is stored in the tag tag, which is accessible through #getTag. CustomData and display are child tags, which can either be retrieved through #getTag().getX methods (getBoolean, getCompound, getShort, etc.) or, for Compound tags, the #getChildTag(String) (getChildTag("display"), but not for "CustomData")

#getTag and #getChildTag may return null, if no such tag exists. Check #hasTag() for the existence of the tag, and null checks for child tags.

Writing data to the tag? Better use #getOrCreateTag() and #getOrCreateChildTag(String); they create the tags, if they don't exist yet.

Directly setting the tags of an ItemStack? Use #setTag(CompoundTag) for the tag tag, and #setTagInfo(String, INBT) for any type of child tags.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ensure your system is running the latest version of Java. Sodium requires Java 17 or later for newer Minecraft versions (like 1.17+). 
    • Hi I wanted to my custom mob to hold any sword item, but didn’t rendered properly.   In entity class, make entity hold items as below: @Override public InteractionResult mobInteract(Player pPlayer, InteractionHand pHand) { //… ItemStack itemstack = pPlayer.getItemInHand(pHand); if (this.isTame()) { if ( (itemstack.is(Items.MELON_SLICE) || itemstack.is(Items.HONEY_BOTTLE)) && this.getHealth() < this.getMaxHealth() ) { //… } /* Handle holding sword */ else if (itemstack.getItem() instanceof SwordItem) { pPlayer.displayClientMessage(Component.literal("Clicked with item: " + itemstack.getDisplayName().getString()).withStyle(ChatFormatting.GOLD), true); //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds item //this.setItemInHand(InteractionHand.MAIN_HAND, itemstack); this.setItemSlot(EquipmentSlot.MAINHAND, itemstack.copy()); //Give copy of itemstack //If player is not in creative mode. From mobInteract() in wolf. if (!pPlayer.getAbilities().instabuild) { //Decrement sword count in hand pPlayer.getItemInHand(pHand).shrink(1); } return InteractionResult.SUCCESS; } else { //If player is sneaking pPlayer.displayClientMessage(getItemInHand(InteractionHand.MAIN_HAND).getDisplayName(), false); if (pPlayer.isShiftKeyDown()) { //Return sword //pPlayer.getInventory().add(this.getItemInHand(InteractionHand.MAIN_HAND)); pPlayer.getInventory().add(this.getItemBySlot(EquipmentSlot.MAINHAND)); //The entity holds nothing this.setItemInHand(InteractionHand.MAIN_HAND, ItemStack.EMPTY); return InteractionResult.SUCCESS; } else { //… } } else { return interactionresult; } }   And in render class, render the item as below: @Override public void render(RanaEntity pEntity, float pEntityYaw, float pPartialTicks, PoseStack pMatrixStack, MultiBufferSource pBuffer, int pPackedLight) { if(pEntity.isBaby()) { pMatrixStack.scale(0.5f, 0.5f, 0.5f); } model.setupAnim(pEntity, 0, 0, 0, pEntityYaw, 0); // //Get location and rotation of arm bone ModelPart rightArm = model.rightArm(); //Get right arm //Get location and rotation of item according to arm bone pMatrixStack.pushPose(); pMatrixStack.translate(rightArm.x, rightArm.y, rightArm.z); //Move to bone location pMatrixStack.mulPose(Axis.XP.rotationDegrees(rightArm.xRot)); //Rotate X pMatrixStack.mulPose(Axis.YP.rotationDegrees(rightArm.yRot)); //Rotate Y pMatrixStack.mulPose(Axis.ZP.rotationDegrees(rightArm.zRot)); //Rotate Z //Draw item //ItemStack itemStack = pEntity.getItemInHand(InteractionHand.MAIN_HAND); ItemStack itemStack = pEntity.getItemBySlot(EquipmentSlot.MAINHAND); if (!itemStack.isEmpty()) { //Offset pMatrixStack.translate(0.0, 0.0, 0.1); // Render the item //Minecraft.getInstance().getItemRenderer().renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); //itemRenderer.renderStatic(itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, pPackedLight, OverlayTexture.NO_OVERLAY, pMatrixStack, pBuffer, pEntity.level(), pEntity.getId()); itemInHandRenderer.renderItem(pEntity, itemStack, ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, false, pMatrixStack, pBuffer, pEntity.getId()); } pMatrixStack.popPose(); super.render(pEntity, pEntityYaw, pPartialTicks, pMatrixStack, pBuffer, pPackedLight); }   I confirmed the entity can properly hold item(logically) but the item which the entity holds is not rendered at all.   Full code: https://github.com/sakiiiiika/ranamod   Thanks.
    • It is Immersive Melodies
    • MINECRAFT JAVA wht is ic_im it shows up yellow heres the modpack https://rocktheslayer.wixsite.com/my-site-7 also It wouldnt Let me submit a bug report only a suggestion for this post
  • Topics

×
×
  • Create New...

Important Information

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