diff --git a/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/BWInventory.java b/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/BWInventory.java index 84cd9e0ba..9c390f533 100644 --- a/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/BWInventory.java +++ b/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/BWInventory.java @@ -41,9 +41,9 @@ public Optional get(int slot) { } @Override - public boolean set(int slot, Optional item) { + public boolean set(int slot, Item item) { Optional orig = get(slot); - wrapped.setInventorySlotContents(slot, item.map(ItemConverter.instance()::toNative).orElse(null)); + wrapped.setInventorySlotContents(slot, ItemConverter.instance().toNative(item)); return !orig.equals(get(slot)); } diff --git a/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/FWInventory.java b/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/FWInventory.java index 194051d3c..42412c013 100644 --- a/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/FWInventory.java +++ b/minecraft/1.7.10/src/main/java/nova/core/wrapper/mc/forge/v1_7_10/wrapper/inventory/FWInventory.java @@ -27,8 +27,6 @@ import nova.core.component.inventory.InventorySimple; import nova.core.wrapper.mc.forge.v1_7_10.wrapper.item.ItemConverter; -import java.util.Optional; - public class FWInventory implements IInventory { public final Inventory wrapped; @@ -70,7 +68,7 @@ public ItemStack getStackInSlotOnClosing(int slot) { @Override public void setInventorySlotContents(int slot, ItemStack item) { if (slot < 0 || slot >= wrapped.size()) return; - wrapped.set(slot, Optional.ofNullable(item).map(ItemConverter.instance()::toNova)); + wrapped.set(slot, item == null ? null : ItemConverter.instance().toNova(item)); } @Override diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/BWInventory.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/BWInventory.java index ac3922731..575faa81e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/BWInventory.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/BWInventory.java @@ -41,9 +41,9 @@ public Optional get(int slot) { } @Override - public boolean set(int slot, Optional item) { + public boolean set(int slot, Item item) { Optional orig = get(slot); - wrapped.setInventorySlotContents(slot, item.map(ItemConverter.instance()::toNative).orElse(null)); + wrapped.setInventorySlotContents(slot, ItemConverter.instance().toNative(item)); return !orig.equals(get(slot)); } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/FWInventory.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/FWInventory.java index 3377365f0..1e3e87314 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/FWInventory.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v1_8/wrapper/inventory/FWInventory.java @@ -28,8 +28,6 @@ import nova.core.component.inventory.InventorySimple; import nova.core.wrapper.mc.forge.v1_8.wrapper.item.ItemConverter; -import java.util.Optional; - public class FWInventory implements IInventory { public Inventory wrapped; @@ -73,7 +71,7 @@ public ItemStack getStackInSlotOnClosing(int slot) { @Override public void setInventorySlotContents(int slot, ItemStack item) { if (slot < 0 || slot >= wrapped.size()) return; - wrapped.set(slot, Optional.ofNullable(item).map(ItemConverter.instance()::toNova)); + wrapped.set(slot, item == null ? null : ItemConverter.instance().toNova(item)); } @Override diff --git a/src/main/java/nova/core/component/inventory/Inventory.java b/src/main/java/nova/core/component/inventory/Inventory.java index e70dfb10b..71fdebfaa 100644 --- a/src/main/java/nova/core/component/inventory/Inventory.java +++ b/src/main/java/nova/core/component/inventory/Inventory.java @@ -47,7 +47,7 @@ public interface Inventory extends Iterable { * @throws IndexOutOfBoundsException if the slot is out of range * (index < 0 || index >= size()) */ - Optional get(int slot); + Optional get(int slot) throws IndexOutOfBoundsException; /** * Sets {@link Item} in slot @@ -57,7 +57,7 @@ public interface Inventory extends Iterable { * @throws IndexOutOfBoundsException if the slot is out of range * (index < 0 || index >= size()) */ - boolean set(int slot, Optional item); + boolean set(int slot, Item item) throws IndexOutOfBoundsException; /** * Gets count of slots @@ -78,8 +78,11 @@ public interface Inventory extends Iterable { * @throws IndexOutOfBoundsException if the slot is out of range * (index < 0 || index >= size()) */ - default Optional add(int slot, Item item) { + default Optional add(int slot, Item item) throws IndexOutOfBoundsException { Optional o = get(slot); + if (item == null) { + return Optional.empty(); + } if (o.isPresent()) { if (item.sameItemType(o.get())) { return Optional.of(item.withAmount(item.count() - o.get().addCount(item.count()))); @@ -87,7 +90,7 @@ default Optional add(int slot, Item item) { return Optional.of(item); } } else { - set(slot, Optional.of(item)); + set(slot, item); return Optional.empty(); } } @@ -98,6 +101,9 @@ default Optional add(int slot, Item item) { * @return Amount of items left(did not fit inside this inventory) */ default Optional add(Item item) { + if (item == null) { + return Optional.empty(); + } int itemsLeft = item.count(); for (int i = 0; i < size(); i++) { itemsLeft = add(i, item.withAmount(itemsLeft)).map(Item::count).orElse(0); @@ -122,7 +128,7 @@ default Optional add(Item item) { * @throws IndexOutOfBoundsException if the slot is out of range * (index < 0 || index >= size()) */ - Optional remove(int slot); + Optional remove(int slot) throws IndexOutOfBoundsException; /** * Removes a certain amount of items from a slot. @@ -132,7 +138,7 @@ default Optional add(Item item) { * @throws IndexOutOfBoundsException if the slot is out of range * (index < 0 || index >= size()) */ - default Optional remove(int slot, int amount) { + default Optional remove(int slot, int amount) throws IndexOutOfBoundsException { Optional o = get(slot); if (o.isPresent()) { Item item = o.get(); @@ -148,15 +154,18 @@ default Optional remove(int slot, int amount) { /** * Removes a certain item from a slot. - * @param check The item type to check with + * @param item The item type to check with * @return The items removed */ - default Optional remove(Item check) { - int left = check.count(); + default Optional remove(Item item) { + if (item == null) { + return Optional.empty(); + } + int left = item.count(); for (int i = 0; i < size(); i++) { Optional opItem = get(i); - if (opItem.isPresent() && check.sameItemType(opItem.get())) { + if (opItem.isPresent() && item.sameItemType(opItem.get())) { Optional removed = remove(i, left); if (removed.isPresent()) { @@ -165,9 +174,9 @@ default Optional remove(Item check) { } } - int removed = check.count() - left; + int removed = item.count() - left; if (removed > 0) { - return Optional.of(check.withAmount(removed)); + return Optional.of(item.withAmount(removed)); } return Optional.empty(); } diff --git a/src/main/java/nova/core/component/inventory/InventorySimple.java b/src/main/java/nova/core/component/inventory/InventorySimple.java index f45deb33b..6121ba084 100644 --- a/src/main/java/nova/core/component/inventory/InventorySimple.java +++ b/src/main/java/nova/core/component/inventory/InventorySimple.java @@ -86,15 +86,15 @@ public Optional get(int slot) throws IndexOutOfBoundsException { } @Override - public boolean set(int slot, Optional item) throws IndexOutOfBoundsException { + public boolean set(int slot, Item item) throws IndexOutOfBoundsException { if (slot < 0 || slot >= items.length) { throw new IndexOutOfBoundsException(); - } else if (!item.filter(i -> isItemValidForSlot.apply(slot, i)).isPresent()) { + } else if (isItemValidForSlot.apply(slot, item)) { return false; } else { - boolean result = (items[slot] != item.orElse(null)); + boolean result = (items[slot] != item); changed |= result; - items[slot] = item.get(); + items[slot] = item; return result; } } @@ -109,7 +109,7 @@ public Optional remove(int slot) throws IndexOutOfBoundsException { return Optional.ofNullable(item); } - public Optional swap(int slot, Optional item) throws IndexOutOfBoundsException { + public Optional swap(int slot, Item item) throws IndexOutOfBoundsException { if (slot < 0 || slot >= items.length) { throw new IndexOutOfBoundsException(); } diff --git a/src/main/java/nova/core/component/inventory/InventoryView.java b/src/main/java/nova/core/component/inventory/InventoryView.java index 9008d7e00..e32947c85 100644 --- a/src/main/java/nova/core/component/inventory/InventoryView.java +++ b/src/main/java/nova/core/component/inventory/InventoryView.java @@ -50,7 +50,7 @@ public Optional get(int slot) throws IndexOutOfBoundsException { } @Override - public boolean set(int slot, Optional stack) throws IndexOutOfBoundsException { + public boolean set(int slot, Item stack) throws IndexOutOfBoundsException { if (slot < 0 || slot >= slots.length) { throw new IndexOutOfBoundsException(); } else {