Skip to content

Commit

Permalink
fix: Actually read the payloads
Browse files Browse the repository at this point in the history
Still need to investigate 1.20.5's networking system, should already work but who knows...
  • Loading branch information
null2264 committed Feb 28, 2024
1 parent da04b29 commit dfaaa13
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 21 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ loader_version_1_18_2=0.14.14
fabric_version_1_18_2=0.76.0+1.18.2

# Runtime Properties
recipe_viewer=none
recipe_viewer=emi

# Dependencies
jankson_version=1.2.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
//#if MC>=1.20.2
//$$ package io.github.null2264.cobblegen.mixin.network;
//$$
//$$ import io.github.null2264.cobblegen.network.payload.CGPingS2CPayload;
//$$ import io.netty.buffer.Unpooled;
//$$ import net.minecraft.network.FriendlyByteBuf;
//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;

//$$ import io.github.null2264.cobblegen.network.CGServerPlayNetworkHandler;
//$$ import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
//$$ import org.spongepowered.asm.mixin.Mixin;
//$$ import org.spongepowered.asm.mixin.injection.At;
//$$ import org.spongepowered.asm.mixin.injection.Inject;
//$$ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
//$$
//$$ import static io.github.null2264.cobblegen.util.Constants.CG_PING;
//$$

//$$ @Mixin(ServerConfigurationPacketListenerImpl.class)
//$$ public abstract class ServerConfigurationPacketListenerMixin {
//$$ @Inject(method = "startConfiguration", at = @At("HEAD"))
//$$ private void syncCG(CallbackInfo ci) {
//$$ FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
//$$ buf.writeResourceLocation(CG_PING.toMC());
//$$ ((ServerConfigurationPacketListenerImpl) (Object) this).send(
//$$ new ClientboundCustomPayloadPacket(new CGPingS2CPayload(false))
//$$ );
//$$ CGServerPlayNetworkHandler.trySync((ServerConfigurationPacketListenerImpl) (Object) this);
//$$ }
//$$ }
//#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.github.null2264.cobblegen.mixin.network.packet;

//#if MC<1.20.2
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
//#else
//#if MC<1.20.5
//$$ import io.github.null2264.cobblegen.data.CGIdentifier;
//$$ import io.github.null2264.cobblegen.network.payload.CGPacketPayload;
//$$ import io.github.null2264.cobblegen.network.payload.CGPayloadReader;
//$$ import io.netty.buffer.Unpooled;
//$$ import net.minecraft.network.FriendlyByteBuf;
//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
//$$ import net.minecraft.resources.ResourceLocation;
//$$ import org.spongepowered.asm.mixin.injection.At;
//$$ import org.spongepowered.asm.mixin.injection.Inject;
//$$ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
//$$
//$$ import static io.github.null2264.cobblegen.util.Constants.KNOWN_CLIENT_PAYLOADS;
//$$ import static io.github.null2264.cobblegen.CobbleGen.MOD_ID;
//#endif
//#endif

import org.spongepowered.asm.mixin.Mixin;

