Posted June 23, 20205 yr After fixing my last issue, I now have another issue I cannot solve. The TextFieldWidget lets me type in characters into the textbox, but it won't let me delete characters. How am I able to do this? Here is my code: package mypackage; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.TranslationTextComponent; public class GUIPunishKick extends Screen { private final int WIDTH = this.width; private final int HEIGHT = this.height; private TextFieldWidget user; public GUIPunishKick() { super(new TranslationTextComponent("screen.guipunishkick.spawn")); } @Override protected void init() { int relX = WIDTH /2; int relY = HEIGHT /2; this.user = new TextFieldWidget(font, relX + 10, relY + 40, 160, 20, "User"); user.setText(""); user.setFocused2(true); user.setVisible(true); user.setMaxStringLength(17); //buttons } public void changeFocus() { if(user.isFocused()) user.setFocused2(false); else user.setFocused2(true); } public boolean charTyped(char par1, int par2) { super.charTyped(par1, par2); if(user.isFocused()) { this.user.charTyped(par1, par2); } return true; } public void updateScreen() { this.updateScreen(); this.user.moveCursorBy(this.user.getText().length()); } protected void mouseClicked(int x, int y, int btn) { super.mouseClicked(x, y, btn); this.user.mouseClicked(x, y, btn); } @Override public boolean isPauseScreen() { return false; } @Override public void render(int mouseX, int mouseY, float partialTicks) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); int relX = (this.width - WIDTH) /2; int relY = (this.height - HEIGHT) /2; this.blit(relX, relY, 0, 0, WIDTH, HEIGHT); this.user.render(mouseX, mouseY, partialTicks); super.render(mouseX, mouseY, partialTicks); } public static void open() { Minecraft.getInstance().displayGuiScreen(new GUIPunishKick()); } } I would really like to know how I can enable a way to delete characters from my TextFieldWidget. Thanks
June 23, 20205 yr Hi, You need to override keyPressed too and put logic inside to pass the key information to textwidget if it has focus Something like this: @Override public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { if (txtXPToTransfer.isFocused()) { txtXPToTransfer.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } †GnR† Slash can one man truly make a difference?
June 23, 20205 yr Author 7 hours ago, GnRSlashSP said: Hi, You need to override keyPressed too and put logic inside to pass the key information to textwidget if it has focus Something like this: @Override public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) { if (txtXPToTransfer.isFocused()) { txtXPToTransfer.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_); } Thank you this is exactly what I needed
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.