Skip to content

Commit

Permalink
Correct wrong item list usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Dec 2, 2021
1 parent 98fbceb commit 160ae47
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -113,11 +114,33 @@ public boolean isInUse() {
}

private @NotNull ItemStack getRawItem(int i) {
return super.getItem(i);
if (i < 0) {
return ItemStack.EMPTY;
}

NonNullList<ItemStack> list;
for (Iterator<NonNullList<ItemStack>> iterator = this.compartments.iterator(); iterator.hasNext(); i -= list.size()) {
list = iterator.next();
if (i < list.size()) {
return list.get(i);
}
}

return ItemStack.EMPTY;
}

private void setRawItem(int i, @NotNull ItemStack itemStack) {
super.setItem(i, itemStack);
if (i < 0) {
return;
}

NonNullList<ItemStack> list;
for (Iterator<NonNullList<ItemStack>> iterator = this.compartments.iterator(); iterator.hasNext(); i -= list.size()) {
list = iterator.next();
if (i < list.size()) {
list.set(i, itemStack);
}
}
}

private static record IndexedCompartment(@Nullable NonNullList<ItemStack> compartment, int index) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -113,11 +114,33 @@ public boolean isInUse() {
}

private @NotNull ItemStack getRawItem(int i) {
return super.getItem(i);
if (i < 0) {
return ItemStack.EMPTY;
}

NonNullList<ItemStack> list;
for (Iterator<NonNullList<ItemStack>> iterator = this.compartments.iterator(); iterator.hasNext(); i -= list.size()) {
list = iterator.next();
if (i < list.size()) {
return list.get(i);
}
}

return ItemStack.EMPTY;
}

private void setRawItem(int i, @NotNull ItemStack itemStack) {
super.setItem(i, itemStack);
if (i < 0) {
return;
}

NonNullList<ItemStack> list;
for (Iterator<NonNullList<ItemStack>> iterator = this.compartments.iterator(); iterator.hasNext(); i -= list.size()) {
list = iterator.next();
if (i < list.size()) {
list.set(i, itemStack);
}
}
}

private static record IndexedCompartment(@Nullable NonNullList<ItemStack> compartment, int index) {}
Expand Down

0 comments on commit 160ae47

Please sign in to comment.