Skip to content

Commit

Permalink
send minecraft:register on neo
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Feb 23, 2024
1 parent cf00fca commit 225a43f
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 62 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ majorVersion = 0
fabricLoader = 0.15.3
fabricApi = 0.93.1+1.20.4
forge = 49.0.19
neo = 20.4.96-beta
neo = 20.4.171

cf.projectId = 615134
mr.projectId = ftdbN0KK
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package lol.bai.badpackets.impl.fabric;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.impl.platform.PlatformProxy;
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking;
Expand All @@ -9,6 +12,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceLocation;

public class FabricProxy extends PlatformProxy {

Expand All @@ -21,31 +25,31 @@ public boolean canSendVanillaRegisterPackets() {
}

@Override
public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
public Packet<?> createVanillaRegisterConfigS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return HAS_FABRIC_API
? ServerConfigurationNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf)
: super.createVanillaRegisterConfigS2CPacket(buf);
? ServerConfigurationNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf.get())
: super.createVanillaRegisterConfigS2CPacket(channels, buf);
}

@Override
public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
public Packet<?> createVanillaRegisterConfigC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return HAS_FABRIC_API
? ClientConfigurationNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf)
: super.createVanillaRegisterConfigC2SPacket(buf);
? ClientConfigurationNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf.get())
: super.createVanillaRegisterConfigC2SPacket(channels, buf);
}

@Override
public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
public Packet<?> createVanillaRegisterPlayS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return HAS_FABRIC_API
? ServerPlayNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf)
: super.createVanillaRegisterPlayS2CPacket(buf);
? ServerPlayNetworking.createS2CPacket(Constants.MC_REGISTER_CHANNEL, buf.get())
: super.createVanillaRegisterPlayS2CPacket(channels, buf);
}

@Override
public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
public Packet<?> createVanillaRegisterPlayC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return HAS_FABRIC_API
? ClientPlayNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf)
: super.createVanillaRegisterPlayC2SPacket(buf);
? ClientPlayNetworking.createC2SPacket(Constants.MC_REGISTER_CHANNEL, buf.get())
: super.createVanillaRegisterPlayC2SPacket(channels, buf);
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
package lol.bai.badpackets.impl.forge;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.impl.platform.PlatformProxy;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
import net.minecraft.resources.ResourceLocation;

public class ForgeProxy extends PlatformProxy {

@Override
public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterConfigS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

@Override
public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterConfigC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

@Override
public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterPlayS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

@Override
public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterPlayC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new DiscardedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

}
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package lol.bai.badpackets.impl.neo;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.impl.platform.PlatformProxy;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.payload.MinecraftRegisterPayload;

// TODO: NeoForge has different format for minecraft:register. Support it again when it reuse the old format.
public class NeoProxy extends PlatformProxy {

@Override
public boolean canSendVanillaRegisterPackets() {
return false;
}

@Override
public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
throw new UnsupportedOperationException("Not yet implemented");
public Packet<?> createVanillaRegisterConfigS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new MinecraftRegisterPayload(channels));
}

@Override
public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
throw new UnsupportedOperationException("Not yet implemented");
public Packet<?> createVanillaRegisterConfigC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new MinecraftRegisterPayload(channels));
}

@Override
public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
throw new UnsupportedOperationException("Not yet implemented");
public Packet<?> createVanillaRegisterPlayS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new MinecraftRegisterPayload(channels));
}

