Jump to content

[1.8]Entities not spawning with the exact same data


The_Fireplace

Recommended Posts

So, I am making it so mobs are reborn at full health during LivingDropsEvent, and it works, except for some data not remaining the same as the original. Here is the void being called during the LivingDropsEvent:

 

 

private void createEntity(LivingDropsEvent event){
NBTTagCompound storedData = event.entityLiving.getEntityData();//As you can see, I am storing the NBT here...
EntityLivingBase entity;
World worldIn = event.entityLiving.worldObj;
int id = EntityList.getEntityID(event.entityLiving);
ItemStack weapon = event.entityLiving.getHeldItem();
entity = (EntityLivingBase) EntityList.createEntityByID(id, worldIn);
    entity.setLocationAndAngles(event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F);
    entity.rotationYawHead = entity.rotationYaw;
    entity.renderYawOffset = entity.rotationYaw;
    ((EntityLivingBase) entity).writeToNBT(storedData);//...and writing it to the new entity here
    entity.setCurrentItemOrArmor(0, weapon);
worldIn.spawnEntityInWorld(entity);
}

 

 

Some of the data not staying the same that I have noticed is:

Villager color always becomes the brown one

Rabbit color always becomes the brown one

Baby villagers become fully grown, probably does that for other animals as well

 

Any help would be appreciated.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

You need to use

readFromNBT

on the entity, instead of

writeToNBT

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Probably because the date you inserted into the new entity says that it should be dead (0 health, etc.).

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

  • 3 weeks later...

Probably because the date you inserted into the new entity says that it should be dead (0 health, etc.).

How exactly do I fix this issue? I have tried multiple times, and they all have failed. Here is what I have tried:

private void createEntity(LivingDropsEvent event){
EntityLivingBase entity;
World worldIn = event.entityLiving.worldObj;
int id = EntityList.getEntityID(event.entityLiving);
NBTTagCompound storedData = event.entityLiving.getEntityData();
ItemStack weapon = event.entityLiving.getHeldItem();
entity = (EntityLivingBase) EntityList.createEntityByID(id, worldIn);
    entity.setLocationAndAngles(event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F);
    entity.rotationYawHead = entity.rotationYaw;
    entity.renderYawOffset = entity.rotationYaw;
    storedData.setInteger("health", (int) event.entityLiving.getMaxHealth());
    ((EntityLivingBase) entity).readFromNBT(storedData);
    entity.setCurrentItemOrArmor(0, weapon);
worldIn.spawnEntityInWorld(entity);
}

private void createEntity(LivingDropsEvent event){
EntityLivingBase entity;
World worldIn = event.entityLiving.worldObj;
int id = EntityList.getEntityID(event.entityLiving);
NBTTagCompound storedData = event.entityLiving.getEntityData();
ItemStack weapon = event.entityLiving.getHeldItem();
entity = (EntityLivingBase) EntityList.createEntityByID(id, worldIn);
    entity.setLocationAndAngles(event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F);
    entity.rotationYawHead = entity.rotationYaw;
    entity.renderYawOffset = entity.rotationYaw;
    entity.setHealth(event.entityLiving.getMaxHealth());
    ((EntityLivingBase) entity).readFromNBT(storedData);
    entity.setCurrentItemOrArmor(0, weapon);
worldIn.spawnEntityInWorld(entity);
}

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Have you even looked at NBT methods?

You actually don't need some of what you did at all. Things like rotation are saved inside NBT (print it out and see, or just look at code).

 

Also it's "Health" not "health". There are also FEW health fields (HealF for example). You'd be better off reading callback hierarchy :D

 

EDIT:

Few things:

1. Not every entity has NBT, NBT is only created for "special" ones. That will be tamed, named with label or mobs with amour (and animals). Rest of them are spawned randomly via world spawner, not saved on disk and loaded later, so 1st check for NBT.

2. Tho I have no idea why it doesn't work - your entity IS being SPAWNED. It's location is 0,0,0 (auto-death) and I honestly have no idea why. Things like setLocationAndAngles seem to not be working.

I only managed to make them work when i put them after spawn-code:

worldIn.spawnEntityInWorld(entity);
	entity.setLocationAndAngles(event.entityLiving.posX, event.entityLiving.posY, event.entityLiving.posZ, MathHelper.wrapAngleTo180_float(worldIn.rand.nextFloat() * 360.0F), 0.0F);
	entity.rotationYawHead = entity.rotationYaw;
	entity.renderYawOffset = entity.rotationYaw;

The entity is being spawned at 0,0,0 and moved to x,y,z desired - that is NOT best way, but still - all happens in one chunk of code so it's literally like you would spawn it in x,y,z.

 

 

1.7.10 is no longer supported by forge, you are on your own.

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.