-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileMiningWell.java
113 lines (98 loc) · 3.22 KB
/
TileMiningWell.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
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.factory;
import java.util.List;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.world.BlockEvent.BreakEvent;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.api.blueprints.BuilderAPI;
import buildcraft.api.tiles.IHasWork;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile.PipeType;
import buildcraft.core.RFBattery;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtils;
import buildcraft.core.utils.Utils;
public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeConnection {
boolean isDigging = true;
private BlockMiner miner;
public TileMiningWell() {
super();
this.setBattery(new RFBattery(2 * 64 * BuilderAPI.BREAK_ENERGY, BuilderAPI.BREAK_ENERGY, 0));
}
/**
* Dig the next available piece of land if not done. As soon as it reaches
* bedrock, lava or goes below 0, it's considered done.
*/
@Override
public void updateEntity () {
if (worldObj.isRemote) {
return;
}
if (getBattery().getEnergyStored() == 0) {
return;
}
if (miner == null) {
World world = worldObj;
int depth = yCoord - 1;
while (world.getBlock(xCoord, depth, zCoord) == BuildCraftFactory.plainPipeBlock) {
depth = depth - 1;
}
if (depth < 1 || depth < yCoord - BuildCraftFactory.miningDepth || !BlockUtils.canChangeBlock(world, xCoord, depth, zCoord)) {
isDigging = false;
// Drain energy, because at 0 energy this will stop doing calculations.
getBattery().useEnergy(0, 10, false);
return;
}
if (world.isAirBlock(xCoord, depth, zCoord)) {
if (getBattery().getEnergyStored() >= BuilderAPI.BUILD_ENERGY) {
getBattery().useEnergy(BuilderAPI.BUILD_ENERGY, BuilderAPI.BUILD_ENERGY, false);
world.setBlock(xCoord, depth, zCoord, BuildCraftFactory.plainPipeBlock);
}
} else {
miner = new BlockMiner(world, this, xCoord, depth, zCoord);
}
} else {
int usedEnergy = miner.acceptEnergy(getBattery().getEnergyStored());
getBattery().useEnergy(usedEnergy, usedEnergy, false);
if (miner.hasMined()) {
if (miner.hasFailed()) {
isDigging = false;
}
miner = null;
}
}
}
@Override
public void invalidate() {
super.invalidate();
if (miner != null) {
miner.invalidate();
}
if (worldObj != null && yCoord > 2) {
BuildCraftFactory.miningWellBlock.removePipes(worldObj, xCoord, yCoord, zCoord);
}
}
@Override
public boolean hasWork() {
return isDigging;
}
@Override
public ConnectOverride overridePipeConnection(PipeType type,
ForgeDirection with) {
return type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
}
}