/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Maps * org.jspecify.annotations.Nullable */ package net.minecraft.client.gui.screens.advancements; import com.google.common.collect.Maps; import java.util.Map; import java.util.Optional; import net.minecraft.advancements.AdvancementHolder; import net.minecraft.advancements.AdvancementNode; import net.minecraft.advancements.DisplayInfo; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.advancements.AdvancementTabType; import net.minecraft.client.gui.screens.advancements.AdvancementWidget; import net.minecraft.client.gui.screens.advancements.AdvancementsScreen; import net.minecraft.client.renderer.RenderPipelines; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.core.ClientAsset; import net.minecraft.network.chat.Component; import net.minecraft.resources.Identifier; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import org.jspecify.annotations.Nullable; public class AdvancementTab { private final Minecraft minecraft; private final AdvancementsScreen screen; private final AdvancementTabType type; private final int index; private final AdvancementNode rootNode; private final DisplayInfo display; private final ItemStack icon; private final Component title; private final AdvancementWidget root; private final Map widgets = Maps.newLinkedHashMap(); private double scrollX; private double scrollY; private int minX = Integer.MAX_VALUE; private int minY = Integer.MAX_VALUE; private int maxX = Integer.MIN_VALUE; private int maxY = Integer.MIN_VALUE; private float fade; private boolean centered; public AdvancementTab(Minecraft minecraft, AdvancementsScreen screen, AdvancementTabType type, int index, AdvancementNode rootNode, DisplayInfo display) { this.minecraft = minecraft; this.screen = screen; this.type = type; this.index = index; this.rootNode = rootNode; this.display = display; this.icon = display.getIcon(); this.title = display.getTitle(); this.root = new AdvancementWidget(this, minecraft, rootNode, display); this.addWidget(this.root, rootNode.holder()); } public AdvancementTabType getType() { return this.type; } public int getIndex() { return this.index; } public AdvancementNode getRootNode() { return this.rootNode; } public Component getTitle() { return this.title; } public DisplayInfo getDisplay() { return this.display; } public void drawTab(GuiGraphics graphics, int xo, int yo, boolean selected) { this.type.draw(graphics, xo, yo, selected, this.index); } public void drawIcon(GuiGraphics graphics, int xo, int yo) { this.type.drawIcon(graphics, xo, yo, this.index, this.icon); } public void drawContents(GuiGraphics graphics, int windowLeft, int windowTop) { if (!this.centered) { this.scrollX = 117 - (this.maxX + this.minX) / 2; this.scrollY = 56 - (this.maxY + this.minY) / 2; this.centered = true; } graphics.enableScissor(windowLeft, windowTop, windowLeft + 234, windowTop + 113); graphics.pose().pushMatrix(); graphics.pose().translate((float)windowLeft, (float)windowTop); Identifier background = this.display.getBackground().map(ClientAsset.ResourceTexture::texturePath).orElse(TextureManager.INTENTIONAL_MISSING_TEXTURE); int intScrollX = Mth.floor(this.scrollX); int intScrollY = Mth.floor(this.scrollY); int left = intScrollX % 16; int top = intScrollY % 16; for (int x = -1; x <= 15; ++x) { for (int y = -1; y <= 8; ++y) { graphics.blit(RenderPipelines.GUI_TEXTURED, background, left + 16 * x, top + 16 * y, 0.0f, 0.0f, 16, 16, 16, 16); } } this.root.drawConnectivity(graphics, intScrollX, intScrollY, true); this.root.drawConnectivity(graphics, intScrollX, intScrollY, false); this.root.draw(graphics, intScrollX, intScrollY); graphics.pose().popMatrix(); graphics.disableScissor(); } public void drawTooltips(GuiGraphics graphics, int mouseX, int mouseY, int xo, int yo) { graphics.fill(0, 0, 234, 113, Mth.floor(this.fade * 255.0f) << 24); boolean hovering = false; int intScrollX = Mth.floor(this.scrollX); int intScrollY = Mth.floor(this.scrollY); if (mouseX > 0 && mouseX < 234 && mouseY > 0 && mouseY < 113) { for (AdvancementWidget widget : this.widgets.values()) { if (!widget.isMouseOver(intScrollX, intScrollY, mouseX, mouseY)) continue; hovering = true; widget.drawHover(graphics, intScrollX, intScrollY, this.fade, xo, yo); break; } } this.fade = hovering ? Mth.clamp(this.fade + 0.02f, 0.0f, 0.3f) : Mth.clamp(this.fade - 0.04f, 0.0f, 1.0f); } public boolean isMouseOver(int xo, int yo, double mx, double my) { return this.type.isMouseOver(xo, yo, this.index, mx, my); } public static @Nullable AdvancementTab create(Minecraft minecraft, AdvancementsScreen screen, int index, AdvancementNode root) { Optional display = root.advancement().display(); if (display.isEmpty()) { return null; } for (AdvancementTabType type : AdvancementTabType.values()) { if (index >= type.getMax()) { index -= type.getMax(); continue; } return new AdvancementTab(minecraft, screen, type, index, root, display.get()); } return null; } public void scroll(double x, double y) { if (this.canScrollHorizontally()) { this.scrollX = Mth.clamp(this.scrollX + x, (double)(-(this.maxX - 234)), 0.0); } if (this.canScrollVertically()) { this.scrollY = Mth.clamp(this.scrollY + y, (double)(-(this.maxY - 113)), 0.0); } } public boolean canScrollHorizontally() { return this.maxX - this.minX > 234; } public boolean canScrollVertically() { return this.maxY - this.minY > 113; } public void addAdvancement(AdvancementNode node) { Optional display = node.advancement().display(); if (display.isEmpty()) { return; } AdvancementWidget widget = new AdvancementWidget(this, this.minecraft, node, display.get()); this.addWidget(widget, node.holder()); } private void addWidget(AdvancementWidget widget, AdvancementHolder advancement) { this.widgets.put(advancement, widget); int x0 = widget.getX(); int x1 = x0 + 28; int y0 = widget.getY(); int y1 = y0 + 27; this.minX = Math.min(this.minX, x0); this.maxX = Math.max(this.maxX, x1); this.minY = Math.min(this.minY, y0); this.maxY = Math.max(this.maxY, y1); for (AdvancementWidget other : this.widgets.values()) { other.attachToParent(); } } public @Nullable AdvancementWidget getWidget(AdvancementHolder advancement) { return this.widgets.get(advancement); } public AdvancementsScreen getScreen() { return this.screen; } }