From d54688013dd5b21ec803aca52a6a96f3da9c165d Mon Sep 17 00:00:00 2001 From: HoverEpic Date: Sun, 17 Dec 2017 22:21:37 +0100 Subject: [PATCH] Fix mount and dismount --- .../PCEntitySetPassengerPacketTranslator.java | 89 ++++++++++++------- 1 file changed, 57 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java index 0c87d77e1..d4160279f 100644 --- a/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java +++ b/src/main/java/org/dragonet/proxy/network/translator/pc/PCEntitySetPassengerPacketTranslator.java @@ -13,6 +13,7 @@ package org.dragonet.proxy.network.translator.pc; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntitySetPassengersPacket; +import java.util.Arrays; import org.dragonet.proxy.network.CacheKey; import org.dragonet.proxy.network.UpstreamSession; import org.dragonet.proxy.network.cache.CachedEntity; @@ -24,46 +25,70 @@ public class PCEntitySetPassengerPacketTranslator implements IPCPacketTranslator { public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPacket 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; - } +// for (int id : packet.getPassengerIds()) { +// System.out.println("ServerEntitySetPassengersPacket entity " + packet.getEntityId() + " rider " + id); +// } + + CachedEntity vehicle = session.getEntityCache().getByRemoteEID(packet.getEntityId()); + if (vehicle == null) { + return null; } - SetEntityLinkPacket pk = new SetEntityLinkPacket(); - pk.rider = entity.proxyEid; + // process not passenger (dismount) + for (long id : vehicle.passengers) { + CachedEntity rider = session.getEntityCache().getByLocalEID(id); - if (packet.getPassengerIds().length == 0) //dismount - { - pk.riding = 0; - pk.type = 0; - pk.unknownByte = 0x00; - session.sendPacket(pk); - } else //mount - { - boolean piloteSet = false; - for (int id : packet.getPassengerIds()) { - CachedEntity riding = session.getEntityCache().getByRemoteEID(id); + if (rider == null) { + continue; + } + if (!Arrays.asList(packet.getPassengerIds()).contains(rider.eid)) { - if (riding == null) { - continue; - } + SetEntityLinkPacket pk = new SetEntityLinkPacket(); + pk.riding = vehicle.proxyEid; + pk.rider = rider.proxyEid; + pk.type = SetEntityLinkPacket.TYPE_REMOVE; + pk.unknownByte = 0x00; + session.sendPacket(pk); + + rider.riding = 0; + System.out.println("DISMOUNT\n" + DebugTools.getAllFields(pk)); + } + } - pk.riding = riding.proxyEid; + //clean cache + vehicle.passengers.clear(); - if (!piloteSet) { - pk.type = 1; - piloteSet = true; - } else { - pk.type = 2; - } + //process mount action + boolean piloteSet = false; + for (int id : packet.getPassengerIds()) { - pk.unknownByte = 0x00; - session.sendPacket(pk); + CachedEntity rider = session.getEntityCache().getByRemoteEID(id); + if (id == (int) session.getDataCache().get(CacheKey.PLAYER_EID)) { + rider = session.getEntityCache().getClientEntity(); + } + + if (rider == null) { + continue; + } + + SetEntityLinkPacket pk = new SetEntityLinkPacket(); + pk.riding = vehicle.proxyEid; + pk.rider = rider.proxyEid; + + if (!piloteSet) { + pk.type = SetEntityLinkPacket.TYPE_RIDE; + piloteSet = true; + } else { + pk.type = SetEntityLinkPacket.TYPE_PASSENGER; } + + pk.unknownByte = 0x00; + session.sendPacket(pk); + + vehicle.passengers.add(rider.proxyEid); + rider.riding = vehicle.proxyEid; + System.out.println("MOUNT\n" + DebugTools.getAllFields(pk)); + } return null; }