Skip to content

Commit

Permalink
fix(neo): 1.20.4 vs 1.20.5 network refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Oct 30, 2024
1 parent 6b64236 commit 5f18765
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package io.github.null2264.cobblegen.mixin.network;

import io.github.null2264.cobblegen.network.CGClientPlayNetworkHandler;
import net.minecraft.network.chat.Component;
//#if MC<1.20.2
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
//#else
//#if MC>=1.20.4 && MC<1.20.5
//$$ import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
//#else if MC>=1.20.5
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
//$$ import io.github.null2264.cobblegen.network.payload.CGPacketPayload;
//$$ import net.minecraft.network.protocol.Packet;
//$$ import net.minecraft.network.protocol.common.ClientCommonPacketListener;
//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
//$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
//#endif
//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
//#endif

import io.github.null2264.cobblegen.network.CGClientPlayNetworkHandler;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand Down Expand Up @@ -63,7 +68,21 @@ private void handleDisconnect(Component reason, CallbackInfo ci) {
}
//#endif

//#if MC>=1.20.4 && FORGE>=1
//#if FORGE>1
//#if MC>=1.20.4 && MC<1.20.5
//$$ @ModifyExpressionValue(
//$$ method = "send",
//$$ at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkRegistry;canSendPacket(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/protocol/common/ClientCommonPacketListener;)Z")
//$$ )
//$$ private boolean validateCobbleGen(boolean original, Packet<?> packet) {
//$$ if (packet instanceof ServerboundCustomPayloadPacket customPayloadPacket) {
//$$ if (customPayloadPacket.payload() instanceof CGPacketPayload) {
//$$ return true;
//$$ }
//$$ }
//$$ return original;
//$$ }
//#else if MC>=1.20.5
//$$ @WrapOperation(
//$$ method = "send",
//$$ at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkRegistry;checkPacket(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/protocol/common/ClientCommonPacketListener;)V")
Expand All @@ -82,4 +101,5 @@ private void handleDisconnect(Component reason, CallbackInfo ci) {
//$$ }
//$$ }
//#endif
//#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
//#if MC<1.20.2
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
//#else
//#if MC>=1.20.4 && MC<1.20.5
//$$ import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
//#else if MC>=1.20.5
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
//$$ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
//$$ import io.github.null2264.cobblegen.network.payload.CGPacketPayload;
//$$ import net.minecraft.network.protocol.Packet;
//$$ import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
//$$ import net.minecraft.network.protocol.common.ServerCommonPacketListener;
//#endif
//$$ import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
//#endif

import io.github.null2264.cobblegen.network.CGServerPlayNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -65,7 +70,21 @@ private void handleCustomPayload(ServerboundCustomPayloadPacket packet, Callback
}
}

//#if MC>=1.20.4 && FORGE>=1
//#if FORGE>1
//#if MC>=1.20.4 && MC<1.20.5
//$$ @ModifyExpressionValue(
//$$ method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
//$$ at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkRegistry;canSendPacket(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/protocol/common/ServerCommonPacketListener;)Z")
//$$ )
//$$ private boolean validateCobbleGen(boolean original, Packet<?> packet) {
//$$ if (packet instanceof ClientboundCustomPayloadPacket customPayloadPacket) {
//$$ if (customPayloadPacket.payload() instanceof CGPacketPayload) {
//$$ return true;
//$$ }
//$$ }
//$$ return original;
//$$ }
//#else if MC>=1.20.5
//$$ @WrapOperation(
//$$ method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V",
//$$ at = @At(value = "INVOKE", target = "Lnet/neoforged/neoforge/network/registration/NetworkRegistry;checkPacket(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/protocol/common/ServerCommonPacketListener;)V")
Expand All @@ -84,4 +103,5 @@ private void handleCustomPayload(ServerboundCustomPayloadPacket packet, Callback
//$$ }
//$$ }
//#endif
//#endif
}

0 comments on commit 5f18765

Please sign in to comment.