This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # src/main/java/org/dragonet/proxy/protocol/Protocol.java
- Loading branch information
Showing
4 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...main/java/org/dragonet/proxy/network/translator/pc/PCEntityEquipmentPacketTranslator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ServerEntityEquipmentPacket> { | ||
|
||
@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}; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/org/dragonet/proxy/protocol/packets/MobArmorEquipmentPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |