Fix crash when unequipping non-Bauble item (#48)

Co-authored-by: Nikolay S. <nicksitnikov@gmail.com>
This commit is contained in:
Wilhelm SchusterandNikolay S. authored and GitHub committed 2026-11-03 21:38:53 -06:00
1 parent 1f6ed77f6d
commit b461473f30
3 files changed
+17 -9

No files matched your search

@@ -298,7 +298,7 @@ public class ContainerPlayerExpanded extends Container {
@Override
public void putStacksInSlots(ItemStack[] p_75131_1_) {
baubles.blockEvents=true;
baubles.blockEvents = true;
super.putStacksInSlots(p_75131_1_);
}
@@ -27,7 +27,7 @@ public class InventoryBaubles implements IInventory {
public ItemStack[] stackList;
private Container eventHandler;
public WeakReference<EntityPlayer> player;
public boolean blockEvents=false;
public boolean blockEvents = false;
public InventoryBaubles(EntityPlayer player) {
stackList = new ItemStack[BaubleExpandedSlots.slotsCurrentlyUsed()];
@@ -133,16 +133,16 @@ public class InventoryBaubles implements IInventory {
*/
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
if(!blockEvents && stackList[slot] != null) {
((IBauble)stackList[slot].getItem()).onUnequipped(stackList[slot], player.get());
if (!blockEvents && stackList[slot] != null && stackList[slot].getItem() instanceof IBauble bauble) {
bauble.onUnequipped(stackList[slot], player.get());
}
stackList[slot] = stack;
if(!blockEvents && stack != null && stack.getItem() instanceof IBauble) {
if(player.get()!=null) {
((IBauble) stack.getItem()).onEquipped(stack, player.get());
if (!blockEvents && stack != null && stack.getItem() instanceof IBauble bauble) {
if (player.get() != null) {
bauble.onEquipped(stack, player.get());
}
}
if(eventHandler != null) {
if (eventHandler != null) {
eventHandler.onCraftMatrixChanged(this);
}
syncSlotToClients(slot);
@@ -89,7 +89,15 @@ public class SlotBauble extends Slot {
@Override
public boolean canTakeStack(EntityPlayer player) {
ItemStack itemStack = getStack();
return itemStack != null && ((IBauble)itemStack.getItem()).canUnequip(itemStack, player);
if (itemStack == null) {
return false;
} else if (itemStack.getItem() instanceof IBauble bauble) {
return bauble.canUnequip(itemStack, player);
} else {
// Consider the rare case of an item that used to be a Bauble, but has this property later removed (no
// longer implements IBauble). The player should still be able to take it out of the slot.
return true;
}
}
@Override