Archived
0

Location world reference

This commit is contained in:
Forwolk
2018-08-04 11:46:28 +03:00
parent f5057d5a92
commit d84e6ca749
4 changed files with 39 additions and 9 deletions

View File

@@ -4,15 +4,16 @@
*/
package mc.core;
import lombok.AllArgsConstructor;
import lombok.Data;
import mc.core.world.World;
import java.io.Serializable;
import java.lang.ref.WeakReference;
@AllArgsConstructor
@Data
public class Location implements Serializable{
private double x, y, z;
private WeakReference<World> world;
private static int floor_double(double value) {
int i = (int)value;
@@ -23,16 +24,35 @@ public class Location implements Serializable{
return new Location(
location.x,
location.y,
location.z
location.z,
location.getWorld()
);
}
public Location (double x, double y, double z, World world) {
this.x = x;
this.y = y;
this.z = z;
this.world = new WeakReference<>(world);
}
public Location (double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public static Location startPointLocation () {
return new Location(0,10,0);
return new Location(0,10,0, null);
}
public Location(long compactValue) {
set(compactValue);
this.world = new WeakReference<>(null);
}
public Location(long compactValue, World world) {
set(compactValue);
}
public void set(Location location) {
@@ -51,7 +71,8 @@ public class Location implements Serializable{
return new Location(
this.x - location.x,
this.y - location.y,
this.z - location.z
this.z - location.z,
this.getWorld().equals(location.getWorld()) ? this.getWorld() : null
);
}
@@ -72,4 +93,12 @@ public class Location implements Serializable{
| ((floor_double(y) & 0xFFF) << 26)
| (floor_double(z) & 0x3FFFFFF);
}
public World getWorld () {
return this.world.get();
}
public void setWorld (World world) {
this.world = new WeakReference<>(world);
}
}