Search in sources :

Example 1 with BlockFace

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

the class GlowChest method getInventory.

@Override
public Inventory getInventory() {
    GlowBlock me = getBlock();
    BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
    BlockFace attachedChest = blockChest.getAttachedChest(me);
    if (attachedChest != null) {
        Block nearbyBlock = me.getRelative(attachedChest);
        GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
        switch(attachedChest) {
            case SOUTH:
            case EAST:
                return new GlowDoubleChestInventory(this, nearbyChest);
            case WEST:
            case NORTH:
                return new GlowDoubleChestInventory(nearbyChest, this);
            default:
                GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
                return getBlockInventory();
        }
    }
    return getBlockInventory();
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockChest(net.glowstone.block.blocktype.BlockChest) BlockFace(org.bukkit.block.BlockFace) GlowDoubleChestInventory(net.glowstone.inventory.GlowDoubleChestInventory) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 2 with BlockFace

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

the class GlowBlock method applyPhysics.

/////////////////////////////////////////////////////////////////////////////
// Physics
/**
     * Notify this block and its surrounding blocks that this block has changed
     * type and data.
     *
     * @param oldType   the old block type
     * @param newTypeId the new block type
     * @param oldData   the old data
     * @param newData   the new data
     */
public void applyPhysics(Material oldType, int newTypeId, byte oldData, byte newData) {
    // notify the surrounding blocks that this block has changed
    ItemTable itemTable = ItemTable.instance();
    Material newType = Material.getMaterial(newTypeId);
    for (int y = -1; y <= 1; y++) {
        for (BlockFace face : LAYER) {
            if (y == 0 && face == BlockFace.SELF) {
                continue;
            }
            GlowBlock notify = getRelative(face.getModX(), face.getModY() + y, face.getModZ());
            BlockFace blockFace;
            if (y == 0) {
                blockFace = face.getOppositeFace();
            } else if (y == -1 && face == BlockFace.SELF) {
                blockFace = BlockFace.UP;
            } else if (y == 1 && face == BlockFace.SELF) {
                blockFace = BlockFace.DOWN;
            } else {
                blockFace = null;
            }
            BlockType notifyType = itemTable.getBlock(notify.getTypeId());
            if (notifyType != null) {
                notifyType.onNearBlockChanged(notify, blockFace, this, oldType, oldData, newType, newData);
            }
        }
    }
    BlockType type = itemTable.getBlock(oldType);
    if (type != null) {
        type.onBlockChanged(this, oldType, oldData, newType, newData);
    }
}
Also used : BlockType(net.glowstone.block.blocktype.BlockType) BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material)

Example 3 with BlockFace

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

the class CocoaTree method addCocoa.

private void addCocoa(int sourceX, int sourceY, int sourceZ) {
    if (height > 5 && random.nextInt(5) == 0) {
        for (int y = 0; y < 2; y++) {
            for (BlockFace cocoaFace : COCOA_FACES) {
                // rotate the 4 trunk faces
                if (random.nextInt(COCOA_FACES.length - y) == 0) {
                    // higher it is, more chances there is
                    CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)];
                    Block block = delegate.getBlockState(loc.getWorld(), sourceX, sourceY + height - 5 + y, sourceZ).getBlock().getRelative(cocoaFace);
                    delegate.setTypeAndData(loc.getWorld(), block.getX(), block.getY(), block.getZ(), Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace()));
                }
            }
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) CocoaPlantSize(org.bukkit.material.CocoaPlant.CocoaPlantSize) CocoaPlant(org.bukkit.material.CocoaPlant)

Example 4 with BlockFace

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

the class ItemItemFrame method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
    List<Message> spawnMessage = entity.createSpawnMessage();
    entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) List(java.util.List) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) ItemStack(org.bukkit.inventory.ItemStack) Message(com.flowpowered.network.Message) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame)

Example 5 with BlockFace

use of org.bukkit.block.BlockFace in project Essentials by drtshock.

the class EssentialsSign method checkIfBlockBreaksSigns.

protected static boolean checkIfBlockBreaksSigns(final Block block) {
    final Block sign = block.getRelative(BlockFace.UP);
    if (sign.getType() == Material.SIGN_POST && isValidSign(new BlockSign(sign))) {
        return true;
    }
    final BlockFace[] directions = new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
    for (BlockFace blockFace : directions) {
        final Block signblock = block.getRelative(blockFace);
        if (signblock.getType() == Material.WALL_SIGN) {
            try {
                final org.bukkit.material.Sign signMat = (org.bukkit.material.Sign) signblock.getState().getData();
                if (signMat != null && signMat.getFacing() == blockFace && isValidSign(new BlockSign(signblock))) {
                    return true;
                }
            } catch (NullPointerException ex) {
            // Sometimes signs enter a state of being semi broken, having no text or state data, usually while burning.
            }
        }
    }
    return false;
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign)

Aggregations

BlockFace (org.bukkit.block.BlockFace)135 Block (org.bukkit.block.Block)53 GlowBlock (net.glowstone.block.GlowBlock)32 Location (org.bukkit.Location)23 Material (org.bukkit.Material)23 Vector (org.bukkit.util.Vector)17 ArrayList (java.util.ArrayList)12 ItemStack (org.bukkit.inventory.ItemStack)12 Sign (org.bukkit.block.Sign)10 BlockState (org.bukkit.block.BlockState)9 MaterialData (org.bukkit.material.MaterialData)9 EventHandler (org.bukkit.event.EventHandler)8 List (java.util.List)7 ItemTable (net.glowstone.block.ItemTable)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 GlowPlayer (net.glowstone.entity.GlowPlayer)6 Player (org.bukkit.entity.Player)6 UUID (java.util.UUID)5 BlockType (net.glowstone.block.blocktype.BlockType)5 PulseTask (net.glowstone.scheduler.PulseTask)5