made progress for builder robot, for #1920

This commit is contained in:
SpaceToad 2014-07-08 22:40:39 +02:00
parent 23d46e2bce
commit b71fe3cce8
8 changed files with 73 additions and 3 deletions

View file

@ -11,5 +11,7 @@ package buildcraft.api.blueprints;
import net.minecraft.inventory.IInventory;
public interface ITileBuilder extends IInventory {
boolean isBuildingMaterialSlot(int i);
}

View file

@ -27,9 +27,9 @@ import buildcraft.api.core.Position;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.blueprints.BuildingSlotBlock;
import buildcraft.core.blueprints.BuildingSlotEntity;
import buildcraft.core.blueprints.IBuilder;
import buildcraft.core.blueprints.IBuilingItem;
public class BuildingItem implements IBuilder {
public class BuildingItem implements IBuilingItem {
private static int ITEMS_SPACE = 2;

View file

@ -23,6 +23,7 @@ import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptContext;
public class TileConstructionMarker extends TileBuildCraft implements IBuildingItemsProvider {
@ -37,6 +38,7 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
public ItemStack itemBlueprint;
public BptBuilderBase bluePrintBuilder;
public BptContext bptContext;
private ArrayList<BuildingItem> buildersInAction = new ArrayList<BuildingItem>();
private NBTTagCompound initNBT;
@ -52,6 +54,7 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
if (itemBlueprint != null && bluePrintBuilder == null) {
bluePrintBuilder = new BptBuilderBlueprint((Blueprint) ItemBlueprint.loadBlueprint(itemBlueprint),
worldObj, xCoord, yCoord, zCoord);
bptContext = bluePrintBuilder.getContext();
}
if (laser == null && direction != ForgeDirection.UNKNOWN) {
@ -137,4 +140,8 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
public boolean needsToBuild() {
return bluePrintBuilder != null && !bluePrintBuilder.isDone(this);
}
public BptContext getContext () {
return bptContext;
}
}

View file

@ -64,4 +64,5 @@ public abstract class BuildingSlot {
public abstract void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException;
public abstract double getEnergyRequirement();
}

View file

@ -173,4 +173,5 @@ public class BuildingSlotBlock extends BuildingSlot {
public double getEnergyRequirement() {
return schematic.getEnergyRequirement(stackConsumed);
}
}

View file

@ -8,6 +8,6 @@
*/
package buildcraft.core.blueprints;
public interface IBuilder {
public interface IBuilingItem {
boolean isDone();
}

View file

@ -35,6 +35,7 @@ import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.IBox;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.api.robots.IDockingStation;
@ -88,6 +89,7 @@ public class EntityRobot extends EntityRobotBase implements
private IDockingStation currentDockingStation;
private WeakHashMap<Entity, Boolean> unreachableEntities = new WeakHashMap<Entity, Boolean>();
@MjBattery
private double mjStored;
public EntityRobot(World world, NBTTagCompound boardNBT) {

View file

@ -8,18 +8,27 @@
*/
package buildcraft.core.robots.boards;
import java.util.LinkedList;
import net.minecraft.item.ItemStack;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.builders.TileConstructionMarker;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.robots.AIRobotGotoBlock;
import buildcraft.core.robots.AIRobotGotoSleep;
import buildcraft.core.robots.AIRobotGotoStationToLoad;
import buildcraft.core.robots.AIRobotLoad;
public class BoardRobotBuilder extends RedstoneBoardRobot {
private TileConstructionMarker markerToBuild;
private BuildingSlot currentBuildingSlot;
private LinkedList<ItemStack> requirementsToLookFor;
public BoardRobotBuilder(EntityRobotBase iRobot) {
super(iRobot);
@ -63,6 +72,54 @@ public class BoardRobotBuilder extends RedstoneBoardRobot {
if (currentBuildingSlot == null) {
currentBuildingSlot = markerToBuild.bluePrintBuilder.reserveNextSlot(robot.worldObj);
if (currentBuildingSlot != null) {
requirementsToLookFor = currentBuildingSlot.getRequirements(markerToBuild.getContext());
} else {
startDelegateAI(new AIRobotGotoSleep(robot));
return;
}
// TODO: what if there's more requirements that this robot can
// handle e.g. not enough free spots?
}
if (requirementsToLookFor != null && requirementsToLookFor.size() > 0) {
startDelegateAI(new AIRobotGotoStationToLoad(robot,
new ArrayStackFilter(requirementsToLookFor.getFirst()),
robot.getAreaToWork()));
}
if (currentBuildingSlot != null && requirementsToLookFor != null && requirementsToLookFor.size() == 0) {
// TODO: It's probably OK to get at least X units away from
// destination. something to handle at the path-finding level (e.g.
// end computation) to be brought up to here as a parameter.
startDelegateAI(new AIRobotGotoBlock(robot,
(int) currentBuildingSlot.getDestination().x,
(int) currentBuildingSlot.getDestination().y,
(int) currentBuildingSlot.getDestination().z));
}
}
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoStationToLoad) {
if (((AIRobotGotoStationToLoad) ai).found) {
// TODO: How to load only the required amount of items there?
startDelegateAI(new AIRobotLoad(robot, new ArrayStackFilter(requirementsToLookFor.getFirst())));
} else {
startDelegateAI(new AIRobotGotoSleep(robot));
}
} else if (ai instanceof AIRobotLoad) {
// TODO: check that we get the proper items in
requirementsToLookFor.removeFirst();
} else if (ai instanceof AIRobotGotoBlock) {
// TODO: here we want to start the animation, and to update the
// builder state (remove slot from list, add to post processing,
// etc);
currentBuildingSlot.writeToWorld(markerToBuild.getContext());
currentBuildingSlot = null;
requirementsToLookFor = null;
}
}
}