package betterwithaddons.interaction.minetweaker;

import betterwithaddons.tileentity.TileEntityLureTree;
import betterwithaddons.tileentity.TileEntityLureTree.TreeFood;
import crafttweaker.IAction;
import crafttweaker.annotations.ZenRegister;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.minecraft.CraftTweakerMC;
import crafttweaker.mc1120.CraftTweaker;
import net.minecraft.item.ItemStack;
import stanhebben.zenscript.annotations.NotNull;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

@ZenRegister
@ZenClass(LureTree.clazz)
public class LureTree {
    public static final String clazz = "mods.betterwithaddons.LureTree";

    @ZenMethod
    public static void add(@NotNull IItemStack input, int food) {
        ItemStack stack = CraftTweakerMC.getItemStack(input);
        TreeFood r = new TreeFood(stack,food);
        CraftTweaker.LATE_ACTIONS.add(new Add(r));
    }

    @ZenMethod
    public static void remove(@NotNull IItemStack input)
    {
        ItemStack stack = CraftTweakerMC.getItemStack(input);
        CraftTweaker.LATE_ACTIONS.add(new Remove(stack));
    }

    public static class Add implements IAction
    {
        TreeFood recipe;

        public Add(TreeFood recipe) {
            this.recipe = recipe;
        }

        @Override
        public void apply() {
            TileEntityLureTree.addTreeFood(recipe);
        }

        @Override
        public String describe() {
            return "Adding Lure Tree food: "+recipe.stack.toString();
        }
    }

    public static class Remove implements IAction
    {
        TreeFood recipe;

        protected Remove(ItemStack stack) {
            recipe = TileEntityLureTree.getTreeFood(stack);
        }

        @Override
        public void apply() {
            if (recipe != null) TileEntityLureTree.getTreeFoods().remove(recipe);
        }

        @Override
        public String describe() {
            return (recipe != null) ? "Removing Lure Tree food:"+recipe.stack.toString() : "";
        }
    }
}

@@ -767,20 +767,22 @@
 ut, int 
-food
+amount
 ) %7B%0A    
@@ -789,156 +789,88 @@
     
-ItemStack stack = CraftTweakerMC.getItemStack(input);%0A        TreeFood r = new TreeFood(stack,food);%0A        CraftTweaker.LATE_ACTIONS.add(new Add(r
+CraftTweaker.LATE_ACTIONS.add(new Add(CraftTweakerMC.getItemStack(input), amount
 ));%0A
@@ -958,70 +958,8 @@
   %7B%0A
-        ItemStack stack = CraftTweakerMC.getItemStack(input);%0A
     
@@ -1003,21 +1003,50 @@
  Remove(
-stack
+CraftTweakerMC.getItemStack(input)
 ));%0A    
@@ -1109,33 +1109,253 @@
         
-TreeFood recipe;%0A
+ItemStack stack;%0A        int amount;%0A%0A        public Add(ItemStack stack, int amount) %7B%0A            this.stack = stack;%0A            this.amount = amount;%0A        %7D%0A        %0A        // Backwards compat snce it's public%0A        @Deprecated
 %0A       
@@ -1402,22 +1402,61 @@
    this.
-recipe
+stack = recipe.stack;%0A            this.amount
  = recip
@@ -1456,16 +1456,23 @@
 = recipe
+.amount
 ;%0A      
@@ -1567,22 +1567,29 @@
 reeFood(
-recipe
+stack, amount
 );%0A     
@@ -1692,23 +1692,16 @@
 food: %22+
-recipe.
 stack.to
@@ -1791,31 +1791,31 @@
         
-TreeFood recipe
+ItemStack stack
 ;%0A%0A     
@@ -1869,54 +1869,26 @@
     
-recipe = TileEntityLureTree.getTreeFood(
+this.stack = 
 stack
-)
 ;%0A  
@@ -1936,32 +1936,101 @@
  void apply() %7B%0A
+            TreeFood recipe = TileEntityLureTree.getTreeFood(stack);%0A
             if (
@@ -2181,27 +2181,8 @@
 turn
- (recipe != null) ?
  %22Re
@@ -2207,17 +2207,11 @@
 ood:
+ 
 %22+
-recipe.
 stac
@@ -2226,13 +2226,8 @@
 ng()
- : %22%22
 ;%0A  

Fix lure tree constructor