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

Hi,

 

I am trying to use the Checkbox. The MC implementation of the checkbox doesnt have a feature to save the current state if the checkbox is clicked. Therefore I added the save feature by extending the Checkbox class. Here you can see the source code:

 

GuiCheckBox:

Spoiler

public class GuiCheckBox extends CheckboxWidget {

	private final CheckBoxOption option;
	private final IConfig config;

	public GuiCheckBox(int x, int y, int width, int height, String message, CheckBoxOption option, IConfig config) {
		super(x, y, width, height, message, option.isChecked());
		this.option = option;
		this.config = config;
	}

	@Override
	public void onPress() {
		super.onPress();
		option.setChecked(super.isChecked());
		config.save();
	}
}

 

The CheckBoxOption is a field inside the config class to provide easy access to a setting.

 

CheckBoxOption:

Spoiler

public class CheckBoxOption {

	@Getter
	@Setter
	private boolean checked = true;

	public CheckBoxOption() {
	}

	public CheckBoxOption(boolean checked) {
		this.checked = checked;
	}
}

 

 

The Config is a simple class to store settings.

IConfig:

Spoiler

public interface IConfig {

	public String getFileName();

	public void save();
}

 

 

And the initialization of a GuiCheckbox:

Spoiler

private final Config cfg;

...

GuiCheckBox showChunk = new GuiCheckBox(leftColumn, posY, 50, 20, I18n.translate("settings.chunk"), cfg.getShowChunk(), cfg);
addButton(showChunk);

 

 

There is no compile error, but if I open the Screen with the GuiCheckbox, the game is crashing and I get an error message which I do not understand:

 

Spoiler

[21:55:31] [main/FATAL]: Unreported exception thrown!
java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    de/d4n1el89/chunkinfo/GuiConfig.init()V @59: invokevirtual
  Reason:
    Type 'de/d4n1el89/modutils/gui/GuiCheckBox' (current frame, stack[1]) is not assignable to 'net/minecraft/client/gui/widget/AbstractButtonWidget'
  Current Frame:
    bci: @59
    flags: { }
    locals: { 'de/d4n1el89/chunkinfo/GuiConfig', integer, integer, integer, 'de/d4n1el89/modutils/gui/GuiCheckBox' }
    stack: { 'de/d4n1el89/chunkinfo/GuiConfig', 'de/d4n1el89/modutils/gui/GuiCheckBox' }
  Bytecode:
    0x0000000: .......

 

 

To fix the error I found a trivial solution, but its blowing up my code...

Spoiler

CheckboxWidget showChunk = new CheckboxWidget(leftColumn, posY, 50, 20, I18n.translate("settings.chunk"),
				cfg.getShowChunk().isChecked()) {
	@Override
	public void onPress() {
		super.onPress();
		cfg.getShowChunk().setChecked(super.isChecked());
		cfg.save();
	}
};
addButton(showChunk);

 

Hence I want a better solution or fix the error above. Any ideas?

 

 

Edited by badner

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.