Code cleanup
This commit is contained in:
parent
8771a1f443
commit
a72bed152c
1 changed files with 37 additions and 32 deletions
|
@ -16,6 +16,9 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
|
|||
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||
private boolean active = false;
|
||||
|
||||
private final int MODE_SCANNING = 0;
|
||||
private final int MODE_HARVESTING = 1;
|
||||
private final int MODE_TAPPING = 2;
|
||||
private int mode = 0;
|
||||
private boolean doLeaves = false;
|
||||
private boolean silkTouchLeaves = false;
|
||||
|
@ -57,12 +60,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
if (active) {
|
||||
scan++;
|
||||
if (mode == 0) {
|
||||
if (mode == MODE_SCANNING) {
|
||||
if (scan >= scanWait) {
|
||||
scan = 0;
|
||||
logs = scanTrees();
|
||||
if(logs.size() > 0)
|
||||
mode = treeTap ? 2 : 1;
|
||||
if (logs.size() > 0) {
|
||||
mode = treeTap ? MODE_TAPPING : MODE_HARVESTING;
|
||||
}
|
||||
logIndex = 0;
|
||||
}
|
||||
} else {
|
||||
|
@ -70,13 +74,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
scan = 0;
|
||||
|
||||
if (logIndex >= logs.size()) {
|
||||
mode = 0;
|
||||
mode = MODE_SCANNING;
|
||||
return;
|
||||
}
|
||||
VectorI pos = logs.get(logIndex);
|
||||
Block block = worldObj.getBlock(pos.x, pos.y, pos.z);
|
||||
|
||||
if (mode == 1) {
|
||||
if (mode == MODE_HARVESTING) {
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromLaserMediums(cost, true)) {
|
||||
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||
|
@ -97,7 +101,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
logIndex++;
|
||||
}
|
||||
} else if(mode == 2) {
|
||||
} else if (mode == MODE_TAPPING) {
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromLaserMediums(cost, true)) {
|
||||
if (isRoomForHarvest()) {
|
||||
|
@ -248,7 +252,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
if (methodName.equals("start")) {
|
||||
if (!active) {
|
||||
mode = 0;
|
||||
mode = MODE_SCANNING;
|
||||
totalHarvested = 0;
|
||||
active = true;
|
||||
}
|
||||
|
@ -256,6 +260,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
} else if (methodName.equals("stop")) {
|
||||
active = false;
|
||||
return new Boolean[] { false };
|
||||
|
||||
} else if (methodName.equals("radius")) {
|
||||
try {
|
||||
|
@ -311,7 +316,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
return new Object[] { treeTap };
|
||||
|
||||
} else if (methodName.equals("state")) {
|
||||
String state = active ? (mode==0?"scanning" : (mode == 1 ? "harvesting" : "tapping")) : "inactive";
|
||||
String state = active ? (mode == MODE_SCANNING ? "scanning" : (mode == MODE_HARVESTING ? "harvesting" : (mode == MODE_TAPPING ? "tapping" : "<invalid>" + mode))) : "inactive";
|
||||
return new Object[] { state, radiusX, radiusZ, energy(), totalHarvested };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue