diff --git a/mcp/mobius/waila/ProxyClient.java b/mcp/mobius/waila/ProxyClient.java index 80f2eff..9adae62 100644 --- a/mcp/mobius/waila/ProxyClient.java +++ b/mcp/mobius/waila/ProxyClient.java @@ -4,6 +4,7 @@ import mcp.mobius.waila.addons.ExternalModulesHandler; import mcp.mobius.waila.addons.appeng.AppEngModule; import mcp.mobius.waila.addons.buildcraft.BCModule; import mcp.mobius.waila.addons.enderstorage.EnderStorageModule; +import mcp.mobius.waila.addons.etb.ETBModule; import mcp.mobius.waila.addons.gravestone.GravestoneModule; import mcp.mobius.waila.addons.ic2.IC2Module; import mcp.mobius.waila.addons.thaumcraft.ThaumcraftModule; @@ -98,6 +99,9 @@ public class ProxyClient extends ProxyServer { /* Thermal Expansion */ ThermalExpansionModule.register(); + + /* ETB */ + ETBModule.register(); } @Override diff --git a/mcp/mobius/waila/addons/etb/ETBModule.java b/mcp/mobius/waila/addons/etb/ETBModule.java new file mode 100644 index 0000000..f78cc6f --- /dev/null +++ b/mcp/mobius/waila/addons/etb/ETBModule.java @@ -0,0 +1,75 @@ +package mcp.mobius.waila.addons.etb; + +import java.lang.reflect.Field; +import java.util.logging.Level; + +import net.minecraft.item.Item; +import mcp.mobius.waila.mod_Waila; +import mcp.mobius.waila.addons.ExternalModulesHandler; + +public class ETBModule { + + public static Class TileSocket = null; + public static Field Socket_sides = null; + public static Field Socket_configs = null; + //public static Field Socket_sideID = null; + //public static Field Socket_sideMeta = null; + //public static Field Socket_facID = null; + //public static Field Socket_facMeta = null; + + public static Class SocketsMod = null; + public static Item module = null; + + public static Class SideConfig = null; + public static Field SC_tank = null; + public static Field SC_inventory = null; + public static Field SC_rsControl = null; + public static Field SC_rsLatch = null; + + public static void register(){ + try{ + Class ModClass = Class.forName("emasher.sockets.TileSocket"); + mod_Waila.log.log(Level.INFO, "Engineer Toolbox mod found."); + } catch (ClassNotFoundException e){ + mod_Waila.log.log(Level.INFO, "[Engineer Toolbox] Engineer Toolbox mod not found."); + return; + } + + try{ + + TileSocket = Class.forName("emasher.sockets.TileSocket"); + Socket_sides = TileSocket.getField("sides"); + Socket_configs = TileSocket.getField("configs"); + //Socket_sideID = TileSocket.getField("sideID"); + //Socket_sideMeta = TileSocket.getField("sideMeta"); + //Socket_facID = TileSocket.getField("facID"); + //Socket_facMeta = TileSocket.getField("facMeta"); + + SocketsMod = Class.forName("emasher.sockets.SocketsMod"); + module = (Item)SocketsMod.getField("module").get(null); + + SideConfig = Class.forName("emasher.api.SideConfig"); + SC_tank = SideConfig.getField("tank"); + SC_inventory = SideConfig.getField("inventory"); + SC_rsControl = SideConfig.getField("rsControl"); + SC_rsLatch = SideConfig.getField("rsLatch"); + + + } catch (ClassNotFoundException e){ + mod_Waila.log.log(Level.WARNING, "[EnderStorage] Class not found. " + e); + return; +// } catch (NoSuchMethodException e){ +// mod_Waila.log.log(Level.WARNING, "[EnderStorage] Method not found." + e); +// return; + } catch (NoSuchFieldException e){ + mod_Waila.log.log(Level.WARNING, "[EnderStorage] Field not found." + e); + return; + } catch (Exception e){ + mod_Waila.log.log(Level.WARNING, "[EnderStorage] Unhandled exception." + e); + return; + } + + ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerSocket(), TileSocket); + + } +} diff --git a/mcp/mobius/waila/addons/etb/HUDHandlerSocket.java b/mcp/mobius/waila/addons/etb/HUDHandlerSocket.java new file mode 100644 index 0000000..0375cd1 --- /dev/null +++ b/mcp/mobius/waila/addons/etb/HUDHandlerSocket.java @@ -0,0 +1,118 @@ +package mcp.mobius.waila.addons.etb; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.ForgeDirection; +import mcp.mobius.waila.WailaExceptionHandler; +import mcp.mobius.waila.api.IWailaConfigHandler; +import mcp.mobius.waila.api.IWailaDataAccessor; +import mcp.mobius.waila.api.IWailaDataProvider; + +public class HUDHandlerSocket implements IWailaDataProvider { + + @Override + public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) { + return null; + } + + @Override + public List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { + return currenttip; + } + + @Override + public List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { + + try { + int[] sides = (int[])ETBModule.Socket_sides.get(accessor.getTileEntity()); + Object[] configs = (Object[])ETBModule.Socket_configs.get(accessor.getTileEntity()); + + for( int s = 0; s < 6; s++){ + if (sides[s]!=0){ + + int tank = (Integer)ETBModule.SC_tank.get(configs[s]); + int inventory = (Integer)ETBModule.SC_inventory.get(configs[s]); + boolean[] rsControl = (boolean[])ETBModule.SC_rsControl.get(configs[s]); + boolean[] rsLatch = (boolean[])ETBModule.SC_rsLatch.get(configs[s]); + + + ItemStack stack = new ItemStack(ETBModule.module, 1, sides[s]); + String tipstr = String.format("%-5s : %s ", ForgeDirection.getOrientation(s), stack.getDisplayName()); + + String configstr = "[ "; + + if (tank != -1) + configstr += "\u00a79" + String.valueOf(tank) + " "; + + if (inventory != -1) + configstr += "\u00a7a" + String.valueOf(inventory) + " "; + + if (rsControl[0] || rsControl[1] || rsControl[2]){ + configstr += "\u00a7c"; + configstr += rsControl[0] ? "1" : "0"; + configstr += rsControl[1] ? "1" : "0"; + configstr += rsControl[2] ? "1" : "0"; + configstr += " "; + } + + if (rsLatch[0] || rsLatch[1] || rsLatch[2]){ + configstr += "\u00a75"; + configstr += rsLatch[0] ? "1" : "0"; + configstr += rsLatch[1] ? "1" : "0"; + configstr += rsLatch[2] ? "1" : "0"; + configstr += " "; + } + + configstr += "\u00a7r]"; + + if (!configstr.equals("[ \u00a7r]")) + tipstr += " " + configstr; + + /* + if ((tank != -1) && (inventory != -1)) + tipstr += String.format("[ \u00a79%d \u00a7a%d \u00a7r]", tank, inventory); + else if (tank != -1) + tipstr += String.format("[ \u00a79%d \u00a7r]", tank); + else if (inventory != -1) + tipstr += String.format("[ \u00a7a%d \u00a7r]", inventory); + */ + + currenttip.add(tipstr); + } + } + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (Exception e){ + e.printStackTrace(); + } + + + //int[] sideID = (int[])ETBModule.Socket_sideID.get(accessor.getTileEntity()); + //int[] sideMeta = (int[])ETBModule.Socket_sideMeta.get(accessor.getTileEntity()); + //int[] facID = (int[])ETBModule.Socket_facID.get(accessor.getTileEntity()); + //int[] facMeta = (int[])ETBModule.Socket_facMeta.get(accessor.getTileEntity()); + + //currenttip.add(String.format("Sides : %s", Arrays.toString(sides))); + //currenttip.add(String.format("SideID : %s", Arrays.toString(sideID))); + //currenttip.add(String.format("SideMeta : %s", Arrays.toString(sideMeta))); + //currenttip.add(String.format("FacID : %s", Arrays.toString(facID))); + //currenttip.add(String.format("FacMeta : %s", Arrays.toString(facMeta))); + + //} catch (Exception e) { + // currenttip = WailaExceptionHandler.handleErr(e, accessor.getTileEntity().getClass().getName(), currenttip); + //} + + return currenttip; + } + + @Override + public List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { + return currenttip; + } + +}