Skip to content

Commit

Permalink
Render text fields using the new texture
Browse files Browse the repository at this point in the history
Minecraft 1.20.2 introduced a background texture for text field widgets.
It looks the same as the previous design, but allows for resource packs
to customize it. Unfortunately, it also makes text fields slightly
smaller than before (if you don't adjust for it).

This commit changes MultilineTextFieldWidget to use the new background
texture. It's still the wrong size; that should be resolved in the next
commit.
  • Loading branch information
arm32x committed Dec 28, 2023
1 parent 05d6d83 commit 2d6dbef
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,8 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt
}

if (self.getDrawsBackground()) {
int borderColor = this.isFocused() ? 0xFFFFFFFF : 0xFFA0A0A0;
context.fill(this.getX() - 1, this.getY() - 1, this.getX() + this.width + 1, this.getY() + this.height + 1, borderColor);
context.fill(this.getX(), this.getY(), this.getX() + this.width, this.getY() + this.height, 0xFF000000);
var textureId = TextFieldWidgetAccessor.getTextures().get(isNarratable(), isFocused());
context.drawGuiTexture(textureId, getX(), getY(), getWidth(), getHeight());
}

Window window = MinecraftClient.getInstance().getWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.function.BiFunction;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.OrderedText;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -19,4 +20,6 @@ public interface TextFieldWidgetAccessor {
@Accessor boolean isFocusUnlocked();

@Invoker int invokeGetMaxLength();

@Accessor("TEXTURES") static ButtonTextures getTextures() { throw new AssertionError(); };
}

0 comments on commit 2d6dbef

Please sign in to comment.