-
Notifications
You must be signed in to change notification settings - Fork 755
/
LumberAxe.java
426 lines (381 loc) · 14.5 KB
/
LumberAxe.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
package tconstruct.items.tools;
import tconstruct.common.TRepo;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.AbilityHelper;
import tconstruct.library.tools.HarvestTool;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class LumberAxe extends HarvestTool
{
public LumberAxe()
{
super(0);
this.setUnlocalizedName("InfiTool.LumberAxe");
}
@Override
protected Material[] getEffectiveMaterials ()
{
return materials;
}
@Override
protected String getHarvestType ()
{
return "axe";
}
@Override
public float getRepairCost ()
{
return 4.0f;
}
public float getDurabilityModifier ()
{
return 2.5f;
}
public String getToolName ()
{
return "Lumber Axe";
}
@Override
public boolean func_150894_a (ItemStack itemstack, World world, Block block, int x, int y, int z, EntityLivingBase player)
{
if (block != null && block.func_149688_o() == Material.field_151584_j)
return false;
return AbilityHelper.onBlockChanged(itemstack, world, block, x, y, z, player, random);
}
static Material[] materials = { Material.field_151575_d, Material.field_151582_l, Material.field_151594_q, Material.field_151570_A, Material.pumpkin };
/* Lumber axe specific */
/*@Override
public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boolean par5)
{
super.onUpdate(stack, world, entity, par4, par5);
if (entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) entity;
ItemStack equipped = player.getCurrentEquippedItem();
if (equipped == stack)
{
player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 1));
}
}
}*/
@Override
public float getStrVsBlock (ItemStack stack, Block block, int meta)
{
if (!stack.hasTagCompound())
return 1.0f;
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.func_149688_o())
{
float mineSpeed = tags.getInteger("MiningSpeed");
int heads = 1;
if (tags.hasKey("MiningSpeed2"))
{
mineSpeed += tags.getInteger("MiningSpeed2");
heads++;
}
if (tags.hasKey("MiningSpeedHandle"))
{
mineSpeed += tags.getInteger("MiningSpeedHandle");
heads++;
}
if (tags.hasKey("MiningSpeedExtra"))
{
mineSpeed += tags.getInteger("MiningSpeedExtra");
heads++;
}
float trueSpeed = mineSpeed / (heads * 300f);
int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
int durability = tags.getInteger("Damage");
float stonebound = tags.getFloat("Shoddy");
float bonusLog = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
trueSpeed += bonusLog;
if (hlvl <= tags.getInteger("HarvestLevel"))
return trueSpeed;
return 0.1f;
}
}
return super.getStrVsBlock(stack, block, meta);
}
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
if (!stack.hasTagCompound())
return false;
World world = player.worldObj;
final Block wood = world.func_147439_a(x, y, z);;
if (wood == null)
{
return super.onBlockStartBreak(stack, x, y, z, player);
}
if (wood.isWood(world, x, y, z) || wood.func_149688_o() == Material.field_151583_m)
{
int height = y;
boolean foundTop = false;
do
{
height++;
Block block = world.func_147439_a(x, height, z);
if (block != wood)
{
height--;
foundTop = true;
}
} while (!foundTop);
int numLeaves = 0;
if (height - y < 50)
{
for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = height - 1; yPos <= height + 1; yPos++)
{
for (int zPos = z - 1; zPos <= z + 1; zPos++)
{
Block leaves = world.func_147439_a(xPos, yPos, zPos);
if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos))
numLeaves++;
}
}
}
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int meta = world.getBlockMetadata(x, y, z);
if (numLeaves > 3)
breakTree(world, x, y, z, stack, tags, wood, meta, player);
else
destroyWood(world, x, y, z, stack, tags, player);
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, woodID + (meta << 12));
}
else if (wood.func_149688_o() == Material.field_151575_d)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
int meta = world.getBlockMetadata(x, y, z);
destroyWood(world, x, y, z, stack, tags, player);
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, woodID + (meta << 12));
}
return super.onBlockStartBreak(stack, x, y, z, player);
}
void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player)
{
Block block;
for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y; yPos <= y + 1; yPos++)
{
for (int zPos = z - 1; zPos <= z + 1; zPos++)
{
if (!(tags.getBoolean("Broken")))
{
Block localblock = world.func_147439_a(xPos, yPos, zPos);
if (bID == localblock)
{
block = localblock;
meta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
if (hlvl <= tags.getInteger("HarvestLevel"))
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
cancelHarvest = true;
}
if (cancelHarvest)
{
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
}
else
{
if (localblock == bID && world.getBlockMetadata(xPos, yPos, zPos) % 4 == meta % 4)
{
/* world.setBlock(xPos, yPos, zPos, 0, 0, 3);
if (!player.capabilities.isCreativeMode)
{
Block.blocksList[bID].harvestBlock(world, player, xPos, yPos, zPos, meta);
onBlockDestroyed(stack, world, bID, xPos, yPos, zPos, player);
}*/
if (!player.capabilities.isCreativeMode)
{
if (block.removeBlockByPlayer(world, player, xPos, yPos, zPos))
{
block.func_149664_b(world, xPos, yPos, zPos, meta);
}
block.func_149636_a(world, player, xPos, yPos, zPos, meta);
block.func_149681_a(world, xPos, yPos, zPos, meta, player);
func_150894_a(stack, world, localblock, xPos, yPos, zPos, player);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
}
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
}
/*else
{
Block leaves = Block.blocksList[localID];
if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos))
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
if (!player.capabilities.isCreativeMode)
{
Block.blocksList[bID].harvestBlock(world, player, xPos, yPos, zPos, meta);
onBlockDestroyed(stack, world, bID, xPos, yPos, zPos, player);
}
}
}*/
}
}
}
}
}
}
}
}
void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player)
{
for (int xPos = x - 1; xPos <= x + 1; xPos++)
{
for (int yPos = y - 1; yPos <= y + 1; yPos++)
{
for (int zPos = z - 1; zPos <= z + 1; zPos++)
{
if (!(tags.getBoolean("Broken")))
{
Block block = world.func_147439_a(xPos, yPos, zPos);
int meta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
if (block != null && block.func_149688_o() == Material.field_151575_d)
{
if (hlvl <= tags.getInteger("HarvestLevel"))
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
cancelHarvest = true;
}
if (!cancelHarvest)
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
if (!player.capabilities.isCreativeMode)
{
//TODO harvestBlock
block.func_149636_a(world, player, xPos, yPos, zPos, meta);
func_150894_a(stack, world, block, xPos, yPos, zPos, player);
}
}
}
}
}
}
}
}
}
@Override
public Item getHeadItem ()
{
return TRepo.broadAxeHead;
}
@Override
public Item getHandleItem ()
{
return TRepo.toughRod;
}
@Override
public Item getAccessoryItem ()
{
return TRepo.largePlate;
}
@Override
public Item getExtraItem ()
{
return TRepo.toughBinding;
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderPasses (int metadata)
{
return 10;
}
@Override
public int getPartAmount ()
{
return 4;
}
@Override
public String getIconSuffix (int partType)
{
switch (partType)
{
case 0:
return "_lumberaxe_head";
case 1:
return "_lumberaxe_head_broken";
case 2:
return "_lumberaxe_handle";
case 3:
return "_lumberaxe_shield";
case 4:
return "_lumberaxe_binding";
default:
return "";
}
}
@Override
public String getEffectSuffix ()
{
return "_lumberaxe_effect";
}
@Override
public String getDefaultFolder ()
{
return "lumberaxe";
}
@Override
public int durabilityTypeAccessory ()
{
return 2;
}
@Override
public int durabilityTypeExtra ()
{
return 1;
}
@Override
public boolean willAllowOffhandWeapon ()
{
return false;
}
@Override
public boolean willAllowShield ()
{
return false;
}
@Override
public boolean isOffhandHandDualWeapon ()
{
return false;
}
@Override
public boolean sheatheOnBack ()
{
return true;
}
}