Java Code Examples for org.bukkit.block.BlockFace#NORTH

The following examples show how to use org.bukkit.block.BlockFace#NORTH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Dispenser.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getFacing() {
    int data = getData() & 0x7;

    switch (data) {
        case 0x0:
            return BlockFace.DOWN;

        case 0x1:
            return BlockFace.UP;

        case 0x2:
            return BlockFace.NORTH;

        case 0x3:
            return BlockFace.SOUTH;

        case 0x4:
            return BlockFace.WEST;

        case 0x5:
        default:
            return BlockFace.EAST;
    }
}
 
Example 2
Source File: Observer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BlockFace getFacing() {
    int data = getData() & 0x7;

    switch (data) {
        case 0x0:
            return BlockFace.DOWN;
        case 0x1:
            return BlockFace.UP;
        case 0x2:
            return BlockFace.SOUTH;
        case 0x3:
            return BlockFace.NORTH;
        case 0x4:
            return BlockFace.EAST;
        case 0x5:
            return BlockFace.WEST;
        default:
            throw new IllegalArgumentException("Illegal facing direction " + data);
    }
}
 
Example 3
Source File: TestMultiblockListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMultiblock() {
    Player player = server.addPlayer();
    World world = server.addSimpleWorld("Multiblock Test World");
    Block top = world.getBlockAt(1234, 92, -60);
    top.setType(multiblock.getStructure()[1]);

    Block self = world.getBlockAt(1234, 91, -60);
    self.setType(multiblock.getStructure()[4]);

    Block bottom = world.getBlockAt(1234, 90, -60);
    bottom.setType(multiblock.getStructure()[7]);

    PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, new ItemStack(Material.AIR), self, BlockFace.NORTH);
    listener.onRightClick(event);

    Assertions.assertEquals(Result.DENY, event.useInteractedBlock());

    server.getPluginManager().assertEventFired(MultiBlockInteractEvent.class, e -> {
        Assertions.assertEquals(player, e.getPlayer());
        Assertions.assertEquals(self, e.getClickedBlock());
        Assertions.assertEquals(BlockFace.NORTH, e.getClickedFace());
        Assertions.assertEquals(multiblock, e.getMultiBlock());
        return true;
    });
}
 
Example 4
Source File: Stairs.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return the direction the stairs ascend towards
 */
public BlockFace getAscendingDirection() {
    byte data = getData();

    switch (data & 0x3) {
        case 0x0:
        default:
            return BlockFace.EAST;

        case 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.SOUTH;

        case 0x3:
            return BlockFace.NORTH;
    }
}
 
Example 5
Source File: Banner.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getAttachedFace() {
    if (isWallBanner()) {
        byte data = getData();

        switch (data) {
            case 0x2:
                return BlockFace.SOUTH;

            case 0x3:
                return BlockFace.NORTH;

            case 0x4:
                return BlockFace.EAST;

            case 0x5:
                return BlockFace.WEST;
        }

        return null;
    } else {
        return BlockFace.DOWN;
    }
}
 
Example 6
Source File: Ladder.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the face that this block is attached on
 *
 * @return BlockFace attached to
 */
public BlockFace getAttachedFace() {
    byte data = getData();

    switch (data) {
        case 0x2:
            return BlockFace.SOUTH;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.EAST;

        case 0x5:
            return BlockFace.WEST;
    }

    return null;
}
 
Example 7
Source File: Button.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the face that this block is attached on
 *
 * @return BlockFace attached to
 */
public BlockFace getAttachedFace() {
    byte data = (byte) (getData() & 0x7);

    switch (data) {
        case 0x0:
            return BlockFace.UP;

        case 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.SOUTH;

        case 0x5:
            return BlockFace.DOWN;
    }

    return null;
}
 
Example 8
Source File: RandomUtils.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static BlockFace randomAdjacentFace(){
	BlockFace[] faces = new BlockFace[]{
		BlockFace.DOWN,
		BlockFace.UP,
		BlockFace.EAST,
		BlockFace.WEST,
		BlockFace.NORTH,
		BlockFace.SOUTH
	};
	return faces[randomInteger(0,faces.length-1)];
}
 
