Search in sources :

Example 1 with SingleIndexedLens

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

the class LensRegistrar method generateLens.

@SuppressWarnings("unchecked")
private static Lens generateLens(Object inventory, int size, SlotLensProvider slotLensProvider) {
    if (size == 0) {
        return new DefaultEmptyLens();
    }
    LensFactory lensFactory = LensRegistrar.lensFactories.get(inventory.getClass());
    Lens lens = null;
    if (lensFactory != null) {
        lens = lensFactory.apply(inventory.getClass(), size, slotLensProvider);
        if (lens != null) {
            return lens;
        }
    }
    if (inventory instanceof CraftingContainer) {
        lens = LensRegistrar.lensCraftingInventory(size, ((CraftingContainer) inventory).getWidth(), ((CraftingContainer) inventory).getHeight(), slotLensProvider);
    } else if (inventory instanceof AbstractContainerMenu) {
        lens = ContainerUtil.generateLens(((AbstractContainerMenu) inventory), slotLensProvider);
    } else if (size == 1) {
        return slotLensProvider.getSlotLens(0);
    }
    if (lens != null) {
        return lens;
    }
    return new SingleIndexedLens(0, size, (Class<? extends Inventory>) inventory.getClass(), slotLensProvider);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) BasicSlotLens(org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens) CraftingGridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingGridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) BrewingStandInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.BrewingStandInventoryLens) FurnaceInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.FurnaceInventoryLens) ContainerPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens) LargeChestInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.LargeChestInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens) SingleIndexedLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens)

Aggregations

AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 Lens (org.spongepowered.common.inventory.lens.Lens)1 CraftingGridInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.CraftingGridInventoryLens)1 CraftingInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens)1 PrimaryPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens)1 BrewingStandInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.BrewingStandInventoryLens)1 FurnaceInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.FurnaceInventoryLens)1 LargeChestInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.LargeChestInventoryLens)1 SingleGridLens (org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens)1 SingleIndexedLens (org.spongepowered.common.inventory.lens.impl.minecraft.SingleIndexedLens)1 ContainerLens (org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens)1 ContainerPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerPlayerInventoryLens)1 BasicSlotLens (org.spongepowered.common.inventory.lens.impl.slot.BasicSlotLens)1 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)1