Search in sources :

Example 1 with Vector2i

use of org.spongepowered.math.vector.Vector2i in project SpongeCommon by SpongePowered.

the class Inventory2DLens method init.

private void init(SlotLensProvider slots) {
    for (int y = 0, slot = this.base; y < this.height; y++) {
        for (int x = 0; x < this.width; x++, slot += this.stride) {
            SlotLens slotLens = slots.getSlotLens(slot);
            this.addChild(slotLens, KeyValuePair.of(Keys.SLOT_POSITION, new Vector2i(this.xBase + x, this.yBase + y)));
        }
    }
}
Also used : Vector2i(org.spongepowered.math.vector.Vector2i) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 2 with Vector2i

use of org.spongepowered.math.vector.Vector2i 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);
}
Also used : GridInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.GridInventoryAdapter) GridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.GridInventoryLens) CompoundSlotLensProvider(org.spongepowered.common.inventory.lens.CompoundSlotLensProvider) EmptyInventoryImpl(org.spongepowered.common.inventory.EmptyInventoryImpl) Vector2i(org.spongepowered.math.vector.Vector2i)

Aggregations

Vector2i (org.spongepowered.math.vector.Vector2i)2 EmptyInventoryImpl (org.spongepowered.common.inventory.EmptyInventoryImpl)1 GridInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.GridInventoryAdapter)1 CompoundSlotLensProvider (org.spongepowered.common.inventory.lens.CompoundSlotLensProvider)1 GridInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.GridInventoryLens)1 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)1