mirror of
https://github.com/GTNewHorizons/WailaHarvestability.git
synced 2026-11-25 06:14:34 +00:00
Standardized formatting
This commit is contained in:
1 parent
83b3f6b885
commit
c025fbd6c4
10 files changed
+73
-73
No files matched your search
@@ -6,7 +6,7 @@ import net.minecraftforge.common.Configuration;
|
||||
public class Config
|
||||
{
|
||||
private static final String CATEGORY_MAIN = "Main";
|
||||
|
||||
|
||||
public static String MINIMAL_SEPARATOR_STRING;
|
||||
private static final String MINIMAL_SEPARATOR_STRING_NAME = "minimal.mode.separator";
|
||||
private static final String MINIMAL_SEPARATOR_STRING_DEFAULT = " : ";
|
||||
@@ -20,12 +20,12 @@ public class Config
|
||||
private static final String NOT_CURRENTLY_HARVESTABLE_STRING_NAME = "not.currently.harvestable.string";
|
||||
// for some reason \u2718 was getting translated as ? when compiled with gradle; no clue why but this seems to work
|
||||
private static final String NOT_CURRENTLY_HARVESTABLE_STRING_DEFAULT = String.valueOf(Character.toChars(0x2718));
|
||||
|
||||
|
||||
private static Configuration config;
|
||||
|
||||
public static void init( File file )
|
||||
|
||||
public static void init(File file)
|
||||
{
|
||||
config = new Configuration( file );
|
||||
config = new Configuration(file);
|
||||
|
||||
load();
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Config
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
|
||||
public static void save()
|
||||
{
|
||||
config.save();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ModWailaHarvestability
|
||||
{
|
||||
Config.init(event.getSuggestedConfigurationFile());
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent event)
|
||||
@@ -40,7 +40,7 @@ public class ModWailaHarvestability
|
||||
hasIguanaTweaks = true;
|
||||
ProxyIguanaTweaks.init();
|
||||
}
|
||||
|
||||
|
||||
ToolHelper.init();
|
||||
}
|
||||
}
|
||||
@@ -39,29 +39,29 @@ public class WailaHandler implements IWailaDataProvider
|
||||
{
|
||||
if (config.getConfig("harvestability.toolrequiredonly") && accessor.getBlock().blockMaterial.isToolNotRequired())
|
||||
return toolTip;
|
||||
|
||||
boolean isSneaking = accessor.getPlayer().isSneaking();
|
||||
|
||||
boolean isSneaking = accessor.getPlayer().isSneaking();
|
||||
boolean showHarvestLevel = config.getConfig("harvestability.harvestlevel") && (!config.getConfig("harvestability.harvestlevel.sneakingonly") || isSneaking);
|
||||
boolean showEffectiveTool = config.getConfig("harvestability.effectivetool") && (!config.getConfig("harvestability.effectivetool.sneakingonly") || isSneaking);
|
||||
boolean showCurrentlyHarvestable = config.getConfig("harvestability.currentlyharvestable") && (!config.getConfig("harvestability.currentlyharvestable.sneakingonly") || isSneaking);
|
||||
boolean showOresOnly = config.getConfig("harvestability.oresonly", false);
|
||||
boolean minimalLayout = config.getConfig("harvestability.minimal", false);
|
||||
boolean hideWhileHarvestable = config.getConfig("harvestability.unharvestableonly", false);
|
||||
|
||||
|
||||
if (showHarvestLevel || showEffectiveTool || showCurrentlyHarvestable)
|
||||
{
|
||||
if (showOresOnly && !OreHelper.isItemAnOre(itemStack))
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
String toolClasses[] = new String[] { "pickaxe", "shovel", "axe" };
|
||||
|
||||
String toolClasses[] = new String[]{"pickaxe", "shovel", "axe"};
|
||||
int harvestLevels[] = new int[toolClasses.length];
|
||||
boolean blockHasEffectiveTools = BlockHelper.getHarvestLevelsOf(accessor.getBlock(), accessor.getMetadata(), toolClasses, harvestLevels);
|
||||
|
||||
|
||||
if (!blockHasEffectiveTools)
|
||||
return toolTip;
|
||||
|
||||
|
||||
int harvestLevel = -1;
|
||||
String effectiveTool = "";
|
||||
int i = 0;
|
||||
@@ -75,12 +75,12 @@ public class WailaHandler implements IWailaDataProvider
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
boolean canHarvest = false;
|
||||
boolean isEffective = false;
|
||||
boolean isAboveMinHarvestLevel = false;
|
||||
boolean isHoldingTinkersTool = false;
|
||||
|
||||
|
||||
ItemStack itemHeld = accessor.getPlayer().getHeldItem();
|
||||
if (itemHeld != null)
|
||||
{
|
||||
@@ -89,30 +89,30 @@ public class WailaHandler implements IWailaDataProvider
|
||||
isAboveMinHarvestLevel = (showCurrentlyHarvestable || showHarvestLevel) && ToolHelper.canToolHarvestLevel(itemHeld, accessor.getBlock(), accessor.getMetadata(), harvestLevel);
|
||||
isEffective = showEffectiveTool && ToolHelper.isToolEffectiveAgainst(itemHeld, accessor.getBlock(), accessor.getMetadata(), effectiveTool);
|
||||
}
|
||||
|
||||
|
||||
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel) || (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(accessor.getBlock(), accessor.getPlayer(), accessor.getMetadata()));
|
||||
|
||||
|
||||
if (hideWhileHarvestable && isCurrentlyHarvestable)
|
||||
return toolTip;
|
||||
|
||||
|
||||
List<String> stringParts = new ArrayList<String>();
|
||||
|
||||
|
||||
if (showCurrentlyHarvestable)
|
||||
stringParts.add(ColorHelper.getBooleanColor(isCurrentlyHarvestable) + (isCurrentlyHarvestable ? Config.CURRENTLY_HARVESTABLE_STRING : Config.NOT_CURRENTLY_HARVESTABLE_STRING) + (!minimalLayout ? EnumChatFormatting.RESET + " Currently Harvestable" : ""));
|
||||
if (harvestLevel != -1 && showEffectiveTool)
|
||||
stringParts.add((!minimalLayout ? "Effective Tool : " : "") + ColorHelper.getBooleanColor(isEffective && (!isHoldingTinkersTool || canHarvest), isHoldingTinkersTool && isEffective && !canHarvest) + StatCollector.translateToLocal("harvestability.toolclass." + effectiveTool));
|
||||
if (harvestLevel >= 1 && showHarvestLevel)
|
||||
stringParts.add((!minimalLayout ? "Harvest Level : " : "") + ColorHelper.getBooleanColor(isAboveMinHarvestLevel && canHarvest) + StringHelper.stripFormatting(StringHelper.getHarvestLevelName(harvestLevel)));
|
||||
|
||||
if (!stringParts.isEmpty())
|
||||
{
|
||||
if (minimalLayout)
|
||||
toolTip.add(StringHelper.concatenateStringList(stringParts, EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
|
||||
else
|
||||
toolTip.addAll(stringParts);
|
||||
}
|
||||
stringParts.add(ColorHelper.getBooleanColor(isCurrentlyHarvestable) + (isCurrentlyHarvestable ? Config.CURRENTLY_HARVESTABLE_STRING : Config.NOT_CURRENTLY_HARVESTABLE_STRING) + (!minimalLayout ? EnumChatFormatting.RESET + " Currently Harvestable" : ""));
|
||||
if (harvestLevel != -1 && showEffectiveTool)
|
||||
stringParts.add((!minimalLayout ? "Effective Tool : " : "") + ColorHelper.getBooleanColor(isEffective && (!isHoldingTinkersTool || canHarvest), isHoldingTinkersTool && isEffective && !canHarvest) + StatCollector.translateToLocal("harvestability.toolclass." + effectiveTool));
|
||||
if (harvestLevel >= 1 && showHarvestLevel)
|
||||
stringParts.add((!minimalLayout ? "Harvest Level : " : "") + ColorHelper.getBooleanColor(isAboveMinHarvestLevel && canHarvest) + StringHelper.stripFormatting(StringHelper.getHarvestLevelName(harvestLevel)));
|
||||
|
||||
if (!stringParts.isEmpty())
|
||||
{
|
||||
if (minimalLayout)
|
||||
toolTip.add(StringHelper.concatenateStringList(stringParts, EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
|
||||
else
|
||||
toolTip.addAll(stringParts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
@@ -140,14 +140,14 @@ public class WailaHandler implements IWailaDataProvider
|
||||
public static void callbackRegister(IWailaRegistrar registrar)
|
||||
{
|
||||
WailaHandler instance = new WailaHandler();
|
||||
|
||||
|
||||
for (Map.Entry<String, Boolean> entry : configOptions.entrySet())
|
||||
{
|
||||
// hacky way to set default values to anything but true
|
||||
ConfigHandler.instance().getConfig(entry.getKey(), entry.getValue());
|
||||
registrar.addConfig("Harvestability", entry.getKey(), "option."+entry.getKey());
|
||||
registrar.addConfig("Harvestability", entry.getKey(), "option." + entry.getKey());
|
||||
}
|
||||
|
||||
|
||||
registrar.registerBodyProvider(instance, Block.class);
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,10 @@ public class BlockHelper
|
||||
for (String toolClass : toolClasses)
|
||||
{
|
||||
harvestLevels[i] = MinecraftForge.getBlockHarvestLevel(block, metadata, toolClass);
|
||||
|
||||
|
||||
if (harvestLevels[i] != -1)
|
||||
hasEffectiveTools = true;
|
||||
|
||||
|
||||
i++;
|
||||
}
|
||||
return hasEffectiveTools;
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ColorHelper
|
||||
EnumChatFormatting.GREEN,
|
||||
EnumChatFormatting.AQUA
|
||||
};
|
||||
|
||||
|
||||
private static final EnumChatFormatting booleanColorRange[] = {
|
||||
EnumChatFormatting.DARK_RED,
|
||||
EnumChatFormatting.RED,
|
||||
@@ -38,7 +38,7 @@ public class ColorHelper
|
||||
{
|
||||
return getBooleanColor(val, false);
|
||||
}
|
||||
|
||||
|
||||
public static String getBooleanColor(boolean val, boolean modified)
|
||||
{
|
||||
return booleanColorRange[(val ? 2 : 0) + (modified ? 1 : 0)].toString();
|
||||
|
||||
@@ -11,13 +11,12 @@ public class KeyHelper
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,27 +10,27 @@ public class OreHelper
|
||||
{
|
||||
return isBlockAnOre(block, 0);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isBlockAnOre(Block block, int metadata)
|
||||
{
|
||||
return isItemAnOre(new ItemStack(block, 1, metadata));
|
||||
}
|
||||
|
||||
|
||||
public static boolean isItemAnOre(ItemStack itemStack)
|
||||
{
|
||||
// check the ore dictionary to see if it starts with "ore"
|
||||
int oreID = -1;
|
||||
if ((oreID = OreDictionary.getOreID(itemStack)) != -1 && OreDictionary.getOreName(oreID).startsWith("ore"))
|
||||
return true;
|
||||
|
||||
|
||||
// ore in the display name (but not part of another word)
|
||||
if (itemStack.getDisplayName().matches(".*(^|\\s)([oO]re)($|\\s).*"))
|
||||
return true;
|
||||
|
||||
|
||||
// ore as the start of the unlocalized name
|
||||
if (itemStack.getUnlocalizedName().startsWith("ore"))
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ public class StringHelper
|
||||
{
|
||||
if (ModWailaHarvestability.hasIguanaTweaks)
|
||||
return ProxyIguanaTweaks.getHarvestLevelName(num);
|
||||
|
||||
|
||||
String unlocalized = "gui.partcrafter.mining" + (num + 1);
|
||||
String localized = StringHelper.getLocalizedString(unlocalized);
|
||||
if (!unlocalized.equals(localized))
|
||||
@@ -45,7 +45,7 @@ public class StringHelper
|
||||
{
|
||||
if (unlocalized.equals("gui.partcrafter.mining6"))
|
||||
return localizationAlternatives.get(unlocalized);
|
||||
|
||||
|
||||
String localized = StatCollector.translateToLocal(unlocalized);
|
||||
if (localized.equals(unlocalized))
|
||||
{
|
||||
@@ -61,13 +61,14 @@ public class StringHelper
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String sep = "";
|
||||
for(String s: strings) {
|
||||
for (String s : strings)
|
||||
{
|
||||
sb.append(sep).append(s);
|
||||
sep = separator;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String stripFormatting(String str)
|
||||
{
|
||||
return EnumChatFormatting.func_110646_a(str);
|
||||
|
||||
@@ -20,10 +20,10 @@ public class ToolHelper
|
||||
private static Method getHarvestType = null;
|
||||
private static Method getSecondHarvestType = null;
|
||||
public static boolean tinkersConstructLoaded = false;
|
||||
|
||||
|
||||
// forge
|
||||
static HashMap<Item, List<Object>> toolClasses = null;
|
||||
|
||||
static HashMap<Item, List<Object>> toolClasses = null;
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public static void init()
|
||||
{
|
||||
@@ -31,13 +31,13 @@ public class ToolHelper
|
||||
{
|
||||
Field toolClassesField = ForgeHooks.class.getDeclaredField("toolClasses");
|
||||
toolClassesField.setAccessible(true);
|
||||
toolClasses = (HashMap<Item, List<Object>>)(toolClassesField.get(null));
|
||||
toolClasses = (HashMap<Item, List<Object>>) (toolClassesField.get(null));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
if (Loader.isModLoaded("TConstruct"))
|
||||
{
|
||||
try
|
||||
@@ -83,18 +83,18 @@ public class ToolHelper
|
||||
{
|
||||
return toolTag.getInteger("HarvestLevel2");
|
||||
}
|
||||
|
||||
|
||||
public static String getToolClassOf(Item tool)
|
||||
{
|
||||
List<Object> toolClass = toolClasses.get(tool);
|
||||
return toolClass != null ? (String) toolClass.get(0) : null;
|
||||
List<Object> toolClass = toolClasses.get(tool);
|
||||
return toolClass != null ? (String) toolClass.get(0) : null;
|
||||
}
|
||||
|
||||
|
||||
public static String getToolClassOf(ItemStack tool)
|
||||
{
|
||||
return getToolClassOf(tool.getItem());
|
||||
return getToolClassOf(tool.getItem());
|
||||
}
|
||||
|
||||
|
||||
public static boolean isToolEffectiveAgainst(ItemStack tool, Block block, int metadata, String effectiveToolClass)
|
||||
{
|
||||
if (tinkersConstructLoaded && HarvestTool.isInstance(tool.getItem()))
|
||||
@@ -110,7 +110,7 @@ public class ToolHelper
|
||||
e.printStackTrace();
|
||||
tinkersConstructLoaded = false;
|
||||
}
|
||||
|
||||
|
||||
if (DualHarvestTool.isInstance(item))
|
||||
{
|
||||
try
|
||||
@@ -123,7 +123,7 @@ public class ToolHelper
|
||||
tinkersConstructLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return harvestTypes.contains(effectiveToolClass);
|
||||
}
|
||||
String toolClass = null;
|
||||
@@ -133,17 +133,17 @@ public class ToolHelper
|
||||
public static boolean canToolHarvestLevel(ItemStack tool, Block block, int metadata, int harvestLevel)
|
||||
{
|
||||
boolean canTinkersToolHarvestBlock = false;
|
||||
|
||||
|
||||
NBTTagCompound toolTag = ToolHelper.getToolTag(tool);
|
||||
if (toolTag != null)
|
||||
{
|
||||
int toolHarvestLevel = Math.max(ToolHelper.getPrimaryHarvestLevel(toolTag), ToolHelper.getSecondaryHarvestLevel(toolTag));
|
||||
canTinkersToolHarvestBlock = toolHarvestLevel >= harvestLevel;
|
||||
}
|
||||
|
||||
|
||||
return canTinkersToolHarvestBlock || ForgeHooks.canToolHarvestBlock(block, metadata, tool);
|
||||
}
|
||||
|
||||
|
||||
public static boolean canToolHarvestBlock(ItemStack tool, Block block, int metadata)
|
||||
{
|
||||
return block.blockMaterial.isToolNotRequired() || tool.canHarvestBlock(block);
|
||||
|
||||
@@ -6,7 +6,7 @@ public class ProxyIguanaTweaks
|
||||
{
|
||||
private static Class<?> IguanaTweaksTConstruct = null;
|
||||
private static Method proxyGetHarvestLevelName;
|
||||
|
||||
|
||||
public static void init()
|
||||
{
|
||||
try
|
||||
@@ -19,11 +19,11 @@ public class ProxyIguanaTweaks
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getHarvestLevelName(int num)
|
||||
{
|
||||
String harvestLevelName = "<Unknown>";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
harvestLevelName = (String) proxyGetHarvestLevelName.invoke(IguanaTweaksTConstruct, num);
|
||||
@@ -32,7 +32,7 @@ public class ProxyIguanaTweaks
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return harvestLevelName;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user