Advertisement
broken-arrow

Untitled

Feb 3rd, 2022
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.     static class CCHWrapperWrapperIteratorBig implements InventoryWrapperIterator {
  2.  
  3.         private final Location location;
  4.         private final InventoryholderStorageUnit holders;
  5.         private ItemStack lastItemStack;
  6.         private int amountRemaining;
  7.         private final int maxStackSize;
  8.         private final ContainerRegistryAPI registry = ContainerRegistryAPI.getInstance();
  9.  
  10.         public CCHWrapperWrapperIteratorBig(Location location, InventoryholderStorageUnit holders) {
  11.             this.location = location;
  12.             this.holders = holders;
  13.             this.amountRemaining = holders.getAmountInt();
  14.             lastItemStack = holders.getItemStack().clone();
  15.             this.maxStackSize = lastItemStack.getMaxStackSize();
  16.  
  17.  
  18.         }
  19.  
  20.         private void provideNextItemStack() {
  21.             StorageProxy.getInstance().getLogger().info("provideNextItemStack amunt  " + amountRemaining);
  22.  
  23.             if (amountRemaining == 0) {
  24.                 lastItemStack = null;
  25.             } else {
  26.                 int amountProvide = Math.min(maxStackSize, amountRemaining);
  27.                 lastItemStack.setAmount(amountProvide);
  28.                 amountRemaining -= amountProvide;
  29.  
  30.                 StorageProxy.getInstance().getLogger().info("provideNextItemStack after  " + amountRemaining + "  " + amountProvide);
  31.                 StorageProxy.getInstance().getLogger().info("provideNextItemStack after  " + lastItemStack);
  32.             }
  33.         }
  34.  
  35.         @Override
  36.         public void setCurrent(ItemStack itemStack) {
  37.             if (itemStack == null || itemStack.getType() == Material.AIR) {
  38.                 registry.subtractAmount(location, BigInteger.valueOf(lastItemStack.getAmount()));
  39.             } else if (lastItemStack.isSimilar(itemStack)) {
  40.                 int lastAmount = lastItemStack.getAmount();
  41.                 int nowAmount = itemStack.getAmount();
  42.                 if (lastAmount != nowAmount) {
  43.                     registry.subtractAmount(location, BigInteger.valueOf(Math.max(lastAmount, nowAmount) - Math.min(lastAmount, nowAmount)));
  44.                 }
  45.             } else throw new IllegalArgumentException("Not supported item " + itemStack);
  46.         }
  47.  
  48.         @Override
  49.         public boolean hasNext() {
  50.             return holders != null && lastItemStack != null;
  51.         }
  52.  
  53.         @Override
  54.         public ItemStack next() {
  55.             provideNextItemStack();
  56.             return lastItemStack.clone();
  57.         }
  58.  
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement