diff --git a/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java index 583152481..0b2affbe4 100644 --- a/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java +++ b/src/main/java/org/dragonet/proxy/network/PacketTranslatorRegister.java @@ -80,6 +80,7 @@ public final class PacketTranslatorRegister { PC_TO_PE_TRANSLATOR.put(ServerEntityRotationPacket.class, new PCEntityRotationPacketTranslator()); PC_TO_PE_TRANSLATOR.put(ServerEntityVelocityPacket.class, new PCEntityVelocityPacketTranslator()); PC_TO_PE_TRANSLATOR.put(ServerEntityEffectPacket.class, new PCEntityEffectPacketTranslator()); + PC_TO_PE_TRANSLATOR.put(ServerEntityEquipmentPacket.class, new PCEntityEquipmentPacketTranslator()); PC_TO_PE_TRANSLATOR.put(ServerEntityRemoveEffectPacket.class, new PCEntityRemoveEffectPacketTranslator()); PC_TO_PE_TRANSLATOR.put(ServerPlayerHealthPacket.class, new PCUpdateHealthPacketTranslator()); PC_TO_PE_TRANSLATOR.put(ServerEntityAnimationPacket.class, new PCAnimationPacketTranslator()); diff --git a/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java index 72481a044..e053f10e7 100644 --- a/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java +++ b/src/main/java/org/dragonet/proxy/network/cache/CachedEntity.java @@ -18,7 +18,9 @@ import java.util.UUID; import org.dragonet.proxy.data.entity.EntityType; +import org.dragonet.proxy.protocol.type.Slot; +import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.type.object.ObjectType; import java.util.HashMap; @@ -46,10 +48,15 @@ public class CachedEntity { public float yaw; public float headYaw; public float pitch; + public boolean shouldMove = false; - public BlockPosition spawnPosition; + public Slot helmet; + public Slot chestplate; + public Slot leggings; + public Slot boots; + // cache riding datas for dismount public long riding = 0; public Set passengers = new HashSet(); diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEquipmentPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEquipmentPacketTranslator.java new file mode 100644 index 000000000..4d8023ebd --- /dev/null +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntityEquipmentPacketTranslator.java @@ -0,0 +1,54 @@ +package org.dragonet.proxy.network.translator.pc; + +import org.dragonet.proxy.network.CacheKey; +import org.dragonet.proxy.network.UpstreamSession; +import org.dragonet.proxy.network.cache.CachedEntity; +import org.dragonet.proxy.network.translator.IPCPacketTranslator; +import org.dragonet.proxy.network.translator.ItemBlockTranslator; +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.packets.MobArmorEquipmentPacket; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityEquipmentPacket; + +public class PCEntityEquipmentPacketTranslator implements IPCPacketTranslator { + + @Override + public PEPacket[] translate(UpstreamSession session, ServerEntityEquipmentPacket packet) { + CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (entity == null) { + if (packet.getEntityId() == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) { + entity = session.getEntityCache().getClientEntity(); + } else { + return null; + } + return null; + } + + ItemStack items = packet.getItem(); + MobArmorEquipmentPacket aeq = new MobArmorEquipmentPacket(); + switch(packet.getSlot()) { + case HELMET: + entity.helmet = ItemBlockTranslator.translateSlotToPE(items); + break; + case CHESTPLATE: + entity.chestplate = ItemBlockTranslator.translateSlotToPE(items); + break; + case LEGGINGS: + entity.leggings = ItemBlockTranslator.translateSlotToPE(items); + break; + case BOOTS: + entity.boots = ItemBlockTranslator.translateSlotToPE(items); + break; + case MAIN_HAND: + break; + case OFF_HAND: + break; + } + aeq.helmet = entity.helmet; + aeq.chestplate = entity.chestplate; + aeq.leggings = entity.leggings; + aeq.boots = entity.boots; + aeq.rtid = entity.proxyEid; + return new PEPacket[]{aeq}; + } +} diff --git a/src/main/java/org/dragonet/proxy/protocol/packets/MobArmorEquipmentPacket.java b/src/main/java/org/dragonet/proxy/protocol/packets/MobArmorEquipmentPacket.java new file mode 100644 index 000000000..728e2c54e --- /dev/null +++ b/src/main/java/org/dragonet/proxy/protocol/packets/MobArmorEquipmentPacket.java @@ -0,0 +1,39 @@ +package org.dragonet.proxy.protocol.packets; + +import org.dragonet.proxy.protocol.PEPacket; +import org.dragonet.proxy.protocol.ProtocolInfo; +import org.dragonet.proxy.protocol.type.Slot; + +public class MobArmorEquipmentPacket extends PEPacket { + + public long rtid; + public Slot helmet; + public Slot chestplate; + public Slot leggings; + public Slot boots; + + @Override + public int pid() { + return ProtocolInfo.MOB_ARMOR_EQUIPMENT_PACKET; + } + + @Override + public void encodePayload() { + putUnsignedVarLong(rtid); + putSlot(helmet); + putSlot(chestplate); + putSlot(leggings); + putSlot(boots); + + } + + @Override + public void decodePayload() { + rtid = getUnsignedVarLong(); + helmet = getSlot(); + chestplate = getSlot(); + leggings = getSlot(); + boots = getSlot(); + } + +}