Skip to content

Commit

Permalink
fix(1.20.5/network): Interrupt findCodec
Browse files Browse the repository at this point in the history
Untested, there's no recipe viewer for 1.20.5 atm. Probably broken idk
  • Loading branch information
null2264 committed Feb 29, 2024
1 parent d70a70e commit dbb1a3a
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@

@Mixin(value = ClientboundCustomPayloadPacket.class, priority = 999)
public abstract class ClientboundCustomPayloadPacketMixin {
//#if MC>=1.20.2
//#if MC<1.20.5
//#if MC>=1.20.2 && 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;
//$$ 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,34 @@
//#if MC>=1.20.5
//$$ package io.github.null2264.cobblegen.mixin.network.packet;
//$$
//$$ import io.github.null2264.cobblegen.data.CGIdentifier;
//$$ import net.minecraft.network.FriendlyByteBuf;
//$$ import net.minecraft.network.codec.StreamCodec;
//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
//$$ import net.minecraft.resources.ResourceLocation;
//$$ 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.CallbackInfoReturnable;
//$$
//$$ import static io.github.null2264.cobblegen.CobbleGen.MOD_ID;
//$$ import static io.github.null2264.cobblegen.util.Constants.KNOWN_PAYLOADS;
//$$
//$$ @Mixin(targets = "net.minecraft.network.protocol.common.custom.CustomPacketPayload$1")
//$$ public abstract class CustomPacketPayloadMixin
//$$ {
//$$ @Inject(method = "findCodec", at = @At("HEAD"), cancellable = true)
//$$ private void getCodec(
//$$ ResourceLocation id,
//$$ CallbackInfoReturnable<StreamCodec<? super FriendlyByteBuf, ? extends CustomPacketPayload>> cir
//$$ ) {
//$$ if (!(id.getNamespace().equals(MOD_ID))) return;
//$$
//$$ StreamCodec<? super FriendlyByteBuf, ? extends CustomPacketPayload> codec =
//$$ KNOWN_PAYLOADS.get(CGIdentifier.fromMC(id));
//$$ if (codec == null) return;
//$$
//$$ cir.setReturnValue(codec);
//$$ }
//$$ }
//#endif
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@

@Mixin(value = ServerboundCustomPayloadPacket.class, priority = 999)
public abstract class ServerboundCustomPayloadPacketMixin {
//#if MC>=1.20.2
//#if MC<1.20.5
//#if MC>=1.20.2 && 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;
//$$ 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
@@ -1,7 +1,6 @@
package io.github.null2264.cobblegen.network.payload;

//#if MC>=1.20.5
//$$ import net.minecraft.network.codec.ByteBufCodecs;
//$$ import net.minecraft.network.codec.StreamCodec;
//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
//#endif
Expand Down Expand Up @@ -60,13 +59,7 @@ public ResourceLocation id() {

//#if MC>=1.20.5
//$$ public static final StreamCodec<FriendlyByteBuf, CGPingC2SPayload> STREAM_CODEC =
//$$ StreamCodec.composite(
//$$ ByteBufCodecs.BOOL,
//$$ CGPingC2SPayload::reload,
//$$ ByteBufCodecs.BOOL,
//$$ CGPingC2SPayload::recipeViewer,
//$$ CGPingC2SPayload::new
//$$ );
//$$ CustomPacketPayload.codec(CGPingC2SPayload::write, CGPingC2SPayload::new);
//$$ public static final CustomPacketPayload.Type<CGPingC2SPayload> TYPE = new CustomPacketPayload.Type<>(ID.toMC());
//$$
//$$ @Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.null2264.cobblegen.network.payload;

//#if MC>=1.20.5
//$$ import net.minecraft.network.codec.ByteBufCodecs;
//$$ import net.minecraft.network.codec.StreamCodec;
//$$ import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
//#endif
Expand Down Expand Up @@ -49,7 +48,7 @@ public ResourceLocation id() {

//#if MC>=1.20.5
//$$ public static final StreamCodec<FriendlyByteBuf, CGPingS2CPayload> STREAM_CODEC =
//$$ StreamCodec.composite(ByteBufCodecs.BOOL, CGPingS2CPayload::reload, CGPingS2CPayload::new);
//$$ CustomPacketPayload.codec(CGPingS2CPayload::write, CGPingS2CPayload::new);
//$$ public static final CustomPacketPayload.Type<CGPingS2CPayload> TYPE = new CustomPacketPayload.Type<>(ID.toMC());
//$$
//$$ @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ResourceLocation id() {

//#if MC>=1.20.5
//$$ public static final StreamCodec<FriendlyByteBuf, CGSyncC2SPayload> STREAM_CODEC =
//$$ StreamCodec.composite(ByteBufCodecs.BOOL, CGSyncC2SPayload::sync, CGSyncC2SPayload::new);
//$$ CustomPacketPayload.codec(CGSyncC2SPayload::write, CGSyncC2SPayload::new);
//$$ public static final CustomPacketPayload.Type<CGSyncC2SPayload> TYPE = new CustomPacketPayload.Type<>(ID.toMC());
//$$
//$$ @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,7 @@ public ResourceLocation id() {

//#if MC>=1.20.5
//$$ public static final StreamCodec<FriendlyByteBuf, CGSyncS2CPayload> STREAM_CODEC =
//$$ StreamCodec.composite(
//$$ ByteBufCodecs.BOOL,
//$$ CGSyncS2CPayload::isReload,
//$$ ByteBufCodecs.map(
//$$ Maps::newHashMapWithExpectedSize,
//$$ Constants.FLUID_CODEC,
//$$ ByteBufCodecs.collection(
//$$ Lists::newArrayListWithCapacity,
//$$ Generator.CODEC
//$$ )
//$$ ),
//$$ CGSyncS2CPayload::recipe,
//$$ CGSyncS2CPayload::new
//$$ );
//$$ CustomPacketPayload.codec(CGSyncS2CPayload::write, CGSyncS2CPayload::new);
//$$ public static final CustomPacketPayload.Type<CGSyncS2CPayload> TYPE = new CustomPacketPayload.Type<>(ID.toMC());
//$$
//$$ @Override
Expand Down
18 changes: 14 additions & 4 deletions src/main/java/io/github/null2264/cobblegen/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@ public class Constants
public static final CGIdentifier JEI_UI_COMPONENT = CGIdentifier.of("textures/gui/jei.png");
public static final CGIdentifier CG_PING = CGIdentifier.of("ping");
public static final CGIdentifier CG_SYNC = CGIdentifier.of("sync");
//#if MC<1.20.5
public static final ImmutableMap<CGIdentifier, CGPayloadReader<? extends CGPacketPayload>> KNOWN_SERVER_PAYLOADS =
ImmutableMap.of(
CGPingC2SPayload.ID, CGPingC2SPayload::new,
CGSyncC2SPayload.ID, CGSyncC2SPayload::new
CGPingC2SPayload.ID, CGPingC2SPayload::new,
CGSyncC2SPayload.ID, CGSyncC2SPayload::new
);
public static final ImmutableMap<CGIdentifier, CGPayloadReader<? extends CGPacketPayload>> KNOWN_CLIENT_PAYLOADS =
ImmutableMap.of(
CGPingS2CPayload.ID, CGPingS2CPayload::new,
CGSyncS2CPayload.ID, CGSyncS2CPayload::new
CGPingS2CPayload.ID, CGPingS2CPayload::new,
CGSyncS2CPayload.ID, CGSyncS2CPayload::new
);
//#else
//$$ public static final ImmutableMap<CGIdentifier, net.minecraft.network.codec.StreamCodec<? super FriendlyByteBuf, ? extends CGPacketPayload>> KNOWN_PAYLOADS =
//$$ ImmutableMap.of(
//$$ CGPingC2SPayload.ID, CGPingC2SPayload.STREAM_CODEC,
//$$ CGSyncC2SPayload.ID, CGSyncC2SPayload.STREAM_CODEC,
//$$ CGPingS2CPayload.ID, CGPingS2CPayload.STREAM_CODEC,
//$$ CGSyncS2CPayload.ID, CGSyncS2CPayload.STREAM_CODEC
//$$ );
//#endif
public static final Jankson JANKSON = Jankson.builder()
.registerSerializer(CGIdentifier.class, (it, m) -> it.toJson())
.registerDeserializer(JsonPrimitive .class, CGIdentifier.class, (json, m) -> CGIdentifier.fromJson(json))
Expand Down
16 changes: 11 additions & 5 deletions src/main/resources/cobblegen.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"compatibilityLevel": "JAVA_8",
//#endif
"mixins": [
//#if MC>=1.20.5
//$$ "network.packet.CustomPacketPayloadMixin",
//#endif
"CommandsMixin",
"MinecraftServerMixin",
//#if MC>1.16.5
Expand All @@ -17,20 +20,23 @@
"fluid.LavaEventMixin"
],
"client": [
//#if MC<1.20.5
"network.packet.ClientboundCustomPayloadPacketMixin"
//#endif
"network.ClientCommonPacketListenerMixin",
"network.ConnectionMixin",
"network.packet.ClientboundCustomPayloadPacketMixin"
],
"server": [
"network.PlayerManagerMixin",
//#if MC<1.20.2
"network.ServerboundCustomPayloadPacketAccessor",
//#endif
"network.ServerCommonPacketListenerMixin",
//#if MC>=1.20.2
//#else
//$$ "network.ServerConfigurationPacketListenerMixin",
//#endif
"network.packet.ServerboundCustomPayloadPacketMixin"
//#if MC<1.20.5
"network.packet.ServerboundCustomPayloadPacketMixin",
//#endif
"network.ServerCommonPacketListenerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit dbb1a3a

Please sign in to comment.