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

The following examples show how to use org.bukkit.block.BlockFace#EAST . 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: Diode.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the direction this diode is facing
 *
 * @return The direction this diode 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 2
Source File: DoubleChestMatcher.java    From Modern-LWC with MIT License 6 votes vote down vote up
public static BlockFace getNeighboringChestBlockFace(Chest chest) {
    if (chest.getType() == Chest.Type.SINGLE)
        return null;
    BlockFace face = chest.getFacing();
    switch (face) {
        case NORTH:
            return chest.getType() == Chest.Type.LEFT ? BlockFace.EAST : BlockFace.WEST;
        case SOUTH:
            return chest.getType() == Chest.Type.LEFT ? BlockFace.WEST : BlockFace.EAST;
        case EAST:
            return chest.getType() == Chest.Type.LEFT ? BlockFace.SOUTH : BlockFace.NORTH;
        case WEST:
            return chest.getType() == Chest.Type.LEFT ? BlockFace.NORTH : BlockFace.SOUTH;
        default:
            return null;
    }
}
 
Example 3
Source File: PistonExtensionMaterial.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public BlockFace getFacing() {
    byte dir = (byte) (getData() & 7);

    switch (dir) {
        case 0:
            return BlockFace.DOWN;
        case 1:
            return BlockFace.UP;
        case 2:
            return BlockFace.NORTH;
        case 3:
            return BlockFace.SOUTH;
        case 4:
            return BlockFace.WEST;
        case 5:
            return BlockFace.EAST;
        default:
            return BlockFace.SELF;
    }
}
 
Example 4
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 5
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 6
Source File: Torch.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 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.SOUTH;

        case 0x5:
        default:
            return BlockFace.DOWN;
    }
}
 
Example 7
Source File: PistonBaseMaterial.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public BlockFace getFacing() {
    byte dir = (byte) (getData() & 7);

    switch (dir) {
        case 0:
            return BlockFace.DOWN;
        case 1:
            return BlockFace.UP;
        case 2:
            return BlockFace.NORTH;
        case 3:
            return BlockFace.SOUTH;
        case 4:
            return BlockFace.WEST;
        case 5:
            return BlockFace.EAST;
        default:
            return BlockFace.SELF;
    }
}
 
Example 8
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 9
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 10
Source File: Utils.java    From BedwarsRel with GNU 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 11
Source File: Rails.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the direction these tracks are set
 * <p>
 * Note that tracks are bidirectional and that the direction returned
 * is the ascending direction if the track is set on a slope. If it is
 * set as a curve, the corner of the track is returned.
 */
public BlockFace getDirection() {
    byte d = getConvertedData();

    switch (d) {
        case 0x0:
        default:
            return BlockFace.SOUTH;

        case 0x1:
            return BlockFace.EAST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.WEST;

        case 0x4:
            return BlockFace.NORTH;

        case 0x5:
            return BlockFace.SOUTH;

        case 0x6:
            return BlockFace.NORTH_WEST;

        case 0x7:
            return BlockFace.NORTH_EAST;

        case 0x8:
            return BlockFace.SOUTH_EAST;

        case 0x9:
            return BlockFace.SOUTH_WEST;
    }
}
 
Example 12
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 13
Source File: Lever.java    From Kettle with GNU General Public License v3.0 5 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 0x1:
            return BlockFace.WEST;

        case 0x2:
            return BlockFace.EAST;

        case 0x3:
            return BlockFace.NORTH;

        case 0x4:
            return BlockFace.SOUTH;

        case 0x5:
        case 0x6:
            return BlockFace.DOWN;

        case 0x0:
        case 0x7:
            return BlockFace.UP;

    }

    return null;
}
 
Example 14
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 15
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 16
Source File: BlockImpl.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Block getRelative(BlockFace blockFace) {
    if (blockFace == BlockFace.NORTH) {
        return new BlockImpl(new Location(location.getWorld(), location.getX() + 1, location.getY(), location.getZ()));
    } else if (blockFace == BlockFace.EAST) {
        return new BlockImpl(new Location(location.getWorld(), location.getX(), location.getY(), location.getZ() + 1));
    } else if (blockFace == BlockFace.SOUTH) {
        return new BlockImpl(new Location(location.getWorld(), location.getX() - 1, location.getY(), location.getZ()));
    } else if (blockFace == BlockFace.WEST) {
        return new BlockImpl(new Location(location.getWorld(), location.getX(), location.getY(), location.getZ() - 1));
    }
    return new BlockImpl(new Location(location.getWorld(), location.getX(), location.getY() + 1, location.getZ()));
}
 
Example 17
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 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: Utils.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Determines the axis-aligned {@link BlockFace} for the given direction.
 * If modY is zero only {@link BlockFace}s facing horizontal will be returned.
 * This method takes into account that the values for EAST/WEST and NORTH/SOUTH
 * were switched in some past version of bukkit. So it should also properly work
 * with older bukkit versions.
 * 
 * @param modX
 * @param modY
 * @param modZ
 * @return
 */
public static BlockFace getAxisBlockFace(double modX, double modY, double modZ) {
	double xAbs = Math.abs(modX);
	double yAbs = Math.abs(modY);
	double zAbs = Math.abs(modZ);

	if (xAbs >= zAbs) {
		if (xAbs >= yAbs) {
			if (modX >= 0.0D) {
				// EAST/WEST and NORTH/SOUTH values were switched in some past bukkit version:
				// with this additional checks it should work across different versions
				if (BlockFace.EAST.getModX() == 1) {
					return BlockFace.EAST;
				} else {
					return BlockFace.WEST;
				}
			} else {
				if (BlockFace.EAST.getModX() == 1) {
					return BlockFace.WEST;
				} else {
					return BlockFace.EAST;
				}
			}
		} else {
			if (modY >= 0.0D) {
				return BlockFace.UP;
			} else {
				return BlockFace.DOWN;
			}
		}
	} else {
		if (zAbs >= yAbs) {
			if (modZ >= 0.0D) {
				if (BlockFace.SOUTH.getModZ() == 1) {
					return BlockFace.SOUTH;
				} else {
					return BlockFace.NORTH;
				}
			} else {
				if (BlockFace.SOUTH.getModZ() == 1) {
					return BlockFace.NORTH;
				} else {
					return BlockFace.SOUTH;
				}
			}
		} else {
			if (modY >= 0.0D) {
				return BlockFace.UP;
			} else {
				return BlockFace.DOWN;
			}
		}
	}
}