Jump to content

[1.7.10] Finding Tile entitys?


robertcars

Recommended Posts

So I need my tile entity to have a method on finding all the tile entity's in the world of the same type. Also my tile entity has a id variable in it and the tile entities it finds has to have the same id as the one that's looking for the others and then I need the first tile entity to get the coords of the one it found.  How would I go about doing this and what is the best way?

Link to comment
Share on other sites

To make my own data structure seems a little out of my reach. Thanks for the advice

 

All he meant was to create a List of your own. So imagine your tile entity class had a static field that was a list and every time an instance was contructed it added it to that list.  Then each tile entity could access this shared list and just check that for ones that may have same id.  You'd also want to make sure that every time the tile entity was destroyed it would remove it from the list as well.

 

So nothing too difficult.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

You probably don't want to populate the List with instances of both client & server, which would happen in SP if you're just using a static field.

 

Hmmm, interesting point.  I guess I have never fully realized that the static was across both sides since I thought that somehow even in SP that the Java was fully segregated.  But I guess that doesn't make sense since SP only kicks off one Java runtime.  So each has own instances but still are technically same class with shared static.  I get it.

 

Back to the question: It's not clear what the OP really wants to do with these tile entities that he's tracking. So he may want to track both, or I guess probably better is only track on server and let client sync naturally?

 

@robertcars, you might want to create two lists, one for tile entities found on server side and one for tile entities found on client side.  (To understand this, the server and client run their own "copies" of many class instances which then are synced via built-in packets.  The problem is that if your client iterates the list it would not be good to try to process the server instances and vice versa.  Depending on what you're doing, you would use the list appropriate to the side you're interested in.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

It depends on where the tile entities exist but they can't populate one block more than once it would be better to go with a hashmap.

No chance of duplicating a tileentity by accident and simply use the x,y,z as key.

E.g. OP speaks of one particular tileentity so using the id with multiple values is redundant.

Link to comment
Share on other sites

It depends on where the tile entities exist but they can't populate one block more than once it would be better to go with a hashmap.

No chance of duplicating a tileentity by accident and simply use the x,y,z as key.

E.g. OP speaks of one particular tileentity so using the id with multiple values is redundant.

 

Actually it is still not clear what the OP wants to do.  Maybe he just wants a count of all TileEntities or something, in which a list might suffice.  Maybe he cares about processing based on ID after his initial search for them, in which case a map might be convenient.  Maybe quickly referencing position is useful and so hashmap keyed of position might be useful.

 

I think the point is there are many standard Java data structures that can help keep track, and the coding isn't that advanced to use them.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.