Skip to content

Commit

Permalink
Account for mods that can shuffle inventories
Browse files Browse the repository at this point in the history
Also fix NPE
  • Loading branch information
DrParadox7 committed Sep 25, 2023
1 parent 70a4376 commit 12d5ad3
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import invtweaks.api.container.ChestContainer;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.inventory.InventoryPersonalChest;
import mekanism.common.inventory.slot.SlotPersonalChest;
import mekanism.common.tile.TileEntityPersonalChest;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -90,8 +91,15 @@ public boolean canInteractWith(EntityPlayer entityplayer)
if(isBlock) {
return tileEntity.isUseableByPlayer(entityplayer);
} else {
return slot == entityplayer.inventory.currentItem;
if (slot == entityplayer.inventory.currentItem && itemInventory instanceof InventoryPersonalChest) {
ItemStack currentHeldItem = entityplayer.getHeldItem();
ItemStack stack = ((InventoryPersonalChest) itemInventory).getStack();

if (stack != null)
return stack == currentHeldItem;
}
}
return false;
}

@Override
Expand Down Expand Up @@ -143,7 +151,7 @@ public ItemStack slotClick(int slotNumber, int destSlot, int modifier, EntityPla
{
ItemStack itemStack = player.inventory.getStackInSlot(destSlot);

if(MachineType.get(itemStack) == MachineType.PERSONAL_CHEST)
if(itemStack != null && MachineType.get(itemStack) == MachineType.PERSONAL_CHEST)
{
return null;
}
Expand Down

0 comments on commit 12d5ad3

Please sign in to comment.