mirror of
https://github.com/GTNewHorizons/WailaHarvestability.git
synced 2026-11-25 06:14:34 +00:00
Initial version
This commit is contained in:
1 parent
08d4230bb9
commit
e57ea8401c
24 files changed
+736
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package squeek.wailaharvestlevels;
|
||||
|
||||
import squeek.wailaharvestlevels.proxy.ProxyIguanaTweaks;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Mod(modid = ModWailaHarvestLevels.MODID, version = ModWailaHarvestLevels.VERSION, dependencies = "after:TConstruct;after:ExtraTiC;after:TSteelworks;after:Mariculture")
|
||||
public class ModWailaHarvestLevels
|
||||
{
|
||||
public static final String MODID = "WailaHarvestLevels";
|
||||
public static final String VERSION = "${version}";
|
||||
|
||||
public static boolean hasIguanaTweaks;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
FMLInterModComms.sendMessage("Waila", "register", "squeek.wailaharvestlevels.WailaHandler.callbackRegister");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
if (Loader.isModLoaded("IguanaTweaksTConstruct"))
|
||||
{
|
||||
hasIguanaTweaks = true;
|
||||
ProxyIguanaTweaks.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package squeek.wailaharvestlevels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import squeek.wailaharvestlevels.helpers.StringHelper;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
import mcp.mobius.waila.api.IWailaRegistrar;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class WailaHandler implements IWailaDataProvider
|
||||
{
|
||||
@Override
|
||||
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaHead(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaBody(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
if (config.getConfig("mining.harvestlevel") || config.getConfig("mining.effectivetool"))
|
||||
{
|
||||
int oreID = -1;
|
||||
if (config.getConfig("mining.oresonly") && ((oreID = OreDictionary.getOreID(itemStack)) == -1 || !OreDictionary.getOreName(oreID).startsWith("ore")))
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
EnumChatFormatting effectiveColor = EnumChatFormatting.DARK_RED;
|
||||
EnumChatFormatting harvestColor = EnumChatFormatting.DARK_RED;
|
||||
ItemStack itemHeld = accessor.getPlayer().getHeldItem();
|
||||
List<String> harvestTypes = new ArrayList<String>();
|
||||
int tinkersHarvestLevel = -1;
|
||||
if (itemHeld != null)
|
||||
{
|
||||
/*
|
||||
if (itemHeld.getItem() instanceof HarvestTool)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method getHarvestType = HarvestTool.class.getDeclaredMethod("getHarvestType");
|
||||
getHarvestType.setAccessible(true);
|
||||
harvestTypes.add((String) getHarvestType.invoke(itemHeld.getItem()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (itemHeld.getItem() instanceof DualHarvestTool)
|
||||
{
|
||||
try
|
||||
{
|
||||
Method getSecondHarvestType = DualHarvestTool.class.getDeclaredMethod("getSecondHarvestType");
|
||||
getSecondHarvestType.setAccessible(true);
|
||||
harvestTypes.add((String) getSecondHarvestType.invoke(itemHeld.getItem()));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
tinkersHarvestLevel = Math.max(ToolHelper.getPrimaryHarvestLevel(ToolHelper.getToolTag(itemHeld)), ToolHelper.getSecondaryHarvestLevel(ToolHelper.getToolTag(itemHeld)));
|
||||
}
|
||||
else*/ if (ForgeHooks.isToolEffective(itemHeld, accessor.getBlock(), accessor.getMetadata()))
|
||||
{
|
||||
effectiveColor = EnumChatFormatting.DARK_GREEN;
|
||||
|
||||
if (ForgeHooks.canToolHarvestBlock(accessor.getBlock(), accessor.getMetadata(), itemHeld))
|
||||
{
|
||||
harvestColor = EnumChatFormatting.DARK_GREEN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int hlvl = MinecraftForge.getBlockHarvestLevel(accessor.getBlock(), accessor.getMetadata(), "pickaxe");
|
||||
String effectiveTool = "Pickaxe";
|
||||
int hlvlMin = 0;
|
||||
|
||||
if (hlvl == -1)
|
||||
{
|
||||
hlvlMin = 1;
|
||||
|
||||
hlvl = MinecraftForge.getBlockHarvestLevel(accessor.getBlock(), accessor.getMetadata(), "shovel");
|
||||
effectiveTool = "Shovel";
|
||||
|
||||
if (hlvl == -1)
|
||||
{
|
||||
hlvl = MinecraftForge.getBlockHarvestLevel(accessor.getBlock(), accessor.getMetadata(), "axe");
|
||||
effectiveTool = "Axe";
|
||||
}
|
||||
}
|
||||
|
||||
if (harvestTypes.contains(effectiveTool.toLowerCase()))
|
||||
{
|
||||
boolean isEffectiveButCantHarvest = itemHeld != null && !itemHeld.canHarvestBlock(accessor.getBlock());
|
||||
if (isEffectiveButCantHarvest)
|
||||
effectiveColor = EnumChatFormatting.RED;
|
||||
else
|
||||
effectiveColor = EnumChatFormatting.DARK_GREEN;
|
||||
}
|
||||
if (tinkersHarvestLevel >= hlvl)
|
||||
harvestColor = EnumChatFormatting.DARK_GREEN;
|
||||
|
||||
if (hlvl >= hlvlMin && config.getConfig("mining.harvestlevel"))
|
||||
toolTip.add("Harvest Level : "+harvestColor+StringHelper.getHarvestLevelName(hlvl));
|
||||
if (hlvl != -1 && config.getConfig("mining.effectivetool"))
|
||||
toolTip.add("Effective Tool : "+effectiveColor+effectiveTool);
|
||||
toolTip.addAll(harvestTypes);
|
||||
}
|
||||
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaTail(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
public static void callbackRegister(IWailaRegistrar registrar)
|
||||
{
|
||||
WailaHandler instance = new WailaHandler();
|
||||
registrar.addConfig("Mining", "mining.harvestlevel", "Show harvest level");
|
||||
registrar.addConfig("Mining", "mining.effectivetool", "Show effective tool");
|
||||
registrar.addConfig("Mining", "mining.oresonly", "Only show on ore blocks");
|
||||
registrar.registerBodyProvider(instance, Block.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package squeek.wailaharvestlevels.helpers;
|
||||
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class ColorHelper
|
||||
{
|
||||
private static final EnumChatFormatting colorRange[] = {
|
||||
EnumChatFormatting.DARK_RED,
|
||||
EnumChatFormatting.RED,
|
||||
EnumChatFormatting.GOLD,
|
||||
EnumChatFormatting.YELLOW,
|
||||
EnumChatFormatting.DARK_GREEN,
|
||||
EnumChatFormatting.GREEN,
|
||||
EnumChatFormatting.AQUA
|
||||
};
|
||||
|
||||
public static String getRelativeColor(double val, double min, double max)
|
||||
{
|
||||
if (min == max)
|
||||
return EnumChatFormatting.RESET.toString();
|
||||
else if ((max > min && val > max) || (min > max && val < max))
|
||||
return EnumChatFormatting.WHITE.toString() + EnumChatFormatting.BOLD;
|
||||
else if ((max > min && val < min) || (min > max && val > min))
|
||||
return colorRange[0].toString() + EnumChatFormatting.BOLD;
|
||||
|
||||
int index = (int) (((val - min) / (max - min)) * (colorRange.length - 1));
|
||||
return colorRange[Math.max(0, Math.min(colorRange.length - 1, index))].toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package squeek.wailaharvestlevels.helpers;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeyHelper
|
||||
{
|
||||
public static boolean isCtrlKeyDown()
|
||||
{
|
||||
// prioritize CONTROL, but allow OPTION as well on Mac (note: GuiScreen's isCtrlKeyDown only checks for the OPTION key on Mac)
|
||||
boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
|
||||
if (!isCtrlKeyDown && Minecraft.isRunningOnMac)
|
||||
isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA);
|
||||
|
||||
return isCtrlKeyDown;
|
||||
}
|
||||
|
||||
public static boolean isShiftKeyDown()
|
||||
{
|
||||
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package squeek.wailaharvestlevels.helpers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import squeek.wailaharvestlevels.ModWailaHarvestLevels;
|
||||
import squeek.wailaharvestlevels.proxy.ProxyIguanaTweaks;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
public class StringHelper
|
||||
{
|
||||
|
||||
//private static DecimalFormat df = new DecimalFormat("##.##");
|
||||
|
||||
// Taken from tconstruct.client.gui.ToolStationGui
|
||||
public static String getHarvestLevelName(int num)
|
||||
{
|
||||
if (ModWailaHarvestLevels.hasIguanaTweaks)
|
||||
return ProxyIguanaTweaks.getHarvestLevelName(num);
|
||||
|
||||
String unlocalized = "gui.partcrafter.mining" + (num + 1);
|
||||
String localized = StringHelper.getLocalizedString(unlocalized);
|
||||
if (!unlocalized.equals(localized))
|
||||
return localized;
|
||||
else
|
||||
return String.valueOf(num);
|
||||
}
|
||||
|
||||
// for TCon version < 1.5.3
|
||||
public static HashMap<String, String> localizationAlternatives = new HashMap<String, String>();
|
||||
static
|
||||
{
|
||||
localizationAlternatives.put("gui.partcrafter.mining1", "Stone");
|
||||
localizationAlternatives.put("gui.partcrafter.mining2", "Iron");
|
||||
localizationAlternatives.put("gui.partcrafter.mining3", "Redstone");
|
||||
localizationAlternatives.put("gui.partcrafter.mining4", "Obsidian");
|
||||
localizationAlternatives.put("gui.partcrafter.mining5", "Cobalt");
|
||||
localizationAlternatives.put("gui.partcrafter.mining6", "Atlarus");
|
||||
localizationAlternatives.put("gui.partcrafter.mining7", "7");
|
||||
localizationAlternatives.put("gui.partcrafter.mining8", "8");
|
||||
localizationAlternatives.put("gui.toolstation15", "Mining Level: ");
|
||||
}
|
||||
|
||||
public static String getLocalizedString(String unlocalized)
|
||||
{
|
||||
if (unlocalized.equals("gui.partcrafter.mining6"))
|
||||
return localizationAlternatives.get(unlocalized);
|
||||
|
||||
String localized = StatCollector.translateToLocal(unlocalized);
|
||||
if (localized.equals(unlocalized))
|
||||
{
|
||||
localized = localizationAlternatives.get(unlocalized);
|
||||
|
||||
if (localized == null)
|
||||
localized = unlocalized;
|
||||
}
|
||||
return localized;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package squeek.wailaharvestlevels.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class ToolHelper
|
||||
{
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasToolTag(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("InfiTool");
|
||||
}
|
||||
|
||||
public static NBTTagCompound getToolTag(ItemStack tool)
|
||||
{
|
||||
NBTTagCompound tag;
|
||||
tag = tool.getTagCompound().getCompoundTag("InfiTool");
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static int getPrimaryHarvestLevel(NBTTagCompound toolTag)
|
||||
{
|
||||
return toolTag.getInteger("HarvestLevel");
|
||||
}
|
||||
|
||||
public static int getSecondaryHarvestLevel(NBTTagCompound toolTag)
|
||||
{
|
||||
return toolTag.getInteger("HarvestLevel2");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package squeek.wailaharvestlevels.proxy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ProxyIguanaTweaks
|
||||
{
|
||||
private static Class<?> IguanaTweaksTConstruct = null;
|
||||
private static Method proxyGetHarvestLevelName;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
try
|
||||
{
|
||||
IguanaTweaksTConstruct = Class.forName("iguanaman.iguanatweakstconstruct.IguanaTweaksTConstruct");
|
||||
proxyGetHarvestLevelName = IguanaTweaksTConstruct.getDeclaredMethod("getHarvestLevelName", int.class);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHarvestLevelName(int num)
|
||||
{
|
||||
String harvestLevelName = "<Unknown>";
|
||||
|
||||
try
|
||||
{
|
||||
harvestLevelName = (String) proxyGetHarvestLevelName.invoke(IguanaTweaksTConstruct, num);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return harvestLevelName;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user