package joshie.harvest.core.loot;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import joshie.harvest.core.base.block.BlockHFEnum;
import joshie.harvest.core.base.item.ItemBlockHF;
import joshie.harvest.core.base.item.ItemHFEnum;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.storage.loot.LootContext;
import net.minecraft.world.storage.loot.conditions.LootCondition;
import net.minecraft.world.storage.loot.functions.LootFunction;

import java.util.Random;


public class SetEnum extends LootFunction {
    private final String name;

    public SetEnum(LootCondition[] conditionsIn, String name) {
        super(conditionsIn);
        this.name = name;
    }

    public ItemStack apply(ItemStack stack, Random rand, LootContext context) {
        if (stack.getItem() instanceof ItemHFEnum) {
            ItemStack ret = ((ItemHFEnum)stack.getItem()).getStackFromEnumString(name);
            ret.stackSize = stack.stackSize; ///Update the size
            return ret;
        } else if (stack.getItem() instanceof ItemBlockHF && ((ItemBlockHF)stack.getItem()).getBlock() instanceof BlockHFEnum) {
            ItemStack ret = ((BlockHFEnum)((ItemBlockHF)stack.getItem()).getBlock()).getStackFromEnumString(name);
            ret.stackSize = stack.stackSize;
            return ret;
        }

        return stack;
    }

    public static class Serializer extends LootFunction.Serializer<SetEnum> {
        public Serializer() {
            super(new ResourceLocation("hf_set_enum"), SetEnum.class);
        }

        public void serialize(JsonObject object, SetEnum functionClazz, JsonSerializationContext serializationContext) {
            object.addProperty("enum", functionClazz.name);
        }

        public SetEnum deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn) {
            return new SetEnum(conditionsIn, object.get("enum").getAsString());
        }
    }
}

@@ -309,24 +309,77 @@
 ItemHFEnum;%0A
+import joshie.harvest.core.base.item.ItemHFFoodEnum;%0A
 import net.m
@@ -959,32 +959,276 @@
 (stack.getItem()
+ instanceof ItemHFFoodEnum) %7B%0A            ItemStack ret = ((ItemHFFoodEnum)stack.getItem()).getStackFromEnumString(name);%0A            ret.stackSize = stack.stackSize; ///Update the size%0A            return ret;%0A        %7D else if (stack.getItem()
  instanceof Item

Fix fishing not adjusting fishies!