Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package mcp.mobius.waila.addons.ic2;

import mcp.mobius.waila.api.ITaggedList;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.cbcore.LangUtil;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import javax.annotation.Nonnull;
import java.util.List;

public class HUDHandlerTEGenerator implements IWailaDataProvider {

static final IWailaDataProvider INSTANCE = new HUDHandlerTEGenerator();

@Nonnull
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
double storage = accessor.getNBTData().getDouble("storage");
int production = accessor.getNBTData().getInteger("production");
long maxStorage = accessor.getNBTData().getLong("maxStorage");

String storedStr = LangUtil.translateG("hud.ic2.msg.stored");
String outputStr = LangUtil.translateG("hud.ic2.msg.output");

if (accessor.getTileEntity() == null) {
return currenttip;
}

/* EU Storage */
if (config.getConfig("ic2.storage"))
if (maxStorage > 0) {
((ITaggedList<String, String>) currenttip)
.add(String.format(
"%s §f%d§r / §f%d§r EU",
storedStr,
Math.round(Math.min(storage, maxStorage)),
maxStorage
), "IEnergyStorage");
}

if (config.getConfig("ic2.outputeu")) {
currenttip.add(String.format("%s §f%d §r EU/t", outputStr, production));
}

return currenttip;
}


@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
double storage = -1;
int production = -1;
long maxStorage = -1;

try {
if (IC2Module.generator.isInstance(te)) {
storage = IC2Module.generatorStorage.getDouble(te);
production = IC2Module.generatorProduction.getInt(te);
maxStorage = IC2Module.generatorMaxStorage.getLong(te);
}
} catch (java.lang.Exception e) {
throw new RuntimeException(e);
}
tag.setDouble("storage", storage);
tag.setInteger("production", production);
tag.setLong("maxStorage", maxStorage);

return tag;
}
}
40 changes: 40 additions & 0 deletions src/main/java/mcp/mobius/waila/addons/ic2/IC2Module.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mcp.mobius.waila.addons.ic2;

import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.IWailaPlugin;
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.WailaPlugin;
import net.minecraftforge.fml.common.Loader;

import java.lang.reflect.Field;

