remove crafter robot
This commit is contained in:
parent
affa7c9a53
commit
2abd030635
6 changed files with 0 additions and 988 deletions
|
@ -68,9 +68,6 @@ import buildcraft.robotics.TileRequester;
|
|||
import buildcraft.robotics.TileZonePlan;
|
||||
import buildcraft.robotics.ai.AIRobotAttack;
|
||||
import buildcraft.robotics.ai.AIRobotBreak;
|
||||
import buildcraft.robotics.ai.AIRobotCraftAssemblyTable;
|
||||
import buildcraft.robotics.ai.AIRobotCraftFurnace;
|
||||
import buildcraft.robotics.ai.AIRobotCraftWorkbench;
|
||||
import buildcraft.robotics.ai.AIRobotDeliverRequested;
|
||||
import buildcraft.robotics.ai.AIRobotDisposeItems;
|
||||
import buildcraft.robotics.ai.AIRobotFetchAndEquipItemStack;
|
||||
|
@ -110,7 +107,6 @@ import buildcraft.robotics.boards.BoardRobotBomber;
|
|||
import buildcraft.robotics.boards.BoardRobotBuilder;
|
||||
import buildcraft.robotics.boards.BoardRobotButcher;
|
||||
import buildcraft.robotics.boards.BoardRobotCarrier;
|
||||
import buildcraft.robotics.boards.BoardRobotCrafter;
|
||||
import buildcraft.robotics.boards.BoardRobotDelivery;
|
||||
import buildcraft.robotics.boards.BoardRobotEmpty;
|
||||
import buildcraft.robotics.boards.BoardRobotFarmer;
|
||||
|
@ -240,7 +236,6 @@ public class BuildCraftRobotics extends BuildCraftMod {
|
|||
|
||||
// Even more expensive
|
||||
// These handle complex multi-step operations.
|
||||
RedstoneBoardRegistry.instance.registerBoardType(new BCBoardNBT("buildcraft:boardRobotCrafter", "crafter", BoardRobotCrafter.class, "blue"), 128000);
|
||||
RedstoneBoardRegistry.instance.registerBoardType(new BCBoardNBT("buildcraft:boardRobotDelivery", "delivery", BoardRobotDelivery.class, "green"), 128000);
|
||||
RedstoneBoardRegistry.instance.registerBoardType(new BCBoardNBT("buildcraft:boardRobotKnight", "knight", BoardRobotKnight.class, "red"), 128000);
|
||||
RedstoneBoardRegistry.instance.registerBoardType(new BCBoardNBT("buildcraft:boardRobotBomber", "bomber", BoardRobotBomber.class, "red"), 128000);
|
||||
|
@ -283,7 +278,6 @@ public class BuildCraftRobotics extends BuildCraftMod {
|
|||
}
|
||||
RobotManager.registerAIRobot(BoardRobotButcher.class, "boardRobotButcher", "buildcraft.core.robots.boards.BoardRobotButcher");
|
||||
RobotManager.registerAIRobot(BoardRobotCarrier.class, "boardRobotCarrier", "buildcraft.core.robots.boards.BoardRobotCarrier");
|
||||
RobotManager.registerAIRobot(BoardRobotCrafter.class, "boardRobotCrafter", "buildcraft.core.robots.boards.BoardRobotCrafter");
|
||||
RobotManager.registerAIRobot(BoardRobotDelivery.class, "boardRobotDelivery", "buildcraft.core.robots.boards.BoardRobotDelivery");
|
||||
RobotManager.registerAIRobot(BoardRobotFarmer.class, "boardRobotFarmer", "buildcraft.core.robots.boards.BoardRobotFarmer");
|
||||
RobotManager.registerAIRobot(BoardRobotFluidCarrier.class, "boardRobotFluidCarrier", "buildcraft.core.robots.boards.BoardRobotFluidCarrier");
|
||||
|
@ -299,9 +293,6 @@ public class BuildCraftRobotics extends BuildCraftMod {
|
|||
RobotManager.registerAIRobot(BoardRobotStripes.class, "boardRobotStripes", "buildcraft.core.robots.boards.BoardRobotStripes");
|
||||
RobotManager.registerAIRobot(AIRobotAttack.class, "aiRobotAttack", "buildcraft.core.robots.AIRobotAttack");
|
||||
RobotManager.registerAIRobot(AIRobotBreak.class, "aiRobotBreak", "buildcraft.core.robots.AIRobotBreak");
|
||||
RobotManager.registerAIRobot(AIRobotCraftAssemblyTable.class, "aiRobotCraftAssemblyTable", "buildcraft.core.robots.AIRobotCraftAssemblyTable");
|
||||
RobotManager.registerAIRobot(AIRobotCraftFurnace.class, "aiRobotCraftFurnace", "buildcraft.core.robots.AIRobotCraftFurnace");
|
||||
RobotManager.registerAIRobot(AIRobotCraftWorkbench.class, "aiRobotCraftWorkbench", "buildcraft.core.robots.AIRobotCraftWorkbench");
|
||||
RobotManager.registerAIRobot(AIRobotDeliverRequested.class, "aiRobotDeliverRequested", "buildcraft.core.robots.AIRobotDeliverRequested");
|
||||
RobotManager.registerAIRobot(AIRobotDisposeItems.class, "aiRobotDisposeItems", "buildcraft.core.robots.AIRobotDisposeItems");
|
||||
RobotManager.registerAIRobot(AIRobotFetchAndEquipItemStack.class, "aiRobotFetchAndEquipItemStack", "buildcraft.core.robots.AIRobotFetchAndEquipItemStack");
|
||||
|
|
|
@ -1,269 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, 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.robotics.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.recipes.CraftingResult;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.DockingStation;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.robots.ResourceIdBlock;
|
||||
import buildcraft.api.robots.RobotManager;
|
||||
import buildcraft.core.lib.inventory.ITransactor;
|
||||
import buildcraft.core.lib.inventory.InvUtils;
|
||||
import buildcraft.core.lib.inventory.InventoryCopy;
|
||||
import buildcraft.core.lib.inventory.InventoryIterator;
|
||||
import buildcraft.core.lib.inventory.StackHelper;
|
||||
import buildcraft.core.lib.inventory.Transactor;
|
||||
import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
|
||||
import buildcraft.core.lib.inventory.filters.IStackFilter;
|
||||
import buildcraft.robotics.IStationFilter;
|
||||
import buildcraft.robotics.statements.ActionRobotFilter;
|
||||
import buildcraft.robotics.statements.ActionStationAllowCraft;
|
||||
import buildcraft.silicon.BlockLaserTable;
|
||||
import buildcraft.silicon.ResourceIdAssemblyTable;
|
||||
import buildcraft.silicon.TileAssemblyTable;
|
||||
|
||||
public class AIRobotCraftAssemblyTable extends AIRobotCraftGeneric {
|
||||
|
||||
private CraftingResult<ItemStack> expectedResult;
|
||||
private DockingStation stationFound;
|
||||
private TileAssemblyTable table;
|
||||
private boolean craftStarted = false;
|
||||
private ArrayList<ArrayStackFilter> requirements;
|
||||
|
||||
private int waitedTime = 0;
|
||||
|
||||
public AIRobotCraftAssemblyTable(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotCraftAssemblyTable(EntityRobotBase iRobot, CraftingResult craftingResult) {
|
||||
this(iRobot);
|
||||
|
||||
expectedResult = craftingResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
requirements = tryCraft();
|
||||
startDelegateAI(new AIRobotSearchStation(robot, new StationAssemblyTableFilter(), robot.getZoneToWork()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (table != null) {
|
||||
if (!craftStarted) {
|
||||
if (requirements.size() != 0) {
|
||||
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqStackFilter(), 1));
|
||||
return;
|
||||
}
|
||||
|
||||
if (robot.getDockingStation() != stationFound) {
|
||||
startDelegateAI(new AIRobotGotoStation(robot, stationFound));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ITransactor trans = Transactor.getTransactorFor(table);
|
||||
|
||||
for (IInvSlot s : InventoryIterator.getIterable(robot)) {
|
||||
if (s.getStackInSlot() != null) {
|
||||
ItemStack added = trans.add(s.getStackInSlot(), ForgeDirection.UNKNOWN, true);
|
||||
|
||||
if (added.stackSize == 0) {
|
||||
terminate();
|
||||
} else if (added.stackSize == s.getStackInSlot().stackSize) {
|
||||
s.setStackInSlot(null);
|
||||
} else {
|
||||
s.getStackInSlot().stackSize -= added.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RobotManager.registryProvider.getRegistry(robot.worldObj).take(new ResourceIdAssemblyTable(table), robot);
|
||||
table.planOutput(expectedResult.recipe);
|
||||
// TODO: How to make sure this output is not crafted more than
|
||||
// once??
|
||||
|
||||
craftStarted = true;
|
||||
} else {
|
||||
waitedTime++;
|
||||
|
||||
if (InvUtils.getItem(robot, new ArrayStackFilter(expectedResult.crafted)) != null) {
|
||||
crafted = true;
|
||||
terminate();
|
||||
} else if (waitedTime > 120 * 60) {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotSearchStation) {
|
||||
if (!ai.success()) {
|
||||
crafted = false;
|
||||
terminate();
|
||||
} else {
|
||||
stationFound = ((AIRobotSearchStation) ai).targetStation;
|
||||
table = getUsableAssemblyTable(new BlockIndex(stationFound.x(), stationFound.y(), stationFound.z()));
|
||||
|
||||
if (table == null) {
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
BlockIndex index = new BlockIndex(table);
|
||||
|
||||
if (!robot.getRegistry().take(new ResourceIdBlock(index), robot)) {
|
||||
terminate();
|
||||
}
|
||||
|
||||
if (!stationFound.take(robot)) {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
} else if (ai instanceof AIRobotGotoStationAndLoad) {
|
||||
if (!ai.success()) {
|
||||
terminate();
|
||||
} else {
|
||||
requirements = tryCraft();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack receiveItem(ItemStack stack) {
|
||||
if (StackHelper.isMatchingItem(stack, expectedResult.crafted)) {
|
||||
ITransactor robotTransactor = Transactor.getTransactorFor(robot);
|
||||
ItemStack added = robotTransactor.add(stack, ForgeDirection.UNKNOWN, true);
|
||||
|
||||
stack.stackSize -= added.stackSize;
|
||||
|
||||
return stack;
|
||||
} else {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList<ArrayStackFilter> tryCraft() {
|
||||
Object[] items = expectedResult.usedItems.toArray();
|
||||
|
||||
ArrayList<ArrayStackFilter> result = new ArrayList<ArrayStackFilter>();
|
||||
|
||||
IInventory inv = new InventoryCopy(robot);
|
||||
|
||||
for (Object tmp : items) {
|
||||
if (tmp == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int qty = 0;
|
||||
ArrayStackFilter filter;
|
||||
|
||||
if (tmp instanceof ItemStack) {
|
||||
ItemStack stack = (ItemStack) tmp;
|
||||
qty = stack.stackSize;
|
||||
filter = new ArrayStackFilter(stack);
|
||||
} else {
|
||||
ArrayList<ItemStack> stacks = (ArrayList<ItemStack>) tmp;
|
||||
qty = stacks.get(0).stackSize;
|
||||
filter = new ArrayStackFilter(stacks.toArray(new ItemStack[stacks.size()]));
|
||||
}
|
||||
|
||||
for (IInvSlot s : InventoryIterator.getIterable(inv)) {
|
||||
if (filter.matches(s.getStackInSlot())) {
|
||||
ItemStack removed = s.decreaseStackInSlot(qty);
|
||||
|
||||
qty = qty - removed.stackSize;
|
||||
|
||||
if (removed.stackSize == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qty > 0) {
|
||||
result.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private class StationAssemblyTableFilter implements IStationFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(DockingStation station) {
|
||||
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(expectedResult.crafted),
|
||||
ActionStationAllowCraft.class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (getUsableAssemblyTable(new BlockIndex(station.x(), station.y(), station.z())) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private TileAssemblyTable getUsableAssemblyTable(BlockIndex b) {
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
BlockIndex index = new BlockIndex (b.x + dir.offsetX, b.y
|
||||
+ dir.offsetY, b.z
|
||||
+ dir.offsetZ);
|
||||
|
||||
if (robot.getRegistry().isTaken(new ResourceIdBlock(index))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block nearbyBlock = robot.worldObj.getBlock(index.x, index.y, index.z);
|
||||
int nearbyMeta = robot.worldObj.getBlockMetadata(index.x, index.y, index.z);
|
||||
|
||||
if (nearbyBlock instanceof BlockLaserTable && nearbyMeta == 0) {
|
||||
TileAssemblyTable f = (TileAssemblyTable) robot.worldObj.getTileEntity(index.x, index.y, index.z);
|
||||
|
||||
// TODO: check if assembly table has some empty slots
|
||||
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private class ReqStackFilter implements IStackFilter {
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
for (ArrayStackFilter s : requirements) {
|
||||
if (s.matches(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, 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.robotics.ai;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFurnace;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.DockingStation;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.robots.ResourceIdBlock;
|
||||
import buildcraft.core.lib.inventory.ITransactor;
|
||||
import buildcraft.core.lib.inventory.InvUtils;
|
||||
import buildcraft.core.lib.inventory.StackHelper;
|
||||
import buildcraft.core.lib.inventory.Transactor;
|
||||
import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
|
||||
import buildcraft.core.lib.inventory.filters.IStackFilter;
|
||||
import buildcraft.robotics.IStationFilter;
|
||||
import buildcraft.robotics.statements.ActionRobotFilter;
|
||||
import buildcraft.robotics.statements.ActionStationAllowCraft;
|
||||
|
||||
public class AIRobotCraftFurnace extends AIRobotCraftGeneric {
|
||||
|
||||
private static final int INPUT_SLOT = 0;
|
||||
private static final int FUEL_SLOT = 1;
|
||||
private static final int OUTPUT_SLOT = 2;
|
||||
|
||||
private ItemStack input;
|
||||
private DockingStation stationFound;
|
||||
private TileEntityFurnace furnace;
|
||||
private boolean craftStarted = false;
|
||||
|
||||
private int waitedTime = 0;
|
||||
private ItemStack expectedOutput;
|
||||
|
||||
public AIRobotCraftFurnace(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotCraftFurnace(EntityRobotBase iRobot, ItemStack iInput, ItemStack iOutput) {
|
||||
this(iRobot);
|
||||
|
||||
input = iInput;
|
||||
expectedOutput = iOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
startDelegateAI(new AIRobotSearchStation(robot, new StationFurnaceFilter(), robot.getZoneToWork()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (furnace != null) {
|
||||
if (!craftStarted) {
|
||||
if (furnace.getStackInSlot(FUEL_SLOT) == null && InvUtils.getItem(robot, new FuelFilter()) == null) {
|
||||
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new FuelFilter(), 1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (InvUtils.getItem(robot, new ArrayStackFilter(input)) == null) {
|
||||
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ArrayStackFilter(input), 1));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (robot.getDockingStation() != stationFound) {
|
||||
startDelegateAI(new AIRobotGotoStation(robot, stationFound));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (furnace.getStackInSlot(FUEL_SLOT) == null) {
|
||||
IInvSlot s = InvUtils.getItem(robot, new FuelFilter());
|
||||
furnace.setInventorySlotContents(FUEL_SLOT, s.decreaseStackInSlot(1));
|
||||
}
|
||||
|
||||
if (furnace.getStackInSlot(INPUT_SLOT) == null) {
|
||||
IInvSlot s = InvUtils.getItem(robot, new ArrayStackFilter(input));
|
||||
furnace.setInventorySlotContents(INPUT_SLOT, s.decreaseStackInSlot(1));
|
||||
}
|
||||
|
||||
craftStarted = true;
|
||||
|
||||
if (!robot.hasFreeSlot()) {
|
||||
startDelegateAI(new AIRobotGotoStationAndUnload(robot));
|
||||
}
|
||||
} else {
|
||||
waitedTime++;
|
||||
|
||||
if (waitedTime > 40 && furnace.getStackInSlot(OUTPUT_SLOT) != null) {
|
||||
if (robot.hasFreeSlot()) {
|
||||
ItemStack stack = furnace.decrStackSize(OUTPUT_SLOT, 1);
|
||||
|
||||
if (stack != null) {
|
||||
ITransactor transactor = Transactor.getTransactorFor(robot);
|
||||
transactor.add(stack, ForgeDirection.UNKNOWN, true);
|
||||
crafted = true;
|
||||
}
|
||||
}
|
||||
|
||||
terminate();
|
||||
} else if (waitedTime > 20 * 60) {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotSearchStation) {
|
||||
if (!ai.success()) {
|
||||
crafted = false;
|
||||
terminate();
|
||||
} else {
|
||||
stationFound = ((AIRobotSearchStation) ai).targetStation;
|
||||
furnace = getUsableFurnace(new BlockIndex(stationFound.x(), stationFound.y(), stationFound.z()));
|
||||
|
||||
if (furnace == null) {
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
BlockIndex index = new BlockIndex(furnace);
|
||||
|
||||
if (!robot.getRegistry().take(new ResourceIdBlock(index), robot)) {
|
||||
terminate();
|
||||
}
|
||||
|
||||
if (!stationFound.take(robot)) {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
} else if (ai instanceof AIRobotGotoStationAndLoad) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// How to operate furnaces
|
||||
// [1] identify a furnace
|
||||
// [2] verify that proper item is in. If empty, and slot out empty or
|
||||
// contains order get proper item, otherwise skip
|
||||
// [3] bring proper item and put in
|
||||
// [4] as soon as output contains expected item, get it and place it
|
||||
// somewhere
|
||||
|
||||
private class StationFurnaceFilter implements IStationFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(DockingStation station) {
|
||||
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackFilter(expectedOutput),
|
||||
ActionStationAllowCraft.class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (getUsableFurnace(new BlockIndex(station.x(), station.y(), station.z())) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class FuelFilter implements IStackFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
return TileEntityFurnace.getItemBurnTime(stack) > 0 && !StackHelper.isMatchingItem(stack, input);
|
||||
}
|
||||
}
|
||||
|
||||
private TileEntityFurnace getUsableFurnace(BlockIndex b) {
|
||||
// reserve that furnace if found from the block reserve system
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
BlockIndex index = new BlockIndex (b.x + dir.offsetX, b.y
|
||||
+ dir.offsetY, b.z
|
||||
+ dir.offsetZ);
|
||||
|
||||
if (robot.getRegistry().isTaken(new ResourceIdBlock(index))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block nearbyBlock = robot.worldObj.getBlock(index.x, index.y, index.z);
|
||||
|
||||
if (nearbyBlock instanceof BlockFurnace) {
|
||||
TileEntityFurnace f = (TileEntityFurnace) robot.worldObj.getTileEntity(index.x, index.y, index.z);
|
||||
|
||||
if (f.getStackInSlot(INPUT_SLOT) != null
|
||||
&& !StackHelper.isMatchingItem(input, f.getStackInSlot(INPUT_SLOT))) {
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, 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.robotics.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
|
||||
|
||||
public abstract class AIRobotCraftGeneric extends AIRobot {
|
||||
|
||||
protected boolean crafted = false;
|
||||
private ArrayList<ArrayStackFilter> requirements = new ArrayList<ArrayStackFilter>();
|
||||
|
||||
public AIRobotCraftGeneric(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void end() {
|
||||
robot.releaseResources();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean success() {
|
||||
return crafted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyCost() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,250 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, 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.robotics.ai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockWorkbench;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.DockingStation;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.lib.inventory.ITransactor;
|
||||
import buildcraft.core.lib.inventory.InventoryCopy;
|
||||
import buildcraft.core.lib.inventory.InventoryIterator;
|
||||
import buildcraft.core.lib.inventory.Transactor;
|
||||
import buildcraft.core.lib.inventory.filters.ArrayStackFilter;
|
||||
import buildcraft.core.lib.inventory.filters.ArrayStackOrListFilter;
|
||||
import buildcraft.core.lib.inventory.filters.IStackFilter;
|
||||
import buildcraft.robotics.IStationFilter;
|
||||
import buildcraft.robotics.statements.ActionRobotFilter;
|
||||
import buildcraft.robotics.statements.ActionStationAllowCraft;
|
||||
|
||||
public class AIRobotCraftWorkbench extends AIRobotCraftGeneric {
|
||||
|
||||
private IRecipe recipe;
|
||||
private int craftingTimer = 0;
|
||||
private ArrayList<ArrayStackFilter> requirements;
|
||||
private ItemStack output;
|
||||
|
||||
public AIRobotCraftWorkbench(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
public AIRobotCraftWorkbench(EntityRobotBase iRobot, IRecipe iRecipe) {
|
||||
this(iRobot);
|
||||
|
||||
recipe = iRecipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start () {
|
||||
requirements = tryCraft(false);
|
||||
|
||||
if (requirements == null) {
|
||||
terminate ();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (recipe == null) {
|
||||
// loading error
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
// [1] look for a crafting order
|
||||
// -- if none, clear temporary item blacklist and sleep
|
||||
// [2] look and fetch items needed to craft (problem with 9 slots inv?)
|
||||
// -- allow upgrades!! And to show contents
|
||||
// -- if can't be done, add item to temporary blacklist, drop inv either
|
||||
// -- in a inventory accepting items or drop in the world, then look for
|
||||
// -- another order
|
||||
// [3] look and goto a station next to a workbench, craft
|
||||
// -- if not, sleep
|
||||
|
||||
if (craftingTimer > 0) {
|
||||
craftingTimer--;
|
||||
|
||||
if (craftingTimer == 0) {
|
||||
craft();
|
||||
terminate();
|
||||
}
|
||||
} else if (requirements.size() > 0) {
|
||||
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqStackFilter(), 1));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotSearchAndGotoStation(robot, new StationWorkbenchFilter(), robot.getZoneToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotGotoStationAndLoad) {
|
||||
if (ai.success()) {
|
||||
requirements = tryCraft(false);
|
||||
} else {
|
||||
terminate();
|
||||
}
|
||||
} else if (ai instanceof AIRobotSearchAndGotoStation) {
|
||||
if (new StationWorkbenchFilter().matches(robot.getDockingStation())) {
|
||||
craftingTimer = 40;
|
||||
} else {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ArrayList<ArrayStackFilter> tryCraft(boolean doRemove) {
|
||||
Object[] items = new Object[0];
|
||||
|
||||
if (recipe instanceof ShapedRecipes) {
|
||||
items = ((ShapedRecipes) recipe).recipeItems;
|
||||
} else if (recipe instanceof ShapelessRecipes) {
|
||||
items = ((ShapelessRecipes) recipe).recipeItems.toArray();
|
||||
} else if (recipe instanceof ShapedOreRecipe) {
|
||||
items = ((ShapedOreRecipe) recipe).getInput();
|
||||
} else if (recipe instanceof ShapelessOreRecipe) {
|
||||
items = ((ShapelessOreRecipe) recipe).getInput().toArray();
|
||||
}
|
||||
|
||||
ArrayList<ArrayStackFilter> result = new ArrayList<ArrayStackFilter>();
|
||||
|
||||
IInventory inv = robot;
|
||||
|
||||
if (!doRemove) {
|
||||
inv = new InventoryCopy(robot);
|
||||
}
|
||||
|
||||
InventoryCrafting invCraft = new InventoryCrafting(new Container() {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith(EntityPlayer player) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
Object tmp = items [i];
|
||||
|
||||
if (tmp == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int qty = 0;
|
||||
ArrayStackFilter filter;
|
||||
|
||||
if (tmp instanceof ItemStack) {
|
||||
ItemStack stack = (ItemStack) tmp;
|
||||
qty = stack.stackSize;
|
||||
filter = new ArrayStackFilter(stack);
|
||||
} else {
|
||||
ArrayList<ItemStack> stacks = (ArrayList<ItemStack>) tmp;
|
||||
qty = stacks.get(0).stackSize;
|
||||
filter = new ArrayStackFilter(stacks.toArray(new ItemStack[stacks.size()]));
|
||||
}
|
||||
|
||||
for (IInvSlot s : InventoryIterator.getIterable(inv)) {
|
||||
if (filter.matches(s.getStackInSlot())) {
|
||||
ItemStack removed = s.decreaseStackInSlot(qty);
|
||||
|
||||
qty = qty - removed.stackSize;
|
||||
|
||||
if (invCraft.getStackInSlot(i) != null) {
|
||||
invCraft.getStackInSlot(i).stackSize += qty;
|
||||
} else {
|
||||
invCraft.setInventorySlotContents(i, removed);
|
||||
}
|
||||
|
||||
invCraft.setInventorySlotContents(i, removed);
|
||||
|
||||
if (removed.stackSize == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qty > 0) {
|
||||
result.add(filter);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.size() == 0 && doRemove) {
|
||||
output = recipe.getCraftingResult(invCraft);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void craft() {
|
||||
if (tryCraft(true).size() == 0 && output != null) {
|
||||
crafted = true;
|
||||
|
||||
ITransactor transactor = Transactor.getTransactorFor(robot);
|
||||
|
||||
transactor.add(output, ForgeDirection.UNKNOWN, true);
|
||||
}
|
||||
}
|
||||
|
||||
private class ReqStackFilter implements IStackFilter {
|
||||
@Override
|
||||
public boolean matches(ItemStack stack) {
|
||||
for (ArrayStackFilter s : requirements) {
|
||||
if (s.matches(stack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class StationWorkbenchFilter implements IStationFilter {
|
||||
|
||||
@Override
|
||||
public boolean matches(DockingStation station) {
|
||||
if (!ActionRobotFilter.canInteractWithItem(station, new ArrayStackOrListFilter(recipe.getRecipeOutput()),
|
||||
ActionStationAllowCraft.class)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
Block nearbyBlock = robot.worldObj.getBlock(station.x() + dir.offsetX, station.y()
|
||||
+ dir.offsetY, station.z()
|
||||
+ dir.offsetZ);
|
||||
|
||||
if (nearbyBlock instanceof BlockWorkbench) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyCost() {
|
||||
return 30;
|
||||
}
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2015, 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.robotics.boards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||
import buildcraft.api.recipes.CraftingResult;
|
||||
import buildcraft.api.recipes.IFlexibleRecipe;
|
||||
import buildcraft.api.robots.AIRobot;
|
||||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.api.robots.StackRequest;
|
||||
import buildcraft.core.lib.inventory.StackHelper;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager;
|
||||
import buildcraft.robotics.ai.AIRobotCraftAssemblyTable;
|
||||
import buildcraft.robotics.ai.AIRobotCraftFurnace;
|
||||
import buildcraft.robotics.ai.AIRobotCraftGeneric;
|
||||
import buildcraft.robotics.ai.AIRobotCraftWorkbench;
|
||||
import buildcraft.robotics.ai.AIRobotDeliverRequested;
|
||||
import buildcraft.robotics.ai.AIRobotDisposeItems;
|
||||
import buildcraft.robotics.ai.AIRobotGotoSleep;
|
||||
import buildcraft.robotics.ai.AIRobotGotoStationToUnload;
|
||||
import buildcraft.robotics.ai.AIRobotSearchStackRequest;
|
||||
import buildcraft.robotics.ai.AIRobotUnload;
|
||||
import buildcraft.robotics.statements.ActionRobotFilter;
|
||||
|
||||
public class BoardRobotCrafter extends RedstoneBoardRobot {
|
||||
|
||||
private ItemStack order;
|
||||
private ArrayList<ItemStack> craftingBlacklist = new ArrayList<ItemStack>();
|
||||
private StackRequest currentRequest = null;
|
||||
|
||||
public BoardRobotCrafter(EntityRobotBase iRobot) {
|
||||
super(iRobot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RedstoneBoardRobotNBT getNBTHandler() {
|
||||
return BCBoardNBT.REGISTRY.get("crafter");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (robot.containsItems()) {
|
||||
// Always makes sure that when starting a craft, the inventory is
|
||||
// clean.
|
||||
|
||||
startDelegateAI(new AIRobotDisposeItems(robot));
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentRequest != null) {
|
||||
order = currentRequest.stack;
|
||||
} else {
|
||||
order = null;
|
||||
}
|
||||
|
||||
if (order == null) {
|
||||
startDelegateAI(new AIRobotSearchStackRequest(robot, ActionRobotFilter.getGateFilter(robot
|
||||
.getLinkedStation()), craftingBlacklist));
|
||||
return;
|
||||
}
|
||||
|
||||
IRecipe recipe = lookForWorkbenchRecipe(order);
|
||||
|
||||
if (recipe != null) {
|
||||
startDelegateAI(new AIRobotCraftWorkbench(robot, recipe));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack furnaceInput = lookForFurnaceRecipe(order);
|
||||
|
||||
if (furnaceInput != null) {
|
||||
startDelegateAI(new AIRobotCraftFurnace(robot, furnaceInput, order));
|
||||
return;
|
||||
}
|
||||
|
||||
CraftingResult craftingResult = lookForAssemblyTableRecipe(order);
|
||||
|
||||
if (craftingResult != null) {
|
||||
startDelegateAI(new AIRobotCraftAssemblyTable(robot, craftingResult));
|
||||
return;
|
||||
}
|
||||
|
||||
craftingBlacklist.add(order);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotCraftGeneric) {
|
||||
if (!ai.success()) {
|
||||
robot.releaseResources();
|
||||
currentRequest = null;
|
||||
craftingBlacklist.add(order);
|
||||
} else {
|
||||
if (currentRequest != null) {
|
||||
startDelegateAI(new AIRobotDeliverRequested(robot, currentRequest));
|
||||
} else {
|
||||
robot.releaseResources();
|
||||
// The extra crafted items may make some crafting possible
|
||||
craftingBlacklist.clear();
|
||||
}
|
||||
}
|
||||
} else if (ai instanceof AIRobotGotoStationToUnload) {
|
||||
if (ai.success()) {
|
||||
startDelegateAI(new AIRobotUnload(robot));
|
||||
} else {
|
||||
robot.releaseResources();
|
||||
currentRequest = null;
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
}
|
||||
} else if (ai instanceof AIRobotSearchStackRequest) {
|
||||
if (!ai.success()) {
|
||||
craftingBlacklist.clear();
|
||||
currentRequest = null;
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
} else {
|
||||
currentRequest = ((AIRobotSearchStackRequest) ai).request;
|
||||
|
||||
if (!currentRequest.station.take(robot)) {
|
||||
currentRequest = null;
|
||||
}
|
||||
}
|
||||
} else if (ai instanceof AIRobotDeliverRequested) {
|
||||
currentRequest = null;
|
||||
robot.releaseResources();
|
||||
// The extra crafted items may make some crafting possible
|
||||
craftingBlacklist.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private IRecipe lookForWorkbenchRecipe(ItemStack order) {
|
||||
for (Object o : CraftingManager.getInstance().getRecipeList()) {
|
||||
IRecipe r = (IRecipe) o;
|
||||
|
||||
if (r instanceof ShapedRecipes
|
||||
|| r instanceof ShapelessRecipes
|
||||
|| r instanceof ShapedOreRecipe
|
||||
|| r instanceof ShapelessOreRecipe) {
|
||||
if (StackHelper.isMatchingItem(r.getRecipeOutput(), order)) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ItemStack lookForFurnaceRecipe(ItemStack order) {
|
||||
for (Object o : FurnaceRecipes.smelting().getSmeltingList().entrySet()) {
|
||||
Map.Entry e = (Map.Entry) o;
|
||||
ItemStack input = (ItemStack) e.getKey();
|
||||
ItemStack output = (ItemStack) e.getValue();
|
||||
|
||||
if (StackHelper.isMatchingItem(output, order)) {
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private CraftingResult<?> lookForAssemblyTableRecipe(ItemStack order) {
|
||||
for (IFlexibleRecipe r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
CraftingResult<?> result = r.canCraft(order);
|
||||
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isBlacklisted(ItemStack stack) {
|
||||
for (ItemStack black : craftingBlacklist) {
|
||||
if (StackHelper.isMatchingItem(stack, black)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue