use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class PipeItemsRequestLogistics method getProvidedItems.
/* IRequestAPI */
@Override
public List<ItemStack> getProvidedItems() {
if (stillNeedReplace()) {
return new ArrayList<>();
}
Map<ItemIdentifier, Integer> items = SimpleServiceLocator.logisticsManager.getAvailableItems(getRouter().getIRoutersByCost());
List<ItemStack> list = new ArrayList<>(items.size());
for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
ItemStack is = item.getKey().unsafeMakeNormalStack(item.getValue());
list.add(is);
}
return list;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class PipeItemsRequestLogistics method simulateRequest.
@Override
public SimulationResult simulateRequest(ItemStack wanted) {
final List<IResource> used = new ArrayList<>();
final List<IResource> missing = new ArrayList<>();
RequestTree.simulate(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {
@Override
public void handleMissingItems(List<IResource> items) {
missing.addAll(items);
}
@Override
public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
}
@Override
public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
used.addAll(items);
}
});
List<ItemStack> usedList = new ArrayList<>(used.size());
List<ItemStack> missingList = new ArrayList<>(missing.size());
for (IResource e : used) {
if (e instanceof ItemResource) {
usedList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
usedList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
for (IResource e : missing) {
if (e instanceof ItemResource) {
missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
} else if (e instanceof DictResource) {
missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
}
}
SimulationResult r = new SimulationResult();
r.used = usedList;
r.missing = missingList;
return r;
}
use of net.minecraft.item.ItemStack 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 net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class LogisticsTileGenericPipe method injectItem.
//@Override
//@ModDependentMethod(modId="BuildCraft|Transport")
@Override
public int injectItem(ItemStack payload, boolean doAdd, ForgeDirection from) {
if (LogisticsBlockGenericPipe.isValid(pipe) && pipe.transport != null && isPipeConnected(from)) {
if (doAdd && MainProxy.isServer(getWorldObj())) {
ItemStack leftStack = payload.copy();
int lastIterLeft;
do {
lastIterLeft = leftStack.stackSize;
LPTravelingItem.LPTravelingItemServer travelingItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(leftStack);
leftStack.stackSize = pipe.transport.injectItem(travelingItem, from.getOpposite());
} while (leftStack.stackSize != lastIterLeft && leftStack.stackSize != 0);
return payload.stackSize - leftStack.stackSize;
}
}
return 0;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method checkOneConnectedInv.
private boolean checkOneConnectedInv(IInventoryUtil inv, ForgeDirection dir) {
boolean contentchanged = false;
if (!itemsOnRoute.isEmpty()) {
// don't check the inventory if you don't want anything
List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
items.retainAll(inv.getItems());
Map<ItemIdentifier, Integer> amounts = null;
if (!items.isEmpty()) {
amounts = inv.getItemsAndCount();
}
for (ItemIdentifier ident : items) {
if (!amounts.containsKey(ident)) {
continue;
}
int itemAmount = amounts.get(ident);
List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
ItemRoutingInformation need = iterator.next();
if (need.getItem().getStackSize() <= itemAmount) {
if (!useEnergy(6)) {
return contentchanged;
}
ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
if (toSend == null) {
return contentchanged;
}
if (toSend.stackSize != need.getItem().getStackSize()) {
if (inv instanceof ITransactor) {
((ITransactor) inv).add(toSend, dir.getOpposite(), true);
} else {
container.getWorldObj().spawnEntityInWorld(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.xCoord, container.yCoord, container.zCoord));
}
new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
return contentchanged;
}
sendStack(need, dir);
// finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
iterator.remove();
contentchanged = true;
if (needs.isEmpty()) {
itemsOnRoute.remove(ident);
}
//Refresh Available Items
amounts = inv.getItemsAndCount();
if (amounts.containsKey(ident)) {
itemAmount = amounts.get(ident);
} else {
itemAmount = 0;
break;
}
}
}
}
}
return contentchanged;
}
Aggregations