Archived
0

apply upgraded Location & EntityLocation

This commit is contained in:
2018-08-08 13:19:45 +03:00
parent 83de8629e1
commit a0f91730d0
18 changed files with 69 additions and 77 deletions

View File

@@ -5,6 +5,7 @@
package mc.core.network.proto_1_12_2;
import lombok.AllArgsConstructor;
import mc.core.EntityLocation;
import mc.core.Location;
import mc.core.player.Player;
@@ -22,7 +23,7 @@ public class TeleportManager {
@AllArgsConstructor
private class TpData {
public Player player;
public Location newLocation;
public EntityLocation newLocation;
// TODO необходимо добавить TimeStamp, что бы понимать, когда клиент отвергнул телепортацию
// т.е. идея такова: долгое молчание клиента знак отвержения телепортации.
}
@@ -32,7 +33,7 @@ public class TeleportManager {
private TeleportManager() {}
public int append(Player player, Location location) {
public int append(Player player, EntityLocation location) {
int teleportId;
do {
teleportId = RAND.nextInt(9999);
@@ -45,7 +46,8 @@ public class TeleportManager {
public void apply(int teleportId) {
if (teleportMap.containsKey(teleportId)) {
TpData data = teleportMap.remove(teleportId);
data.player.getLocation().set(data.newLocation);
data.player.getLocation().setXYZ(data.newLocation);
data.player.getLocation().setYawPitch(data.newLocation);
}
}

View File

@@ -8,17 +8,15 @@ import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import mc.core.Location;
import mc.core.EntityLocation;
import mc.core.network.*;
import mc.core.player.Look;
@NoArgsConstructor
@Getter
@Setter
@ToString
public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
private Location location;
private Look look;
private EntityLocation location;
private int teleportId;
private boolean onGround = false;
@@ -27,9 +25,9 @@ public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
netStream.writeDouble(location.getX());
netStream.writeDouble(location.getY());
netStream.writeDouble(location.getZ());
netStream.writeFloat(look.getYaw());
netStream.writeFloat(look.getPitch());
netStream.writeByte(0); // It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute.
netStream.writeFloat(location.getYaw());
netStream.writeFloat(location.getPitch());
netStream.writeByte(0); // It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is setXYZ, the x value is relative and not absolute.
/* X - 0x01
* Y - 0x02
* Z - 0x04
@@ -41,15 +39,13 @@ public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
@Override
public void readSelf(NetInputStream netStream) {
this.location = new Location(
this.location = new EntityLocation(
netStream.readDouble(),
netStream.readDouble(),
netStream.readDouble(),
netStream.readDouble()
);
this.look = new Look(
netStream.readFloat(),
netStream.readFloat()
netStream.readFloat(),
null
);
this.onGround = netStream.readBoolean();

View File

@@ -19,8 +19,19 @@ import mc.core.network.SCPacket;
public class SpawnPositionPacket implements SCPacket {
private Location location;
private int floor_double(double value) {
int i = (int)value;
return value < (double)i ? i - 1 : i;
}
private long location2long(Location location) {
return ((floor_double(location.getX()) & 0x3FFFFFF) << 38)
| ((floor_double(location.getY()) & 0xFFF) << 26)
| (floor_double(location.getZ()) & 0x3FFFFFF);
}
@Override
public void writeSelf(NetOutputStream netStream) {
netStream.writeLong(location.toLong());
netStream.writeLong(location2long(location));
}
}

View File

@@ -21,7 +21,13 @@ public class TabCompletePacket implements CSPacket {
this.hasPosition = netStream.readBoolean();
if (this.hasPosition) {
this.location = new Location(netStream.readLong());
long compactValue = netStream.readLong();
double x = compactValue >> 38;
double y = (compactValue >> 26) & 0xFFF;
double z = compactValue << 38 >> 38; // is normal?
this.location = new Location(x, y, z, null);
}
}
}