38 lines
1.3 KiB
Java
38 lines
1.3 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* io.netty.buffer.ByteBuf
|
|
*/
|
|
package net.minecraft.network.protocol;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
import net.minecraft.network.PacketListener;
|
|
import net.minecraft.network.codec.IdDispatchCodec;
|
|
import net.minecraft.network.codec.StreamCodec;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.network.protocol.PacketFlow;
|
|
import net.minecraft.network.protocol.PacketType;
|
|
|
|
public class ProtocolCodecBuilder<B extends ByteBuf, L extends PacketListener> {
|
|
private final IdDispatchCodec.Builder<B, Packet<? super L>, PacketType<? extends Packet<? super L>>> dispatchBuilder = IdDispatchCodec.builder(Packet::type);
|
|
private final PacketFlow flow;
|
|
|
|
public ProtocolCodecBuilder(PacketFlow flow) {
|
|
this.flow = flow;
|
|
}
|
|
|
|
public <T extends Packet<? super L>> ProtocolCodecBuilder<B, L> add(PacketType<T> type, StreamCodec<? super B, T> serializer) {
|
|
if (type.flow() != this.flow) {
|
|
throw new IllegalArgumentException("Invalid packet flow for packet " + String.valueOf(type) + ", expected " + this.flow.name());
|
|
}
|
|
this.dispatchBuilder.add(type, serializer);
|
|
return this;
|
|
}
|
|
|
|
public StreamCodec<B, Packet<? super L>> build() {
|
|
return this.dispatchBuilder.build();
|
|
}
|
|
}
|
|
|