use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCUpdateHealthPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerPlayerHealthPacket packet) {
// Always round up
int newHealth = (int) Math.ceil(packet.getHealth());
SetHealthPacket h = new SetHealthPacket(newHealth);
CachedEntity peSelfPlayer = session.getEntityCache().getClientEntity();
peSelfPlayer.attributes.put(PEEntityAttribute.HEALTH, PEEntityAttribute.findAttribute(PEEntityAttribute.HEALTH).setValue(newHealth));
if (peSelfPlayer.foodPacketCount == 0) {
peSelfPlayer.attributes.put(PEEntityAttribute.FOOD, PEEntityAttribute.findAttribute(PEEntityAttribute.FOOD).setValue(packet.getFood()));
}
UpdateAttributesPacket pk = new UpdateAttributesPacket();
pk.rtid = peSelfPlayer.proxyEid;
pk.entries = peSelfPlayer.attributes.values();
if (newHealth <= 0)
return new PEPacket[] { h, pk, new RespawnPacket() };
return new PEPacket[] { h, pk };
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityEquipmentPacketTranslator method translate.
@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;
}
}
ItemStack items = packet.getItem();
boolean handModified = false;
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:
entity.mainHand = ItemBlockTranslator.translateSlotToPE(items);
case OFF_HAND:
handModified = true;
break;
}
entity.updateEquipment(session);
if (handModified) {
MobEquipmentPacket equipPacket = new MobEquipmentPacket();
equipPacket.rtid = entity.proxyEid;
equipPacket.item = entity.mainHand;
equipPacket.inventorySlot = 0;
equipPacket.hotbarSlot = 0;
equipPacket.windowId = 0;
session.sendPacket(equipPacket);
}
return null;
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityMetadataPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityMetadataPacket packet) {
CachedEntity entity = session.getEntityCache().getByRemoteEID(packet.getEntityId());
if (entity == null) {
if (packet.getEntityId() == session.getEntityCache().getClientEntity().eid)
entity = session.getEntityCache().getClientEntity();
else
return null;
// System.out.println("!!!!!!!!!!!!!!! TRY TO update the player meta from PCEntityMetadataPacketTranslator");
// return null;
}
entity.pcMeta = packet.getMetadata();
if (entity.spawned) {
SetEntityDataPacket pk = new SetEntityDataPacket();
pk.rtid = entity.proxyEid;
pk.meta = EntityMetaTranslator.translateToPE(session, packet.getMetadata(), entity.peType);
session.sendPacket(pk);
} else if (entity.peType == EntityType.PLAYER || entity.peType == EntityType.PAINTING) {
// Do nothing here !
} else
entity.spawn(session);
return null;
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityPositionRotationPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityPositionRotationPacket 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;
}
}
entity.relativeMove(packet.getMovementX(), packet.getMovementY(), packet.getMovementZ(), packet.getYaw(), packet.getPitch());
if (entity.shouldMove) {
MoveEntityPacket pk = new MoveEntityPacket();
pk.rtid = entity.proxyEid;
pk.yaw = (byte) (entity.yaw / (360d / 256d));
pk.headYaw = (byte) (entity.headYaw / (360d / 256d));
pk.pitch = (byte) (entity.pitch / (360d / 256d));
pk.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
pk.onGround = packet.isOnGround();
entity.shouldMove = false;
return new PEPacket[] { pk };
}
return null;
}
use of org.dragonet.proxy.network.cache.CachedEntity 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