finished implementation of career, close #1907

This commit is contained in:
SpaceToad 2014-06-25 22:54:11 +02:00
parent b400c561e3
commit 35c592f041
9 changed files with 261 additions and 163 deletions

View file

@ -73,7 +73,7 @@ public class EntityRobot extends EntityRobotBase implements
public long lastUpdateTime = 0;
private boolean needsUpdate = false;
private ItemStack[] inv = new ItemStack[6];
private ItemStack[] inv = new ItemStack[4];
private String boardID;
private ResourceLocation texture;
private DockingStation currentDockingStation;

View file

@ -33,7 +33,7 @@ public class AIRobotFetchAndEquipItemStack extends AIRobot {
@Override
public void update() {
startDelegateAI(new AIRobotGotoItemStack(robot, filter));
startDelegateAI(new AIRobotGotoStationToLoad(robot, filter));
}
@Override

View file

@ -0,0 +1,98 @@
/**
* 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.core.robots.boards;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.robots.AIRobotLookForStation;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.IStationFilter;
import buildcraft.silicon.statements.StateStationRequestItems;
import buildcraft.transport.Pipe;
public class AIRobotGoToStationToUnload extends AIRobot {
public AIRobotGoToStationToUnload(EntityRobotBase iRobot) {
super(iRobot, 0, 1);
}
@Override
public void start() {
startDelegateAI(new AIRobotLookForStation(robot, new StationInventory()));
}
@Override
public void delegateAIEnded(AIRobot ai) {
terminate();
}
private class StationInventory implements IStationFilter {
@Override
public boolean matches(DockingStation station) {
Pipe pipe = station.pipe.pipe;
for (int i = 0; i < robot.getSizeInventory(); ++i) {
boolean found = false;
ItemStack stackToAdd = robot.getStackInSlot(i);
if (stackToAdd == null) {
continue;
}
for (Object s : pipe.getActionStates()) {
if (s instanceof StateStationRequestItems) {
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
found = true;
break;
}
}
}
if (!found) {
// This stack is not accepted by any of the action states
// currently active on this pipe - look for another one
continue;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile);
if (stackToAdd != null && trans.add(stackToAdd, dir, false) != null) {
// We can add the item to this inventory, go to this
// station.
return true;
}
}
}
}
return false;
}
}
}

View file

@ -24,11 +24,11 @@ import buildcraft.core.robots.IStationFilter;
import buildcraft.silicon.statements.StateStationProvideItems;
import buildcraft.transport.Pipe;
public class AIRobotGotoItemStack extends AIRobot {
public class AIRobotGotoStationToLoad extends AIRobot {
private IStackFilter filter;
public AIRobotGotoItemStack(EntityRobotBase iRobot, IStackFilter iFilter) {
public AIRobotGotoStationToLoad(EntityRobotBase iRobot, IStackFilter iFilter) {
super(iRobot, 0, 1);
filter = iFilter;

View file

@ -0,0 +1,66 @@
/**
* 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.core.robots.boards;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.robots.DockingStation;
public class AIRobotLoad extends AIRobot {
public AIRobotLoad(EntityRobotBase iRobot) {
super(iRobot, 0, 1);
}
@Override
public void start() {
if (robot.getDockingStation() != null) {
DockingStation station = (DockingStation) robot.getDockingStation();
ItemStack itemFound = null;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.pipe.xCoord + dir.offsetX,
station.pipe.yCoord
+ dir.offsetY, station.pipe.zCoord + dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
IInventory tileInventory = (IInventory) nearbyTile;
ITransactor robotTransactor = Transactor.getTransactorFor(robot);
for (int i = 0; i < robot.getSizeInventory(); ++i) {
if (robot.getStackInSlot(i) == null) {
for (IInvSlot slot : InventoryIterator.getIterable(tileInventory, dir.getOpposite())) {
ItemStack stack = slot.getStackInSlot();
if (stack != null) {
slot.setStackInSlot(null);
robot.setInventorySlotContents(i, stack);
break;
}
}
}
}
}
}
}
terminate();
}
}

View file

@ -0,0 +1,83 @@
/**
* 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.core.robots.boards;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.robots.DockingStation;
import buildcraft.silicon.statements.StateStationRequestItems;
import buildcraft.transport.Pipe;
public class AIRobotUnload extends AIRobot {
public AIRobotUnload(EntityRobotBase iRobot) {
super(iRobot, 0, 1);
}
@Override
public void start() {
DockingStation station = (DockingStation) robot.getDockingStation();
if (station == null) {
return;
}
Pipe pipe = station.pipe.pipe;
for (int i = 0; i < robot.getSizeInventory(); ++i) {
boolean found = false;
ItemStack stackToAdd = robot.getStackInSlot(i);
if (stackToAdd == null) {
continue;
}
for (Object s : pipe.getActionStates()) {
if (s instanceof StateStationRequestItems) {
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
found = true;
break;
}
}
}
if (!found) {
// This stack is not accepted by any of the action states
// currently active on this pipe - look for another one
continue;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile);
if (stackToAdd != null) {
ItemStack added = trans.add(stackToAdd, dir, true);
robot.decrStackSize(i, added.stackSize);
}
}
}
}
terminate();
}
}

View file

@ -8,20 +8,11 @@
*/
package buildcraft.core.robots.boards;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.PassThroughStackFilter;
import buildcraft.core.robots.DockingStation;
public class BoardRobotCarrier extends RedstoneBoardRobot {
@ -45,51 +36,22 @@ public class BoardRobotCarrier extends RedstoneBoardRobot {
}
if (!containItems) {
startDelegateAI(new AIRobotGotoItemStack(robot, new PassThroughStackFilter()));
startDelegateAI(new AIRobotGotoStationToLoad(robot, new PassThroughStackFilter()));
} else {
startDelegateAI(new AIRobotGoToStationToUnload(robot));
}
}
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGotoItemStack) {
load();
if (ai instanceof AIRobotGotoStationToLoad) {
startDelegateAI(new AIRobotLoad(robot));
} else if (ai instanceof AIRobotGoToStationToUnload) {
startDelegateAI(new AIRobotUnload(robot));
}
}
private void load() {
if (robot.getDockingStation() != null) {
DockingStation station = (DockingStation) robot.getDockingStation();
ItemStack itemFound = null;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.pipe.xCoord + dir.offsetX,
station.pipe.yCoord
+ dir.offsetY, station.pipe.zCoord + dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
IInventory tileInventory = (IInventory) nearbyTile;
ITransactor robotTransactor = Transactor.getTransactorFor(robot);
for (int i = 0; i < robot.getSizeInventory(); ++i) {
if (robot.getStackInSlot(i) == null) {
for (int j = 0; j < robot.getSizeInventory(); ++j) {
ItemStack stack = tileInventory.getStackInSlot(j);
if (tileInventory.getStackInSlot(j) != null) {
tileInventory.setInventorySlotContents(j, null);
robot.setInventorySlotContents(i, stack);
}
}
}
}
}
}
}
}
private void unload() {
}
}

