From 6a22635d7d2adc6d4be32c727f707d8da8d22f99 Mon Sep 17 00:00:00 2001 From: TheCodex6824 Date: Sun, 15 Dec 2024 23:11:24 -0500 Subject: [PATCH] Fix TileThaumcraftInventory trying to send packets to the client on the client side (#57) --- build.gradle | 4 +- gradle.properties | 4 +- .../thaumcraftfix/core/ThaumcraftFixCore.java | 2 +- .../tile/TileThaumcraftInventoryMixin.java | 42 +++++++++++++++++++ src/main/resources/mcmod.info | 2 +- src/main/resources/mixin/aura.json | 2 +- src/main/resources/mixin/block.json | 2 +- src/main/resources/mixin/event.json | 2 +- src/main/resources/mixin/item.json | 2 +- src/main/resources/mixin/render.json | 2 +- src/main/resources/mixin/tile.json | 9 ++++ src/main/resources/mixin/vanilla.json | 2 +- .../thaumcraftfix/test/GlobalTestSetup.java | 17 ++++++++ .../test/TestTileThaumcraftInventory.java | 22 ++++++++++ .../test/fixture/UnitTestClassProvider.java | 11 ++++- .../thaumcraftfix/test/lib/MockWorld.java | 6 ++- 16 files changed, 116 insertions(+), 15 deletions(-) create mode 100644 src/main/java/thecodex6824/thaumcraftfix/mixin/tile/TileThaumcraftInventoryMixin.java create mode 100644 src/main/resources/mixin/tile.json create mode 100644 src/test/java/thecodex6824/thaumcraftfix/test/TestTileThaumcraftInventory.java diff --git a/build.gradle b/build.gradle index b21653a..14227ab 100644 --- a/build.gradle +++ b/build.gradle @@ -212,7 +212,7 @@ processResources { inputs.property 'apiversion', apiversion inputs.property 'mcversion', mcversion inputs.property 'forgeminversion', forgeminversion - inputs.property 'mixinbooterminversion', mixinbooterminversion + inputs.property 'mixinminversion', mixinminversion inputs.property 'refmap', refmap // replace stuff in mcmod.info, nothing else @@ -227,7 +227,7 @@ processResources { from(sourceSets.main.resources.srcDirs) { include 'mixin/*.json' - expand 'mixinbooterminversion': mixinbooterminversion, 'refmap': refmap + expand 'mixinminversion': mixinminversion, 'refmap': refmap } // copy everything else except everything handled above diff --git a/gradle.properties b/gradle.properties index ded4ea7..f01d803 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ apiversion=1.0.1 mcversion=1.12.2 forgeversion=14.23.5.2860 forgeminversion=14.23.5.2856 -mixinbooterversion=9.3 -mixinbooterminversion=0.8 +mixinbooterversion=10.2 +mixinminversion=0.8 refmap=thaumcraftfix.refmap.json diff --git a/src/main/java/thecodex6824/thaumcraftfix/core/ThaumcraftFixCore.java b/src/main/java/thecodex6824/thaumcraftfix/core/ThaumcraftFixCore.java index 6cf6afd..d644e10 100644 --- a/src/main/java/thecodex6824/thaumcraftfix/core/ThaumcraftFixCore.java +++ b/src/main/java/thecodex6824/thaumcraftfix/core/ThaumcraftFixCore.java @@ -135,7 +135,7 @@ public static List getEarlyMixinConfigs() { public static List getLateMixinConfigs() { return ImmutableList.of("mixin/aura.json", "mixin/block.json", "mixin/event.json", - "mixin/item.json", "mixin/render.json"); + "mixin/item.json", "mixin/render.json", "mixin/tile.json"); } } diff --git a/src/main/java/thecodex6824/thaumcraftfix/mixin/tile/TileThaumcraftInventoryMixin.java b/src/main/java/thecodex6824/thaumcraftfix/mixin/tile/TileThaumcraftInventoryMixin.java new file mode 100644 index 0000000..727bb48 --- /dev/null +++ b/src/main/java/thecodex6824/thaumcraftfix/mixin/tile/TileThaumcraftInventoryMixin.java @@ -0,0 +1,42 @@ +/** + * Thaumcraft Fix + * Copyright (c) 2024 TheCodex6824. + * + * This file is part of Thaumcraft Fix. + * + * Thaumcraft Fix is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Thaumcraft Fix is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Thaumcraft Fix. If not, see . + */ + +package thecodex6824.thaumcraftfix.mixin.tile; + +import org.spongepowered.asm.mixin.Mixin; + +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; + +import net.minecraft.entity.player.EntityPlayerMP; +import thaumcraft.common.tiles.TileThaumcraft; +import thaumcraft.common.tiles.TileThaumcraftInventory; + +@Mixin(TileThaumcraftInventory.class) +public class TileThaumcraftInventoryMixin extends TileThaumcraft { + + @WrapMethod(method = "syncSlots", remap = false) + private void wrapSyncSlots(EntityPlayerMP player, Operation original) { + if (!world.isRemote) { + original.call(player); + } + } + +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 4a82092..7206aca 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -12,7 +12,7 @@ "logoFile": "assets/thaumcraftfix/textures/gui/logo.png", "screenshots": [], "useDependencyInformation": true, - "requiredMods": ["forge@[${forgeminversion},)", "thaumcraft@[6.1.BETA26,)", "mixinbooter@[9.0,)"], + "requiredMods": ["forge@[${forgeminversion},)", "thaumcraft@[6.1.BETA26,)", "mixinbooter@[10.0,)"], "dependencies": ["thaumcraft", "mixinbooter"] } ] diff --git a/src/main/resources/mixin/aura.json b/src/main/resources/mixin/aura.json index aed05f0..00dd041 100644 --- a/src/main/resources/mixin/aura.json +++ b/src/main/resources/mixin/aura.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.aura", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "mixins": [ "AuraHandlerMixin" diff --git a/src/main/resources/mixin/block.json b/src/main/resources/mixin/block.json index a0c20f1..1f46f7c 100644 --- a/src/main/resources/mixin/block.json +++ b/src/main/resources/mixin/block.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.block", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "mixins": [ "BlockPillarMixin" diff --git a/src/main/resources/mixin/event.json b/src/main/resources/mixin/event.json index 8cb1878..cad8edc 100644 --- a/src/main/resources/mixin/event.json +++ b/src/main/resources/mixin/event.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.event", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "mixins": [ "CraftingEventsMixin", diff --git a/src/main/resources/mixin/item.json b/src/main/resources/mixin/item.json index 78b82e6..762debf 100644 --- a/src/main/resources/mixin/item.json +++ b/src/main/resources/mixin/item.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.item", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "mixins": [ "ItemGenericEssentiaContainerMixin", diff --git a/src/main/resources/mixin/render.json b/src/main/resources/mixin/render.json index f8b70d8..434c013 100644 --- a/src/main/resources/mixin/render.json +++ b/src/main/resources/mixin/render.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.render", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "client": [ "ModelCustomArmorMixin", diff --git a/src/main/resources/mixin/tile.json b/src/main/resources/mixin/tile.json new file mode 100644 index 0000000..5e3bf6d --- /dev/null +++ b/src/main/resources/mixin/tile.json @@ -0,0 +1,9 @@ +{ + "package": "thecodex6824.thaumcraftfix.mixin.tile", + "refmap": "${refmap}", + "minVersion": "${mixinminversion}", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "TileThaumcraftInventoryMixin" + ] +} \ No newline at end of file diff --git a/src/main/resources/mixin/vanilla.json b/src/main/resources/mixin/vanilla.json index 5b7b8b0..9128709 100644 --- a/src/main/resources/mixin/vanilla.json +++ b/src/main/resources/mixin/vanilla.json @@ -1,7 +1,7 @@ { "package": "thecodex6824.thaumcraftfix.mixin.vanilla", "refmap": "${refmap}", - "minVersion": "${mixinbooterminversion}", + "minVersion": "${mixinminversion}", "compatibilityLevel": "JAVA_8", "mixins": [ "SetDamageLootFunctionMixin" diff --git a/src/test/java/thecodex6824/thaumcraftfix/test/GlobalTestSetup.java b/src/test/java/thecodex6824/thaumcraftfix/test/GlobalTestSetup.java index 91d2f04..a20fa7e 100644 --- a/src/test/java/thecodex6824/thaumcraftfix/test/GlobalTestSetup.java +++ b/src/test/java/thecodex6824/thaumcraftfix/test/GlobalTestSetup.java @@ -20,6 +20,8 @@ package thecodex6824.thaumcraftfix.test; +import java.lang.reflect.Field; + import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -42,6 +44,7 @@ import net.minecraftforge.fml.common.discovery.ASMDataTable; import net.minecraftforge.fml.common.event.FMLConstructionEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.common.registry.ForgeRegistries; import thaumcraft.api.blocks.BlocksTC; import thaumcraft.api.items.ItemsTC; @@ -51,6 +54,7 @@ import thaumcraft.common.config.ConfigResearch; import thaumcraft.common.items.baubles.ItemCuriosityBand; import thaumcraft.common.items.curios.ItemPrimordialPearl; +import thaumcraft.common.lib.network.PacketHandler; import thecodex6824.thaumcraftfix.ThaumcraftFix; import thecodex6824.thaumcraftfix.api.internal.ThaumcraftFixApiBridge; import thecodex6824.thaumcraftfix.common.internal.DefaultApiImplementation; @@ -86,6 +90,19 @@ public Logger getModLog() { } }); + // initialize TC network messages + PacketHandler.preInit(); + // null out internals so we get an NPE thrown instead of netty just logging + // TODO: make packets assertable somehow + try { + Field channels = SimpleNetworkWrapper.class.getDeclaredField("channels"); + channels.setAccessible(true); + channels.set(PacketHandler.INSTANCE, null); + } + catch (ReflectiveOperationException ex) { + throw new RuntimeException(ex); + } + // initialize TC research ConfigResearch.init(); diff --git a/src/test/java/thecodex6824/thaumcraftfix/test/TestTileThaumcraftInventory.java b/src/test/java/thecodex6824/thaumcraftfix/test/TestTileThaumcraftInventory.java new file mode 100644 index 0000000..2b20784 --- /dev/null +++ b/src/test/java/thecodex6824/thaumcraftfix/test/TestTileThaumcraftInventory.java @@ -0,0 +1,22 @@ +package thecodex6824.thaumcraftfix.test; + +import org.junit.jupiter.api.Test; + +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import thaumcraft.common.tiles.crafting.TileResearchTable; +import thecodex6824.thaumcraftfix.test.lib.MockWorld; + +public class TestTileThaumcraftInventory { + + @Test + public void testSyncSlotsClient() { + TileResearchTable table = new TileResearchTable() { + @Override + public void markDirty() {} + }; + table.setWorld(new MockWorld(true)); + table.setInventorySlotContents(1, new ItemStack(Items.PAPER, 64)); + } + +} diff --git a/src/test/java/thecodex6824/thaumcraftfix/test/fixture/UnitTestClassProvider.java b/src/test/java/thecodex6824/thaumcraftfix/test/fixture/UnitTestClassProvider.java index b4206c2..14e41a1 100644 --- a/src/test/java/thecodex6824/thaumcraftfix/test/fixture/UnitTestClassProvider.java +++ b/src/test/java/thecodex6824/thaumcraftfix/test/fixture/UnitTestClassProvider.java @@ -62,6 +62,11 @@ public ClassNode getClassNode(String name) throws ClassNotFoundException, IOExce return getClassNode(name, true); } + @Override + public ClassNode getClassNode(String name, boolean runTransformers) throws ClassNotFoundException, IOException { + return getClassNode(name, runTransformers, ClassReader.EXPAND_FRAMES); + } + private byte[] getClassBytes(String name) throws IOException { try (InputStream input = getResourceAsStream(name)) { if (input == null) throw new IOException(); @@ -70,9 +75,11 @@ private byte[] getClassBytes(String name) throws IOException { } @Override - public ClassNode getClassNode(String name, boolean runTransformers) throws ClassNotFoundException, IOException { + public ClassNode getClassNode(String name, boolean runTransformers, int readerFlags) + throws ClassNotFoundException, IOException { + ClassNode node = new ClassNode(Opcodes.ASM5); - new ClassReader(getClassBytes(name.replace('.', '/') + ".class")).accept(node, ClassReader.EXPAND_FRAMES); + new ClassReader(getClassBytes(name.replace('.', '/') + ".class")).accept(node, readerFlags); if (runTransformers) { Proxy.transformer.transformClass(MixinEnvironment.getCurrentEnvironment(), name, node); } diff --git a/src/test/java/thecodex6824/thaumcraftfix/test/lib/MockWorld.java b/src/test/java/thecodex6824/thaumcraftfix/test/lib/MockWorld.java index daec94f..47b5336 100644 --- a/src/test/java/thecodex6824/thaumcraftfix/test/lib/MockWorld.java +++ b/src/test/java/thecodex6824/thaumcraftfix/test/lib/MockWorld.java @@ -31,8 +31,12 @@ public class MockWorld extends World { public MockWorld() { + this(false); + } + + public MockWorld(boolean isRemote) { super(null, new WorldInfo(new WorldSettings(0, GameType.CREATIVE, false, false, WorldType.CUSTOMIZED), - "test"), new WorldProviderSurface(), null, false); + "test"), new WorldProviderSurface(), null, isRemote); provider.setWorld(this); }