Jump to content

[1.11] Adding world options


Kokkie

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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