Search in sources :

Example 26 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockStem method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    GlowBlockState state = block.getState();
    int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
    if (cropState > CropState.RIPE.ordinal()) {
        cropState = CropState.RIPE.ordinal();
    }
    state.setRawData((byte) cropState);
    BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
    EventFactory.callEvent(growEvent);
    if (!growEvent.isCancelled()) {
        state.update(true);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 27 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockSugarCane method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (!canPlaceAt(block, BlockFace.DOWN)) {
        block.breakNaturally();
        return;
    }
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    // check it's the highest block of cactus
    if (blockAbove.isEmpty()) {
        // check the current cane height
        Block blockBelow = block.getRelative(BlockFace.DOWN);
        int height = 1;
        while (blockBelow.getType() == Material.SUGAR_CANE_BLOCK) {
            height++;
            blockBelow = blockBelow.getRelative(BlockFace.DOWN);
        }
        if (height < 3) {
            GlowBlockState state = block.getState();
            if (state.getRawData() < 15) {
                // increase age
                state.setRawData((byte) (state.getRawData() + 1));
                state.update(true);
            } else {
                // grow the sugar cane on the above block
                state.setRawData((byte) 0);
                state.update(true);
                state = blockAbove.getState();
                state.setType(Material.SUGAR_CANE_BLOCK);
                state.setRawData((byte) 0);
                BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    state.update(true);
                }
                updatePhysics(blockAbove);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 28 with GlowBlockState

use of net.glowstone.block.GlowBlockState 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);
        if (attachedChests.isEmpty()) {
            chest.setFacingDirection(normalFacing);
            state.setData(chest);
            return;
        } else if (attachedChests.size() > 1) {
            GlowServer.logger.warning("Chest placed near two other chests!");
            return;
        }
        BlockFace otherPart = attachedChests.iterator().next();
        GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
        if (getAttachedChest(otherPartBlock) != null) {
            GlowServer.logger.warning("Chest placed near already attached chest!");
            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 29 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockButton method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Button)) {
        warnMaterialData(Button.class, data);
        return false;
    }
    Button button = (Button) data;
    if (button.isPowered()) {
        return true;
    }
    button.setPowered(true);
    state.update();
    extraUpdate(block);
    // todo: switch to block scheduling system when one is available
    new BukkitRunnable() {

        @Override
        public void run() {
            button.setPowered(false);
            state.update();
            if (block.getType() == Material.WOOD_BUTTON || block.getType() == Material.STONE_BUTTON) {
                extraUpdate(block);
                block.getWorld().playSound(block.getLocation(), block.getType() == Material.WOOD_BUTTON ? Sound.BLOCK_WOOD_BUTTON_CLICK_OFF : Sound.BLOCK_STONE_BUTTON_CLICK_OFF, 0.3f, 0.5f);
            }
        }
    }.runTaskLater(null, block.getType() == Material.STONE_BUTTON ? 20 : 30);
    return true;
}
Also used : Button(org.bukkit.material.Button) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Example 30 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockCactus method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // TODO: Drop entity if the block has near blocks
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    // check it's the highest block of cactus
    if (blockAbove.isEmpty()) {
        // check the current cactus height
        Block blockBelow = block.getRelative(BlockFace.DOWN);
        int height = 1;
        while (blockBelow.getType() == Material.CACTUS) {
            height++;
            blockBelow = blockBelow.getRelative(BlockFace.DOWN);
        }
        if (height < 3) {
            GlowBlockState state = block.getState();
            if (state.getRawData() < 15) {
                // increase age
                state.setRawData((byte) (state.getRawData() + 1));
                state.update(true);
            } else {
                // grow the cactus on the above block
                state.setRawData((byte) 0);
                state.update(true);
                state = blockAbove.getState();
                state.setType(Material.CACTUS);
                state.setRawData((byte) 0);
                BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    state.update(true);
                }
                updatePhysics(blockAbove);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)54 GlowBlock (net.glowstone.block.GlowBlock)21 MaterialData (org.bukkit.material.MaterialData)20 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowWorld (net.glowstone.GlowWorld)10 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)7 BlockFace (org.bukkit.block.BlockFace)6 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)5 ItemStack (org.bukkit.inventory.ItemStack)4 Material (org.bukkit.Material)3 Block (org.bukkit.block.Block)3 Door (org.bukkit.material.Door)3 DoublePlant (org.bukkit.material.DoublePlant)3 BlockType (net.glowstone.block.blocktype.BlockType)2 ItemType (net.glowstone.block.itemtype.ItemType)2 GlowDispenser (net.glowstone.block.state.GlowDispenser)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 BlockIgniteEvent (org.bukkit.event.block.BlockIgniteEvent)2 CocoaPlant (org.bukkit.material.CocoaPlant)2 CocoaPlantSize (org.bukkit.material.CocoaPlant.CocoaPlantSize)2