public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
assert mode != ChangeMode.RESET;
final ItemType t = delta == null ? null : (ItemType) delta[0];
final Item i = item != null ? item.getSingle(e) : null;
final Slot s = slot != null ? slot.getSingle(e) : null;
if (i == null && s == null)
return;
ItemStack is = i != null ? i.getItemStack() : s != null ? s.getItem() : null;
switch (mode) {
case SET:
assert t != null;
is = t.getRandom();
break;
case ADD:
case REMOVE:
case REMOVE_ALL:
assert t != null;
if (t.isOfType(is)) {
if (mode == ChangeMode.ADD)
is = t.addTo(is);
else if (mode == ChangeMode.REMOVE)
is = t.removeFrom(is);
else
is = t.removeAll(is);
}
break;
case DELETE:
is = null;
if (i != null)
i.remove();
break;
case RESET:
assert false;
}
if (i != null)
i.setItemStack(is);
else if (s != null)
s.setItem(is);
else
assert false;
}