/*
 * License (MIT)
 *
 * Copyright (c) 2014 Granite Team
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
 * software and associated documentation files (the "Software"), to deal in the
 * Software without restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so, subject to the
 * following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package org.granitepowered.granite.impl.item;

import org.granitepowered.granite.composite.Composite;
import org.granitepowered.granite.mc.MCItem;
import org.granitepowered.granite.mc.MCItemStack;
import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.inventory.ItemStack;

import static org.granitepowered.granite.utils.MinecraftUtils.wrap;

public class GraniteItemStack extends Composite<MCItemStack> implements ItemStack {
    public GraniteItemStack(MCItemStack obj) {
        super(obj);
    }

    @Override
    public ItemType getItem() {
        return (ItemType) wrap(getMCItem());
    }

    @Override
    public short getDamage() {
        return (short) obj.fieldGet$itemDamage();
    }

    @Override
    public void setDamage(short damage) {
        obj.fieldSet$itemDamage(damage);
    }

    @Override
    public int getQuantity() {
        return obj.fieldGet$stackSize();
    }

    @Override
    public void setQuantity(int quantity) throws IllegalArgumentException {
        if (quantity > getMaxStackQuantity()) {
            throw new IllegalArgumentException("Quantity exceeds maximum quantity");
        }
        obj.fieldSet$stackSize(quantity);
    }

    @Override
    public int getMaxStackQuantity() {
        return getMCItem().fieldGet$maxStackSize();
    }

    @Override
    public void setMaxStackQuantity(int quantity) {
        // TODO: Check if you can set max stack size on an ItemStack
        throw new UnsupportedOperationException("Cannot set max stack size on a single ItemStack");
    }

    @Override
    public int compareTo(ItemStack o) {
        // TODO: Check what this actually compares
        return 0;
    }

    public MCItem getMCItem() {
        return obj.fieldGet$item();
    }
}

@@ -1230,16 +1230,115 @@
 posite;%0A
+import org.granitepowered.granite.mappings.Mappings;%0Aimport org.granitepowered.granite.mc.MCBlock;%0A
 import o
@@ -1374,16 +1374,16 @@
 MCItem;%0A
-
 import o
@@ -1420,24 +1420,70 @@
 CItemStack;%0A
+import org.spongepowered.api.block.BlockType;%0A
 import org.s
@@ -1570,16 +1570,86 @@
 Stack;%0A%0A
+import static org.granitepowered.granite.utils.MinecraftUtils.unwrap;%0A
 import s
@@ -1836,24 +1836,24 @@
 tack obj) %7B%0A
-
         supe
@@ -1859,32 +1859,847 @@
 er(obj);%0A    %7D%0A%0A
+    public GraniteItemStack(ItemType type, int amount) %7B%0A        this((MCItem) unwrap(type), amount);%0A    %7D%0A%0A    public GraniteItemStack(BlockType type, int amount) %7B%0A        this((MCBlock) unwrap(type), amount);%0A    %7D%0A%0A    public GraniteItemStack(MCItem item, int amount) %7B%0A        this(item, amount, 0);%0A    %7D%0A%0A    public GraniteItemStack(MCItem item, int amount, int meta) %7B%0A        super(Mappings.getClass(%22ItemStack%22), new Class%5B%5D%7BMappings.getClass(%22Item%22), int.class, int.class%7D, item, amount, meta);%0A    %7D%0A%0A    public GraniteItemStack(MCBlock block, int amount) %7B%0A        this(block, amount, 0);%0A    %7D%0A%0A    public GraniteItemStack(MCBlock block, int amount, int meta) %7B%0A        super(Mappings.getClass(%22ItemStack%22), new Class%5B%5D%7BMappings.getClass(%22Block%22), int.class, int.class%7D, block, amount, meta);%0A    %7D%0A%0A
     @Override%0A  

Add a bunch of constructors to GraniteItemStack