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

The following examples show how to use org.bukkit.block.BlockFace#WEST . 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: 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 2
Source File: Comparator.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the direction this comparator is facing
 *
 * @return The direction this comparator is facing
 * @see BlockFace
 */
@Override
public BlockFace getFacing() {
    byte data = (byte) (getData() & 0x3);

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

        case 0x1:
            return BlockFace.EAST;

        case 0x2:
            return BlockFace.SOUTH;

        case 0x3:
            return BlockFace.WEST;
    }
}
 
Example 3
Source File: DirectionalContainer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getFacing() {
    byte data = getData();

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

        case 0x3:
            return BlockFace.SOUTH;

        case 0x4:
            return BlockFace.WEST;

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

    switch (data) {
        case 0x1:
        default:
            return BlockFace.SELF;

        case 0x2:
            return BlockFace.NORTH;

        case 0x3:
            return BlockFace.SOUTH;

        case 0x4:
            return BlockFace.WEST;

        case 0x5:
            return BlockFace.EAST;
    }
}
 
Example 5
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Find a block that is adjacent to another block on any of the block's 6 sides
 * given a Material
 *
 * @param block
 * @param material
 * @param ignore
 * @return
 */
public Block findAdjacentBlockOnAllSides(Block block, Material material, Block... ignore) {
    BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST,
            BlockFace.UP, BlockFace.DOWN};
    List<Block> ignoreList = Arrays.asList(ignore);

    for (BlockFace face : faces) {
        Block adjacentBlock = block.getRelative(face);

        if (adjacentBlock.getType() == material && !ignoreList.contains(adjacentBlock)) {
            return adjacentBlock;
        }
    }

    return null;
}
 
Example 6
Source File: LWC.java    From Modern-LWC with MIT License 6 votes vote down vote up
/**
 * Find a protection that is adjacent to another block on any of the block's 6
 * sides
 *
 * @param block
 * @param ignore
 * @return
 */
public List<Protection> findAdjacentProtectionsOnAllSides(Block block, Block... ignore) {
    BlockFace[] faces = new BlockFace[]{BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST,
            BlockFace.UP, BlockFace.DOWN};
    List<Block> ignoreList = Arrays.asList(ignore);
    List<Protection> found = new ArrayList<Protection>();

    for (BlockFace face : faces) {
        Protection protection;
        Block adjacentBlock = block.getRelative(face);

        if (!ignoreList.contains(adjacentBlock.getLocation())
                && (protection = findProtection(adjacentBlock.getLocation())) != null) {
            found.add(protection);
        }
    }

    return found;
}
 
