Jump to content

Recommended Posts

Posted

I read on one of these threads to use addScheduledTask to do things "next tick". I call it on the server side, and it seems like the Runnable I give it only gets called on the client.

 

Is this normal?

 

Posted
Just now, Animefan8888 said:

If you are using Minecraft#addScheduledTask yes. You probably want WorldServer#addScheduledTask

Ahh, thanks so much. I was already trying to come up with silly workarounds like recursively adding tasks til it gets called on the server.

Posted
32 minutes ago, Animefan8888 said:

Well depending on what you are doing there might be a better way to run code on the next tick.

Still working on that load chunk -> teleport entity bit. I wanted to make sure the chunk was loaded and also have access to the variables in the function that loads the chunk. Maybe its possible without the next-tick bit though, couldn't really find information on whether forceChunk happens right away or queues the chunk up for loading

Posted
6 minutes ago, stepsword said:

Maybe its possible without the next-tick bit though, couldn't really find information on whether forceChunk happens right away or queues the chunk up for loading 

If I'm not mistaken I don't think you should use forceChunk as that is meant for persistent chunk loading. So if you were to just do something along the lines of Chunk chunk = World#getChunkAt(...); Which should load the chunk immediately. Then you can get the entity either from the chunk or from the world. Then move the Entity. And the chunk will unload just like that.

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.

Posted (edited)
5 minutes ago, Animefan8888 said:

If I'm not mistaken I don't think you should use forceChunk as that is meant for persistent chunk loading. So if you were to just do something along the lines of Chunk chunk = World#getChunkAt(...); Which should load the chunk immediately. Then you can get the entity either from the chunk or from the world. Then move the Entity. And the chunk will unload just like that.

Haha - I learned that the hard way actually, while trying to get the Chunk to check isLoaded() I called getChunkAt().. which loads the chunk. That said, I do have one command planned where it would be useful to keep the chunk loaded so I'm trying to get it working with tickets for this one which will be simpler to test than the other one.

Edited by stepsword
Posted (edited)

As an update: something I think wasn't immediately clear to me is that forceChunk seems to be only for chunks which are already loaded? i.e. if you call forceChunk on an unloaded chunk, nothing happens - you have to load it, then call forceChunk to keep it loaded. I haven't done a lot of testing of this theory to confirm if it's true, but based on the usage of getPersistentChunks() by Forge, I think it's true.

 

This is in the "unload chunks" method. I guess this probably isn't a problem for most people but in case someone stumbles on this later looking for why their forceChunks on a remote location isn't working, it could be because forceChunks only prevents loaded things from being unloaded, so they have to be loaded first for forceChunks to actually work.

 

if (!this.droppedChunksSet.isEmpty())
{
    for (ChunkPos forced : this.world.getPersistentChunks().keySet())
    {
Edited by stepsword

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.