Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,75 @@
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 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");

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

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

if (config.getConfig("ic2.outputeu")) {
currenttip.add(String.format("%s §f%d §r EU/t", "OUTPUT", 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.TileBaseGenerator.isInstance(te)) {
storage = IC2Module.TileBaseGenerator_storage.getDouble(te);
production = IC2Module.TileBaseGenerator_production.getInt(te);
maxStorage = IC2Module.TileBaseGenerator_maxStorage.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;
}
}
43 changes: 43 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,43 @@
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 java.lang.reflect.Field;

@WailaPlugin
public class IC2Module implements IWailaPlugin{

public static Class TileBaseGenerator = null;
public static Field TileBaseGenerator_storage = null;
public static Field TileBaseGenerator_maxStorage = null;
public static Field TileBaseGenerator_production = null;


@Override
public void register(IWailaRegistrar registrar) {

try {
TileBaseGenerator = Class.forName("ic2.core.block.base.tile.TileEntityGeneratorBase");
TileBaseGenerator_storage = TileBaseGenerator.getDeclaredField("storage");
TileBaseGenerator_maxStorage = TileBaseGenerator.getDeclaredField("maxStorage");
TileBaseGenerator_production = TileBaseGenerator.getDeclaredField("production");


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

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

} catch (Exception e) {
if (e instanceof ClassNotFoundException || e instanceof NoSuchFieldException) {
Waila.LOGGER.info("[Industrial Craft 2] IndustrialCraft 2 mod not found.");
} else {
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,98 @@
package mcp.mobius.waila.addons.thermalexpansion;

import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.tileentity.TileEntity;
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;
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) {;
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;

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);
// currenttip.add("Stored: " + stored + "/" + maxStored); //TODO: maxStored
} else currenttip.add("Capacity: " + maxStored);

return currenttip;
}


@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);

if (te != null) te.writeToNBT(tag);
try {
tag.setInteger("MaxStored", 0); //TODO: maxStored
tag.setInteger("Stored", (Integer) ThermalExpansionModule.TileCache_getStored.invoke(te));
} catch (InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
return tag;
}

public ItemStack readItemStack(NBTTagCompound tag) {
ItemStack is = new ItemStack(Item.getByNameOrId(tag.getString("id")));
// TODO: WIP
// is.splitStack(tag.getInteger("Count"));
// is.setItemDamage(Math.max(0, tag.getShort("Damage")));
// if (tag.hasKey("tag", 10)) {
// is.setTagCompound(tag.getCompoundTag("tag"));
// }
return is;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 java.lang.reflect.Method;

@WailaPlugin
public class ThermalExpansionModule implements IWailaPlugin {

public static Class TileCache = null;
public static Method TileCache_getStored = null;

public static Method IBlockInfo_getBlockInfo = null;

public void register(IWailaRegistrar registrar) {
boolean printedThermalExpansionNotFound = false;

try {
TileCache = Class.forName("cofh.thermalexpansion.block.storage.TileCache");
TileCache_getStored = 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) {
if (e instanceof ClassNotFoundException) {
if (!printedThermalExpansionNotFound) {
printedThermalExpansionNotFound = true;
Waila.LOGGER.info("[Thermal Expansion] Thermal Expansion mod not found.");
}
} else {
Waila.LOGGER.warn("[Thermal Expansion] Error while loading store cache hooks. {}", e);
}
}
if (!printedThermalExpansionNotFound) {
Waila.LOGGER.info("Thermal Expansion mod found.");
}
}

}