All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.level.generator.populator.impl.nether.CrimsonFungiTreePopulator Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.level.generator.populator.impl.nether;

import cn.nukkit.block.Block;
import cn.nukkit.level.ChunkManager;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.generator.object.tree.ObjectCrimsonTree;
import cn.nukkit.level.generator.populator.type.Populator;
import cn.nukkit.math.NukkitMath;
import cn.nukkit.math.NukkitRandom;

import java.util.ArrayList;

public class CrimsonFungiTreePopulator extends Populator {
    private ChunkManager level;

    @Override
    public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
        this.level = level;
        int amount = random.nextBoundedInt(6) + 4;

        for (int i = 0; i < amount; ++i) {
            int x = NukkitMath.randomRange(random, chunkX << 4, (chunkX << 4) + 15);
            int z = NukkitMath.randomRange(random, chunkZ << 4, (chunkZ << 4) + 15);
            ArrayList ys = this.getHighestWorkableBlocks(x, z);
            for (int y : ys) {
                if (y <= 1) continue;
                if (random.nextBoundedInt(4) == 1) continue;
                new ObjectCrimsonTree().placeObject(this.level, x, y, z, random);
            }
        }
    }

    private ArrayList getHighestWorkableBlocks(int x, int z) {
        int y;
        ArrayList blockYs = new ArrayList<>();
        for (y = 128; y > 0; --y) {
            int b = this.level.getBlockIdAt(x, y, z);
            if ((b == Block.CRIMSON_NYLIUM) && this.level.getBlockIdAt(x, y + 1, z) == 0) {
                blockYs.add(y + 1);
            }
        }
        return blockYs;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy