Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.forge.content.world.node;
- /**
- * | RuneForge 317 |
- * Location.java
- * @version 1.0.0
- * @author SiniSoul (SiniSoul@live.com)
- */
- public final class Location {
- /**
- * The Tile X and Y coordinates.
- */
- private int tilex = 0,
- tiley = 0;
- /**
- * The Height of the location.
- */
- private int height = 0;
- /**
- * The asynchronous Chunk X and Y coordinates; used in region updating.
- */
- private int chunkx = 0,
- chunky = 0;
- /**
- * Sets the Tile X value.
- * @param tilex The Tile X value.
- */
- public void setTileX(int tilex) {
- this.tilex = (tilex & 0xFFFF);
- }
- /**
- * Gets The Tile X, also known as the absolute X.
- * @return The Tile X value.
- */
- public int getTileX() {
- return tilex;
- }
- /**
- * Sets the Tile Y value.
- * @param tilex The Tile Y value.
- */
- public void setTileY(int tiley) {
- this.tiley = (tiley & 0xFFFF);
- }
- /**
- * Gets the Tile Y, also known as the absolute Y.
- * @return The Tile Y.
- */
- public int getTileY() {
- return tiley;
- }
- /**
- * Calculates the Chunk X the location is within.
- * @param formated If the chunk is formatted for map positioning or
- * other formatted chunk comparison.
- * @return
- */
- public int calculateChunkX(boolean formated) {
- return formated ? (getTileX() >> 3) - 6 : (getTileX() >> 3);
- }
- /**
- * Calculates the Chunk Y the location is within.
- * @param formated If the chunk is formatted for map positioning or
- * other formatted chunk comparison.
- * @return
- */
- public int calculateChunkY(boolean formated) {
- return formated ? (getTileY() >> 3) - 6 : (getTileY() >> 3);
- }
- /**
- * Updates the Chunk X used for walking/region updating.
- * This chunk is formatted.
- */
- public void updateChunkX() {
- this.chunkx = calculateChunkX(true);
- }
- /**
- * Updates the Chunk Y used for walking/region updating.
- * This chunk is formatted.
- */
- public void updateChunkY() {
- this.chunkx = calculateChunkY(true);
- }
- /**
- * Gets the asynchronous Chunk X.
- * @return This Chunk should only be used in walking/region update.
- */
- public int getChunkX() {
- return chunkx;
- }
- /**
- * Gets the Tile X within the map.
- * @return The calculation should never be greater or equal to 104 or
- * less than or equal to 0.
- */
- public int getMapLocalX() {
- return getTileX() - (getChunkX() << 3);
- }
- /**
- * Gets the asynchronous Chunk Y.
- * @return This Chunk should only be used in walking/region update.
- */
- public int getChunkY() {
- return chunky;
- }
- /**
- * Gets the Tile Y within the map.
- * @return The calculation should never be greater or equal to 104 or
- * less than or equal to 0.
- */
- public int getMapLocalY() {
- return getTileX() - (getChunkY() << 3);
- }
- /**
- * Sets the Height of the location.
- * @param height Since the height is never larger than 2 bits,
- * it is masked to never be greater than 3.
- */
- public void setHeight(int height) {
- this.height = (height & 0x3);
- }
- /**
- * Gets the Height of the location.
- * @return The Height.
- */
- public int getHeight() {
- return height;
- }
- /**
- * Gets/Calculates the Region X.
- * @return The calculation uses the non-formatted chunk.
- */
- public int getRegionX() {
- return calculateChunkX(false) >> 3;
- }
- /**
- * Gets the Tile X within the region, should never be larger than 6 bits.
- * Range is 0 - 63 according; corresponding to the face a region is 64 x 64.
- * @return The result is automatically masked to be smaller than 63.
- */
- public int getRegionLocalX() {
- return (getTileX() - (getRegionX() << 6)) & 0x3F;
- }
- /**
- * Gets/Calculates the Region Y
- * @return The calculation uses the non-formatted chunk.
- */
- public int getRegionY() {
- return calculateChunkY(false) >> 3;
- }
- /**
- * Gets the Tile Y within the region, should never be larger than 6 bits.
- * Range is 0 - 63 according; corresponding to the face a region is 64 x 64.
- * @return The result is automatically masked to be smaller than 63.
- */
- public int getRegionLocalY() {
- return (getTileY() - (getRegionY() << 6)) & 0x3F;
- }
- /**
- * Sets the Tile X Y coordinates and the height of the location.
- *
- * @param tilex The X coordinate of the Tile to set the location at.
- * @param tiley The Y coordinate of the Tile to set the location at.
- * @param height The Height of the location.
- */
- public void set(int tilex, int tiley, int height) {
- setTileX(tilex);
- setTileY(tiley);
- setHeight(height);
- }
- /**
- *
- * @param tilex The X coordinate of the Tile to set the location at.
- * @param tiley The Y coordinate of the Tile to set the location at.
- * @param height The Height of the location.
- *
- * Updates the Chunk X and Y coordinates also.
- */
- public Location(int tilex, int tiley, int height) {
- set(tilex, tiley, height);
- updateChunkX();
- updateChunkY();
- }
- }
Add Comment
Please, Sign In to add comment