Search in sources :

Example 1 with MainPlayerInventoryLensImpl

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

the class ContainerUtil method generateAdapterLens.

@Nullable
private static Lens<IInventory, ItemStack> generateAdapterLens(SlotProvider<IInventory, ItemStack> slots, int index, CraftingInventoryData crafting, List<Slot> slotList, @Nullable IInventory subInventory) {
    if (!(subInventory instanceof InventoryAdapter)) {
        return null;
    }
    Lens<IInventory, ItemStack> adapterLens = ((InventoryAdapter) subInventory).getRootLens();
    if (adapterLens == null) {
        return null;
    }
    if (subInventory.getSizeInventory() == 0) {
        return new DefaultEmptyLens<>(((InventoryAdapter) subInventory));
    }
    if (adapterLens instanceof PlayerInventoryLens) {
        if (slotList.size() == 36) {
            return new DelegatingLens(index, new MainPlayerInventoryLensImpl(index, slots, true), slots);
        }
        return null;
    }
    // For Crafting Result we need the Slot to get Filter logic
    if (subInventory instanceof InventoryCraftResult) {
        Slot slot = slotList.get(0);
        adapterLens = new CraftingOutputSlotLensImpl(index, item -> slot.isItemValid(((ItemStack) item)), itemType -> (slot.isItemValid((ItemStack) org.spongepowered.api.item.inventory.ItemStack.of(itemType, 1))));
        crafting.out = index;
        if (slot instanceof SlotCrafting) {
            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 = ((SlotCrafting) slot).craftMatrix;
            }
        }
    }
    if (subInventory instanceof InventoryCrafting) {
        crafting.base = index;
        crafting.grid = ((InventoryCrafting) subInventory);
    }
    return new DelegatingLens(index, adapterLens, slots);
}
Also used : IInventory(net.minecraft.inventory.IInventory) MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) MinecraftFabric(org.spongepowered.common.item.inventory.lens.impl.MinecraftFabric) LargeChestInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.LargeChestInventoryLens) Random(java.util.Random) ContainerChest(net.minecraft.inventory.ContainerChest) ContainerWorkbench(net.minecraft.inventory.ContainerWorkbench) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) PhaseData(org.spongepowered.common.event.tracking.PhaseData) CustomContainer(org.spongepowered.common.item.inventory.custom.CustomContainer) BlockCarrier(org.spongepowered.api.item.inventory.BlockCarrier) Map(java.util.Map) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) AbstractChestHorse(net.minecraft.entity.passive.AbstractChestHorse) EntityItem(net.minecraft.entity.item.EntityItem) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) ContainerBeacon(net.minecraft.inventory.ContainerBeacon) Location(org.spongepowered.api.world.Location) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) InventoryHelper(net.minecraft.inventory.InventoryHelper) Collection(java.util.Collection) GridInventoryLens(org.spongepowered.common.item.inventory.lens.comp.GridInventoryLens) Carrier(org.spongepowered.api.item.inventory.Carrier) Collectors(java.util.stream.Collectors) SlotCrafting(net.minecraft.inventory.SlotCrafting) InventoryArchetype(org.spongepowered.api.item.inventory.InventoryArchetype) InventoryBasic(net.minecraft.inventory.InventoryBasic) BrewingStandInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.BrewingStandInventoryLens) List(java.util.List) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) CraftingOutputAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.CraftingOutputAdapter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ContainerDispenser(net.minecraft.inventory.ContainerDispenser) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) Optional(java.util.Optional) MixinInventoryHelper(org.spongepowered.common.mixin.core.inventory.MixinInventoryHelper) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider) ContainerRepair(net.minecraft.inventory.ContainerRepair) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) ContainerMerchant(net.minecraft.inventory.ContainerMerchant) SpongeImpl(org.spongepowered.common.SpongeImpl) GridInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.GridInventoryLensImpl) AbstractHorse(net.minecraft.entity.passive.AbstractHorse) VanillaAdapter(org.spongepowered.common.item.inventory.adapter.impl.VanillaAdapter) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) ContainerHopper(net.minecraft.inventory.ContainerHopper) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) Multimap(com.google.common.collect.Multimap) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ItemStack(net.minecraft.item.ItemStack) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Inventory2DLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.Inventory2DLensImpl) ContainerEnchantment(net.minecraft.inventory.ContainerEnchantment) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) ContainerFurnace(net.minecraft.inventory.ContainerFurnace) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) ContainerBrewingStand(net.minecraft.inventory.ContainerBrewingStand) WorldServer(net.minecraft.world.WorldServer) Nullable(javax.annotation.Nullable) FurnaceInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.FurnaceInventoryLens) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) Inventory2DLens(org.spongepowered.common.item.inventory.lens.comp.Inventory2DLens) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) ContainerHorseInventory(net.minecraft.inventory.ContainerHorseInventory) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) IMixinSingleBlockCarrier(org.spongepowered.common.interfaces.IMixinSingleBlockCarrier) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) CraftingInventoryLens(org.spongepowered.common.item.inventory.lens.comp.CraftingInventoryLens) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Container(org.spongepowered.api.item.inventory.Container) SlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.SlotLensImpl) IInventory(net.minecraft.inventory.IInventory) Slot(net.minecraft.inventory.Slot) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) VecHelper(org.spongepowered.common.util.VecHelper) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) TileEntity(net.minecraft.tileentity.TileEntity) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Collections(java.util.Collections) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) SlotCrafting(net.minecraft.inventory.SlotCrafting) Nullable(javax.annotation.Nullable)

