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;
}
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);
}
}
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);
}
}
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);
}
}
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;
}
Aggregations