Search in sources :

Example 46 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class DefaultDispenseBehavior method dispenseStack.

protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    BlockFace facing = BlockDispenser.getFacing(block);
    Vector dispensePosition = BlockDispenser.getDispensePosition(block);
    ItemStack items = new ItemStack(stack.getType(), 1);
    stack.setAmount(stack.getAmount() - 1);
    doDispense(block, items, 6, facing, dispensePosition);
    return stack.getAmount() > 0 ? stack : null;
}
Also used : BlockFace(org.bukkit.block.BlockFace) ItemStack(org.bukkit.inventory.ItemStack) Vector(org.bukkit.util.Vector)

Example 47 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class SugarCane method generate.

public void generate(World world, Random random, int x, int y, int z) {
    if (world.getBlockAt(x, y, z).isEmpty()) {
        Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
        boolean adjacentWater = false;
        for (BlockFace face : FACES) {
            // needs a directly adjacent water block
            if (block.getRelative(face).getType() == Material.STATIONARY_WATER || block.getRelative(face).getType() == Material.WATER) {
                adjacentWater = true;
                break;
            }
        }
        if (adjacentWater) {
            for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) {
                block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN);
                if (block.getType() == Material.SUGAR_CANE_BLOCK || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState().getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) {
                    Block caneBlock = block.getRelative(BlockFace.UP);
                    if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
                        return;
                    }
                    BlockState state = caneBlock.getState();
                    state.setType(Material.SUGAR_CANE_BLOCK);
                    state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK));
                    state.update(true);
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 48 with BlockFace

use of org.bukkit.block.BlockFace in project Glowstone by GlowstoneMC.

the class TaxicabBlockIterator method hasNext.

@Override
public boolean hasNext() {
    if (validBlockCount >= maxBlocks) {
        return false;
    }
    // Note that the pending analysis queue will always contain at least one element: the end of distance marker.
    while (nextValidBlocks.isEmpty() && currentDistance <= maxDistance && pendingAnalysis.size() >= 2) {
        Object object = pendingAnalysis.remove();
        // If we find the end of distance marker, we'll increase the distance, and then we'll re-add it to the end.
        if (object == DistanceMarker.INSTANCE) {
            pendingAnalysis.add(object);
            currentDistance++;
            continue;
        }
        // If it wasn't the EoD marker, it must be a block. We'll look now for valid blocks around it.
        Block block = (Block) object;
        for (BlockFace face : VALID_FACES) {
            Block near = block.getRelative(face);
            // Only analyse the block if we haven't checked it yet.
            if (usedBlocks.add(near) && isValid(near)) {
                nextValidBlocks.add(near);
                pendingAnalysis.add(near);
            }
        }
    }
    return !nextValidBlocks.isEmpty();
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block)

Example 49 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class CommonMapController method onEntityRightClick.

@EventHandler(priority = EventPriority.LOWEST)
protected void onEntityRightClick(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof ItemFrame)) {
        return;
    }
    ItemFrame itemFrame = (ItemFrame) event.getRightClicked();
    if (lastClickOffset != null) {
        Vector pos = lastClickOffset;
        lastClickOffset = null;
        BlockFace attachedFace = itemFrame.getAttachedFace();
        double dx, dy;
        if (FaceUtil.isAlongZ(attachedFace)) {
            dx = pos.getX() + 0.5;
            dy = 1.0 - (pos.getY() + 0.5);
            if (attachedFace == BlockFace.SOUTH) {
                dx = 1.0 - dx;
            }
        } else {
            dx = pos.getZ() + 0.5;
            dy = 1.0 - (pos.getY() + 0.5);
            if (attachedFace == BlockFace.WEST) {
                dx = 1.0 - dx;
            }
        }
        event.setCancelled(dispatchClickAction(event.getPlayer(), itemFrame, dx, dy, MapAction.RIGHT_CLICK));
    } else {
        event.setCancelled(dispatchClickActionApprox(event.getPlayer(), itemFrame, MapAction.RIGHT_CLICK));
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) ItemFrame(org.bukkit.entity.ItemFrame) Vector(org.bukkit.util.Vector) EventHandler(org.bukkit.event.EventHandler)

Example 50 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class CommonMapController method dispatchClickActionApprox.

private boolean dispatchClickActionApprox(Player player, ItemFrame itemFrame, MapAction action) {
    // Calculate the vector position on the map that was clicked
    BlockFace attachedFace = itemFrame.getAttachedFace();
    Location playerPos = player.getEyeLocation();
    Vector dir = playerPos.getDirection();
    Block itemBlock = EntityUtil.getHangingBlock(itemFrame);
    double target_x = (double) itemBlock.getX() + 1.0;
    double target_y = (double) itemBlock.getY() + 1.0;
    double target_z = (double) itemBlock.getZ() + 1.0;
    // offset from wall
    final double FRAME_OFFSET = 0.0625;
    double dx, dy;
    if (FaceUtil.isAlongZ(attachedFace)) {
        if (attachedFace == BlockFace.NORTH) {
            target_z -= 1.0;
        }
        target_z -= attachedFace.getModZ() * FRAME_OFFSET;
        dir.multiply((target_z - playerPos.getZ()) / dir.getZ());
        dx = target_x - (playerPos.getX() + dir.getX());
        dy = target_y - (playerPos.getY() + dir.getY());
        if (attachedFace == BlockFace.NORTH) {
            dx = 1.0 - dx;
        }
    } else {
        if (attachedFace == BlockFace.WEST) {
            target_x -= 1.0;
        }
        target_x -= attachedFace.getModX() * FRAME_OFFSET;
        dir.multiply((target_x - playerPos.getX()) / dir.getX());
        dx = target_z - (playerPos.getZ() + dir.getZ());
        dy = target_y - (playerPos.getY() + dir.getY());
        if (attachedFace == BlockFace.EAST) {
            dx = 1.0 - dx;
        }
    }
    return dispatchClickAction(player, itemFrame, dx, dy, action);
}
Also used : BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

BlockFace (org.bukkit.block.BlockFace)50 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)17 MaterialData (org.bukkit.material.MaterialData)9 BlockState (org.bukkit.block.BlockState)8 Vector (org.bukkit.util.Vector)8 GlowBlockState (net.glowstone.block.GlowBlockState)6 Location (org.bukkit.Location)6 ItemStack (org.bukkit.inventory.ItemStack)6 ItemTable (net.glowstone.block.ItemTable)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Sign (org.bukkit.block.Sign)4 ArrayList (java.util.ArrayList)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 GlowWorld (net.glowstone.GlowWorld)2 BlockLiquid (net.glowstone.block.blocktype.BlockLiquid)2 ItemType (net.glowstone.block.itemtype.ItemType)2 Material (org.bukkit.Material)2 Action (org.bukkit.event.block.Action)2