Search in sources :

Example 1 with BlockLiquid

use of net.glowstone.block.blocktype.BlockLiquid in project Glowstone by GlowstoneMC.

the class EmptyBucketDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowDispenser dispenser = (GlowDispenser) block.getState();
    GlowBlock target = block.getRelative(BlockDispenser.getFacing(block));
    BlockLiquid liquid = collectableLiquidAtBlock(target);
    if (liquid == null) {
        return super.dispenseStack(block, stack);
    }
    Material bucket = liquid.getBucketType();
    target.setType(Material.AIR);
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() == 0) {
        stack.setAmount(1);
        stack.setType(bucket);
    } else {
        ItemStack toPlace = new ItemStack(bucket);
        ItemStack remaining = dispenser.placeInDispenser(toPlace);
        if (remaining != null) {
            INSTANCE.dispense(block, remaining);
        }
    }
    return stack;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) GlowDispenser(net.glowstone.block.entity.state.GlowDispenser) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with BlockLiquid

use of net.glowstone.block.blocktype.BlockLiquid in project Glowstone by GlowstoneMC.

the class ItemBucket method rightClickAir.

@Override
public void rightClickAir(GlowPlayer player, ItemStack holding) {
    Iterator<Block> itr = new BlockIterator(player, 5);
    Block target = null;
    // Used to determine the side the block was clicked on:
    Block previousTarget = null;
    BlockType targetBlockType = null;
    boolean validTarget = false;
    // Find the next available non-air liquid block type which is collectible in a radius of 5 blocks
    while (itr.hasNext()) {
        previousTarget = target;
        target = itr.next();
        targetBlockType = ItemTable.instance().getBlock(target.getType());
        if (targetBlockType instanceof BlockLiquid) {
            if (((BlockLiquid) targetBlockType).isCollectible((GlowBlockState) target.getState())) {
                validTarget = true;
                break;
            }
        }
    }
    if (target != null && validTarget) {
        // Get the direction of the bucket fill
        BlockFace face;
        if (previousTarget != null) {
            face = target.getFace(previousTarget);
        } else {
            face = BlockFace.SELF;
        }
        Material replaceWith = ((BlockLiquid) targetBlockType).getBucketType();
        PlayerBucketFillEvent event = EventFactory.callEvent(new PlayerBucketFillEvent(player, target, face, holding.getType(), holding));
        if (event.isCancelled()) {
            return;
        }
        if (player.getGameMode() != GameMode.CREATIVE) {
            if (holding.getAmount() == 1) {
                holding.setType(replaceWith);
            } else {
                holding.setAmount(holding.getAmount() - 1);
                player.getInventory().addItem(new ItemStack(replaceWith));
            }
        }
        target.setType(Material.AIR);
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) BlockType(net.glowstone.block.blocktype.BlockType) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with BlockLiquid

use of net.glowstone.block.blocktype.BlockLiquid in project Glowstone by GlowstoneMC.

the class ItemBucket method clickBucket.

private void clickBucket(GlowPlayer player, ItemStack holding) {
    Iterator<Block> itr = new BlockIterator(player, 5);
    Block target = null;
    // Used to determine the side the block was clicked on:
    Block previousTarget = null;
    BlockType targetBlockType = null;
    boolean validTarget = false;
    // blocks
    while (itr.hasNext()) {
        previousTarget = target;
        target = itr.next();
        targetBlockType = ItemTable.instance().getBlock(target.getType());
        if (targetBlockType instanceof BlockLiquid) {
            if (((BlockLiquid) targetBlockType).isCollectible((GlowBlockState) target.getState())) {
                validTarget = true;
                break;
            }
        } else if (!target.isEmpty()) {
            break;
        }
    }
    if (target != null && validTarget) {
        // Get the direction of the bucket fill
        BlockFace face;
        if (previousTarget != null) {
            face = target.getFace(previousTarget);
        } else {
            face = BlockFace.SELF;
        }
        Material replaceWith = ((BlockLiquid) targetBlockType).getBucketType();
        PlayerBucketFillEvent event = EventFactory.getInstance().callEvent(new PlayerBucketFillEvent(player, target, face, holding.getType(), holding));
        if (event.isCancelled()) {
            return;
        }
        if (player.getGameMode() != GameMode.CREATIVE) {
            if (holding.getAmount() == 1) {
                holding.setType(replaceWith);
            } else {
                holding.setAmount(holding.getAmount() - 1);
                player.getInventory().addItem(new ItemStack(replaceWith));
            }
        }
        target.setType(Material.AIR);
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) PlayerBucketFillEvent(org.bukkit.event.player.PlayerBucketFillEvent) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) BlockType(net.glowstone.block.blocktype.BlockType) BlockFace(org.bukkit.block.BlockFace) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with BlockLiquid

use of net.glowstone.block.blocktype.BlockLiquid in project Glowstone by GlowstoneMC.

the class BucketDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    ItemFilledBucket bucket = (ItemFilledBucket) ItemTable.instance().getItem(stack.getType());
    BlockLiquid liquid = (BlockLiquid) bucket.getLiquid();
    BlockFace facing = BlockDispenser.getFacing(block);
    GlowBlock target = block.getRelative(facing);
    if (canPlace(target, facing, stack)) {
        target.setType(liquid.getMaterial());
        stack.setType(Material.BUCKET);
        stack.setAmount(1);
        return stack;
    } else {
        return INSTANCE.dispense(block, stack);
    }
}
Also used : ItemFilledBucket(net.glowstone.block.itemtype.ItemFilledBucket) GlowBlock(net.glowstone.block.GlowBlock) BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) BlockFace(org.bukkit.block.BlockFace)

Example 5 with BlockLiquid

use of net.glowstone.block.blocktype.BlockLiquid in project Glowstone by GlowstoneMC.

the class EmptyBucketDispenseBehavior method collectableLiquidAtBlock.

private BlockLiquid collectableLiquidAtBlock(GlowBlock target) {
    Material material = target.getType();
    if (material == null || material == Material.AIR) {
        return null;
    }
    BlockType type = ItemTable.instance().getBlock(material);
    if (!(type instanceof BlockLiquid)) {
        return null;
    }
    BlockLiquid liquid = (BlockLiquid) type;
    if (!liquid.isCollectible(target.getState())) {
        return null;
    }
    return liquid;
}
Also used : BlockLiquid(net.glowstone.block.blocktype.BlockLiquid) BlockType(net.glowstone.block.blocktype.BlockType) Material(org.bukkit.Material)

Aggregations

BlockLiquid (net.glowstone.block.blocktype.BlockLiquid)5 Material (org.bukkit.Material)4 GlowBlock (net.glowstone.block.GlowBlock)3 BlockType (net.glowstone.block.blocktype.BlockType)3 BlockFace (org.bukkit.block.BlockFace)3 ItemStack (org.bukkit.inventory.ItemStack)3 Block (org.bukkit.block.Block)2 PlayerBucketFillEvent (org.bukkit.event.player.PlayerBucketFillEvent)2 BlockIterator (org.bukkit.util.BlockIterator)2 GlowDispenser (net.glowstone.block.entity.state.GlowDispenser)1 ItemFilledBucket (net.glowstone.block.itemtype.ItemFilledBucket)1