Search in sources :

Example 6 with Dirt

use of org.bukkit.material.Dirt in project Glowstone by GlowstoneMC.

the class SwampTree method generate.

@Override
public boolean generate() {
    while (loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.WATER || loc.getBlock().getRelative(BlockFace.DOWN).getType() == Material.STATIONARY_WATER) {
        loc.subtract(0, 1, 0);
    }
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    for (int y = loc.getBlockY() + height - 3; y <= loc.getBlockY() + height; y++) {
        int n = y - (loc.getBlockY() + height);
        int radius = 2 - n / 2;
        for (int x = loc.getBlockX() - radius; x <= loc.getBlockX() + radius; x++) {
            for (int z = loc.getBlockZ() - radius; z <= loc.getBlockZ() + radius; z++) {
                if (Math.abs(x - loc.getBlockX()) != radius || Math.abs(z - loc.getBlockZ()) != radius || random.nextBoolean() && n != 0) {
                    Material material = delegate.getBlockState(loc.getWorld(), x, y, z).getType();
                    if (material == Material.AIR || material == Material.LEAVES) {
                        delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                    }
                }
            }
        }
    }
    // generate the trunk
    for (int y = 0; y < height; y++) {
        Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (material == Material.AIR || material == Material.LEAVES || material == Material.WATER || material == Material.STATIONARY_WATER) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // add some vines on the leaves
    addVinesOnLeaves();
    // block below trunk is always dirt
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 7 with Dirt

use of org.bukkit.material.Dirt in project Glowstone by GlowstoneMC.

the class MushroomDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    if (random.nextFloat() < density) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = world.getHighestBlockYAt(sourceX, sourceZ);
        sourceY = fixedHeightRange ? sourceY : random.nextInt(sourceY << 1);
        for (int i = 0; i < 64; i++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY + random.nextInt(4) - random.nextInt(4);
            Block block = world.getBlockAt(x, y, z);
            Block blockBelow = world.getBlockAt(x, y - 1, z);
            if (y < 255 && block.getType() == Material.AIR && ((blockBelow.getType() == Material.GRASS || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() != DirtType.PODZOL) && block.getLightLevel() < 13 || blockBelow.getType() == Material.MYCEL || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() == DirtType.PODZOL)) {
                BlockState state = block.getState();
                state.setType(type);
                state.setData(new MaterialData(type));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 8 with Dirt

use of org.bukkit.material.Dirt in project Glowstone by GlowstoneMC.

the class AcaciaTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // random direction
    float d = (float) (random.nextFloat() * Math.PI * 2.0F);
    int dx = (int) (Math.cos(d) + 1.5F) - 1;
    int dz = (int) (Math.sin(d) + 1.5F) - 1;
    if (Math.abs(dx) > 0 && Math.abs(dz) > 0) {
        // reduce possible directions to NESW
        if (random.nextBoolean()) {
            dx = 0;
        } else {
            dz = 0;
        }
    }
    int twistHeight = height - 1 - random.nextInt(4);
    int twistCount = random.nextInt(3) + 1;
    int centerX = loc.getBlockX(), centerZ = loc.getBlockZ();
    int trunkTopY = 0;
    // generates the trunk
    for (int y = 0; y < height; y++) {
        // trunk twists
        if (twistCount > 0 && y >= twistHeight) {
            centerX += dx;
            centerZ += dz;
            twistCount--;
        }
        Material material = delegate.getBlockState(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ).getType();
        if (material == Material.AIR || material == Material.LEAVES) {
            trunkTopY = loc.getBlockY() + y;
            delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ, Material.LOG_2, 0);
        }
    }
    // generates leaves
    for (int x = -3; x <= 3; x++) {
        for (int z = -3; z <= 3; z++) {
            if (Math.abs(x) < 3 || Math.abs(z) < 3) {
                setLeaves(centerX + x, trunkTopY, centerZ + z);
            }
            if (Math.abs(x) < 2 && Math.abs(z) < 2) {
                setLeaves(centerX + x, trunkTopY + 1, centerZ + z);
            }
            if (Math.abs(x) == 2 && Math.abs(z) == 0 || Math.abs(x) == 0 && Math.abs(z) == 2) {
                setLeaves(centerX + x, trunkTopY + 1, centerZ + z);
            }
        }
    }
    // try to choose a different direction for second branching and canopy
    d = (float) (random.nextFloat() * Math.PI * 2.0F);
    int dxB = (int) (Math.cos(d) + 1.5F) - 1;
    int dzB = (int) (Math.sin(d) + 1.5F) - 1;
    if (Math.abs(dxB) > 0 && Math.abs(dzB) > 0) {
        if (random.nextBoolean()) {
            dxB = 0;
        } else {
            dzB = 0;
        }
    }
    if (dx != dxB || dz != dzB) {
        centerX = loc.getBlockX();
        centerZ = loc.getBlockZ();
        int branchHeight = twistHeight - 1 - random.nextInt(2);
        twistCount = random.nextInt(3) + 1;
        trunkTopY = 0;
        // generates the trunk
        for (int y = branchHeight + 1; y < height; y++) {
            if (twistCount > 0) {
                centerX += dxB;
                centerZ += dzB;
                Material material = delegate.getBlockState(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ).getType();
                if (material == Material.AIR || material == Material.LEAVES) {
                    trunkTopY = loc.getBlockY() + y;
                    delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ, Material.LOG_2, 0);
                }
                twistCount--;
            }
        }
        // generates the leaves
        if (trunkTopY > 0) {
            for (int x = -2; x <= 2; x++) {
                for (int z = -2; z <= 2; z++) {
                    if (Math.abs(x) < 2 || Math.abs(z) < 2) {
                        setLeaves(centerX + x, trunkTopY, centerZ + z);
                    }
                }
            }
            for (int x = -1; x <= 1; x++) {
                for (int z = -1; z <= 1; z++) {
                    setLeaves(centerX + x, trunkTopY + 1, centerZ + z);
                }
            }
        }
    }
    // block below trunk is always dirt
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 9 with Dirt

use of org.bukkit.material.Dirt in project Glowstone by GlowstoneMC.

the class SugarCane method generate.

public void generate(World world, Random random, int x, int y, int z) {
    if (world.getBlockAt(x, y, z).isEmpty()) {
        Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
        boolean adjacentWater = false;
        for (BlockFace face : FACES) {
            // needs a directly adjacent water block
            if (block.getRelative(face).getType() == Material.STATIONARY_WATER || block.getRelative(face).getType() == Material.WATER) {
                adjacentWater = true;
                break;
            }
        }
        if (adjacentWater) {
            for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) {
                block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN);
                if (block.getType() == Material.SUGAR_CANE_BLOCK || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState().getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) {
                    Block caneBlock = block.getRelative(BlockFace.UP);
                    if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
                        return;
                    }
                    BlockState state = caneBlock.getState();
                    state.setType(Material.SUGAR_CANE_BLOCK);
                    state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK));
                    state.update(true);
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 10 with Dirt

use of org.bukkit.material.Dirt in project Glowstone by GlowstoneMC.

the class MegaJungleTree method generateDirtBelowTrunk.

protected void generateDirtBelowTrunk() {
    // SELF, SOUTH, EAST, SOUTH EAST
    Dirt dirt = new Dirt(DirtType.NORMAL);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ() + 1, Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX() + 1, loc.getBlockY() - 1, loc.getBlockZ(), Material.DIRT, dirt);
    delegate.setTypeAndData(loc.getWorld(), loc.getBlockX() + 1, loc.getBlockY() - 1, loc.getBlockZ() + 1, Material.DIRT, dirt);
}
Also used : Dirt(org.bukkit.material.Dirt)

Aggregations

Dirt (org.bukkit.material.Dirt)12 Material (org.bukkit.Material)7 Block (org.bukkit.block.Block)3 BlockState (org.bukkit.block.BlockState)3 MaterialData (org.bukkit.material.MaterialData)3 GlowBlock (net.glowstone.block.GlowBlock)1 BlockFace (org.bukkit.block.BlockFace)1 DirtType (org.bukkit.material.types.DirtType)1