Last active
February 2, 2024 21:23
-
-
Save KosmX/38dee96151142cf8861ed2ee5eadcd23 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.kosmx.emotes.forge.fixingbadsoftware; | |
import io.github.kosmx.emotes.forge.ForgeWrapper; | |
import net.minecraft.network.protocol.Packet; | |
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; | |
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | |
import net.minecraft.server.network.ConfigurationTask; | |
import net.neoforged.neoforge.network.configuration.ICustomConfigurationTask; | |
import org.jetbrains.annotations.NotNull; | |
import java.util.function.Consumer; | |
public class UnNeoForgifierConfigurationTaskWrapper implements ICustomConfigurationTask { | |
@NotNull public static ICustomConfigurationTask wrap(@NotNull ConfigurationTask task){ | |
return new UnNeoForgifierConfigurationTaskWrapper(task); | |
} | |
@NotNull | |
private final ConfigurationTask originalTask; | |
public UnNeoForgifierConfigurationTaskWrapper(@NotNull ConfigurationTask originalTask) { | |
this.originalTask = originalTask; | |
} | |
@Override | |
public void run(@NotNull Consumer<CustomPacketPayload> consumer) { | |
ForgeWrapper.logger.warn("NeoForge is invoking a method that shouldn't be invoked. Consider using Fabric"); | |
originalTask.start(packet -> { | |
if (packet instanceof ClientboundCustomPayloadPacket clientPacket) { | |
consumer.accept(clientPacket.payload()); // and let it re-wrap into the same class | |
} else { | |
throw new AssertionError("Wrapped task does not use CustomPayloadPacket and NeoForge does not respect MC API"); | |
} | |
}); | |
} | |
@Override | |
@SuppressWarnings("ALL") // Fuck you NeoForge for this. This method should not be internal and your API should accept the base ConfigureTask | |
public void start(@NotNull Consumer<Packet<?>> sender) { | |
originalTask.start(sender); | |
} | |
@Override | |
public @NotNull Type type() { | |
return originalTask.type(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment