Skip to content

Commit

Permalink
Fix TileThaumcraftInventory trying to send packets to the client on t…
Browse files Browse the repository at this point in the history
…he client side (#57)
  • Loading branch information
TheCodex6824 committed Dec 16, 2024
1 parent ee6c8fa commit 6a22635
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 15 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static List<String> getEarlyMixinConfigs() {

public static List<String> 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");
}

}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Void> original) {
if (!world.isRemote) {
original.call(player);
}
}

}
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
2 changes: 1 addition & 1 deletion src/main/resources/mixin/aura.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.aura",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"AuraHandlerMixin"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixin/block.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.block",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"BlockPillarMixin"
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixin/event.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.event",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"CraftingEventsMixin",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixin/item.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.item",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ItemGenericEssentiaContainerMixin",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixin/render.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.render",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"client": [
"ModelCustomArmorMixin",
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/mixin/tile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.tile",
"refmap": "${refmap}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"TileThaumcraftInventoryMixin"
]
}
2 changes: 1 addition & 1 deletion src/main/resources/mixin/vanilla.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"package": "thecodex6824.thaumcraftfix.mixin.vanilla",
"refmap": "${refmap}",
"minVersion": "${mixinbooterminversion}",
"minVersion": "${mixinminversion}",
"compatibilityLevel": "JAVA_8",
"mixins": [
"SetDamageLootFunctionMixin"
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/thecodex6824/thaumcraftfix/test/GlobalTestSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 6a22635

Please sign in to comment.