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

So, I have made a block with a gui but it crashes when it reaches this:

case 6 :
		buttonList.removeAll(buttonList);
		buttonList.add(cookies = new GuiSlider(8, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik wil ", " koekjes(" + cookies.getValueInt() + ")", 1, 10, 5, true, true));
		buttonList.add(new GuiButtonExt(10, width / 2 - 100, height / 4 + 72 + -16, 200, 20, "Ok"));
		break;

and I know that is because of this:

" koekjes(" + cookies.getValueInt() + ")"

but how should I convert an int into a string part?

  • Author

So this:

int i = cookies.getValueInt();
		buttonList.add(cookies = new GuiSlider(8, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik wil ", " koekjes(" + String.valueOf(i) + ")", 1, 10, 5, true, true));

or this:

buttonList.add(cookies = new GuiSlider(8, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik wil ", " koekjes(" + String.valueOf(cookies.getValueInt()) + ")", 1, 10, 5, true, true));

  • Author

Well, it's a nullpointer exception:

[20:04:03] [Client thread/FATAL]: Reported exception thrown!
net.minecraft.util.ReportedException: Updating screen events
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1810) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1118) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:406) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.lang.NullPointerException
at com.Egietje.degeweldigemod.gui.CheeseCookieGui.actionPerformed(CheeseCookieGui.java:53) ~[CheeseCookieGui.class:?]
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:500) ~[GuiScreen.class:?]
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:615) ~[GuiScreen.class:?]
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:581) ~[GuiScreen.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1797) ~[Minecraft.class:?]
... 15 more

You are creating a variable named cookies then when you are creating it you try to reference it.

cookies.getValueInt()

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

Well, now I just do this:

drawCenteredString(fontRendererObj, String.valueOf(cookies.getValueInt()) + "koekjes, dat is " + String.valueOf(cookies.getValueInt() * 3) + " XP levels" , width / 2 - 100, height / 4 + 102 + -16, 0x8B4513);

  • Author

I now do

			buttonList.add(cookies = new GuiSlider(8, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik wil ", " koekjes", 1, 10, 5, true, true));
		drawCenteredString(fontRendererObj, String.valueOf(cookies.getValueInt()) + "koekjes, dat is " + String.valueOf(cookies.getValueInt() * 3) + " XP levels" , width / 2 - 100, height / 4 + 102 + -16, 0xFFFFFF);

Because you only call it once all rendering code needs to be in the rendering methods aka draw...

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author

So, now I have this:

public class CheeseCookieGui extends GuiScreen {

public GuiSlider cookies = new GuiSlider(0, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik wil ", " koekjes", 1, 10, 5, true, true);
public boolean slider = false;

@Override
public void initGui() {
	slider = false;
	buttonList.add(new GuiButtonExt(1, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Goed geopend!"));
}

@Override
protected void actionPerformed(GuiButton button) throws IOException {
	switch(button.id) {
	case 1 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(2, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Stop!"));
		break;
	case 2 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(3, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Ik zei STOP!"));
		break;
	case 3 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(4, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Nooit luisteren he"));
		break;
	case 4 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(5, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Wil je een koekje?"));
		buttonList.add(new GuiButtonExt(6, width / 2 - 100, height / 4 + 72 + -16, 75, 20, "Ja"));
		buttonList.add(new GuiButtonExt(7, width / 2 + 25, height / 4 + 72 + -16, 75, 20, "Nee"));
		break;
	case 5 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(8, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Mahn, niet op klikken"));
		buttonList.add(new GuiButtonExt(9, width / 2 - 100, height / 4 + 72 + -16, 200, 20, "Terug naar koekjes"));
		break;
	case 6 :
		buttonList.removeAll(buttonList);
		buttonList.add(cookies);
		buttonList.add(new GuiButtonExt(10, width / 2 - 100, height / 4 + 72 + -16, 200, 20, "Ok"));
		slider = true;
		break;
	case 7 :
		buttonList.removeAll(buttonList);
		this.mc.displayGuiScreen((GuiScreen)null);
		break;
	case 8 :
		break;
	case 9 :
		buttonList.removeAll(buttonList);
		buttonList.add(new GuiButtonExt(5, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Wil je een koekje?"));
		buttonList.add(new GuiButtonExt(6, width / 2 - 100, height / 4 + 72 + -16, 75, 20, "Ja"));
		buttonList.add(new GuiButtonExt(7, width / 2 + 25, height / 4 + 72 + -16, 75, 20, "Nee"));
		break;
	case 10 :
		buttonList.removeAll(buttonList);
		slider = false;
		if(!Minecraft.getMinecraft().thePlayer.isCreative()) {
			if(Minecraft.getMinecraft().thePlayer.experienceLevel > 3 * cookies.getValueInt()) {
				Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(new ItemStack(Items.COOKIE, cookies.getValueInt()));
				Minecraft.getMinecraft().thePlayer.removeExperienceLevel(3 * cookies.getValueInt());
				this.mc.displayGuiScreen((GuiScreen)null);
			} else {
				buttonList.add(new GuiButtonExt(7, width / 2 - 100, height / 4 + 42 + -16, 200, 20, "Je hebt niet genoeg xp"));
			}
		} else {
			Minecraft.getMinecraft().thePlayer.inventory.addItemStackToInventory(new ItemStack(Items.COOKIE, cookies.getValueInt()));
			this.mc.displayGuiScreen((GuiScreen)null);
		}
		break;
	}
}

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	if(slider) {
		drawCenteredString(fontRendererObj, "Je krijgt " + String.valueOf(cookies.getValueInt()) + " koekjes, dat is " + String.valueOf(cookies.getValueInt() * 3) + " XP levels" , width / 2 - 100, height / 4 + 102 + -16, 0xFFFFFF);
	}
	super.drawScreen(mouseX, mouseY, partialTicks);
}
}

But the slider and text appear in weird places

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.