diff --git a/README.md b/README.md new file mode 100644 index 0000000..ab996a4 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +Waila Harvest Levels +==================== + +Minecraft mod that adds required harvest level and the effective tool to Waila tooltips of harvestable blocks + +[Minecraft Forum Thread]() + +###Building + +1. Clone this repository into a folder named WailaHarvestLevels +2. If you have [Gradle](http://www.gradle.org/) installed, open a command line in the WailaHarvestLevels folder and execute: ```gradle build```. To give the build a version number, use ```gradle build -Pversion=``` instead (example: ```gradle build -Pversion=1.0.0```) + * If you don't have Gradle installed, you can use [ForgeGradle](http://www.minecraftforge.net/forum/index.php?topic=14048.0)'s gradlew/gradlew.bat instead \ No newline at end of file diff --git a/apis/mcp/mobius/waila/api/IWailaBlock.java b/apis/mcp/mobius/waila/api/IWailaBlock.java new file mode 100644 index 0000000..8b4dd13 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaBlock.java @@ -0,0 +1,34 @@ +package mcp.mobius.waila.api; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +@Deprecated +public interface IWailaBlock { + /* + * Use this method to return an item stack in case the default lookup system fails. + * Return null if you want to use the default lookup system. + * You get the world, the player and the location of the block. With that, it is easy to gather information & tile entities + */ + ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config); + + /* Waila HUD is divided into 3 zones. The head corresponds to the item name, + * body to where you mostly want to put informations, and I reserve the tail for modname display + */ + + /* Those 2 methods works exactly the same way, except they are related to a different zone in Waila HUD. + * You get in input world, player and the block location. You also get the itemstack as returned by the default lookup system or getWailaStack(). + * ConfigHandler provides the current Waila config state so you can show/hide elements depending on the configuration. Refer the ConfigHandler class for more info. + * currenttip represents the current list of text lines in the tooltip zone. + * For example, getWailaHead() will have the current item name as currenttip. + * You can modify the tips, add more, remove some, etc. + * When you are done, just returns the currenttip and it will display in Waila. + * + * Always return the currenttip is you don't want to modify the current zone. + */ + + List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); + List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); + List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/IWailaBlockDecorator.java b/apis/mcp/mobius/waila/api/IWailaBlockDecorator.java new file mode 100644 index 0000000..935d475 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaBlockDecorator.java @@ -0,0 +1,9 @@ +package mcp.mobius.waila.api; + +import net.minecraft.item.ItemStack; + +public interface IWailaBlockDecorator { + + void decorateBlock(ItemStack itemStack, IWailaDataAccessor accessor, IWailaConfigHandler config); + +} diff --git a/apis/mcp/mobius/waila/api/IWailaConfigHandler.java b/apis/mcp/mobius/waila/api/IWailaConfigHandler.java new file mode 100644 index 0000000..faede63 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaConfigHandler.java @@ -0,0 +1,28 @@ +package mcp.mobius.waila.api; + +import java.util.HashMap; +import java.util.Set; + +public interface IWailaConfigHandler { + /* Returns a set of all the currently loaded modules in the config handler */ + public Set getModuleNames(); + + /* Returns all the currently available options for a given module */ + public HashMap getConfigKeys(String modName); + + /* Add a new option to a given module + * + * modName is the name of the module to add the option to (ie : Buildcraft, IndustrialCraft2, etc) + * key is the config key (ie : bc.tankcontent, ic2.inputvalue) + * name is the human readable name of the option (ie : "Tank content", "Max EU Input") + * */ + //public void addConfig(String modName, String key, String name); + + /* Returns the current value of an option (true/false) with a default value defvalue if not set*/ + public boolean getConfig(String key, boolean defvalue); + + /* Returns the current value of an option (true/false) with a default value true if not set*/ + public boolean getConfig(String key); + + //public void setConfig(String key, boolean value); +} diff --git a/apis/mcp/mobius/waila/api/IWailaDataAccessor.java b/apis/mcp/mobius/waila/api/IWailaDataAccessor.java new file mode 100644 index 0000000..5eade35 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaDataAccessor.java @@ -0,0 +1,33 @@ +package mcp.mobius.waila.api; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; + +/* The Accessor is used to get some basic data out of the game without having to request + * direct access to the game engine. + * It will also return things that are unmodified by the overriding systems (like getWailaStack). + */ + +public interface IWailaDataAccessor { + + World getWorld(); + EntityPlayer getPlayer(); + Block getBlock(); + int getBlockID(); + int getMetadata(); + TileEntity getTileEntity(); + MovingObjectPosition getPosition(); + Vec3 getRenderingPosition(); + NBTTagCompound getNBTData(); + int getNBTInteger(NBTTagCompound tag, String keyname); + double getPartialFrame(); + ForgeDirection getSide(); + ItemStack getStack(); +} diff --git a/apis/mcp/mobius/waila/api/IWailaDataProvider.java b/apis/mcp/mobius/waila/api/IWailaDataProvider.java new file mode 100644 index 0000000..4859d9c --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaDataProvider.java @@ -0,0 +1,33 @@ +package mcp.mobius.waila.api; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +public interface IWailaDataProvider{ + /* + * Use this method to return an item stack in case the default lookup system fails. + * Return null if you want to use the default lookup system. + * You get the world, the player and the location of the block. With that, it is easy to gather information & tile entities + */ + ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config); + + /* Waila HUD is divided into 3 zones. The head corresponds to the item name, + * body to where you mostly want to put informations, and I reserve the tail for modname display + */ + + /* Those 2 methods works exactly the same way, except they are related to a different zone in Waila HUD. + * You get in input world, player and the block location. You also get the itemstack as returned by the default lookup system or getWailaStack(). + * ConfigHandler provides the current Waila config state so you can show/hide elements depending on the configuration. Refer the ConfigHandler class for more info. + * currenttip represents the current list of text lines in the tooltip zone. + * For example, getWailaHead() will have the current item name as currenttip. + * You can modify the tips, add more, remove some, etc. + * When you are done, just returns the currenttip and it will display in Waila. + * + * Always return the currenttip is you don't want to modify the current zone. + */ + + List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); + List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); + List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/IWailaEntityAccessor.java b/apis/mcp/mobius/waila/api/IWailaEntityAccessor.java new file mode 100644 index 0000000..788067a --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaEntityAccessor.java @@ -0,0 +1,24 @@ +package mcp.mobius.waila.api; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +/* The Accessor is used to get some basic data out of the game without having to request + * direct access to the game engine. + * It will also return things that are unmodified by the overriding systems (like getWailaStack). + */ + +public interface IWailaEntityAccessor { + World getWorld(); + EntityPlayer getPlayer(); + Entity getEntity(); + MovingObjectPosition getPosition(); + Vec3 getRenderingPosition(); + NBTTagCompound getNBTData(); + int getNBTInteger(NBTTagCompound tag, String keyname); + double getPartialFrame(); +} diff --git a/apis/mcp/mobius/waila/api/IWailaEntityProvider.java b/apis/mcp/mobius/waila/api/IWailaEntityProvider.java new file mode 100644 index 0000000..9548289 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaEntityProvider.java @@ -0,0 +1,16 @@ +package mcp.mobius.waila.api; + +import java.util.List; + +import net.minecraft.entity.Entity; + +public interface IWailaEntityProvider { + + /* A way to get an override on the entity returned by the raytracing */ + Entity getWailaOverride(IWailaEntityAccessor accessor, IWailaConfigHandler config); + + /* The classical HEAD/BODY/TAIL text getters */ + List getWailaHead(Entity entity, List currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config); + List getWailaBody(Entity entity, List currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config); + List getWailaTail(Entity entity, List currenttip, IWailaEntityAccessor accessor, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/IWailaFMPAccessor.java b/apis/mcp/mobius/waila/api/IWailaFMPAccessor.java new file mode 100644 index 0000000..e30afc4 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaFMPAccessor.java @@ -0,0 +1,28 @@ +package mcp.mobius.waila.api; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; + +/* The Accessor is used to get some basic data out of the game without having to request + * direct access to the game engine. + * It will also return things that are unmodified by the overriding systems (like getWailaStack). + */ + +public interface IWailaFMPAccessor { + World getWorld(); + EntityPlayer getPlayer(); + TileEntity getTileEntity(); + MovingObjectPosition getPosition(); + NBTTagCompound getNBTData(); + NBTTagCompound getFullNBTData(); + int getNBTInteger(NBTTagCompound tag, String keyname); + double getPartialFrame(); + Vec3 getRenderingPosition(); + String getID(); +} diff --git a/apis/mcp/mobius/waila/api/IWailaFMPDecorator.java b/apis/mcp/mobius/waila/api/IWailaFMPDecorator.java new file mode 100644 index 0000000..839af31 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaFMPDecorator.java @@ -0,0 +1,7 @@ +package mcp.mobius.waila.api; + +import net.minecraft.item.ItemStack; + +public interface IWailaFMPDecorator { + void decorateBlock(ItemStack itemStack, IWailaFMPAccessor accessor, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/IWailaFMPProvider.java b/apis/mcp/mobius/waila/api/IWailaFMPProvider.java new file mode 100644 index 0000000..232c83e --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaFMPProvider.java @@ -0,0 +1,12 @@ +package mcp.mobius.waila.api; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +public interface IWailaFMPProvider { + /* The classical HEAD/BODY/TAIL text getters */ + List getWailaHead(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config); + List getWailaBody(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config); + List getWailaTail(ItemStack itemStack, List currenttip, IWailaFMPAccessor accessor, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/IWailaRegistrar.java b/apis/mcp/mobius/waila/api/IWailaRegistrar.java new file mode 100644 index 0000000..833f771 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaRegistrar.java @@ -0,0 +1,56 @@ +package mcp.mobius.waila.api; + +public interface IWailaRegistrar { + /* Add a config option in the section modname with displayed text configtext and access key keyname */ + public void addConfig(String modname, String keyname, String configtext); + public void addConfigRemote(String modname, String keyname, String configtext); + public void addConfig(String modname, String keyname); + public void addConfigRemote(String modname, String keyname); + + /* Register a IWailaDataProvider for the given blockID, either for the Head section or the Body section */ + @Deprecated + public void registerHeadProvider (IWailaDataProvider dataProvider, int blockID); + @Deprecated + public void registerBodyProvider (IWailaDataProvider dataProvider, int blockID); + @Deprecated + public void registerTailProvider (IWailaDataProvider dataProvider, int blockID); + + /* Register a stack overrider for the given blockID */ + @Deprecated + public void registerStackProvider(IWailaDataProvider dataProvider, int blockID); + public void registerStackProvider(IWailaDataProvider dataProvider, Class block); + + /* Same thing, but works on a class hierarchy instead */ + public void registerHeadProvider (IWailaDataProvider dataProvider, Class block); + public void registerBodyProvider (IWailaDataProvider dataProvider, Class block); + public void registerTailProvider (IWailaDataProvider dataProvider, Class block); + + /* Entity text registration methods */ + public void registerHeadProvider (IWailaEntityProvider dataProvider, Class entity); + public void registerBodyProvider (IWailaEntityProvider dataProvider, Class entity); + public void registerTailProvider (IWailaEntityProvider dataProvider, Class entity); + public void registerOverrideEntityProvider (IWailaEntityProvider dataProvider, Class entity); + + /* FMP Providers */ + public void registerHeadProvider(IWailaFMPProvider dataProvider, String name); + public void registerBodyProvider(IWailaFMPProvider dataProvider, String name); + public void registerTailProvider(IWailaFMPProvider dataProvider, String name); + + /* The block decorators */ + @Deprecated + public void registerDecorator (IWailaBlockDecorator decorator, int blockID); + public void registerDecorator (IWailaBlockDecorator decorator, Class block); + public void registerDecorator (IWailaFMPDecorator decorator, String name); + + /* Selective NBT key syncing. Will register a key to sync over the network for the given class (block, te or ent). + * Accept * as a ending wildcard + * registerNBTKey("bob.*", MyBlock.class) + * registerNBTKey("data.life", MyEntity.class) + * registerNBTKey("*", MyTileEntity.class) will reproduce the full tag syncing from 1.4.5 + * */ + public void registerSyncedNBTKey(String key, Class target); + + /* UNUSED FOR NOW (Will be used for the ingame wiki */ + public void registerDocTextFile (String filename); + public void registerShortDataProvider (IWailaSummaryProvider dataProvider, Class item); +} diff --git a/apis/mcp/mobius/waila/api/IWailaSummaryProvider.java b/apis/mcp/mobius/waila/api/IWailaSummaryProvider.java new file mode 100644 index 0000000..f790649 --- /dev/null +++ b/apis/mcp/mobius/waila/api/IWailaSummaryProvider.java @@ -0,0 +1,21 @@ +package mcp.mobius.waila.api; + +import java.util.LinkedHashMap; + +import net.minecraft.item.ItemStack; + +public interface IWailaSummaryProvider { + /* This interface is used to control the display data in the description screen */ + + /* BASIC TOOLS & ITEMS DATA */ + //EnumToolMaterial getMaterial(ItemStack stack); + //String getMaterialName(ItemStack stack); + //String getEffectiveBlock(ItemStack stack); + //int getHarvestLevel(ItemStack stack); + //float getEfficiencyOnProperMaterial(ItemStack stack); + //int getEnchantability(ItemStack stack); + //int getDamageVsEntity(ItemStack stack); + //int getDurability(ItemStack stack); + + LinkedHashMap getSummary(ItemStack stack, LinkedHashMap currentSummary, IWailaConfigHandler config); +} diff --git a/apis/mcp/mobius/waila/api/SpecialChars.java b/apis/mcp/mobius/waila/api/SpecialChars.java new file mode 100644 index 0000000..5bd92a8 --- /dev/null +++ b/apis/mcp/mobius/waila/api/SpecialChars.java @@ -0,0 +1,40 @@ +package mcp.mobius.waila.api; + +public class SpecialChars { + + public static String MCStyle = "\u00A7"; + + public static String BLACK = MCStyle + "0"; + public static String DBLUE = MCStyle + "1"; + public static String DGREEN = MCStyle + "2"; + public static String DAQUA = MCStyle + "3"; + public static String DRED = MCStyle + "4"; + public static String DPURPLE = MCStyle + "5"; + public static String GOLD = MCStyle + "6"; + public static String GRAY = MCStyle + "7"; + public static String DGRAY = MCStyle + "8"; + public static String BLUE = MCStyle + "9"; + public static String GREEN = MCStyle + "a"; + public static String AQUA = MCStyle + "b"; + public static String RED = MCStyle + "c"; + public static String LPURPLE = MCStyle + "d"; + public static String YELLOW = MCStyle + "e"; + public static String WHITE = MCStyle + "f"; + + public static String OBF = MCStyle + "k"; + public static String BOLD = MCStyle + "l"; + public static String STRIKE = MCStyle + "m"; + public static String UNDER = MCStyle + "n"; + public static String ITALIC = MCStyle + "o"; + public static String RESET = MCStyle + "r"; + + public static String WailaStyle = "\u00A4"; + public static String WailaIcon = "\u00A5"; + public static String TAB = WailaStyle + WailaStyle +"a"; + public static String ALIGNRIGHT = WailaStyle + WailaStyle +"b"; + public static String ALIGNCENTER = WailaStyle + WailaStyle +"c"; + public static String HEART = WailaStyle + WailaIcon +"a"; + public static String HHEART = WailaStyle + WailaIcon +"b"; + public static String EHEART = WailaStyle + WailaIcon +"c"; + +} diff --git a/apis/mcp/mobius/waila/api/package-info.java b/apis/mcp/mobius/waila/api/package-info.java new file mode 100644 index 0000000..9b5e663 --- /dev/null +++ b/apis/mcp/mobius/waila/api/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion="1.0",owner="Waila",provides="WailaAPI") +package mcp.mobius.waila.api; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8c40103..d7b0dad 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ archivesBaseName = project.projectDir.name + "-mc" + project.minecraft.version sourceSets.main{ java { - srcDirs 'java' //set the source folder as the /src subfolder + srcDirs 'java', 'apis' //set the source folder as the /src subfolder } resources { srcDirs 'resources' //set the resources folder as the /resources subfolder diff --git a/java/squeek/wailaharvestlevels/ModWailaHarvestLevels.java b/java/squeek/wailaharvestlevels/ModWailaHarvestLevels.java new file mode 100644 index 0000000..31c252c --- /dev/null +++ b/java/squeek/wailaharvestlevels/ModWailaHarvestLevels.java @@ -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(); + } + } +} diff --git a/java/squeek/wailaharvestlevels/WailaHandler.java b/java/squeek/wailaharvestlevels/WailaHandler.java new file mode 100644 index 0000000..31b88fe --- /dev/null +++ b/java/squeek/wailaharvestlevels/WailaHandler.java @@ -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 getWailaHead(ItemStack itemStack, List toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config) + { + return toolTip; + } + + @Override + public List getWailaBody(ItemStack itemStack, List 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 harvestTypes = new ArrayList(); + 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 getWailaTail(ItemStack itemStack, List 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); + } +} \ No newline at end of file diff --git a/java/squeek/wailaharvestlevels/helpers/ColorHelper.java b/java/squeek/wailaharvestlevels/helpers/ColorHelper.java new file mode 100644 index 0000000..b3f446c --- /dev/null +++ b/java/squeek/wailaharvestlevels/helpers/ColorHelper.java @@ -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(); + } +} \ No newline at end of file diff --git a/java/squeek/wailaharvestlevels/helpers/KeyHelper.java b/java/squeek/wailaharvestlevels/helpers/KeyHelper.java new file mode 100644 index 0000000..4da1e69 --- /dev/null +++ b/java/squeek/wailaharvestlevels/helpers/KeyHelper.java @@ -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); + + } +} diff --git a/java/squeek/wailaharvestlevels/helpers/StringHelper.java b/java/squeek/wailaharvestlevels/helpers/StringHelper.java new file mode 100644 index 0000000..9b17b01 --- /dev/null +++ b/java/squeek/wailaharvestlevels/helpers/StringHelper.java @@ -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 localizationAlternatives = new HashMap(); + 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; + } +} diff --git a/java/squeek/wailaharvestlevels/helpers/ToolHelper.java b/java/squeek/wailaharvestlevels/helpers/ToolHelper.java new file mode 100644 index 0000000..bf0d40c --- /dev/null +++ b/java/squeek/wailaharvestlevels/helpers/ToolHelper.java @@ -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"); + } + +} diff --git a/java/squeek/wailaharvestlevels/proxy/ProxyIguanaTweaks.java b/java/squeek/wailaharvestlevels/proxy/ProxyIguanaTweaks.java new file mode 100644 index 0000000..1cd050d --- /dev/null +++ b/java/squeek/wailaharvestlevels/proxy/ProxyIguanaTweaks.java @@ -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 = ""; + + try + { + harvestLevelName = (String) proxyGetHarvestLevelName.invoke(IguanaTweaksTConstruct, num); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return harvestLevelName; + } +} diff --git a/resources/mcmod.info b/resources/mcmod.info new file mode 100644 index 0000000..7c1ad8e --- /dev/null +++ b/resources/mcmod.info @@ -0,0 +1,16 @@ +[ +{ + "modid": "WailaHarvestLevels", + "name": "Waila Harvest Levels", + "description": "An add-on for Waila that adds information about the required harvest level and effective tools for harvestable blocks.", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "", + "updateUrl": "", + "authors": ["squeek"], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] +} +]