use of org.dragonet.protocol.PEPacket in project DragonProxy by DragonetMC.
the class PCSpawnPositionPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerSpawnPositionPacket packet) {
CachedEntity entity = session.getEntityCache().getClientEntity();
entity.spawnPosition = new BlockPosition(packet.getPosition());
SetSpawnPositionPacket pk = new SetSpawnPositionPacket();
pk.position = entity.spawnPosition;
return new PEPacket[] {};
}
use of org.dragonet.protocol.PEPacket 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.protocol.PEPacket in project DragonProxy by DragonetMC.
the class PCUpdateTimePacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerUpdateTimePacket packet) {
SetTimePacket pk = new SetTimePacket();
pk.time = (int) Math.abs(packet.getTime());
return new PEPacket[] { pk };
}
use of org.dragonet.protocol.PEPacket 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.protocol.PEPacket in project DragonProxy by DragonetMC.
the class PCPlaySoundPacketTranslator method translate.
public PEPacket[] translate(UpstreamSession session, ServerPlaySoundPacket packet) {
try {
String soundName;
if (BuiltinSound.class.isAssignableFrom(packet.getSound().getClass())) {
BuiltinSound sound = (BuiltinSound) packet.getSound();
soundName = sound.name();
} else {
soundName = ((CustomSound) packet.getSound()).getName();
}
if (soundName == null) {
return null;
}
PlaySoundPacket pk = new PlaySoundPacket();
pk.blockPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
pk.name = soundName;
pk.volume = packet.getVolume();
pk.pitch = packet.getPitch();
return new PEPacket[] { pk };
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations