use of org.spongepowered.common.inventory.adapter.impl.comp.GridInventoryAdapter 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);
}
Aggregations