use of org.spongepowered.api.item.inventory.property.SlotIndex in project modules-extra by CubeEngine.
the class Observe method transactions.
/**
* Observes a SlotTransaction
*
* @param transactions the transaction to observe
* @return the observed data
*/
public static List<Map<String, Object>> transactions(List<SlotTransaction> transactions) {
List<Map<String, Object>> list = new ArrayList<>();
for (SlotTransaction transaction : transactions) {
Map<String, Object> data = new HashMap<>();
ItemStackSnapshot originalStack = transaction.getOriginal();
ItemStackSnapshot finalStack = transaction.getFinal();
data.put(ChangeInventoryReport.ORIGINAL, toRawData(originalStack.toContainer()));
data.put(ChangeInventoryReport.REPLACEMENT, toRawData(finalStack.toContainer()));
data.put(ChangeInventoryReport.SLOT_INDEX, transaction.getSlot().getInventoryProperty(SlotIndex.class).map(SlotIndex::getValue).orElse(-1));
list.add(data);
}
return list;
}
use of org.spongepowered.api.item.inventory.property.SlotIndex in project LanternServer by LanternPowered.
the class UserStore method serializeSlot.
private static void serializeSlot(Inventory parent, Slot slot, int indexOffset, ObjectSerializer<LanternItemStack> itemStackSerializer, List<DataView> views) {
// Key doesn't matter
final SlotIndex index = parent.getProperty(slot, SlotIndex.class, "index").get();
serializeSlot(index.getValue() + indexOffset, slot, itemStackSerializer, views);
}
use of org.spongepowered.api.item.inventory.property.SlotIndex 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.spongepowered.api.item.inventory.property.SlotIndex 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.spongepowered.api.item.inventory.property.SlotIndex in project LanternServer by LanternPowered.
the class InventorySnapshot method ofInventory.
/**
* Creates a {@link InventorySnapshot} for the specified {@link Inventory}.
*
* @param inventory The inventory
* @return The snapshot
*/
public static InventorySnapshot ofInventory(Inventory inventory) {
final Iterator<Slot> it = inventory.<Slot>slots().iterator();
final Int2ObjectMap<ItemStackSnapshot> itemStackSnapshots = new Int2ObjectOpenHashMap<>();
while (it.hasNext()) {
final Slot slot = it.next();
slot.peek().map(ItemStack::createSnapshot).ifPresent(itemStackSnapshot -> {
// noinspection ConstantConditions
final SlotIndex index = inventory.getProperty(slot, SlotIndex.class, null).get();
itemStackSnapshots.put(index.getValue(), itemStackSnapshot);
});
}
return new InventorySnapshot(itemStackSnapshots);
}
Aggregations