package net.minecraft.client.gui.components.toasts;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.client.resources.language.I18n;
import com.mojang.blaze3d.systems.RenderSystem;
import com.google.common.collect.Lists;
import net.minecraft.world.item.crafting.Recipe;
import java.util.List;

public class RecipeToast implements Toast {
    private final List<Recipe<?>> recipes;
    private long lastChanged;
    private boolean changed;
    
    public RecipeToast(final Recipe<?> bgw) {
        (this.recipes = Lists.newArrayList()).add(bgw);
    }
    
    @Override
    public Visibility render(final ToastComponent deb, final long long2) {
        if (this.changed) {
            this.lastChanged = long2;
            this.changed = false;
        }
        if (this.recipes.isEmpty()) {
            return Visibility.HIDE;
        }
        deb.getMinecraft().getTextureManager().bind(RecipeToast.TEXTURE);
        RenderSystem.color3f(1.0f, 1.0f, 1.0f);
        deb.blit(0, 0, 0, 32, 160, 32);
        deb.getMinecraft().font.draw(I18n.get("recipe.toast.title"), 30.0f, 7.0f, -11534256);
        deb.getMinecraft().font.draw(I18n.get("recipe.toast.description"), 30.0f, 18.0f, -16777216);
        final Recipe<?> bgw5 = this.recipes.get((int)(long2 / (5000L / this.recipes.size()) % this.recipes.size()));
        final ItemStack ben6 = bgw5.getToastSymbol();
        RenderSystem.pushMatrix();
        RenderSystem.scalef(0.6f, 0.6f, 1.0f);
        deb.getMinecraft().getItemRenderer().renderAndDecorateItem(null, ben6, 3, 3);
        RenderSystem.popMatrix();
        deb.getMinecraft().getItemRenderer().renderAndDecorateItem(null, bgw5.getResultItem(), 8, 8);
        return (long2 - this.lastChanged >= 5000L) ? Visibility.HIDE : Visibility.SHOW;
    }
    
    public void addItem(final Recipe<?> bgw) {
        if (this.recipes.add(bgw)) {
            this.changed = true;
        }
    }
    
    public static void addOrUpdate(final ToastComponent deb, final Recipe<?> bgw) {
        final RecipeToast ddy3 = deb.<RecipeToast>getToast(RecipeToast.class, RecipeToast.NO_TOKEN);
        if (ddy3 == null) {
            deb.addToast(new RecipeToast(bgw));
        }
        else {
            ddy3.addItem(bgw);
        }
    }
}
