diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java
new file mode 100644
index 000000000..df17337bb
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketPlayerPositionAndRotation.java
@@ -0,0 +1,67 @@
+/*
+ * Codename Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.protocol.packets.clientbound.play;
+
+import de.bixilon.minosoft.game.datatypes.entities.Location;
+import de.bixilon.minosoft.logging.Log;
+import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
+import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
+import de.bixilon.minosoft.protocol.protocol.PacketHandler;
+import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
+
+
+public class PacketPlayerPositionAndRotation implements ClientboundPacket {
+ Location location;
+ float yaw;
+ float pitch;
+ boolean onGround;
+
+ @Override
+ public void read(InPacketBuffer buffer, ProtocolVersion v) {
+ switch (v) {
+ case VERSION_1_7_10:
+ location = buffer.readLocation();
+ yaw = buffer.readFloat();
+ pitch = buffer.readFloat();
+ onGround = buffer.readBoolean();
+ break;
+ }
+ }
+
+ @Override
+ public void log() {
+ Log.protocol(String.format("Received player location: %s - %s %s", location.toString(), yaw, pitch));
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public float getPitch() {
+ return pitch;
+ }
+
+ public float getYaw() {
+ return yaw;
+ }
+
+ public boolean isOnGround() {
+ return onGround;
+ }
+
+ @Override
+ public void handle(PacketHandler h) {
+ h.handle(this);
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java
new file mode 100644
index 000000000..c0baa12ac
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionAndRotationSending.java
@@ -0,0 +1,64 @@
+/*
+ * Codename Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.protocol.packets.serverbound.play;
+
+import de.bixilon.minosoft.logging.Log;
+import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
+import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
+import de.bixilon.minosoft.protocol.protocol.Packets;
+import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
+
+public class PacketPlayerPositionAndRotationSending implements ServerboundPacket {
+ double x;
+ double feetY;
+ double headY;
+ double z;
+ float yaw;
+ float pitch;
+ 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;
+ log();
+ }
+
+
+ @Override
+ public OutPacketBuffer write(ProtocolVersion v) {
+ OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_POSITION_AND_ROTATION));
+ switch (v) {
+ case VERSION_1_7_10:
+ buffer.writeDouble(x);
+ buffer.writeDouble(feetY);
+ buffer.writeDouble(headY);
+ buffer.writeDouble(z);
+ buffer.writeFloat(yaw);
+ buffer.writeFloat(pitch);
+ buffer.writeBoolean(onGround);
+ break;
+ }
+ return buffer;
+ }
+
+ @Override
+ public void log() {
+ Log.protocol(String.format("Sending player position and rotation: %s %s %s - %s %s", x, headY, z, yaw, pitch));
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java
new file mode 100644
index 000000000..eebbf21ce
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerPositionSending.java
@@ -0,0 +1,58 @@
+/*
+ * Codename Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.protocol.packets.serverbound.play;
+
+import de.bixilon.minosoft.logging.Log;
+import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
+import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
+import de.bixilon.minosoft.protocol.protocol.Packets;
+import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
+
+public class PacketPlayerPositionSending implements ServerboundPacket {
+ double x;
+ double feetY;
+ double headY;
+ double z;
+ boolean onGround;
+
+ public PacketPlayerPositionSending(double x, double feetY, double headY, double z, boolean onGround) {
+ this.x = x;
+ this.feetY = feetY;
+ this.headY = headY;
+ this.z = z;
+ this.onGround = onGround;
+ log();
+ }
+
+
+ @Override
+ public OutPacketBuffer write(ProtocolVersion v) {
+ OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_POSITION));
+ switch (v) {
+ case VERSION_1_7_10:
+ buffer.writeDouble(x);
+ buffer.writeDouble(feetY);
+ buffer.writeDouble(headY);
+ buffer.writeDouble(z);
+ buffer.writeBoolean(onGround);
+ break;
+ }
+ return buffer;
+ }
+
+ @Override
+ public void log() {
+ Log.protocol(String.format("Sending player position: %s %s %s", x, headY, z));
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java
new file mode 100644
index 000000000..863d83cea
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/protocol/packets/serverbound/play/PacketPlayerRotationSending.java
@@ -0,0 +1,52 @@
+/*
+ * Codename Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.protocol.packets.serverbound.play;
+
+import de.bixilon.minosoft.logging.Log;
+import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
+import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
+import de.bixilon.minosoft.protocol.protocol.Packets;
+import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
+
+public class PacketPlayerRotationSending implements ServerboundPacket {
+ float yaw;
+ float pitch;
+ boolean onGround;
+
+ public PacketPlayerRotationSending(float yaw, float pitch, boolean onGround) {
+ this.yaw = yaw;
+ this.pitch = pitch;
+ this.onGround = onGround;
+ log();
+ }
+
+
+ @Override
+ public OutPacketBuffer write(ProtocolVersion v) {
+ OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_PLAYER_ROTATION));
+ switch (v) {
+ case VERSION_1_7_10:
+ buffer.writeFloat(yaw);
+ buffer.writeFloat(pitch);
+ buffer.writeBoolean(onGround);
+ break;
+ }
+ return buffer;
+ }
+
+ @Override
+ public void log() {
+ Log.protocol(String.format("Sending player rotation: %s %s", yaw, pitch));
+ }
+}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
index ee450a9d8..3bc47b589 100644
--- a/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
+++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/InByteBuffer.java
@@ -16,6 +16,7 @@ package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.game.datatypes.Direction;
import de.bixilon.minosoft.game.datatypes.Slot;
import de.bixilon.minosoft.game.datatypes.TextComponent;
+import de.bixilon.minosoft.game.datatypes.entities.Location;
import de.bixilon.minosoft.game.datatypes.entities.Pose;
import de.bixilon.minosoft.game.datatypes.particle.BlockParticle;
import de.bixilon.minosoft.game.datatypes.particle.OtherParticles;
@@ -284,4 +285,8 @@ public class InByteBuffer {
public short readAngle() {
return (short) (readByte() * ProtocolDefinition.ANGLE_CALCULATION_CONSTANT);
}
+
+ public Location readLocation() {
+ return new Location(readDouble(), readDouble(), readDouble());
+ }
}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java
index c257eb62d..1616d5f26 100644
--- a/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java
+++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/PacketHandler.java
@@ -27,6 +27,7 @@ import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusPong;
import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusResponse;
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketEncryptionResponse;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketKeepAliveResponse;
+import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPlayerPositionAndRotationSending;
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPluginMessageSending;
import javax.crypto.SecretKey;
@@ -271,4 +272,14 @@ public class PacketHandler {
public void handle(PacketPlayerAbilitiesReceiving pkg) {
//ToDo: used to set fly abilities
}
+
+ public void handle(PacketPlayerPositionAndRotation pkg) {
+ //ToDo handle with gui
+ if (!connection.getPlayer().isSpawnConfirmed()) {
+ // oops, not spawned yet, confirming position
+ //ToDo feet position
+ connection.sendPacket(new PacketPlayerPositionAndRotationSending(pkg.getLocation().getX(), pkg.getLocation().getY() - 1.65F, pkg.getLocation().getY(), pkg.getLocation().getZ(), pkg.getYaw(), pkg.getPitch(), pkg.isOnGround()));
+ connection.getPlayer().setSpawnConfirmed(true);
+ }
+ }
}
diff --git a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java
index 47a022c8c..e866e581c 100644
--- a/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java
+++ b/src/main/java/de/bixilon/minosoft/protocol/protocol/Protocol.java
@@ -80,7 +80,7 @@ public interface Protocol {
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
- packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_ABILITIES, PacketPlayerAbilitiesReceiving.class);
+ packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_POSITION_AND_LOOK, PacketPlayerPositionAndRotation.class);
}
int getProtocolVersion();