DrEinsteinium Posted November 9, 2013 Share Posted November 9, 2013 Hey everyone. I've been fiddling around with NBTTagCompounds lately and I can't quite decipher entirely how it works. I am currently making a pretty simple item that stores the number of entities killed and adds to the number every time a monster is killed by the player Here is my code. @ForgeSubscribe public void soulBagListener(LivingDeathEvent event) { if(event.source.getDamageType().equals("player") && event.entityLiving instanceof EntityMob) { EntityPlayer player = (EntityPlayer)event.source.getEntity(); String entityLivingName = event.entityLiving.getEntityName(); for(int i = 0; i < player.inventory.getSizeInventory(); i++) { if(player.inventory.getStackInSlot(i) != null) if(player.inventory.getStackInSlot(i).getItem() instanceof ItemSoulBag) { ItemStack item = player.inventory.getStackInSlot(i); NBTTagCompound nbt = item.getTagCompound(); if(nbt == null) item.setTagCompound(new NBTTagCompound()); if(!nbt.hasKey("tsouls")) nbt.setInteger("tsouls", 0); nbt.setInteger("tsouls", nbt.getInteger("tsouls") + 1); if(!nbt.hasKey("tsouls" + "-" + entityLivingName)) nbt.setInteger("tsouls" + "-" + entityLivingName, 0); nbt.setInteger("tsouls" + "-" + entityLivingName, nbt.getInteger("tsouls" + "-" + entityLivingName) + 1); return; } } } } Essentially, it loops through all of the inventory slots and finds the first SoulBagItem, then executing the code. The first part of the code adds +1 to the "total soul count" named "tsouls" which is displayed rather easily on the ItemStack's tooltip. That part is easy. The second part of the code adds a +1 to the "specific mob soul count" named "tsouls-" + entity name. This is what I am having trouble with, as I highly doubt this is how NBT tag compounds should work. I want to loop through the NBTTagCompound and add each entity specific counts to the tooltip as well, but I can't do that with my current system. Can anyone explain to me what I am doing wrong or critique my system? And also help me understand the differences between 1. NBTTagCompound 2. NBTTagList - specifically "subtag" 3. NBTBase And before I possibly get flamed, I have looked at a fairly decent tutorial on the MC forums, as well as the Forge wiki, but they don't explain everything. Thanks in advance, Dr. E. Quote Follow me on twitter! @keepablock Read up on whats new! www.catacombs.co http://electronic-chronic.com/assets/keep-a-block/wikilink/wikilink_logo.png[/img] Link to comment Share on other sites More sharing options...
Draco18s Posted November 9, 2013 Share Posted November 9, 2013 Look at NBTTagCompoundList (IIRC the class name correctly) Essentially it's a list of tags that you can add to a tag, then each one of the tags in the list can hold the mob name and the count. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
Recommended Posts
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.