-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from mircokroon/dimensions
Added support for custom dimensions
- Loading branch information
Showing
17 changed files
with
1,007 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,101 @@ | ||
package game.data; | ||
|
||
import java.util.Objects; | ||
|
||
public class Coordinate2D { | ||
private static int offsetX = 0; | ||
private static int offsetZ = 0; | ||
|
||
int x; | ||
int z; | ||
|
||
public Coordinate2D(int x, int z) { | ||
this.x = x; | ||
this.z = z; | ||
} | ||
|
||
public Coordinate2D(double x, double z) { | ||
this.x = (int) x; | ||
this.z = (int) z; | ||
} | ||
|
||
public void offset(int x, int z) { | ||
this.x += x; | ||
this.z += z; | ||
} | ||
|
||
public static void setOffset(int x, int z) { | ||
offsetX = x >> 4 << 4; | ||
offsetZ = z >> 4 << 4; | ||
} | ||
|
||
public void offsetGlobal() { | ||
this.x += offsetX; | ||
this.z += offsetZ; | ||
} | ||
|
||
public void offsetChunk() { | ||
this.x += offsetX >> 4; | ||
this.z += offsetZ >> 4; | ||
} | ||
|
||
public boolean isInRange(Coordinate2D other, int distanceX, int distanceZ) { | ||
return Math.abs(this.x - other.x) <= distanceX && Math.abs(this.z - other.z) <= distanceZ; | ||
} | ||
|
||
public boolean isInRange(Coordinate2D other, int distance) { | ||
return isInRange(other, distance, distance); | ||
} | ||
|
||
public Coordinate2D globalToChunk() { | ||
return new Coordinate2D(x >> 4, z >> 4); | ||
} | ||
public Coordinate2D chunkToRegion() { | ||
return new Coordinate2D(x >> 5, z >> 5); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getZ() { | ||
return z; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, z); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { return true; } | ||
if (o == null || getClass() != o.getClass()) { return false; } | ||
Coordinate2D that = (Coordinate2D) o; | ||
return x == that.x && | ||
z == that.z; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "(" + x + ", " + z + ")"; | ||
} | ||
|
||
public Coordinate2D toRegionLocal() { | ||
return new Coordinate2D(toLocal(x), toLocal(z)); | ||
} | ||
|
||
private int toLocal(int pos) { | ||
pos = pos % 32; | ||
if (pos < 0) { | ||
return pos + 32; | ||
} | ||
return pos; | ||
} | ||
|
||
public CoordinateDim2D addDimension(Dimension dimension) { | ||
return new CoordinateDim2D(this, dimension); | ||
} | ||
} | ||
package game.data; | ||
|
||
import game.data.dimension.Dimension; | ||
|
||
import java.util.Objects; | ||
|
||
public class Coordinate2D { | ||
private static int offsetX = 0; | ||
private static int offsetZ = 0; | ||
|
||
int x; | ||
int z; | ||
|
||
public Coordinate2D(int x, int z) { | ||
this.x = x; | ||
this.z = z; | ||
} | ||
|
||
public Coordinate2D(double x, double z) { | ||
this.x = (int) x; | ||
this.z = (int) z; | ||
} | ||
|
||
public void offset(int x, int z) { | ||
this.x += x; | ||
this.z += z; | ||
} | ||
|
||
public static void setOffset(int x, int z) { | ||
offsetX = x >> 4 << 4; | ||
offsetZ = z >> 4 << 4; | ||
} | ||
|
||
public void offsetGlobal() { | ||
this.x += offsetX; | ||
this.z += offsetZ; | ||
} | ||
|
||
public void offsetChunk() { | ||
this.x += offsetX >> 4; | ||
this.z += offsetZ >> 4; | ||
} | ||
|
||
public boolean isInRange(Coordinate2D other, int distanceX, int distanceZ) { | ||
return Math.abs(this.x - other.x) <= distanceX && Math.abs(this.z - other.z) <= distanceZ; | ||
} | ||
|
||
public boolean isInRange(Coordinate2D other, int distance) { | ||
return isInRange(other, distance, distance); | ||
} | ||
|
||
public Coordinate2D globalToChunk() { | ||
return new Coordinate2D(x >> 4, z >> 4); | ||
} | ||
public Coordinate2D chunkToRegion() { | ||
return new Coordinate2D(x >> 5, z >> 5); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getZ() { | ||
return z; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(x, z); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { return true; } | ||
if (o == null || getClass() != o.getClass()) { return false; } | ||
Coordinate2D that = (Coordinate2D) o; | ||
return x == that.x && | ||
z == that.z; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "(" + x + ", " + z + ")"; | ||
} | ||
|
||
public Coordinate2D toRegionLocal() { | ||
return new Coordinate2D(toLocal(x), toLocal(z)); | ||
} | ||
|
||
private int toLocal(int pos) { | ||
pos = pos % 32; | ||
if (pos < 0) { | ||
return pos + 32; | ||
} | ||
return pos; | ||
} | ||
|
||
public CoordinateDim2D addDimension(Dimension dimension) { | ||
return new CoordinateDim2D(this, dimension); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,73 @@ | ||
package game.data; | ||
|
||
public class Coordinate3D extends Coordinate2D { | ||
private int y; | ||
|
||
public Coordinate3D(double x, double y, double z) { | ||
this((int) x, (int) y, (int) z); | ||
} | ||
|
||
public Coordinate3D(int x, int y, int z) { | ||
super(x, z); | ||
this.y = y; | ||
} | ||
|
||
public Coordinate3D add(Coordinate2D change) { | ||
return new Coordinate3D(this.x + change.x, this.y, this.z + change.z); | ||
} | ||
|
||
public void setTo(int x, int y, int z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public Coordinate3D withinChunk() { | ||
return new Coordinate3D(withinChunk(x), y, withinChunk(z)); | ||
} | ||
|
||
private int withinChunk(int val) { | ||
int newVal = val % 16; | ||
if (newVal < 0) { return newVal + 16; } | ||
return newVal; | ||
} | ||
|
||
public CoordinateDim3D addDimension3D(Dimension dimension) { | ||
return new CoordinateDim3D(this, dimension); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "(" + x + ", " + y + ", " + z + ")"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
|
||
Coordinate3D that = (Coordinate3D) o; | ||
|
||
return y == that.y; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + y; | ||
return result; | ||
} | ||
} | ||
package game.data; | ||
|
||
import game.data.dimension.Dimension; | ||
|
||
public class Coordinate3D extends Coordinate2D { | ||
private int y; | ||
|
||
public Coordinate3D(double x, double y, double z) { | ||
this((int) x, (int) y, (int) z); | ||
} | ||
|
||
public Coordinate3D(int x, int y, int z) { | ||
super(x, z); | ||
this.y = y; | ||
} | ||
|
||
public Coordinate3D add(Coordinate2D change) { | ||
return new Coordinate3D(this.x + change.x, this.y, this.z + change.z); | ||
} | ||
|
||
public void setTo(int x, int y, int z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public Coordinate3D withinChunk() { | ||
return new Coordinate3D(withinChunk(x), y, withinChunk(z)); | ||
} | ||
|
||
private int withinChunk(int val) { | ||
int newVal = val % 16; | ||
if (newVal < 0) { return newVal + 16; } | ||
return newVal; | ||
} | ||
|
||
public CoordinateDim3D addDimension3D(Dimension dimension) { | ||
return new CoordinateDim3D(this, dimension); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "(" + x + ", " + y + ", " + z + ")"; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (!super.equals(o)) { | ||
return false; | ||
} | ||
|
||
Coordinate3D that = (Coordinate3D) o; | ||
|
||
return y == that.y; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = super.hashCode(); | ||
result = 31 * result + y; | ||
return result; | ||
} | ||
} |
Oops, something went wrong.