diff --git a/src/main/java/com/github/wohaopa/tc4helper/ClientProxy.java b/src/main/java/com/github/wohaopa/tc4helper/ClientProxy.java deleted file mode 100644 index ff049ad..0000000 --- a/src/main/java/com/github/wohaopa/tc4helper/ClientProxy.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.github.wohaopa.tc4helper; - -public class ClientProxy extends CommonProxy { - - // Override CommonProxy methods here, if you want a different behaviour on the client (e.g. registering renders). - // Don't forget to call the super methods as well. - -} diff --git a/src/main/java/com/github/wohaopa/tc4helper/CommonProxy.java b/src/main/java/com/github/wohaopa/tc4helper/CommonProxy.java deleted file mode 100644 index 7e60d31..0000000 --- a/src/main/java/com/github/wohaopa/tc4helper/CommonProxy.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.wohaopa.tc4helper; - -import net.minecraftforge.client.ClientCommandHandler; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; - -public class CommonProxy { - - // preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the - // GameRegistry." (Remove if not needed) - public void preInit(FMLPreInitializationEvent event) { - Config.synchronizeConfiguration(event.getSuggestedConfigurationFile()); - } - - // load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed) - public void init(FMLInitializationEvent event) {} - - // postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) - public void postInit(FMLPostInitializationEvent event) { - ClientCommandHandler.instance.registerCommand(new Command()); - } - - // register server commands in this event handler (Remove if not needed) - public void serverStarting(FMLServerStartingEvent event) {} -} diff --git a/src/main/java/com/github/wohaopa/tc4helper/Config.java b/src/main/java/com/github/wohaopa/tc4helper/Config.java deleted file mode 100644 index 37b9d33..0000000 --- a/src/main/java/com/github/wohaopa/tc4helper/Config.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.wohaopa.tc4helper; - -import java.io.File; - -import net.minecraftforge.common.config.Configuration; - -public class Config { - - public static String greeting = "Hello World"; - - public static void synchronizeConfiguration(File configFile) { - Configuration configuration = new Configuration(configFile); - - greeting = configuration.getString("greeting", Configuration.CATEGORY_GENERAL, greeting, "How shall I greet?"); - - if (configuration.hasChanged()) { - configuration.save(); - } - } -} diff --git a/src/main/java/com/github/wohaopa/tc4helper/GuiHandler.java b/src/main/java/com/github/wohaopa/tc4helper/GuiHandler.java new file mode 100644 index 0000000..55ac94d --- /dev/null +++ b/src/main/java/com/github/wohaopa/tc4helper/GuiHandler.java @@ -0,0 +1,37 @@ +package com.github.wohaopa.tc4helper; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.World; + +import cpw.mods.fml.common.network.IGuiHandler; +import thaumcraft.client.gui.GuiResearchTable; +import thaumcraft.common.container.ContainerResearchTable; +import thaumcraft.common.tiles.TileResearchTable; + +public class GuiHandler implements IGuiHandler { + + private final IGuiHandler guiHandler; + + public GuiHandler(IGuiHandler guiHandler) { + this.guiHandler = guiHandler; + } + + @Override + public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + if (TC4Helper.enabled) { + if (ID == 0) + return new ContainerResearchTable(player.inventory, (TileResearchTable) world.getTileEntity(x, y, z)); + + return null; + } else return guiHandler.getServerGuiElement(ID, player, world, x, y, z); + } + + @Override + public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + if (TC4Helper.enabled) { + if (ID == 0) return new GuiResearchTable(player, (TileResearchTable) world.getTileEntity(x, y, z)); + + return null; + } else return guiHandler.getClientGuiElement(ID, player, world, x, y, z); + } +} diff --git a/src/main/java/com/github/wohaopa/tc4helper/TC4Helper.java b/src/main/java/com/github/wohaopa/tc4helper/TC4Helper.java index 5ad9381..a8f1968 100644 --- a/src/main/java/com/github/wohaopa/tc4helper/TC4Helper.java +++ b/src/main/java/com/github/wohaopa/tc4helper/TC4Helper.java @@ -3,14 +3,19 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.github.wohaopa.tc4helper.proxy.IProxy; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLLoadCompleteEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.event.FMLServerStartingEvent; -@Mod(modid = TC4Helper.MODID, version = Tags.VERSION, name = "TC4Helper", acceptedMinecraftVersions = "[1.7.10]") +@Mod( + modid = TC4Helper.MODID, + version = Tags.VERSION, + name = "TC4Helper", + acceptedMinecraftVersions = "[1.7.10]", + dependencies = "after:ThaumcraftResearchTweaks") public class TC4Helper { public static final String MODID = "tc4helper"; @@ -18,32 +23,18 @@ public class TC4Helper { public static boolean enabled = true; @SidedProxy( - clientSide = "com.github.wohaopa.tc4helper.ClientProxy", - serverSide = "com.github.wohaopa.tc4helper.CommonProxy") - public static CommonProxy proxy; - - @Mod.EventHandler - // preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the - // GameRegistry." (Remove if not needed) - public void preInit(FMLPreInitializationEvent event) { - proxy.preInit(event); - } + clientSide = "com.github.wohaopa.tc4helper.proxy.ClientProxy", + serverSide = "com.github.wohaopa.tc4helper.proxy.ServerProxy") + public static IProxy proxy; @Mod.EventHandler - // load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed) - public void init(FMLInitializationEvent event) { - proxy.init(event); - } - - @Mod.EventHandler - // postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) public void postInit(FMLPostInitializationEvent event) { proxy.postInit(event); } @Mod.EventHandler - // register server commands in this event handler (Remove if not needed) - public void serverStarting(FMLServerStartingEvent event) { - proxy.serverStarting(event); + public void complete(FMLLoadCompleteEvent event) { + proxy.complete(event); } + } diff --git a/src/main/java/com/github/wohaopa/tc4helper/autoplay/AutoPlayButton.java b/src/main/java/com/github/wohaopa/tc4helper/autoplay/AutoPlayButton.java index b511f67..a72c90f 100644 --- a/src/main/java/com/github/wohaopa/tc4helper/autoplay/AutoPlayButton.java +++ b/src/main/java/com/github/wohaopa/tc4helper/autoplay/AutoPlayButton.java @@ -42,7 +42,7 @@ public void onAction(EntityPlayer player, ResearchNoteData note, GuiResearchTabl switch (autoPlay.getStatus()) { case Leisure, Done -> { - if (autoPlay.set(obj, player, note)) autoPlay.start(); + if (note != null) if (autoPlay.set(obj, player, note)) autoPlay.start(); } case Searching -> { autoPlay.abort(); diff --git a/src/main/java/com/github/wohaopa/tc4helper/proxy/ClientProxy.java b/src/main/java/com/github/wohaopa/tc4helper/proxy/ClientProxy.java new file mode 100644 index 0000000..c8b1291 --- /dev/null +++ b/src/main/java/com/github/wohaopa/tc4helper/proxy/ClientProxy.java @@ -0,0 +1,49 @@ +package com.github.wohaopa.tc4helper.proxy; + +import java.lang.reflect.Field; +import java.util.Map; + +import net.minecraftforge.client.ClientCommandHandler; + +import com.github.wohaopa.tc4helper.Command; +import com.github.wohaopa.tc4helper.GuiHandler; + +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.event.FMLLoadCompleteEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.network.IGuiHandler; +import cpw.mods.fml.common.network.NetworkRegistry; + +public class ClientProxy implements IProxy { + + @Override + public void postInit(FMLPostInitializationEvent event) { + ClientCommandHandler.instance.registerCommand(new Command()); + } + + @Override + public void complete(FMLLoadCompleteEvent event) { + if (Loader.isModLoaded("ThaumcraftResearchTweaks")) { + + try { + Class clazz = NetworkRegistry.class; + Field field = clazz.getDeclaredField("clientGuiHandlers"); + field.setAccessible(true); + Map clientGuiHandlers = (Map) field + .get(NetworkRegistry.INSTANCE); + ModContainer mc = Loader.instance() + .getIndexedModList() + .get("ThaumcraftResearchTweaks"); + + NetworkRegistry.INSTANCE + .registerGuiHandler("ThaumcraftResearchTweaks", new GuiHandler(clientGuiHandlers.get(mc))); + + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new RuntimeException(e); + } + + } + + } +} diff --git a/src/main/java/com/github/wohaopa/tc4helper/proxy/IProxy.java b/src/main/java/com/github/wohaopa/tc4helper/proxy/IProxy.java new file mode 100644 index 0000000..b281021 --- /dev/null +++ b/src/main/java/com/github/wohaopa/tc4helper/proxy/IProxy.java @@ -0,0 +1,11 @@ +package com.github.wohaopa.tc4helper.proxy; + +import cpw.mods.fml.common.event.FMLLoadCompleteEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; + +public interface IProxy { + + default void postInit(FMLPostInitializationEvent event) {} + + default void complete(FMLLoadCompleteEvent event) {} +} diff --git a/src/main/java/com/github/wohaopa/tc4helper/proxy/ServerProxy.java b/src/main/java/com/github/wohaopa/tc4helper/proxy/ServerProxy.java new file mode 100644 index 0000000..d6a5234 --- /dev/null +++ b/src/main/java/com/github/wohaopa/tc4helper/proxy/ServerProxy.java @@ -0,0 +1,4 @@ +package com.github.wohaopa.tc4helper.proxy; + +public class ServerProxy implements IProxy { +} diff --git a/src/main/java/elan/tweaks/thaumcraft/research/frontend/integration/table/mixin/TableBlockMixin.java b/src/main/java/elan/tweaks/thaumcraft/research/frontend/integration/table/mixin/TableBlockMixin.java deleted file mode 100644 index f74fbf8..0000000 --- a/src/main/java/elan/tweaks/thaumcraft/research/frontend/integration/table/mixin/TableBlockMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package elan.tweaks.thaumcraft.research.frontend.integration.table.mixin; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.World; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import com.github.wohaopa.tc4helper.TC4Helper; - -import thaumcraft.common.blocks.BlockTable; - -@Mixin(BlockTable.class) -public class TableBlockMixin { - - @Redirect( - method = ("onBlockActivated"), - at = @At( - value = "INVOKE", - target = "net.minecraft.entity.player.EntityPlayer.openGui(Ljava/lang/Object;ILnet/minecraft/world/World;III)V", - remap = false), - require = 4) - private void correctGuiCallFor(EntityPlayer entityPlayer, Object mod, int modGuiId, World world, int x, int y, - int z) { - if (modGuiId == 10 && !TC4Helper.enabled) { - entityPlayer.openGui("ThaumcraftResearchTweaks", 0, world, x, y, z); - } else { - entityPlayer.openGui(mod, modGuiId, world, x, y, z); - } - } -}