minecraft-src/net/minecraft/client/gui/screens/inventory/AbstractFurnaceScreen.java
2025-07-04 01:41:11 +03:00

133 lines
5.2 KiB
Java

package net.minecraft.client.gui.screens.inventory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.recipebook.AbstractFurnaceRecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractFurnaceMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
@Environment(EnvType.CLIENT)
public abstract class AbstractFurnaceScreen<T extends AbstractFurnaceMenu> extends AbstractContainerScreen<T> implements RecipeUpdateListener {
public final AbstractFurnaceRecipeBookComponent recipeBookComponent;
private boolean widthTooNarrow;
private final ResourceLocation texture;
private final ResourceLocation litProgressSprite;
private final ResourceLocation burnProgressSprite;
public AbstractFurnaceScreen(
T menu,
AbstractFurnaceRecipeBookComponent recipeBookComponent,
Inventory playerInventory,
Component title,
ResourceLocation texture,
ResourceLocation listProgressSprite,
ResourceLocation burnProgressSprite
) {
super(menu, playerInventory, title);
this.recipeBookComponent = recipeBookComponent;
this.texture = texture;
this.litProgressSprite = listProgressSprite;
this.burnProgressSprite = burnProgressSprite;
}
@Override
public void init() {
super.init();
this.widthTooNarrow = this.width < 379;
this.recipeBookComponent.init(this.width, this.height, this.minecraft, this.widthTooNarrow, this.menu);
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
this.addRenderableWidget(new ImageButton(this.leftPos + 20, this.height / 2 - 49, 20, 18, RecipeBookComponent.RECIPE_BUTTON_SPRITES, button -> {
this.recipeBookComponent.toggleVisibility();
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
button.setPosition(this.leftPos + 20, this.height / 2 - 49);
}));
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
}
@Override
public void containerTick() {
super.containerTick();
this.recipeBookComponent.tick();
}
@Override
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
if (this.recipeBookComponent.isVisible() && this.widthTooNarrow) {
this.renderBackground(guiGraphics, mouseX, mouseY, partialTick);
this.recipeBookComponent.render(guiGraphics, mouseX, mouseY, partialTick);
} else {
super.render(guiGraphics, mouseX, mouseY, partialTick);
this.recipeBookComponent.render(guiGraphics, mouseX, mouseY, partialTick);
this.recipeBookComponent.renderGhostRecipe(guiGraphics, this.leftPos, this.topPos, true, partialTick);
}
this.renderTooltip(guiGraphics, mouseX, mouseY);
this.recipeBookComponent.renderTooltip(guiGraphics, this.leftPos, this.topPos, mouseX, mouseY);
}
@Override
protected void renderBg(GuiGraphics guiGraphics, float partialTick, int mouseX, int mouseY) {
int i = this.leftPos;
int j = this.topPos;
guiGraphics.blit(this.texture, i, j, 0, 0, this.imageWidth, this.imageHeight);
if (this.menu.isLit()) {
int k = 14;
int l = Mth.ceil(this.menu.getLitProgress() * 13.0F) + 1;
guiGraphics.blitSprite(this.litProgressSprite, 14, 14, 0, 14 - l, i + 56, j + 36 + 14 - l, 14, l);
}
int k = 24;
int l = Mth.ceil(this.menu.getBurnProgress() * 24.0F);
guiGraphics.blitSprite(this.burnProgressSprite, 24, 16, 0, 0, i + 79, j + 34, l, 16);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (this.recipeBookComponent.mouseClicked(mouseX, mouseY, button)) {
return true;
} else {
return this.widthTooNarrow && this.recipeBookComponent.isVisible() ? true : super.mouseClicked(mouseX, mouseY, button);
}
}
@Override
protected void slotClicked(Slot slot, int slotId, int mouseButton, ClickType type) {
super.slotClicked(slot, slotId, mouseButton, type);
this.recipeBookComponent.slotClicked(slot);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return this.recipeBookComponent.keyPressed(keyCode, scanCode, modifiers) ? true : super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
protected boolean hasClickedOutside(double mouseX, double mouseY, int guiLeft, int guiTop, int mouseButton) {
boolean bl = mouseX < guiLeft || mouseY < guiTop || mouseX >= guiLeft + this.imageWidth || mouseY >= guiTop + this.imageHeight;
return this.recipeBookComponent.hasClickedOutside(mouseX, mouseY, this.leftPos, this.topPos, this.imageWidth, this.imageHeight, mouseButton) && bl;
}
@Override
public boolean charTyped(char codePoint, int modifiers) {
return this.recipeBookComponent.charTyped(codePoint, modifiers) ? true : super.charTyped(codePoint, modifiers);
}
@Override
public void recipesUpdated() {
this.recipeBookComponent.recipesUpdated();
}
@Override
public RecipeBookComponent getRecipeBookComponent() {
return this.recipeBookComponent;
}
}