Archived
0

refactory Location & Look

This commit is contained in:
2018-08-08 13:17:56 +03:00
parent fc4dd46610
commit 83de8629e1
3 changed files with 54 additions and 61 deletions

View File

@@ -0,0 +1,34 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-08-08
*/
package mc.core;
import lombok.Getter;
import lombok.Setter;
import mc.core.world.World;
public class EntityLocation extends Location implements Cloneable {
@Getter
@Setter
private float yaw, pitch;
public EntityLocation(double x, double y, double z, float yaw, float pitch, World world) {
super(x, y, z, world);
setYawPitch(yaw, pitch);
}
public void setYawPitch(float yaw, float pitch) {
this.yaw = yaw;
this.pitch = pitch;
}
public void setYawPitch(EntityLocation entityLocation) {
setYawPitch(entityLocation.yaw, entityLocation.pitch);
}
@Override
public EntityLocation clone() {
return (EntityLocation) super.clone(); //TODO need test
}
}

View File

@@ -1,56 +1,43 @@
/* /*
* DmitriyMX <dimon550@gmail.com> * DmitriyMX <dimon550@gmail.com>
* 2018-04-15 * 2018-08-08
*/ */
package mc.core; package mc.core;
import lombok.AllArgsConstructor; import lombok.Getter;
import lombok.Data; import lombok.Setter;
import mc.core.world.World;
import java.io.Serializable; import java.io.Serializable;
import java.lang.ref.WeakReference;
@AllArgsConstructor public class Location implements Serializable, Cloneable {
@Data @Getter
public class Location implements Serializable, Cloneable{ @Setter
private double x, y, z; private double x, y, z;
private WeakReference<World> refWorld;
private static int floor_double(double value) { public Location(double x, double y, double z, World world) {
int i = (int)value; setXYZ(x, y, z);
return value < (double)i ? i - 1 : i; setWorld(world);
} }
public static Location startPointLocation () { public void setXYZ(double x, double y, double z) {
return new Location(0,10,0);
}
public Location(long compactValue) {
set(compactValue);
}
public void set(double x, double y, double z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
} }
public void set(Location location) { public void setXYZ(Location location) {
this.x = location.x; setXYZ(location.x, location.y, location.z);
this.y = location.y;
this.z = location.z;
} }
public void set(long compactValue) { public World getWorld() {
this.x = compactValue >> 38; return refWorld.get();
this.y = (compactValue >> 26) & 0xFFF;
this.z = compactValue << 38 >> 38; // is normal?
} }
public Location diff(Location location) { public void setWorld(World world) {
return new Location( this.refWorld = new WeakReference<>(world);
this.x - location.x,
this.y - location.y,
this.z - location.z
);
} }
public int getBlockX() { public int getBlockX() {
@@ -65,18 +52,11 @@ public class Location implements Serializable, Cloneable{
return (int) z; return (int) z;
} }
public long toLong() {
return ((floor_double(x) & 0x3FFFFFF) << 38)
| ((floor_double(y) & 0xFFF) << 26)
| (floor_double(z) & 0x3FFFFFF);
}
@Override @Override
public Location clone() { public Location clone() {
try { try {
return (Location) super.clone(); return (Location) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) { // такое в нашем случае вообще возможно?
return null; return null;
} }
} }

View File

@@ -1,21 +0,0 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-04-22
*/
package mc.core.player;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.io.Serializable;
@Data
@AllArgsConstructor
public class Look implements Serializable{
private float yaw, pitch;
public void set(Look look) {
this.yaw = look.yaw;
this.pitch = look.pitch;
}
}