Java Code Examples for cn.nukkit.math.NukkitMath#randomRange()

The following examples show how to use cn.nukkit.math.NukkitMath#randomRange() . 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: MushroomPopulator.java    From Jupiter 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 BigMushroom(type).generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 2
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 3
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 4
Source File: JungleBigTreePopulator.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 ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE)).generate(this.level, random, v.setComponents(x, y, z));
    }
}
 
Example 5
Source File: PopulatorFlower.java    From Jupiter 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;

    if (flowerTypes.size() == 0) {
        this.addType(Block.RED_FLOWER, BlockFlower.TYPE_POPPY);
        this.addType(Block.DANDELION, 0);
    }

    int endNum = this.flowerTypes.size();

    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.canFlowerStay(x, y, z)) {
            int[] type = this.flowerTypes.get(random.nextRange(0, endNum - 1));
            this.level.setBlockIdAt(x, y, z, type[0]);
            this.level.setBlockDataAt(x, y, z, type[1]);
        }
    }
}
 
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: 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 8
Source File: PopulatorFlower.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;

    if (flowerTypes.size() == 0) {
        this.addType(Block.RED_FLOWER, BlockFlower.TYPE_POPPY);
        this.addType(Block.DANDELION, 0);
    }

    int endNum = this.flowerTypes.size();

    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.canFlowerStay(x, y, z)) {
            int[] type = this.flowerTypes.get(random.nextRange(0, endNum - 1));
            this.level.setBlockIdAt(x, y, z, type[0]);
            this.level.setBlockDataAt(x, y, z, type[1]);
        }
    }
}
 
Example 9
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 10
Source File: JungleBigTreePopulator.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 ObjectJungleBigTree(10, 20, Block.get(BlockID.WOOD, BlockWood.JUNGLE), Block.get(BlockID.LEAVES, BlockLeaves.JUNGLE)).generate(this.level, random, v.setComponents(x, y, z));
    }
}
 
Example 11
Source File: SavannaTreePopulator.java    From Jupiter 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 ObjectSavannaTree().generate(level, random, v.setComponents(x, y, z));
    }
}
 
Example 12
Source File: PopulatorOre.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) {
    int sx = chunkX << 4;
    int ex = sx + 15;
    int sz = chunkZ << 4;
    int ez = sz + 15;
    for (OreType type : this.oreTypes) {
        for (int i = 0; i < type.clusterCount; i++) {
            int x = NukkitMath.randomRange(random, sx, ex);
            int z = NukkitMath.randomRange(random, sz, ez);
            int y = NukkitMath.randomRange(random, type.minHeight, type.maxHeight);
            if (level.getBlockIdAt(x, y, z) != replaceId) {
                continue;
            }
            type.spawn(level, random, replaceId, x, y, z);
        }
    }
}
 
Example 13
Source File: PopulatorCactus.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.canCactusStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.CACTUS);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 14
Source File: PopulatorSugarcane.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.canSugarcaneStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.SUGARCANE_BLOCK);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 15
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 16
Source File: PopulatorTallSugarcane.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.canSugarcaneStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.SUGARCANE_BLOCK);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 17
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 18
Source File: PopulatorLilyPad.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.canLilyPadStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.WATER_LILY);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}
 
Example 19
Source File: PopulatorTree.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) {
    this.level = level;
    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 < 3) {
        return;
    }
    ObjectTree.growTree(this.level, x, y, z, random, this.type);
}
 
Example 20
Source File: PopulatorDeadBush.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.canDeadBushStay(x, y, z)) {
            this.level.setBlockIdAt(x, y, z, Block.DEAD_BUSH);
            this.level.setBlockDataAt(x, y, z, 1);
        }
    }
}