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;
import de.bixilon.minosoft.data.entities.EntityRotation;
import de.bixilon.minosoft.data.entities.Location;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
@ -21,8 +22,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
public class PacketPlayerPositionAndRotation implements ClientboundPacket {
Location location;
float yaw;
float pitch;
EntityRotation rotation;
boolean onGround;
byte flags;
@ -31,8 +31,7 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
location = buffer.readLocation();
yaw = buffer.readFloat();
pitch = buffer.readFloat();
rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0);
if (buffer.getVersionId() < 6) {
onGround = buffer.readBoolean();
return true;
@ -52,19 +51,15 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
@Override
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() {
return location;
}
public float getPitch() {
return pitch;
}
public float getYaw() {
return yaw;
public EntityRotation getRotation() {
return rotation;
}
public boolean isOnGround() {
@ -74,4 +69,5 @@ public class PacketPlayerPositionAndRotation implements ClientboundPacket {
public int getTeleportId() {
return teleportId;
}
}

View File

@ -13,6 +13,7 @@
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.logging.Log;
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;
public class PacketPlayerPositionAndRotationSending implements ServerboundPacket {
final double x;
final double feetY;
final double headY;
final double z;
final float yaw;
final float pitch;
Location location;
EntityRotation rotation;
final boolean onGround;
public PacketPlayerPositionAndRotationSending(double x, double feetY, double headY, double z, float yaw, float pitch, boolean onGround) {
this.x = x;
this.feetY = feetY;
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;
public PacketPlayerPositionAndRotationSending(Location location, EntityRotation rotation, boolean onGround) {
this.location = location;
this.rotation = rotation;
this.onGround = onGround;
}
@Override
public OutPacketBuffer write(Connection connection) {
OutPacketBuffer buffer = new OutPacketBuffer(connection, Packets.Serverbound.PLAY_PLAYER_POSITION_AND_ROTATION);
buffer.writeDouble(x);
buffer.writeDouble(feetY);
buffer.writeDouble(location.x());
buffer.writeDouble(location.y());
if (buffer.getVersionId() < 10) {
buffer.writeDouble(headY);
buffer.writeDouble(location.y() - 1.62);
}
buffer.writeDouble(z);
buffer.writeFloat(yaw);
buffer.writeFloat(pitch);
buffer.writeDouble(location.z());
buffer.writeFloat(rotation.yaw());
buffer.writeFloat(rotation.pitch());
buffer.writeBoolean(onGround);
return buffer;
}
@Override
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) {
// ToDo: GUI should do this
connection.getPlayer().getEntity().setLocation(pkg.getLocation());
if (connection.getVersion().getVersionId() >= 79) {
connection.sendPacket(new PacketConfirmTeleport(pkg.getTeleportId()));
} 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;
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.modding.event.events.ChatMessageSendingEvent;
import de.bixilon.minosoft.modding.event.events.CloseWindowEvent;
@ -58,11 +60,11 @@ public class PacketSender {
}
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) {
// 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() {
@ -100,4 +102,10 @@ public class PacketSender {
public void sendLoginPluginMessageResponse(int messageId, OutByteBuffer toSend) {
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);
}
}