Jump to content

Entities in unloaded chunks


stepsword

Recommended Posts

23 minutes ago, stepsword said:

but I'm storing a reference to the "Entity" object somewhere, what happens to the object? Can I still teleport the entity and do other entity things with it?

If you mean you have an instance of an Entity then yes you should. It shouldn't be Garbage Collected, but it won't be the same entity as the one that is loaded later when the chunk is loaded.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

If you mean you have an instance of an Entity then yes you should. It shouldn't be Garbage Collected, but it won't be the same entity as the one that is loaded later when the chunk is loaded.

Thanks - a couple follow ups (and yes, I did mean an instance of an Entity): 

If I teleport the entity out of an unloaded chunk, does the chunk automatically remove it from its "saved" data?

Is there a right way to keep track of entities that may be in unloaded chunks? I was under the impression that there's no world-wide "get Entity by UUID" and the getEntityById method requires an AABB. Mainly if I have an instance of Entity *now* and I want to sync it up with the instance of Entity when the chunk is loaded later, is there a right way to do that?

Link to comment
Share on other sites

1 minute ago, stepsword said:

If I teleport the entity out of an unloaded chunk, does the chunk automatically remove it from its "saved" data?

No it won't. You'll have to teleport it out before the chunk unloads.

 

3 minutes ago, stepsword said:

Is there a right way to keep track of entities that may be in unloaded chunks?

Nope because they are unloaded.

 

3 minutes ago, stepsword said:

Mainly if I have an instance of Entity *now* and I want to sync it up with the instance of Entity when the chunk is loaded later, is there a right way to do that?

Yes if you give that entity a UUID that is also saved and loaded. And you access that data when the Entity joins the world(EntityJoinWorldEvent). But then you will have to make sure to save the entity that you have an instance of when it changes and hasn't been synced because the entity in question hasn't been reloaded.

Let's just ask this question. What are you trying to do?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

20 minutes ago, Animefan8888 said:

No it won't. You'll have to teleport it out before the chunk unloads.

 

Nope because they are unloaded.

 

Yes if you give that entity a UUID that is also saved and loaded. And you access that data when the Entity joins the world(EntityJoinWorldEvent). But then you will have to make sure to save the entity that you have an instance of when it changes and hasn't been synced because the entity in question hasn't been reloaded.

Let's just ask this question. What are you trying to do?

Thanks, that makes sense - I never thought of making my own UUID and saving it.

 

I'm trying to create behavior for a summoned pet, but I also wanted to make it possible to give the pet commands remotely, so the chunk might be unloaded when the command is given. I hadn't actually started coding anything for it cause I wanted to understand the limitations before I jumped in. I was planning to have most commands just fail for unloaded chunks, but a teleport command would be the exception for that, so I'll probably delete the entity when it joins the world if it's got a duplicate UUID of another entity. Thanks again!

Link to comment
Share on other sites

What if:

  1. The entity gets unloaded
  2. The player teleports it to them (it gets cloned)
  3. The new one gets unloaded
  4. The player goes to the chunk where the old one (from (1) is)?

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

1 minute ago, Draco18s said:

What if:

  1. The entity gets unloaded
  2. The player teleports it to them (it gets cloned)
  3. The new one gets unloaded
  4. The player goes to the chunk where the old one (from (1) is)?

That's a good point, thanks.. Hadn't considered that. Maybe I'll add to the player capability a "last known position" for their pet and just delete it if it's not within a few blocks on the EntityJoinEvent. They're meant to be expendable anyway

Link to comment
Share on other sites

As an update to this I think what I will do is force load the chunk of the user's stored pet when I'm issuing commands, and then replace the stored pet with the one with a matching UUID loaded in the chunk - I think that solves the major issues since I won't be teleporting things out of unloaded chunks anymore.

Link to comment
Share on other sites

1 minute ago, stepsword said:

As an update to this I think what I will do is force load the chunk of the user's stored pet when I'm issuing commands, and then replace the stored pet with the one with a matching UUID loaded in the chunk - I think that solves the major issues since I won't be teleporting things out of unloaded chunks anymore.

That idea would work, but here's another idea. Don't let the entity become unloaded in the chunk. Remove the entity from the chunk before it unloads. Then make sure to save them in a World Capability. This might be better??? Because loading chunks is actually quite intensive.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

4 minutes ago, Animefan8888 said:

That idea would work, but here's another idea. Don't let the entity become unloaded in the chunk. Remove the entity from the chunk before it unloads. Then make sure to save them in a World Capability. This might be better??? Because loading chunks is actually quite intensive.

Even if it's just the chunk the entity is in when a player wants to give a command? I figured one chunk extra per player wouldn't be too bad since like 400 chunks are loaded for each player at a given time anyway. 

 

 

Link to comment
Share on other sites

12 minutes ago, stepsword said:

As an update to this I think what I will do is force load the chunk of the user's stored pet when I'm issuing commands,

You would end up loading the chunk basically every time you issue the command. Though I guess one chunk and only to teleport the Entity out of there wouldn't be that bad.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

You would end up loading the chunk basically every time you issue the command. Though I guess one chunk and only to teleport the Entity out of there wouldn't be that bad.

Yea, I think it will be not intensive based on the little I've read of chunk loading - I'm not planning to have many commands, just one or two (like teleport and blow up the nearest creature) and they're going to be very simple things that wouldn't be used in quick succession. I wasn't planning to give the player full control of the pet like "move to XYZ" or anything that would require micromanaging. 

Link to comment
Share on other sites

11 hours ago, Animefan8888 said:

You would end up loading the chunk basically every time you issue the command. Though I guess one chunk and only to teleport the Entity out of there wouldn't be that bad.

Mystcraft would do this when non-player entities were teleported to Myst dimensions via a portal. It really isn't that intensive.

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.