Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 :)

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?

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.