mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-10-25 20:22:23 +00:00
Fix crash when removing inventory from Inventory Panel network (#243)
This commit is contained in:
1 parent
84052a1c42
commit
503b90a5d0
2 files changed
+43
-38
No files matched your search
@@ -6,6 +6,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -425,7 +427,7 @@ public class NetworkedInventory {
|
||||
return inv;
|
||||
}
|
||||
|
||||
public ISidedInventory getInventoryRecheck() {
|
||||
public @Nullable ISidedInventory getInventoryRecheck() {
|
||||
if (isInvalid()) {
|
||||
updateInventory();
|
||||
}
|
||||
|
||||
@@ -16,50 +16,53 @@ class NormalInventory extends AbstractInventory {
|
||||
@Override
|
||||
int scanInventory(InventoryDatabaseServer db) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices == null || slotIndices.length == 0) {
|
||||
setEmpty(db);
|
||||
return 0;
|
||||
}
|
||||
int count = slotIndices.length;
|
||||
if (count != slotKeys.length) {
|
||||
reset(db, count);
|
||||
}
|
||||
for (int slot = 0; slot < count; slot++) {
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack != null && !inv.canExtractItem(invSlot, stack, side)) {
|
||||
stack = null;
|
||||
if (inv != null) {
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices != null && slotIndices.length > 0) {
|
||||
int count = slotIndices.length;
|
||||
if (count != slotKeys.length) {
|
||||
reset(db, count);
|
||||
}
|
||||
for (int slot = 0; slot < count; slot++) {
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack != null && !inv.canExtractItem(invSlot, stack, side)) {
|
||||
stack = null;
|
||||
}
|
||||
updateSlot(db, slot, stack);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
updateSlot(db, slot, stack);
|
||||
}
|
||||
return count;
|
||||
|
||||
setEmpty(db);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractItem(InventoryDatabaseServer db, ItemEntry entry, int slot, int count) {
|
||||
ISidedInventory inv = ni.getInventoryRecheck();
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices == null || slot >= slotIndices.length) {
|
||||
return 0;
|
||||
if (inv != null) {
|
||||
int side = ni.getInventorySide();
|
||||
int[] slotIndices = inv.getAccessibleSlotsFromSide(side);
|
||||
if (slotIndices != null && slot < slotIndices.length) {
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack != null && inv.canExtractItem(invSlot, stack, side)
|
||||
&& db.lookupItem(stack, entry, false) == entry) {
|
||||
int remaining = stack.stackSize;
|
||||
if (count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
ni.itemExtracted(invSlot, count);
|
||||
remaining -= count;
|
||||
updateCount(db, slot, entry, remaining);
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
int invSlot = slotIndices[slot];
|
||||
ItemStack stack = inv.getStackInSlot(invSlot);
|
||||
if (stack == null || !inv.canExtractItem(invSlot, stack, side)) {
|
||||
return 0;
|
||||
}
|
||||
if (db.lookupItem(stack, entry, false) != entry) {
|
||||
return 0;
|
||||
}
|
||||
int remaining = stack.stackSize;
|
||||
if (count > remaining) {
|
||||
count = remaining;
|
||||
}
|
||||
ni.itemExtracted(invSlot, count);
|
||||
remaining -= count;
|
||||
updateCount(db, slot, entry, remaining);
|
||||
return count;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user