Search in sources :

Example 1 with QueryLens

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

the class SpongeQuery method toResult.

protected Inventory toResult(Inventory inventory, Fabric fabric, Map<Lens, Integer> matches) {
    if (matches.isEmpty()) {
        return new EmptyInventoryImpl(inventory);
    }
    if (matches.size() == 1) {
        final Map.Entry<Lens, Integer> entry = matches.entrySet().iterator().next();
        if (entry.getValue() == 0) {
            return entry.getKey().getAdapter(fabric, inventory);
        }
        final LensRegistrar.BasicSlotLensProvider slotProvider = new LensRegistrar.BasicSlotLensProvider(entry.getKey().slotCount());
        // TODO check correct slotprovider
        final DelegatingLens delegate = new DelegatingLens(entry.getValue(), entry.getKey(), slotProvider);
        return delegate.getAdapter(fabric, inventory);
    }
    final QueryLens lens = new QueryLens(matches, this);
    return lens.getAdapter(fabric, inventory);
}
Also used : LensRegistrar(org.spongepowered.common.inventory.lens.impl.LensRegistrar) EmptyInventoryImpl(org.spongepowered.common.inventory.EmptyInventoryImpl) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) QueriedSlotLens(org.spongepowered.common.inventory.lens.impl.slot.QueriedSlotLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) QueryLens(org.spongepowered.common.inventory.lens.impl.QueryLens) Lens(org.spongepowered.common.inventory.lens.Lens) DelegatingSlotLens(org.spongepowered.common.inventory.lens.impl.slot.DelegatingSlotLens) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) QueryLens(org.spongepowered.common.inventory.lens.impl.QueryLens)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 EmptyInventoryImpl (org.spongepowered.common.inventory.EmptyInventoryImpl)1 Lens (org.spongepowered.common.inventory.lens.Lens)1 DelegatingLens (org.spongepowered.common.inventory.lens.impl.DelegatingLens)1 LensRegistrar (org.spongepowered.common.inventory.lens.impl.LensRegistrar)1 QueryLens (org.spongepowered.common.inventory.lens.impl.QueryLens)1 DelegatingSlotLens (org.spongepowered.common.inventory.lens.impl.slot.DelegatingSlotLens)1 QueriedSlotLens (org.spongepowered.common.inventory.lens.impl.slot.QueriedSlotLens)1 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)1