use of logisticspipes.utils.SidedInventoryMinecraftAdapter in project LogisticsPipes by RS485.
the class ModuleCrafter method spaceFor.
protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
if (cache != null) {
int count = (Integer) cache;
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
if (invDirPair.getValue1() instanceof ISidedInventory) {
invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
}
if (getUpgradeManager().hasSneakyUpgrade()) {
invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
}
IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
return inv.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
_service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
use of logisticspipes.utils.SidedInventoryMinecraftAdapter in project LogisticsPipes by RS485.
the class ModuleSatellite method spaceFor.
private int spaceFor(ItemIdentifier item, boolean includeInTransit) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(pipe.container);
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> {
IInventory inv = (IInventory) adjacent.tileEntity;
if (inv instanceof net.minecraft.inventory.ISidedInventory) {
inv = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) inv, adjacent.direction.getOpposite(), false);
}
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, adjacent.direction);
return util.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
if (includeInTransit) {
count -= pipe.countOnRoute(item);
}
return count;
}
use of logisticspipes.utils.SidedInventoryMinecraftAdapter in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method getAdaptedInventoryUtil.
private IInventoryUtil getAdaptedInventoryUtil(AdjacentTileEntity adjacent) {
IInventory base = (IInventory) adjacent.tileEntity;
if (base instanceof net.minecraft.inventory.ISidedInventory) {
base = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) base, adjacent.direction.getOpposite(), true);
}
ExtractionMode mode = getExtractionMode();
switch(mode) {
case LeaveFirst:
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), false, false, 1, 0);
case LeaveLast:
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), false, false, 0, 1);
case LeaveFirstAndLast:
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), false, false, 1, 1);
case Leave1PerStack:
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), true, false, 0, 0);
case Leave1PerType:
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), false, true, 0, 0);
default:
break;
}
return SimpleServiceLocator.inventoryUtilFactory.getHidingInventoryUtil(base, adjacent.direction.getOpposite(), false, false, 0, 0);
}
use of logisticspipes.utils.SidedInventoryMinecraftAdapter in project LogisticsPipes by RS485.
the class PipeTransportLogistics method handleTileReachedServer_internal.
protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
if (remainingItem != null) {
getRoutedPipe().getRouter().update(true, getRoutedPipe());
this.injectItem(remainingItem, dir);
}
return;
}
if (getPipe() instanceof PipeItemsFluidSupplier) {
((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
return;
}
}
markChunkModified(tile);
if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
}
if (getPipe() instanceof FluidRoutedPipe) {
if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
return;
}
}
boolean isSpecialConnectionInformationTransition = false;
if (MainProxy.isServer(getWorld())) {
if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
isSpecialConnectionInformationTransition = true;
SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
}
}
if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
if (passToNextPipe(arrivingItem, tile)) {
return;
}
} else if (tile instanceof IInventory && isRouted) {
getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
// items.scheduleRemoval(arrivingItem);
if (MainProxy.isServer(getWorld())) {
// destroy the item on exit if it isn't exitable
if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
return;
}
// last chance for chassi to back out
if (arrivingItem != null) {
if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
reverseItem(arrivingItem);
return;
}
}
ISlotUpgradeManager slotManager;
{
ModulePositionType slot = null;
int positionInt = -1;
if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
slot = ModulePositionType.SLOT;
} else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
System.out.println(arrivingItem);
new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
}
slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
}
boolean tookSome = false;
if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
IInventory inv = (IInventory) tile;
if (inv instanceof ISidedInventory) {
inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
}
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
if (util instanceof ISpecialInsertion) {
int slot = information.getTargetSlot();
int amount = information.getAmount();
if (util.getSizeInventory() > slot) {
ItemStack content = util.getStackInSlot(slot);
ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
if (toAdd.stackSize > 0) {
if (util.getSizeInventory() > slot) {
int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
arrivingItem.getItemIdentifierStack().lowerStackSize(added);
if (added > 0) {
tookSome = true;
}
}
}
}
if (information.isLimited()) {
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
reverseItem(arrivingItem);
}
return;
}
}
}
// sneaky insertion
if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
ForgeDirection insertion = arrivingItem.output.getOpposite();
if (slotManager.hasSneakyUpgrade()) {
insertion = slotManager.getSneakyOrientation();
}
ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
tookSome = true;
arrivingItem.setBufferCounter(0);
}
ItemRoutingInformation info;
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
// we have some leftovers, we are splitting the stack, we need to clone the info
info = arrivingItem.getInfo().clone();
// For InvSysCon
info.getItem().setStackSize(added.stackSize);
insertedItemStack(info, tile);
} else {
info = arrivingItem.getInfo();
info.getItem().setStackSize(added.stackSize);
// For InvSysCon
insertedItemStack(info, tile);
// every item has been inserted.
return;
}
} else {
ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
for (ForgeDirection insertion : dirs) {
if (insertion == null) {
continue;
}
ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
if (added.stackSize > 0) {
tookSome = true;
arrivingItem.setBufferCounter(0);
}
ItemRoutingInformation info;
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
// we have some leftovers, we are splitting the stack, we need to clone the info
info = arrivingItem.getInfo().clone();
// For InvSysCon
info.getItem().setStackSize(added.stackSize);
insertedItemStack(info, tile);
} else {
info = arrivingItem.getInfo();
info.getItem().setStackSize(added.stackSize);
// For InvSysCon
insertedItemStack(info, tile);
// every item has been inserted.
return;
}
}
}
if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
reverseItem(arrivingItem);
}
}
// the item is handled
return;
}
// end of insert into IInventory
dropItem(arrivingItem);
}
Aggregations