// Path: src/main/java/cn/mccraft/chinacraft/api/CCRecipeManager.java
// public class CCRecipeManager {
//     private static final Map<Class<? extends ICCRecipe>, Set<ICCRecipe>> RECIPES = new HashMap<>();
// 
//     public static <T extends ICCRecipe> void addRecipe(Class<T> recipeClass, T recipe) {
//         Set<ICCRecipe> recipes = RECIPES.getOrDefault(recipeClass, new HashSet<>());
//         recipes.add(recipe);
//         RECIPES.put(recipeClass, recipes);
//     }
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T extends ICCRecipe> Set<T> removeRecipe(Class<T> recipeClass) {
//         return (Set<T>) RECIPES.remove(recipeClass);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> void addAllRecipes(Class<T> recipeClass, Set<T> recipeSet) {
//         RECIPES.put(recipeClass, recipeSet.stream().collect(Collectors.toSet()));
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> Optional<T> getRecipe(Class<T> recipeClass, List<ItemStack> inputs) {
//         return RECIPES.getOrDefault(recipeClass, new HashSet<>()).stream().filter(recipe -> recipe.getInputItems().equals(inputs)).findFirst().map(recipe -> (T) recipe);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> Set<T> getRecipes(Class<T> recipeClass) {
//         return (Set<T>) RECIPES.getOrDefault(recipeClass, new HashSet<>());
//     }
// }
// 
// Path: src/main/java/cn/mccraft/chinacraft/api/recipe/CrusherRecipe.java
// public class CrusherRecipe extends SimpleOreRecipe {
//     private int time;
//     private int energy;
//     private EnumCrusherMaterial material = EnumCrusherMaterial.STONE;
// 
//     public int getTime() {
//         return time;
//     }
// 
//     public void setTime(int time) {
//         this.time = time;
//     }
// 
//     public int getEnergy() {
//         return energy;
//     }
// 
//     public void setEnergy(int energy) {
//         this.energy = energy;
//     }
// 
//     public EnumCrusherMaterial getMaterial() {
//         return material;
//     }
// }
// 
// Path: src/main/java/cn/mccraft/chinacraft/block/machine/EnumCrusherMaterial.java
// public enum EnumCrusherMaterial implements IStringSerializable {
//     // Grey
//     STONE(189, 189, 189, 1),
// 
//     // Deep orange
//     BRONZE(255, 171, 145, 1),
// 
//     // Grey lighten
//     IRON(245, 245, 245, 1);
// 
//     private float r, g, b, a;
// 
//     EnumCrusherMaterial(int r, int g, int b, int a) {
//         Color color = new Color(r, g, b, a);
//         this.r = color.getRGBComponents(null)[0];
//         this.g = color.getRGBComponents(null)[1];
//         this.b = color.getRGBComponents(null)[2];
//         this.a = color.getRGBComponents(null)[3];
//     }
// 
//     public float getRed() {
//         return r;
//     }
// 
//     public float getGreen() {
//         return g;
//     }
// 
//     public float getBlue() {
//         return b;
//     }
// 
//     public float getAlpha() {
//         return a;
//     }
// 
//     @Override
//     public String getName() {
//         return this.toString().toLowerCase();
//     }
// }


import cn.mccraft.chinacraft.api.CCRecipeManager;
import cn.mccraft.chinacraft.api.recipe.CrusherRecipe;
import cn.mccraft.chinacraft.block.machine.EnumCrusherMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;
        compound = super.writeToNBT(compound);
        compound.setTag("inventory", inventory.serializeNBT());
        compound.setTag("energy", CapabilityEnergy.ENERGY.getStorage().writeNBT(CapabilityEnergy.ENERGY, energyStorage, null));
        compound.setTag("inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().writeNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, inventory, null));
        return compound;
    }

    public EnumCrusherMaterial getCrusherMaterial() {
        return crusherMaterial;
    }

    @Override
    public void update() {
        if (currentRecipe != null && progress != 0) {
            if (progress == currentRecipe.getTime()) { // 达到时间, 输出
                inventory.setStackInSlot(0, ItemStack.EMPTY);
                inventory.setStackInSlot(1, ItemStack.EMPTY);
                inventory.setStackInSlot(2, currentRecipe.getOutputItems().get(0));
                inventory.setStackInSlot(3, currentRecipe.getOutputItems().get(1));
                currentRecipe = null;
                progress = 0;
            } else {
                // 继续运转
                ++progress;
            }
        } else if (progress != 0)
            // 清理
            progress = 0;
        else {
            progress = 0;
// Path: src/main/java/cn/mccraft/chinacraft/api/CCRecipeManager.java
// public class CCRecipeManager {
//     private static final Map<Class<? extends ICCRecipe>, Set<ICCRecipe>> RECIPES = new HashMap<>();
// 
//     public static <T extends ICCRecipe> void addRecipe(Class<T> recipeClass, T recipe) {
//         Set<ICCRecipe> recipes = RECIPES.getOrDefault(recipeClass, new HashSet<>());
//         recipes.add(recipe);
//         RECIPES.put(recipeClass, recipes);
//     }
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T extends ICCRecipe> Set<T> removeRecipe(Class<T> recipeClass) {
//         return (Set<T>) RECIPES.remove(recipeClass);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> void addAllRecipes(Class<T> recipeClass, Set<T> recipeSet) {
//         RECIPES.put(recipeClass, recipeSet.stream().collect(Collectors.toSet()));
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> Optional<T> getRecipe(Class<T> recipeClass, List<ItemStack> inputs) {
//         return RECIPES.getOrDefault(recipeClass, new HashSet<>()).stream().filter(recipe -> recipe.getInputItems().equals(inputs)).findFirst().map(recipe -> (T) recipe);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T extends ICCRecipe> Set<T> getRecipes(Class<T> recipeClass) {
//         return (Set<T>) RECIPES.getOrDefault(recipeClass, new HashSet<>());
//     }
// }
// 
// Path: src/main/java/cn/mccraft/chinacraft/api/recipe/CrusherRecipe.java
// public class CrusherRecipe extends SimpleOreRecipe {
//     private int time;
//     private int energy;
//     private EnumCrusherMaterial material = EnumCrusherMaterial.STONE;
// 
//     public int getTime() {
//         return time;
//     }
// 
//     public void setTime(int time) {
//         this.time = time;
//     }
// 
//     public int getEnergy() {
//         return energy;
//     }
// 
//     public void setEnergy(int energy) {
//         this.energy = energy;
//     }
// 
//     public EnumCrusherMaterial getMaterial() {
//         return material;
//     }
// }
// 
// Path: src/main/java/cn/mccraft/chinacraft/block/machine/EnumCrusherMaterial.java
// public enum EnumCrusherMaterial implements IStringSerializable {
//     // Grey
//     STONE(189, 189, 189, 1),
// 
//     // Deep orange
//     BRONZE(255, 171, 145, 1),
// 
//     // Grey lighten
//     IRON(245, 245, 245, 1);
// 
//     private float r, g, b, a;
// 
//     EnumCrusherMaterial(int r, int g, int b, int a) {
//         Color color = new Color(r, g, b, a);
//         this.r = color.getRGBComponents(null)[0];
//         this.g = color.getRGBComponents(null)[1];
//         this.b = color.getRGBComponents(null)[2];
//         this.a = color.getRGBComponents(null)[3];
//     }
// 
//     public float getRed() {
//         return r;
//     }
// 
//     public float getGreen() {
//         return g;
//     }
// 
//     public float getBlue() {
//         return b;
//     }
// 
//     public float getAlpha() {
//         return a;
//     }
// 
//     @Override
//     public String getName() {
//         return this.toString().toLowerCase();
//     }
// }


// Path: src/main/java/cn/mccraft/chinacraft/block/tileentity/TileEntityCrusher.java
import cn.mccraft.chinacraft.api.CCRecipeManager;
import cn.mccraft.chinacraft.api.recipe.CrusherRecipe;
import cn.mccraft.chinacraft.block.machine.EnumCrusherMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.EnergyStorage;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;

        compound = super.writeToNBT(compound);
        compound.setTag("inventory", inventory.serializeNBT());
        compound.setTag("energy", CapabilityEnergy.ENERGY.getStorage().writeNBT(CapabilityEnergy.ENERGY, energyStorage, null));
        compound.setTag("inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().writeNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, inventory, null));
        return compound;
    }

    public EnumCrusherMaterial getCrusherMaterial() {
        return crusherMaterial;
    }

    @Override
    public void update() {
        if (currentRecipe != null && progress != 0) {
            if (progress == currentRecipe.getTime()) { // 达到时间, 输出
                inventory.setStackInSlot(0, ItemStack.EMPTY);
                inventory.setStackInSlot(1, ItemStack.EMPTY);
                inventory.setStackInSlot(2, currentRecipe.getOutputItems().get(0));
                inventory.setStackInSlot(3, currentRecipe.getOutputItems().get(1));
                currentRecipe = null;
                progress = 0;
            } else {
                // 继续运转
                ++progress;
            }
        } else if (progress != 0)
            // 清理
            progress = 0;
        else {
            progress = 0;
            Optional<CrusherRecipe> recipe = CCRecipeManager.getRecipe(CrusherRecipe.class, Arrays.asList(inventory.getStackInSlot(0), inventory.getStackInSlot(1)));