use of org.dragonet.protocol.packets.MobEquipmentPacket in project DragonProxy by DragonetMC.
the class PCEntityEquipmentPacketTranslator method translate.
@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;
}
}
ItemStack items = packet.getItem();
boolean handModified = false;
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:
entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
case OFF_HAND:
handModified = true;
break;
}
entity.updateEquipment(session);
if (handModified) {
MobEquipmentPacket equipPacket = new MobEquipmentPacket();
equipPacket.rtid = entity.proxyEid;
equipPacket.item = entity.mainHand;
equipPacket.inventorySlot = 0;
equipPacket.hotbarSlot = 0;
equipPacket.windowId = 0;
session.sendPacket(equipPacket);
}
return null;
}
Aggregations