-
Notifications
You must be signed in to change notification settings - Fork 755
/
AOEHarvestTool.java
84 lines (70 loc) · 3.09 KB
/
AOEHarvestTool.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
package tconstruct.library.tools;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.util.MovingObjectPosition;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public abstract class AOEHarvestTool extends HarvestTool {
public int breakRadius;
public int breakDepth;
public AOEHarvestTool(int baseDamage, int breakRadius, int breakDepth) {
super(baseDamage);
this.breakRadius = breakRadius;
this.breakDepth = breakDepth;
}
@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
// only effective materials matter. We don't want to aoe when beraking dirt with a hammer.
Block block = player.worldObj.getBlock(x,y,z);
int meta = player.worldObj.getBlockMetadata(x,y,z);
if(block == null || !isEffective(block, meta) || !stack.hasTagCompound())
return super.onBlockStartBreak(stack, x,y,z, player);
// tool broken?
NBTTagCompound toolTags = stack.getTagCompound().getCompoundTag("InfiTool");
if(toolTags == null || toolTags.getBoolean("Broken"))
return super.onBlockStartBreak(stack, x,y,z, player);
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(player.worldObj, player, false, 4.5d);
if(mop == null)
return super.onBlockStartBreak(stack, x,y,z, player);
int sideHit = mop.sideHit;
//int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;
// we successfully destroyed a block. time to do AOE!
int xRange = breakRadius;
int yRange = breakRadius;
int zRange = breakDepth;
switch (sideHit) {
case 0:
case 1:
yRange = breakDepth;
zRange = breakRadius;
break;
case 2:
case 3:
xRange = breakRadius;
zRange = breakDepth;
break;
case 4:
case 5:
xRange = breakDepth;
zRange = breakRadius;
break;
}
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
for (int zPos = z - zRange; zPos <= z + zRange; zPos++) {
// don't break the originally already broken block, duh
if (xPos == x && yPos == y && zPos == z)
continue;
if(!super.onBlockStartBreak(stack, xPos, yPos, zPos, player))
breakExtraBlock(player.worldObj, xPos, yPos, zPos, sideHit, player, x,y,z);
}
return super.onBlockStartBreak(stack, x, y, z, player);
}
}