Files
TinkersConstruct/src/main/java/tconstruct/library/tools/DualHarvestTool.java
T

99 lines
3.0 KiB
Java
Raw Normal View History

package tconstruct.library.tools;
2014-01-16 01:36:18 -05:00
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
2014-01-10 21:14:54 -05:00
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
2014-09-09 18:30:15 +10:00
import tconstruct.library.*;
/* Base class for harvest tools with each head having a different purpose */
public abstract class DualHarvestTool extends HarvestTool
{
2013-12-31 16:37:46 -05:00
public DualHarvestTool(int baseDamage)
{
2013-12-31 16:37:46 -05:00
super(baseDamage);
}
2014-09-09 18:30:15 +10:00
@Override
public int getHarvestLevel(ItemStack stack, String toolClass) {
// well, we can only get the harvestlevel if we have an item to get it from!
if(stack == null || !(stack.getItem() instanceof HarvestTool))
return -1;
// invalid query or wrong toolclass
if(toolClass == null)
return -1;
if(!stack.hasTagCompound())
return -1;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
// broken tools suck.
if (tags.getBoolean("Broken"))
return -1;
if(this.getHarvestType().equals(toolClass))
return tags.getInteger("HarvestLevel");
else if(this.getSecondHarvestType().equals(toolClass))
return tags.getInteger("HarvestLevel2");
return -1;
}
@Override
public float getDigSpeed (ItemStack stack, Block block, int meta)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.getBoolean("Broken"))
return 0.1f;
Material[] materials = getEffectiveMaterials();
for (int i = 0; i < materials.length; i++)
{
2014-02-05 08:28:53 -05:00
if (materials[i] == block.getMaterial())
{
if (block.getHarvestLevel(meta) <= tags.getInteger("HarvestLevel"))
2014-11-04 15:44:22 +01:00
return AbilityHelper.calcDualToolSpeed(this, tags, false);
return 0.1f;
}
}
materials = getEffectiveSecondaryMaterials();
for (int i = 0; i < materials.length; i++)
{
2014-02-05 08:28:53 -05:00
if (materials[i] == block.getMaterial())
{
if (block.getHarvestLevel(meta) <= tags.getInteger("HarvestLevel2"))
2014-11-04 15:44:22 +01:00
return AbilityHelper.calcDualToolSpeed(this, tags, true);
return 0.1f;
}
}
return super.getDigSpeed(stack, block, meta);
}
@Override
2014-09-09 18:30:15 +10:00
public boolean isEffective (Material material)
{
if (super.isEffective(material))
return true;
2014-09-09 18:30:15 +10:00
for (Material m : getEffectiveSecondaryMaterials())
if (m == material)
return true;
return false;
}
@Override
2014-06-30 22:26:00 -08:00
public String[] getTraits ()
{
return new String[] { "harvest", "dualharvest" };
}
protected abstract Material[] getEffectiveSecondaryMaterials ();
protected abstract String getSecondHarvestType ();
}