Search in sources :

Example 36 with BlockFace

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

the class BlockBed method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    if (block.getType() == Material.BED_BLOCK) {
        BlockFace direction = ((Bed) block.getState().getData()).getFacing();
        GlowBlock headBlock = block.getRelative(direction);
        headBlock.setType(Material.BED_BLOCK);
        GlowBlockState headBlockState = headBlock.getState();
        MaterialData data = headBlockState.getData();
        ((Bed) data).setHeadOfBed(true);
        ((Bed) data).setFacingDirection(direction);
        headBlockState.setData(data);
        headBlockState.update(true);
    }
}
Also used : Bed(org.bukkit.material.Bed) GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 37 with BlockFace

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

the class BlockDirectional method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    // the direction of the block
    BlockFace faceHead = calculateFace(player, state);
    state.setRawData((byte) getRawFace(opposite ? faceHead.getOppositeFace() : faceHead));
}
Also used : BlockFace(org.bukkit.block.BlockFace)

Example 38 with BlockFace

use of org.bukkit.block.BlockFace 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 39 with BlockFace

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

the class TaxicabBlockIterator method hasNext.

@Override
public boolean hasNext() {
    if (validBlockCount >= maxBlocks) {
        return false;
    }
    // Note that the pending analysis queue will always contain at least one element: the end of distance marker.
    while (nextValidBlocks.isEmpty() && currentDistance <= maxDistance && pendingAnalysis.size() >= 2) {
        Object object = pendingAnalysis.remove();
        // If we find the end of distance marker, we'll increase the distance, and then we'll re-add it to the end.
        if (object == DistanceMarker.INSTANCE) {
            pendingAnalysis.add(object);
            currentDistance++;
            continue;
        }
        // If it wasn't the EoD marker, it must be a block. We'll look now for valid blocks around it.
        Block block = (Block) object;
        for (BlockFace face : VALID_FACES) {
            Block near = block.getRelative(face);
            // Only analyse the block if we haven't checked it yet.
            if (usedBlocks.add(near) && isValid(near)) {
                nextValidBlocks.add(near);
                pendingAnalysis.add(near);
            }
        }
    }
    return !nextValidBlocks.isEmpty();
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block)

Example 40 with BlockFace

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

the class BlockStem method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // in order to grow naturally (vanilla behavior)
    if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
        int cropState = block.getData();
        if (cropState >= CropState.RIPE.ordinal()) {
            // check around there's not already a fruit
            if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
                return;
            }
            // produce a fruit if possible
            int n = random.nextInt(4);
            BlockFace face;
            switch(n) {
                case 1:
                    face = BlockFace.WEST;
                    break;
                case 2:
                    face = BlockFace.NORTH;
                    break;
                case 3:
                    face = BlockFace.SOUTH;
                    break;
                default:
                    face = BlockFace.EAST;
            }
            GlowBlock targetBlock = block.getRelative(face);
            GlowBlockState targetBlockState = targetBlock.getState();
            GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
            if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
                targetBlockState.setType(fruitType);
                if (fruitType == Material.PUMPKIN) {
                    targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
                }
                targetBlockState.update(true);
            }
        } else {
            cropState++;
            GlowBlockState state = block.getState();
            state.setRawData((byte) cropState);
            BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
            EventFactory.callEvent(growEvent);
            if (!growEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
    // we check for insufficient light on the block itself, then drop
    if (block.getLightLevel() < 8) {
        block.breakNaturally();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) Pumpkin(org.bukkit.material.Pumpkin) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Aggregations

BlockFace (org.bukkit.block.BlockFace)58 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)20 MaterialData (org.bukkit.material.MaterialData)10 Vector (org.bukkit.util.Vector)9 BlockState (org.bukkit.block.BlockState)8 ArrayList (java.util.ArrayList)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 ItemTable (net.glowstone.block.ItemTable)5 Sign (org.bukkit.block.Sign)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Material (org.bukkit.Material)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 List (java.util.List)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2