Example 7
Source File: Sign.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() {
    if (isWallSign()) {
        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 8
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 9
Source File: ExtendedRails.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setDirection(BlockFace face, boolean isOnSlope) {
    boolean extraBitSet = (getData() & 0x8) == 0x8;

    if (face != BlockFace.WEST && face != BlockFace.EAST && face != BlockFace.NORTH && face != BlockFace.SOUTH) {
        throw new IllegalArgumentException("Detector rails and powered rails cannot be set on a curve!");
    }

    super.setDirection(face, isOnSlope);
    setData((byte) (extraBitSet ? (getData() | 0x8) : (getData() & ~0x8)));
}
 
Example 10
Source File: TripwireHook.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public BlockFace getAttachedFace() {
    switch (getData() & 0x3) {
        case 0:
            return BlockFace.NORTH;
        case 1:
            return BlockFace.EAST;
        case 2:
            return BlockFace.SOUTH;
        case 3:
            return BlockFace.WEST;
    }
    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: CraftSkull.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
static BlockFace getBlockFace(byte rotation) {
    switch (rotation % 16) {
        case 0:
            return BlockFace.NORTH;
        case 1:
            return BlockFace.NORTH_NORTH_EAST;
        case 2:
            return BlockFace.NORTH_EAST;
        case 3:
            return BlockFace.EAST_NORTH_EAST;
        case 4:
            return BlockFace.EAST;
        case 5:
            return BlockFace.EAST_SOUTH_EAST;
        case 6:
            return BlockFace.SOUTH_EAST;
        case 7:
            return BlockFace.SOUTH_SOUTH_EAST;
        case 8:
            return BlockFace.SOUTH;
        case 9:
            return BlockFace.SOUTH_SOUTH_WEST;
        case 10:
            return BlockFace.SOUTH_WEST;
        case 11:
            return BlockFace.WEST_SOUTH_WEST;
        case 12:
            return BlockFace.WEST;
        case 13:
            return BlockFace.WEST_NORTH_WEST;
        case 14:
            return BlockFace.NORTH_WEST;
        case 15:
            return BlockFace.NORTH_NORTH_WEST;
        default:
            throw new AssertionError(rotation);
    }
}
 
Example 13
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 14
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 15
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 16
Source File: MultiBlockListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean compareMaterials(Block b, Material[] blocks, boolean onlyTwoWay) {
    if (!compareMaterialsVertical(b, blocks[1], blocks[4], blocks[7])) {
        return false;
    }

    BlockFace[] directions = onlyTwoWay ? new BlockFace[] { BlockFace.NORTH, BlockFace.EAST } : new BlockFace[] { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };

    for (BlockFace direction : directions) {
        if (compareMaterialsVertical(b.getRelative(direction), blocks[0], blocks[3], blocks[6]) && compareMaterialsVertical(b.getRelative(direction.getOppositeFace()), blocks[2], blocks[5], blocks[8])) {
            return true;
        }
    }

    return false;
}
 
Example 17
Source File: Banner.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public BlockFace getFacing() {
    byte data = getData();

    if (!isWallBanner()) {
        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 18
Source File: MapBuilder.java    From AnnihilationPro with MIT License 4 votes vote down vote up
public static BlockFace getCardinalDirection(Player player)
{
	BlockFace f = null;
	double rotation = (player.getLocation().getYaw() - 90) % 360;
	if (rotation < 0)
	{
		rotation += 360.0;
	}
	if (0 <= rotation && rotation < 22.5)
	{
		f = BlockFace.EAST;
	}
		//
		else if (22.5 <= rotation && rotation < (67.5/2))
		{
			f = BlockFace.EAST;
		}
		else if ((67.5/2) <= rotation && rotation < 67.5)
		{
			f = BlockFace.SOUTH;
		}
		//
	else if (67.5 <= rotation && rotation < 112.5)
	{
		f = BlockFace.SOUTH;
	}
		//
		else if (112.5 <= rotation && rotation < (157.5/2))
		{
			f = BlockFace.SOUTH;
		}
		else if ((157.5/2) <= rotation && rotation < 157.5)
		{
			f = BlockFace.WEST;
		}
		//
	else if (157.5 <= rotation && rotation < 202.5)
	{
		f = BlockFace.WEST;
	}
		//
		else if (202.5 <= rotation && rotation < (247.5/2))
		{
			f = BlockFace.WEST;
		}
		else if ((247.5/2) <= rotation && rotation < 247.5)
		{
			f = BlockFace.NORTH;
		}
		//
	else if (247.5 <= rotation && rotation < 292.5)
	{
		f = BlockFace.NORTH;
	}
		//
		else if (292.5 <= rotation && rotation < (337.5/2))
		{
			f = BlockFace.NORTH;
		}
		else if ((337.5/2) <= rotation && rotation < 337.5)
		{
			f = BlockFace.EAST;
		}
		//
	else if (337.5 <= rotation && rotation < 360.0)
	{
		f = BlockFace.EAST;
	}
	else
	{
		f = null;
	}
	return f.getOppositeFace();
}
 
Example 19
Source File: DragonRushListener.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onEnable(){
    if (!GameManager.getGameManager().getConfiguration().getEnableTheEnd()){
        Bukkit.broadcastMessage(ChatColor.RED + "[UhcCore] For DragonRush the end needs to be enabled first!");
        getScenarioManager().removeScenario(Scenario.DRAGONRUSH);
        return;
    }

    Location portalLoc = getPortalLocation();

    portalBlocks.add(portalLoc.clone().add(1, 0, 2).getBlock());
    portalBlocks.add(portalLoc.clone().add(0, 0, 2).getBlock());
    portalBlocks.add(portalLoc.clone().add(-1, 0, 2).getBlock());

    portalBlocks.add(portalLoc.clone().add(-2, 0, 1).getBlock());
    portalBlocks.add(portalLoc.clone().add(-2, 0, 0).getBlock());
    portalBlocks.add(portalLoc.clone().add(-2, 0, -1).getBlock());

    portalBlocks.add(portalLoc.clone().add(1, 0, -2).getBlock());
    portalBlocks.add(portalLoc.clone().add(0, 0, -2).getBlock());
    portalBlocks.add(portalLoc.clone().add(-1, 0, -2).getBlock());

    portalBlocks.add(portalLoc.clone().add(2, 0, 1).getBlock());
    portalBlocks.add(portalLoc.clone().add(2, 0, 0).getBlock());
    portalBlocks.add(portalLoc.clone().add(2, 0, -1).getBlock());

    int i = 0;
    BlockFace blockFace = BlockFace.NORTH;
    for (Block block : portalBlocks){
        block.setType(UniversalMaterial.END_PORTAL_FRAME.getType());
        VersionUtils.getVersionUtils().setEndPortalFrameOrientation(block, blockFace);
        if (RandomUtils.randomInteger(0, 2) == 1){
            VersionUtils.getVersionUtils().setEye(block, true);
        }
        i++;
        if (i == 3){
            i = 0;
            if (blockFace == BlockFace.NORTH){
                blockFace = BlockFace.EAST;
            }else if (blockFace == BlockFace.EAST){
                blockFace = BlockFace.SOUTH;
            }else if (blockFace == BlockFace.SOUTH){
                blockFace = BlockFace.WEST;
            }
        }
    }
}
 
Example 20
Source File: Utils.java    From Shopkeepers with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Checks if the given {@link BlockFace} is valid to be used for a wall sign.
 * 
 * @param blockFace
 * @return
 */
public static boolean isWallSignFace(BlockFace blockFace) {
	return blockFace == BlockFace.NORTH || blockFace == BlockFace.SOUTH || blockFace == BlockFace.EAST || blockFace == BlockFace.WEST;
}