From a16d63d864ea676885fae5e57c829438e55b4732 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 1 Oct 2024 20:37:22 +0100 Subject: [PATCH] One fewer allocation, waaow --- .../ContainerLocationDeciderScreen.java | 29 ++-- .../gui/widgets/TextRenderable.java | 126 ------------------ 2 files changed, 19 insertions(+), 136 deletions(-) delete mode 100644 src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TextRenderable.java diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java b/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java index 4aee637..076fbe5 100644 --- a/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java +++ b/src/main/java/uk/protonull/civ/chesttracker/gui/screens/ContainerLocationDeciderScreen.java @@ -16,7 +16,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import uk.protonull.civ.chesttracker.gui.widgets.TextRenderable; import uk.protonull.civ.chesttracker.mixing.InventoryWindow; import uk.protonull.civ.chesttracker.utilities.Shortcuts; @@ -57,14 +56,6 @@ public ContainerLocationDeciderScreen( @Override protected void init() { - addRenderableOnly(new TextRenderable.CentreAligned( - this.font, - this.width / 2, - 20, - Component.translatable("civchesttracker.picker.header"), - PICKER_COLOUR_RBG - )); - addRenderableWidget(new Button( (this.width / 2) - (Button.DEFAULT_WIDTH / 2), this.height - 40 - Button.DEFAULT_HEIGHT, @@ -112,7 +103,25 @@ public void renderBackground( final int mouseY, final float partialTick ) { - // DO NOTHING + // Prevent the blurry background from being rendered as the player needs to be able to see the world. + } + + @Override + public void render( + final @NotNull GuiGraphics guiGraphics, + final int mouseX, + final int mouseY, + final float partialTick + ) { + super.render(guiGraphics, mouseX, mouseY, partialTick); + + guiGraphics.drawCenteredString( + this.font, + Component.translatable("civchesttracker.picker.header"), + this.width / 2, + 20, + PICKER_COLOUR_RBG + ); } @Override diff --git a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TextRenderable.java b/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TextRenderable.java deleted file mode 100644 index 634a2da..0000000 --- a/src/main/java/uk/protonull/civ/chesttracker/gui/widgets/TextRenderable.java +++ /dev/null @@ -1,126 +0,0 @@ -package uk.protonull.civ.chesttracker.gui.widgets; - -import java.util.Objects; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -public sealed abstract class TextRenderable implements Renderable { - public @NotNull Font font; - public int x; - public int y; - public @NotNull Component text; - public int colour; - - protected TextRenderable( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text - ) { - this(font, x, y, text, 0xFF_FF_FF); - } - - protected TextRenderable( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text, - final int colour - ) { - this.font = Objects.requireNonNull(font); - this.x = x; - this.y = y; - this.text = Objects.requireNonNull(text); - this.colour = colour; - } - - public static final class LeftAligned extends TextRenderable { - public LeftAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text - ) { - super(font, x, y, text); - } - public LeftAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text, - final int colour - ) { - super(font, x, y, text, colour); - } - @Override - public void render( - final @NotNull GuiGraphics guiGraphics, - final int mouseX, - final int mouseY, - final float partialTick - ) { - guiGraphics.drawString(this.font, this.text, this.x, this.y, this.colour); - } - } - - public static final class CentreAligned extends TextRenderable { - public CentreAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text - ) { - super(font, x, y, text); - } - public CentreAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text, - final int colour - ) { - super(font, x, y, text, colour); - } - @Override - public void render( - final @NotNull GuiGraphics guiGraphics, - final int mouseX, - final int mouseY, - final float partialTick - ) { - guiGraphics.drawCenteredString(this.font, this.text, this.x, this.y, this.colour); - } - } - - public static final class RightAligned extends TextRenderable { - public RightAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text - ) { - super(font, x, y, text); - } - public RightAligned( - final @NotNull Font font, - final int x, - final int y, - final @NotNull Component text, - final int colour - ) { - super(font, x, y, text, colour); - } - @Override - public void render( - final @NotNull GuiGraphics guiGraphics, - final int mouseX, - final int mouseY, - final float partialTick - ) { - guiGraphics.drawString(this.font, this.text, this.x - this.font.width(this.text), this.y, this.colour); - } - } -}