mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 00:47:26 -04:00
player position
This commit is contained in:
parent
5b424574ac
commit
2a21f320c4
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user