Remove ICustomPacket and add PayloadChannel. (#9972)

New PayloadChannel that uses the vanilla payload Type for packet distinction
Implement the minecraft:register/unregister channels using the new PayloadChannel
New generic channel builder function allowing people to implement channels however they want.
This commit is contained in:
LexManos authored and GitHub committed 2024-05-14 08:36:42 -07:00
1 parent 640c206117
commit 2b3a4137e1
34 files changed
+1035 -338

No files matched your search

@@ -16,7 +16,7 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.network.Connection;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.network.ICustomPacket;
import net.minecraftforge.network.ForgePayload;
import net.minecraftforge.common.util.LogicalSidedProvider;
import org.jetbrains.annotations.Nullable;
@@ -26,27 +26,30 @@ import java.util.concurrent.CompletableFuture;
// But also expose it as a generic listener event for anyone who cares about it but is outside out channel control system.
public class CustomPayloadEvent extends Event {
private final ResourceLocation channel;
private final FriendlyByteBuf payload;
private final Object payload;
private final FriendlyByteBuf data;
private final Context source;
private final int loginIndex;
public CustomPayloadEvent(ResourceLocation channel, FriendlyByteBuf payload, Context source, int loginIndex) {
public CustomPayloadEvent(ResourceLocation channel, Object payload, Context source, int loginIndex) {
this.channel = channel;
this.payload = payload;
this.data = payload instanceof ForgePayload forge ? forge.data() : null;
this.source = source;
this.loginIndex = loginIndex;
}
public CustomPayloadEvent(ICustomPacket<?> payload, Context source) {
this(payload.getName(), payload.getInternalData(), source, payload.getIndex());
}
public ResourceLocation getChannel() {
return this.channel;
}
@Nullable
public FriendlyByteBuf getPayload() {
return payload;
return data;
}
public Object getPayloadObject() {
return this.payload;
}
public int getLoginIndex() {