use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.
the class ActionRobotFilterTool method getGateFilterStacks.
public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
ArrayList<ItemStack> result = new ArrayList<>();
for (StatementSlot slot : station.getActiveActions()) {
if (slot.statement instanceof ActionRobotFilterTool) {
for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) {
StatementParameterItemStack param = (StatementParameterItemStack) p;
ItemStack stack = param.getItemStack();
if (stack != null) {
result.add(stack);
}
}
}
}
}
return result;
}
use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.
the class ActionRobotGotoStation method actionActivate.
@Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
IRobotRegistry registry = RobotManager.registryProvider.getRegistry(container.getTile().getWorld());
List<DockingStation> stations = RobotUtils.getStations(container.getTile());
for (DockingStation station : stations) {
if (station.robotTaking() != null) {
EntityRobot robot = (EntityRobot) station.robotTaking();
AIRobot ai = robot.getOverridingAI();
if (ai != null) {
continue;
}
DockingStation newStation = station;
if (parameters[0] != null) {
newStation = getStation((StatementParameterItemStack) parameters[0], registry);
}
if (newStation != null) {
robot.overrideAI(new AIRobotGoAndLinkToDock(robot, newStation));
}
}
}
}
use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.
the class ActionRobotGotoStation method getStation.
private DockingStation getStation(StatementParameterItemStack stackParam, IRobotRegistry registry) {
ItemStack item = stackParam.getItemStack();
if (item != null && item.getItem() instanceof IMapLocation) {
IMapLocation map = (IMapLocation) item.getItem();
BlockPos index = map.getPoint(item);
if (index != null) {
EnumFacing side = map.getPointSide(item);
DockingStation paramStation = registry.getStation(index, side);
if (paramStation != null) {
return paramStation;
}
}
}
return null;
}
use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.
the class TriggerInventoryLevel method isTriggerActive.
@Override
public boolean isTriggerActive(TileEntity tile, EnumFacing side, IStatementContainer container, IStatementParameter[] parameters) {
IItemHandler itemHandler = tile.getCapability(CapUtil.CAP_ITEMS, side.getOpposite());
if (itemHandler == null) {
return false;
}
IItemHandlerFiltered filters = ObjectUtilBC.castOrNull(itemHandler, IItemHandlerFiltered.class);
StatementParameterItemStack param = getParam(0, parameters, new StatementParameterItemStack());
ItemStack searchStack = param.getItemStack();
int itemSpace = 0;
int foundItems = 0;
for (int slot = 0; slot < itemHandler.getSlots(); slot++) {
ItemStack stackInSlot = itemHandler.getStackInSlot(slot);
if (stackInSlot.isEmpty()) {
if (searchStack.isEmpty()) {
itemSpace += itemHandler.getSlotLimit(slot);
} else {
if (searchStack.getItem() instanceof IList) {
// Unfortunately lists are too generic to work properly
// without a simple filtered inventory.
ItemStack filter = filters == null ? ItemStack.EMPTY : filters.getFilter(slot);
if (StackUtil.matchesStackOrList(searchStack, filter)) {
itemSpace += Math.min(filter.getMaxStackSize(), itemHandler.getSlotLimit(slot));
}
} else {
ItemStack stack = searchStack.copy();
int count = Math.min(itemHandler.getSlotLimit(slot), searchStack.getMaxStackSize());
stack.setCount(count);
ItemStack leftOver = itemHandler.insertItem(slot, stack, true);
if (leftOver.isEmpty()) {
itemSpace += count;
} else {
itemSpace += count - leftOver.getCount();
}
}
}
} else {
if (searchStack.isEmpty() || StackUtil.matchesStackOrList(searchStack, stackInSlot)) {
itemSpace += Math.min(stackInSlot.getMaxStackSize(), itemHandler.getSlotLimit(slot));
foundItems += stackInSlot.getCount();
}
}
}
if (itemSpace > 0) {
float percentage = foundItems / (float) itemSpace;
return percentage < type.level;
}
return false;
}
use of buildcraft.api.statements.StatementParameterItemStack in project BuildCraft by BuildCraft.
the class ActionRobotFilter method getGateFilterStacks.
public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
ArrayList<ItemStack> result = new ArrayList<>();
for (StatementSlot slot : station.getActiveActions()) {
if (slot.statement instanceof ActionRobotFilter) {
for (IStatementParameter p : slot.parameters) {
if (p != null && p instanceof StatementParameterItemStack) {
StatementParameterItemStack param = (StatementParameterItemStack) p;
ItemStack stack = param.getItemStack();
if (stack != null) {
result.add(stack);
}
}
}
}
}
return result;
}
Aggregations