Search in sources :

Example 6 with BlockFace

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

the class BlockLever method extraUpdate.

private void extraUpdate(GlowBlock block) {
    Lever lever = (Lever) block.getState().getData();
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(lever.getAttachedFace());
    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) Lever(org.bukkit.material.Lever) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Example 7 with BlockFace

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

the class ProjectileDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowWorld world = block.getWorld();
    Vector position = BlockDispenser.getDispensePosition(block);
    BlockFace face = BlockDispenser.getFacing(block);
    Projectile entity = getProjectileEntity(world, position);
    entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
    stack.setAmount(stack.getAmount() - 1);
    if (stack.getAmount() < 1) {
        return null;
    }
    return stack;
}
Also used : BlockFace(org.bukkit.block.BlockFace) GlowWorld(net.glowstone.GlowWorld) Vector(org.bukkit.util.Vector) Projectile(org.bukkit.entity.Projectile)

Example 8 with BlockFace

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

the class ArmorDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    BlockFace facing = BlockDispenser.getFacing(block);
    Location targetLocation = block.getLocation().clone().add(facing.getModX(), facing.getModY(), facing.getModZ());
    // Find all nearby entities and see if they are players or armor stands
    List<LivingEntity> entities = new ArrayList<>();
    for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) {
        switch(entity.getType()) {
            case PLAYER:
                entities.add((LivingEntity) entity);
                break;
        }
    }
    boolean targetLocationTest1;
    boolean targetLocationTest2;
    // Loop through entities to see if any are in the location where armor would be dispensed
    for (LivingEntity player : entities) {
        targetLocationTest1 = (player.getLocation().getBlockX() == targetLocation.getX() && player.getLocation().getBlockY() == targetLocation.getY() && player.getLocation().getBlockZ() == targetLocation.getZ());
        targetLocationTest2 = (player.getEyeLocation().getBlockX() == targetLocation.getX() && player.getEyeLocation().getBlockY() == targetLocation.getY() && player.getEyeLocation().getBlockZ() == targetLocation.getZ());
        if ((targetLocationTest1 || targetLocationTest2)) {
            return ((GlowInventory) ((Player) player).getInventory()).tryToFillSlots(stack, 36, 40);
        }
    }
    // Fallback
    return defaultBehavior.dispense(block, stack);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) GlowInventory(net.glowstone.inventory.GlowInventory) Location(org.bukkit.Location)

Example 9 with BlockFace

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

the class GlowChest method getInventory.

@Override
public Inventory getInventory() {
    GlowBlock me = getBlock();
    BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
    BlockFace attachedChest = blockChest.getAttachedChest(me);
    if (attachedChest != null) {
        Block nearbyBlock = me.getRelative(attachedChest);
        GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
        switch(attachedChest) {
            case SOUTH:
            case EAST:
                return new GlowDoubleChestInventory(this, nearbyChest);
            case WEST:
            case NORTH:
                return new GlowDoubleChestInventory(nearbyChest, this);
            default:
                GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
                return getBlockInventory();
        }
    }
    return getBlockInventory();
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockChest(net.glowstone.block.blocktype.BlockChest) BlockFace(org.bukkit.block.BlockFace) GlowDoubleChestInventory(net.glowstone.inventory.GlowDoubleChestInventory) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 10 with BlockFace

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

the class BlockBed method getExitLocation.

/**
     * Returns an 'empty' block next to the bed used to put the player at when they exit a bed / respawn.
     *
     * @param head head of the bed
     * @param foot foot of the bed
     * @return Exit block or {@code null} if all spots are blocked
     */
public static Block getExitLocation(GlowBlock head, GlowBlock foot) {
    // First check blocks near head
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            Block b = head.getRelative(x, 0, z);
            boolean floorValid = b.getRelative(BlockFace.DOWN).getType().isSolid();
            boolean bottomValid = isValidSpawn(b.getType());
            boolean topValid = isValidSpawn(b.getRelative(BlockFace.UP).getType());
            if (floorValid && bottomValid && topValid) {
                return b;
            }
        }
    }
    // Then check the last three blocks near foot
    BlockFace face = head.getFace(foot);
    int modX = face.getModX();
    int modZ = face.getModZ();
    for (int x = modX == 0 ? -1 : modX; x <= (modX == 0 ? 1 : modX); x++) {
        for (int z = modZ == 0 ? -1 : modZ; z <= (modZ == 0 ? 1 : modZ); z++) {
            Block b = foot.getRelative(x, 0, z);
            boolean floorValid = b.getRelative(BlockFace.DOWN).getType().isSolid();
            boolean bottomValid = isValidSpawn(b.getType());
            boolean topValid = isValidSpawn(b.getRelative(BlockFace.UP).getType());
            if (floorValid && bottomValid && topValid) {
                return b;
            }
        }
    }
    return null;
}
Also used : BlockFace(org.bukkit.block.BlockFace) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

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