Add slot type policies and contextual bauble lifecycle

This commit is contained in:
ABKQPO committed 2026-11-07 00:30:48 +08:00
1 parent 4ed16b03c8
commit ff835dfc79
24 files changed
+995 -169

No files matched your search

@@ -1,9 +1,10 @@
package baubles.common.container;
import baubles.api.BaubleType;
import baubles.api.IBauble;
import baubles.api.expanded.BaubleExpandedSlots;
import baubles.api.expanded.IBaubleExpanded;
import baubles.api.expanded.BaubleSlotType;
import baubles.api.expanded.BaubleSlotContext;
import baubles.common.BaubleSlotConfiguration;
import baubles.common.Baubles;
import baubles.common.BaublesConfig;
import baubles.common.ItemDebugger;
@@ -12,7 +13,6 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
@@ -40,36 +40,31 @@ public class SlotBauble extends Slot {
return slotType;
}
public InventoryBaubles getBaublesInventory() {
return inventory instanceof InventoryBaubles baubles ? baubles : null;
}
public BaubleSlotType getSlotDefinition() {
InventoryBaubles baubles = getBaublesInventory();
return baubles != null ? baubles.getSlotDefinition(slotType)
: BaubleSlotConfiguration.getDefinitions().getOrDefault(slotType, BaubleSlotType.defaults(slotType));
}
public boolean isCosmeticSlot() {
return false;
}
public boolean isSlotActive() {
InventoryBaubles baubles = getBaublesInventory();
return baubles == null || baubles.isSlotActive(getSlotIndex());
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack stack) {
if (stack == null || BaubleExpandedSlots.unknownType.equals(slotType)) {
return false;
}
Item item = stack.getItem();
if(!(item instanceof IBauble) || !((IBauble)item).canEquip(stack, ((InventoryBaubles)inventory).player.get())) {
return false;
}
String[] types;
if(item instanceof IBaubleExpanded) {
types = ((IBaubleExpanded)item).getBaubleTypes(stack);
} else {
BaubleType legacyType = ((IBauble)item).getBaubleType(stack);
types = new String[] {BaubleExpandedSlots.getTypeFromBaubleType(legacyType)};
}
if (types == null) return false;
for(String type : types) {
if (BaublesConfig.canTypeFitSlot(type, slotType)) {
return true;
}
}
return false;
return inventory.isItemValidForSlot(getSlotIndex(), stack);
}
@Override
@@ -84,25 +79,22 @@ public class SlotBauble extends Slot {
@Override
public boolean canTakeStack(EntityPlayer player) {
ItemStack itemStack = getStack();
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;
}
InventoryBaubles baubles = getBaublesInventory();
BaubleSlotContext context = baubles != null ? baubles.getSlotContext(getSlotIndex(), isCosmeticSlot())
: new BaubleSlotContext(player, slotType, getSlotIndex(), getSlotIndex(), false, true, true);
return itemStack != null && isSlotActive()
&& BaubleLifecycle.canUnequip(itemStack, context);
}
@Override
public int getSlotStackLimit() {
return BaublesConfig.getStackLimitForSlotType(slotType);
return getSlotDefinition().stackLimit();
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getBackgroundIconIndex() {
if (!getSlotDefinition().icon().isEmpty()) return null;
if (!BaublesConfig.useOldGuiRendering && BaubleExpandedSlots.unknownType.equals(slotType)) {
return null;
}