@Override
public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
throw new UnsupportedOperationException("Not yet implemented");
public Packet<?> createVanillaRegisterPlayC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new MinecraftRegisterPayload(channels));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -145,21 +146,23 @@ public void remove() {

private void sendVanillaChannelRegisterPacket(Set<ResourceLocation> channels) {
if (PlatformProxy.INSTANCE.canSendVanillaRegisterPackets() && !channels.isEmpty()) {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
boolean first = true;
for (ResourceLocation channel : channels) {
if (first) {
first = false;
} else {
buf.writeByte(0);
connection.send(createVanillaRegisterPacket(channels, () -> {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
boolean first = true;
for (ResourceLocation channel : channels) {
if (first) {
first = false;
} else {
buf.writeByte(0);
}
buf.writeBytes(channel.toString().getBytes(StandardCharsets.US_ASCII));
}
buf.writeBytes(channel.toString().getBytes(StandardCharsets.US_ASCII));
}
connection.send(createVanillaRegisterPacket(buf));
return buf;
}));
}
}

protected abstract Packet<?> createVanillaRegisterPacket(FriendlyByteBuf buf);
protected abstract Packet<?> createVanillaRegisterPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf);

@Override
public void send(CustomPacketPayload payload, @Nullable PacketSendListener callback) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package lol.bai.badpackets.impl.handler;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.api.config.ClientConfigPacketReadyCallback;
import lol.bai.badpackets.api.config.ClientConfigPacketReceiver;
import lol.bai.badpackets.impl.platform.PlatformProxy;
Expand All @@ -12,6 +15,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public class ClientConfigPacketHandler extends AbstractPacketHandler<ClientConfigPacketReceiver<CustomPacketPayload>> {

Expand All @@ -26,8 +30,8 @@ public ClientConfigPacketHandler(Minecraft client, ClientConfigurationPacketList
}

@Override
protected Packet<?> createVanillaRegisterPacket(FriendlyByteBuf buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterConfigC2SPacket(buf);
protected Packet<?> createVanillaRegisterPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterConfigC2SPacket(channels, buf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package lol.bai.badpackets.impl.handler;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.api.play.ClientPlayPacketReadyCallback;
import lol.bai.badpackets.api.play.ClientPlayPacketReceiver;
import lol.bai.badpackets.impl.platform.PlatformProxy;
Expand All @@ -11,6 +14,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;

public class ClientPlayPacketHandler extends AbstractPacketHandler<ClientPlayPacketReceiver<CustomPacketPayload>> {

Expand All @@ -34,8 +38,8 @@ public static ClientPlayPacketHandler get() {
}

@Override
protected Packet<?> createVanillaRegisterPacket(FriendlyByteBuf buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterPlayC2SPacket(buf);
protected Packet<?> createVanillaRegisterPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterPlayC2SPacket(channels, buf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import lol.bai.badpackets.api.config.ConfigTaskExecutor;
import lol.bai.badpackets.api.config.ServerConfigPacketReadyCallback;
Expand Down Expand Up @@ -46,8 +48,8 @@ public CallbackTask createCallbackTask() {
}

@Override
protected Packet<?> createVanillaRegisterPacket(FriendlyByteBuf buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterConfigS2CPacket(buf);
protected Packet<?> createVanillaRegisterPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterConfigS2CPacket(channels, buf);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package lol.bai.badpackets.impl.handler;

import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.api.play.ServerPlayPacketReadyCallback;
import lol.bai.badpackets.api.play.ServerPlayPacketReceiver;
import lol.bai.badpackets.impl.platform.PlatformProxy;
Expand All @@ -10,6 +13,7 @@
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
Expand All @@ -30,8 +34,8 @@ public static ServerPlayPacketHandler get(ServerPlayer player) {
}

@Override
protected Packet<?> createVanillaRegisterPacket(FriendlyByteBuf buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterPlayS2CPacket(buf);
protected Packet<?> createVanillaRegisterPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return PlatformProxy.INSTANCE.createVanillaRegisterPlayS2CPacket(channels, buf);
}

@Override
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/lol/bai/badpackets/impl/platform/PlatformProxy.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package lol.bai.badpackets.impl.platform;

import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Supplier;

import lol.bai.badpackets.impl.Constants;
import lol.bai.badpackets.impl.payload.UntypedPayload;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.resources.ResourceLocation;

public class PlatformProxy {

Expand All @@ -17,20 +20,20 @@ public boolean canSendVanillaRegisterPackets() {
return true;
}

public Packet<?> createVanillaRegisterConfigC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterConfigC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

public Packet<?> createVanillaRegisterConfigS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterConfigS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

public Packet<?> createVanillaRegisterPlayC2SPacket(FriendlyByteBuf buf) {
return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterPlayC2SPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ServerboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

public Packet<?> createVanillaRegisterPlayS2CPacket(FriendlyByteBuf buf) {
return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf));
public Packet<?> createVanillaRegisterPlayS2CPacket(Set<ResourceLocation> channels, Supplier<FriendlyByteBuf> buf) {
return new ClientboundCustomPayloadPacket(new UntypedPayload(Constants.MC_REGISTER_CHANNEL, buf.get()));
}

}

0 comments on commit 225a43f

Please sign in to comment.