Search in sources :

Example 31 with GlowBlock

use of net.glowstone.block.GlowBlock 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 32 with GlowBlock

use of net.glowstone.block.GlowBlock 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 33 with GlowBlock

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

the class BlockRedstoneRepeater method receivePulse.

@Override
public void receivePulse(GlowBlock block) {
    Diode diode = (Diode) block.getState().getData();
    GlowBlock target = block.getRelative(diode.getFacing().getOppositeFace());
    boolean powered = target.getType() == Material.REDSTONE_TORCH_ON || target.isBlockPowered() || target.getType() == Material.REDSTONE_WIRE && target.getData() > 0 && BlockRedstone.calculateConnections(target).contains(diode.getFacing()) || target.getType() == Material.DIODE_BLOCK_ON && ((Diode) target.getState().getData()).getFacing() == diode.getFacing();
    if (!powered && block.getType() == Material.DIODE_BLOCK_ON) {
        block.setTypeIdAndData(Material.DIODE_BLOCK_OFF.getId(), block.getData(), true);
        extraUpdate(block);
    } else if (powered && block.getType() == Material.DIODE_BLOCK_OFF) {
        block.setTypeIdAndData(Material.DIODE_BLOCK_ON.getId(), block.getData(), true);
        extraUpdate(block);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Diode(org.bukkit.material.Diode)

Example 34 with GlowBlock

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

the class BlockRedstoneRepeater method extraUpdate.

private void extraUpdate(GlowBlock block) {
    Diode diode = (Diode) block.getState().getData();
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(diode.getFacing());
    if (target.getType().isSolid()) {
        for (BlockFace face2 : ADJACENT) {
            GlowBlock target2 = target.getRelative(face2);
            BlockType notifyType = itemTable.getBlock(target2.getTypeId());
            if (notifyType != null) {
                if (target2.getFace(block) == null) {
                    notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
                }
                notifyType.onRedstoneUpdate(target2);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Diode(org.bukkit.material.Diode) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Example 35 with GlowBlock

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

the class BlockRedstoneTorch method extraUpdate.

private void extraUpdate(GlowBlock block) {
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(BlockFace.UP);
    if (target.getType().isSolid()) {
        for (BlockFace face2 : ADJACENT) {
            GlowBlock target2 = target.getRelative(face2);
            BlockType notifyType = itemTable.getBlock(target2.getTypeId());
            if (notifyType != null) {
                if (target2.getFace(block) == null) {
                    notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
                }
                notifyType.onRedstoneUpdate(target2);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)72 BlockFace (org.bukkit.block.BlockFace)23 GlowBlockState (net.glowstone.block.GlowBlockState)21 Block (org.bukkit.block.Block)16 GlowWorld (net.glowstone.GlowWorld)14 MaterialData (org.bukkit.material.MaterialData)13 ItemTable (net.glowstone.block.ItemTable)10 BlockType (net.glowstone.block.blocktype.BlockType)7 ItemType (net.glowstone.block.itemtype.ItemType)7 Material (org.bukkit.Material)7 Vector (org.bukkit.util.Vector)7 BlockEntity (net.glowstone.block.entity.BlockEntity)6 ItemStack (org.bukkit.inventory.ItemStack)6 BlockVector (org.bukkit.util.BlockVector)5 Message (com.flowpowered.network.Message)4 IOException (java.io.IOException)4 GlowPlayer (net.glowstone.entity.GlowPlayer)4 Title (com.destroystokyo.paper.Title)3 ByteBufUtils (com.flowpowered.network.util.ByteBufUtils)3 Preconditions (com.google.common.base.Preconditions)3