Search in sources :

Example 1 with Dirt

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

the class TallRedwoodTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    int radius = 0;
    for (int y = loc.getBlockY() + height; y >= loc.getBlockY() + leavesHeight; y--) {
        // leaves are built from top to bottom
        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 || radius <= 0) && delegate.getBlockState(loc.getWorld(), x, y, z).getType() == Material.AIR) {
                    delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                }
            }
        }
        if (radius >= 1 && y == loc.getBlockY() + leavesHeight + 1) {
            radius--;
        } else if (radius < maxRadius) {
            radius++;
        }
    }
    // generate the trunk
    for (int y = 0; y < height - 1; y++) {
        Material type = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (type == Material.AIR || type == Material.LEAVES) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // 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 2 with Dirt

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

the class DarkOakTree 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 - random.nextInt(4);
    int twistCount = random.nextInt(3);
    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;
            // SELF, SOUTH, EAST, SOUTH EAST
            delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX, loc.getBlockY() + y, centerZ + 1, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX + 1, loc.getBlockY() + y, centerZ, Material.LOG_2, 1);
            delegate.setTypeAndRawData(loc.getWorld(), centerX + 1, loc.getBlockY() + y, centerZ + 1, Material.LOG_2, 1);
        }
    }
    // generates leaves
    for (int x = -2; x <= 0; x++) {
        for (int z = -2; z <= 0; z++) {
            if ((x != -1 || z != -2) && (x > -2 || z > -1)) {
                setLeaves(centerX + x, trunkTopY + 1, centerZ + z);
                setLeaves(1 + centerX - x, trunkTopY + 1, centerZ + z);
                setLeaves(centerX + x, trunkTopY + 1, 1 + centerZ - z);
                setLeaves(1 + centerX - x, trunkTopY + 1, 1 + centerZ - z);
            }
            setLeaves(centerX + x, trunkTopY - 1, centerZ + z);
            setLeaves(1 + centerX - x, trunkTopY - 1, centerZ + z);
            setLeaves(centerX + x, trunkTopY - 1, 1 + centerZ - z);
            setLeaves(1 + centerX - x, trunkTopY - 1, 1 + centerZ - z);
        }
    }
    // finish leaves below the canopy
    for (int x = -3; x <= 4; x++) {
        for (int z = -3; z <= 4; z++) {
            if (Math.abs(x) < 3 || Math.abs(z) < 3) {
                setLeaves(centerX + x, trunkTopY, centerZ + z);
            }
        }
    }
    // generates some trunk excrescences
    for (int x = -1; x <= 2; x++) {
        for (int z = -1; z <= 2; z++) {
            if ((x == -1 || z == -1 || x == 2 || z == 2) && random.nextInt(3) == 0) {
                for (int y = 0; y < random.nextInt(3) + 2; y++) {
                    Material material = delegate.getBlockState(loc.getWorld(), loc.getBlockX() + x, trunkTopY - y - 1, loc.getBlockZ() + z).getType();
                    if (material == Material.AIR || material == Material.LEAVES) {
                        delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX() + x, trunkTopY - y - 1, loc.getBlockZ() + z, Material.LOG_2, 1);
                    }
                }
                // leaves below the canopy
                for (int i = -1; i <= 1; i++) {
                    for (int j = -1; j <= 1; j++) {
                        setLeaves(centerX + x + i, trunkTopY, centerZ + z + j);
                    }
                }
                for (int i = -2; i <= 2; i++) {
                    for (int j = -2; j <= 2; j++) {
                        if (Math.abs(i) < 2 || Math.abs(j) < 2) {
                            setLeaves(centerX + x + i, trunkTopY - 1, centerZ + z + j);
                        }
                    }
                }
            }
        }
    }
    // 50% chance to have a 4 leaves cap on the center of the canopy
    if (random.nextInt(2) == 0) {
        setLeaves(centerX, trunkTopY + 2, centerZ);
        setLeaves(centerX + 1, trunkTopY + 2, centerZ);
        setLeaves(centerX + 1, trunkTopY + 2, centerZ + 1);
        setLeaves(centerX, trunkTopY + 2, centerZ + 1);
    }
    // block below trunk is always dirt (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);
    return true;
}
Also used : Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material)

Example 3 with Dirt

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

the class GenericTree method generate.

public boolean generate() {
    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 = 1 - 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) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // 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 4 with Dirt

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

the class MegaPineTree method generatePodzolPatch.

private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ) {
    for (int x = -2; x <= 2; x++) {
        for (int z = -2; z <= 2; z++) {
            if (Math.abs(x) != 2 || Math.abs(z) != 2) {
                for (int y = 2; y >= -3; y--) {
                    Block block = loc.getWorld().getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
                    if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) {
                        BlockState state = block.getState();
                        state.setType(Material.DIRT);
                        DirtType dirtType = DirtType.PODZOL;
                        if (loc.getWorld().getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z).getType().isOccluding()) {
                            dirtType = DirtType.NORMAL;
                        }
                        state.setData(new Dirt(dirtType));
                        state.update(true);
                    } else if (!block.isEmpty() && sourceY + y < sourceY) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : DirtType(org.bukkit.material.types.DirtType) BlockState(org.bukkit.block.BlockState) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block)

Example 5 with Dirt

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

the class RedwoodTree method generate.

@Override
public boolean generate() {
    if (!canHeightFit() || !canPlaceOn() || !canPlace()) {
        return false;
    }
    // generate the leaves
    int radius = random.nextInt(2);
    int peakRadius = 1;
    int minRadius = 0;
    for (int y = loc.getBlockY() + height; y >= loc.getBlockY() + leavesHeight; y--) {
        // leaves are built from top to bottom
        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 || radius <= 0) && delegate.getBlockState(loc.getWorld(), x, y, z).getType() == Material.AIR) {
                    delegate.setTypeAndRawData(loc.getWorld(), x, y, z, Material.LEAVES, leavesType);
                }
            }
        }
        if (radius >= peakRadius) {
            radius = minRadius;
            // after the peak radius is reached once, the min radius increases
            minRadius = 1;
            // the peak radius increases each time it's reached
            peakRadius++;
            if (peakRadius > maxRadius) {
                peakRadius = maxRadius;
            }
        } else {
            radius++;
        }
    }
    // generate the trunk
    for (int y = 0; y < height - random.nextInt(3); y++) {
        Material type = delegate.getBlockState(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ()).getType();
        if (overridables.contains(type)) {
            delegate.setTypeAndRawData(loc.getWorld(), loc.getBlockX(), loc.getBlockY() + y, loc.getBlockZ(), Material.LOG, logType);
        }
    }
    // 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)

Aggregations

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