How to get relative block for facing?

Hello,

I’ve take a look on google for few hours and didnt find a solution to get the relative block using Direction, equivalent to “block.getRelative(BlockFace.EAST)”.

I found this example on this page: org.spongepowered.api.util.Direction Java Exaples

Example 6
Project: Lift File: SpongeElevatorManager.java View source code Vote up 6 votes

public static void scanBaseBlocks(BlockLoc block, SpongeElevator elevator){
if (elevator.baseBlocks.size() >= SpongeLift.maxLiftArea || elevator.baseBlocks.contains(block))
return;
elevator.baseBlocks.add(block);
if (block.getRelative(Direction.NORTH).getType() == elevator.baseBlockType)
scanBaseBlocks(block.getRelative(Direction.NORTH), elevator);
if (block.getRelative(Direction.EAST).getType() == elevator.baseBlockType)
scanBaseBlocks(block.getRelative(Direction.EAST), elevator);
if (block.getRelative(Direction.SOUTH).getType() == elevator.baseBlockType)
scanBaseBlocks(block.getRelative(Direction.SOUTH), elevator);
if (block.getRelative(Direction.WEST).getType() == elevator.baseBlockType)
scanBaseBlocks(block.getRelative(Direction.WEST), elevator);
return;
}

But seem to API dont have the BlockLoc type. How to get the block relative to another based on Direction?

Thanks.

BlockLoc was renamed to simply Location.

So if you wanted to get the block above, you could use Location up = Location.getRelative(Direction.UP)

1 Like

Keep in mind that during 2015 Sponge was under heavy development, and many breaking changes were made to the API. This means many examples and documentation (including our own) may be incorrect.

From 2016 onwards, from version 3.0.0, there will be much less of these changes. When we do make them, this will be clear from the version number.

Yayy, works! Thank you!