Skip to content

Instantly share code, notes, and snippets.

@nsporillo
Created February 17, 2015 21:51
Show Gist options
  • Save nsporillo/418abf2a9ec85caffb69 to your computer and use it in GitHub Desktop.
Save nsporillo/418abf2a9ec85caffb69 to your computer and use it in GitHub Desktop.
Methods
public boolean isOutsideWorldBorder1(FLocation flocation) {
World world = flocation.getWorld();
WorldBorder border = world.getWorldBorder();
Chunk chunk = border.getCenter().getChunk();
// chunkToRegion for the fast divide by 32
int lim = FLocation.chunkToRegion((int) border.getSize());
int diffX = (int) Math.abs(chunk.getX() - flocation.getX());
int diffZ = (int) Math.abs(chunk.getZ() - flocation.getZ());
return diffX > lim || diffZ > lim;
}
public boolean isOutsideWorldBorder2(FLocation flocation) {
World world = flocation.getWorld();
WorldBorder border = world.getWorldBorder();
Chunk chunk = border.getCenter().getChunk();
// blockToChunk for the fast divide by 16
int lim = FLocation.blockToChunk((int) border.getSize());
int diffX = (int) Math.abs(chunk.getX() - flocation.getX());
int diffZ = (int) Math.abs(chunk.getZ() - flocation.getZ());
return diffX + diffZ > lim;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment