rutgerkok / WorldGeneratorApi

Minecraft Spigot plugin that enables other plugins to customize world generation
MIT License
95 stars 9 forks source link

Fix setBlock in custom terrain generation. #50

Closed SuperSpyTX closed 3 years ago

SuperSpyTX commented 3 years ago

I've been dealing with a world generation bug for several days and could not figure out why blocks were not being set in my custom BaseTerrainGenerator:

import nl.rutgerkok.worldgeneratorapi.BaseTerrainGenerator;
import nl.rutgerkok.worldgeneratorapi.BiomeGenerator;
import org.bukkit.Material;

public class TestGenerator implements BaseTerrainGenerator {

    public TestGenerator(long unused) {

    }

    @Override
    public void setBlocksInChunk(GeneratingChunk generatingChunk) {
        for (int y = 0; y < 64; y++) {
            for (int x = 0; x < CHUNK_SIZE; x++) {
                for (int z = 0; z < CHUNK_SIZE; z++) {
//                    generatingChunk.getBlocksForChunk().getBlockData(x, y, z);
                    generatingChunk.getBlocksForChunk().setBlock(x, y, z, Material.TNT);
                }
            }
        }
    }

    @Override
    public int getHeight(BiomeGenerator biomeGenerator, int x, int z, HeightType type) {
        return 64;
    }
}

This is the result of the world generation on the current 1.2.2-SNAPSHOT: image

After careful evaluation, i noticed that if I uncomment the getBlockData line, it works correctly.

The respective line where getBlockData is called: https://github.com/rutgerkok/WorldGeneratorApi/blob/master/worldgeneratorapi-impl/src/main/java/nl/rutgerkok/worldgeneratorapi/internal/bukkitoverrides/ChunkDataImpl.java#L28

setBlock function call: https://github.com/rutgerkok/WorldGeneratorApi/blob/master/worldgeneratorapi-impl/src/main/java/nl/rutgerkok/worldgeneratorapi/internal/bukkitoverrides/ChunkDataImpl.java#L69

By updating the function call in setBlock to match the above, the world generates correctly: image

rutgerkok commented 3 years ago

Thanks, nice find!