Jump to content

Saving a Reference to an Entity (Save/Load Persistence)


Draco18s

Recommended Posts

I need to be able to save out and then reload a reference to a Minecart, because the TileEntity is "catching" it and hold it in place until its finished, then reapplying some momentum to it when its done, so that the cart continues on its merry way.

 

Problem is, I can't seem to make that "reapplying some momentum to it when its done" part work after a save/load because I literally have no way of getting an entity from the World by anything other than incremental spawn ID (not guaranteed to persist, AFAIK) or by AABB (not save-able or not able to ensure match).

 

What am I missing?

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

Hi

 

I think you could try three things - One is to "leash" your minecart similar to what DieSieben suggested, not sure if that works for non-EntityLiving.  Second is to replace the vanilla Minecart Entity with a MyCapturableMinecart extends EntityMinecart to make it responsible for maintaining a link to the "capturing" tileentity, or thirdly your TileEntity could despawn the Minecart while it is captured and respawn once it's finished.

 

-TGG

 

> I literally have no way of getting an entity from the World by anything other than incremental spawn ID

PS forgot to mention- do you already know about persistent EntityID ?

i.e. getPersistentID() or getUniqueID() instead of getEntityId()

Link to comment
Share on other sites

> I literally have no way of getting an entity from the World by anything other than incremental spawn ID

PS forgot to mention- do you already know about persistent EntityID ?

i.e. getPersistentID() or getUniqueID() instead of getEntityId()

 

Oh, I can get a persistent ID all I want.

 

I have no way of going "Hey, server, find me this non-living entity by this UUID."  I can get players by UUID, but not any thing else.

 

Use UUIDs and search in a confined space, so you don't have to check every entity in the world. That's how leashes work, too.

 

I'll take a look at leashes.  I was going that route, but I wasn't sure if that'd even work for entities like minecarts (its not transparent on if those are saved/loaded and keep the same UUID, or what.  I would assume so, but you know what they say about about assuming...).

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

Also keep in mind that your entity reference will always return null if the chunk that it is in is not currently loaded. I've gotten around that by also storing the last known chunk coordinates, then force loading those chunks for the search when necessary.

 

As diesieben pointed out, though, it might not be a bad idea to store the coordinates anyway for the sake of narrowing your search. For my part, I just use the UUID when the entityId is no longer valid, and use the entityId once the entity is found.

 

See here.

Link to comment
Share on other sites

Also keep in mind that your entity reference will always return null if the chunk that it is in is not currently loaded. I've gotten around that by also storing the last known chunk coordinates, then force loading those chunks for the search when necessary.

 

TE and cart will be in the same chunk.  Specifically 1 block away from each other.

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

Also keep in mind that your entity reference will always return null if the chunk that it is in is not currently loaded. I've gotten around that by also storing the last known chunk coordinates, then force loading those chunks for the search when necessary.

 

TE and cart will be in the same chunk.  Specifically 1 block away from each other.

In that case you can simply store the UUID, and if the world#getEntityById returns null, get a list of entities in a bounding box enclosing that area and iterate through them until you find one with a matching UUID - there's your minecart.

Link to comment
Share on other sites

Yep, just got it working. :)

Did a slightly larger volume, just in case the cart gets away for any reason.

 

Thanks muchly.

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

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.