Search in sources :

Example 56 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class OreVein method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    float angle = random.nextFloat() * (float) Math.PI;
    double dx1 = sourceX + Math.sin(angle) * amount / 8.0F;
    double dx2 = sourceX - Math.sin(angle) * amount / 8.0F;
    double dz1 = sourceZ + Math.cos(angle) * amount / 8.0F;
    double dz2 = sourceZ - Math.cos(angle) * amount / 8.0F;
    double dy1 = sourceY + random.nextInt(3) - 2;
    double dy2 = sourceY + random.nextInt(3) - 2;
    for (int i = 0; i < amount; i++) {
        double originX = dx1 + (dx2 - dx1) * i / amount;
        double originY = dy1 + (dy2 - dy1) * i / amount;
        double originZ = dz1 + (dz2 - dz1) * i / amount;
        double q = random.nextDouble() * amount / 16.0D;
        double hRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        double vRadius = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        for (int x = (int) (originX - hRadius); x <= (int) (originX - hRadius); x++) {
            double pX = (x + 0.5D - originX) / hRadius;
            pX *= pX;
            if (pX < 1) {
                for (int y = (int) (originY - vRadius); y <= (int) (originY + vRadius); y++) {
                    double pY = (y + 0.5D - originY) / vRadius;
                    pY *= pY;
                    if (pX + pY < 1) {
                        for (int z = (int) (originZ - hRadius); z <= (int) (originZ + hRadius); z++) {
                            double pZ = (z + 0.5D - originZ) / hRadius;
                            pZ *= pZ;
                            if (pX + pY + pZ < 1 && world.getBlockAt(x, y, z).getType() == targetType) {
                                BlockState state = world.getBlockAt(x, y, z).getState();
                                state.setType(type);
                                state.setData(data);
                                state.update(true);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState)

Example 57 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class StoneBoulder method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean groundReached = false;
    while (!groundReached && sourceY > 3) {
        Block block = world.getBlockAt(sourceX, sourceY - 1, sourceZ);
        if (!block.isEmpty()) {
            for (Material mat : GROUND_TYPES) {
                if (mat == block.getType()) {
                    groundReached = true;
                    sourceY++;
                    break;
                }
            }
        }
        sourceY--;
    }
    if (groundReached && world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
        for (int i = 0; i < 3; i++) {
            int radiusX = random.nextInt(2);
            int radiusZ = random.nextInt(2);
            int radiusY = random.nextInt(2);
            float f = (radiusX + radiusZ + radiusY) * 0.333F + 0.5F;
            for (int x = -radiusX; x <= radiusX; x++) {
                for (int z = -radiusZ; z <= radiusZ; z++) {
                    for (int y = -radiusY; y <= radiusY; y++) {
                        if (x * x + z * z + y * y <= f * f) {
                            BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
                            Block blockAbove = state.getBlock().getRelative(BlockFace.UP);
                            for (Material mat : PLANT_TYPES) {
                                if (blockAbove.getType() == mat) {
                                    if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
                                        blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
                                    }
                                    blockAbove.setType(Material.AIR);
                                    break;
                                }
                            }
                            state.setType(Material.MOSSY_COBBLESTONE);
                            state.setData(new MaterialData(Material.MOSSY_COBBLESTONE));
                            state.update(true);
                        }
                    }
                }
            }
            sourceX += random.nextInt(4) - 1;
            sourceZ += random.nextInt(4) - 1;
            sourceY -= random.nextInt(2);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 58 with BlockState

use of org.bukkit.block.BlockState 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 59 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class StructureBuilder method createRandomItemsContainer.

public boolean createRandomItemsContainer(Vector pos, Random random, RandomItemsContent content, DirectionalContainer container, int maxStacks) {
    Vector vec = translate(pos);
    if (boundingBox.isVectorInside(vec)) {
        BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
        delegate.backupBlockState(state.getBlock());
        state.setType(container.getItemType());
        state.setData(container);
        state.update(true);
        return content.fillContainer(random, container, state, maxStacks);
    }
    return false;
}
Also used : BlockState(org.bukkit.block.BlockState) Vector(org.bukkit.util.Vector)

Aggregations

BlockState (org.bukkit.block.BlockState)59 Block (org.bukkit.block.Block)26 EventHandler (org.bukkit.event.EventHandler)15 MaterialData (org.bukkit.material.MaterialData)12 Location (org.bukkit.Location)11 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)5 World (org.bukkit.World)5 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 ItemStack (org.bukkit.inventory.ItemStack)4 GlowBlock (net.glowstone.block.GlowBlock)3 HashMap (java.util.HashMap)2 Handler (me.botsko.prism.actions.Handler)2 ChangeResult (me.botsko.prism.appliers.ChangeResult)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 Element (net.aufdemrand.denizencore.objects.Element)2