#You should make a thread on discord tbh
1 messages · Page 1 of 1 (latest)
here we go
I've done something similar previously and it was ok
How do I synchronize ? Do I have to put he key word on each child method ?
Just the ones that will be called from biomeprovider
public synchronized Biome getBiome(int x, int z){
count++;
System.out.println(count);
return biomes.get(voronoi.getPixels()[x + Voronoi.SIZE /2][z + Voronoi.SIZE /2]);
}```
nop it keeps crashing but the number changed
Changed to?
Lol
Just restarted, still 12221 on the thread swap
Are there any other methods you're calling?
let's see from the beginning
WorldCreator wc = new WorldCreator(GameSettings.WORLD_NAME);
wc.biomeProvider(new CustomBiomeProvider());
System.out.println("0");
wc.createWorld();
System.out.println("1");```
it starts with this
Right and in custombiomeprovider
package net.johnpoliakov.ultrapower.utils.world;
import org.bukkit.block.Biome;
import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.WorldInfo;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class CustomBiomeProvider extends BiomeProvider {
private final ArrayList<Biome> biomes = new ArrayList<>();
private final MapReader mapReader = new MapReader();
public CustomBiomeProvider() {
for(BiomesEnum biome : BiomesEnum.values()){
addBiome(biome.getBiome());
}
}
private void addBiome(Biome biome) {
this.biomes.add(biome);
}
@Override
public @NotNull Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) {
// Plains in 150 blocks radius from 0:0
if ((Math.pow(x, 2) + Math.pow(z, 2)) < Math.pow(150, 2))
return Biome.PLAINS;
// void if outside the border
if(x >= 2048 || x <= -2048 || z >= 2048 || z <= -2048)
return Biome.THE_VOID;
// read from voronoi
return mapReader.getBiome(x, z);
}
@Override
public @NotNull List<Biome> getBiomes(@NotNull WorldInfo worldInfo) {
return biomes;
}
}
then the MapReader
package net.johnpoliakov.ultrapower.utils.world;
import org.bukkit.block.Biome;
import java.util.HashMap;
public class MapReader {
private final Voronoi voronoi;
private final HashMap<Integer, Biome> biomes = new HashMap<>();
private int count = 0;
public MapReader(){
voronoi = new Voronoi(2, 150);
for(BiomesEnum biome : BiomesEnum.values()){
biomes.put(biome.getColor(), biome.getBiome());
}
}
public synchronized Biome getBiome(int x, int z){
count++;
System.out.println(count);
return biomes.get(voronoi.getPixels()[x + Voronoi.SIZE /2][z + Voronoi.SIZE /2]);
}
}```
mmmmm
now I'm back to 12223
I'm guessing that number is jist telling us abt how long it takes for the new thread to kick in
Try printing every 10th number
but if you take a look to the post I linked, that's basically the same thing
I don't understand why it crashes
Sounds dumb bit it'll probably go up
My guess was that there is some sort of deadlock
But i dont think i know enough to be able to help further
I think you should add to your post that it stops generatijg and freezes the server when the worker thread starts generation
nop we stop at 12220
Weird
I'm gonna try something
instead of getting the color from the array
I'm gonna pick it from the image buffer
still crashing
ok
solved I guess
It works?
gne
so it crashes, I tried with an area between -1024:-1024/1024:1024 instead of -2048:-2048/2048:2048
I reach 1180830
still on the 10th number print
but it crashes
That's just concurrency i guess
from 122230 to 1180830 it's on the worker thread
What changes when you change the size?
and the method is still synchronized
I can generate more blocks I guess
let's try whith 512
When you stored the pixels in a concurrenthasmap that didn't work?
nop
sure
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
with 512 size map I can reach 407433
but still crash
it's stupid
Working?
need to recheck but yeah
What did u change?
Ohh that's why it kept crashing at the same number
yep
What was wrong with the coord tho?
Like why wasn't there just a npe or something
Something froze all server threads
out of size I was checking negative coord on the image because I was adding only half ot it's size to compensate negative coord instead of it's fullsize