mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-21 20:52:40 +00:00
Fix for Thermal Expansion stuff - Also added HUD for Caches :)
This commit is contained in:
1 parent
ea95fadb78
commit
f4f5920d88
2 files changed
+145
-17
No files matched your search
@@ -0,0 +1,111 @@
|
||||
package mcp.mobius.waila.addons.thermalexpansion;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameData;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
import mcp.mobius.waila.api.SpecialChars;
|
||||
import mcp.mobius.waila.cbcore.LangUtil;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public class HUDHandlerCache implements IWailaDataProvider {
|
||||
|
||||
@Override
|
||||
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) { return null; }
|
||||
|
||||
@Override
|
||||
public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
if(!config.getConfig("thermalexpansion.cache"))
|
||||
return currenttip;
|
||||
try {
|
||||
ItemStack storedItem = null;
|
||||
if(accessor.getNBTData().hasKey("Item"))
|
||||
storedItem = readItemStack(accessor.getNBTData().getCompoundTag("Item"));
|
||||
|
||||
String name = currenttip.get(0);
|
||||
String color = "";
|
||||
if(name.startsWith("\u00a7"))
|
||||
color = name.substring(0, 2);
|
||||
|
||||
if(storedItem != null) {
|
||||
String namex = GameData.getItemRegistry().getNameForObject(storedItem.getItem());
|
||||
name += String.format(" < " + SpecialChars.getRenderString("waila.stack", "1", namex, "0", String.valueOf(storedItem.getItemDamage())) + color + " %s >", storedItem.getDisplayName());
|
||||
}
|
||||
else
|
||||
name += " " + LangUtil.translateG("hud.msg.empty");
|
||||
|
||||
currenttip.set(0, name);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
if (!config.getConfig("thermalexpansion.cache"))
|
||||
return currenttip;
|
||||
|
||||
NBTTagCompound tag = accessor.getNBTData();
|
||||
ItemStack storedItem = null;
|
||||
if(tag.hasKey("Item"))
|
||||
storedItem = readItemStack(tag.getCompoundTag("Item"));
|
||||
|
||||
int stored = 0;
|
||||
int maxStored = 0;
|
||||
if(tag.hasKey("Stored"))
|
||||
stored = tag.getInteger("Stored");
|
||||
if(tag.hasKey("MaxStored"))
|
||||
maxStored = tag.getInteger("MaxStored");
|
||||
|
||||
if(storedItem != null) {
|
||||
currenttip.add("Stored: " + stored + "/" + maxStored);
|
||||
}
|
||||
else
|
||||
currenttip.add("Capacity: " + maxStored);
|
||||
|
||||
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z) {
|
||||
if(te != null)
|
||||
te.writeToNBT(tag);
|
||||
try {
|
||||
tag.setInteger("MaxStored", (Integer) ThermalExpansionModule.TileCache_getMaxStored.invoke(te));
|
||||
tag.setInteger("Stored", (Integer) ThermalExpansionModule.TileCache_getStored.invoke(te));
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
public ItemStack readItemStack(NBTTagCompound tag) {
|
||||
ItemStack is = new ItemStack(Item.getItemById(tag.getShort("id")));
|
||||
is.stackSize = tag.getInteger("Count");
|
||||
is.setItemDamage(Math.max(0, tag.getShort("Damage")));
|
||||
if (tag.hasKey("tag", 10)) {
|
||||
is.stackTagCompound = tag.getCompoundTag("tag");
|
||||
}
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
}
|
||||
+34
-17
@@ -1,16 +1,12 @@
|
||||
package mcp.mobius.waila.addons.thermalexpansion;
|
||||
|
||||
import mcp.mobius.waila.Waila;
|
||||
import mcp.mobius.waila.api.impl.ModuleRegistrar;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import mcp.mobius.waila.Waila;
|
||||
import mcp.mobius.waila.api.impl.ModuleRegistrar;
|
||||
|
||||
public class ThermalExpansionModule {
|
||||
|
||||
@@ -44,6 +40,11 @@ public class ThermalExpansionModule {
|
||||
public static Class ISecureTile = null;
|
||||
public static Method ISecureTile_getAccess = null;
|
||||
public static Method ISecureTile_getOwnerName = null;
|
||||
|
||||
public static Class TileCache = null;
|
||||
public static Method TileCache_getItemStack = null;
|
||||
public static Method TileCache_getMaxStored = null;
|
||||
public static Method TileCache_getStored = null;
|
||||
|
||||
public static Class BlockMultipart = null;
|
||||
|
||||
@@ -76,15 +77,15 @@ public class ThermalExpansionModule {
|
||||
|
||||
} catch (Exception e){
|
||||
Waila.log.log(Level.WARN, "[Thermal Expansion] Error while loading Energy hooks." + e);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX : We register the energy cell
|
||||
try{
|
||||
TileEnergyCell = Class.forName("thermalexpansion.block.cell.TileCell");
|
||||
TileEnergyCell = Class.forName("cofh.thermalexpansion.block.cell.TileCell");
|
||||
TileEnergyCell_Recv = TileEnergyCell.getDeclaredField("energyReceive");
|
||||
TileEnergyCell_Send = TileEnergyCell.getDeclaredField("energySend");
|
||||
|
||||
ModuleRegistrar.instance().addConfigRemote("Thermal Expansion", "thermalexpansion.energycell");
|
||||
ModuleRegistrar.instance().addConfigRemote("Thermal Expansion", "thermalexpansion.energycell");
|
||||
ModuleRegistrar.instance().registerBodyProvider(new HUDHandlerEnergyCell(), TileEnergyCell);
|
||||
ModuleRegistrar.instance().registerNBTProvider (new HUDHandlerEnergyCell(), TileEnergyCell);
|
||||
|
||||
@@ -94,7 +95,7 @@ public class ThermalExpansionModule {
|
||||
|
||||
// XXX : We register the Tank interface
|
||||
try{
|
||||
TileTank = Class.forName("thermalexpansion.block.tank.TileTank");
|
||||
TileTank = Class.forName("cofh.thermalexpansion.block.tank.TileTank");
|
||||
TileTank_getTankFluid = TileTank.getMethod("getTankFluid");
|
||||
TileTank_getTankCapacity = TileTank.getMethod("getTankCapacity");
|
||||
TileTank_getTankAmount = TileTank.getMethod("getTankFluidAmount");
|
||||
@@ -113,7 +114,7 @@ public class ThermalExpansionModule {
|
||||
|
||||
// XXX : We register the Tesseract interface
|
||||
try{
|
||||
TileTesseract = Class.forName("thermalexpansion.block.ender.TileTesseract");
|
||||
TileTesseract = Class.forName("cofh.thermalexpansion.block.ender.TileTesseract");
|
||||
TileTesseract_Item = TileTesseract.getDeclaredField("modeItem");
|
||||
TileTesseract_Fluid = TileTesseract.getDeclaredField("modeFluid");
|
||||
TileTesseract_Energy = TileTesseract.getDeclaredField("modeEnergy");
|
||||
@@ -141,9 +142,25 @@ public class ThermalExpansionModule {
|
||||
|
||||
} catch (Exception e){
|
||||
Waila.log.log(Level.WARN, "[Thermal Expansion] Error while loading ISecureTile hooks." + e);
|
||||
}
|
||||
|
||||
// XXX : We register the IBlockInfo interface
|
||||
}
|
||||
|
||||
// XXX : We register the Cache interface
|
||||
try{
|
||||
TileCache = Class.forName("cofh.thermalexpansion.block.cache.TileCache");
|
||||
TileCache_getItemStack = TileCache.getDeclaredMethod("getStoredItemType");
|
||||
TileCache_getMaxStored = TileCache.getDeclaredMethod("getMaxStoredCount");
|
||||
TileCache_getStored = TileCache.getDeclaredMethod("getStoredCount");
|
||||
|
||||
ModuleRegistrar.instance().addConfigRemote("Thermal Expansion", "thermalexpansion.cache");
|
||||
ModuleRegistrar.instance().registerHeadProvider(new HUDHandlerCache(), TileCache);
|
||||
ModuleRegistrar.instance().registerBodyProvider(new HUDHandlerCache(), TileCache);
|
||||
ModuleRegistrar.instance().registerNBTProvider (new HUDHandlerCache(), TileCache);
|
||||
|
||||
} catch (Exception e){
|
||||
Waila.log.log(Level.WARN, "[Thermal Expansion] Error while loading Tesseract hooks." + e);
|
||||
}
|
||||
|
||||
// XXX : We register the IBlockInfo interface
|
||||
/*
|
||||
try{
|
||||
IBlockInfo = Class.forName("cofh.api.block.IBlockInfo");
|
||||
|
||||
Reference in new issue
Block a user