Search in sources :

Example 91 with BlockState

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

the class MelonDecorator method populate.

@Override
public void populate(World world, Random random, Chunk source) {
    int sourceX = (source.getX() << 4) + random.nextInt(16);
    int sourceZ = (source.getZ() << 4) + random.nextInt(16);
    int sourceY = random.nextInt(world.getSeaLevel() << 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);
        if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS_BLOCK) {
            BlockState state = world.getBlockAt(x, y, z).getState();
            state.setType(Material.MELON);
            // TODO: 1.13 block data
            state.setData(new MaterialData(Material.MELON));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) MaterialData(org.bukkit.material.MaterialData)

Example 92 with BlockState

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

the class OreVein method generate.

@Override
public boolean 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;
    boolean succeeded = false;
    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 radiusH = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        double radiusV = (Math.sin(i * (float) Math.PI / amount) + 1 * q + 1) / 2.0D;
        for (int x = (int) (originX - radiusH); x <= (int) (originX + radiusH); x++) {
            // scale the center of x to the range [-1, 1] within the circle
            double squaredNormalizedX = normalizedSquaredCoordinate(originX, radiusH, x);
            if (squaredNormalizedX >= 1) {
                continue;
            }
            for (int y = (int) (originY - radiusV); y <= (int) (originY + radiusV); y++) {
                double squaredNormalizedY = normalizedSquaredCoordinate(originY, radiusV, y);
                if (squaredNormalizedX + squaredNormalizedY >= 1) {
                    continue;
                }
                for (int z = (int) (originZ - radiusH); z <= (int) (originZ + radiusH); z++) {
                    double squaredNormalizedZ = normalizedSquaredCoordinate(originZ, radiusH, z);
                    Block block = world.getBlockAt(x, y, z);
                    if (squaredNormalizedX + squaredNormalizedY + squaredNormalizedZ < 1 && block.getType() == targetType) {
                        BlockState state = block.getState();
                        state.setType(type);
                        state.setData(data);
                        state.update(true, false);
                        succeeded = true;
                    }
                }
            }
        }
    }
    return succeeded;
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block)

Example 93 with BlockState

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

the class StoneBoulder method generate.

@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean groundReached = false;
    while (sourceY > 3) {
        sourceY--;
        Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
        if (block.isEmpty()) {
            continue;
        }
        if (GROUND_TYPES.contains(block.getType())) {
            groundReached = true;
            sourceY++;
            break;
        }
    }
    if (!groundReached || !world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
        return false;
    }
    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;
        float fsquared = f * f;
        for (int x = -radiusX; x <= radiusX; x++) {
            float xsquared = x * x;
            for (int z = -radiusZ; z <= radiusZ; z++) {
                float zsquared = z * z;
                for (int y = -radiusY; y <= radiusY; y++) {
                    if (xsquared + zsquared + y * y > fsquared) {
                        continue;
                    }
                    BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
                    if (!TerrainObject.killPlantAbove(state.getBlock())) {
                        // FIXME: Is it a bug to suppress the cobblestone beneath where a plant
                        // previously stood?!
                        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);
    }
    return true;
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 94 with BlockState

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

the class MegaPineTree method generatePodzolPatch.

private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ, World world) {
    for (int x = -2; x <= 2; x++) {
        for (int z = -2; z <= 2; z++) {
            if (Math.abs(x) == 2 && Math.abs(z) == 2) {
                continue;
            }
            for (int y = 2; y >= -3; y--) {
                Block block = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
                if (block.getType() == Material.GRASS_BLOCK || block.getType() == Material.DIRT) {
                    BlockState state = block.getState();
                    if (world.getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z).getType().isOccluding()) {
                        state.setType(Material.DIRT);
                    } else {
                        state.setType(Material.PODZOL);
                    }
                    state.update(true);
                } else if (!block.isEmpty() && sourceY + y < sourceY) {
                    break;
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block)

Example 95 with BlockState

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

the class StructureBuilder method createRandomItemsContainer.

/**
 * Sets the given block to a container and fills it with random items.
 *
 * @param pos a point relative to this structure's root point
 * @param random the PRNG to use
 * @param content the distribution to draw items from
 * @param container the container to place
 * @param maxStacks the maximum number of slots to fill
 * @return true if the container was placed and filled; false if {@code pos} is outside the
 *         builder's bounding box or {@link RandomItemsContent#fillContainer(Random, BlockState,
 *         int)} fails
 */
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, state, maxStacks);
    }
    return false;
}
Also used : BlockState(org.bukkit.block.BlockState) Vector(org.bukkit.util.Vector)

Aggregations

BlockState (org.bukkit.block.BlockState)127 Block (org.bukkit.block.Block)54 EventHandler (org.bukkit.event.EventHandler)35 Sign (org.bukkit.block.Sign)17 Location (org.bukkit.Location)16 World (org.bukkit.World)15 InventoryHolder (org.bukkit.inventory.InventoryHolder)14 Material (org.bukkit.Material)13 MaterialData (org.bukkit.material.MaterialData)13 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 CreatureSpawner (org.bukkit.block.CreatureSpawner)10 Player (org.bukkit.entity.Player)10 BlockFace (org.bukkit.block.BlockFace)9 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)7 Vector (org.bukkit.util.Vector)7 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)5 Chunk (org.bukkit.Chunk)5 CommandBlock (org.bukkit.block.CommandBlock)5 Skull (org.bukkit.block.Skull)5