package projectzombie.items.modifier;

import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.util.ItemStack;

public class ItemModifierMeta extends ItemModifier
{
	private int meta;

	public ItemModifierMeta(int meta) {
		this.meta = meta;
	}
	
	public ItemModifierMeta(BdfObject bdf) {
		BdfClassLoad(bdf);
	}
	
	public static int getStackMeta(ItemStack stack)
	{
		ItemModifier modifier = stack.getModifier(ItemModifierMeta.class);
		
		if(modifier != null && modifier instanceof ItemModifierMeta) {
			return ((ItemModifierMeta)modifier).meta;
		}
		
		return 0;
	}
	
	@Override
	public void BdfClassLoad(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		meta = nl.get("meta").getInteger();
	}

	@Override
	public void BdfClassSave(BdfObject bdf) {
		BdfNamedList nl = bdf.getNamedList();
		nl.set("meta", bdf.newObject().setInteger(meta));
	}
	
	@Override
	public boolean isEqual(ItemModifier other) {
		return (other instanceof ItemModifierMeta) && ((ItemModifierMeta)other).meta == meta;
	}
	
	@Override
	public ItemModifier copy() {
		return new ItemModifierMeta(meta);
	}

}