Example 9
Source File: CraftBlock.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public int getBlockPower(BlockFace face) {
    int power = 0;
    BlockRedstoneWire wire = Blocks.redstone_wire;
    net.minecraft.world.World world = chunk.getHandle().worldObj;
    if ((face == BlockFace.DOWN || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y - 1, z, 0)) power = wire.func_150178_a(world, x, y - 1, z, power);
    if ((face == BlockFace.UP || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y + 1, z, 1)) power = wire.func_150178_a(world, x, y + 1, z, power);
    if ((face == BlockFace.EAST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x + 1, y, z, 2)) power = wire.func_150178_a(world, x + 1, y, z, power);
    if ((face == BlockFace.WEST || face == BlockFace.SELF) && world.getIndirectPowerOutput(x - 1, y, z, 3)) power = wire.func_150178_a(world, x - 1, y, z, power);
    if ((face == BlockFace.NORTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z - 1, 4)) power = wire.func_150178_a(world, x, y, z - 1, power);
    if ((face == BlockFace.SOUTH || face == BlockFace.SELF) && world.getIndirectPowerOutput(x, y, z + 1, 5)) power = wire.func_150178_a(world, x, y, z - 1, power);
    return power > 0 ? power : (face == BlockFace.SELF ? isBlockIndirectlyPowered() : isBlockFaceIndirectlyPowered(face)) ? 15 : 0;
}
 
Example 10
Source File: BukkitImageViewer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) {
    try {
        Location distance = pos2.clone().subtract(pos1).add(1, 1, 1);
        int width = Math.max(distance.getBlockX(), distance.getBlockZ());
        ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()];

        World world = pos1.getWorld();

        this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST);
        int v = 0;
        for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) {
            int h = 0;
            for (double z = pos1.getZ(); z <= pos2.getZ(); z++) {
                for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) {
                    Location pos = new Location(world, x, y, z);
                    Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
                    boolean contains = false;
                    for (Entity ent : entities) {
                        if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
                            ItemFrame itemFrame = (ItemFrame) ent;
                            itemFrame.setRotation(Rotation.NONE);
                            contains = true;
                            frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent;
                            break;
                        }
                    }
                    if (!contains) return null;
                }
            }
        }
        return frames;
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 11
Source File: Flags.java    From CardinalPGM with MIT License 5 votes vote down vote up
public static BlockFace yawToFace(float yaw) {
    BlockFace[] RADIAL = {
            BlockFace.NORTH, BlockFace.NORTH_NORTH_EAST, BlockFace.NORTH_EAST, BlockFace.EAST_NORTH_EAST,
            BlockFace.EAST, BlockFace.EAST_SOUTH_EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_SOUTH_EAST,
            BlockFace.SOUTH, BlockFace.SOUTH_SOUTH_WEST, BlockFace.SOUTH_WEST, BlockFace.WEST_SOUTH_WEST,
            BlockFace.WEST, BlockFace.WEST_NORTH_WEST, BlockFace.NORTH_WEST, BlockFace.NORTH_NORTH_WEST
    };
    int i = Math.round((yaw + 360f)/ 22.5f);
    return RADIAL[(i + 8)% 16];
}
 
Example 12
Source File: Tree.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get direction of the log
 *
 * @return one of:
 * <ul>
 * <li>BlockFace.TOP for upright (default)
 * <li>BlockFace.NORTH (east-west)
 * <li>BlockFace.WEST (north-south)
 * <li>BlockFace.SELF (directionless)
 * </ul>
 */
@SuppressWarnings("deprecation")
public BlockFace getDirection() {
    switch ((getData() >> 2) & 0x3) {
        case 0: // Up-down
        default:
            return BlockFace.UP;
        case 1: // North-south
            return BlockFace.WEST;
        case 2: // East-west
            return BlockFace.NORTH;
        case 3: // Directionless (bark on all sides)
            return BlockFace.SELF;
    }
}
 
Example 13
Source File: Gate.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public BlockFace getFacing() {
    switch (getData() & DIR_BIT) {
        case GATE_SOUTH:
            return BlockFace.EAST;
        case GATE_WEST:
            return BlockFace.SOUTH;
        case GATE_NORTH:
            return BlockFace.WEST;
        case GATE_EAST:
            return BlockFace.NORTH;
    }

    return BlockFace.EAST;
}
 
