use of org.dragonet.protocol.packets.SetEntityLinkPacket in project DragonProxy by DragonetMC.
the class PCEntitySetPassengerPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntitySetPassengersPacket packet) {
CachedEntity vehicle = session.getEntityCache().getByRemoteEID(packet.getEntityId());
if (vehicle == null) {
return null;
}
// process not passenger (dismount)
Iterator<Long> itr = vehicle.passengers.iterator();
while (itr.hasNext()) {
long id = itr.next();
CachedEntity rider = session.getEntityCache().getByLocalEID(id);
if (rider == null) {
continue;
}
if (!Arrays.asList(packet.getPassengerIds()).contains(rider.eid)) {
SetEntityLinkPacket pk = new SetEntityLinkPacket();
pk.riding = vehicle.proxyEid;
pk.rider = rider.proxyEid;
pk.type = SetEntityLinkPacket.TYPE_REMOVE;
setRiding(session, rider, null);
pk.unknownByte = 0x00;
session.putCachePacket(pk);
itr.remove();
rider.riding = 0;
// System.out.println("DISMOUNT\n" + DebugTools.getAllFields(pk));
}
}
// process mount action
boolean piloteSet = false;
for (int id : packet.getPassengerIds()) {
CachedEntity rider = session.getEntityCache().getByRemoteEID(id);
if (rider == null) {
continue;
}
SetEntityLinkPacket pk = new SetEntityLinkPacket();
pk.riding = vehicle.proxyEid;
pk.rider = rider.proxyEid;
if (!piloteSet) {
piloteSet = true;
pk.type = SetEntityLinkPacket.TYPE_RIDE;
setRiding(session, rider, getSeatOffset(rider.peType, 1));
} else {
pk.type = SetEntityLinkPacket.TYPE_PASSENGER;
setRiding(session, rider, getSeatOffset(rider.peType, 2));
}
pk.unknownByte = 0x00;
session.putCachePacket(pk);
vehicle.passengers.add(rider.proxyEid);
rider.riding = vehicle.proxyEid;
// System.out.println("MOUNT\n" + DebugTools.getAllFields(pk));
}
return null;
}
Aggregations