PacketFacePlayer

This commit is contained in:
Bixilon 2020-07-09 19:53:39 +02:00
parent dbabc8177a
commit be2d3443b9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,96 @@
/*
* 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;
public class PacketFacePlayer implements ClientboundPacket {
PlayerFaces face;
Location location;
int entityId = -1;
PlayerFaces entityFace;
@Override
public boolean read(InPacketBuffer buffer) {
switch (buffer.getVersion()) {
case VERSION_1_13_2:
face = PlayerFaces.byId(buffer.readVarInt());
location = buffer.readLocation();
if (buffer.readBoolean()) {
// entity present
entityId = buffer.readVarInt();
entityFace = PlayerFaces.byId(buffer.readVarInt());
}
return true;
}
return false;
}
@Override
public void log() {
Log.protocol(String.format("Received face player packet (face=%s, location=%s, entityId=%d, entityFace=%s)", face.name(), location.toString(), entityId, ((entityFace != null) ? entityFace.name() : null)));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public PlayerFaces getFace() {
return face;
}
public Location getLocation() {
return location;
}
public int getEntityId() {
return entityId;
}
public PlayerFaces getEntityFace() {
return entityFace;
}
public enum PlayerFaces {
FEET(0),
EYES(1);
final int id;
PlayerFaces(int id) {
this.id = id;
}
public static PlayerFaces byId(int id) {
for (PlayerFaces face : values()) {
if (face.getId() == id) {
return face;
}
}
return null;
}
public int getId() {
return id;
}
}
}

View File

@ -577,4 +577,7 @@ public class PacketHandler {
public void handle(PacketNBTQueryResponse pkg) {
}
public void handle(PacketFacePlayer pkg) {
}
}

View File

@ -146,6 +146,7 @@ public abstract class Protocol implements ProtocolInterface {
packetClassMapping.put(Packets.Clientbound.PLAY_SELECT_ADVANCEMENT_TAB, PacketSelectAdvancementTab.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ADVANCEMENTS, PacketAdvancements.class);
packetClassMapping.put(Packets.Clientbound.PLAY_NBT_QUERY_RESPONSE, PacketNBTQueryResponse.class);
packetClassMapping.put(Packets.Clientbound.PLAY_FACE_PLAYER, PacketFacePlayer.class);
}
public static ProtocolVersion getLowestVersionSupported() {