package net.minecraft.client.gui.screens.recipebook; import com.google.common.collect.Lists; import java.util.List; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.RenderType; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.RecipeHolder; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class GhostRecipe { @Nullable private RecipeHolder recipe; private final List ingredients = Lists.newArrayList(); float time; public void clear() { this.recipe = null; this.ingredients.clear(); this.time = 0.0F; } public void addIngredient(Ingredient ingredient, int x, int y) { this.ingredients.add(new GhostRecipe.GhostIngredient(ingredient, x, y)); } public GhostRecipe.GhostIngredient get(int index) { return (GhostRecipe.GhostIngredient)this.ingredients.get(index); } public int size() { return this.ingredients.size(); } @Nullable public RecipeHolder getRecipe() { return this.recipe; } public void setRecipe(RecipeHolder recipe) { this.recipe = recipe; } public void render(GuiGraphics guiGraphics, Minecraft minecraft, int leftPos, int topPos, boolean offset, float partialTick) { if (!Screen.hasControlDown()) { this.time += partialTick; } for (int i = 0; i < this.ingredients.size(); i++) { GhostRecipe.GhostIngredient ghostIngredient = (GhostRecipe.GhostIngredient)this.ingredients.get(i); int j = ghostIngredient.getX() + leftPos; int k = ghostIngredient.getY() + topPos; if (i == 0 && offset) { guiGraphics.fill(j - 4, k - 4, j + 20, k + 20, 822018048); } else { guiGraphics.fill(j, k, j + 16, k + 16, 822018048); } ItemStack itemStack = ghostIngredient.getItem(); guiGraphics.renderFakeItem(itemStack, j, k); guiGraphics.fill(RenderType.guiGhostRecipeOverlay(), j, k, j + 16, k + 16, 822083583); if (i == 0) { guiGraphics.renderItemDecorations(minecraft.font, itemStack, j, k); } } } @Environment(EnvType.CLIENT) public class GhostIngredient { private final Ingredient ingredient; private final int x; private final int y; public GhostIngredient(final Ingredient ingredient, final int x, final int y) { this.ingredient = ingredient; this.x = x; this.y = y; } public int getX() { return this.x; } public int getY() { return this.y; } public ItemStack getItem() { ItemStack[] itemStacks = this.ingredient.getItems(); return itemStacks.length == 0 ? ItemStack.EMPTY : itemStacks[Mth.floor(GhostRecipe.this.time / 30.0F) % itemStacks.length]; } } }