Jump to content

[1.7.10] Reading all data from NBT on Entities


American2050

Recommended Posts

Hi guys, I'm not familiar with NBT Data at all.

 

What I need is to get all the Data stored on Entities when they die.

 

What I'm trying to achieve is to identify when an specific mob dies. So for example, for a Wither I have something like.

 

public static final Class NETHER_BOSS = (Class) EntityList.stringToClassMapping.get("WitherBoss");

event.entityLiving.getClass().equals(EventHandler.NETHER_BOSS)

 

Back to the NBT problem, how can I get all the NBT data stored on the entities?

 

And also, would it be posible somehow to "Dump" into the console or a file (Kinda like NEI does the Data Dumps for items or blocks in game) but for all the entities with their registered string names? So that way I can use the EntityList.stringToClassMapping.get

 

Thanks a lot, hope I'm not confusing to much with what I'm trying to do ;)

Link to comment
Share on other sites

1) When entity dies:

LivingDeathEvent

2) Save all data to nbt:

entity.writeToNbt(nbtTag)

This will save all information about this entity to this NBTTagCompound

3) Save:

Save how? Where? When?

4) Load:

EntityList.createFromNbt(nbtTag)

This will return you your entity filled with data found in this nbtTag.

Link to comment
Share on other sites

1) When entity dies:

LivingDeathEvent

2) Save all data to nbt:

entity.writeToNbt(nbtTag)

This will save all information about this entity to this NBTTagCompound

3) Save:

Save how? Where? When?

4) Load:

EntityList.createFromNbt(nbtTag)

This will return you your entity filled with data found in this nbtTag.

 

I am confuse. I don't need to write to the NBT, I just need to know everything that the entity that died had on his NBT

So I have "public void onLivingDeath(LivingDeathEvent event)"

 

and when I do event.entityLiving I can see there is event.entityLiving.readFromNBT() but I don't know how to use it

 

 

Link to comment
Share on other sites

Entities don't have NBT.  NBT is their compressed save file format.

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

Entities don't have NBT.  NBT is their compressed save file format.

I was told by the developer of the Mod of the entity I'm trying to identify that:

 

To make/check it being Umber you need to use the "Subspecies" NBT tag which is an int, 0 = Normal, 1-2 = Azure/Scarlet and 3 = Umber

 

But I never worked with NBT Tags, so I'm not sure how to get that info on the LivingDeathEvent.

Link to comment
Share on other sites

Entity#getEntityData() returns the entity's custom NBT tag data; if the modder is being nice, he/she either used this custom tag or IExtendedEntityProperties. Otherwise, I think your only recourse would be to write the entity to an NBTTagCompound, then get the info from that.

 

Using the getEntityData() tag, which is the most likely scenario:

int type = entity.getEntityData().getInteger("Subspecies");

Link to comment
Share on other sites

Entity#getEntityData() returns the entity's custom NBT tag data; if the modder is being nice, he/she either used this custom tag or IExtendedEntityProperties. Otherwise, I think your only recourse would be to write the entity to an NBTTagCompound, then get the info from that.

 

Using the getEntityData() tag, which is the most likely scenario:

int type = entity.getEntityData().getInteger("Subspecies");

 

Thanks. Yes I will contact him, apparently thats what I'm doing, so, I'm either doing something wrong, or trying to read data that isn't there, that's why I first wanted to know if there is a method to dump everything inside the NBT to know exactly what is stored on it.

 

 

    	NBTTagCompound EntityNBT;
    	int EntitySpecie;

    	EntityNBT = event.entityLiving.getEntityData();

    	EntitySpecie = EntityNBT.getInteger("Subspecies");

        MyMod.log("Entity Specie: "+EntitySpecie);

 

I bet I'm missing something, or as I said, maybe I'm trying to read something that isn't there.

 

Gonna do some testing and try with event.entity.getEntityData(); instead of entityLiving

 

 

Link to comment
Share on other sites

This is not what getEntityData does. getEntityData is a poor man's IExtendedEntityProperties. It is for storing additional data about the entity, not things that the entity itself saves.

 

Then I'm lost. I thought I was getting the NBT with that

 

/**

    * Returns a NBTTagCompound that can be used to store custom data for this entity.

    * It will be written, and read from disc, so it persists over world saves.

    * @return A NBTTagCompound

    */

    public NBTTagCompound getEntityData()

 

I'm way confuse here. I'll have to look around and see if I find any good tutorial about the NBT and see if I figure out how to apply it in this case.

Link to comment
Share on other sites

@diesieben Except he's not trying to get a field in the class, but additional data set by another mod. Whether the other mod uses IEEP, getEntityData(), or some other method of adding this data is unknown.

 

@OP You need to ask the mod author how they are adding the data, because that determines how you will retrieve it:

 

1. IEEP would be something like: ModsIeepClass.get(player).getSubspecies()

 

2. getEntityData() would be just as you have it in your code above, but you need to make sure you have the tag key exact - "Subspecies" and "subspecies" are not the same, for example

 

3. Somehow written to the entity's actual NBT compound, which is a non-trivial exercise and not very likely that the mod author took this route - if they did, you should ask them to use IEEP instead, but you can test by doing this:

NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
// This will print out all the entry keys in the entity's NBT tag:
for (Object o : tag.getKeySet()) {
System.out.println((String) o);
}
// Once you find which one you want, you can use it:
int subspecies = tag.getInteger("Subspecies");

Again, that last method is VERY unlikely, and if that is indeed what the modder used, it's also very hacky, but that's how you would use it if that's the case.

Link to comment
Share on other sites

@diesieben Except he's not trying to get a field in the class, but additional data set by another mod. Whether the other mod uses IEEP, getEntityData(), or some other method of adding this data is unknown.

 

@OP You need to ask the mod author how they are adding the data, because that determines how you will retrieve it:

 

1. IEEP would be something like: ModsIeepClass.get(player).getSubspecies()

 

2. getEntityData() would be just as you have it in your code above, but you need to make sure you have the tag key exact - "Subspecies" and "subspecies" are not the same, for example

 

3. Somehow written to the entity's actual NBT compound, which is a non-trivial exercise and not very likely that the mod author took this route - if they did, you should ask them to use IEEP instead, but you can test by doing this:

NBTTagCompound tag = new NBTTagCompound();
entity.writeToNBT(tag);
// This will print out all the entry keys in the entity's NBT tag:
for (Object o : tag.getKeySet()) {
System.out.println((String) o);
}
// Once you find which one you want, you can use it:
int subspecies = tag.getInteger("Subspecies");

Again, that last method is VERY unlikely, and if that is indeed what the modder used, it's also very hacky, but that's how you would use it if that's the case.

 

Thanks coolAlias, I will give a try to your method. Also will ask about the method used to the Mod Developer on Monday.

 

Thanks for the help and patience.

 

Link to comment
Share on other sites

Thanks coolAlias, I was totally missing that I actually had to use event.entity.writeToNBT(tag);

 

I thought I just read from it, didn't know I had to use the write first in order to access the information ;)

 

Everything working now :)

 

*****

 

Just a quick note, I had to use tag.func_150296_c() instead of tag.getKeySet() this last one wasn't present, but looking at the source, I figured out that func_150296_c was going to work (Got lucky on that one I guess)

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



×
×
  • Create New...

Important Information

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