@Mixin(value = ClientboundCustomPayloadPacket.class, priority = 999)
public abstract class ClientboundCustomPayloadPacketMixin {
//#if MC>=1.20.2
//#if MC<1.20.5
//$$ @Inject(method = "readPayload", at = @At("HEAD"), cancellable = true)
//$$ private static void read(ResourceLocation id, FriendlyByteBuf buf, CallbackInfoReturnable<CustomPacketPayload> cir) {
//$$ if (!id.getNamespace().equals(MOD_ID))
//$$ return;
//$$
//$$ CGPayloadReader<? extends CGPacketPayload> reader = KNOWN_CLIENT_PAYLOADS.get(CGIdentifier.fromMC(id));
//$$ if (reader == null) return;
//$$
//$$ cir.setReturnValue(reader.apply(buf));
//$$ }
//#endif
//#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.null2264.cobblegen.mixin.network.packet;

import org.spongepowered.asm.mixin.Mixin;
//#if MC<1.20.2
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
//#else
//#if MC<1.20.5
//$$ import io.github.null2264.cobblegen.data.CGIdentifier;
//$$ import io.github.null2264.cobblegen.network.payload.CGPacketPayload;
//$$ import io.github.null2264.cobblegen.network.payload.CGPayloadReader;
//$$ import io.netty.buffer.Unpooled;
//$$ import net.minecraft.network.FriendlyByteBuf;
//$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
//$$ import net.minecraft.resources.ResourceLocation;
//$$ import org.spongepowered.asm.mixin.injection.At;
//$$ import org.spongepowered.asm.mixin.injection.Inject;
//$$ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
//$$
//$$ import static io.github.null2264.cobblegen.util.Constants.KNOWN_SERVER_PAYLOADS;
//$$ import static io.github.null2264.cobblegen.CobbleGen.MOD_ID;
//#endif
//#endif

@Mixin(value = ServerboundCustomPayloadPacket.class, priority = 999)
public abstract class ServerboundCustomPayloadPacketMixin {
//#if MC>=1.20.2
//#if MC<1.20.5
//$$ @Inject(method = "readPayload", at = @At("HEAD"), cancellable = true)
//$$ private static void read(ResourceLocation id, FriendlyByteBuf buf, CallbackInfoReturnable<CustomPacketPayload> cir) {
//$$ if (!id.getNamespace().equals(MOD_ID))
//$$ return;
//$$
//$$ CGPayloadReader<? extends CGPacketPayload> reader = KNOWN_SERVER_PAYLOADS.get(CGIdentifier.fromMC(id));
//$$ if (reader == null) return;
//$$
//$$ cir.setReturnValue(reader.apply(buf));
//$$ }
//#endif
//#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.github.null2264.cobblegen.network.payload.*;
import io.github.null2264.cobblegen.util.CGLog;
import io.github.null2264.cobblegen.util.Util;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import org.jetbrains.annotations.ApiStatus;

Expand Down Expand Up @@ -75,7 +74,7 @@ public static void onDisconnect() {
@ApiStatus.Internal
private static ServerboundCustomPayloadPacket createC2SPacket(CGPacketPayload payload) {
//#if MC<=1.20.1
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
FriendlyByteBuf buf = FriendlyByteBuf.unpooled();
payload.write(buf);
return new ServerboundCustomPayloadPacket(payload.id(), buf);
//#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.github.null2264.cobblegen.data.CGIdentifier;
import io.github.null2264.cobblegen.network.payload.*;
import io.github.null2264.cobblegen.util.CGLog;
import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf;
import org.jetbrains.annotations.ApiStatus;

Expand Down Expand Up @@ -102,7 +101,7 @@ public static void sync(ServerGamePacketListenerImpl handler, boolean isReload)
@ApiStatus.Internal
public static ClientboundCustomPayloadPacket createS2CPacket(CGPacketPayload payload) {
//#if MC<=1.20.1
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
FriendlyByteBuf buf = FriendlyByteBuf.unpooled();
payload.write(buf);
return new ClientboundCustomPayloadPacket(payload.id(), buf);
//#else
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/cobblegen.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
"fluid.CreateFluidReactionsMixin",
//#endif
"fluid.FluidEventMixin",
"fluid.LavaEventMixin",
"fluid.LavaEventMixin"
],
"client": [
"network.ClientCommonPacketListenerMixin",
"network.ConnectionMixin"
"network.ConnectionMixin",
"network.packet.ClientboundCustomPayloadPacketMixin"
],
"server": [
"network.PlayerManagerMixin",
Expand All @@ -27,8 +28,9 @@
//#endif
"network.ServerCommonPacketListenerMixin",
//#if MC>=1.20.2
//$$ "network.ServerConfigurationPacketListenerMixin"
//$$ "network.ServerConfigurationPacketListenerMixin",
//#endif
"network.packet.ServerboundCustomPayloadPacketMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit dfaaa13

Please sign in to comment.