Example 14
Source File: PlayerInteract.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	PlayerInventory inv = player.getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (event.getHand() != null)
		switch (event.getHand()) {
		case OFF_HAND:
			item = inv.getItemInOffHand();
			break;
		default:
			break;
		}

	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemPlayerInteractEvent customEvent = new CustomItemPlayerInteractEvent(event,
				new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
	if (event.getAction() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
			&& ToolType.getToolType(item.getType()) != null
			&& ToolType.getToolType(item.getType()).equals(ToolType.HOE)) {
		Block block = event.getClickedBlock();
		Material material = block.getType();
		Location blockLoc = block.getLocation();
		blockLoc.setY(blockLoc.getBlockY() + 1);
		Material materialUp = blockLoc.getBlock().getType();
		@SuppressWarnings("deprecation")
		byte data = block.getData();

		BlockFace face = event.getBlockFace();
		if (materialUp == Material.AIR && (face == BlockFace.UP || face == BlockFace.EAST || face == BlockFace.NORTH
				|| face == BlockFace.SOUTH || face == BlockFace.WEST))
			if (shouldPlaySound(material, item, data, player))
				player.playSound(block.getLocation(), "additionsapi.hoe.till", 1.0F, 1.0F);
	}
}
 
Example 15
Source File: CocoaPlant.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public BlockFace getFacing() {
    switch (getData() & 0x3) {
        case 0:
            return BlockFace.SOUTH;
        case 1:
            return BlockFace.WEST;
        case 2:
            return BlockFace.NORTH;
        case 3:
            return BlockFace.EAST;
    }
    return null;
}
 
Example 16
Source File: MiscUtils.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static BlockFace getCardinalDirection(Location location) {
    double rotation = (location.getYaw() - 90) % 360;
    if (rotation < 0) {
        rotation += 360.0;
    }
    if (0 <= rotation && rotation < 22.5) {
        return BlockFace.NORTH;
    } else if (22.5 <= rotation && rotation < 67.5) {
        return BlockFace.NORTH_EAST;
    } else if (67.5 <= rotation && rotation < 112.5) {
        return BlockFace.EAST;
    } else if (112.5 <= rotation && rotation < 157.5) {
        return BlockFace.SOUTH_EAST;
    } else if (157.5 <= rotation && rotation < 202.5) {
        return BlockFace.SOUTH;
    } else if (202.5 <= rotation && rotation < 247.5) {
        return BlockFace.SOUTH_WEST;
    } else if (247.5 <= rotation && rotation < 292.5) {
        return BlockFace.WEST;
    } else if (292.5 <= rotation && rotation < 337.5) {
        return BlockFace.NORTH_WEST;
    } else if (337.5 <= rotation && rotation < 360.0) {
        return BlockFace.NORTH;
    } else {
        return BlockFace.NORTH;
    }
}
 
