use of buildcraft.api.inventory.IItemTransactor in project BuildCraft by BuildCraft.
the class ItemTransactorTester method testSimpleMoving.
@Test
public void testSimpleMoving() {
IItemTransactor trans = new ItemHandlerSimple(2, null);
Assert.assertTrue(trans.extract(null, 1, 1, false).isEmpty());
ItemStack insert = new ItemStack(Items.APPLE);
ItemStack leftOver = trans.insert(insert.copy(), false, false);
Assert.assertTrue(leftOver.isEmpty());
ItemStack extracted = trans.extract(null, 1, 1, false);
Assert.assertTrue(ItemStack.areItemStacksEqual(insert, extracted));
extracted = trans.extract(null, 1, 1, false);
Assert.assertTrue(extracted.isEmpty());
}
use of buildcraft.api.inventory.IItemTransactor in project BuildCraft by BuildCraft.
the class PipeFlowItems method tryExtractItems.
// IFlowItems
@Override
public int tryExtractItems(int count, EnumFacing from, EnumDyeColor colour, IStackFilter filter, boolean simulate) {
if (pipe.getHolder().getPipeWorld().isRemote) {
throw new IllegalStateException("Cannot extract items on the client side!");
}
if (from == null) {
return 0;
}
TileEntity tile = pipe.getConnectedTile(from);
IItemTransactor trans = ItemTransactorHelper.getTransactor(tile, from.getOpposite());
ItemStack possible = trans.extract(filter, 1, count, true);
if (possible.isEmpty()) {
return 0;
}
if (possible.getCount() > possible.getMaxStackSize()) {
possible.setCount(possible.getMaxStackSize());
count = possible.getMaxStackSize();
}
IPipeHolder holder = pipe.getHolder();
PipeEventItem.TryInsert tryInsert = new PipeEventItem.TryInsert(holder, this, colour, from, possible);
holder.fireEvent(tryInsert);
if (tryInsert.isCanceled() || tryInsert.accepted <= 0) {
return 0;
}
count = Math.min(count, tryInsert.accepted);
ItemStack stack = trans.extract(filter, count, count, simulate);
if (stack.isEmpty()) {
throw new IllegalStateException("The transactor " + trans + " returned an empty itemstack from a known good request!");
}
if (!simulate) {
insertItemEvents(stack, colour, EXTRACT_SPEED, from);
}
return count;
}
use of buildcraft.api.inventory.IItemTransactor in project BuildCraft by BuildCraft.
the class PipeFlowItems method onItemReachEnd.
private void onItemReachEnd(TravellingItem item) {
IPipeHolder holder = pipe.getHolder();
PipeEventItem.ReachEnd reachEnd = new PipeEventItem.ReachEnd(holder, this, item.colour, item.stack, item.side);
holder.fireEvent(reachEnd);
item.colour = reachEnd.colour;
item.stack = reachEnd.getStack();
ItemStack excess = item.stack;
if (excess.isEmpty()) {
return;
}
if (pipe.isConnected(item.side)) {
ConnectedType type = pipe.getConnectedType(item.side);
EnumFacing oppositeSide = item.side.getOpposite();
switch(type) {
case PIPE:
{
IPipe oPipe = pipe.getConnectedPipe(item.side);
if (oPipe == null) {
break;
}
PipeFlow flow = oPipe.getFlow();
if (flow instanceof IFlowItems) {
IFlowItems oFlow = (IFlowItems) flow;
ItemStack before = excess;
excess = oFlow.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
before.shrink(excess.getCount());
}
excess = fireEventEjectIntoPipe(oFlow, item.side, before, excess);
}
break;
}
case TILE:
{
TileEntity tile = pipe.getConnectedTile(item.side);
IInjectable injectable = ItemTransactorHelper.getInjectable(tile, oppositeSide);
ItemStack before = excess;
excess = injectable.injectItem(excess.copy(), true, oppositeSide, item.colour, item.speed);
if (!excess.isEmpty()) {
IItemTransactor transactor = ItemTransactorHelper.getTransactor(tile, oppositeSide);
excess = transactor.insert(excess, false, false);
}
excess = fireEventEjectIntoTile(tile, item.side, before, excess);
break;
}
}
}
if (excess.isEmpty()) {
return;
}
item.tried.add(item.side);
item.toCenter = true;
item.stack = excess;
item.genTimings(holder.getPipeWorld().getTotalWorldTime(), getPipeLength(item.side));
items.add(item.timeToDest, item);
sendItemDataToClient(item);
}
Aggregations