Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ItemStack insertRoundRobin(ItemStack stack, boolean simulate, boolean global) {
- List<ItemRoutePath> routePaths = net.getNetData(pipe.getPipePos(), facing);
- if (routePaths.isEmpty())
- return stack;
- if (routePaths.size() == 1)
- return insert(routePaths.get(0), stack, simulate);
- List<ItemRoutePath> routePathsCopy = new ArrayList<>(routePaths);
- if (global) {
- stack = insertToHandlersEnhanced(routePathsCopy, stack, routePaths.size(), simulate);
- } else {
- FMLLog.warning(
- "11111111111111111111111111111111111111111111111111111111111111111111111111111111 first insertToHandlers call");
- stack = insertToHandlers(routePathsCopy, stack, simulate);
- if (!stack.isEmpty() && !routePathsCopy.isEmpty()) {
- FMLLog.warning(
- "222222222222222222222222222222222222222222222222222222222222222222222222222222 second insertToHandlers call");
- stack = insertToHandlers(routePathsCopy, stack, simulate);
- }
- }
- return stack;
- }
- /**
- * Inserts items equally to all handlers
- * if it couldn't insert all items, the handler will be removed
- *
- * @param copy to insert to
- * @param stack to insert
- * @param simulate simulate
- * @return remainder
- */
- private ItemStack insertToHandlers(List<ItemRoutePath> copy, ItemStack stack, boolean simulate) {
- FMLLog.warning("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV insertToHandlers begins ");
- Iterator<ItemRoutePath> routePathIterator = copy.listIterator();
- int insertedTotal = 0;
- FMLLog.warning("insertedTotal " + insertedTotal);
- int count = stack.getCount();
- FMLLog.warning("count " + count);
- int itemsPerHandler = count / copy.size();
- FMLLog.warning("itemsPerHandler " + itemsPerHandler);
- int initialRemainder = itemsPerHandler == 0 ? count % copy.size() : 0;
- FMLLog.warning("================================================================ iterations begin ");
- while (routePathIterator.hasNext()) {
- FMLLog.warning("--------------------------------------------------------------- iteration start ");
- ItemRoutePath routePath = routePathIterator.next();
- FMLLog.warning("facing " + routePath.toFacingPos().getFacing());
- int insertAmount = itemsPerHandler;
- FMLLog.warning("insertAmount set to " + insertAmount);
- if (initialRemainder > 0) {
- insertAmount++;
- initialRemainder--;
- }
- insertAmount = Math.min(insertAmount, stack.getCount() - insertedTotal);
- FMLLog.warning("insertAmount updated to " + insertAmount);
- if (insertAmount == 0) break;
- ItemStack toInsert = stack.copy();
- toInsert.setCount(insertAmount);
- FMLLog.warning("items in handler before insertion: " + routePath.getHandler().getStackInSlot(0).getCount() +
- " " + routePath.getHandler().getStackInSlot(0).getDisplayName());
- int insertRemainder = insert(routePath, toInsert, simulate).getCount(); // Try to insert the items
- FMLLog.warning("items in handler after insertion: " + routePath.getHandler().getStackInSlot(0).getCount() +
- " " + routePath.getHandler().getStackInSlot(0).getDisplayName());
- FMLLog.warning("insertRemainder " + insertRemainder);
- if (insertRemainder < insertAmount) { // if inserted anything
- insertedTotal += (insertAmount - insertRemainder);
- }
- FMLLog.warning("insertedTotal " + insertedTotal);
- if (insertRemainder == 1 && itemsPerHandler == 0 && insertAmount == 1) {
- initialRemainder++;
- }
- if (insertRemainder > 0) // if not inserted everything
- routePathIterator.remove();
- FMLLog.warning("--------------------------------------------------------------- iteration end ");
- }
- ItemStack outputRemainder = stack.copy();
- outputRemainder.setCount(count - insertedTotal);
- FMLLog.warning(
- "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ insertToHandlers ends, outputRemainder: " +
- outputRemainder.getCount() + " " + outputRemainder.getDisplayName());
- return outputRemainder;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement