#You should make a thread on discord tbh

1 messages · Page 1 of 1 (latest)

round stream
#

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 ?

plucky scaffold
#

Just the ones that will be called from biomeprovider

round stream
#
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

plucky scaffold
#

Changed to?

round stream
#

we went back 2

#

12221

plucky scaffold
#

Lol

round stream
#

Just restarted, still 12221 on the thread swap

plucky scaffold
#

Are there any other methods you're calling?

round stream
#

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

plucky scaffold
#

Right and in custombiomeprovider

round stream
#
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

plucky scaffold
#

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

round stream
#

but if you take a look to the post I linked, that's basically the same thing

#

I don't understand why it crashes

plucky scaffold
#

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

round stream
plucky scaffold
#

Weird

round stream
#

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

plucky scaffold
#

It works?

round stream
#

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

plucky scaffold
#

Bruh

#

Does it crash on switching tjreads again?

round stream
#

nop

#

it did a long part on the worker thread

plucky scaffold
#

That's just concurrency i guess

round stream
#

from 122230 to 1180830 it's on the worker thread

plucky scaffold
#

What changes when you change the size?

round stream
#

and the method is still synchronized

#

I can generate more blocks I guess

#

let's try whith 512

plucky scaffold
#

When you stored the pixels in a concurrenthasmap that didn't work?

round stream
#

nop

plucky scaffold
#

Can i have your voroni class

#

I wanna try it myself

round stream
#

sure

#

with 512 size map I can reach 407433

#

but still crash

#

it's stupid

plucky scaffold
#

Do a bukkit.ismainthread check

#

If it's not just return void

round stream
#

euh ok

#

wtf

#

it's...

#

wait

plucky scaffold
#

Working?

round stream
#

need to recheck but yeah

plucky scaffold
#

What did u change?

round stream
#

there was an error on my coord

#

I saw it with a smaller map size

plucky scaffold
#

Ohh that's why it kept crashing at the same number

round stream
#

yep

plucky scaffold
#

What was wrong with the coord tho?

#

Like why wasn't there just a npe or something

#

Something froze all server threads

round stream
#

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