View file

@ -34,7 +34,7 @@ public final class BoardRobotCarrierNBT extends RedstoneBoardRobotNBT {
@Override
public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) {
return new BoardRobotPlanter(robot);
return new BoardRobotCarrier(robot);
}
@Override

View file

@ -11,12 +11,8 @@ package buildcraft.core.robots.boards;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.boards.IBoardParameter;
import buildcraft.api.boards.IBoardParameterStack;
@ -26,15 +22,9 @@ import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.robots.AIRobot;
import buildcraft.api.robots.EntityRobotBase;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.robots.AIRobotLookForStation;
import buildcraft.core.robots.DockingStation;
import buildcraft.core.robots.IStationFilter;
import buildcraft.silicon.statements.StateStationRequestItems;
import buildcraft.transport.Pipe;
public class BoardRobotPicker extends RedstoneBoardRobot {
@ -83,59 +73,10 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
startDelegateAI(new AIRobotFetchItem(robot, range, stackFilter));
} else {
// otherwise, let's deliver items
startDelegateAI(new AIRobotLookForStation(robot, new StationInventory()));
startDelegateAI(new AIRobotGoToStationToUnload(robot));
}
} else if (ai instanceof AIRobotLookForStation) {
emptyContainerInInventory();
}
}
private void emptyContainerInInventory() {
DockingStation station = (DockingStation) robot.getDockingStation();
if (station == null) {
return;
}
Pipe pipe = station.pipe.pipe;
for (int i = 0; i < robot.getSizeInventory(); ++i) {
boolean found = false;
ItemStack stackToAdd = robot.getStackInSlot(i);
if (stackToAdd == null) {
continue;
}
for (Object s : pipe.getActionStates()) {
if (s instanceof StateStationRequestItems) {
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
found = true;
break;
}
}
}
if (!found) {
// This stack is not accepted by any of the action states
// currently active on this pipe - look for another one
continue;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile);
if (stackToAdd != null) {
ItemStack added = trans.add(stackToAdd, dir, true);
robot.decrStackSize(i, added.stackSize);
}
}
}
startDelegateAI(new AIRobotUnload(robot));
}
}
@ -143,56 +84,4 @@ public class BoardRobotPicker extends RedstoneBoardRobot {
public RedstoneBoardRobotNBT getNBTHandler() {
return BoardRobotPickerNBT.instance;
}
private class StationInventory implements IStationFilter {
@Override
public boolean matches(DockingStation station) {
Pipe pipe = station.pipe.pipe;
for (int i = 0; i < robot.getSizeInventory(); ++i) {
boolean found = false;
ItemStack stackToAdd = robot.getStackInSlot(i);
if (stackToAdd == null) {
continue;
}
for (Object s : pipe.getActionStates()) {
if (s instanceof StateStationRequestItems) {
if (((StateStationRequestItems) s).matches(new ArrayStackFilter(stackToAdd))) {
found = true;
break;
}
}
}
if (!found) {
// This stack is not accepted by any of the action states
// currently active on this pipe - look for another one
continue;
}
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity nearbyTile = robot.worldObj.getTileEntity(station.x() + dir.offsetX, station.y()
+ dir.offsetY, station.z()
+ dir.offsetZ);
if (nearbyTile != null && nearbyTile instanceof IInventory) {
ITransactor trans = Transactor.getTransactorFor(nearbyTile);
if (stackToAdd != null && trans.add(stackToAdd, dir, false) != null) {
// We can add the item to this inventory, go to this
// station.
return true;
}
}
}
}
return false;
}
}
}