Jump to content

New attributes for custom entities


acbart

Recommended Posts

I've read through several tutorials, and I've gone through multiple forum posts, and at this point I'm a little confused. I have a new custom mob (extending EntityAnimal) that needs to have a bunch of new properties - we'll say "gender" (Enum) and "domestication"(int) for simplicity's sake. These properties are given values based on a random distribution when the entity first appears in the world, but afterwards need to be consistent across the life of the entity. What is the best way to store these properties so that they are synchronized between the client/server and are not reset when I reload the world from a save?

 

More generally, I would really just like to understand how the following programming elements work with each other.

 

* New instance attributes set in the Constructor - as in, just regular class attributes

* DataWatcher

* Entity.writeEntityToNBT/Entity.readEntityFromNBT

* Entity.applyEntityAttributes

* Entity.extendedProperties

* Entity.entityInit

* IAttribute

 

I'm a PhD student in Computer Science, so please don't be afraid to dive into the technical side of things! Even if you can just point to an up-to-date, authoritative blog post that can really describe all the differences, that would be useful.

Link to comment
Share on other sites

Note that DataWatchers have a specific number of things that they watch and once they're used up, they're used up.  All the vanilla entities are already using about half that limit, plus or minus two (e.g. the dogs have a datawatcher object for their collar color, chickens do not).

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

Thank you both so much! This is extremely helpful. It sounds like most of what I want needs to be managed through the DataWatcher and/or custom packets.

 

Something that's a little strange to me - the DataWatcher can watch Byte, Short, Integer, Float, String, ItemStack and ChunkCoordinates, according to the wiki (http://www.minecraftforge.net/wiki/Datawatcher).  Is there a character limit on Strings? The difference between an Integer and a String in terms of data tored is pretty massive - Integers and Floats are 4 bytes, but a String is able to have Integer.MAX_VALUE (2^31) bytes - it is a glorified array of char after all. Not to endorse a Stringly-typed data structure, but couldn't I avoid managing packets by simply packaging my data into a single String? Or perhaps some related clusters of data into a few Strings? Managing manipulation and storage of that String might be as big a hassle as actually learning how to send my own packets, and is ultimately less flexible, but it's just strange to me that any sized Strings could be sent alongside considerably smaller data formats when there's an upper bound on how many things the DataWatcher can manage.

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.