mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-10-12 02:13:42 -04:00
Made Point3D, Quaternion, and Location classes Encodables removing the need for getLocation and addLocation methods in SWGPacket class
This commit is contained in:
@@ -27,10 +27,15 @@
|
||||
***********************************************************************************/
|
||||
package resources;
|
||||
|
||||
import network.packets.Packet;
|
||||
import resources.encodables.Encodable;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
|
||||
public class Location implements Serializable {
|
||||
public class Location implements Encodable, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -238,7 +243,26 @@ public class Location implements Serializable {
|
||||
return false;
|
||||
return x == y;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] encode() {
|
||||
ByteBuffer bb = ByteBuffer.allocate(28).order(ByteOrder.LITTLE_ENDIAN);
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(orientation.getX()) ? 0 : orientation.getX()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(orientation.getY()) ? 0 : orientation.getY()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(orientation.getZ()) ? 0 : orientation.getZ()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(orientation.getW()) ? 1 : orientation.getW()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(point.getX()) ? 0 : point.getX()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(point.getY()) ? 0 : point.getY()));
|
||||
Packet.addFloat(bb, (float) (Double.isNaN(point.getZ()) ? 0 : point.getZ()));
|
||||
return bb.array();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuffer data) {
|
||||
orientation.decode(data);
|
||||
point.decode(data);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("Location[TRN=%s, %s %s]", terrain, point, orientation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user