package net.rustnotmc.client.gui; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiTextField; /** * A text field that shows dots instead of what is in it. * * The game has no password field, and a password that appears on the screen * while it is typed is a password that ends up in a screenshot. * * The game draws the text field from its own private text, so the only way to * mask it without copying the whole field is to put the dots in for the moment * it takes to draw and put the real text back afterwards. The cursor ends up * at the end of the text, which for a password is where it is wanted anyway. */ public class RsxPasswordField extends GuiTextField { public RsxPasswordField(int id, FontRenderer font, int x, int y, int width, int height) { super(id, font, x, y, width, height); } @Override public void drawTextBox() { String real = getText(); if (real.isEmpty()) { super.drawTextBox(); return; } StringBuilder dots = new StringBuilder(real.length()); for (int i = 0; i < real.length(); i++) { dots.append('*'); } setText(dots.toString()); super.drawTextBox(); setText(real); } }