-
Notifications
You must be signed in to change notification settings - Fork 755
/
DualHarvestTool.java
151 lines (132 loc) · 4.91 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package tconstruct.library.tools;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper;
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 boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
int meta = world.getBlockMetadata(x, y, z);
Block block = player.worldObj.getBlock(x, y, z);
if (block == null || block == Blocks.air)
return false;
int hlvl = -1;
int shlvl = -1;
if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getHarvestType()))
hlvl = block.getHarvestLevel(meta);
if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getSecondHarvestType()))
shlvl = block.getHarvestLevel(meta);
if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2"))
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, x, y, z, player))
cancelHarvest = true;
}
return cancelHarvest;
}
else
{
if (!player.capabilities.isCreativeMode)
{
// Workaround for dropping experience
int fortune = EnchantmentHelper.getFortuneModifier(player);
int exp = block.getExpDrop(world, meta, fortune);
block.dropXpOnBlockBreak(world, x, y, z, exp);
onBlockDestroyed(stack, world, block, x, y, z, player);
}
WorldHelper.setBlockToAir(world, x, y, z);
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
}
}
@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 ();
}