Example 2 with MainPlayerInventoryLensImpl

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

the class MixinContainerWorkbench method rootLens.

@Override
public Lens<IInventory, ItemStack> rootLens(Fabric<IInventory> fabric, InventoryAdapter<IInventory, ItemStack> adapter) {
    List<Lens<IInventory, ItemStack>> lenses = new ArrayList<>();
    lenses.add(new CraftingInventoryLensImpl(0, 1, 3, 3, inventory$getSlotProvider()));
    lenses.add(new MainPlayerInventoryLensImpl(3 * 3 + 1, inventory$getSlotProvider(), true));
    return new ContainerLens(adapter, inventory$getSlotProvider(), lenses);
}
Also used : MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) ArrayList(java.util.ArrayList) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) Lens(org.spongepowered.common.item.inventory.lens.Lens)

Example 3 with MainPlayerInventoryLensImpl

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

the class PlayerInventoryLens method init.

@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
    // Adding slots
    for (int ord = 0, slot = this.base; ord < this.size; ord++, slot++) {
        this.addChild(slots.getSlot(slot), new SlotIndex(ord));
    }
    int base = 0;
    this.main = new MainPlayerInventoryLensImpl(base, slots, false);
    base += this.main.slotCount();
    this.equipment = new EquipmentInventoryLensImpl(this.player, base, EQUIPMENT, 1, slots, false);
    base += EQUIPMENT;
    this.offhand = slots.getSlot(base);
    // TODO Hotbar in Vanilla is part of the main inventory (first 9 slots) ; maybe wrap it in a Lens?
    this.addSpanningChild(this.main);
    this.addSpanningChild(this.equipment);
    this.addSpanningChild(this.offhand);
    // Additional Slots for bigger modded inventories
    int additionalSlots = this.size - base - 1;
    if (additionalSlots > 0) {
        this.addSpanningChild(new OrderedInventoryLensImpl(base, additionalSlots, 1, slots));
    }
}
Also used : MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) EquipmentInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.EquipmentInventoryLensImpl) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex)

Example 4 with MainPlayerInventoryLensImpl

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

the class ContainerPlayerInventoryLens method init.

@Override
protected void init(SlotProvider<IInventory, ItemStack> slots) {
    // 1
    int base = CRAFTING_OUTPUT;
    final CraftingInventoryLensImpl crafting = new CraftingInventoryLensImpl(0, base, CRAFTING_GRID, CRAFTING_GRID, slots);
    // 4
    base += CRAFTING_GRID * CRAFTING_GRID;
    // TODO pass player for carrier to EquipmentInventory
    final EquipmentInventoryLensImpl armor = new EquipmentInventoryLensImpl(null, base, EQUIPMENT, 1, slots, true);
    // 4
    base += EQUIPMENT;
    final MainPlayerInventoryLensImpl main = new MainPlayerInventoryLensImpl(base, slots, true);
    // 9
    base += MAIN_INVENTORY_HEIGHT * INVENTORY_WIDTH + HOTBAR * INVENTORY_WIDTH;
    final SlotLens<IInventory, ItemStack> offHand = slots.getSlot(base);
    base += OFFHAND;
    this.viewedInventories = new ArrayList<>(Arrays.asList(crafting, armor, offHand, main));
    int additionalSlots = this.size - base - 1;
    if (additionalSlots > 0) {
        viewedInventories.add(new OrderedInventoryLensImpl(base, additionalSlots, 1, slots));
    }
    // TODO actual Container order is:
    // CraftingOutput (1) -> Crafting (4) -> ArmorSlots (4) -> MainInventory (27) -> Hotbar (9) -> Offhand (1)
    // how to handle issues like in #939? ; e.g. Inventory#offer using a different insertion order
    super.init(slots);
}
Also used : IInventory(net.minecraft.inventory.IInventory) MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) EquipmentInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.EquipmentInventoryLensImpl) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MainPlayerInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl)3 ArrayList (java.util.ArrayList)2 IInventory (net.minecraft.inventory.IInventory)2 ItemStack (net.minecraft.item.ItemStack)2 CraftingInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl)2 EquipmentInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.EquipmentInventoryLensImpl)2 OrderedInventoryLensImpl (org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl)2 Multimap (com.google.common.collect.Multimap)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 EntityItem (net.minecraft.entity.item.EntityItem)1 AbstractChestHorse (net.minecraft.entity.passive.AbstractChestHorse)1 AbstractHorse (net.minecraft.entity.passive.AbstractHorse)1