-
Notifications
You must be signed in to change notification settings - Fork 754
/
DualHarvestTool.java
105 lines (90 loc) · 3.05 KB
/
DualHarvestTool.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package tconstruct.library.tools;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
/* Base class for harvest tools with each head having a different purpose */
public abstract class DualHarvestTool extends HarvestTool
{
public DualHarvestTool(int baseDamage)
{
super(baseDamage);
}
@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++)
{
if (materials[i] == block.getMaterial())
{
float speed = tags.getInteger("MiningSpeed");
speed /= 100f;
int hlvl = block.getHarvestLevel(meta);
int durability = tags.getInteger("Damage");
float shoddy = tags.getFloat("Shoddy");
speed += shoddy * durability / 100f;
if (hlvl <= tags.getInteger("HarvestLevel"))
return speed;
return 0.1f;
}
}
materials = getEffectiveSecondaryMaterials();
for (int i = 0; i < materials.length; i++)
{
if (materials[i] == block.getMaterial())
{
float speed = tags.getInteger("MiningSpeed2");
speed /= 100f;
int hlvl = block.getHarvestLevel(meta);
int durability = tags.getInteger("Damage");
float shoddy = tags.getFloat("Shoddy");
speed += shoddy * durability / 100f;
if (hlvl <= tags.getInteger("HarvestLevel2"))
return speed;
return 0.1f;
}
}
return super.getDigSpeed(stack, block, meta);
}
@Override
public boolean func_150897_b (Block block)
{
if (block.getMaterial().isToolNotRequired())
{
return true;
}
for (Material m : getEffectiveMaterials())
{
if (m == block.getMaterial())
return true;
}
for (Material m : getEffectiveSecondaryMaterials())
{
if (m == block.getMaterial())
return true;
}
return false;
}
@Override
public boolean canHarvestBlock (Block block, ItemStack itemStack)
{
return func_150897_b(block);
}
@Override
public String[] getTraits ()
{
return new String[] { "harvest", "dualharvest" };
}
protected abstract Material[] getEffectiveSecondaryMaterials ();
protected abstract String getSecondHarvestType ();
}