Search in sources :

Example 91 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 newType the new block type
 * @param oldData the old data
 * @param newData the new data
 */
public void applyPhysics(Material oldType, Material newType, byte oldData, byte newData) {
    if (!world.isInitialized()) {
        // World is still loading.
        return;
    }
    // notify the surrounding blocks that this block has changed
    ItemTable itemTable = ItemTable.instance();
    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.getType());
            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)

Example 92 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) {
    Material type = block.getType();
    if (!MaterialTags.BEDS.isTagged(type)) {
        return;
    }
    GlowBed bed = (GlowBed) block.getState();
    bed.setColor(DyeColor.getByWoolData(holding.getData().getData()));
    bed.update(true);
    BlockFace direction = ((Bed) bed.getData()).getFacing();
    GlowBlock headBlock = block.getRelative(direction);
    headBlock.setType(type);
    GlowBed headBlockState = (GlowBed) headBlock.getState();
    headBlockState.setColor(DyeColor.getByWoolData(holding.getData().getData()));
    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) GlowBed(net.glowstone.block.entity.state.GlowBed) GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) GlowBed(net.glowstone.block.entity.state.GlowBed)

Example 93 with BlockFace

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

the class BlockBed method canPlaceAt.

@Override
public boolean canPlaceAt(GlowPlayer player, GlowBlock block, BlockFace against) {
    if (player != null) {
        BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace();
        final GlowBlock otherEnd = block.getRelative(direction);
        return otherEnd.getType() == Material.AIR && otherEnd.getRelative(BlockFace.DOWN).getType().isSolid();
    } else {
        return false;
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace)

Example 94 with BlockFace

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

the class BlockChest method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Chest) {
        Chest chest = (Chest) data;
        GlowBlock chestBlock = state.getBlock();
        BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);
        Collection<BlockFace> attachedChests = searchChests(chestBlock);
        switch(attachedChests.size()) {
            case 0:
                chest.setFacingDirection(normalFacing);
                state.setData(chest);
                return;
            case 1:
                break;
            default:
                ConsoleMessages.Warn.Block.Chest.TRIPLE_MIDDLE.log();
                return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            ConsoleMessages.Warn.Block.Chest.TRIPLE_END.log();
            return;
        }
        BlockState otherPartState = otherPartBlock.getState();
        MaterialData otherPartData = otherPartState.getData();
        if (otherPartData instanceof Chest) {
            Chest otherChest = (Chest) otherPartData;
            BlockFace facing = getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);
            chest.setFacingDirection(facing);
            state.setData(chest);
            otherChest.setFacingDirection(facing);
            otherPartState.setData(otherChest);
            otherPartState.update();
        } else {
            warnMaterialData(Chest.class, otherPartData);
        }
    } else {
        warnMaterialData(Chest.class, data);
    }
}
Also used : Chest(org.bukkit.material.Chest) GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Example 95 with BlockFace

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

the class BlockDoor method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // place the door and calculate the facing
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (!(data instanceof Door)) {
        warnMaterialData(Door.class, data);
        return;
    }
    BlockFace facing = player.getCardinalFacing();
    ((Door) data).setFacingDirection(facing.getOppositeFace());
    // modify facing for double-doors
    GlowBlock leftBlock = null;
    byte newDirectionData = 0;
    switch(facing) {
        case NORTH:
            leftBlock = state.getBlock().getRelative(BlockFace.WEST);
            newDirectionData = 6;
            break;
        case WEST:
            leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
            newDirectionData = 5;
            break;
        case SOUTH:
            leftBlock = state.getBlock().getRelative(BlockFace.EAST);
            newDirectionData = 4;
            break;
        case EAST:
            leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
            newDirectionData = 7;
            break;
        default:
    }
    if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
        data.setData(newDirectionData);
    }
    // place top half of door
    GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
    topState.setType(state.getType());
    MaterialData topData = topState.getData();
    if (!(topData instanceof Door)) {
        warnMaterialData(Door.class, data);
    } else {
        ((Door) topData).setTopHalf(true);
        topState.update(true);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Door(org.bukkit.material.Door)

Aggregations

BlockFace (org.bukkit.block.BlockFace)136 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)18 ArrayList (java.util.ArrayList)12 ItemStack (org.bukkit.inventory.ItemStack)12 Sign (org.bukkit.block.Sign)10 BlockState (org.bukkit.block.BlockState)9 EventHandler (org.bukkit.event.EventHandler)8 MaterialData (org.bukkit.material.MaterialData)8 List (java.util.List)7 ItemTable (net.glowstone.block.ItemTable)7 Player (org.bukkit.entity.Player)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 GlowPlayer (net.glowstone.entity.GlowPlayer)6 UUID (java.util.UUID)5 BlockType (net.glowstone.block.blocktype.BlockType)5 PulseTask (net.glowstone.scheduler.PulseTask)5