Search in sources :

Example 1 with ReusableLens

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

the class MixinTraitAdapter method getReusableLens.

@SuppressWarnings("unchecked")
private ReusableLens<?> getReusableLens() {
    if (this.reusableLens != null) {
        return this.reusableLens;
    }
    if (this instanceof ReusableLensProvider) {
        return ((ReusableLensProvider<IInventory, ItemStack>) this).generateLens(this.getFabric(), this);
    }
    if (this instanceof LensProvider) {
        this.slots = ((LensProvider) this).slotProvider(this.getFabric(), this);
        Lens lens = ((LensProvider) this).rootLens(this.getFabric(), this);
        return new ReusableLens<>(this.slots, lens);
    }
    SlotCollection slots = new SlotCollection.Builder().add(this.getFabric().getSize()).build();
    Lens<IInventory, ItemStack> lens;
    if (this.getFabric().getSize() == 0) {
        lens = new DefaultEmptyLens<>(this);
    } else {
        lens = new OrderedInventoryLensImpl(0, this.getFabric().getSize(), 1, slots);
    }
    return new ReusableLens<>(slots, lens);
}
Also used : IInventory(net.minecraft.inventory.IInventory) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) ReusableLensProvider(org.spongepowered.common.item.inventory.lens.ReusableLensProvider) ReusableLens(org.spongepowered.common.item.inventory.lens.impl.ReusableLens) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) Lens(org.spongepowered.common.item.inventory.lens.Lens) ReusableLens(org.spongepowered.common.item.inventory.lens.impl.ReusableLens) ItemStack(net.minecraft.item.ItemStack) ReusableLensProvider(org.spongepowered.common.item.inventory.lens.ReusableLensProvider) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider)

Example 2 with ReusableLens

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

the class MixinTileEntityLockable method generateLens.

@Override
public ReusableLens<?> generateLens(Fabric<IInventory> fabric, InventoryAdapter<IInventory, ItemStack> adapter) {
    SlotCollection slots = new SlotCollection.Builder().add(this.getSizeInventory()).build();
    OrderedInventoryLensImpl lens = new OrderedInventoryLensImpl(0, this.getSizeInventory(), 1, slots);
    return new ReusableLens<>(slots, lens);
}
Also used : SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) ReusableLens(org.spongepowered.common.item.inventory.lens.impl.ReusableLens)

Aggregations

ReusableLens (org.spongepowered.common.item.inventory.lens.impl.ReusableLens)2 SlotCollection (org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection)2 OrderedInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl)2 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1 Lens (org.spongepowered.common.item.inventory.lens.Lens)1 LensProvider (org.spongepowered.common.item.inventory.lens.LensProvider)1 ReusableLensProvider (org.spongepowered.common.item.inventory.lens.ReusableLensProvider)1 DefaultEmptyLens (org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens)1