Jump to content

[1.9] Set the size of the slime to spawn


American2050

Recommended Posts

I am having problems setting the size of a slime when I want to spawn them. By default they spawn as small ones, but I want the big ones.

 

This is what I have tried, not sure what I'm doing wrong.

 

private static final DataParameter<Integer> SLIME_SIZE = null;

 

EntitySlime entityLocal = new EntitySlime(world);
entityLocal.setPosition(pos.getX(), pos.getY(), pos.getZ());
entityLocal.getDataManager().set(SLIME_SIZE, 4);
world.spawnEntityInWorld(entityLocal);

 

I believe that's not the way to do it and that's the reason why it just doesnt work :P

Link to comment
Share on other sites

That's not how DataParameters work at all. Creating a field with the same type and name as the field that stores the DataParameter won't work, DataParameters are stored as Objects, not types. To get the parameter's value, you need the Object that was registered to the EntityDataManager. You could get it using reflection, but that's messy and has more overhead than a simpler option.

 

Slimes store their size in NBT as well, because DataParameters do not persist after the world is unloaded; this means that you can create an NBTTagCompound, set a tag with the identifier(The String that identifies the tag) "Size" to whatever size you want and then use Entity#readEntityFromNBT to apply it to a slime.

Link to comment
Share on other sites

(You'll actually want to create a blank NBT tag, run it through, writeToNBT, then change the one value, then run it through readFromNBT: that makes sure that every other value doesn't get altered or throw errors)

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

(You'll actually want to create a blank NBT tag, run it through, writeToNBT, then change the one value, then run it through readFromNBT: that makes sure that every other value doesn't get altered or throw errors)

I think I understand what you mean, but, wont this be ok?

I'm starting my NBT from the data on the Entity itself, and then just changing the Size to be 4 and then passing it back to the entity.

 

Not sure if I'm missing something, so far it works, but maybe I'm going something wrong.

 

			EntitySlime entityLocal = new EntitySlime(world);

		entityLocal.setPosition(pos.getX(), pos.getY(), pos.getZ());

        	NBTTagCompound tag = entityLocal.getEntityData();
        	
        	tag.setInteger("Size", 4);
       	
        	entityLocal.readEntityFromNBT(tag);

		world.spawnEntityInWorld(entityLocal);

Link to comment
Share on other sites

entityLocal.getEntityData(); is functionally identical to entityLocal.writeToNBT(tag); for this, but definitely cleaner. I forget that getEntityData() exists.

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

Entity#getEntityData

returns a compound tag for storing custom data on external entities. It does not store the entity's own data (e.g. Slime size) and should not be combined with

Entity#readFromNBT

and

Entity#writeToNBT

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Entity#getEntityData

returns a compound tag for storing custom data on external entities. It does not store the entity's own data (e.g. Slime size) and should not be combined with

Entity#readFromNBT

and

Entity#writeToNBT

.

Thanks Choonster. I believe this is the right way to do it then.

 

			EntitySlime entityLocal = new EntitySlime(world);

		entityLocal.setPosition(pos.getX(), pos.getY(), pos.getZ());

		NBTTagCompound tag = new NBTTagCompound();
        	
        	entityLocal.writeEntityToNBT(tag);;
        	
        	tag.setInteger("Size", 4);
       	
        	entityLocal.readEntityFromNBT(tag);

		world.spawnEntityInWorld(entityLocal);

 

Thanks a lot for the help and patience  ;)

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.