use of org.spongepowered.common.inventory.EmptyInventoryImpl 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);
}
use of org.spongepowered.common.inventory.EmptyInventoryImpl in project SpongeCommon by SpongePowered.
the class GridQuery method execute.
@Override
public Inventory execute(Inventory inventory, InventoryAdapter adapter) {
if (!(adapter instanceof GridInventoryAdapter)) {
return new EmptyInventoryImpl(inventory);
}
GridInventoryAdapter gridAdapter = (GridInventoryAdapter) adapter;
Vector2i max = gridAdapter.dimensions();
if (max.x() < this.offset.x() + this.size.x() && max.y() < this.offset.y() + this.size.y()) {
// queried grid does not fit inventory
return new EmptyInventoryImpl(inventory);
}
// Get slots for new grid
CompoundSlotLensProvider slotProvider = new CompoundSlotLensProvider();
for (int dy = 0; dy < this.size.y(); dy++) {
for (int dx = 0; dx < this.size.x(); dx++) {
slotProvider.add(gridAdapter.getSlotLens(this.offset.x() + dx, this.offset.y() + dy));
}
}
// build new grid lens
GridInventoryLens lens = new GridInventoryLens(0, this.size.x(), this.size.y(), slotProvider);
return new GridInventoryAdapter(adapter.inventoryAdapter$getFabric(), lens, inventory);
}
use of org.spongepowered.common.inventory.EmptyInventoryImpl in project SpongeCommon by SpongePowered.
the class AppendQuery method execute.
@Override
public Inventory execute(Inventory inventory, InventoryAdapter adapter) {
Inventory result = new EmptyInventoryImpl(inventory);
if (this.queryList.isEmpty()) {
return result;
}
List<Inventory> results = this.queryList.stream().map(q -> q.execute(inventory)).collect(Collectors.toList());
return new MultiInventoryAdapter(results);
}
Aggregations