Advertisement
Guest User

Untitled

a guest
Jul 21st, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | Source Code | 0 0
  1.     public ItemStack insertRoundRobin(ItemStack stack, boolean simulate, boolean global) {
  2.         List<ItemRoutePath> routePaths = net.getNetData(pipe.getPipePos(), facing);
  3.         if (routePaths.isEmpty())
  4.             return stack;
  5.         if (routePaths.size() == 1)
  6.             return insert(routePaths.get(0), stack, simulate);
  7.         List<ItemRoutePath> routePathsCopy = new ArrayList<>(routePaths);
  8.  
  9.         if (global) {
  10.             stack = insertToHandlersEnhanced(routePathsCopy, stack, routePaths.size(), simulate);
  11.         } else {
  12.             FMLLog.warning(
  13.                     "11111111111111111111111111111111111111111111111111111111111111111111111111111111 first insertToHandlers call");
  14.             stack = insertToHandlers(routePathsCopy, stack, simulate);
  15.             if (!stack.isEmpty() && !routePathsCopy.isEmpty()) {
  16.                 FMLLog.warning(
  17.                         "222222222222222222222222222222222222222222222222222222222222222222222222222222 second insertToHandlers call");
  18.                 stack = insertToHandlers(routePathsCopy, stack, simulate);
  19.             }
  20.         }
  21.  
  22.         return stack;
  23.     }
  24.  
  25.     /**
  26.      * Inserts items equally to all handlers
  27.      * if it couldn't insert all items, the handler will be removed
  28.      *
  29.      * @param copy     to insert to
  30.      * @param stack    to insert
  31.      * @param simulate simulate
  32.      * @return remainder
  33.      */
  34.     private ItemStack insertToHandlers(List<ItemRoutePath> copy, ItemStack stack, boolean simulate) {
  35.         FMLLog.warning("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV insertToHandlers begins ");
  36.         Iterator<ItemRoutePath> routePathIterator = copy.listIterator();
  37.         int insertedTotal = 0;
  38.         FMLLog.warning("insertedTotal " + insertedTotal);
  39.         int count = stack.getCount();
  40.         FMLLog.warning("count " + count);
  41.         int itemsPerHandler = count / copy.size();
  42.         FMLLog.warning("itemsPerHandler " + itemsPerHandler);
  43.         int initialRemainder = itemsPerHandler == 0 ? count % copy.size() : 0;
  44.         FMLLog.warning("================================================================ iterations begin ");
  45.         while (routePathIterator.hasNext()) {
  46.             FMLLog.warning("--------------------------------------------------------------- iteration start ");
  47.             ItemRoutePath routePath = routePathIterator.next();
  48.             FMLLog.warning("facing " + routePath.toFacingPos().getFacing());
  49.             int insertAmount = itemsPerHandler;
  50.             FMLLog.warning("insertAmount set to " + insertAmount);
  51.             if (initialRemainder > 0) {
  52.                 insertAmount++;
  53.                 initialRemainder--;
  54.             }
  55.             insertAmount = Math.min(insertAmount, stack.getCount() - insertedTotal);
  56.             FMLLog.warning("insertAmount updated to " + insertAmount);
  57.             if (insertAmount == 0) break;
  58.             ItemStack toInsert = stack.copy();
  59.             toInsert.setCount(insertAmount);
  60.             FMLLog.warning("items in handler before insertion: " + routePath.getHandler().getStackInSlot(0).getCount() +
  61.                     " " + routePath.getHandler().getStackInSlot(0).getDisplayName());
  62.             int insertRemainder = insert(routePath, toInsert, simulate).getCount(); // Try to insert the items
  63.             FMLLog.warning("items in handler after insertion: " + routePath.getHandler().getStackInSlot(0).getCount() +
  64.                     " " + routePath.getHandler().getStackInSlot(0).getDisplayName());
  65.             FMLLog.warning("insertRemainder " + insertRemainder);
  66.             if (insertRemainder < insertAmount) { // if inserted anything
  67.                 insertedTotal += (insertAmount - insertRemainder);
  68.             }
  69.             FMLLog.warning("insertedTotal " + insertedTotal);
  70.             if (insertRemainder == 1 && itemsPerHandler == 0 && insertAmount == 1) {
  71.                 initialRemainder++;
  72.             }
  73.             if (insertRemainder > 0) // if not inserted everything
  74.                 routePathIterator.remove();
  75.             FMLLog.warning("--------------------------------------------------------------- iteration end ");
  76.         }
  77.  
  78.         ItemStack outputRemainder = stack.copy();
  79.         outputRemainder.setCount(count - insertedTotal);
  80.         FMLLog.warning(
  81.                 "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ insertToHandlers ends, outputRemainder: " +
  82.                         outputRemainder.getCount() + " " + outputRemainder.getDisplayName());
  83.         return outputRemainder;
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement