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.world.entity.LivingEntity;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.Minecraft;
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 bgt, final int integer2, final int integer3) {
        this.ingredients.add(new GhostIngredient(bgt, 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<?> bgw) {
        this.recipe = bgw;
    }
    
    public void render(final Minecraft dbn, final int integer2, final int integer3, final boolean boolean4, final float float5) {
        if (!Screen.hasControlDown()) {
            this.time += float5;
        }
        for (int integer4 = 0; integer4 < this.ingredients.size(); ++integer4) {
            final GhostIngredient a8 = this.ingredients.get(integer4);
            final int integer5 = a8.getX() + integer2;
            final int integer6 = a8.getY() + integer3;
            if (integer4 == 0 && boolean4) {
                GuiComponent.fill(integer5 - 4, integer6 - 4, integer5 + 20, integer6 + 20, 822018048);
            }
            else {
                GuiComponent.fill(integer5, integer6, integer5 + 16, integer6 + 16, 822018048);
            }
            final ItemStack ben11 = a8.getItem();
            final ItemRenderer dvz12 = dbn.getItemRenderer();
            dvz12.renderAndDecorateItem(dbn.player, ben11, integer5, integer6);
            RenderSystem.depthFunc(516);
            GuiComponent.fill(integer5, integer6, integer5 + 16, integer6 + 16, 822083583);
            RenderSystem.depthFunc(515);
            if (integer4 == 0) {
                dvz12.renderGuiItemDecorations(dbn.font, ben11, integer5, integer6);
            }
        }
    }
    
    public class GhostIngredient {
        private final Ingredient ingredient;
        private final int x;
        private final int y;
        
        public GhostIngredient(final Ingredient bgt, final int integer3, final int integer4) {
            this.ingredient = bgt;
            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];
        }
    }
}
