Continue mapping migration

This commit is contained in:
Aleksey 2021-04-12 21:38:22 +03:00
parent 99ade39404
commit f03fd03bd0
499 changed files with 12567 additions and 12723 deletions

View file

@ -1,72 +1,69 @@
package ru.betterend.client.gui;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.world.entity.player.PlayerInventory;
import net.minecraft.screen.slot.Slot;
import net.minecraft.screen.slot.SlotActionType;
import net.minecraft.text.StringVisitable;
import net.minecraft.text.Text;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
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.network.chat.FormattedText;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import ru.betterend.BetterEnd;
@Environment(EnvType.CLIENT)
public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHandler> implements RecipeBookProvider {
public class EndStoneSmelterScreen extends AbstractContainerScreen<EndStoneSmelterScreenHandler> implements RecipeUpdateListener {
private final static ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation(
"textures/gui/recipe_button.png");
private final static ResourceLocation RECIPE_BUTTON_TEXTURE = new ResourceLocation("textures/gui/recipe_button.png");
private final static ResourceLocation BACKGROUND_TEXTURE = BetterEnd.makeID("textures/gui/smelter_gui.png");
public final EndStoneSmelterRecipeBookScreen recipeBook;
private boolean narrow;
public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, PlayerInventory inventory, Text title) {
public EndStoneSmelterScreen(EndStoneSmelterScreenHandler handler, Inventory inventory, Component title) {
super(handler, inventory, title);
this.recipeBook = new EndStoneSmelterRecipeBookScreen();
}
public void init() {
super.init();
this.narrow = this.width < 379;
this.recipeBook.initialize(width, height, client, narrow, handler);
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
this.addButton(new TexturedButtonWidget(x + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE,
(buttonWidget) -> {
this.recipeBook.reset(narrow);
this.recipeBook.toggleOpen();
this.x = this.recipeBook.findLeftEdge(narrow, width, backgroundWidth);
((TexturedButtonWidget) buttonWidget).setPos(this.x + 20, height / 2 - 49);
}));
this.titleX = (this.backgroundWidth - this.textRenderer.getWidth((StringVisitable) this.title)) / 2;
this.recipeBook.init(width, height, minecraft, narrow, menu);
this.leftPos = this.recipeBook.updateScreenPosition(narrow, width, imageWidth);
this.addButton(new ImageButton(leftPos + 20, height / 2 - 49, 20, 18, 0, 0, 19, RECIPE_BUTTON_TEXTURE, (buttonWidget) -> {
this.recipeBook.initVisuals(narrow);
this.recipeBook.toggleVisibility();
this.leftPos = this.recipeBook.updateScreenPosition(narrow, width, imageWidth);
((ImageButton) buttonWidget).setPosition(this.leftPos + 20, height / 2 - 49);
}));
this.titleLabelX = (this.imageWidth - this.font.width((FormattedText)this.title)) / 2;
}
@Override
public void tick() {
super.tick();
this.recipeBook.update();
this.recipeBook.tick();
}
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
this.renderBackground(matrices);
if (this.recipeBook.isOpen() && this.narrow) {
this.drawBackground(matrices, delta, mouseX, mouseY);
if (this.recipeBook.isVisible() && this.narrow) {
this.renderBg(matrices, delta, mouseX, mouseY);
this.recipeBook.render(matrices, mouseX, mouseY, delta);
} else {
this.recipeBook.render(matrices, mouseX, mouseY, delta);
super.render(matrices, mouseX, mouseY, delta);
this.recipeBook.drawGhostSlots(matrices, x, y, true, delta);
this.recipeBook.renderGhostRecipe(matrices, leftPos, topPos, true, delta);
}
this.drawMouseoverTooltip(matrices, mouseX, mouseY);
this.recipeBook.drawTooltip(matrices, x, y, mouseX, mouseY);
this.renderTooltip(matrices, mouseX, mouseY);
this.recipeBook.renderTooltip(matrices, leftPos, topPos, mouseX, mouseY);
}
@Override
@ -74,28 +71,25 @@ public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHa
if (this.recipeBook.mouseClicked(mouseX, mouseY, button)) {
return true;
} else {
return this.narrow && this.recipeBook.isOpen() ? true : super.mouseClicked(mouseX, mouseY, button);
return this.narrow && this.recipeBook.isVisible() ? true : super.mouseClicked(mouseX, mouseY, button);
}
}
@Override
protected void onMouseClick(Slot slot, int invSlot, int clickData, SlotActionType actionType) {
super.onMouseClick(slot, invSlot, clickData, actionType);
protected void slotClicked(Slot slot, int invSlot, int clickData, ClickType actionType) {
super.slotClicked(slot, invSlot, clickData, actionType);
this.recipeBook.slotClicked(slot);
}
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
return this.recipeBook.keyPressed(keyCode, scanCode, modifiers) ? false
: super.keyPressed(keyCode, scanCode, modifiers);
return this.recipeBook.keyPressed(keyCode, scanCode, modifiers) ? false : super.keyPressed(keyCode, scanCode, modifiers);
}
@Override
protected boolean isClickOutsideBounds(double mouseX, double mouseY, int left, int top, int button) {
boolean isMouseOut = mouseX < left || mouseY < top || mouseX >= (left + backgroundWidth)
|| mouseY >= (top + backgroundHeight);
return this.recipeBook.isClickOutsideBounds(mouseX, mouseY, x, y, backgroundWidth, backgroundHeight, button)
&& isMouseOut;
protected boolean hasClickedOutside(double mouseX, double mouseY, int left, int top, int button) {
boolean isMouseOut = mouseX < left || mouseY < top || mouseX >= (left + imageWidth) || mouseY >= (top + imageHeight);
return this.recipeBook.hasClickedOutside(mouseX, mouseY, leftPos, topPos, imageWidth, imageHeight, button) && isMouseOut;
}
@Override
@ -104,32 +98,32 @@ public class EndStoneSmelterScreen extends HandledScreen<EndStoneSmelterScreenHa
}
@Override
public void refreshRecipeBook() {
this.recipeBook.refresh();
public void recipesUpdated() {
this.recipeBook.recipesUpdated();
}
@Override
public RecipeBookWidget getRecipeBookWidget() {
public RecipeBookComponent getRecipeBookComponent() {
return this.recipeBook;
}
@Override
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
protected void renderBg(PoseStack matrices, float delta, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.client.getTextureManager().bindTexture(BACKGROUND_TEXTURE);
this.drawTexture(matrices, x, y, 0, 0, backgroundWidth, backgroundHeight);
this.minecraft.getTextureManager().bind(INVENTORY_LOCATION);
this.blit(matrices, leftPos, topPos, 0, 0, imageWidth, imageHeight);
int p;
if (handler.isBurning()) {
p = handler.getFuelProgress();
this.drawTexture(matrices, x + 56, y + 36 + 12 - p, 176, 12 - p, 14, p + 1);
if (menu.isBurning()) {
p = menu.getFuelProgress();
this.blit(matrices, leftPos + 56, topPos + 36 + 12 - p, 176, 12 - p, 14, p + 1);
}
p = handler.getSmeltProgress();
this.drawTexture(matrices, x + 92, y + 34, 176, 14, p + 1, 16);
p = menu.getSmeltProgress();
this.blit(matrices, leftPos + 92, topPos + 34, 176, 14, p + 1, 16);
}
@Override
public void removed() {
this.recipeBook.close();
this.recipeBook.removed();
super.removed();
}
}