From 5116f250ad2e7d30ddd26fd4d36bff5a21d90847 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sat, 11 Apr 2020 18:48:04 -0400 Subject: [PATCH] Add item collection animation --- .../java/world/JavaCollectItemTranslator.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java new file mode 100644 index 000000000..c6af7a138 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java @@ -0,0 +1,30 @@ +package org.geysermc.connector.network.translators.java.world; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityCollectItemPacket; +import com.nukkitx.protocol.bedrock.packet.TakeItemEntityPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + +@Translator(packet = ServerEntityCollectItemPacket.class) +public class JavaCollectItemTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityCollectItemPacket packet, GeyserSession session) { + // This is the definition of translating - both packets take the same values + TakeItemEntityPacket takeItemEntityPacket = new TakeItemEntityPacket(); + // Collected entity is the item + Entity collectedEntity = session.getEntityCache().getEntityByJavaId(packet.getCollectedEntityId()); + // Collector is the entity picking up the item + Entity collectorEntity; + if (packet.getCollectorEntityId() == session.getPlayerEntity().getEntityId()) { + collectorEntity = session.getPlayerEntity(); + } else { + collectorEntity = session.getEntityCache().getEntityByJavaId(packet.getCollectorEntityId()); + } + takeItemEntityPacket.setRuntimeEntityId(collectorEntity.getGeyserId()); + takeItemEntityPacket.setItemRuntimeEntityId(collectedEntity.getGeyserId()); + session.getUpstream().sendPacket(takeItemEntityPacket); + } +}