use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method equipment.
@Override
public EquipmentInventory equipment() {
if (this.api$equipment == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$equipment = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getEquipmentLens().getAdapter(fabric, this);
}
return this.api$equipment;
}
use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.
the class SlotMixin_Lens_Inventory method lensGeneratorBridge$generateLens.
@Override
public Lens lensGeneratorBridge$generateLens(SlotLensProvider slotLensProvider) {
try {
final Lens rootLens = ((InventoryAdapter) this.container).inventoryAdapter$getRootLens();
SlotLens lens = rootLens.getSlotLens(this.inventoryAdapter$getFabric(), this.slot);
if (lens != null) {
return lens;
}
} catch (Exception ignored) {
}
// this works as a fallback but removes Inventory Property Support completely
return new BasicSlotLens(0);
}
use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin_Inventory method impl$getSpongeSlot.
// -- small bridge-like methods
@SuppressWarnings("ConstantConditions")
@Override
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
final PlayerInventoryBridge inventory = (PlayerInventoryBridge) ((net.minecraft.server.level.ServerPlayer) (Object) this).inventory;
final Lens lens = ((InventoryAdapter) inventory).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) inventory).inventoryAdapter$getFabric();
if (lens instanceof PlayerInventoryLens) {
final SlotLens slotLens = ((PlayerInventoryLens) lens).getEquipmentLens().getSlotLens(equipmentType);
return slotLens.getAdapter(fabric, (Inventory) inventory);
}
throw new IllegalStateException("Unknown Lens for Player Inventory: " + lens.getClass().getName());
}
use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.
the class InventoryMixin_Inventory_API method offhand.
@Override
public Slot offhand() {
if (this.api$offhand == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
this.api$offhand = (SlotAdapter) ((PlayerInventoryLens) lens).getOffhandLens().getAdapter(fabric, this);
}
return this.api$offhand;
}
use of org.spongepowered.common.inventory.adapter.InventoryAdapter in project SpongeCommon by SpongePowered.
the class ReverseQuery method execute.
@Override
public Inventory execute(Inventory parent, InventoryAdapter inventory) {
List<Slot> slots = new ArrayList<>(((Inventory) inventory).slots());
Collections.reverse(slots);
CompoundSlotLensProvider slotProvider = new CompoundSlotLensProvider();
slots.forEach(s -> slotProvider.add((InventoryAdapter) s));
InventoryAdapter adapter = ((InventoryBridge) inventory).bridge$getAdapter();
CompoundLens lens = CompoundLens.builder().add(adapter.inventoryAdapter$getRootLens()).build(slotProvider);
return lens.getAdapter(adapter.inventoryAdapter$getFabric(), (Inventory) inventory);
}
Aggregations