Search in sources :

Example 1 with PlayerInventoryLens

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

the class ContainerUtil method generateAdapterLens.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static Lens generateAdapterLens(final SlotLensProvider slots, final int index, final org.spongepowered.common.inventory.util.ContainerUtil.CraftingInventoryData crafting, final List<Slot> slotList, final net.minecraft.world.@Nullable Container subInventory) {
    Lens lens = ((InventoryBridge) subInventory).bridge$getAdapter().inventoryAdapter$getRootLens();
    if (lens instanceof PlayerInventoryLens) {
        if (slotList.size() == 36) {
            return new DelegatingLens(index, new PrimaryPlayerInventoryLens(0, slots, true), slots);
        }
        return lens;
    }
    // For Crafting Result we need the Slot to get Filter logic
    if (subInventory instanceof ResultContainer) {
        final Slot slot = slotList.get(0);
        if (slot instanceof ResultSlotAccessor) {
            crafting.out = index;
            if (crafting.base == null) {
                // In case we do not find the InventoryCrafting later assume it is directly after the SlotCrafting
                // e.g. for IC2 ContainerIndustrialWorkbench
                crafting.base = index + 1;
                crafting.grid = ((ResultSlotAccessor) slot).accessor$craftSlots();
            }
        }
    }
    if (subInventory instanceof CraftingContainer) {
        crafting.base = index;
        crafting.grid = ((CraftingContainer) subInventory);
    }
    return new DelegatingLens(index, slotList, lens, slots);
}
Also used : CraftingContainer(net.minecraft.world.inventory.CraftingContainer) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) ResultSlotAccessor(org.spongepowered.common.accessor.world.inventory.ResultSlotAccessor) Slot(net.minecraft.world.inventory.Slot) CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) PrimaryPlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens) GridInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.GridInventoryLens) ContainerLens(org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens) CompoundLens(org.spongepowered.common.inventory.lens.impl.CompoundLens) Lens(org.spongepowered.common.inventory.lens.Lens) SingleGridLens(org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) DelegatingLens(org.spongepowered.common.inventory.lens.impl.DelegatingLens) ResultContainer(net.minecraft.world.inventory.ResultContainer)

Example 2 with PlayerInventoryLens

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

the class InventoryMixin_Inventory_API method equipment.

@Override
public EquipmentInventory equipment() {
    if (this.api$equipment == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$equipment = (EquipmentInventoryAdapter) ((PlayerInventoryLens) lens).getEquipmentLens().getAdapter(fabric, this);
    }
    return this.api$equipment;
}
Also used : EquipmentInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter) PrimaryPlayerInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Example 3 with PlayerInventoryLens

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

the class ServerPlayerMixin_Inventory method impl$getSpongeSlot.

// -- small bridge-like methods
@SuppressWarnings("ConstantConditions")
@Override
protected Slot impl$getSpongeSlot(final EquipmentSlot equipmentSlot) {
    final EquipmentType equipmentType = (EquipmentType) (Object) equipmentSlot;
    final PlayerInventoryBridge inventory = (PlayerInventoryBridge) ((net.minecraft.server.level.ServerPlayer) (Object) this).inventory;
    final Lens lens = ((InventoryAdapter) inventory).inventoryAdapter$getRootLens();
    final Fabric fabric = ((InventoryAdapter) inventory).inventoryAdapter$getFabric();
    if (lens instanceof PlayerInventoryLens) {
        final SlotLens slotLens = ((PlayerInventoryLens) lens).getEquipmentLens().getSlotLens(equipmentType);
        return slotLens.getAdapter(fabric, (Inventory) inventory);
    }
    throw new IllegalStateException("Unknown Lens for Player Inventory: " + lens.getClass().getName());
}
Also used : PlayerInventoryBridge(org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens) Lens(org.spongepowered.common.inventory.lens.Lens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) EquipmentType(org.spongepowered.api.item.inventory.equipment.EquipmentType) Fabric(org.spongepowered.common.inventory.fabric.Fabric) SlotLens(org.spongepowered.common.inventory.lens.slots.SlotLens)

Example 4 with PlayerInventoryLens

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

the class InventoryMixin_Inventory_API method offhand.

@Override
public Slot offhand() {
    if (this.api$offhand == null && ((InventoryAdapter) this).inventoryAdapter$getRootLens() instanceof PlayerInventoryLens) {
        final Lens lens = ((InventoryAdapter) this).inventoryAdapter$getRootLens();
        final Fabric fabric = ((InventoryAdapter) this).inventoryAdapter$getFabric();
        this.api$offhand = (SlotAdapter) ((PlayerInventoryLens) lens).getOffhandLens().getAdapter(fabric, this);
    }
    return this.api$offhand;
}
Also used : EquipmentInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter) PrimaryPlayerInventoryAdapter(org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter) InventoryAdapter(org.spongepowered.common.inventory.adapter.InventoryAdapter) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens) Lens(org.spongepowered.common.inventory.lens.Lens) Fabric(org.spongepowered.common.inventory.fabric.Fabric)

Example 5 with PlayerInventoryLens

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

the class ContainerPlayerInventoryLens method lenses.

private static List<Lens> lenses(int size, SlotLensProvider slots) {
    // 1
    int base = ContainerPlayerInventoryLens.CRAFTING_OUTPUT;
    final CraftingInventoryLens crafting = new CraftingInventoryLens(0, base, ContainerPlayerInventoryLens.CRAFTING_GRID, ContainerPlayerInventoryLens.CRAFTING_GRID, slots);
    // 4
    base += ContainerPlayerInventoryLens.CRAFTING_GRID * ContainerPlayerInventoryLens.CRAFTING_GRID;
    final PlayerInventoryLens player = new PlayerInventoryLens(base, size - base, slots);
    return Arrays.asList(crafting, player);
}
Also used : CraftingInventoryLens(org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens) PlayerInventoryLens(org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens)

Aggregations

PlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.minecraft.PlayerInventoryLens)7 Lens (org.spongepowered.common.inventory.lens.Lens)6 InventoryAdapter (org.spongepowered.common.inventory.adapter.InventoryAdapter)5 Fabric (org.spongepowered.common.inventory.fabric.Fabric)5 EquipmentInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.EquipmentInventoryAdapter)4 PrimaryPlayerInventoryAdapter (org.spongepowered.common.inventory.adapter.impl.comp.PrimaryPlayerInventoryAdapter)4 CraftingInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.CraftingInventoryLens)2 CraftingContainer (net.minecraft.world.inventory.CraftingContainer)1 ResultContainer (net.minecraft.world.inventory.ResultContainer)1 Slot (net.minecraft.world.inventory.Slot)1 EquipmentType (org.spongepowered.api.item.inventory.equipment.EquipmentType)1 ResultSlotAccessor (org.spongepowered.common.accessor.world.inventory.ResultSlotAccessor)1 PlayerInventoryBridge (org.spongepowered.common.bridge.world.entity.player.PlayerInventoryBridge)1 CompoundLens (org.spongepowered.common.inventory.lens.impl.CompoundLens)1 DelegatingLens (org.spongepowered.common.inventory.lens.impl.DelegatingLens)1 GridInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.GridInventoryLens)1 PrimaryPlayerInventoryLens (org.spongepowered.common.inventory.lens.impl.comp.PrimaryPlayerInventoryLens)1 SingleGridLens (org.spongepowered.common.inventory.lens.impl.minecraft.SingleGridLens)1 ContainerLens (org.spongepowered.common.inventory.lens.impl.minecraft.container.ContainerLens)1 SlotLens (org.spongepowered.common.inventory.lens.slots.SlotLens)1