#Batch particle packet

5 messages · Page 1 of 1 (latest)

worthy jackal
#

Code:

public class BatchParticleS2CPacket implements Packet<ClientPlayPacketListener>{
    public static final PacketCodec<RegistryByteBuf, BatchParticleS2CPacket> CODEC = Packet.createCodec(BatchParticleS2CPacket::write, BatchParticleS2CPacket::new);
    private final float[] x;
    private final float[] y;
    private final float[] z;
    private final ParticleEffect parameters;

    public <T extends ParticleEffect> BatchParticleS2CPacket(T parameters, float[] x, float[] y, float[] z) {
        this.parameters = parameters;
        this.x = x;
        this.y = y;
        this.z = z;
    }

    private BatchParticleS2CPacket(RegistryByteBuf buf) {
        int length = buf.readInt();
        this.x = new float[length];
        this.y = new float[length];
        this.z = new float[length];
        for (int i = 0; i < length; i++) {
            this.x[i] = buf.readFloat();
            this.y[i] = buf.readFloat();
            this.z[i] = buf.readFloat();
        }
        this.parameters = ParticleTypes.PACKET_CODEC.decode(buf);
    }

    private void write(RegistryByteBuf buf) {
        buf.writeInt(this.x.length);
        for (int i = 0; i < this.x.length; i += 3) {
            buf.writeFloat(this.x[i]);
            buf.writeFloat(this.y[i + 1]);
            buf.writeFloat(this.z[i + 2]);
        }
        ParticleTypes.PACKET_CODEC.encode(buf, this.parameters);
    }

    @Override
    public PacketType<BatchParticleS2CPacket> getPacketId() {
        return PlayPackets.LEVEL_PARTICLES;
    }

    @Override
    public void apply(ClientPlayPacketListener clientPlayPacketListener) {
        clientPlayPacketListener.onParticle(this);
    }

    public float getX(int index) {
        return this.x[index];
    }

    public float getY(int index) {
        return this.y[index];
    }

    public float getZ(int index) {
        return this.z[index];
    }

    public ParticleEffect getParameters() {
        return this.parameters;
    }
}
#

So i am trying to make a custom packet that basically hosts a particle with all of the position. This is for optimisation as currently the server sends a bunch of very small packets(ParticleS2CPacket) and well i try to get it working

#

the thing i basically want is optimise the rendering for large amounts particles, so i removed some unnedeed data and thats why i am making my own packet

worthy jackal
#

(well this is gonna be complicated to make)

worthy jackal
#

Anyone?