Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.11.2] Detect player movement or teleportation

Featured Replies

Posted

I am making a mod which generates the real world in Minecraft, using manly the Mapbox API.

Querying the API works fine, but the fact the the mod can create an error when generating a chunk if the internet access drops is a very big problem, as it's impossible to cancel the generation of the chunk to stop the server. To counter this, my mod uses a daemon thread to download the data of the area that could potentially be generated in a near future.

This system works great when you are just flying over the world in creative, but the game will still crash if the player teleports somewhere where the data hasn't been downloaded yet.

 

How do you think I could detect such an action to stop the server before it tries to generate the area where the player moves?

 

You can find the sources here: https://github.com/ZeSmiler/irlw/tree/0.2_dev .

I will create a new repository when the mod will get playable, I know this one doesn't follow the guidelines you guys are giving on the forum about creating a repository, so I will fix it then.

 

Thanks in advance.

I guess my question is -- do you want to prevent the player from going somewhere that cannot be loaded, do you want to just somehow queue up the teleport until the chunk is loaded, or do you want to load some sort of default "filler" in the case where it won't load?

 

Personally if the network is down then I think you should prevent the player from going somewhere where you don't have info. Alternatively when network is down you should just render a default chunk (maybe flat so it is obvious that there is a problem). 

 

IIn any case, you should be able to handle any error and prevent crashes. What error specifically were you seeing and did you try to catch it.

 

 

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

  • Author

I need to be able to be able to stop the server if the player moves quickly to a zone which needs to be generated, before the server tries to generate it. I don't want to generate a default chunk in this case. I will recommend not to use my mod offline, but I still need to properly handles the connection being lost at the middle of the game.

 

 

Well when a chunk is being generated by my IChunkGenerator implementation's provideChunk(int x, int z) method and is on a tile of the map which needs to be downloaded from the Mapbox's server, it's too late to cancel the chunk generation, and the method has to return something. Returning null crashes the game.

At this stage, a two things can happened:

  • The network is disconnected
  • The API http response code is 403, telling that the access token is not valid.

In the first case, the server should be stopped for both the integrated and the physical server.

In the second one, the physical server should stop and the integrated server should ask for a valid token through the client and wait for it (I already implemented this). If no token is provided, it should close the server.

 

This is impossible to do from IChunkGenerator::provideChunk(), as the server can't be stopped from there. As I mentioned in my previous post, the data being downloaded from IChunkGenerator::provideChunk() is my fallback option, and I have a daemon thread running to download tiles. So when the tile at (x;y) is being loaded to be used for world generation, the tiles surrounding tiles are added to a download queue, where any problem can be solved by shutting down the server. The problem is that when the player moves quickly to a new zone, this wont work because I have no way to have added the tile to the download queue before, so it's being downloaded from the server thread, within IChunkGenerator::provideChunk().

  • Author

It seems to be exactly what I need and I didn't know about it, thanks!

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.