Java Code Examples for cn.nukkit.block.Block#GRASS

The following examples show how to use cn.nukkit.block.Block#GRASS . 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: ObjectTallGrass.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) {
    int[][] arr = {
            {Block.DANDELION, 0},
            {Block.POPPY, 0},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1}
    };
    int arrC = arr.length - 1;
    for (int c = 0; c < count; c++) {
        int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius));
        int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius));

        if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) {
            int[] t = arr[random.nextRange(0, arrC)];
            level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]);
            level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]);
        }
    }
}
 
Example 2
Source File: ObjectTallGrass.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) {
    int[][] arr = {
            {Block.DANDELION, 0},
            {Block.POPPY, 0},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1},
            {Block.TALL_GRASS, 1}
    };
    int arrC = arr.length - 1;
    for (int c = 0; c < count; c++) {
        int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius));
        int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius));

        if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) {
            int[] t = arr[random.nextRange(0, arrC)];
            level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]);
            level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]);
        }
    }
}
 
Example 3
Source File: PopulatorTree.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 4
Source File: JungleTreePopulator.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 5
Source File: HugeTreesGenerator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
/**
 * returns whether or not there is dirt underneath the block where the tree will be grown.
 * It also generates dirt around the block in a 2x2 square if there is dirt underneath the blockpos.
 */
private boolean ensureDirtsUnderneath(Vector3 pos, ChunkManager worldIn) {
    Vector3 blockpos = pos.down();
    int block = worldIn.getBlockIdAt((int) blockpos.x, (int) blockpos.y, (int) blockpos.z);

    if ((block == Block.GRASS || block == Block.DIRT) && pos.getY() >= 2) {
        this.setDirtAt(worldIn, blockpos);
        this.setDirtAt(worldIn, blockpos.east());
        this.setDirtAt(worldIn, blockpos.south());
        this.setDirtAt(worldIn, blockpos.south().east());
        return true;
    } else {
        return false;
    }
}
 
Example 6
Source File: SpruceBigTreePopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 255; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 7
Source File: JungleBigTreePopulator.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 8
Source File: JungleTreePopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 255; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 9
Source File: MushroomPopulator.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 10
Source File: SavannaTreePopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 11
Source File: DarkOakTreePopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 12
Source File: MushroomPopulator.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 127; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 13
Source File: PopulatorTree.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private int getHighestWorkableBlock(int x, int z) {
    int y;
    for (y = 254; y > 0; --y) {
        int b = this.level.getBlockIdAt(x, y, z);
        if (b == Block.DIRT || b == Block.GRASS) {
            break;
        } else if (b != Block.AIR && b != Block.SNOW_LAYER) {
            return -1;
        }
    }

    return ++y;
}
 
Example 14
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 15
Source File: PopulatorGrass.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
private boolean canGrassStay(int x, int y, int z) {
    int b = this.level.getBlockIdAt(x, y, z);
    return (b == Block.AIR || b == Block.SNOW_LAYER) && this.level.getBlockIdAt(x, y - 1, z) == Block.GRASS;
}
 
Example 16
Source File: GrassyBiome.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSurfaceBlock() {
    return Block.GRASS;
}
 
Example 17
Source File: GrassyBiome.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public int getSurfaceBlock() {
    return Block.GRASS;
}
 
Example 18
Source File: PopulatorSugarcane.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
private boolean canSugarcaneStay(int x, int y, int z) {
    int b = this.level.getBlockIdAt(x, y, z);
    int c = this.level.getBlockIdAt(x, y - 1, z);
    return (b == Block.AIR) && (c == Block.SAND || c == Block.GRASS) && this.findWater(x, y - 1, z);
}
 
Example 19
Source File: PopulatorSugarcane.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private boolean canSugarcaneStay(int x, int y, int z) {
    int b = this.level.getBlockIdAt(x, y, z);
    int c = this.level.getBlockIdAt(x, y - 1, z);
    return (b == Block.AIR) && (c == Block.SAND || c == Block.GRASS) && this.findWater(x, y - 1, z);
}
 
Example 20
Source File: PopulatorGrass.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private boolean canGrassStay(int x, int y, int z) {
    int b = this.level.getBlockIdAt(x, y, z);
    return (b == Block.AIR || b == Block.SNOW_LAYER) && this.level.getBlockIdAt(x, y - 1, z) == Block.GRASS;
}