Search in sources :

Example 6 with SlotIndex

use of org.spongepowered.api.item.inventory.property.SlotIndex in project LanternServer by LanternPowered.

the class InventorySnapshot method offerTo.

public void offerTo(Inventory inventory) {
    for (Slot slot : inventory.<Slot>slots()) {
        // noinspection ConstantConditions
        final SlotIndex index = inventory.getProperty(slot, SlotIndex.class, null).get();
        final ItemStackSnapshot itemStackSnapshot = this.itemStackSnapshots.get(index.getValue());
        if (itemStackSnapshot != null) {
            slot.set(itemStackSnapshot.createStack());
        }
    }
}
Also used : SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) Slot(org.spongepowered.api.item.inventory.Slot) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Example 7 with SlotIndex

use of org.spongepowered.api.item.inventory.property.SlotIndex in project SpongeCommon by SpongePowered.

the class EquipmentInventoryLensImpl method initInventory.

private void initInventory(SlotProvider<IInventory, ItemStack> slots) {
    int index = this.base;
    int ord = 0;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.BOOTS));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.LEGGINGS));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.CHESTPLATE));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord), EquipmentSlotType.of(EquipmentTypes.HEADWEAR));
    this.cache();
}
Also used : SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex)

Example 8 with SlotIndex

use of org.spongepowered.api.item.inventory.property.SlotIndex in project SpongeCommon by SpongePowered.

the class EquipmentInventoryLensImpl method initContainer.

private void initContainer(SlotProvider<IInventory, ItemStack> slots) {
    int index = this.base;
    int ord = 0;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.HEADWEAR));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.CHESTPLATE));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord++), EquipmentSlotType.of(EquipmentTypes.LEGGINGS));
    index += this.stride;
    this.addSpanningChild(slots.getSlot(index), new SlotIndex(ord), EquipmentSlotType.of(EquipmentTypes.BOOTS));
    this.cache();
}
Also used : SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex)

Example 9 with SlotIndex

use of org.spongepowered.api.item.inventory.property.SlotIndex in project SpongeCommon by SpongePowered.

the class LargeChestInventoryLens method initLargeChest.

private void initLargeChest(SlotProvider<IInventory, ItemStack> slots) {
    // add grids
    int base = 0;
    this.addSpanningChild(new GridInventoryLensImpl(base, 9, this.upperChest / 9, 9, (Class) TileEntityChest.class, slots));
    base += this.upperChest;
    this.addSpanningChild(new GridInventoryLensImpl(base, 9, this.lowerChest / 9, 9, (Class) TileEntityChest.class, slots));
    base += this.lowerChest;
    this.addChild(new GridInventoryLensImpl(0, 9, (this.upperChest + this.lowerChest) / 9, 9, slots));
    // add slot childs for grids
    for (int ord = 0, slot = this.base; ord < base; ord++, slot++) {
        this.addChild(slots.getSlot(slot), new SlotIndex(ord));
    }
    // handle possible extension by mods:
    for (int i = base; i < this.slotCount(); i++) {
        this.addSpanningChild(new SlotLensImpl(i), SlotIndex.of(i));
    }
}
Also used : SlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.SlotLensImpl) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) GridInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.GridInventoryLensImpl)

Example 10 with SlotIndex

use of org.spongepowered.api.item.inventory.property.SlotIndex 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)

Aggregations

SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)15 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)4 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)3 DataView (org.spongepowered.api.data.DataView)3 IInventory (net.minecraft.inventory.IInventory)2 Inventory (org.spongepowered.api.item.inventory.Inventory)2 Slot (org.spongepowered.api.item.inventory.Slot)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 IMerchant (net.minecraft.entity.IMerchant)1 AbstractHorse (net.minecraft.entity.passive.AbstractHorse)1 Container (net.minecraft.inventory.Container)1 ContainerBeacon (net.minecraft.inventory.ContainerBeacon)1 ContainerBrewingStand (net.minecraft.inventory.ContainerBrewingStand)1 ContainerChest (net.minecraft.inventory.ContainerChest)1 ContainerDispenser (net.minecraft.inventory.ContainerDispenser)1 ContainerEnchantment (net.minecraft.inventory.ContainerEnchantment)1