Merge remote-tracking branch 'origin/master' into 1.7.x

Conflicts:
	java/squeek/wailaharvestability/WailaHandler.java
	java/squeek/wailaharvestability/helpers/BlockHelper.java
This commit is contained in:
squeek committed 2014-08-25 23:36:28 -07:00
commit de602fb320
11 files changed
+233 -50

No files matched your search

+12 -4
View File
@@ -13,13 +13,19 @@ public class Config
public static String CURRENTLY_HARVESTABLE_STRING;
private static final String CURRENTLY_HARVESTABLE_STRING_NAME = "is.currently.harvestable.string";
// for some reason \u2714 was getting translated as ? when compiled with gradle; no clue why but this seems to work
private static final String CURRENTLY_HARVESTABLE_STRING_DEFAULT = String.valueOf(Character.toChars(0x2714));
private static final String CURRENTLY_HARVESTABLE_STRING_DEFAULT = "\u2714";
public static String NOT_CURRENTLY_HARVESTABLE_STRING;
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 final String NOT_CURRENTLY_HARVESTABLE_STRING_DEFAULT = "\u2718";
public static String SHEARABILITY_STRING;
private static final String SHEARABILITY_STRING_NAME = "shearability.string";
private static final String SHEARABILITY_STRING_DEFAULT = "\u2702";
public static String SILK_TOUCHABILITY_STRING;
private static final String SILK_TOUCHABILITY_STRING_NAME = "silk.touchability.string";
private static final String SILK_TOUCHABILITY_STRING_DEFAULT = "\u2712";
private static Configuration config;
@@ -32,6 +38,8 @@ public class Config
MINIMAL_SEPARATOR_STRING = config.get(CATEGORY_MAIN, MINIMAL_SEPARATOR_STRING_NAME, MINIMAL_SEPARATOR_STRING_DEFAULT).getString();
CURRENTLY_HARVESTABLE_STRING = config.get(CATEGORY_MAIN, CURRENTLY_HARVESTABLE_STRING_NAME, CURRENTLY_HARVESTABLE_STRING_DEFAULT).getString();
NOT_CURRENTLY_HARVESTABLE_STRING = config.get(CATEGORY_MAIN, NOT_CURRENTLY_HARVESTABLE_STRING_NAME, NOT_CURRENTLY_HARVESTABLE_STRING_DEFAULT).getString();
SHEARABILITY_STRING = config.get(CATEGORY_MAIN, SHEARABILITY_STRING_NAME, SHEARABILITY_STRING_DEFAULT).getString();
SILK_TOUCHABILITY_STRING = config.get(CATEGORY_MAIN, SILK_TOUCHABILITY_STRING_NAME, SILK_TOUCHABILITY_STRING_DEFAULT).getString();
save();
}
@@ -2,6 +2,7 @@ package squeek.wailaharvestability;
import squeek.wailaharvestability.helpers.ToolHelper;
import squeek.wailaharvestability.proxy.ProxyIguanaTweaks;
import squeek.wailaharvestability.setup.MissingHarvestInfo;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
@@ -28,6 +29,7 @@ public class ModWailaHarvestability
@EventHandler
public void init(FMLInitializationEvent event)
{
MissingHarvestInfo.init();
FMLInterModComms.sendMessage("Waila", "register", "squeek.wailaharvestability.WailaHandler.callbackRegister");
}
+111 -33
View File
@@ -4,21 +4,30 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import squeek.wailaharvestability.helpers.ColorHelper;
import squeek.wailaharvestability.helpers.OreHelper;
import squeek.wailaharvestability.helpers.StringHelper;
import squeek.wailaharvestability.helpers.ToolHelper;
import java.util.Random;
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 mcp.mobius.waila.api.impl.ConfigHandler;
import net.minecraft.block.Block;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IShearable;
import squeek.wailaharvestability.helpers.BlockHelper;
import squeek.wailaharvestability.helpers.ColorHelper;
import squeek.wailaharvestability.helpers.OreHelper;
import squeek.wailaharvestability.helpers.StringHelper;
import squeek.wailaharvestability.helpers.ToolHelper;
public class WailaHandler implements IWailaDataProvider
{
@@ -39,6 +48,7 @@ public class WailaHandler implements IWailaDataProvider
{
Block block = accessor.getBlock();
int meta = accessor.getMetadata();
EntityPlayer player = accessor.getPlayer();
// for disguised blocks
if (itemStack.getItem() instanceof ItemBlock)
@@ -46,70 +56,134 @@ public class WailaHandler implements IWailaDataProvider
block = Block.getBlockFromItem(itemStack.getItem());
meta = itemStack.getItemDamage();
}
if (config.getConfig("harvestability.toolrequiredonly") && block.getMaterial().isToolNotRequired())
return toolTip;
boolean isSneaking = accessor.getPlayer().isSneaking();
boolean minimalLayout = config.getConfig("harvestability.minimal", false);
List<String> stringParts = new ArrayList<String>();
getHarvestability(stringParts, player, block, meta, accessor.getPosition(), config, minimalLayout);
if (!stringParts.isEmpty())
{
if (minimalLayout)
toolTip.add(StringHelper.concatenateStringList(stringParts, EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
else
toolTip.addAll(stringParts);
}
return toolTip;
}
public void getHarvestability(List<String> stringList, EntityPlayer player, Block block, int meta, MovingObjectPosition position, IWailaConfigHandler config, boolean minimalLayout)
{
boolean isSneaking = player.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);
boolean showOresOnly = config.getConfig("harvestability.oresonly", false);
boolean toolRequiredOnly = config.getConfig("harvestability.toolrequiredonly");
if (showHarvestLevel || showEffectiveTool || showCurrentlyHarvestable)
{
if (showOresOnly && !OreHelper.isItemAnOre(itemStack))
if (showOresOnly && !OreHelper.isBlockAnOre(block, meta))
{
return toolTip;
return;
}
if (BlockHelper.isBlockUnbreakable(block, player.worldObj, position.blockX, position.blockY, position.blockZ))
{
String unbreakableString = ColorHelper.getBooleanColor(false) + Config.NOT_CURRENTLY_HARVESTABLE_STRING + (!minimalLayout ? EnumChatFormatting.RESET + StatCollector.translateToLocal("wailaharvestability.harvestable") : "");
stringList.add(unbreakableString);
return;
}
// needed to stop array index out of bounds exceptions on mob spawners
// block.getHarvestLevel/getHarvestTool are only 16 elements big
if (meta >= 16)
meta = 0;
int harvestLevel = block.getHarvestLevel(meta);
String effectiveTool = block.getHarvestTool(meta);
String effectiveTool = BlockHelper.getEffectiveToolOf(player.worldObj, position.blockX, position.blockY, position.blockZ, block, meta);
if (effectiveTool != null && harvestLevel < 0)
harvestLevel = 0;
boolean blockHasEffectiveTools = harvestLevel >= 0 && effectiveTool != null;
if (!blockHasEffectiveTools)
return toolTip;
String shearability = getShearabilityString(player, block, meta, position, config);
String silkTouchability = getSilkTouchabilityString(player, block, meta, position, config);
if (toolRequiredOnly && block.getMaterial().isToolNotRequired() && !blockHasEffectiveTools && shearability.isEmpty() && silkTouchability.isEmpty())
return;
boolean canHarvest = false;
boolean isEffective = false;
boolean isAboveMinHarvestLevel = false;
boolean isHoldingTinkersTool = false;
ItemStack itemHeld = accessor.getPlayer().getHeldItem();
ItemStack itemHeld = player.getHeldItem();
if (itemHeld != null)
{
isHoldingTinkersTool = ToolHelper.hasToolTag(itemHeld);
canHarvest = ToolHelper.canToolHarvestBlock(itemHeld, block, meta) || (!isHoldingTinkersTool && block.canHarvestBlock(accessor.getPlayer(), meta));
canHarvest = ToolHelper.canToolHarvestBlock(itemHeld, block, meta) || (!isHoldingTinkersTool && block.canHarvestBlock(player, meta));
isAboveMinHarvestLevel = (showCurrentlyHarvestable || showHarvestLevel) && ToolHelper.canToolHarvestLevel(itemHeld, block, meta, harvestLevel);
isEffective = showEffectiveTool && ToolHelper.isToolEffectiveAgainst(itemHeld, block, meta, effectiveTool);
}
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel) || (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(block, accessor.getPlayer(), meta));
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel) || (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(block, player, meta));
if (hideWhileHarvestable && isCurrentlyHarvestable)
return toolTip;
return;
List<String> stringParts = new ArrayList<String>();
String currentlyHarvestable = showCurrentlyHarvestable ? ColorHelper.getBooleanColor(isCurrentlyHarvestable) + (isCurrentlyHarvestable ? Config.CURRENTLY_HARVESTABLE_STRING : Config.NOT_CURRENTLY_HARVESTABLE_STRING) + (!minimalLayout ? EnumChatFormatting.RESET + StatCollector.translateToLocal("wailaharvestability.currentlyharvestable") : "") : "";
if (showCurrentlyHarvestable)
stringParts.add(ColorHelper.getBooleanColor(isCurrentlyHarvestable) + (isCurrentlyHarvestable ? Config.CURRENTLY_HARVESTABLE_STRING : Config.NOT_CURRENTLY_HARVESTABLE_STRING) + (!minimalLayout ? EnumChatFormatting.RESET + StatCollector.translateToLocal("wailaharvestability.currentlyharvestable") : ""));
if (harvestLevel != -1 && showEffectiveTool)
stringParts.add((!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.effectivetool") : "") + ColorHelper.getBooleanColor(isEffective && (!isHoldingTinkersTool || canHarvest), isHoldingTinkersTool && isEffective && !canHarvest) + StatCollector.translateToLocal("wailaharvestability.toolclass." + effectiveTool));
if (harvestLevel >= 1 && showHarvestLevel)
stringParts.add((!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.harvestlevel") : "") + ColorHelper.getBooleanColor(isAboveMinHarvestLevel && canHarvest) + StringHelper.stripFormatting(StringHelper.getHarvestLevelName(harvestLevel)));
if (!stringParts.isEmpty())
if (!currentlyHarvestable.isEmpty() || !shearability.isEmpty() || !silkTouchability.isEmpty())
{
if (minimalLayout)
toolTip.add(StringHelper.concatenateStringList(stringParts, EnumChatFormatting.RESET + Config.MINIMAL_SEPARATOR_STRING));
String separator = (!shearability.isEmpty() || !silkTouchability.isEmpty() ? " " : "");
stringList.add(currentlyHarvestable + separator + silkTouchability + (!silkTouchability.isEmpty() ? separator : "") + shearability);
}
if (harvestLevel != -1 && showEffectiveTool)
{
String effectiveToolString;
if (StatCollector.canTranslate("wailaharvestability.toolclass." + effectiveTool))
effectiveToolString = StatCollector.translateToLocal("wailaharvestability.toolclass." + effectiveTool);
else
toolTip.addAll(stringParts);
effectiveToolString = effectiveTool.substring(0, 1).toUpperCase() + effectiveTool.substring(1);
stringList.add((!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.effectivetool") : "") + ColorHelper.getBooleanColor(isEffective && (!isHoldingTinkersTool || canHarvest), isHoldingTinkersTool && isEffective && !canHarvest) + effectiveToolString);
}
if (harvestLevel >= 1 && showHarvestLevel)
stringList.add((!minimalLayout ? StatCollector.translateToLocal("wailaharvestability.harvestlevel") : "") + ColorHelper.getBooleanColor(isAboveMinHarvestLevel && canHarvest) + StringHelper.stripFormatting(StringHelper.getHarvestLevelName(harvestLevel)));
}
}
public String getShearabilityString(EntityPlayer player, Block block, int meta, MovingObjectPosition position, IWailaConfigHandler config)
{
boolean isSneaking = player.isSneaking();
boolean showShearability = config.getConfig("harvestability.shearability") && (!config.getConfig("harvestability.shearability.sneakingonly") || isSneaking);
if (showShearability && (block instanceof IShearable || block == Blocks.deadbush || (block == Blocks.double_plant && block.getItemDropped(meta, new Random(), 0) == null)))
{
ItemStack itemHeld = player.getHeldItem();
boolean isHoldingShears = itemHeld != null && itemHeld.getItem() instanceof ItemShears;
boolean isShearable = isHoldingShears && ((IShearable) block).isShearable(itemHeld, player.worldObj, position.blockX, position.blockY, position.blockZ);
return ColorHelper.getBooleanColor(isShearable, !isShearable && isHoldingShears) + Config.SHEARABILITY_STRING;
}
return "";
}
public String getSilkTouchabilityString(EntityPlayer player, Block block, int meta, MovingObjectPosition position, IWailaConfigHandler config)
{
boolean isSneaking = player.isSneaking();
boolean showSilkTouchability = config.getConfig("harvestability.silktouchability") && (!config.getConfig("harvestability.silktouchability.sneakingonly") || isSneaking);
if (showSilkTouchability && block.canSilkHarvest(player.worldObj, player, position.blockX, position.blockY, position.blockZ, meta))
{
boolean silkTouchMatters = block.getItemDropped(meta, new Random(), 0) != Item.getItemFromBlock(block) || block.quantityDropped(new Random()) <= 0;
if (silkTouchMatters)
{
boolean hasSilkTouch = EnchantmentHelper.getSilkTouchModifier(player);
return ColorHelper.getBooleanColor(hasSilkTouch) + Config.SILK_TOUCHABILITY_STRING;
}
}
return toolTip;
return "";
}
@Override
@@ -131,6 +205,10 @@ public class WailaHandler implements IWailaDataProvider
configOptions.put("harvestability.minimal", false);
configOptions.put("harvestability.unharvestableonly", false);
configOptions.put("harvestability.toolrequiredonly", true);
configOptions.put("harvestability.shearability", true);
configOptions.put("harvestability.shearability.sneakingonly", true);
configOptions.put("harvestability.silktouchability", true);
configOptions.put("harvestability.silktouchability.sneakingonly", true);
}
public static void callbackRegister(IWailaRegistrar registrar)
@@ -1,6 +1,47 @@
package squeek.wailaharvestability.helpers;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemTool;
import net.minecraft.world.World;
public class BlockHelper
{
private static final HashMap<String, ItemStack> testTools = new HashMap<String, ItemStack>();
static
{
testTools.put("pickaxe", new ItemStack(Items.wooden_pickaxe));
testTools.put("shovel", new ItemStack(Items.wooden_shovel));
testTools.put("axe", new ItemStack(Items.wooden_axe));
}
public static String getEffectiveToolOf(World world, int x, int y, int z, Block block, int metadata)
{
String effectiveTool = block.getHarvestTool(metadata);
if (effectiveTool == null)
{
float hardness = block.getBlockHardness(world, x, y, z);
if (hardness > 0f)
{
for (Map.Entry<String, ItemStack> testToolEntry : testTools.entrySet())
{
ItemStack testTool = testToolEntry.getValue();
if (testTool != null && testTool.getItem() instanceof ItemTool && testTool.func_150997_a(block) >= ((ItemTool) testTool.getItem()).func_150913_i().getEfficiencyOnProperMaterial())
{
effectiveTool = testToolEntry.getKey();
break;
}
}
}
}
return effectiveTool;
}
public static boolean isBlockUnbreakable(Block block, World world, int x, int y, int z)
{
return block.getBlockHardness(world, x, y, z) == -1.0f;
}
}
@@ -0,0 +1,16 @@
package squeek.wailaharvestability.setup;
import net.minecraft.init.Blocks;
public class MissingHarvestInfo
{
public static void init()
{
vanilla();
}
public static void vanilla()
{
Blocks.web.setHarvestLevel("sword", 0);
}
}