Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class CCHWrapperWrapperIteratorBig implements InventoryWrapperIterator {
- private final Location location;
- private final InventoryholderStorageUnit holders;
- private ItemStack lastItemStack;
- private int amountRemaining;
- private final int maxStackSize;
- private final ContainerRegistryAPI registry = ContainerRegistryAPI.getInstance();
- public CCHWrapperWrapperIteratorBig(Location location, InventoryholderStorageUnit holders) {
- this.location = location;
- this.holders = holders;
- this.amountRemaining = holders.getAmountInt();
- lastItemStack = holders.getItemStack().clone();
- this.maxStackSize = lastItemStack.getMaxStackSize();
- }
- private void provideNextItemStack() {
- StorageProxy.getInstance().getLogger().info("provideNextItemStack amunt " + amountRemaining);
- if (amountRemaining == 0) {
- lastItemStack = null;
- } else {
- int amountProvide = Math.min(maxStackSize, amountRemaining);
- lastItemStack.setAmount(amountProvide);
- amountRemaining -= amountProvide;
- StorageProxy.getInstance().getLogger().info("provideNextItemStack after " + amountRemaining + " " + amountProvide);
- StorageProxy.getInstance().getLogger().info("provideNextItemStack after " + lastItemStack);
- }
- }
- @Override
- public void setCurrent(ItemStack itemStack) {
- if (itemStack == null || itemStack.getType() == Material.AIR) {
- registry.subtractAmount(location, BigInteger.valueOf(lastItemStack.getAmount()));
- } else if (lastItemStack.isSimilar(itemStack)) {
- int lastAmount = lastItemStack.getAmount();
- int nowAmount = itemStack.getAmount();
- if (lastAmount != nowAmount) {
- registry.subtractAmount(location, BigInteger.valueOf(Math.max(lastAmount, nowAmount) - Math.min(lastAmount, nowAmount)));
- }
- } else throw new IllegalArgumentException("Not supported item " + itemStack);
- }
- @Override
- public boolean hasNext() {
- return holders != null && lastItemStack != null;
- }
- @Override
- public ItemStack next() {
- provideNextItemStack();
- return lastItemStack.clone();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement