Skip to content

Commit

Permalink
Fixes some things
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Feb 10, 2024
1 parent 1d28cb5 commit d0cb007
Show file tree
Hide file tree
Showing 47 changed files with 340 additions and 388 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Java with Gradle

on:
push:
branches: [master]
branches: [1.19.4]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

/fabric/build/
/forge/build/
/common/build/
/fabric/.gradle/
/forge/.gradle/
/common/.gradle/
/fabric/run/
/forge/run/
44 changes: 41 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import net.fabricmc.loom.api.LoomGradleExtensionAPI

plugins {
java
id("architectury-plugin") version "3.4-SNAPSHOT"
id("dev.architectury.loom") version "1.4-SNAPSHOT" apply false
}

val modVersion: String by extra
val minecraftVersion: String by extra

architectury {
minecraft = minecraftVersion
}

subprojects {
apply(plugin = "dev.architectury.loom")

base.archivesName.set("PacketFixer-" + project.name)

configure<LoomGradleExtensionAPI> {
silentMojangMappingsLicense()
}

repositories {

}

dependencies {
"minecraft"("com.mojang:minecraft:$minecraftVersion")
"mappings"(project.the<LoomGradleExtensionAPI>().officialMojangMappings())
}
}

allprojects {
apply(plugin = "java")
apply(plugin = "architectury-plugin")

version = "$modVersion-$minecraftVersion"
group = "net.tonimatasdev"
version = "$minecraftVersion-$modVersion"
group = "dev.tonimatas.packetfixer"

base.archivesName.set("PacketFixer-" + project.name)
repositories {

}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

java {
withSourcesJar()
}
}
13 changes: 13 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
val fabricLoaderVersion: String by extra

dependencies {
modImplementation("net.fabricmc:fabric-loader:$fabricLoaderVersion")
}

architectury {
common("fabric", "forge", "neoforge")
}

loom {
accessWidenerPath.set(file("src/main/resources/cerium.accesswidener"))
}
10 changes: 10 additions & 0 deletions common/src/main/java/dev/tonimatas/packetfixer/PacketFixer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.tonimatas.packetfixer;

import com.mojang.logging.LogUtils;
public class PacketFixer {
public static final String MOD_ID = "packetfixer";

public static void init() {
LogUtils.getLogger().info("Packet Fixer has been initialized successfully");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;

package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -8,7 +8,7 @@
@Mixin(value = ClientboundCustomQueryPacket.class, priority = 9999)
public class ClientboundCustomQueryPacketMixin {
@ModifyConstant(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", constant = @Constant(intValue = 1048576))
private static int newSize(int value) {
private 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;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.CompressionDecoder;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import com.mojang.logging.LogUtils;
import net.minecraftforge.fml.loading.FMLLoader;
import dev.tonimatas.packetfixer.util.Hooks;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -23,14 +23,16 @@ 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.SplitterHandlerMixin") || mixinClassName.equalsIgnoreCase("net.tonimatasdev.packetfixerforge.mixin.SizePrependerMixin")) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton or Pluto.");
return !krypton;
boolean connectivity = Hooks.isModLoaded("connectivity");
boolean krypton = Hooks.isModLoaded("krypton") || Hooks.isModLoaded("pluto");

if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.CompressionDecoderMixin")) return !connectivity;
if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.compat.connectivity.CompressionDecoderMixin")) return connectivity;
if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.SplitterHandlerMixin") || mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.SizePrependerMixin")) {
if (krypton) {
LogUtils.getLogger().warn("For can't fit X into 3 error fix. Delete Krypton or Pluto.");
return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.nbt.NbtAccounter;
import org.objectweb.asm.Opcodes;
Expand All @@ -8,7 +8,7 @@

@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))
@Redirect(method = "accountBytes", at = @At(value = "FIELD", target = "Lnet/minecraft/nbt/NbtAccounter;quota:J", opcode = Opcodes.GETFIELD))
public long accountBits(NbtAccounter instance) {
return Long.MAX_VALUE;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.PacketEncoder;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -8,7 +8,7 @@
@Mixin(value = ServerboundCustomPayloadPacket.class, priority = 9999)
public class ServerboundCustomPayloadPacketMixin {
@ModifyConstant(method = "<init>(Lnet/minecraft/network/FriendlyByteBuf;)V", constant = @Constant(intValue = 32767))
private static int newSize(int value) {
private 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;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.Varint21LengthFieldPrepender;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin;
package dev.tonimatas.packetfixer.mixins;

import net.minecraft.network.Varint21FrameDecoder;
import org.spongepowered.asm.mixin.Mixin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.tonimatasdev.packetfixerforge.mixin.compat.connectivity;
package dev.tonimatas.packetfixer.mixins.compat.connectivity;

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

@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;
}
Expand Down
11 changes: 11 additions & 0 deletions common/src/main/java/dev/tonimatas/packetfixer/util/Hooks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.tonimatas.packetfixer.util;

import dev.architectury.injectables.annotations.ExpectPlatform;
import org.apache.commons.lang3.NotImplementedException;

public class Hooks {
@ExpectPlatform
public static boolean isModLoaded(String modId) {
throw new NotImplementedException();
}
}
3 changes: 3 additions & 0 deletions common/src/main/resources/cerium.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessWidener v2 named

mutable field net/minecraft/network/protocol/game/ClientboundAddEntityPacket data I
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.tonimatasdev.packetfixerforge.mixin",
"package": "dev.tonimatas.packetfixer.mixins",
"compatibilityLevel": "JAVA_17",
"refmap": "packetfixer.refmap.json",
"plugin": "net.tonimatasdev.packetfixerforge.mixin.MixinConfigPlugin",
"injectors": {
"defaultRequire": 1
},
"plugin": "dev.tonimatas.packetfixer.mixins.MixinConfigPlugin",
"mixins": [
"ClientboundCustomPayloadPacketMixin",
"ClientboundCustomQueryPacketMixin",
Expand All @@ -19,5 +15,10 @@
"SizePrependerMixin",
"SplitterHandlerMixin",
"compat.connectivity.CompressionDecoderMixin"
]
],
"client": [
],
"injectors": {
"defaultRequire": 1
}
}
67 changes: 49 additions & 18 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
@file:Suppress("UnstableApiUsage")
@file:Suppress("DEPRECATION", "HasPlatformType")

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import net.fabricmc.loom.task.RemapJarTask
import org.gradle.api.component.AdhocComponentWithVariants

plugins {
id("fabric-loom") version "1.3-SNAPSHOT"
id("com.github.johnrengelman.shadow") version "7.1.2"
}

architectury {
platformSetupLoomIde()
fabric()
}

loom {
accessWidenerPath.set(project(":common").loom.accessWidenerPath)
}

val loaderVersion: String by extra
val yarnMappings: String by extra
val modVersion: String by extra
val minecraftVersion: String by extra
val fabricLoaderVersion: String by extra
val fabricMinecraftVersionRange: String by extra
val modVersion: String by extra

val common by configurations.creating
val shadowCommon by configurations.creating

configurations["compileClasspath"].extendsFrom(common)
configurations["runtimeClasspath"].extendsFrom(common)
configurations["developmentFabric"].extendsFrom(common)

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

common(project(path = ":common", configuration = "namedElements")) { isTransitive = false }
shadowCommon(project(path = ":common", configuration = "transformProductionFabric")) { isTransitive = false }
}

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

inputs.properties(replaceProperties)

Expand All @@ -26,19 +46,30 @@ tasks.withType<ProcessResources> {
}
}

tasks.withType<JavaCompile> {
options.release.set(17)
tasks.withType<ShadowJar> {
configurations = listOf(shadowCommon)
archiveClassifier.set("dev-shadow")
}

java {
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
tasks.withType<RemapJarTask> {
val shadowTask = tasks.shadowJar.get()
input.set(shadowTask.archiveFile)
dependsOn(shadowTask)
archiveClassifier.set("")
}

tasks.jar {
from("LICENSE") {
rename { "${it}_${project.base.archivesName.get()}"}
archiveClassifier.set("dev")
}

tasks.sourcesJar {
val commonSources = project(":common").tasks.sourcesJar.get()
dependsOn(commonSources)
from(commonSources.archiveFile.map { zipTree(it) })
}

components.getByName<AdhocComponentWithVariants>("java").apply {
withVariantsFromConfiguration(project.configurations["shadowRuntimeElements"]) {
skip()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.tonimatas.packetfixer;

import net.fabricmc.api.ModInitializer;

public class PacketFixerFabric implements ModInitializer {
@Override
public void onInitialize() {
PacketFixer.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.tonimatas.packetfixer.util.fabric;

import net.fabricmc.loader.api.FabricLoader;

@SuppressWarnings("unused")
public class HooksImpl {
public static boolean isModLoaded(String modId) {
return FabricLoader.getInstance().isModLoaded(modId);
}
}
Loading

0 comments on commit d0cb007

Please sign in to comment.