Archived
0

Merge branch 'dev/utils' into dev/world

This commit is contained in:
2021-07-17 17:37:07 +03:00
10 changed files with 217 additions and 27 deletions

View File

@@ -0,0 +1,11 @@
package mc.protocol.model;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mc.utils.vector.Vector3i;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BlockLocation extends Vector3i {
}

View File

@@ -0,0 +1,10 @@
package mc.protocol.model;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mc.utils.vector.Vector3i;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ChunkSectionLocation extends Vector3i {
}

View File

@@ -1,18 +1,10 @@
package mc.protocol.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mc.utils.vector.Vector3d;
@Data
public class Location {
private double x = 0d;
private double y = 0d;
private double z = 0d;
public Location set(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
return this;
}
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Location extends Vector3d {
}

View File

@@ -1,16 +1,26 @@
package mc.protocol.model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import mc.utils.vector.Vector2f;
@Data
public class Look {
private float yaw;
private float pitch;
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class Look extends Vector2f {
public Look set(float yaw, float pitch) {
this.yaw = yaw;
this.pitch = pitch;
/**
* Equal X
* @return X
*/
public float getYaw() {
return this.getX();
}
return this;
/**
* Equal Y
* @return Y
*/
public float getPitch() {
return this.getY();
}
}

View File

@@ -43,21 +43,27 @@ public class CPlayerPositionAndLookPacket implements ClientSidePacket {
double x = netByteBuf.readDouble();
double y = netByteBuf.readDouble();
double z = netByteBuf.readDouble();
this.position = ProtocolObjectPool.getLocationPool().borrowObject().set(x, y, z);
this.position = ProtocolObjectPool.getLocationPool().borrowObject();
position.set(x, y, z);
float yaw = netByteBuf.readFloat();
float pitch = netByteBuf.readFloat();
this.look = ProtocolObjectPool.getLookPool().borrowObject().set(yaw, pitch);
this.look = ProtocolObjectPool.getLookPool().borrowObject();
this.look.set(yaw, pitch);
this.onGround = netByteBuf.readBoolean();
}
@Override
public void passivate() {
this.position.set(0, 0, 0);
ProtocolObjectPool.getLocationPool().returnObject(this.position);
this.position = null;
this.look.set(0, 0);
ProtocolObjectPool.getLookPool().returnObject(this.look);
this.look = null;
this.onGround = false;
}

View File

@@ -36,15 +36,18 @@ public class PlayerLookPacket implements ClientSidePacket {
public void readSelf(NetByteBuf netByteBuf) {
float yaw = netByteBuf.readFloat();
float pitch = netByteBuf.readFloat();
this.look = ProtocolObjectPool.getLookPool().borrowObject().set(yaw, pitch);
this.look = ProtocolObjectPool.getLookPool().borrowObject();
this.look.set(yaw, pitch);
this.onGround = netByteBuf.readBoolean();
}
@Override
public void passivate() {
this.look.set(0, 0);
ProtocolObjectPool.getLookPool().returnObject(this.look);
this.look = null;
this.onGround = false;
}
}

View File

@@ -39,15 +39,18 @@ public class PlayerPositionPacket implements ClientSidePacket {
double x = netByteBuf.readDouble();
double y = netByteBuf.readDouble();
double z = netByteBuf.readDouble();
this.position = ProtocolObjectPool.getLocationPool().borrowObject().set(x, y, z);
this.position = ProtocolObjectPool.getLocationPool().borrowObject();
this.position.set(x, y, z);
this.onGround = netByteBuf.readBoolean();
}
@Override
public void passivate() {
this.position.set(0, 0, 0);
ProtocolObjectPool.getLocationPool().returnObject(this.position);
this.position = null;
this.onGround = false;
}

View File

@@ -0,0 +1,49 @@
package mc.utils.vector;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@EqualsAndHashCode
@ToString
public class Vector2f {
private float x;
private float y;
public Vector2f(float x, float y) {
this.x = x;
this.y = y;
}
public Vector2f(Vector2f vector2f) {
this(vector2f.getX(), vector2f.getY());
}
public Vector2f() {
this(0f, 0f);
}
public void set(float x, float y) {
this.x = x;
this.y = y;
}
public void set(Vector2f vector2f) {
this.set(vector2f.getX(), vector2f.getY());
}
public void add(float x, float y) {
this.x += x;
this.y += y;
}
public void add(Vector2f vector2f) {
this.add(vector2f.getX(), vector2f.getY());
}
public Vector2f copy() {
return new Vector2f(this);
}
}

View File

@@ -0,0 +1,53 @@
package mc.utils.vector;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@EqualsAndHashCode
@ToString
public class Vector3d {
private double x;
private double y;
private double z;
public Vector3d(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector3d(Vector3d vector3d) {
this(vector3d.getX(), vector3d.getY(), vector3d.getZ());
}
public Vector3d() {
this(0d, 0d, 0d);
}
public void set(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public void set(Vector3d vector3d) {
this.set(vector3d.getX(), vector3d.getY(), vector3d.getZ());
}
public void add(double x, double y, double z) {
this.x += x;
this.y += y;
this.z += z;
}
public void add(Vector3d vector3d) {
this.add(vector3d.getX(), vector3d.getY(), vector3d.getZ());
}
public Vector3d copy() {
return new Vector3d(this);
}
}

View File

@@ -0,0 +1,53 @@
package mc.utils.vector;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
@Getter
@EqualsAndHashCode
@ToString
public class Vector3i {
private int x;
private int y;
private int z;
public Vector3i(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public Vector3i(Vector3i vector3i) {
this(vector3i.getX(), vector3i.getY(), vector3i.getZ());
}
public Vector3i() {
this(0, 0, 0);
}
public void set(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
public void set(Vector3i vector3i) {
this.set(vector3i.getX(), vector3i.getY(), vector3i.getZ());
}
public void add(int x, int y, int z) {
this.x += x;
this.y += y;
this.z += z;
}
public void add(Vector3i vector3i) {
this.add(vector3i.getX(), vector3i.getY(), vector3i.getZ());
}
public Vector3i copy() {
return new Vector3i(this);
}
}