Jump to content

Recommended Posts

Posted (edited)

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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