use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityTeleportPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityTeleportPacket 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.absoluteMove(packet.getX(), packet.getY(), packet.getZ(), 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 PCSpawnPaintingPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerSpawnPaintingPacket packet) {
CachedEntity entity = session.getEntityCache().newEntity(packet);
if (entity == null)
return null;
entity.spawn(session);
return null;
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityEffectPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityEffectPacket 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;
}
}
int effectId = MagicValues.value(Integer.class, packet.getEffect());
PocketPotionEffect effect = PocketPotionEffect.getByID(effectId);
if (effect == null) {
System.out.println("Unknown effect ID: " + effectId);
return null;
}
MobEffectPacket eff = new MobEffectPacket();
eff.rtid = entity.proxyEid;
eff.effectId = effect.getEffect();
if (entity.effects.contains(effectId)) {
eff.eventId = MobEffectPacket.EVENT_MODIFY;
} else {
eff.eventId = MobEffectPacket.EVENT_ADD;
entity.effects.add(effectId);
}
eff.amplifier = packet.getAmplifier();
eff.duration = packet.getDuration();
eff.particles = packet.getShowParticles();
return new PEPacket[] { eff };
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCEntityHeadLookPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerEntityHeadLookPacket 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.headYaw = packet.getHeadYaw();
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 = true;
return new PEPacket[] { pk };
}
use of org.dragonet.proxy.network.cache.CachedEntity in project DragonProxy by DragonetMC.
the class PCSpawnExpOrbPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerSpawnExpOrbPacket packet) {
CachedEntity entity = session.getEntityCache().newEntity(packet);
if (entity == null)
return null;
if (session.isSpawned()) {
SpawnExperienceOrb spawnXpOrb = new SpawnExperienceOrb();
spawnXpOrb.position = new Vector3F((float) entity.x, (float) entity.y + entity.peType.getOffset(), (float) entity.z);
spawnXpOrb.count = packet.getExp();
entity.spawned = true;
session.sendPacket(spawnXpOrb);
}
return null;
}
Aggregations