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

I want to add more world options when making a world, for example the start chest option etc.

Should I use an event or something to look when the GUI of world-options is opened and then add another button?

Also, how can I save what you provided (for now I only want a boolean) and use it in the world?

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

  • Author

I want to add an option to the world that, if set to true, gives you items when you first spawn, so a little bit like the spawn chest

Also, I can't access the buttonList

Forgot to look in the event for it

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

  • Author

So, I've now got it all working, but when I resize the screen while the gui is up, my button disappears and only reappears when I 'reload' the screen

Anyone knows how to fix this?

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

  • Author

Client handler

	@SubscribeEvent
public void onGuiPreInit(GuiScreenEvent.InitGuiEvent.Pre event) {
	GuiScreen gui = event.getGui();
	if (gui instanceof GuiCreateWorld) {
		List<GuiButton> buttonList = event.getButtonList();
		GuiButton giveItem;
		giveItem = addButton(new GuiButton(11, gui.width / 2 + 5, 187, 150, 20, "Give Items: OFF"), buttonList);
		giveItem.visible = false;
	}
}

protected <T extends GuiButton> T addButton(GuiButton button, List<GuiButton> list) {
	list.add(button);
	return (T) button;
}

@SubscribeEvent
public void onGuiPreInteraction(GuiScreenEvent.ActionPerformedEvent.Pre event) {
	GuiScreen gu = event.getGui();
	if (gu instanceof GuiCreateWorld) {
		GuiCreateWorld gui = (GuiCreateWorld) gu;
		GuiButton button = event.getButton();
		if (button.id == 2) {
			for (int i = 0; i < event.getButtonList().size(); i++) {
				GuiButton button1 = event.getButtonList().get(i);
				if (button1.id == 11) {
					if ("survival".equals(CheeseUtils.getField(GuiCreateWorld.class, gui, "gameMode"))) {
						ShouldGiveItems.worldCreateGive = false;
						button1.enabled = false;
					} else if ("hardcore".equals(CheeseUtils.getField(GuiCreateWorld.class, gui, "gameMode"))) {
						ShouldGiveItems.worldCreateGive = false;
						button1.enabled = true;

					} else {
						ShouldGiveItems.worldCreateGive = false;
						button1.enabled = true;
					}
				}
			}
		} else if (button.id == 3) {
			for (int i = 0; i < event.getButtonList().size(); i++) {
				GuiButton button1 = event.getButtonList().get(i);
				if (button1.id == 11) {
					button1.visible = !(Boolean) CheeseUtils.getField(GuiCreateWorld.class, gui,
							"inMoreWorldOptionsDisplay");
				} else if (button1.id == 3) {
					if (!(Boolean) CheeseUtils.getField(GuiCreateWorld.class, gui, "inMoreWorldOptionsDisplay")) {
						button1.xPosition = gui.width / 2 - 155;
					} else {
						button1.xPosition = gui.width / 2 - 75;
					}
				}
			}
		} else if (button.id == 11) {
			if (!ShouldGiveItems.worldCreateGive) {
				button.displayString = "Give Items: ON";
				ShouldGiveItems.worldCreateGive = true;
			} else {
				button.displayString = "Give Items: OFF";
				ShouldGiveItems.worldCreateGive = false;
			}
		}
	}
}

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

  • Author

It is yes..? Now the whole button is gone?!?! WHAT?!?! Okay, now the whole button is gone, and the Done button still moves place, like in the code and the code is not being ran (the init gui event, checked by printing in console), code is the same as before..?

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

You should use InitGuiEvent.Post instead of InitGuiEvent.Pre, because the button list is cleared after the Pre event.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Guest
This topic is now closed to further replies.

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.