Skip to content

Commit

Permalink
Update 1.20.3 and support neoforge
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Dec 8, 2023
1 parent 139d529 commit e27f763
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 40 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@ jobs:
uses: actions/[email protected]
with:
name: PacketFixerFabric
path: fabric/build/libs/**.jar
path: fabric/build/libs/**.jar

- name: Upload a NeoForge Artifacts
uses: actions/[email protected]
with:
name: PacketFixerNeoForge
path: neoforge/build/libs/**.jar
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

/fabric/build/
/forge/build/
/neoforge/build/
/fabric/.gradle/
/forge/.gradle/
/neoforge/.gradle/
/fabric/run/
/forge/run/
/forge/run/
/neoforge/run/
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ val minecraftVersion: String by extra

dependencies {
minecraft("com.mojang:minecraft:$minecraftVersion")
mappings("net.fabricmc:yarn:$yarnMappings:v2")
mappings("net.fabricmc:yarn:$minecraftVersion+build.$yarnMappings:v2")
modImplementation("net.fabricmc:fabric-loader:$loaderVersion")

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ public String getRefMapperConfig() {
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
List<String> mods = FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).map(ModMetadata::getId).toList();

boolean connectivity = mods.contains("connectivity");
boolean krypton = mods.contains("krypton");

if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerfabric.mixin.PacketInflaterMixin")) return !connectivity;
if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerfabric.mixin.compat.connectivity.PacketInflaterMixin")) return connectivity;
if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerfabric.mixin.SplitterHandlerMixin") || mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerfabric.mixin.SizePrependerMixin")) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton.");
return !krypton;
if (krypton) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton.");
return false;
}
}

return true;
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions fabric/src/main/resources/packetfixer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"PacketEncoderMixin",
"PacketInflaterMixin",
"SizePrependerMixin",
"SplitterHandlerMixin",
"compat.connectivity.PacketInflaterMixin"
"SplitterHandlerMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
boolean connectivity = FMLLoader.getLoadingModList().getModFileById("connectivity") != null;
boolean krypton = FMLLoader.getLoadingModList().getModFileById("krypton") != null || FMLLoader.getLoadingModList().getModFileById("pluto") != null;

if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.CompressionDecoderMixin")) return !connectivity;
if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.compat.connectivity.CompressionDecoderMixin")) return connectivity;
if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.Varint21FrameDecoderMixin") || mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.Varint21LengthFieldPrependerMixin")) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton or Pluto.");
return !krypton;
if (krypton) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton or Pluto.");
return false;
}
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions forge/src/main/resources/packetfixer.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"ServerboundCustomPayloadPacketMixin",
"ServerboundCustomQueryPacketMixin",
"Varint21LengthFieldPrependerMixin",
"Varint21FrameDecoderMixin",
"compat.connectivity.CompressionDecoderMixin"
"Varint21FrameDecoderMixin"
]
}
12 changes: 7 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

# Mod Properties
modVersion=1.2.0
modVersion=1.2.2

minecraftVersion=1.20.2
forgeVersion=48.0.34
minecraftVersion=1.20.3
forgeVersion=49.0.2
forgeVersionRange=48
loaderVersion=0.14.24
yarnMappings=1.20.2+build.4
neoforgeVersion=20.3.8-beta
neoforgeVersionRange=20.3
loaderVersion=0.15.1
yarnMappings=1
46 changes: 46 additions & 0 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
@file:Suppress("UnstableApiUsage")

plugins {
id ("java-library")
id ("eclipse")
id ("idea")
id ("maven-publish")
id ("net.neoforged.gradle.userdev") version "7.0.57"
}

val modVersion: String by extra
val minecraftVersion: String by extra
val neoforgeVersion: String by extra
val neoforgeVersionRange: String by extra

group = "net.tonimatasdev"
version = "$modVersion-$minecraftVersion"

java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

sourceSets.main.get().resources { srcDir("src/generated/resources") }

repositories {

}

dependencies {
implementation("net.neoforged:neoforge:${neoforgeVersion}")
annotationProcessor("org.spongepowered:mixin:0.8.5:processor")
}



tasks.withType<ProcessResources> {
val replaceProperties = mapOf("neoforgeVersionRange" to neoforgeVersionRange, "modVersion" to modVersion, "minecraftVersion" to minecraftVersion)

inputs.properties(replaceProperties)

filesMatching(listOf("META-INF/mods.toml", "pack.mcmeta")) {
expand(replaceProperties)
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.tonimatasdev.packetfixerforge;

import com.mojang.logging.LogUtils;
import net.neoforged.fml.common.Mod;

@Mod("packetfixer")
public class PacketFixerNeoForge {
public PacketFixerNeoForge() {
LogUtils.getLogger().info("Packet Fixer (NeoForge) has been initialized successfully");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.tonimatasdev.packetfixerforge.mixin;


import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = ClientboundCustomPayloadPacket.class, priority = 9999)
public class ClientboundCustomPayloadPacketMixin {
@ModifyConstant(method = "readUnknownPayload", constant = @Constant(intValue = 1048576))
private static int newSize(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = ClientboundCustomQueryPacket.class, priority = 9999)
public class ClientboundCustomQueryPacketMixin {
@ModifyConstant(method = "readUnknownPayload", constant = @Constant(intValue = 1048576))
private static int newSize(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin.compat.connectivity;
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.network.CompressionDecoder;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -7,8 +7,8 @@

@Mixin(value = CompressionDecoder.class, priority = 9999)
public class CompressionDecoderMixin {
@ModifyConstant(method = "decode", constant = @Constant(intValue = 2097152))
@ModifyConstant(method = "decode", constant = @Constant(intValue = 8388608))
private int newSize(int value) {
return Integer.MAX_VALUE;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.tonimatasdev.packetfixerforge.mixin;

import com.mojang.logging.LogUtils;
import net.neoforged.fml.loading.FMLLoader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;

import java.util.List;
import java.util.Set;

public class MixinConfigPlugin implements IMixinConfigPlugin {

@Override
public void onLoad(String mixinPackage) {
System.getProperties().setProperty("forge.disablePacketCompressionDebug", "true");
}

@Override
public String getRefMapperConfig() {
return null;
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
boolean krypton = FMLLoader.getLoadingModList().getModFileById("krypton") != null || FMLLoader.getLoadingModList().getModFileById("pluto") != null;

if (mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.Varint21FrameDecoderMixin") || mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.Varint21LengthFieldPrependerMixin")) {
if (krypton) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton or Pluto.");
return false;
}
}

return true;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return null;
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.nbt.NbtAccounter;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = NbtAccounter.class, priority = 9999)
public abstract class NbtAccounterMixin {
@Redirect(method = "accountBytes(J)V", at = @At(value = "FIELD", target = "Lnet/minecraft/nbt/NbtAccounter;quota:J", opcode = Opcodes.GETFIELD))
public long accountBits(NbtAccounter instance) {
return Long.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.network.PacketEncoder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = PacketEncoder.class, priority = 9999)
public class PacketEncoderMixin {
@ModifyConstant(method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/protocol/Packet;Lio/netty/buffer/ByteBuf;)V", constant = @Constant(intValue = 8388608))
private int newSize(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = ServerboundCustomPayloadPacket.class, priority = 9999)
public class ServerboundCustomPayloadPacketMixin {
@ModifyConstant(method = "readUnknownPayload", constant = @Constant(intValue = 32767))
private static int newSize(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.tonimatasdev.packetfixerforge.mixin;

import net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = ServerboundCustomQueryAnswerPacket.class, priority = 9999)
public class ServerboundCustomQueryPacketMixin {
@ModifyConstant(method = "readUnknownPayload", constant = @Constant(intValue = 1048576))
private static int newSize(int value) {
return Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.tonimatasdev.packetfixerforge.mixin;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.network.Varint21FrameDecoder;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Varint21FrameDecoder.class)
public class Varint21FrameDecoderMixin {
@ModifyConstant(method = "copyVarint", constant = @Constant(intValue = 3))
private static int newSize(int value) {
return 8;
}

@Inject(method = "handlerRemoved0", at = @At(value = "HEAD"), cancellable = true)
private void redirectReadNullable(ChannelHandlerContext p_299287_, CallbackInfo ci) {
Unpooled.directBuffer(8).release();
ci.cancel();
}

@Redirect(method = "decode", at = @At(value = "FIELD", target = "Lnet/minecraft/network/Varint21FrameDecoder;helperBuf:Lio/netty/buffer/ByteBuf;", opcode = Opcodes.GETFIELD))
public ByteBuf accountBits(Varint21FrameDecoder instance) {
return Unpooled.directBuffer(8);
}
}
Loading

0 comments on commit e27f763

Please sign in to comment.