Add ServerPlayerFacingPacket

This commit is contained in:
Jonas Herzig 2018-07-19 12:26:05 +02:00
parent 304c8b73be
commit d7a39e67df
4 changed files with 98 additions and 1 deletions

View file

@ -80,6 +80,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntit
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerVehicleMovePacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerAbilitiesPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerChangeHeldItemPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerFacingPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerSetExperiencePacket;
@ -391,7 +392,7 @@ public class MinecraftProtocol extends PacketProtocol {
this.registerIncoming(0x2E, ServerPlayerAbilitiesPacket.class);
this.registerIncoming(0x2F, ServerCombatPacket.class);
this.registerIncoming(0x30, ServerPlayerListEntryPacket.class);
// FIXME: 0x31
this.registerIncoming(0x31, ServerPlayerFacingPacket.class);
this.registerIncoming(0x32, ServerPlayerPositionRotationPacket.class);
this.registerIncoming(0x33, ServerPlayerUseBedPacket.class);
this.registerIncoming(0x34, ServerUnlockRecipesPacket.class);

View file

@ -13,6 +13,7 @@ import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
import com.github.steveice10.mc.protocol.data.game.entity.Effect;
import com.github.steveice10.mc.protocol.data.game.entity.EntityStatus;
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
import com.github.steveice10.mc.protocol.data.game.entity.FeetOrEyes;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.AttributeType;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOperation;
import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierType;
@ -894,6 +895,9 @@ public class MagicValues {
register(EquipmentSlot.CHESTPLATE, 4);
register(EquipmentSlot.HELMET, 5);
register(FeetOrEyes.FEET, 0);
register(FeetOrEyes.EYES, 1);
register(SoundCategory.MASTER, 0);
register(SoundCategory.MUSIC, 1);
register(SoundCategory.RECORD, 2);

View file

@ -0,0 +1,6 @@
package com.github.steveice10.mc.protocol.data.game.entity;
public enum FeetOrEyes {
FEET,
EYES;
}

View file

@ -0,0 +1,86 @@
package com.github.steveice10.mc.protocol.packet.ingame.server.entity.player;
import com.github.steveice10.mc.protocol.data.MagicValues;
import com.github.steveice10.mc.protocol.data.game.entity.FeetOrEyes;
import com.github.steveice10.mc.protocol.packet.MinecraftPacket;
import com.github.steveice10.packetlib.io.NetInput;
import com.github.steveice10.packetlib.io.NetOutput;
import java.io.IOException;
public class ServerPlayerFacingPacket extends MinecraftPacket {
private FeetOrEyes origin; // presumably the origin from which pitch is calculated at
private double x;
private double y;
private double z;
private Integer targetEntityId;
private FeetOrEyes targetEntityFeetOrEyes;
@SuppressWarnings("unused")
private ServerPlayerFacingPacket() {
}
public ServerPlayerFacingPacket(FeetOrEyes origin, double x, double y, double z) {
this.origin = origin;
this.x = x;
this.y = y;
this.z = z;
}
public ServerPlayerFacingPacket(FeetOrEyes origin, int targetEntityId, FeetOrEyes lookAt) {
this.origin = origin;
this.targetEntityId = targetEntityId;
this.targetEntityFeetOrEyes = lookAt;
}
public FeetOrEyes getOrigin() {
return origin;
}
public double getX() {
return this.x;
}
public double getY() {
return this.y;
}
public double getZ() {
return this.z;
}
public Integer getTargetEntityId() {
return targetEntityId;
}
public FeetOrEyes getTargetEntityFeetOrEyes() {
return targetEntityFeetOrEyes;
}
@Override
public void read(NetInput in) throws IOException {
this.origin = MagicValues.key(FeetOrEyes.class, in.readVarInt());
this.x = in.readDouble();
this.y = in.readDouble();
this.z = in.readDouble();
if (in.readBoolean()) {
this.targetEntityId = in.readVarInt();
this.targetEntityFeetOrEyes = MagicValues.key(FeetOrEyes.class, in.readVarInt());
}
}
@Override
public void write(NetOutput out) throws IOException {
out.writeVarInt(MagicValues.value(Integer.class, this.origin));
out.writeDouble(this.x);
out.writeDouble(this.y);
out.writeDouble(this.z);
if (this.targetEntityId != null) {
out.writeBoolean(true);
out.writeVarInt(this.targetEntityId);
out.writeVarInt(MagicValues.value(Integer.class, this.targetEntityFeetOrEyes));
} else {
out.writeBoolean(false);
}
}
}