@WailaPlugin
public class IC2Module implements IWailaPlugin {

public static Class generator = null;
public static Field generatorStorage = null;
public static Field generatorMaxStorage = null;
public static Field generatorProduction = null;


@Override
public void register(IWailaRegistrar registrar) {
if (!Loader.isModLoaded("ic2")) return;
try {
generator = Class.forName("ic2.core.block.base.tile.TileEntityGeneratorBase");
generatorStorage = generator.getDeclaredField("storage");
generatorMaxStorage = generator.getDeclaredField("maxStorage");
generatorProduction = generator.getDeclaredField("production");


registrar.registerBodyProvider(HUDHandlerTEGenerator.INSTANCE, generator);
registrar.registerNBTProvider(HUDHandlerTEGenerator.INSTANCE, generator);

registrar.addConfig("Industrial Craft 2", "ic2.storage", true);
registrar.addConfig("Industrial Craft 2", "ic2.outputeu", true);

} catch (Exception e) {
Waila.LOGGER.warn("[Industrial Craft 2] Error while loading generator hooks.", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package mcp.mobius.waila.addons.thermalexpansion;

import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
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.util.math.BlockPos;
import net.minecraft.world.World;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.annotation.Nonnull;

public class HUDHandlerCache implements IWailaDataProvider {

static final IWailaDataProvider INSTANCE = new HUDHandlerCache();

@Nonnull
@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;
TileEntity te = accessor.getTileEntity();
NBTTagCompound tag = accessor.getNBTData();
if (accessor.getNBTData().hasKey("Item"))
storedItem = (ItemStack) ThermalExpansionModule.readItemStackFromNBT.invoke(te, tag.getCompoundTag("Item"));


String name = currenttip.get(0);
String color = "";
if (name.startsWith("§")) color = name.substring(0, 2);

if (storedItem != null) {
name += String.format(color + " < %s >", storedItem.getDisplayName());
} else name += " " + "EMPTY";

currenttip.set(0, name);
} catch (Exception e) {
throw new RuntimeException(e);
}

return currenttip;
}

@Nonnull
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {

if (!config.getConfig("thermalexpansion.cache")) return currenttip;

try {
String storedStr = LangUtil.translateG("hud.te.msg.stored");
String capacityStr = LangUtil.translateG("hud.te.msg.capacity");

TileEntity te = accessor.getTileEntity();
NBTTagCompound tag = accessor.getNBTData();

ItemStack storedItem = null;
if (tag.hasKey("Item")) {
storedItem = (ItemStack) ThermalExpansionModule.readItemStackFromNBT.invoke(te, 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(storedStr + ": " + stored);
// currenttip.add("Stored: " + stored + "/" + maxStored); //TODO: add maxStored value
} else currenttip.add(capacityStr + ": " + maxStored);
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}

return currenttip;
}


@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
if (te != null) te.writeToNBT(tag);

try {
tag.setInteger("MaxStored", 0); //TODO: add maxStored value
tag.setInteger("Stored", (Integer) ThermalExpansionModule.tileCacheGetStored.invoke(te));
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
return tag;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package mcp.mobius.waila.addons.thermalexpansion;

import mcp.mobius.waila.Waila;
import mcp.mobius.waila.api.IWailaPlugin;
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.api.WailaPlugin;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.Loader;

import java.lang.reflect.Method;

@WailaPlugin
public class ThermalExpansionModule implements IWailaPlugin {

public static Class cofhItemHelper = null;
public static Method readItemStackFromNBT = null;

public static Class tileCache = null;
public static Method tileCacheGetStored = null;

public void register(IWailaRegistrar registrar) {
if (!Loader.isModLoaded("thermalexpansion") || !Loader.isModLoaded("cofhcore")) return;
try {
cofhItemHelper = Class.forName("cofh.core.util.helpers.ItemHelper");
readItemStackFromNBT = cofhItemHelper.getMethod("readItemStackFromNBT", NBTTagCompound.class);


tileCache = Class.forName("cofh.thermalexpansion.block.storage.TileCache");
tileCacheGetStored = tileCache.getDeclaredMethod("getStoredCount");

registrar.registerHeadProvider(HUDHandlerCache.INSTANCE, tileCache);
registrar.registerBodyProvider(HUDHandlerCache.INSTANCE, tileCache);
registrar.registerNBTProvider(HUDHandlerCache.INSTANCE, tileCache);

registrar.addConfig("Thermal Expansion", "thermalexpansion.cache");
} catch (Exception e) {
Waila.LOGGER.warn("[Thermal Expansion] Error while loading store cache hooks.", e);
}
}
}
8 changes: 7 additions & 1 deletion src/main/resources/assets/waila/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ hud.msg.offers=Offers
hud.msg.demands=Demands
hud.msg.career=Career: %s

hud.ic2.msg.stored=Stored
hud.ic2.msg.output=Output

hud.te.msg.stored=Stored
hud.te.msg.capacity=Capacity

hud.item.melonstem=Melon Stem
hud.item.pumpkinstem=Pumpkin Stem

Expand All @@ -87,4 +93,4 @@ option.general.registry=Show registry data
option.capability.tankinfo=Show tank data
option.capability.energyinfo=Show energy data

nei.options.keys.showenchant=Show enchanting values
nei.options.keys.showenchant=Show enchanting values
6 changes: 6 additions & 0 deletions src/main/resources/assets/waila/lang/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ hud.msg.offers=Предложения
hud.msg.demands=Запросы
hud.msg.career=Карьера: %s

hud.ic2.msg.stored=Хранится
hud.ic2.msg.output=Вывод

hud.te.msg.stored=Хранится
hud.te.msg.capacity=Объём

hud.item.melonstem=Стебель дыни
hud.item.pumpkinstem=Стебель арбуза

Expand Down