use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class PipeItemsSatelliteLogistics method throttledUpdateEntity.
@Override
public void throttledUpdateEntity() {
super.throttledUpdateEntity();
if (_lostItems.isEmpty()) {
return;
}
final Iterator<ItemIdentifierStack> iterator = _lostItems.iterator();
while (iterator.hasNext()) {
ItemIdentifierStack stack = iterator.next();
int received = RequestTree.requestPartial(stack, (CoreRoutedPipe) container.pipe, null);
if (received > 0) {
if (received == stack.getStackSize()) {
iterator.remove();
} else {
stack.setStackSize(stack.getStackSize() - received);
}
}
}
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class PipeLogisticsChassi method registerExtras.
@Override
public void registerExtras(IPromise promise) {
if (!(promise instanceof LogisticsPromise)) {
throw new UnsupportedOperationException("Extra has to be an item for a chassis pipe");
}
ItemIdentifierStack stack = new ItemIdentifierStack(((LogisticsPromise) promise).item, ((LogisticsPromise) promise).numberOfItems);
_extras.add(new LogisticsItemOrder(new DictResource(stack, null), null, ResourceType.EXTRA, null));
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class PipeLogisticsChassi method onAllowedRemoval.
@Override
public void onAllowedRemoval() {
_moduleInventory.removeListener(this);
if (MainProxy.isServer(getWorld())) {
for (int i = 0; i < getChassiSize(); i++) {
LogisticsModule x = _module.getSubModule(i);
if (x instanceof ILegacyActiveModule) {
ILegacyActiveModule y = (ILegacyActiveModule) x;
y.onBlockRemoval();
}
}
for (int i = 0; i < _moduleInventory.getSizeInventory(); i++) {
ItemIdentifierStack ms = _moduleInventory.getIDStackInSlot(i);
if (ms != null) {
ItemStack s = ms.makeNormalStack();
ItemModuleInformationManager.saveInfotmation(s, getLogisticsModule().getSubModule(i));
_moduleInventory.setInventorySlotContents(i, s);
}
}
_moduleInventory.dropContents(getWorld(), getX(), getY(), getZ());
}
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class PipeFluidProvider method enabledUpdateEntity.
@Override
public void enabledUpdateEntity() {
super.enabledUpdateEntity();
if (!getFluidOrderManager().hasOrders(ResourceType.PROVIDER) || !isNthTick(6)) {
return;
}
LogisticsFluidOrder order = getFluidOrderManager().peekAtTopRequest(ResourceType.PROVIDER);
int amountToSend, attemptedAmount;
amountToSend = attemptedAmount = Math.min(order.getAmount(), 5000);
for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(false)) {
if (amountToSend <= 0) {
break;
}
boolean fallback = true;
if (SimpleServiceLocator.specialTankHandler.hasHandlerFor(pair.getValue1())) {
ISpecialTankHandler handler = SimpleServiceLocator.specialTankHandler.getTankHandlerFor(pair.getValue1());
if (handler instanceof ISpecialTankAccessHandler) {
fallback = false;
FluidStack drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, false);
if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
drained = ((ISpecialTankAccessHandler) handler).drainFrom(pair.getValue1(), order.getFluid(), amountToSend, true);
int amount = drained.amount;
amountToSend -= amount;
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
this.queueRoutedItem(item, pair.getValue2());
getFluidOrderManager().sendSuccessfull(amount, false, item);
if (amountToSend <= 0) {
break;
}
}
}
}
if (fallback) {
FluidTankInfo[] tanks = ((IFluidHandler) pair.getValue1()).getTankInfo(pair.getValue2().getOpposite());
if (tanks != null) {
for (FluidTankInfo tank : tanks) {
if (tank == null) {
continue;
}
FluidStack liquid;
if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
if (order.getFluid().equals(FluidIdentifier.get(liquid))) {
int amount = Math.min(liquid.amount, amountToSend);
FluidStack drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, false);
if (drained != null && drained.amount > 0 && order.getFluid().equals(FluidIdentifier.get(drained))) {
drained = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amount, true);
while (drained.amount < amountToSend) {
FluidStack addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, false);
if (addition != null && addition.amount > 0 && order.getFluid().equals(FluidIdentifier.get(addition))) {
addition = ((IFluidHandler) pair.getValue1()).drain(pair.getValue2().getOpposite(), amountToSend - drained.amount, true);
drained.amount += addition.amount;
} else {
break;
}
}
amount = drained.amount;
amountToSend -= amount;
ItemIdentifierStack stack = SimpleServiceLocator.logisticsFluidManager.getFluidContainer(drained);
IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stack);
item.setDestination(order.getRouter().getSimpleID());
item.setTransportMode(TransportMode.Active);
this.queueRoutedItem(item, pair.getValue2());
getFluidOrderManager().sendSuccessfull(amount, false, item);
if (amountToSend <= 0) {
break;
}
}
}
}
}
}
}
}
if (amountToSend >= attemptedAmount) {
getFluidOrderManager().sendFailed();
}
}
use of logisticspipes.utils.item.ItemIdentifierStack in project LogisticsPipes by RS485.
the class LogisticsCraftingTable method importFuzzyFlags.
@Override
public void importFuzzyFlags(TileEntity tile, ItemIdentifierInventory inventory, DictResource[] flags, DictResource output) {
if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
return;
}
LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
if (!bench.isFuzzy()) {
return;
}
for (int i = 0; i < bench.fuzzyFlags.length; i++) {
if (i >= flags.length) {
break;
}
flags[i].loadFromBitSet(bench.fuzzyFlags[i].getBitSet());
}
output.loadFromBitSet(bench.outputFuzzyFlags.getBitSet());
for (int i = 0; i < 9; i++) {
final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
if (stackInSlot == null) {
continue;
}
final ItemIdentifier itemInSlot = stackInSlot.getItem();
for (int j = i + 1; j < 9; j++) {
final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
if (stackInOtherSlot == null) {
continue;
}
if (itemInSlot.equals(stackInOtherSlot.getItem()) && flags[i].getBitSet().equals(flags[j].getBitSet())) {
stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
inventory.clearInventorySlotContents(j);
// clear
flags[j].loadFromBitSet(new BitSet());
}
}
inventory.setInventorySlotContents(i, stackInSlot);
}
for (int i = 0; i < 9; i++) {
if (inventory.getStackInSlot(i) != null) {
continue;
}
for (int j = i + 1; j < 9; j++) {
if (inventory.getStackInSlot(j) == null) {
continue;
}
inventory.setInventorySlotContents(i, inventory.getStackInSlot(j));
flags[i].loadFromBitSet(flags[j].getBitSet());
inventory.clearInventorySlotContents(j);
// clear
flags[j].loadFromBitSet(new BitSet());
break;
}
}
return;
}
Aggregations