package org.cyclops.cyclopscore.recipe.custom.component;

import lombok.Getter;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

import java.util.List;

/**
 * A {@link org.cyclops.cyclopscore.recipe.custom.api.IRecipe} component (input, output or properties) that holds an
 * oredictionary key.
 *
 * @author immortaleeb
 */
public class OreDictItemStackRecipeComponent extends ItemStackRecipeComponent {

    @Getter private final String key;
    @Getter(lazy=true) private final List<ItemStack> itemStacks = OreDictionary.getOres(getKey());

    public OreDictItemStackRecipeComponent(String key) {
        super(null);
        this.key = key;
    }

    @Override
    public boolean equals(Object object) {
        if(super.equals(object)) {
            return true;
        }

        if (!(object instanceof ItemStackRecipeComponent)) return false;
        ItemStackRecipeComponent that = (ItemStackRecipeComponent)object;

        // To increase performance, first check if the comparing stack is not null before
        // potentially matching it with the whole oredict.
        if(that.getItemStack() != null) {
            for (ItemStack itemStack : getItemStacks()) {
                if (equals(itemStack, that.getItemStack())) {
                    return true;
                }
            }
        }

        return false;
    }

    @Override
    public int hashCode() {
        return key != null ? key.hashCode() + 876 : 0;
    }

}

@@ -746,79 +746,8 @@
 ) %7B%0A
-        if(super.equals(object)) %7B%0A            return true;%0A        %7D%0A%0A
     
@@ -811,24 +811,24 @@
 turn false;%0A
+
         Item
@@ -1049,16 +1049,17 @@
       if
+ 
 (that.ge
@@ -1289,29 +1289,49 @@
      return 
-false
+getItemStacks().isEmpty()
 ;%0A    %7D%0A%0A   

Fix OreDictItemStackRecipeComponent matching null itemstacks