Search in sources :

Example 1 with GlowUnsafeValues

use of net.glowstone.util.GlowUnsafeValues in project Glowstone by GlowstoneMC.

the class GlowBufUtils method readSlot.

/**
 * Read an item stack from the buffer.
 *
 * @param buf     The buffer.
 * @param network Mark network source.
 * @return The stack read, or null.
 */
public static ItemStack readSlot(ByteBuf buf, boolean network) throws IOException {
    boolean present = buf.readBoolean();
    if (!present) {
        return InventoryUtil.createEmptyStack();
    }
    int type = ByteBufUtils.readVarInt(buf);
    int amount = buf.readUnsignedByte();
    GlowUnsafeValues unsafeValues = (GlowUnsafeValues) Bukkit.getServer().getUnsafe();
    Material material = unsafeValues.fromId(type);
    if (material == null) {
        return InventoryUtil.createEmptyStack();
    }
    CompoundTag tag = readCompound(buf, network);
    ItemStack stack = new ItemStack(material, amount);
    stack.setItemMeta(GlowItemFactory.instance().readNbt(material, tag));
    return stack;
}
Also used : GlowUnsafeValues(net.glowstone.util.GlowUnsafeValues) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

GlowUnsafeValues (net.glowstone.util.GlowUnsafeValues)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1