Skip to content

Commit

Permalink
Guard against negative slot indexes. Fix crash with Botania (but stil…
Browse files Browse the repository at this point in the history
…l doesn't work right)
  • Loading branch information
jaquadro committed Oct 18, 2014
1 parent 581ecd7 commit ea47e67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public ItemStack getReadOnlyItemStack () {
}

public ItemStack getNewItemStack () {
if (protoStack == null)
if (protoStack == nullStack)
return null;

return protoStack.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public int getSizeInventory () {

@Override
public ItemStack getStackInSlot (int slot) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return null;

ItemStack stack = getItemsFromSlot(slot, getItemStackSize(slot));
Expand All @@ -478,7 +478,7 @@ public ItemStack getStackInSlot (int slot) {

@Override
public ItemStack decrStackSize (int slot, int count) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return null;

ItemStack stack = takeItemsFromSlot(slot, count);
Expand All @@ -495,7 +495,7 @@ public ItemStack getStackInSlotOnClosing (int slot) {

@Override
public void setInventorySlotContents (int slot, ItemStack itemStack) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return;

int insertCount = itemStack.stackSize;
Expand Down Expand Up @@ -551,7 +551,7 @@ public void closeInventory () {

@Override
public boolean isItemValidForSlot (int slot, ItemStack itemStack) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return false;

if (!isSlotValid(0))
Expand Down Expand Up @@ -581,7 +581,7 @@ public int[] getAccessibleSlotsFromSide (int side) {

@Override
public boolean canInsertItem (int slot, ItemStack stack, int side) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return false;

for (int aside : autoSides) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public int getSizeInventory () {

@Override
public ItemStack getStackInSlot (int slot) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return null;

ItemStack stack = getItemsFromSlot(slot, getItemStackSize(slot));
Expand All @@ -237,7 +237,7 @@ public ItemStack getStackInSlot (int slot) {

@Override
public ItemStack decrStackSize (int slot, int count) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return null;

ItemStack stack = takeItemsFromSlot(slot, count);
Expand All @@ -254,7 +254,7 @@ public ItemStack getStackInSlotOnClosing (int slot) {

@Override
public void setInventorySlotContents (int slot, ItemStack itemStack) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return;

int insertCount = itemStack.stackSize;
Expand Down Expand Up @@ -310,7 +310,7 @@ public void closeInventory () {

@Override
public boolean isItemValidForSlot (int slot, ItemStack itemStack) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return false;

if (data[slot].getItem() == null)
Expand Down Expand Up @@ -341,7 +341,7 @@ public int[] getAccessibleSlotsFromSide (int side) {

@Override
public boolean canInsertItem (int slot, ItemStack stack, int side) {
if (slot >= getSizeInventory())
if (slot < 0 || slot >= getSizeInventory())
return false;

for (int aside : autoSides) {
Expand Down

0 comments on commit ea47e67

Please sign in to comment.