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;
}
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);
}
}
}
Aggregations