Search in sources :

Example 1 with LanternMainPlayerInventory

use of org.lanternpowered.server.inventory.vanilla.LanternMainPlayerInventory in project LanternServer by LanternPowered.

the class UserStore method serializePlayerInventory.

private static List<DataView> serializePlayerInventory(AbstractUserInventory<?> inventory) {
    final List<DataView> itemViews = new ArrayList<>();
    final LanternMainPlayerInventory mainInventory = inventory.getMain();
    final LanternPlayerEquipmentInventory equipmentInventory = inventory.getEquipment();
    final AbstractSlot offHandSlot = inventory.getOffhand();
    Iterable<Slot> slots = mainInventory.slots();
    for (Slot slot : slots) {
        serializeSlot(mainInventory, slot, 0, ItemStackStore.INSTANCE, itemViews);
    }
    slots = equipmentInventory.slots();
    for (Slot slot : slots) {
        serializeSlot(equipmentInventory, slot, 100, ItemStackStore.INSTANCE, itemViews);
    }
    serializeSlot(150, offHandSlot, ItemStackStore.INSTANCE, itemViews);
    return itemViews;
}
Also used : DataView(org.spongepowered.api.data.DataView) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) ArrayList(java.util.ArrayList) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) Slot(org.spongepowered.api.item.inventory.Slot) LanternPlayerEquipmentInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerEquipmentInventory) LanternMainPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternMainPlayerInventory)

Example 2 with LanternMainPlayerInventory

use of org.lanternpowered.server.inventory.vanilla.LanternMainPlayerInventory in project LanternServer by LanternPowered.

the class UserStore method deserializePlayerInventory.

private static void deserializePlayerInventory(AbstractUserInventory<?> inventory, List<DataView> itemViews) {
    final LanternMainPlayerInventory mainInventory = inventory.getMain();
    final LanternPlayerEquipmentInventory equipmentInventory = inventory.getEquipment();
    final AbstractSlot offHandSlot = inventory.getOffhand();
    for (DataView itemView : itemViews) {
        final int slot = itemView.getByte(SLOT).get() & 0xff;
        final LanternItemStack itemStack = ItemStackStore.INSTANCE.deserialize(itemView);
        if (slot >= 0 && slot < mainInventory.capacity()) {
            mainInventory.set(new SlotIndex(slot), itemStack);
        } else if (slot >= 100 && slot - 100 < equipmentInventory.capacity()) {
            equipmentInventory.set(new SlotIndex(slot - 100), itemStack);
        } else if (slot == 150) {
            offHandSlot.set(itemStack);
        }
    }
}
Also used : DataView(org.spongepowered.api.data.DataView) AbstractSlot(org.lanternpowered.server.inventory.AbstractSlot) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) LanternPlayerEquipmentInventory(org.lanternpowered.server.inventory.vanilla.LanternPlayerEquipmentInventory) LanternMainPlayerInventory(org.lanternpowered.server.inventory.vanilla.LanternMainPlayerInventory) LanternItemStack(org.lanternpowered.server.inventory.LanternItemStack)

Aggregations

AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)2 LanternMainPlayerInventory (org.lanternpowered.server.inventory.vanilla.LanternMainPlayerInventory)2 LanternPlayerEquipmentInventory (org.lanternpowered.server.inventory.vanilla.LanternPlayerEquipmentInventory)2 DataView (org.spongepowered.api.data.DataView)2 ArrayList (java.util.ArrayList)1 LanternItemStack (org.lanternpowered.server.inventory.LanternItemStack)1 Slot (org.spongepowered.api.item.inventory.Slot)1 SlotIndex (org.spongepowered.api.item.inventory.property.SlotIndex)1