Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Suppose server
Browse files Browse the repository at this point in the history
  • Loading branch information
wohaopa committed Jun 28, 2024
1 parent dc9f421 commit ba930fa
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 113 deletions.
8 changes: 0 additions & 8 deletions src/main/java/com/github/wohaopa/tc4helper/ClientProxy.java

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/com/github/wohaopa/tc4helper/CommonProxy.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/com/github/wohaopa/tc4helper/Config.java

This file was deleted.

37 changes: 37 additions & 0 deletions src/main/java/com/github/wohaopa/tc4helper/GuiHandler.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
39 changes: 15 additions & 24 deletions src/main/java/com/github/wohaopa/tc4helper/TC4Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,38 @@
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";
public static final Logger LOG = LogManager.getLogger(MODID);
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/github/wohaopa/tc4helper/proxy/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -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<NetworkRegistry> clazz = NetworkRegistry.class;
Field field = clazz.getDeclaredField("clientGuiHandlers");
field.setAccessible(true);
Map<ModContainer, IGuiHandler> clientGuiHandlers = (Map<ModContainer, IGuiHandler>) 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);
}

}

}
}
11 changes: 11 additions & 0 deletions src/main/java/com/github/wohaopa/tc4helper/proxy/IProxy.java
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.wohaopa.tc4helper.proxy;

public class ServerProxy implements IProxy {
}

This file was deleted.

0 comments on commit ba930fa

Please sign in to comment.