Java Code Examples for cn.nukkit.math.NukkitRandom#nextBoundedInt()

The following examples show how to use cn.nukkit.math.NukkitRandom#nextBoundedInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JungleFloorPopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new NewJungleTree(1, 0).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 2
Source File: ObjectTree.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {

        this.placeTrunk(level, x, y, z, random, this.getTreeHeight() - 1);

        for (int yy = y - 3 + this.getTreeHeight(); yy <= y + this.getTreeHeight(); ++yy) {
            double yOff = yy - (y + this.getTreeHeight());
            int mid = (int) (1 - yOff / 2);
            for (int xx = x - mid; xx <= x + mid; ++xx) {
                int xOff = Math.abs(xx - x);
                for (int zz = z - mid; zz <= z + mid; ++zz) {
                    int zOff = Math.abs(zz - z);
                    if (xOff == mid && zOff == mid && (yOff == 0 || random.nextBoundedInt(2) == 0)) {
                        continue;
                    }
                    if (!Block.solid[level.getBlockIdAt(xx, yy, zz)]) {

                        level.setBlockIdAt(xx, yy, zz, this.getLeafBlock());
                        level.setBlockDataAt(xx, yy, zz, this.getType());
                    }
                }
            }
        }
    }
 
Example 3
Source File: SpruceMegaTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectBigSpruceTree(1 / 4f, 5).placeObject(this.level, (int) (v.x = x), (int) (v.y = y), (int) (v.z = z), random);
    }
}
 
Example 4
Source File: SavannaTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectSavannaTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 5
Source File: NoiseGeneratorSimplexD.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public NoiseGeneratorSimplexD(NukkitRandom p_i45471_1_) {
    this.p = new int[512];
    this.xo = p_i45471_1_.nextDouble() * 256.0D;
    this.yo = p_i45471_1_.nextDouble() * 256.0D;
    this.zo = p_i45471_1_.nextDouble() * 256.0D;

    int i = 0;
    while (i < 256) {
        this.p[i] = i++;
    }

    for (int l = 0; l < 256; ++l) {
        int j = p_i45471_1_.nextBoundedInt(256 - l) + l;
        int k = this.p[l];
        this.p[l] = this.p[j];
        this.p[j] = k;
        this.p[l + 256] = this.p[l];
    }
}
 
Example 6
Source File: SpruceBigTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new ObjectBigSpruceTree(3 / 4f, 4).placeObject(this.level, (int) (v.x = x), (int) (v.y = y), (int) (v.z = z), random);
    }
}
 
Example 7
Source File: JungleTreePopulator.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    Vector3 v = new Vector3();

    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        new NewJungleTree(4 + random.nextBoundedInt(7)).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 8
Source File: PopulatorTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    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);
        int y = this.getHighestWorkableBlock(x, z);
        if (y == -1) {
            continue;
        }
        ObjectTree.growTree(this.level, x, y, z, random, this.type);
    }
}
 
Example 9
Source File: ObjectSpruceTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void placeLeaves(ChunkManager level, int topSize, int lRadius, int x, int y, int z, NukkitRandom random)   {
    int radius = random.nextBoundedInt(2);
    int maxR = 1;
    int minR = 0;

    for (int yy = 0; yy <= topSize; ++yy) {
        int yyy = y + this.treeHeight - yy;

        for (int xx = x - radius; xx <= x + radius; ++xx) {
            int xOff = Math.abs(xx - x);
            for (int zz = z - radius; zz <= z + radius; ++zz) {
                int zOff = Math.abs(zz - z);
                if (xOff == radius && zOff == radius && radius > 0) {
                    continue;
                }

                if (!Block.solid[level.getBlockIdAt(xx, yyy, zz)]) {
                    level.setBlockAt(xx, yyy, zz, this.getLeafBlock(), this.getType());
                }
            }
        }

        if (radius >= maxR) {
            radius = minR;
            minR = 1;
            if (++maxR > lRadius) {
                maxR = lRadius;
            }
        } else {
            ++radius;
        }
    }
}
 
Example 10
Source File: MushroomPopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populateCount(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) {
    int x = (chunkX << 4) | random.nextBoundedInt(16);
    int z = (chunkZ << 4) | random.nextBoundedInt(16);
    int y = this.getHighestWorkableBlock(level, x, z, chunk);
    if (y != -1) {
        new BigMushroom(type).generate(level, random, new Vector3(x, y, z));
    }
}
 
Example 11
Source File: PopulatorTallSugarcane.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);

        if (y != -1 && this.canSugarcaneStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.SUGARCANE_BLOCK);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 12
