use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleCrafterMK3 method tick.
@Override
public void tick() {
super.tick();
if (inv.isEmpty()) {
return;
}
if (!_service.isNthTick(6)) {
return;
}
//Add from internal buffer
List<AdjacentTileEntity> crafters = locateCrafters();
boolean change = false;
for (AdjacentTileEntity adjacent : crafters) {
for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
ItemIdentifierStack slot = inv.getIDStackInSlot(i);
if (slot == null) {
continue;
}
ForgeDirection insertion = adjacent.direction.getOpposite();
if (getUpgradeManager().hasSneakyUpgrade()) {
insertion = getUpgradeManager().getSneakyOrientation();
}
ItemIdentifierStack toadd = slot.clone();
toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
slot.setStackSize(slot.getStackSize() - added.stackSize);
if (added.stackSize != 0) {
change = true;
}
} else {
_service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
change = true;
}
if (slot.getStackSize() <= 0) {
inv.clearInventorySlotContents(i);
} else {
inv.setInventorySlotContents(i, slot);
}
}
}
if (change) {
inv.markDirty();
_service.getCacheHolder().trigger(CacheTypes.Inventory);
}
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleElectricBuffer method tick.
@Override
public void tick() {
if (++currentTickCount < ticksToAction) {
return;
}
currentTickCount = 0;
IInventoryUtil inv = _service.getPointedInventory(true);
if (inv == null) {
return;
}
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack stack = inv.getStackInSlot(i);
if (stack == null) {
continue;
}
if (SimpleServiceLocator.IC2Proxy.isElectricItem(stack)) {
Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricManager);
if (reply == null) {
continue;
}
_service.spawnParticle(Particles.OrangeParticle, 2);
_service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
return;
}
continue;
}
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ItemParts method getSubItems.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void getSubItems(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
par3List.add(new ItemStack(this, 1, 0));
par3List.add(new ItemStack(this, 1, 1));
par3List.add(new ItemStack(this, 1, 2));
par3List.add(new ItemStack(this, 1, 3));
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleExtractor method tick.
@Override
public void tick() {
if (++currentTick < ticksToAction()) {
return;
}
currentTick = 0;
//Extract Item
IInventory realInventory = _service.getRealInventory();
if (realInventory == null) {
return;
}
ForgeDirection extractOrientation = _sneakyDirection;
if (extractOrientation == ForgeDirection.UNKNOWN) {
extractOrientation = _service.inventoryOrientation().getOpposite();
}
IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
ItemStack slot = targetUtil.getStackInSlot(i);
if (slot == null) {
continue;
}
ItemIdentifier slotitem = ItemIdentifier.get(slot);
List<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
if (reply == null) {
continue;
}
int itemsleft = itemsToExtract();
while (reply != null) {
int count = Math.min(itemsleft, slot.stackSize);
count = Math.min(count, slotitem.getMaxStackSize());
if (reply.getValue2().maxNumberOfItems > 0) {
count = Math.min(count, reply.getValue2().maxNumberOfItems);
}
while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
_service.spawnParticle(Particles.OrangeParticle, 2);
count--;
}
if (count <= 0) {
break;
}
ItemStack stackToSend = targetUtil.decrStackSize(i, count);
if (stackToSend == null || stackToSend.stackSize == 0) {
break;
}
count = stackToSend.stackSize;
_service.sendStack(stackToSend, reply, itemSendMode());
itemsleft -= count;
if (itemsleft <= 0) {
break;
}
slot = targetUtil.getStackInSlot(i);
if (slot == null) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
}
break;
}
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ModuleCCBasedQuickSort method handle.
private boolean handle(IInventoryUtil invUtil, int slot, List<CCSinkResponder> list) {
if (list.isEmpty()) {
return false;
}
ItemIdentifier ident = list.get(0).getStack().getItem();
ItemStack stack = invUtil.getStackInSlot(slot);
if (stack == null || !ItemIdentifier.get(stack).equals(ident)) {
return false;
}
final IRouter source = _service.getRouter();
List<Triplet<Integer, Double, CCSinkResponder>> posibilities = new ArrayList<>();
for (CCSinkResponder sink : list) {
if (!sink.isDone()) {
continue;
}
if (sink.getCanSink() < 1) {
continue;
}
IRouter r = SimpleServiceLocator.routerManager.getRouter(sink.getRouterId());
if (r == null) {
continue;
}
List<ExitRoute> ways = source.getDistanceTo(r);
double minDistance = Double.MAX_VALUE;
outer: for (ExitRoute route : ways) {
for (IFilter filter : route.filters) {
if (filter.blockRouting() || filter.isFilteredItem(ident) == filter.isBlocked()) {
continue outer;
}
}
minDistance = Math.min(route.distanceToDestination, minDistance);
}
if (minDistance != Integer.MAX_VALUE) {
posibilities.add(new Triplet<>(sink.getPriority(), minDistance, sink));
}
}
if (posibilities.isEmpty()) {
return false;
}
Collections.sort(posibilities, (o1, o2) -> {
int c = o2.getValue1() - o1.getValue1();
if (c != 0) {
return c;
}
double e = o1.getValue2() - o2.getValue2();
return e < 0 ? -1 : 1;
});
boolean sended = false;
for (Triplet<Integer, Double, CCSinkResponder> triple : posibilities) {
CCSinkResponder sink = triple.getValue3();
if (sink.getCanSink() < 0) {
continue;
}
stack = invUtil.getStackInSlot(slot);
if (stack == null || stack.stackSize <= 0) {
continue;
}
int amount = Math.min(stack.stackSize, sink.getCanSink());
ItemStack extracted = invUtil.decrStackSize(slot, amount);
_service.sendStack(extracted, sink.getRouterId(), ItemSendMode.Fast, null);
sended = true;
}
return sended;
}
Aggregations