Search in sources :

Example 51 with BlockFace

use of org.bukkit.block.BlockFace 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 defaultBehavior.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 52 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 53 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 54 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)

Example 55 with BlockFace

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

the class MapResourcePack method createPlaceholderModel.

/**
 * Creates a placeholder model. Used when models can not be loaded.
 *
 * @return placeholder model
 */
protected final Model createPlaceholderModel(RenderOptions renderOptions) {
    Model model = new Model();
    Model.Element element = new Model.Element();
    for (BlockFace face : FaceUtil.BLOCK_SIDES) {
        element.faces.put(face, createPlaceholderFace());
    }
    element.buildQuads();
    model.placeholder = true;
    model.elements.add(element);
    model.name = renderOptions.lookupModelName();
    return model;
}
Also used : BlockFace(org.bukkit.block.BlockFace) Model(com.bergerkiller.bukkit.common.map.util.Model) GeneratedModel(com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)

Aggregations

BlockFace (org.bukkit.block.BlockFace)58 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)20 MaterialData (org.bukkit.material.MaterialData)10 Vector (org.bukkit.util.Vector)9 BlockState (org.bukkit.block.BlockState)8 ArrayList (java.util.ArrayList)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 ItemTable (net.glowstone.block.ItemTable)5 Sign (org.bukkit.block.Sign)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Material (org.bukkit.Material)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 List (java.util.List)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2