Example 17
Source File: ChestProtectListener.java    From ShopChest with MIT License 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent e) {
    final Player p = e.getPlayer();
    final Block b = e.getBlockPlaced();

    if (!b.getType().equals(Material.CHEST) && !b.getType().equals(Material.TRAPPED_CHEST)) {
        return;
    }
    
    Chest c = (Chest) b.getState();
    Block b2;

    // Can't use Utils::getChestLocations since inventory holder
    // has not been updated yet in this event (for 1.13+)

    if (Utils.getMajorVersion() < 13) {
        InventoryHolder ih = c.getInventory().getHolder();
        if (!(ih instanceof DoubleChest)) {
            return;
        }

        DoubleChest dc = (DoubleChest) ih;
        Chest l = (Chest) dc.getLeftSide();
        Chest r = (Chest) dc.getRightSide();

        if (b.getLocation().equals(l.getLocation())) {
            b2 = r.getBlock();
        } else {
            b2 = l.getBlock();
        }
    } else {
        org.bukkit.block.data.type.Chest data = (org.bukkit.block.data.type.Chest) c.getBlockData();

        if (data.getType() == Type.SINGLE) {
            return;
        }

        BlockFace neighborFacing;

        switch (data.getFacing()) {
            case NORTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
                break;
            case EAST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
                break;
            case SOUTH:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
                break;
            case WEST:
                neighborFacing = data.getType() == Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
                break;
            default:
                neighborFacing = null;
        }

        b2 = b.getRelative(neighborFacing);
    }

    final Shop shop = shopUtils.getShop(b2.getLocation());
    if (shop == null)
        return;

    plugin.debug(String.format("%s tries to extend %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));

    ShopExtendEvent event = new ShopExtendEvent(p, shop, b.getLocation());
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled() && !p.hasPermission(Permissions.EXTEND_PROTECTED)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_PROTECTED));
        return;
    }

    if (!p.getUniqueId().equals(shop.getVendor().getUniqueId()) && !p.hasPermission(Permissions.EXTEND_OTHER)) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.NO_PERMISSION_EXTEND_OTHERS));
        return;
    }

    if (!ItemUtils.isAir(b.getRelative(BlockFace.UP).getType())) {
        e.setCancelled(true);
        p.sendMessage(LanguageUtils.getMessage(Message.CHEST_BLOCKED));
        return;
    }

    final Shop newShop = new Shop(shop.getID(), plugin, shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.getShopType());

    shopUtils.removeShop(shop, true, new Callback<Void>(plugin) {
        @Override
        public void onResult(Void result) {
            newShop.create(true);
            shopUtils.addShop(newShop, true);
            plugin.debug(String.format("%s extended %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
        }
    });
}
 
Example 18
Source File: Sign.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the direction that this sign is currently facing
 *
 * @return BlockFace indicating where this sign is facing
 */
public BlockFace getFacing() {
    byte data = getData();

    if (!isWallSign()) {
        switch (data) {
            case 0x0:
                return BlockFace.SOUTH;

            case 0x1:
                return BlockFace.SOUTH_SOUTH_WEST;

            case 0x2:
                return BlockFace.SOUTH_WEST;

            case 0x3:
                return BlockFace.WEST_SOUTH_WEST;

            case 0x4:
                return BlockFace.WEST;

            case 0x5:
                return BlockFace.WEST_NORTH_WEST;

            case 0x6:
                return BlockFace.NORTH_WEST;

            case 0x7:
                return BlockFace.NORTH_NORTH_WEST;

            case 0x8:
                return BlockFace.NORTH;

            case 0x9:
                return BlockFace.NORTH_NORTH_EAST;

            case 0xA:
                return BlockFace.NORTH_EAST;

            case 0xB:
                return BlockFace.EAST_NORTH_EAST;

            case 0xC:
                return BlockFace.EAST;

            case 0xD:
                return BlockFace.EAST_SOUTH_EAST;

            case 0xE:
                return BlockFace.SOUTH_EAST;

            case 0xF:
                return BlockFace.SOUTH_SOUTH_EAST;
        }

        return null;
    } else {
        return getAttachedFace().getOppositeFace();
    }
}
 
Example 19
Source File: Shop.java    From ShopChest with MIT License 4 votes vote down vote up
private Location getHologramLocation(Chest[] chests, BlockFace face) {
    World w = location.getWorld();
    int x = location.getBlockX();
    int y  = location.getBlockY();
    int z = location.getBlockZ();

    Location holoLocation = new Location(w, x, y, z);

    double deltaY = -0.6;

    if (Config.hologramFixedBottom) deltaY = -0.85;

    if (chests[1] != null) {
        Chest c1 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[1] : chests[0];
        Chest c2 = Utils.getMajorVersion() >= 13 && (face == BlockFace.NORTH || face == BlockFace.EAST) ? chests[0] : chests[1];

        if (holoLocation.equals(c1.getLocation())) {
            if (c1.getX() != c2.getX()) {
                holoLocation.add(0, deltaY, 0.5);
            } else if (c1.getZ() != c2.getZ()) {
                holoLocation.add(0.5, deltaY, 0);
            } else {
                holoLocation.add(0.5, deltaY, 0.5);
            }
        } else {
            if (c1.getX() != c2.getX()) {
                holoLocation.add(1, deltaY, 0.5);
            } else if (c1.getZ() != c2.getZ()) {
                holoLocation.add(0.5, deltaY, 1);
            } else {
                holoLocation.add(0.5, deltaY, 0.5);
            }
        }
    } else {
        holoLocation.add(0.5, deltaY, 0.5);
    }

    holoLocation.add(0, Config.hologramLift, 0);

    return holoLocation;
}
 
Example 20
Source File: BlockIterator.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
private BlockFace getZFace(Vector direction) {
    return ((direction.getZ() > 0) ? BlockFace.SOUTH : BlockFace.NORTH);
}