Search in sources :

Example 21 with GlowBlockState

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

the class BlockSnowBlock method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (block.getLightFromBlocks() > 11) {
        GlowBlockState state = block.getState();
        state.setType(Material.AIR);
        state.setData(new MaterialData(Material.AIR));
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    }
}
Also used : BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 22 with GlowBlockState

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

the class ItemFilledBucket method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock target = against.getRelative(face);
    BlockType againstBlockType = ItemTable.instance().getBlock(against.getType());
    if (againstBlockType.canAbsorb(target, face, holding)) {
        target = against;
    } else if (!target.isEmpty()) {
        BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
        if (!targetType.canOverride(target, face, holding)) {
            return;
        }
    }
    GlowBlockState newState = target.getState();
    PlayerBucketEmptyEvent event = EventFactory.callEvent(new PlayerBucketEmptyEvent(player, target, face, holding.getType(), holding));
    if (event.isCancelled()) {
        return;
    }
    liquid.placeBlock(player, newState, face, holding, clickedLoc);
    // perform the block change
    newState.update(true);
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) GlowBlockState(net.glowstone.block.GlowBlockState) PlayerBucketEmptyEvent(org.bukkit.event.player.PlayerBucketEmptyEvent)

Example 23 with GlowBlockState

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

the class BlockType method rightClickBlock.

@Override
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock target = against.getRelative(face);
    // prevent building above the height limit
    if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
        player.sendMessage(ChatColor.RED + "The height limit for this world is " + target.getWorld().getMaxHeight() + " blocks");
        return;
    }
    // check whether the block clicked against should absorb the placement
    BlockType againstType = ItemTable.instance().getBlock(against.getTypeId());
    if (againstType != null) {
        if (againstType.canAbsorb(against, face, holding)) {
            target = against;
        } else if (!target.isEmpty()) {
            // air can always be overridden
            BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
            if (targetType != null && !targetType.canOverride(target, face, holding)) {
                return;
            }
        }
    }
    if (getMaterial().isSolid()) {
        BlockBoundingBox box = new BlockBoundingBox(target);
        List<Entity> entities = target.getWorld().getEntityManager().getEntitiesInside(box, null);
        for (Entity e : entities) {
            if (e instanceof LivingEntity) {
                return;
            }
        }
    }
    // call canBuild event
    boolean canBuild = canPlaceAt(target, face);
    BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
    if (!EventFactory.callEvent(canBuildEvent).isBuildable()) {
        //revert(player, target);
        return;
    }
    // grab states and update block
    GlowBlockState oldState = target.getState(), newState = target.getState();
    ItemType itemType = ItemTable.instance().getItem(holding.getType());
    if (itemType.getPlaceAs() == null) {
        placeBlock(player, newState, face, holding, clickedLoc);
    } else {
        placeBlock(player, newState, face, new ItemStack(itemType.getPlaceAs().getMaterial(), holding.getAmount(), holding.getDurability()), clickedLoc);
    }
    newState.update(true);
    // call blockPlace event
    BlockPlaceEvent event = new BlockPlaceEvent(target, oldState, against, holding, player, canBuild);
    EventFactory.callEvent(event);
    if (event.isCancelled() || !event.canBuild()) {
        oldState.update(true);
        return;
    }
    // play the placement sound, except for the current player (handled by the client)
    SoundUtil.playSoundAtLocationExcept(target.getLocation(), getPlaceSound().getSound(), (getPlaceSound().getVolume() + 1F) / 2F, getPlaceSound().getPitch() * 0.8F, player);
    // do any after-place actions
    afterPlace(player, target, holding, oldState);
    // deduct from stack if not in creative mode
    if (player.getGameMode() != GameMode.CREATIVE) {
        holding.setAmount(holding.getAmount() - 1);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) BlockEntity(net.glowstone.block.entity.BlockEntity) GlowBlock(net.glowstone.block.GlowBlock) BlockCanBuildEvent(org.bukkit.event.block.BlockCanBuildEvent) GlowBlockState(net.glowstone.block.GlowBlockState) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) ItemType(net.glowstone.block.itemtype.ItemType) BlockBoundingBox(net.glowstone.entity.physics.BlockBoundingBox) ItemStack(org.bukkit.inventory.ItemStack)

Example 24 with GlowBlockState

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

the class BlockVine method putVine.

private void putVine(GlowBlock block, Vine vine, GlowBlock fromBlock) {
    GlowBlockState state = block.getState();
    state.setType(Material.VINE);
    state.setData(vine);
    if (fromBlock != null) {
        BlockSpreadEvent spreadEvent = new BlockSpreadEvent(block, fromBlock, state);
        EventFactory.callEvent(spreadEvent);
        if (!spreadEvent.isCancelled()) {
            state.update(true);
        }
    } else {
        state.update(true);
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState)

Example 25 with GlowBlockState

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

the class BlockTrapDoor method onRedstoneUpdate.

public void onRedstoneUpdate(GlowBlock block) {
    GlowBlockState state = block.getState();
    TrapDoor trapdoor = (TrapDoor) state.getData();
    boolean powered = block.isBlockIndirectlyPowered();
    if (powered != trapdoor.isOpen()) {
        trapdoor.setOpen(powered);
        state.update();
    }
}
Also used : TrapDoor(org.bukkit.material.TrapDoor) GlowBlockState(net.glowstone.block.GlowBlockState)

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