[SOLVED]ChunkGeneration help

Discussion in 'Plugin Development' started by stelar7, Jul 9, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    stelar7

    I want to make a world with certain layers made of bedrock, then a certain amount of layers with another material, then on top a x*z cuboid of another material...

    As of now, everything works except the cuboids, as they are always 15*15 of air then the material is around it (shown in the spoiler below)
    Show Spoiler

    [​IMG]



    Code so far:
    Code:
    @Override
    public byte[] generate(final World world, final Random random, final int cx, final int cz) {
        final byte[] result = new byte[32768];
        for (int x = 0; x < 16; x++) {
            for (int z = 0; z < 16; z++) {
                if (Config.useBedrock()) {
                    for (int y = Config.lowestLayer(); y < Config.bedrockLayers(); y++) {
                        result[(((x * 16) + z) * 128) + y] = (byte) Material.BEDROCK.getId();
                    }
                }
                for (int y = Config.normalStart(); y < Config.normalEnd(); y++) {
                    result[(((x * 16) + z) * 128) + y] = (byte) mat.getId();
                }
                for (int y = Config.normalEnd(); y < (Config.normalEnd() + 1); y++) {
                    if (((x % Config.plotLength()) == 0) || ((z % Config.plotWidth()) == 0)) {
                        result[(((x * 16) + z) * 128) + y] = (byte) sep.getId();
                        result[(((z * 16) + x) * 128) + y] = (byte) sep.getId();
                    }
                }
            }
        }
        return result;
    }
     
  2. I think the problem islocated here

    if (((x % Config.plotLength()) == 0) || ((z % Config.plotWidth()) == 0)) {
    result[(((x * 16) + z) * 128) + y] = (byte) sep.getId();
    result[(((z * 16) + x) * 128) + y] = (byte) sep.getId();
    }

    I think config,plotLenght and config.plotWidth are both 16
     
  3. Offline

    stelar7

    nope, they are both set at 20
     
  4. debug the satate of x % Config.plotLength()) == 0 to verify the result
     
  5. Offline

    stelar7

    I suspect it only happens for the first block (0), but I need help to make it a configurable size, and I'm not even sure this is the right way...
     
  6. Offline

    enjikaka

    Where is your god now?
     
  7. I think i found your problem, you just doing every loop of the methodes x = 0 to 16
    so it wil always stay between 0 and 16
    try this part:

    (x+(cx*16)) % Config.plotLength()
     
  8. Offline

    stelar7

    tried that, didnt work
     
  9. try uusing this
    if ((((x+(cx<<4)) % Config.plotLength()) == 0) || (((z+(cz<<4)) % Config.plotWidth()) == 0)) {
     
  10. Offline

    stelar7

    stil nothing

    got it working!
    final code:
    Code:
    package my.plugin.stelar7.plots;
     
    import java.util.Random;
     
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Biome;
    import org.bukkit.generator.ChunkGenerator;
     
    public class PlotGen extends ChunkGenerator {
     
        Material mat = Config.getBaseMaterial();
        Material sep = Config.getSeparatorMaterial();
     
        @Override
        public byte[][] generateBlockSections(final World world, final Random random, final int cx, final int cz, final ChunkGenerator.BiomeGrid biomes) {
            final byte[][] result = new byte[16][];
     
            if (Config.useBedrock()) {
                for (int x = 0; x < 16; x++) {
                    for (int z = 0; z < 16; z++) {
                        biomes.setBiome(x, z, Biome.PLAINS);
                        for (int y = Config.lowestLayer(); y < Config.bedrockLayers(); y++) {
                            setBlock(result, x, y, z, (byte) Material.BEDROCK.getId());
                        }
                        for (int y = Config.normalStart(); y < Config.normalEnd(); y++) {
                            setBlock(result, x, y, z, (byte) mat.getId());
                        }
                        for (int y = Config.normalEnd(); y < (Config.normalEnd() + 1); y++) {
                            if ((((x + (cx * 16)) % Config.plotSize()) == 0) || (((z + (cz * 16)) % Config.plotSize()) == 0)) {
                                setBlock(result, x, y, z, (byte) sep.getId());
                            }
                        }
                    }
                }
            }
            return result;
        }
     
        private void setBlock(final byte[][] result, final int x, final int y, final int z, final byte blkid) {
            if (result[y >> 4] == null) {
                result[y >> 4] = new byte[4096];
            }
            result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
        }
     
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page