Source File: PopulatorGrass.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);

        if (y != -1 && this.canGrassStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.TALL_GRASS);
            this.level.setBlockDataAt(x, y, z, 0);
        }
    }
}
 
Example 13
Source File: ObjectTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void growTree(ChunkManager level, int x, int y, int z, NukkitRandom random, int type) {
    ObjectTree tree;
    switch (type) {
        case BlockSapling.SPRUCE:
            if (random.nextBoundedInt(39) == 0) {
                tree = new ObjectSpruceTree();
            } else {
                tree = new ObjectSpruceTree();
            }
            break;
        case BlockSapling.BIRCH:
            if (random.nextBoundedInt(39) == 0) {
                tree = new ObjectTallBirchTree();
            } else {
                tree = new ObjectBirchTree();
            }
            break;
        case BlockSapling.JUNGLE:
            tree = new ObjectJungleTree();
            break;
        case BlockSapling.OAK:
        default:
            tree = new ObjectOakTree();
            //todo: more complex treeeeeeeeeeeeeeeee
            break;
    }

    if (tree.canPlaceObject(level, x, y, z, random)) {
        tree.placeObject(level, x, y, z, random);
    }
}
 
Example 14
Source File: PopulatorSugarcane.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
    this.level = level;
    int amount = random.nextBoundedInt(this.randomAmount + 1) + this.baseAmount;
    for (int i = 0; i < amount; ++i) {
        int x = NukkitMath.randomRange(random, chunkX * 16, chunkX * 16 + 15);
        int z = NukkitMath.randomRange(random, chunkZ * 16, chunkZ * 16 + 15);
        int y = this.getHighestWorkableBlock(x, z);

        if (y != -1 && this.canSugarcaneStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.SUGARCANE_BLOCK);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 15
Source File: ObjectTallGrass.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random) {
    for (int i = 0; i < 128; ++i) {
        int num = 0;

        int x = pos.getFloorX();
        int y = pos.getFloorY() + 1;
        int z = pos.getFloorZ();

        while (true) {
            if (num >= i / 16) {
                if (level.getBlockIdAt(x, y, z) == Block.AIR) {
                    if (random.nextBoundedInt(8) == 0) {
                        //porktodo: biomes have specific flower types that can grow in them
                        if (random.nextBoolean()) {
                            level.setBlockAt(x, y, z, Block.DANDELION);
                        } else {
                            level.setBlockAt(x, y, z, Block.POPPY);
                        }
                    } else {
                        level.setBlockAt(x, y, z, Block.TALL_GRASS, 1);
                    }
                }

                break;
            }

            x += random.nextRange(-1, 1);
            y += random.nextRange(-1, 1) * random.nextBoundedInt(3) / 2;
            z += random.nextRange(-1, 1);

            if (level.getBlockIdAt(x, y - 1, z) != Block.GRASS || y > 255 || y < 0) {
                break;
            }

            ++num;
        }
    }
}
 
Example 16
Source File: ObjectTree.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public static void growTree(ChunkManager level, int x, int y, int z, NukkitRandom random, int type) {
    ObjectTree tree;
    switch (type) {
        case BlockSapling.SPRUCE:
            if (random.nextBoundedInt(39) == 0) {
                tree = new ObjectSpruceTree();
            } else {
                tree = new ObjectSpruceTree();
            }
            break;
        case BlockSapling.BIRCH:
            if (random.nextBoundedInt(39) == 0) {
                tree = new ObjectTallBirchTree();
            } else {
                tree = new ObjectBirchTree();
            }
            break;
        case BlockSapling.JUNGLE:
            tree = new ObjectJungleTree();
            break;
        case BlockSapling.OAK:
        default:
            tree = new ObjectOakTree();
            //todo: more complex treeeeeeeeeeeeeeeee
            break;
    }

    if (tree.canPlaceObject(level, x, y, z, random)) {
        tree.placeObject(level, x, y, z, random);
    }
}
 
Example 17
Source File: ObjectJungleTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(6) + 4;
    super.placeObject(level, x, y, z, random);
}
 
Example 18
Source File: ObjectTallBirchTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(3) + 10;
    super.placeObject(level, x, y, z, random);
}
 
Example 19
Source File: ObjectBirchTree.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(2) + 5;
    super.placeObject(level, x, y, z, random);
}
 
Example 20
Source File: ObjectTallBirchTree.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void placeObject(ChunkManager level, int x, int y, int z, NukkitRandom random) {
    this.treeHeight = random.nextBoundedInt(3) + 10;
    super.placeObject(level, x, y, z, random);
}