use of org.lanternpowered.server.inventory.LanternItemStack 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);
}
}
}
use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.
the class UserStore method deserializeEnderChest.
private static void deserializeEnderChest(GridInventory enderChestInventory, List<DataView> itemViews) {
for (DataView itemView : itemViews) {
final int slot = itemView.getByte(SLOT).get() & 0xff;
final LanternItemStack itemStack = ItemStackStore.INSTANCE.deserialize(itemView);
enderChestInventory.set(new SlotIndex(slot), itemStack);
}
}
use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.
the class ItemStackStore method deserialize.
@Override
public LanternItemStack deserialize(DataView dataView) throws InvalidDataException {
final String identifier = dataView.getString(IDENTIFIER).get();
final ItemType itemType = ItemRegistryModule.get().getById(identifier).orElseThrow(() -> new InvalidDataException("There is no item type with the id: " + identifier));
final LanternItemStack itemStack = new LanternItemStack(itemType);
deserialize(itemStack, dataView);
return itemStack;
}
use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.
the class ContainerTileEntityStore method serialize.
@Override
public void serialize(T object, DataView dataView) {
super.serialize(object, dataView);
final ObjectSerializer<LanternItemStack> itemStackSerializer = ObjectSerializerRegistry.get().get(LanternItemStack.class).get();
final List<DataView> itemViews = new ArrayList<>();
final Inventory inventory = object.getInventory();
final Iterable<Slot> slots = inventory.slots();
for (Slot slot : slots) {
final Optional<ItemStack> optItemStack = slot.peek();
if (!optItemStack.isPresent()) {
continue;
}
final DataView itemView = itemStackSerializer.serialize((LanternItemStack) optItemStack.get());
// noinspection ConstantConditions
itemView.set(SLOT, (byte) inventory.getProperty(slot, SlotIndex.class, null).get().getValue().intValue());
itemViews.add(itemView);
}
dataView.set(ITEMS, itemViews);
}
use of org.lanternpowered.server.inventory.LanternItemStack in project LanternServer by LanternPowered.
the class HandlerPlayInSignBook method handle.
@Override
public void handle(NetworkContext context, MessagePlayInSignBook message) {
final LanternPlayer player = context.getSession().getPlayer();
final AbstractSlot slot = player.getInventory().getHotbar().getSelectedSlot();
ItemStack itemStack = slot.peek().orElse(null);
if (itemStack != null && itemStack.getType() == ItemTypes.WRITABLE_BOOK) {
final ItemStack itemStack1 = new LanternItemStack(ItemTypes.WRITTEN_BOOK);
itemStack.getValues().forEach(itemStack1::offer);
itemStack1.offer(Keys.BOOK_PAGES, message.getPages().stream().map(Text::of).collect(Collectors.toList()));
itemStack1.offer(Keys.BOOK_AUTHOR, Text.of(message.getAuthor()));
itemStack1.offer(Keys.DISPLAY_NAME, Text.of(message.getTitle()));
slot.set(itemStack1);
}
}
Aggregations