forked from TehNut-Mods/HWYLA
-
Notifications
You must be signed in to change notification settings - Fork 1
Added IC2 and TE addons #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/mcp/mobius/waila/addons/ic2/HUDHandlerTEGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
98 changes: 98 additions & 0 deletions
98
src/main/java/mcp/mobius/waila/addons/thermalexpansion/HUDHandlerCache.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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) { | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| e.printStackTrace(); | ||
| } | ||
| return tag; | ||
| } | ||
|
|
||
| public ItemStack readItemStack(NBTTagCompound tag) { | ||
| ItemStack is = new ItemStack(Item.getByNameOrId(tag.getString("id"))); | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 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; | ||
| } | ||
|
|
||
| } | ||
46 changes: 46 additions & 0 deletions
46
src/main/java/mcp/mobius/waila/addons/thermalexpansion/ThermalExpansionModule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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."); | ||
| } | ||
TheAndrey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.