Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Commit

Permalink
Fix mount and dismount
Browse files Browse the repository at this point in the history
  • Loading branch information
HoverEpic committed Dec 17, 2017
1 parent f3f8f15 commit d546880
Showing 1 changed file with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,46 +25,70 @@
public class PCEntitySetPassengerPacketTranslator implements IPCPacketTranslator<ServerEntitySetPassengersPacket> {

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;
}
Expand Down

0 comments on commit d546880

Please sign in to comment.