本文整理匯總了Java中org.spongepowered.api.world.Location.getRelative方法的典型用法代碼示例。如果您正苦於以下問題:Java Location.getRelative方法的具體用法?Java Location.getRelative怎麽用?Java Location.getRelative使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.spongepowered.api.world.Location
的用法示例。
在下文中一共展示了Location.getRelative方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isSignAndShop
import org.spongepowered.api.world.Location; //導入方法依賴的package包/類
private boolean isSignAndShop(Location<World> loc, Direction dir, boolean wall) {
if (loc.getRelative(dir).getBlockType() == (wall ? BlockTypes.WALL_SIGN : BlockTypes.STANDING_SIGN)) {
if (wall) {
Location<World> sign = loc.getRelative(dir);
if (sign.supports(Keys.DIRECTION)) {
Optional<Direction> direction = sign.get(Keys.DIRECTION);
if (direction.isPresent()) {
if (direction.get() != dir)
return false;
}
}
}
Optional<List<Shop>> shops = ShopsData.getShops(loc.getRelative(dir));
if (shops.isPresent())
return true;
}
return false;
}
示例2: findPartnerBlock
import org.spongepowered.api.world.Location; //導入方法依賴的package包/類
/**
* Find a matching partner block. Must be the same type
* and in one of the four cardinal directions.
*
* @param location Location of source block.
* @return Optional Location of partner.
*/
public static Optional<Location<World>> findPartnerBlock(Location<World> location) {
BlockType type = location.getBlockType();
Location<World> north = location.getRelative(Direction.NORTH);
if (north.getBlockType().equals(type)) {
return Optional.of(north);
}
Location<World> west = location.getRelative(Direction.WEST);
if (west.getBlockType().equals(type)) {
return Optional.of(west);
}
Location<World> south = location.getRelative(Direction.SOUTH);
if (south.getBlockType().equals(type)) {
return Optional.of(south);
}
Location<World> east = location.getRelative(Direction.EAST);
if (east.getBlockType().equals(type)) {
return Optional.of(east);
}
return Optional.empty();
}