implemented delivery robot, for #1984
This commit is contained in:
parent
19989256e2
commit
1bd39d326a
6 changed files with 342 additions and 101 deletions
|
@ -14,8 +14,7 @@ buildcraft.boardRobotShovelman=Shovelman
|
||||||
buildcraft.boardRobotButcher=Butcher
|
buildcraft.boardRobotButcher=Butcher
|
||||||
buildcraft.boardRobotBuilder=Builder
|
buildcraft.boardRobotBuilder=Builder
|
||||||
buildcraft.boardRobotCrafter=Crafter
|
buildcraft.boardRobotCrafter=Crafter
|
||||||
buildcraft.boardDetail.parameters=Parameters
|
buildcraft.boardRobotDelivery=Delivery
|
||||||
buildcraft.boardDetail.range=Range
|
|
||||||
|
|
||||||
chat.pipe.power.iron.mode=Switched to %d MJ/t limit
|
chat.pipe.power.iron.mode=Switched to %d MJ/t limit
|
||||||
chat.pipe.power.energyConverter=Energy conversion: %s
|
chat.pipe.power.energyConverter=Energy conversion: %s
|
||||||
|
|
|
@ -52,6 +52,7 @@ import buildcraft.core.robots.boards.BoardRobotBuilderNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotButcherNBT;
|
import buildcraft.core.robots.boards.BoardRobotButcherNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotCarrierNBT;
|
import buildcraft.core.robots.boards.BoardRobotCarrierNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotCrafterNBT;
|
import buildcraft.core.robots.boards.BoardRobotCrafterNBT;
|
||||||
|
import buildcraft.core.robots.boards.BoardRobotDeliveryNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotFarmerNBT;
|
import buildcraft.core.robots.boards.BoardRobotFarmerNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotHarvesterNBT;
|
import buildcraft.core.robots.boards.BoardRobotHarvesterNBT;
|
||||||
import buildcraft.core.robots.boards.BoardRobotKnightNBT;
|
import buildcraft.core.robots.boards.BoardRobotKnightNBT;
|
||||||
|
@ -217,6 +218,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotButcherNBT.instance, 5);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotButcherNBT.instance, 5);
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotShovelmanNBT.instance, 5);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotShovelmanNBT.instance, 5);
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotCrafterNBT.instance, 5);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotCrafterNBT.instance, 5);
|
||||||
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotDeliveryNBT.instance, 5);
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotKnightNBT.instance, 1);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotKnightNBT.instance, 1);
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBomberNBT.instance, 1);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBomberNBT.instance, 1);
|
||||||
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBuilderNBT.instance, 0.5F);
|
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotBuilderNBT.instance, 0.5F);
|
||||||
|
@ -227,18 +229,22 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void init(FMLInitializationEvent evt) {
|
public void init(FMLInitializationEvent evt) {
|
||||||
channels = NetworkRegistry.INSTANCE.newChannel
|
channels = NetworkRegistry.INSTANCE
|
||||||
|
.newChannel
|
||||||
(DefaultProps.NET_CHANNEL_NAME + "-SILICON", new BuildCraftChannelHandler(), new PacketHandlerSilicon());
|
(DefaultProps.NET_CHANNEL_NAME + "-SILICON", new BuildCraftChannelHandler(), new PacketHandlerSilicon());
|
||||||
|
|
||||||
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
|
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
|
||||||
CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser");
|
CoreProxy.proxy.registerTileEntity(TileLaser.class, "net.minecraft.src.buildcraft.factory.TileLaser");
|
||||||
CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyTable");
|
CoreProxy.proxy.registerTileEntity(TileAssemblyTable.class,
|
||||||
CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class, "net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench");
|
"net.minecraft.src.buildcraft.factory.TileAssemblyTable");
|
||||||
CoreProxy.proxy.registerTileEntity(TileIntegrationTable.class, "net.minecraft.src.buildcraft.factory.TileIntegrationTable");
|
CoreProxy.proxy.registerTileEntity(TileAdvancedCraftingTable.class,
|
||||||
|
"net.minecraft.src.buildcraft.factory.TileAssemblyAdvancedWorkbench");
|
||||||
|
CoreProxy.proxy.registerTileEntity(TileIntegrationTable.class,
|
||||||
|
"net.minecraft.src.buildcraft.factory.TileIntegrationTable");
|
||||||
CoreProxy.proxy.registerTileEntity(TileZonePlan.class, "net.minecraft.src.buildcraft.commander.TileZonePlan");
|
CoreProxy.proxy.registerTileEntity(TileZonePlan.class, "net.minecraft.src.buildcraft.commander.TileZonePlan");
|
||||||
CoreProxy.proxy.registerTileEntity(TileRequester.class, "net.minecraft.src.buildcraft.commander.TileRequester");
|
CoreProxy.proxy.registerTileEntity(TileRequester.class, "net.minecraft.src.buildcraft.commander.TileRequester");
|
||||||
|
|
||||||
SchematicRegistry.registerSchematicBlock(laserBlock, SchematicRotateMeta.class, new int[]{2, 5, 3, 4}, true);
|
SchematicRegistry.registerSchematicBlock(laserBlock, SchematicRotateMeta.class, new int[] {2, 5, 3, 4}, true);
|
||||||
|
|
||||||
if (BuildCraftCore.loadDefaultRecipes) {
|
if (BuildCraftCore.loadDefaultRecipes) {
|
||||||
loadRecipes();
|
loadRecipes();
|
||||||
|
|
161
common/buildcraft/core/robots/AIRobotSearchStackRequest.java
Executable file
161
common/buildcraft/core/robots/AIRobotSearchStackRequest.java
Executable file
|
@ -0,0 +1,161 @@
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ActionParameterItemStack;
|
||||||
|
import buildcraft.api.gates.IStatementParameter;
|
||||||
|
import buildcraft.api.robots.AIRobot;
|
||||||
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
|
import buildcraft.api.robots.IRequestProvider;
|
||||||
|
import buildcraft.api.robots.StackRequest;
|
||||||
|
import buildcraft.core.inventory.StackHelper;
|
||||||
|
import buildcraft.silicon.statements.ActionStationRequestItems;
|
||||||
|
import buildcraft.silicon.statements.ActionStationRequestItemsMachine;
|
||||||
|
import buildcraft.transport.Pipe;
|
||||||
|
import buildcraft.transport.gates.ActionIterator;
|
||||||
|
import buildcraft.transport.gates.ActionSlot;
|
||||||
|
|
||||||
|
public class AIRobotSearchStackRequest extends AIRobot {
|
||||||
|
|
||||||
|
public StackRequest request = null;
|
||||||
|
|
||||||
|
private Collection<ItemStack> blackList;
|
||||||
|
|
||||||
|
public AIRobotSearchStackRequest(EntityRobotBase iRobot) {
|
||||||
|
super(iRobot);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AIRobotSearchStackRequest(EntityRobotBase iRobot, Collection<ItemStack> iBlackList) {
|
||||||
|
super(iRobot);
|
||||||
|
|
||||||
|
blackList = iBlackList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start() {
|
||||||
|
startDelegateAI(new AIRobotSearchStation(robot, new StationProviderFilter(), robot.getZoneToWork()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
|
if (ai instanceof AIRobotSearchStation) {
|
||||||
|
if (!ai.success()) {
|
||||||
|
terminate();
|
||||||
|
} else {
|
||||||
|
request = getOrderFromRequestingAction(((AIRobotSearchStation) ai).targetStation);
|
||||||
|
|
||||||
|
if (request == null) {
|
||||||
|
request = getOrderFromRequestingStation(((AIRobotSearchStation) ai).targetStation, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean success() {
|
||||||
|
return request != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isBlacklisted(ItemStack stack) {
|
||||||
|
for (ItemStack black : blackList) {
|
||||||
|
if (StackHelper.isMatchingItem(stack, black)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StackRequest getOrderFromRequestingStation(DockingStation station, boolean take) {
|
||||||
|
boolean actionFound = false;
|
||||||
|
|
||||||
|
Pipe pipe = station.getPipe().pipe;
|
||||||
|
|
||||||
|
for (ActionSlot s : new ActionIterator(pipe)) {
|
||||||
|
if (s.action instanceof ActionStationRequestItemsMachine) {
|
||||||
|
actionFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!actionFound) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 instanceof IRequestProvider) {
|
||||||
|
IRequestProvider provider = (IRequestProvider) nearbyTile;
|
||||||
|
|
||||||
|
for (int i = 0; i < provider.getNumberOfRequests(); ++i) {
|
||||||
|
StackRequest requestFound = provider.getAvailableRequest(i);
|
||||||
|
|
||||||
|
if (requestFound != null && !isBlacklisted(requestFound.stack)) {
|
||||||
|
requestFound.station = station;
|
||||||
|
|
||||||
|
if (take) {
|
||||||
|
if (provider.takeRequest(i, robot)) {
|
||||||
|
return requestFound;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return requestFound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StackRequest getOrderFromRequestingAction(DockingStation station) {
|
||||||
|
boolean actionFound = false;
|
||||||
|
|
||||||
|
Pipe pipe = station.getPipe().pipe;
|
||||||
|
|
||||||
|
for (ActionSlot s : new ActionIterator(pipe)) {
|
||||||
|
if (s.action instanceof ActionStationRequestItems) {
|
||||||
|
for (IStatementParameter p : s.parameters) {
|
||||||
|
ActionParameterItemStack param = (ActionParameterItemStack) p;
|
||||||
|
|
||||||
|
if (param != null && !isBlacklisted(param.getItemStackToDraw())) {
|
||||||
|
StackRequest req = new StackRequest();
|
||||||
|
req.station = station;
|
||||||
|
req.stack = param.getItemStackToDraw();
|
||||||
|
|
||||||
|
return req;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class StationProviderFilter implements IStationFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(DockingStation station) {
|
||||||
|
return getOrderFromRequestingAction(station) != null
|
||||||
|
|| getOrderFromRequestingStation(station, false) != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,9 +18,7 @@ import net.minecraft.item.crafting.FurnaceRecipes;
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
import net.minecraft.item.crafting.ShapedRecipes;
|
import net.minecraft.item.crafting.ShapedRecipes;
|
||||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
|
||||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||||
|
|
||||||
|
@ -28,13 +26,11 @@ import buildcraft.api.boards.RedstoneBoardRobot;
|
||||||
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
import buildcraft.api.gates.ActionParameterItemStack;
|
import buildcraft.api.gates.ActionParameterItemStack;
|
||||||
import buildcraft.api.gates.IActionParameter;
|
import buildcraft.api.gates.IActionParameter;
|
||||||
import buildcraft.api.gates.IStatementParameter;
|
|
||||||
import buildcraft.api.recipes.CraftingResult;
|
import buildcraft.api.recipes.CraftingResult;
|
||||||
import buildcraft.api.recipes.IFlexibleRecipe;
|
import buildcraft.api.recipes.IFlexibleRecipe;
|
||||||
import buildcraft.api.robots.AIRobot;
|
import buildcraft.api.robots.AIRobot;
|
||||||
import buildcraft.api.robots.EntityRobotBase;
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
import buildcraft.api.robots.IDockingStation;
|
import buildcraft.api.robots.IDockingStation;
|
||||||
import buildcraft.api.robots.IRequestProvider;
|
|
||||||
import buildcraft.api.robots.StackRequest;
|
import buildcraft.api.robots.StackRequest;
|
||||||
import buildcraft.core.inventory.StackHelper;
|
import buildcraft.core.inventory.StackHelper;
|
||||||
import buildcraft.core.recipes.AssemblyRecipeManager;
|
import buildcraft.core.recipes.AssemblyRecipeManager;
|
||||||
|
@ -44,15 +40,12 @@ import buildcraft.core.robots.AIRobotCraftGeneric;
|
||||||
import buildcraft.core.robots.AIRobotCraftWorkbench;
|
import buildcraft.core.robots.AIRobotCraftWorkbench;
|
||||||
import buildcraft.core.robots.AIRobotDeliverRequested;
|
import buildcraft.core.robots.AIRobotDeliverRequested;
|
||||||
import buildcraft.core.robots.AIRobotGotoSleep;
|
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||||
|
import buildcraft.core.robots.AIRobotGotoStationAndUnload;
|
||||||
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
import buildcraft.core.robots.AIRobotGotoStationToUnload;
|
||||||
import buildcraft.core.robots.AIRobotSearchStation;
|
import buildcraft.core.robots.AIRobotSearchStackRequest;
|
||||||
import buildcraft.core.robots.AIRobotUnload;
|
import buildcraft.core.robots.AIRobotUnload;
|
||||||
import buildcraft.core.robots.DockingStation;
|
import buildcraft.core.robots.DockingStation;
|
||||||
import buildcraft.core.robots.IStationFilter;
|
|
||||||
import buildcraft.silicon.statements.ActionRobotCraft;
|
import buildcraft.silicon.statements.ActionRobotCraft;
|
||||||
import buildcraft.silicon.statements.ActionStationRequestItems;
|
|
||||||
import buildcraft.silicon.statements.ActionStationRequestItemsMachine;
|
|
||||||
import buildcraft.transport.Pipe;
|
|
||||||
import buildcraft.transport.gates.ActionIterator;
|
import buildcraft.transport.gates.ActionIterator;
|
||||||
import buildcraft.transport.gates.ActionSlot;
|
import buildcraft.transport.gates.ActionSlot;
|
||||||
|
|
||||||
|
@ -80,7 +73,7 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
|
||||||
|
|
||||||
// TODO: We should call load or drop, in order to clean items even
|
// TODO: We should call load or drop, in order to clean items even
|
||||||
// if no destination is to be found
|
// if no destination is to be found
|
||||||
startDelegateAI(new AIRobotGotoStationToUnload(robot, robot.getZoneToWork()));
|
startDelegateAI(new AIRobotGotoStationAndUnload(robot, robot.getZoneToWork()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +84,7 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (order == null) {
|
if (order == null) {
|
||||||
startDelegateAI(new AIRobotSearchStation(robot, new StationProviderFilter(), robot.getZoneToWork()));
|
startDelegateAI(new AIRobotSearchStackRequest(robot, craftingBlacklist));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,16 +134,12 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
|
||||||
} else {
|
} else {
|
||||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||||
}
|
}
|
||||||
} else if (ai instanceof AIRobotSearchStation) {
|
} else if (ai instanceof AIRobotSearchStackRequest) {
|
||||||
if (!ai.success()) {
|
if (!ai.success()) {
|
||||||
craftingBlacklist.clear();
|
craftingBlacklist.clear();
|
||||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||||
} else {
|
} else {
|
||||||
currentRequest = getOrderFromRequestingAction(((AIRobotSearchStation) ai).targetStation);
|
currentRequest = ((AIRobotSearchStackRequest) ai).request;
|
||||||
|
|
||||||
if (currentRequest == null) {
|
|
||||||
currentRequest = getOrderFromRequestingStation(((AIRobotSearchStation) ai).targetStation, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!currentRequest.station.take(robot)) {
|
if (!currentRequest.station.take(robot)) {
|
||||||
currentRequest = null;
|
currentRequest = null;
|
||||||
|
@ -237,81 +226,4 @@ public class BoardRobotCrafter extends RedstoneBoardRobot {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StackRequest getOrderFromRequestingStation(DockingStation station, boolean take) {
|
|
||||||
boolean actionFound = false;
|
|
||||||
|
|
||||||
Pipe pipe = station.getPipe().pipe;
|
|
||||||
|
|
||||||
for (ActionSlot s : new ActionIterator(pipe)) {
|
|
||||||
if (s.action instanceof ActionStationRequestItemsMachine) {
|
|
||||||
actionFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!actionFound) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 instanceof IRequestProvider) {
|
|
||||||
IRequestProvider provider = (IRequestProvider) nearbyTile;
|
|
||||||
|
|
||||||
for (int i = 0; i < provider.getNumberOfRequests(); ++i) {
|
|
||||||
StackRequest request = provider.getAvailableRequest(i);
|
|
||||||
|
|
||||||
if (request != null && !isBlacklisted(request.stack)) {
|
|
||||||
request.station = station;
|
|
||||||
|
|
||||||
if (take) {
|
|
||||||
if (provider.takeRequest(i, robot)) {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private StackRequest getOrderFromRequestingAction(DockingStation station) {
|
|
||||||
boolean actionFound = false;
|
|
||||||
|
|
||||||
Pipe pipe = station.getPipe().pipe;
|
|
||||||
|
|
||||||
for (ActionSlot s : new ActionIterator(pipe)) {
|
|
||||||
if (s.action instanceof ActionStationRequestItems) {
|
|
||||||
for (IStatementParameter p : s.parameters) {
|
|
||||||
ActionParameterItemStack param = (ActionParameterItemStack) p;
|
|
||||||
|
|
||||||
if (param != null && !isBlacklisted(param.getItemStackToDraw())) {
|
|
||||||
StackRequest req = new StackRequest();
|
|
||||||
req.station = station;
|
|
||||||
req.stack = param.getItemStackToDraw();
|
|
||||||
|
|
||||||
return req;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StationProviderFilter implements IStationFilter {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean matches(DockingStation station) {
|
|
||||||
return getOrderFromRequestingAction(station) != null
|
|
||||||
|| getOrderFromRequestingStation(station, false) != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
99
common/buildcraft/core/robots/boards/BoardRobotDelivery.java
Executable file
99
common/buildcraft/core/robots/boards/BoardRobotDelivery.java
Executable file
|
@ -0,0 +1,99 @@
|
||||||
|
/**
|
||||||
|
* 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 java.util.ArrayList;
|
||||||
|
|
||||||
|
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.api.robots.StackRequest;
|
||||||
|
import buildcraft.core.inventory.StackHelper;
|
||||||
|
import buildcraft.core.inventory.filters.IStackFilter;
|
||||||
|
import buildcraft.core.robots.AIRobotDeliverRequested;
|
||||||
|
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||||
|
import buildcraft.core.robots.AIRobotGotoStationAndLoad;
|
||||||
|
import buildcraft.core.robots.AIRobotGotoStationAndUnload;
|
||||||
|
import buildcraft.core.robots.AIRobotSearchStackRequest;
|
||||||
|
|
||||||
|
public class BoardRobotDelivery extends RedstoneBoardRobot {
|
||||||
|
|
||||||
|
private ArrayList<ItemStack> deliveryBlacklist = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
|
private StackRequest currentRequest = null;
|
||||||
|
|
||||||
|
public BoardRobotDelivery(EntityRobotBase iRobot) {
|
||||||
|
super(iRobot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RedstoneBoardRobotNBT getNBTHandler() {
|
||||||
|
return BoardRobotDeliveryNBT.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
if (robot.containsItems()) {
|
||||||
|
// Always makes sure that when starting a craft, the inventory is
|
||||||
|
// clean.
|
||||||
|
|
||||||
|
// TODO: We should call load or drop, in order to clean items even
|
||||||
|
// if no destination is to be found
|
||||||
|
startDelegateAI(new AIRobotGotoStationAndUnload(robot, robot.getZoneToWork()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentRequest == null) {
|
||||||
|
startDelegateAI(new AIRobotSearchStackRequest(robot, deliveryBlacklist));
|
||||||
|
} else {
|
||||||
|
startDelegateAI(new AIRobotGotoStationAndLoad(robot, new ReqFilter(), robot.getZoneToWork()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delegateAIEnded(AIRobot ai) {
|
||||||
|
if (ai instanceof AIRobotSearchStackRequest) {
|
||||||
|
if (!ai.success()) {
|
||||||
|
deliveryBlacklist.clear();
|
||||||
|
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||||
|
} else {
|
||||||
|
currentRequest = ((AIRobotSearchStackRequest) ai).request;
|
||||||
|
|
||||||
|
if (!currentRequest.station.take(robot)) {
|
||||||
|
currentRequest = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (ai instanceof AIRobotGotoStationAndLoad) {
|
||||||
|
if (!ai.success()) {
|
||||||
|
deliveryBlacklist.add(currentRequest.stack);
|
||||||
|
robot.releaseResources();
|
||||||
|
currentRequest = null;
|
||||||
|
} else {
|
||||||
|
startDelegateAI(new AIRobotDeliverRequested(robot, currentRequest));
|
||||||
|
}
|
||||||
|
} else if (ai instanceof AIRobotDeliverRequested) {
|
||||||
|
robot.releaseResources();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ReqFilter implements IStackFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(ItemStack stack) {
|
||||||
|
if (currentRequest == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return StackHelper.isMatchingItem(stack, currentRequest.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
common/buildcraft/core/robots/boards/BoardRobotDeliveryNBT.java
Executable file
64
common/buildcraft/core/robots/boards/BoardRobotDeliveryNBT.java
Executable file
|
@ -0,0 +1,64 @@
|
||||||
|
/**
|
||||||
|
* 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 java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.util.IIcon;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
|
import buildcraft.api.boards.RedstoneBoardRobot;
|
||||||
|
import buildcraft.api.boards.RedstoneBoardRobotNBT;
|
||||||
|
import buildcraft.api.robots.EntityRobotBase;
|
||||||
|
import buildcraft.core.DefaultProps;
|
||||||
|
import buildcraft.core.utils.StringUtils;
|
||||||
|
|
||||||
|
public final class BoardRobotDeliveryNBT extends RedstoneBoardRobotNBT {
|
||||||
|
|
||||||
|
public static BoardRobotDeliveryNBT instance = new BoardRobotDeliveryNBT();
|
||||||
|
|
||||||
|
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft",
|
||||||
|
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_delivery.png");
|
||||||
|
|
||||||
|
private IIcon icon;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) {
|
||||||
|
return new BoardRobotDelivery(robot);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourceLocation getRobotTexture() {
|
||||||
|
return TEXTURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getID() {
|
||||||
|
return "buildcraft:boardRobotDelivery";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
|
||||||
|
list.add(StringUtils.localize("buildcraft.boardRobotDelivery"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerIcons(IIconRegister iconRegister) {
|
||||||
|
icon = iconRegister.registerIcon("buildcraft:board_green");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IIcon getIcon(NBTTagCompound nbt) {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue