Search in sources :

Example 1 with CompoundLens

use of org.spongepowered.common.inventory.lens.impl.CompoundLens in project SpongeCommon by SpongePowered.

the class UnionQuery method execute.

@Override
public Inventory execute(Inventory inventory, InventoryAdapter adapter) {
    final CompoundLens.Builder lensBuilder = CompoundLens.builder().add(adapter.inventoryAdapter$getRootLens());
    final CompoundFabric fabric = new CompoundFabric(adapter.inventoryAdapter$getFabric(), ((InventoryBridge) this.other).bridge$getAdapter().inventoryAdapter$getFabric());
    final CompoundSlotLensProvider provider = new CompoundSlotLensProvider().add(adapter);
    for (final Inventory inv : this.other.children()) {
        lensBuilder.add(((InventoryAdapter) inv).inventoryAdapter$getRootLens());
        provider.add((InventoryAdapter) inv);
    }
    final CompoundLens lens = lensBuilder.build(provider);
    return lens.getAdapter(fabric, inventory);
}
Also used : CompoundFabric(org.spongepowered.common.inventory.fabric.CompoundFabric) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) CompoundSlotLensProvider(org.spongepowered.common.inventory.lens.CompoundSlotLensProvider) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 2 with CompoundLens

use of org.spongepowered.common.inventory.lens.impl.CompoundLens 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);
}
Also used : InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) InventoryBridge(org.spongepowered.common.bridge.world.inventory.InventoryBridge) ArrayList(java.util.ArrayList) Slot(org.spongepowered.api.item.inventory.Slot) CompoundSlotLensProvider(org.spongepowered.common.inventory.lens.CompoundSlotLensProvider) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens)

Aggregations

InventoryBridge (org.spongepowered.common.bridge.world.inventory.InventoryBridge)2 CompoundSlotLensProvider (org.spongepowered.common.inventory.lens.CompoundSlotLensProvider)2 CompoundLens (org.spongepowered.common.inventory.lens.impl.CompoundLens)2 ArrayList (java.util.ArrayList)1 Inventory (org.spongepowered.api.item.inventory.Inventory)1 Slot (org.spongepowered.api.item.inventory.Slot)1 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)1 CompoundFabric (org.spongepowered.common.inventory.fabric.CompoundFabric)1