public int delete(ItemStack template, int amount) { Key key = Key.of(template); Element e = _elements.get(key); log.debug("take", "template", template, "key", key, "e", e); if (e == null) return 0; int taken = e.take(amount); _total = Math.max(0, _total - taken); return taken; }
public boolean allowed(ItemStack stack) { log.trace("allowed", "template", stack, "size", stack == null ? 0 : stack.stackSize); Key key = Key.of(stack); Element e = _elements.get(key); if (e == null || !e.whitelisted()) return false; if (e.count() + stack.stackSize > _maxPerKey) return false; if (_total + stack.stackSize > _maxTotal) return false; return true; }
public void deny(ItemStack template) { Key key = Key.of(template); Element e = _elements.get(key); log.debug("deny", "template", template, "key", key, "e", e); if (e == null || !e.whitelisted()) return; log.debug("deny: whitelisted: removing...", "empty", e.empty()); e.whitelisted(false); _whitelist.remove(key); if (e.empty()) _elements.remove(key); }
/** Inserts the target stack and returns what didn't fit. */ public ItemStack put(ItemStack stack) { int amount = Math.min(_max - _size, stack.stackSize); if (amount <= 0) return stack; Key k = Key.of(stack); Integer current = _elements.get(k); _elements.put(k, current == null ? amount : current + amount); _size += amount; stack.splitStack(amount); return stack.stackSize > 0 ? stack : null; }
public ItemStack take(ItemStack template, int amount) { Key k = Key.of(template); Integer count = _elements.get(k); if (count == null) return null; ItemStack stack = k.stack().copy(); stack.stackSize = Math.min(stack.getMaxStackSize(), Math.min(SLOT_STACK_LIMIT, Math.min(amount, count))); _size -= stack.stackSize; if (stack.stackSize >= count) _elements.remove(k); else _elements.put(k, count - stack.stackSize); return stack; }
public ItemStack put(ItemStack stack) { log.debug("put", "stack", stack, "size", stack.stackSize); if (stack == null) return null; Key key = Key.of(stack); Element e = _elements.get(key); if (e == null) return stack; int amount = stack.stackSize; amount = Math.min(amount, _maxTotal - _total); amount = e.put(amount, _maxPerKey); if (amount == 0) return stack; _total += amount; log.debug("put: done", "amount", amount); return stack.splitStack(amount); }
public boolean allow(ItemStack template) { log.debug("allow", "template", template); if (_whitelist.size() >= _maxKeys) return false; Key key = Key.of(template); Element e = _elements.get(key); if (e == null) { e = Element.of(key, 0, true); _elements.put(key, e); _whitelist.add(key); } else if (!e.whitelisted()) { e.whitelisted(true); _whitelist.add(key); } return true; }
public boolean has(ItemStack template) { Key key = Key.of(template); Element e = _elements.get(key); log.debug("has", "template", template, "key", key, "e", e); return e != null && !e.empty(); }
public static Key fromNbt(NBTTagCompound tag) { return Key.of(ItemHelper.readItemStackFromNBT(tag)); }