package projectzombie.util.math;

import bdf.classes.IBdfClassManager;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.init.Items;
import projectzombie.items.Item;

public class ItemStack implements IBdfClassManager
{
	public short meta;
	public Item item;
	public int count;
	
	public ItemStack(Item item, int count, short meta) {
		this.item = item;
		this.count = count;
		this.meta = meta;
	}
	
	public ItemStack copy() {
		return new ItemStack(item, count, meta);
	}
	
	public boolean isEmpty() {
		if(count < 1) return true;
		if(item == null) return true;
		if(item == Items.EMPTY) return true;
		return false;
	}
	
	public boolean stackEquals(ItemStack other) {
		if(other.item != item) return false;
		if(other.meta != meta) return false;
		return true;
	}

	@Override
	public void BdfClassLoad(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		meta = nl.get("meta").getShort();
		count = nl.get("count").getInteger();
		item = Items.items.get(nl.get("item").getInteger());
	}

	@Override
	public void BdfClassSave(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		nl.set("meta", bdf.newObject().setShort(meta));
		nl.set("count", bdf.newObject().setInteger(count));
		nl.set("item", bdf.newObject().setInteger(item.id));
	}
	
	public ItemStack(BdfObject bdf) {
		BdfClassLoad(bdf);
	}
	
	public static ItemStack getEmpty() {
		return new ItemStack(Items.EMPTY, 0, (short)0);
	}
}
