Jump to content

Recommended Posts

Posted

Hey all,

I'm wondering if there's a way to forceload a chunk instantly in 1.18.2.  I'm updating an older mod from 1.16, and in that version of the game I was able to do so just by calling

serverWorld.forceChunk(chunkPos.x, chunkPos.z, false);

which would then enable me to access the Chunk at that location and get a list of the entities inside it (which is my end goal here as well).  However, although in 1.18 I still have the ability to call

serverLevel.setChunkForced(chunkPos.x, chunkPos.z, false);

it no longer seems to load the chunk immediately, but instead (from my understanding) submits a ticket to load it on the next tick.  This is problematic for my use case, as my goal is to load the chunk, access an entity within it, and then deload the chunk on completion, which I can no longer do in a single tick with this method.  LevelChunks also don't seem to contain a list of entities anymore in 1.18, and seem to have less automated functions connected to them, which could I suppose also be the source of my issue.

Is there a way to load a chunk instantaneously from its coordinates and immediately access the entities within it?

Posted
37 minutes ago, Xoroshio said:

Just call level.getChunk(x, y);

After that you can get the entities. Dont worry about the return value, the method loads the chunk.

Huh, well that's more straightforward than I expected.  Good to know, thanks!

Entity here is still coming back null, though.  Do I need to retrieve the entity differently?  Right now I'm doing it like this-

serverLevel.getChunk(chunkPos.x, chunkPos.z);
Entity entity = serverLevel.getEntity(uuidIn);

 

Posted
3 hours ago, Xoroshio said:

Ahhhh idk. Been awhile. How do you know the entity is in the chunk.

I'm saving and storing the position at a different point.  I know it's accurate in my testing cases because I'm also displaying the entity's coordinates, and if I manually teleport to them I can verify the entity is there.

Posted (edited)
1 hour ago, Xoroshio said:

My guess would be that you are not getting the chunk coordinates right, or getChunk dosnt work.

I've tried multiple ways to get the chunk coordinates and none of them have worked, so I'm guessing it may be getChunk().  Is there another way to forcibly load a chunk on that same tick?

If all else fails I guess I can just delay my action by a tick, but that's a pain in the butt and makes it more complex to provide appropriate feedback...

Also welcome, Zander.  If you're searching for a similar solution, I hope this (eventually) helps you too 😅

Edited by JayZX535
  • 1 month later...
Posted

Finally circling back to this, and I think all of us were half right.  getChunk() does appear to immediately load the chunk, but what changed between 1.16 and 1.18 is that the list of entities is now stored in the server, not per chunk.  So while it was possible to load a chunk in 1.16 and immediately grab an entity out of it, 1.18 loads the chunk and submits a request to load its entities on the next tick (if I understand correctly).  All this to say, you can immediately access the chunk itself, however you have to wait an additional tick for its entities to load in.

In my case what this means is that I do have to set up an interface to wait an additional tick before submitting the request to retrieve the entity.  However, other functions do appear to be available immediately.  Just depends on what you're trying to do.

Thank you all for the help! 

Posted

Ah, it appears I spoke too soon, I still need a little help here.

I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it.

However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call).

ChunkPos chunkPos = new ChunkPos(entityPosIn);
if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) {
	boolean isSummoned = // The method I'm using for actual summoning is called here.  Apart from a few checks, the bulk of it is shown later on.
	if (isSummoned) {
		// Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload
	}
}
else {
	// I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared
	ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true);
}

The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly:

if (entity.isAlive()) {
	entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ());
	serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F);
	return true;
}

I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag?

At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it.

Thanks!

Posted

I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅

Posted
15 minutes ago, Xoroshio said:

I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅

That's basically what the failure does, my apologies for failing to specify.  It just tries again on the next tick until it detects the entities for that chunk are loaded, and then tries to load the entity.  From there it gets into different failure states depending on what goes wrong, but in short, if the entity fails to load once the entity list becomes available, the request is cleared and must be resubmitted by the end user.  There should be few cases where that actually happens.

Yes, that is my understanding of forceloading.  That's why on a successful summon, it removes the forceload.  Otherwise it does just leave the chunks loaded long term.

Thank you for your help, any knowledge is useful!  I don't often mess with forceloading and my prior experience is 1.16 so I'm also a bit out of my depth haha.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Please read the FAQ and post logs as described there.
    • Upon starting the server I get; [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [     Framework (framework) has failed to load correctly §7java.lang.NoClassDefFoundError: net/minecraft/client/gui/components/toasts/Toast ] I suspect there is a (possibly a few) client-only mods installed on my server. Any help would be appreciated! (Yes I know there are a lot of mods...) Here is the crash log:   https://paste.ee/p/pRz5mhMl#s=0
    • That's basically what the failure does, my apologies for failing to specify.  It just tries again on the next tick until it detects the entities for that chunk are loaded, and then tries to load the entity.  From there it gets into different failure states depending on what goes wrong, but in short, if the entity fails to load once the entity list becomes available, the request is cleared and must be resubmitted by the end user.  There should be few cases where that actually happens. Yes, that is my understanding of forceloading.  That's why on a successful summon, it removes the forceload.  Otherwise it does just leave the chunks loaded long term. Thank you for your help, any knowledge is useful!  I don't often mess with forceloading and my prior experience is 1.16 so I'm also a bit out of my depth haha.
    • I will have to do more research about 1.18 chunk loading. You were unclear about how your code manages with the entity load failure. If you simply used a loop, I suggest submitting a tick task to the next tick which does the same thing, checking if the entities are loaded and if so teleporting the right one else submitting another tick task etc. Also I think forceloading permanently force loads the chunk, and it only starts to unload when you make a subsequent call to mark the chunk as not forceloaded. I may be completely wrong, I dont know much about 1.18, most of my experience is 1.20. Good luck I hope you figure it out after all this time 😅
    • i managed to fix it by reinstalling the modpack and re-add all the extra mods I've had previously.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.