use of io.xol.chunkstories.api.client.net.ClientPacketsProcessor in project chunkstories-core by Hugobros3.
the class PacketExplosionEffect method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
center = new Vector3d(in.readDouble(), in.readDouble(), in.readDouble());
radius = in.readDouble();
debrisSpeed = in.readDouble();
f = in.readFloat();
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
WorldEffects.createFireballFx(cpp.getWorld(), center, radius, debrisSpeed, f);
}
}
use of io.xol.chunkstories.api.client.net.ClientPacketsProcessor in project chunkstories-api by Hugobros3.
the class PacketParticle method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
particleName = in.readUTF();
Vector3d position = new Vector3d();
position.x = (in.readDouble());
position.y = (in.readDouble());
position.z = (in.readDouble());
Vector3d velocity = new Vector3d();
if (in.readBoolean()) {
velocity.x = (in.readDouble());
velocity.y = (in.readDouble());
velocity.z = (in.readDouble());
}
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
cpp.getContext().getParticlesManager().spawnParticleAtPositionWithVelocity(particleName, position, velocity);
}
}
use of io.xol.chunkstories.api.client.net.ClientPacketsProcessor in project chunkstories-api by Hugobros3.
the class PacketVelocityDelta method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
Vector3d delta = new Vector3d(in.readDouble(), in.readDouble(), in.readDouble());
EntityControllable entity = ((ClientPacketsProcessor) processor).getContext().getPlayer().getControlledEntity();
if (entity != null && entity instanceof EntityWithVelocity) {
System.out.println("Debug: received velocity delta " + delta);
((EntityWithVelocity) entity).getVelocityComponent().addVelocity(delta);
}
}
use of io.xol.chunkstories.api.client.net.ClientPacketsProcessor in project chunkstories-api by Hugobros3.
the class PacketVoxelUpdate method process.
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException {
if (processor instanceof ClientPacketsProcessor) {
ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
int x = in.readInt();
int y = in.readInt();
int z = in.readInt();
int data = in.readInt();
Voxel voxel = world.getContentTranslator().getVoxelForId(VoxelFormat.id(data));
byte nextComponent = in.readByte();
try {
ChunkCell context = cpp.getWorld().getChunkWorldCoordinates(x, y, z).poke(x, y, z, voxel, VoxelFormat.sunlight(data), VoxelFormat.blocklight(data), VoxelFormat.meta(data), null);
while (nextComponent != 0) {
String componentName = in.readUTF();
context.components().get(componentName).pull(sender, in);
nextComponent = in.readByte();
}
} catch (WorldException e) {
// Maybe the world wasn't ready ?
// Edge case: what happens we receive an update for a chunk we haven't received the data yet ?
// The best option would be to delay the process but this is complicated for a rare instance
// Maybe one day
}
} else {
// Fail hard
}
}
use of io.xol.chunkstories.api.client.net.ClientPacketsProcessor in project chunkstories by Hugobros3.
the class PacketSoundSource method process.
@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
String soundName = in.readUTF();
long UUID = in.readLong();
boolean hasPosition = in.readBoolean();
Vector3dc position = null;
if (hasPosition) {
position = new Vector3d(in.readFloat(), in.readFloat(), in.readFloat());
}
// boolean loop = in.readBoolean();
// boolean isAmbient = in.readBoolean();
// boolean buffered = in.readBoolean();
byte modeByte = in.readByte();
Mode mode = Mode.values()[modeByte];
boolean stopped = in.readBoolean();
float pitch = in.readFloat();
float gain = in.readFloat();
float attenuationStart = in.readFloat();
float attenuationEnd = in.readFloat();
if (!(processor instanceof ClientPacketsProcessor))
return;
ClientPacketsProcessor cpe = (ClientPacketsProcessor) processor;
SoundSource soundSource = cpe.getContext().getSoundManager().getSoundSourceByUUID(UUID);
// ALSoundSource soundSource = (ALSoundSource) Client.getInstance().getSoundManager().getSoundSourceByUUID(UUID);
if (soundSource == null && stopped)
return;
if (soundSource == null) {
soundSource = cpe.getContext().getSoundManager().replicateServerSoundSource(soundName, mode, position, pitch, gain, attenuationStart, attenuationEnd, UUID);
return;
}
if (stopped) {
soundSource.stop();
return;
}
// Update the soundSource with all we can
soundSource.setPosition(position);
soundSource.setPitch(pitch);
soundSource.setGain(gain);
soundSource.setAttenuationStart(attenuationStart);
soundSource.setAttenuationEnd(attenuationEnd);
}
Aggregations