Merge branch '6.5.x' of github.com:BuildCraft/BuildCraft into 6.5.x

This commit is contained in:
asiekierka 2015-04-25 12:40:03 +02:00
commit 32e4b77b26
5 changed files with 86 additions and 41 deletions

View file

@ -190,7 +190,7 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
}
public boolean needsToBuild() {
return bluePrintBuilder != null && !bluePrintBuilder.isDone(this);
return !isInvalid() && bluePrintBuilder != null && !bluePrintBuilder.isDone(this);
}
public BptContext getContext () {

View file

@ -255,6 +255,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
public BuildingSlot reserveNextBlock(World world) {
if (buildList.size() != 0) {
BuildingSlot slot = internalGetNextBlock(world, null);
checkDone();
if (slot != null) {
slot.reserved = true;

View file

@ -243,7 +243,9 @@ public class PathFinding implements IIterableAlgorithm {
int y = from.index.y + dy;
int z = from.index.z + dz;
if (endReached(x, y, z)) {
if (y < 0) {
resultMoves[dx + 1][dy + 1][dz + 1] = 0;
} else if (endReached(x, y, z)) {
resultMoves[dx + 1][dy + 1][dz + 1] = 2;
} else if (!BuildCraftAPI.isSoftBlock(world, x, y, z)) {
resultMoves[dx + 1][dy + 1][dz + 1] = 0;

View file

@ -19,6 +19,7 @@ import buildcraft.builders.TileConstructionMarker;
import buildcraft.core.builders.BuildingItem;
import buildcraft.core.builders.BuildingSlot;
import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
import buildcraft.robotics.ai.AIRobotDisposeItems;
import buildcraft.robotics.ai.AIRobotGotoBlock;
import buildcraft.robotics.ai.AIRobotGotoSleep;
import buildcraft.robotics.ai.AIRobotGotoStationAndLoad;
@ -26,6 +27,8 @@ import buildcraft.robotics.ai.AIRobotRecharge;
public class BoardRobotBuilder extends RedstoneBoardRobot {
private static final int MAX_RANGE_SQ = 3 * 64 * 64;
private TileConstructionMarker markerToBuild;
private BuildingSlot currentBuildingSlot;
private LinkedList<ItemStack> requirementsToLookFor;
@ -48,69 +51,76 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
}
if (markerToBuild == null) {
double minDistance = Double.MAX_VALUE;
for (TileConstructionMarker marker : TileConstructionMarker.currentMarkers) {
if (marker.getWorldObj() == robot.worldObj && marker.needsToBuild()) {
double dx = robot.posX - marker.xCoord;
double dy = robot.posY - marker.yCoord;
double dz = robot.posZ - marker.zCoord;
double distance = dx * dx + dy * dy + dz * dz;
if (distance < minDistance) {
markerToBuild = marker;
minDistance = distance;
}
}
}
markerToBuild = findClosestMarker();
if (markerToBuild == null) {
startDelegateAI(new AIRobotGotoSleep(robot));
if (robot.containsItems()) {
startDelegateAI(new AIRobotDisposeItems(robot));
} else {
startDelegateAI(new AIRobotGotoSleep(robot));
}
return;
}
}
if (markerToBuild == null || !markerToBuild.needsToBuild()) {
if (!markerToBuild.needsToBuild()) {
markerToBuild = null;
// TODO: review what is this, maybe shutdown the robot
startDelegateAI(new AIRobot(robot));
currentBuildingSlot = null;
return;
}
if (currentBuildingSlot == null) {
currentBuildingSlot = markerToBuild.bluePrintBuilder.reserveNextSlot(robot.worldObj);
if (currentBuildingSlot != null) {
// The above may return null even if not done, if it's scanning
// for available blocks.
requirementsToLookFor = currentBuildingSlot.getRequirements(markerToBuild.getContext());
if (currentBuildingSlot == null) {
// No slots available yet
launchingDelay = 40;
return;
}
// TODO: what if there's more requirements that this robot can
// handle e.g. not enough free spots? If there's more than X slots
// found that can't be built, go to sleep.
}
if (requirementsToLookFor != null && requirementsToLookFor.size() > 0) {
if (requirementsToLookFor == null) {
if (robot.containsItems()) {
startDelegateAI(new AIRobotDisposeItems(robot));
}
requirementsToLookFor = currentBuildingSlot.getRequirements(markerToBuild
.getContext());
if (requirementsToLookFor == null) {
launchingDelay = 40;
return;
}
if (requirementsToLookFor.size() > 4) {
currentBuildingSlot.built = true;
currentBuildingSlot = null;
requirementsToLookFor = null;
}
}
if (requirementsToLookFor.size() > 0) {
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ArrayStackFilter(
requirementsToLookFor.getFirst()), requirementsToLookFor.getFirst().stackSize));
return;
}
if (currentBuildingSlot != null && requirementsToLookFor != null && requirementsToLookFor.size() == 0) {
if (requirementsToLookFor.size() == 0) {
if (currentBuildingSlot.stackConsumed == null) {
// Once all the element are in, if not already, use them to
// prepare the slot.
markerToBuild.bluePrintBuilder.useRequirements(robot, currentBuildingSlot);
}
if (robot.getEnergy() - currentBuildingSlot.getEnergyRequirement() < EntityRobotBase.SAFETY_ENERGY) {
if (!hasEnoughEnergy()) {
startDelegateAI(new AIRobotRecharge(robot));
} else {
startDelegateAI(new AIRobotGotoBlock(robot,
(int) currentBuildingSlot.getDestination().x,
(int) currentBuildingSlot.getDestination().y,
(int) currentBuildingSlot.getDestination().z,
8));
(int) currentBuildingSlot.getDestination().x,
(int) currentBuildingSlot.getDestination().y,
(int) currentBuildingSlot.getDestination().z,
8));
}
// TODO: take into account cases where the robot can't reach the
// destination - go to work on another block
@ -131,16 +141,17 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
return;
}
if (robot.getEnergy() - currentBuildingSlot.getEnergyRequirement() < EntityRobotBase.SAFETY_ENERGY) {
if (!hasEnoughEnergy()) {
startDelegateAI(new AIRobotRecharge(robot));
return;
}
robot.getBattery().extractEnergy(currentBuildingSlot.getEnergyRequirement(), false);
launchingDelay = currentBuildingSlot.getStacksToDisplay().size() * BuildingItem.ITEMS_SPACE;
markerToBuild.bluePrintBuilder.buildSlot
(robot.worldObj, markerToBuild, currentBuildingSlot,
robot.posX + 0.125F, robot.posY + 0.125F, robot.posZ + 0.125F);
launchingDelay = currentBuildingSlot.getStacksToDisplay().size()
* BuildingItem.ITEMS_SPACE;
markerToBuild.bluePrintBuilder.buildSlot(robot.worldObj, markerToBuild,
currentBuildingSlot, robot.posX + 0.125F, robot.posY + 0.125F,
robot.posZ + 0.125F);
currentBuildingSlot = null;
requirementsToLookFor = null;
}
@ -159,4 +170,34 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
launchingDelay = nbt.getInteger("launchingDelay");
}
private TileConstructionMarker findClosestMarker() {
double minDistance = Double.MAX_VALUE;
TileConstructionMarker minMarker = null;
for (TileConstructionMarker marker : TileConstructionMarker.currentMarkers) {
if (marker.getWorldObj() == robot.worldObj && marker.needsToBuild()) {
double dx = robot.posX - marker.xCoord;
double dy = robot.posY - marker.yCoord;
double dz = robot.posZ - marker.zCoord;
double distance = dx * dx + dy * dy + dz * dz;
if (distance < minDistance) {
minMarker = marker;
minDistance = distance;
}
}
}
if (minMarker != null && minDistance < MAX_RANGE_SQ) {
return minMarker;
} else {
return null;
}
}
private boolean hasEnoughEnergy() {
return robot.getEnergy() - currentBuildingSlot.getEnergyRequirement() > EntityRobotBase.SAFETY_ENERGY;
}
}

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemReed;
import net.minecraft.item.ItemStack;
@ -154,7 +155,7 @@ public class BoardRobotPlanter extends RedstoneBoardRobot {
private static class ReedFilter implements IStackFilter {
@Override
public boolean matches(ItemStack stack) {
return stack.getItem() instanceof ItemReed;
return stack.getItem() == Items.reeds;
}
}