package net.minecraft.client.gui.screens.recipebook;

import net.minecraft.util.Mth;
import net.minecraft.client.renderer.entity.ItemRenderer;
import net.minecraft.world.item.ItemStack;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.Minecraft;
import com.mojang.blaze3d.vertex.PoseStack;
import javax.annotation.Nullable;
import net.minecraft.world.item.crafting.Ingredient;
import com.google.common.collect.Lists;
import java.util.List;
import net.minecraft.world.item.crafting.Recipe;

public class GhostRecipe {
    private Recipe<?> recipe;
    private final List<GhostIngredient> ingredients;
    private float time;
    
    public GhostRecipe() {
        this.ingredients = Lists.newArrayList();
    }
    
    public void clear() {
        this.recipe = null;
        this.ingredients.clear();
        this.time = 0.0f;
    }
    
    public void addIngredient(final Ingredient bmr, final int integer2, final int integer3) {
        this.ingredients.add(new GhostIngredient(bmr, integer2, integer3));
    }
    
    public GhostIngredient get(final int integer) {
        return this.ingredients.get(integer);
    }
    
    public int size() {
        return this.ingredients.size();
    }
    
    @Nullable
    public Recipe<?> getRecipe() {
        return this.recipe;
    }
    
    public void setRecipe(final Recipe<?> bmu) {
        this.recipe = bmu;
    }
    
    public void render(final PoseStack dhl, final Minecraft dlx, final int integer3, final int integer4, final boolean boolean5, final float float6) {
        if (!Screen.hasControlDown()) {
            this.time += float6;
        }
        for (int integer5 = 0; integer5 < this.ingredients.size(); ++integer5) {
            final GhostIngredient a9 = this.ingredients.get(integer5);
            final int integer6 = a9.getX() + integer3;
            final int integer7 = a9.getY() + integer4;
            if (integer5 == 0 && boolean5) {
                GuiComponent.fill(dhl, integer6 - 4, integer7 - 4, integer6 + 20, integer7 + 20, 822018048);
            }
            else {
                GuiComponent.fill(dhl, integer6, integer7, integer6 + 16, integer7 + 16, 822018048);
            }
            final ItemStack bki12 = a9.getItem();
            final ItemRenderer ehh13 = dlx.getItemRenderer();
            ehh13.renderAndDecorateFakeItem(bki12, integer6, integer7);
            RenderSystem.depthFunc(516);
            GuiComponent.fill(dhl, integer6, integer7, integer6 + 16, integer7 + 16, 822083583);
            RenderSystem.depthFunc(515);
            if (integer5 == 0) {
                ehh13.renderGuiItemDecorations(dlx.font, bki12, integer6, integer7);
            }
        }
    }
    
    public class GhostIngredient {
        private final Ingredient ingredient;
        private final int x;
        private final int y;
        
        public GhostIngredient(final Ingredient bmr, final int integer3, final int integer4) {
            this.ingredient = bmr;
            this.x = integer3;
            this.y = integer4;
        }
        
        public int getX() {
            return this.x;
        }
        
        public int getY() {
            return this.y;
        }
        
        public ItemStack getItem() {
            final ItemStack[] arr2 = this.ingredient.getItems();
            return arr2[Mth.floor(GhostRecipe.this.time / 30.0f) % arr2.length];
        }
    }
}
