mirror of
https://github.com/GTNewHorizons/WailaHarvestability.git
synced 2026-11-25 06:14:34 +00:00
Initial update to 1.8
This commit is contained in:
1 parent
82289c36a5
commit
583fcd13c8
23 files changed
+137
-613
No files matched your search
@@ -1,17 +1,14 @@
|
||||
package squeek.wailaharvestability;
|
||||
|
||||
import squeek.wailaharvestability.helpers.ToolHelper;
|
||||
import squeek.wailaharvestability.proxy.ProxyIguanaTweaks;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import squeek.wailaharvestability.setup.MissingHarvestInfo;
|
||||
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.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Mod(modid = ModInfo.MODID, version = ModInfo.VERSION, dependencies = "after:TConstruct;after:ExtraTiC;after:TSteelworks;after:Mariculture", acceptableRemoteVersions = "*")
|
||||
public class ModWailaHarvestability
|
||||
@@ -39,12 +36,5 @@ public class ModWailaHarvestability
|
||||
@EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event)
|
||||
{
|
||||
if (Loader.isModLoaded("IguanaTweaksTConstruct"))
|
||||
{
|
||||
hasIguanaTweaks = true;
|
||||
ProxyIguanaTweaks.init();
|
||||
}
|
||||
|
||||
ToolHelper.init();
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,14 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import mcp.mobius.waila.api.ITaggedList.ITipList;
|
||||
import mcp.mobius.waila.api.IWailaConfigHandler;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessor;
|
||||
import mcp.mobius.waila.api.IWailaDataAccessorServer;
|
||||
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.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -18,8 +20,10 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemShears;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockPos;
|
||||
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;
|
||||
@@ -39,18 +43,12 @@ public class WailaHandler implements IWailaDataProvider
|
||||
}
|
||||
|
||||
@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)
|
||||
public ITipList getWailaBody(ItemStack itemStack, ITipList toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
Block block = accessor.getBlock();
|
||||
int meta = accessor.getMetadata();
|
||||
IBlockState blockState = accessor.getBlockState();
|
||||
|
||||
if (ProxyCreativeBlocks.isCreativeBlock(block, meta))
|
||||
if (ProxyCreativeBlocks.isCreativeBlock(block, accessor.getMetadata()))
|
||||
return toolTip;
|
||||
|
||||
EntityPlayer player = accessor.getPlayer();
|
||||
@@ -59,14 +57,14 @@ public class WailaHandler implements IWailaDataProvider
|
||||
if (itemStack.getItem() instanceof ItemBlock)
|
||||
{
|
||||
block = Block.getBlockFromItem(itemStack.getItem());
|
||||
meta = itemStack.getItemDamage();
|
||||
blockState = block.getStateFromMeta(itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
boolean minimalLayout = config.getConfig("harvestability.minimal", false);
|
||||
|
||||
|
||||
List<String> stringParts = new ArrayList<String>();
|
||||
getHarvestability(stringParts, player, block, meta, accessor.getPosition(), config, minimalLayout);
|
||||
|
||||
getHarvestability(stringParts, player, block, blockState, accessor.getPosition(), config, minimalLayout);
|
||||
|
||||
if (!stringParts.isEmpty())
|
||||
{
|
||||
if (minimalLayout)
|
||||
@@ -74,11 +72,11 @@ public class WailaHandler implements IWailaDataProvider
|
||||
else
|
||||
toolTip.addAll(stringParts);
|
||||
}
|
||||
|
||||
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
public void getHarvestability(List<String> stringList, EntityPlayer player, Block block, int meta, MovingObjectPosition position, IWailaConfigHandler config, boolean minimalLayout)
|
||||
|
||||
public void getHarvestability(List<String> stringList, EntityPlayer player, Block block, IBlockState blockState, BlockPos position, IWailaConfigHandler config, boolean minimalLayout)
|
||||
{
|
||||
boolean isSneaking = player.isSneaking();
|
||||
boolean showHarvestLevel = config.getConfig("harvestability.harvestlevel") && (!config.getConfig("harvestability.harvestlevel.sneakingonly") || isSneaking);
|
||||
@@ -90,31 +88,26 @@ public class WailaHandler implements IWailaDataProvider
|
||||
|
||||
if (showHarvestLevel || showEffectiveTool || showCurrentlyHarvestable)
|
||||
{
|
||||
if (showOresOnly && !OreHelper.isBlockAnOre(block, meta))
|
||||
if (showOresOnly && !OreHelper.isBlockAnOre(block, block.getMetaFromState(blockState)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (BlockHelper.isBlockUnbreakable(block, player.worldObj, position.blockX, position.blockY, position.blockZ))
|
||||
if (BlockHelper.isBlockUnbreakable(block, player.worldObj, position))
|
||||
{
|
||||
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 = BlockHelper.getEffectiveToolOf(player.worldObj, position.blockX, position.blockY, position.blockZ, block, meta);
|
||||
int harvestLevel = block.getHarvestLevel(blockState);
|
||||
String effectiveTool = BlockHelper.getEffectiveToolOf(player.worldObj, position, block, blockState);
|
||||
if (effectiveTool != null && harvestLevel < 0)
|
||||
harvestLevel = 0;
|
||||
boolean blockHasEffectiveTools = harvestLevel >= 0 && effectiveTool != null;
|
||||
|
||||
String shearability = getShearabilityString(player, block, meta, position, config);
|
||||
String silkTouchability = getSilkTouchabilityString(player, block, meta, position, config);
|
||||
String shearability = getShearabilityString(player, block, blockState, position, config);
|
||||
String silkTouchability = getSilkTouchabilityString(player, block, blockState, position, config);
|
||||
|
||||
if (toolRequiredOnly && block.getMaterial().isToolNotRequired() && !blockHasEffectiveTools && shearability.isEmpty() && silkTouchability.isEmpty())
|
||||
return;
|
||||
@@ -127,13 +120,12 @@ public class WailaHandler implements IWailaDataProvider
|
||||
ItemStack itemHeld = player.getHeldItem();
|
||||
if (itemHeld != null)
|
||||
{
|
||||
isHoldingTinkersTool = ToolHelper.hasToolTag(itemHeld);
|
||||
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);
|
||||
canHarvest = ToolHelper.canToolHarvestBlock(itemHeld, block, blockState) || (!isHoldingTinkersTool && block.canHarvestBlock(player.worldObj, position, player));
|
||||
isAboveMinHarvestLevel = (showCurrentlyHarvestable || showHarvestLevel) && ToolHelper.canToolHarvestLevel(itemHeld, player.worldObj, position, harvestLevel);
|
||||
isEffective = showEffectiveTool && ToolHelper.isToolEffectiveAgainst(itemHeld, player.worldObj, position, block, effectiveTool);
|
||||
}
|
||||
|
||||
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel) || (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(block, player, meta));
|
||||
boolean isCurrentlyHarvestable = (canHarvest && isAboveMinHarvestLevel) || (!isHoldingTinkersTool && ForgeHooks.canHarvestBlock(block, player, player.worldObj, position));
|
||||
|
||||
if (hideWhileHarvestable && isCurrentlyHarvestable)
|
||||
return;
|
||||
@@ -145,7 +137,7 @@ public class WailaHandler implements IWailaDataProvider
|
||||
String separator = (!shearability.isEmpty() || !silkTouchability.isEmpty() ? " " : "");
|
||||
stringList.add(currentlyHarvestable + separator + silkTouchability + (!silkTouchability.isEmpty() ? separator : "") + shearability);
|
||||
}
|
||||
if (harvestLevel != -1 && showEffectiveTool)
|
||||
if (harvestLevel != -1 && showEffectiveTool && effectiveTool != null)
|
||||
{
|
||||
String effectiveToolString;
|
||||
if (StatCollector.canTranslate("wailaharvestability.toolclass." + effectiveTool))
|
||||
@@ -158,30 +150,30 @@ public class WailaHandler implements IWailaDataProvider
|
||||
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)
|
||||
|
||||
public String getShearabilityString(EntityPlayer player, Block block, IBlockState blockState, BlockPos 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)))
|
||||
|
||||
if (showShearability && (block instanceof IShearable || block == Blocks.deadbush || (block == Blocks.double_plant && block.getItemDropped(blockState, 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);
|
||||
boolean isShearable = isHoldingShears && ((IShearable) block).isShearable(itemHeld, player.worldObj, position);
|
||||
return ColorHelper.getBooleanColor(isShearable, !isShearable && isHoldingShears) + Config.SHEARABILITY_STRING;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getSilkTouchabilityString(EntityPlayer player, Block block, int meta, MovingObjectPosition position, IWailaConfigHandler config)
|
||||
public String getSilkTouchabilityString(EntityPlayer player, Block block, IBlockState blockState, BlockPos 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))
|
||||
|
||||
if (showSilkTouchability && block.canSilkHarvest(player.worldObj, position, blockState, player))
|
||||
{
|
||||
boolean silkTouchMatters = block.getItemDropped(meta, new Random(), 0) != Item.getItemFromBlock(block) || block.quantityDropped(new Random()) <= 0;
|
||||
boolean silkTouchMatters = block.getItemDropped(blockState, new Random(), 0) != Item.getItemFromBlock(block) || block.quantityDropped(new Random()) <= 0;
|
||||
if (silkTouchMatters)
|
||||
{
|
||||
boolean hasSilkTouch = EnchantmentHelper.getSilkTouchModifier(player);
|
||||
@@ -191,12 +183,6 @@ public class WailaHandler implements IWailaDataProvider
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getWailaTail(ItemStack itemStack, List<String> toolTip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
public static HashMap<String, Boolean> configOptions = new HashMap<String, Boolean>();
|
||||
static
|
||||
{
|
||||
@@ -218,15 +204,30 @@ 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(), entry.getValue());
|
||||
}
|
||||
|
||||
WailaHandler instance = new WailaHandler();
|
||||
registrar.registerBodyProvider(instance, Block.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITipList getWailaHead(ItemStack itemStack, ITipList currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITipList getWailaTail(ItemStack itemStack, ITipList currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config)
|
||||
{
|
||||
return currenttip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound getNBTData(TileEntity te, NBTTagCompound tag, IWailaDataAccessorServer accessor)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package squeek.wailaharvestability.helpers;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemTool;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockHelper
|
||||
@@ -18,18 +20,18 @@ public class BlockHelper
|
||||
testTools.put("axe", new ItemStack(Items.wooden_axe));
|
||||
}
|
||||
|
||||
public static String getEffectiveToolOf(World world, int x, int y, int z, Block block, int metadata)
|
||||
public static String getEffectiveToolOf(World world, BlockPos blockPos, Block block, IBlockState blockState)
|
||||
{
|
||||
String effectiveTool = block.getHarvestTool(metadata);
|
||||
String effectiveTool = block.getHarvestTool(blockState);
|
||||
if (effectiveTool == null)
|
||||
{
|
||||
float hardness = block.getBlockHardness(world, x, y, z);
|
||||
float hardness = block.getBlockHardness(world, blockPos);
|
||||
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())
|
||||
if (testTool != null && testTool.getItem() instanceof ItemTool && testTool.getStrVsBlock(block) >= ((ItemTool) testTool.getItem()).getToolMaterial().getEfficiencyOnProperMaterial())
|
||||
{
|
||||
effectiveTool = testToolEntry.getKey();
|
||||
break;
|
||||
@@ -40,8 +42,8 @@ public class BlockHelper
|
||||
return effectiveTool;
|
||||
}
|
||||
|
||||
public static boolean isBlockUnbreakable(Block block, World world, int x, int y, int z)
|
||||
public static boolean isBlockUnbreakable(Block block, World world, BlockPos blockPos)
|
||||
{
|
||||
return block.getBlockHardness(world, x, y, z) == -1.0f;
|
||||
return block.getBlockHardness(world, blockPos) == -1.0f;
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,13 @@ public class OreHelper
|
||||
|
||||
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;
|
||||
// check the ore dictionary to see if any entry starts with "ore"
|
||||
int[] oreIDs = OreDictionary.getOreIDs(itemStack);
|
||||
for (int oreID : oreIDs)
|
||||
{
|
||||
if (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).*"))
|
||||
|
||||
@@ -3,8 +3,6 @@ package squeek.wailaharvestability.helpers;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import squeek.wailaharvestability.ModWailaHarvestability;
|
||||
import squeek.wailaharvestability.proxy.ProxyIguanaTweaks;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
@@ -40,9 +38,6 @@ public class StringHelper
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ModWailaHarvestability.hasIguanaTweaks)
|
||||
return ProxyIguanaTweaks.getHarvestLevelName(num);
|
||||
|
||||
String unlocalized = "gui.partcrafter.mining" + (num + 1);
|
||||
String localized = StringHelper.getLocalizedString(unlocalized);
|
||||
if (!unlocalized.equals(localized))
|
||||
|
||||
@@ -1,135 +1,43 @@
|
||||
package squeek.wailaharvestability.helpers;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
|
||||
public class ToolHelper
|
||||
{
|
||||
// tinkers construct
|
||||
private static Class<?> HarvestTool = null;
|
||||
private static Class<?> DualHarvestTool = null;
|
||||
private static Method getHarvestType = null;
|
||||
private static Method getSecondHarvestType = null;
|
||||
public static boolean tinkersConstructLoaded = false;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if (Loader.isModLoaded("TConstruct"))
|
||||
{
|
||||
try
|
||||
{
|
||||
HarvestTool = Class.forName("tconstruct.library.tools.HarvestTool");
|
||||
DualHarvestTool = Class.forName("tconstruct.library.tools.DualHarvestTool");
|
||||
getHarvestType = HarvestTool.getDeclaredMethod("getHarvestType");
|
||||
getSecondHarvestType = DualHarvestTool.getDeclaredMethod("getSecondHarvestType");
|
||||
getHarvestType.setAccessible(true);
|
||||
getSecondHarvestType.setAccessible(true);
|
||||
tinkersConstructLoaded = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasToolTag(ItemStack itemStack)
|
||||
{
|
||||
return itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey("InfiTool");
|
||||
}
|
||||
|
||||
public static NBTTagCompound getToolTag(ItemStack tool)
|
||||
{
|
||||
NBTTagCompound tag = null;
|
||||
if (tool.hasTagCompound())
|
||||
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");
|
||||
}
|
||||
|
||||
public static Set<String> getToolClassesOf(ItemStack tool)
|
||||
{
|
||||
return tool.getItem().getToolClasses(tool);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isToolOfClass(ItemStack tool, String toolClass)
|
||||
{
|
||||
return getToolClassesOf(tool).contains(toolClass);
|
||||
}
|
||||
|
||||
|
||||
public static boolean toolHasAnyToolClass(ItemStack tool)
|
||||
{
|
||||
return !getToolClassesOf(tool).isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isToolEffectiveAgainst(ItemStack tool, Block block, int metadata, String effectiveToolClass)
|
||||
public static boolean isToolEffectiveAgainst(ItemStack tool, IBlockAccess blockAccess, BlockPos blockPos, Block block, String effectiveToolClass)
|
||||
{
|
||||
if (tinkersConstructLoaded && HarvestTool.isInstance(tool.getItem()))
|
||||
{
|
||||
Item item = tool.getItem();
|
||||
List<String> harvestTypes = new ArrayList<String>();
|
||||
try
|
||||
{
|
||||
harvestTypes.add((String) getHarvestType.invoke(item));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
tinkersConstructLoaded = false;
|
||||
}
|
||||
|
||||
if (DualHarvestTool.isInstance(item))
|
||||
{
|
||||
try
|
||||
{
|
||||
harvestTypes.add((String) getSecondHarvestType.invoke(item));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
tinkersConstructLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
return harvestTypes.contains(effectiveToolClass);
|
||||
}
|
||||
return ForgeHooks.isToolEffective(tool, block, metadata) || (toolHasAnyToolClass(tool) ? isToolOfClass(tool, effectiveToolClass) : tool.func_150997_a(block) > 1.5f); // func_150997_a = getStrVsBlock
|
||||
return ForgeHooks.isToolEffective(blockAccess, blockPos, tool) || (toolHasAnyToolClass(tool) ? isToolOfClass(tool, effectiveToolClass) : tool.getStrVsBlock(block) > 1.5f); // func_150997_a = getStrVsBlock
|
||||
}
|
||||
|
||||
public static boolean canToolHarvestLevel(ItemStack tool, Block block, int metadata, int harvestLevel)
|
||||
public static boolean canToolHarvestLevel(ItemStack tool, IBlockAccess blockAccess, BlockPos blockPos, 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);
|
||||
return ForgeHooks.canToolHarvestBlock(blockAccess, blockPos, tool);
|
||||
}
|
||||
|
||||
public static boolean canToolHarvestBlock(ItemStack tool, Block block, int metadata)
|
||||
public static boolean canToolHarvestBlock(ItemStack tool, Block block, IBlockState blockState)
|
||||
{
|
||||
return block.getMaterial().isToolNotRequired() || tool.func_150998_b(block); // func_150998_b = canHarvestBlock
|
||||
return block.getMaterial().isToolNotRequired() || tool.canHarvestBlock(block); // func_150998_b = canHarvestBlock
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package squeek.wailaharvestability.proxy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import net.minecraft.block.Block;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
|
||||
public class ProxyCreativeBlocks
|
||||
{
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package squeek.wailaharvestability.proxy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ProxyIguanaTweaks
|
||||
{
|
||||
private static Class<?> HarvestLevels = null;
|
||||
private static Method proxyGetHarvestLevelName;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
try
|
||||
{
|
||||
HarvestLevels = Class.forName("iguanaman.iguanatweakstconstruct.util.HarvestLevels");
|
||||
proxyGetHarvestLevelName = HarvestLevels.getDeclaredMethod("getHarvestLevelName", int.class);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getHarvestLevelName(int num)
|
||||
{
|
||||
String harvestLevelName = "<Unknown>";
|
||||
|
||||
try
|
||||
{
|
||||
harvestLevelName = (String) proxyGetHarvestLevelName.invoke(null, num);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return harvestLevelName;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user