Skip to content

Commit

Permalink
Add support for extended BlockStates.
Browse files Browse the repository at this point in the history
Extended BlockStates include extra properties about a given location such
as if a podzul dirt block is covered by snow or a fence is connected to
other fences.

There are currently 2 ways to retrieve an extended BlockState :

1. From a BlockSnapshot by calling getExtendedState.
2. From a BlockState by calling withExtendedProperties. This method should
only be called on live BlockStates and may not work correctly if used
with a BlockSnapshot such as during a ChangeBlockEvent.
  • Loading branch information
bloodmc committed Oct 31, 2015
1 parent fada308 commit e2c644a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/spongepowered/api/block/BlockSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public interface BlockSnapshot extends LocateableSnapshot<BlockSnapshot> {
*/
BlockState getState();

/**
* Gets the extended {@link BlockState}. This applies extended properties
* that are usually located around the associated {@link BlockType}. Check
* {@link BlockState#withExtendedProperties(Location)} for more info.
*
* @return The extended BlockState
*/
BlockState getExtendedState();

/**
* Creates a copy of the {@link BlockSnapshot} with the provided
* {@link BlockState}. Any additional data associated with a
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/spongepowered/api/block/BlockState.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ public interface BlockState extends ImmutableDataHolder<BlockState>, DirectionRe
*/
BlockType getType();

/**
* Applies extended properties for the current @{link BlockType} if any to
* the current {@link BlockState}. This usually is gathered from surrounding
* {@link BlockState}'s.
*
* <p>Note: This should only be called for live {@link BlockState}'s at
* a specific {@link Location} for accurate results.</p>
*
* <p>
* Examples of some extended properties are:
* </p>
*
* <ul>
* <li>snow on podzul dirt block</li>
* <li>occupied status for beds</li>
* <li>fence connections</li>
* </ul>
*
* @param location The location used to search for extended properties
* @return The blockstate with extended properties included if any
*/
BlockState withExtendedProperties(Location<World> location);

/**
* Gets the associated {@link BlockState} with the cycled
* {@link BaseValue}. Note that only {@link Cycleable} values can be
Expand Down

0 comments on commit e2c644a

Please sign in to comment.