PacketSender: re-enable some things, replace x y z values with Location

This commit is contained in:
Bixilon 2020-11-29 22:31:07 +01:00
parent 1d09f928b5
commit 7ffed6a053
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 32 additions and 54 deletions

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.clientbound.play; package de.bixilon.minosoft.protocol.packets.clientbound.play;
import de.bixilon.minosoft.data.entities.EntityRotation;
import de.bixilon.minosoft.data.entities.Location; import de.bixilon.minosoft.data.entities.Location;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket; import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
@ -21,8 +22,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketPlayerPositionAndRotation implements ClientboundPacket { public class PacketPlayerPositionAndRotation implements ClientboundPacket {
Location location; Location location;
float yaw; EntityRotation rotation;
float pitch;
boolean onGround; boolean onGround;
byte flags; byte flags;
@ -31,8 +31,7 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
@Override @Override
public boolean read(InByteBuffer buffer) { public boolean read(InByteBuffer buffer) {
location = buffer.readLocation(); location = buffer.readLocation();
yaw = buffer.readFloat(); rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0);
pitch = buffer.readFloat();
if (buffer.getVersionId() < 6) { if (buffer.getVersionId() < 6) {
onGround = buffer.readBoolean(); onGround = buffer.readBoolean();
return true; return true;
@ -52,19 +51,15 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
@Override @Override
public void log() { public void log() {
Log.protocol(String.format("[IN] Received player location: %s (yaw=%s, pitch=%s)", location, yaw, pitch)); Log.protocol(String.format("[IN] Received player location: (location=%s, rotation=%s, onGround=%b)", location, rotation, onGround));
} }
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
public float getPitch() { public EntityRotation getRotation() {
return pitch; return rotation;
}
public float getYaw() {
return yaw;
} }
public boolean isOnGround() { public boolean isOnGround() {
@ -74,4 +69,5 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
public int getTeleportId() { public int getTeleportId() {
return teleportId; return teleportId;
} }
} }

View File

@ -13,6 +13,7 @@
package de.bixilon.minosoft.protocol.packets.serverbound.play; package de.bixilon.minosoft.protocol.packets.serverbound.play;
import de.bixilon.minosoft.data.entities.EntityRotation;
import de.bixilon.minosoft.data.entities.Location; import de.bixilon.minosoft.data.entities.Location;
import de.bixilon.minosoft.logging.Log; import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.network.Connection; import de.bixilon.minosoft.protocol.network.Connection;
@ -21,61 +22,33 @@ import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
import de.bixilon.minosoft.protocol.protocol.Packets; import de.bixilon.minosoft.protocol.protocol.Packets;
public class PacketPlayerPositionAndRotationSending implements ServerboundPacket { public class PacketPlayerPositionAndRotationSending implements ServerboundPacket {
final double x; Location location;
final double feetY; EntityRotation rotation;
final double headY;
final double z;
final float yaw;
final float pitch;
final boolean onGround; final boolean onGround;
public PacketPlayerPositionAndRotationSending(double x, double feetY, double headY, double z, float yaw, float pitch, boolean onGround) { public PacketPlayerPositionAndRotationSending(Location location, EntityRotation rotation, boolean onGround) {
this.x = x; this.location = location;
this.feetY = feetY; this.rotation = rotation;
this.headY = headY;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
this.onGround = onGround;
}
public PacketPlayerPositionAndRotationSending(double x, double feetY, double z, float yaw, float pitch, boolean onGround) {
this.x = x;
this.feetY = feetY;
this.headY = feetY + 1.62F;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
this.onGround = onGround;
}
public PacketPlayerPositionAndRotationSending(Location location, float yaw, float pitch, boolean onGround) {
this.x = location.getX();
this.feetY = location.getY();
this.z = location.getZ();
this.headY = feetY - 1.62F;
this.yaw = yaw;
this.pitch = pitch;
this.onGround = onGround; this.onGround = onGround;
} }
@Override @Override
public OutPacketBuffer write(Connection connection) { public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION_AND_ROTATION); OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION_AND_ROTATION);
buffer.writeDouble(x); buffer.writeDouble(location.x());
buffer.writeDouble(feetY); buffer.writeDouble(location.y());
if (buffer.getVersionId() < 10) { if (buffer.getVersionId() < 10) {
buffer.writeDouble(headY); buffer.writeDouble(location.y() - 1.62);
} }
buffer.writeDouble(z); buffer.writeDouble(location.z());
buffer.writeFloat(yaw); buffer.writeFloat(rotation.yaw());
buffer.writeFloat(pitch); buffer.writeFloat(rotation.pitch());
buffer.writeBoolean(onGround); buffer.writeBoolean(onGround);
return buffer; return buffer;
} }
@Override @Override
public void log() { public void log() {
Log.protocol(String.format("[OUT] Sending player position and rotation: %s %s %s (yaw=%s, pitch=%s)", x, headY, z, yaw, pitch)); Log.protocol(String.format("[OUT] Sending player position and rotation: (location=%s, rotation=%s, onGround=%b)", location, rotation, onGround));
} }
} }

View File

@ -506,10 +506,11 @@ public class PacketHandler {
public void handle(PacketPlayerPositionAndRotation pkg) { public void handle(PacketPlayerPositionAndRotation pkg) {
// ToDo: GUI should do this // ToDo: GUI should do this
connection.getPlayer().getEntity().setLocation(pkg.getLocation());
if (connection.getVersion().getVersionId() >= 79) { if (connection.getVersion().getVersionId() >= 79) {
connection.sendPacket(new PacketConfirmTeleport(pkg.getTeleportId())); connection.sendPacket(new PacketConfirmTeleport(pkg.getTeleportId()));
} else { } else {
connection.sendPacket(new PacketPlayerPositionAndRotationSending(pkg.getLocation(), pkg.getYaw(), pkg.getPitch(), pkg.isOnGround())); connection.sendPacket(new PacketPlayerPositionAndRotationSending(pkg.getLocation(), pkg.getRotation(), pkg.isOnGround()));
} }
} }

View File

@ -13,6 +13,8 @@
package de.bixilon.minosoft.protocol.protocol; package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.data.entities.EntityRotation;
import de.bixilon.minosoft.data.entities.Location;
import de.bixilon.minosoft.data.player.Hands; import de.bixilon.minosoft.data.player.Hands;
import de.bixilon.minosoft.modding.event.events.ChatMessageSendingEvent; import de.bixilon.minosoft.modding.event.events.ChatMessageSendingEvent;
import de.bixilon.minosoft.modding.event.events.CloseWindowEvent; import de.bixilon.minosoft.modding.event.events.CloseWindowEvent;
@ -58,11 +60,11 @@ public class PacketSender {
} }
public void sendAction(PacketEntityAction.EntityActions action) { public void sendAction(PacketEntityAction.EntityActions action) {
// connection.sendPacket(new PacketEntityAction(connection.getPlayer().getPlayer().getEntityId(), action)); connection.sendPacket(new PacketEntityAction(connection.getPlayer().getEntity().getEntityId(), action));
} }
public void jumpWithHorse(int jumpBoost) { public void jumpWithHorse(int jumpBoost) {
// connection.sendPacket(new PacketEntityAction(connection.getPlayer().getPlayer().getEntityId(), PacketEntityAction.EntityActions.START_HORSE_JUMP, jumpBoost)); connection.sendPacket(new PacketEntityAction(connection.getPlayer().getEntity().getEntityId(), PacketEntityAction.EntityActions.START_HORSE_JUMP, jumpBoost));
} }
public void dropItem() { public void dropItem() {
@ -100,4 +102,10 @@ public class PacketSender {
public void sendLoginPluginMessageResponse(int messageId, OutByteBuffer toSend) { public void sendLoginPluginMessageResponse(int messageId, OutByteBuffer toSend) {
connection.sendPacket(new PacketLoginPluginResponse(messageId, toSend.getOutBytes())); connection.sendPacket(new PacketLoginPluginResponse(messageId, toSend.getOutBytes()));
} }
public void setLocation(Location location, EntityRotation rotation, boolean onGround) {
connection.sendPacket(new PacketPlayerPositionAndRotationSending(location, rotation, onGround));
connection.getPlayer().getEntity().setLocation(location);
connection.getPlayer().getEntity().setRotation(rotation);
}
} }