Search in sources :

Example 1 with Bisected

use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
    headBlockState.setType(block.getType());
    Bisected upper = getCastedBlockData(Bisected.class, block.getType().createBlockData());
    upper.setHalf(Half.TOP);
    headBlockState.setBlockData(upper);
    headBlockState.update(true);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) Bisected(org.bukkit.block.data.Bisected)

Example 2 with Bisected

use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method blockDestroy.

@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
    Bisected data = getCastedBlockData(Bisected.class, block.getBlockData());
    if (data.getHalf() == Half.TOP) {
        GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
        if (!getMaterials().contains(block.getType())) {
            return;
        }
        blockUnder.setType(Material.AIR);
    } else {
        GlowBlock blockTop = block.getRelative(BlockFace.UP);
        if (!getMaterials().contains(block.getType())) {
            return;
        }
        blockTop.setType(Material.AIR);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Bisected(org.bukkit.block.data.Bisected)

Example 3 with Bisected

use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method canAbsorb.

@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
    BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
    Material species = block.getType();
    if (species == Material.TALL_GRASS || species == Material.LARGE_FERN) {
        if (holdingType != null && holdingType.canPlaceAt(null, block, face)) {
            block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
        }
        return true;
    }
    Bisected data = getCastedBlockData(Bisected.class, block.getBlockData());
    if (data.getHalf() == Half.TOP) {
        GlowBlock under = block.getRelative(BlockFace.DOWN);
        if (getMaterials().contains(under.getType())) {
            Material underSpecies = under.getType();
            if (underSpecies == Material.TALL_GRASS || underSpecies == Material.LARGE_FERN) {
                if (holdingType != null && holdingType.canPlaceAt(null, block, face)) {
                    under.setType(Material.AIR, (byte) 0, false);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Material(org.bukkit.Material) Bisected(org.bukkit.block.data.Bisected)

Example 4 with Bisected

use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.

the class DoubleTallPlant method generate.

/**
 * Generates up to 64 plants around the given point.
 *
 * @return true if at least one plant was successfully generated
 */
@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean placed = false;
    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 topBlock = block.getRelative(BlockFace.UP);
        if (y < 255 && block.isEmpty() && topBlock.isEmpty() && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS_BLOCK) {
            BlockState state = block.getState();
            state.setType(species);
            Bisected lower = (Bisected) species.createBlockData();
            lower.setHalf(Half.BOTTOM);
            state.setBlockData(lower);
            state.update(true);
            state = topBlock.getState();
            state.setType(species);
            Bisected upper = (Bisected) species.createBlockData();
            upper.setHalf(Half.TOP);
            state.setBlockData(upper);
            placed = true;
        }
    }
    return placed;
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Bisected(org.bukkit.block.data.Bisected)

Example 5 with Bisected

use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.

the class TerrainObject method killPlantAbove.

/**
 * Removes the grass, shrub, flower or mushroom directly above the given block, if present. Does
 * not drop an item.
 *
 * @param block the block to update
 * @return true if a plant was removed; false if none was present
 */
static boolean killPlantAbove(Block block) {
    Block blockAbove = block.getRelative(BlockFace.UP);
    BlockData blockAboveData = blockAbove.getBlockData();
    Material mat = blockAboveData.getMaterial();
    if (PLANT_TYPES.contains(mat)) {
        if (blockAboveData instanceof Bisected && ((Bisected) blockAboveData).getHalf() == Bisected.Half.BOTTOM) {
            // Large plant
            Block plantTop = blockAbove.getRelative(BlockFace.UP);
            BlockData plantTopData = plantTop.getBlockData();
            if (plantTopData.getMaterial() == mat && ((Bisected) plantTopData).getHalf() == Bisected.Half.TOP) {
                plantTop.setType(Material.AIR);
            }
        }
        blockAbove.setType(Material.AIR);
        return true;
    }
    return false;
}
Also used : Block(org.bukkit.block.Block) Material(org.bukkit.Material) BlockData(org.bukkit.block.data.BlockData) Bisected(org.bukkit.block.data.Bisected)

Aggregations

Bisected (org.bukkit.block.data.Bisected)7 Block (org.bukkit.block.Block)4 BlockData (org.bukkit.block.data.BlockData)3 GlowBlock (net.glowstone.block.GlowBlock)2 Material (org.bukkit.Material)2 BlockState (org.bukkit.block.BlockState)2 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)1 MaterialSwitchable (com.denizenscript.denizen.objects.properties.material.MaterialSwitchable)1 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)1 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 Location (org.bukkit.Location)1 Nameable (org.bukkit.Nameable)1 CommandBlock (org.bukkit.block.CommandBlock)1 CreatureSpawner (org.bukkit.block.CreatureSpawner)1 Sign (org.bukkit.block.Sign)1 Bed (org.bukkit.block.data.type.Bed)1 TrapDoor (org.bukkit.block.data.type.TrapDoor)1 NotNull (org.jetbrains.annotations.NotNull)1