Allow Blocks to be accessed via a long key

The key can be retrieved via methods Location#toBlockKey() and
Block#getBlockKey()

World provides lookup for blocks by long key via method World#getBlockAtKey(long)

The formatting for the key is as follows:

10 bit y|27 bit z|27 bit x

The y value is considered unsigned while z and x are considered two's complement

Y range: [0, 1023]
X, Z range: [-67 108 864, 67 108 863]
This commit is contained in:
Spottedleaf
2018-08-14 21:42:10 -07:00
parent ffe27211fb
commit 8170ae9d64
3 changed files with 124 additions and 1 deletions

View File

@@ -99,6 +99,41 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@NotNull
public Block getBlockAt(@NotNull Location location);
// Paper start
/**
* Gets the {@link Block} at the given block key
*
* @param key The block key. See {@link Block#getBlockKey()}
* @return Block at the key
* @see Block#getBlockKey(int, int, int)
* @deprecated only encodes y block ranges from -512 to 511 and represents an already changed implementation detail
*/
@NotNull
@Deprecated(since = "1.18.1")
public default Block getBlockAtKey(long key) {
int x = Block.getBlockKeyX(key);
int y = Block.getBlockKeyY(key);
int z = Block.getBlockKeyZ(key);
return getBlockAt(x, y, z);
}
/**
* Gets the {@link Location} at the given block key
*
* @param key The block key. See {@link Location#toBlockKey()}
* @return Location at the key
* @see Block#getBlockKey(int, int, int)
*/
@NotNull
@Deprecated(since = "1.18.1")
public default Location getLocationAtKey(long key) {
int x = Block.getBlockKeyX(key);
int y = Block.getBlockKeyY(key);
int z = Block.getBlockKeyZ(key);
return new Location(this, x, y, z);
}
// Paper end
/**
* Gets the highest non-empty (impassable) block at the given coordinates.
*