Search in sources :

Example 1 with ClientPacketsProcessor

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);
    }
}
Also used : ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d)

Example 2 with ClientPacketsProcessor

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);
    }
}
Also used : ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d)

Example 3 with ClientPacketsProcessor

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);
    }
}
Also used : ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) EntityWithVelocity(io.xol.chunkstories.api.entity.interfaces.EntityWithVelocity) Vector3d(org.joml.Vector3d) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 4 with ClientPacketsProcessor

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
    }
}
Also used : ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) WorldException(io.xol.chunkstories.api.exceptions.world.WorldException) Voxel(io.xol.chunkstories.api.voxel.Voxel) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell)

Example 5 with ClientPacketsProcessor

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);
}
Also used : Vector3dc(org.joml.Vector3dc) SoundSource(io.xol.chunkstories.api.sound.SoundSource) ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d) Mode(io.xol.chunkstories.api.sound.SoundSource.Mode)

Aggregations

ClientPacketsProcessor (io.xol.chunkstories.api.client.net.ClientPacketsProcessor)7 Vector3d (org.joml.Vector3d)5 Location (io.xol.chunkstories.api.Location)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)1 EntityWithVelocity (io.xol.chunkstories.api.entity.interfaces.EntityWithVelocity)1 UnknownComponentException (io.xol.chunkstories.api.exceptions.UnknownComponentException)1 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)1 PacketWorld (io.xol.chunkstories.api.net.PacketWorld)1 Player (io.xol.chunkstories.api.player.Player)1 RemotePlayer (io.xol.chunkstories.api.server.RemotePlayer)1 SoundSource (io.xol.chunkstories.api.sound.SoundSource)1 Mode (io.xol.chunkstories.api.sound.SoundSource.Mode)1 Voxel (io.xol.chunkstories.api.voxel.Voxel)1 World (io.xol.chunkstories.api.world.World)1 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)1 ChunkCell (io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell)1 Vector3dc (org.joml.Vector3dc)1