Hello. I came from Bukkit.
I’m trying to make a simple plugin that would generate 3 random locations when the player first hits.
How do I dealu:

  • generate 3 locations in a given interval.
  • I save them in HashMap<String, List<Location>>
  • when entering a command I take the specified location and teleport it to the specified location number 1-3.

The problem is that when generating a location, I check the floor for validity.
The location, more precisely its chunk, has not yet been generated and the server goes into an endless loop to find a safe location.
How can I solve this problem?
Translate by Google

Location<World> loc;

Thats from what i can remeber. Im on mobile so i can not check

Sponge actually has a mechanism for safe teleporting built-in. Get the TeleportHelper from Sponge and call getSafeLocation.

The chunk in which the safeLocation is being conducted is not yet generated, is this method likely to generate it?

I mean, there’s no sane way of figuring out whether a location is safe without generating it first. So I would assume so. But try it and see.

Yep. You will need to put a true boolean on the end to generate it

It works RandomSpawnManager - Pastebin.com. But the locations are generated for a long time, which leads to this:http://joxi.ru/a2XQ9MNu19RDwA

That is what it is, generating chunks is one of the most challanging and cpu intensive operations taking a lot of (relative) time on a server, period. When you need to test a whole bunch of them in different areas its going to take a while, and if most of the coordinates are in ocean etc, its not going to have an easy time finding safe teleport spots.

If you have the option, with your plugin working within a set of constrained regions on a map, and a map border that isn’t large, pregenerating the map will eliminate most of that overhead each time, but that gets to be intensive and quite sizable when you have maps with borders >12k diameter, and at 20k diameter it will take a long time and a lot of space, if youre using 50k to 100k or more, forget it…

Your doing

getChunk(Vector3i, true)

It needs to be

loadChunkAtBlock(Vector3i, true)

The get chunk refers to the chunk position. Not the block position.

On second thoughts i dont think there is a load chunk at block. In that case you can grab the chunk x and z from the location Object. And then load the chunk using that with the y being 0.

I’m trying to make a random location generator for the players who entered the game for the first time. Code: https://pastebin.com/Sm9963zn The problem in the getRandomLocation () method.

  1. Generate x and z.
  2. Based on x and y, I get the chunk. The chunk may not yet be generated.
    This requires you to load asynchronously (and if you need to generate chunk).
  3. From the chunk get the location of x y z.
  4. Locate a safe place using Sponge.getTeleportHelper ().

It is not possible to properly organize asynchronous loading of the chunk and correct teleportation by coordinates. Help is needed.