2025-11-24 22:52:51 +03:00

95 lines
4.0 KiB
Java

/*
* Decompiled with CFR 0.152.
*/
package net.minecraft.client.gui.screens.recipebook;
import java.util.List;
import net.minecraft.client.ClientRecipeBook;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.StateSwitchingButton;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.resources.Identifier;
import net.minecraft.world.item.crafting.ExtendedRecipeBookCategory;
import net.minecraft.world.item.crafting.display.RecipeDisplayEntry;
public class RecipeBookTabButton
extends StateSwitchingButton {
private static final WidgetSprites SPRITES = new WidgetSprites(Identifier.withDefaultNamespace("recipe_book/tab"), Identifier.withDefaultNamespace("recipe_book/tab_selected"));
private final RecipeBookComponent.TabInfo tabInfo;
private static final float ANIMATION_TIME = 15.0f;
private float animationTime;
public RecipeBookTabButton(RecipeBookComponent.TabInfo tabInfo) {
super(0, 0, 35, 27, false);
this.tabInfo = tabInfo;
this.initTextureValues(SPRITES);
}
public void startAnimation(ClientRecipeBook recipeBook, boolean isFiltering) {
RecipeCollection.CraftableStatus recipesToShow = isFiltering ? RecipeCollection.CraftableStatus.CRAFTABLE : RecipeCollection.CraftableStatus.ANY;
List<RecipeCollection> collection = recipeBook.getCollection(this.tabInfo.category());
for (RecipeCollection recipeCollection : collection) {
for (RecipeDisplayEntry recipe : recipeCollection.getSelectedRecipes(recipesToShow)) {
if (!recipeBook.willHighlight(recipe.id())) continue;
this.animationTime = 15.0f;
return;
}
}
}
@Override
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float a) {
if (this.sprites == null) {
return;
}
if (this.animationTime > 0.0f) {
float squeeze = 1.0f + 0.1f * (float)Math.sin(this.animationTime / 15.0f * (float)Math.PI);
graphics.pose().pushMatrix();
graphics.pose().translate((float)(this.getX() + 8), (float)(this.getY() + 12));
graphics.pose().scale(1.0f, squeeze);
graphics.pose().translate((float)(-(this.getX() + 8)), (float)(-(this.getY() + 12)));
}
Identifier sprite = this.sprites.get(true, this.isStateTriggered);
int xPos = this.getX();
if (this.isStateTriggered) {
xPos -= 2;
}
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, sprite, xPos, this.getY(), this.width, this.height);
this.renderIcon(graphics);
if (this.animationTime > 0.0f) {
graphics.pose().popMatrix();
this.animationTime -= a;
}
}
private void renderIcon(GuiGraphics graphics) {
int moveLeft;
int n = moveLeft = this.isStateTriggered ? -2 : 0;
if (this.tabInfo.secondaryIcon().isPresent()) {
graphics.renderFakeItem(this.tabInfo.primaryIcon(), this.getX() + 3 + moveLeft, this.getY() + 5);
graphics.renderFakeItem(this.tabInfo.secondaryIcon().get(), this.getX() + 14 + moveLeft, this.getY() + 5);
} else {
graphics.renderFakeItem(this.tabInfo.primaryIcon(), this.getX() + 9 + moveLeft, this.getY() + 5);
}
}
public ExtendedRecipeBookCategory getCategory() {
return this.tabInfo.category();
}
public boolean updateVisibility(ClientRecipeBook book) {
List<RecipeCollection> collections = book.getCollection(this.tabInfo.category());
this.visible = false;
for (RecipeCollection collection : collections) {
if (!collection.hasAnySelected()) continue;
this.visible = true;
break;
}
return this.visible;
}
}