Jump to content

[1.10.2] Minecraft crashes when gui part is opened


Egietje

Recommended Posts

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?

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I had an amazing experience with The Hack Angels. I had given up hope, but they managed to recover my bitcoins from an online scammer. I was able to retrieve what I had thought was lost forever because of their knowledge and commitment. I heartily endorse the services of The Hack Angels to anyone in need of help recovering cryptocurrency. They really are authorities in their domain.  (Web: https://thehackangels.com)     Whats Ap; +1 520) - 200, 23  20 ) ,  Mail Box; support@thehackangels. com
    • I got my model to render from the models renderToBuffer method. But still not quite what I want. I want to render the model from my renderer's render method. I feel that having access to the renderer and it's methods will open some doors for me later down the line. //EntityRendererProvider.Context pContext = ; I want this //ToaPlayerRenderer render = new ToaPlayerRenderer(pContext, false); // if I can get the above line to work, having the methods from the renderer class would be incredibly helpful down the line RenderType rendertype = model.renderType(p.getSkinTextureLocation()); // this should be something like render.getTextureLocation() VertexConsumer vertexconsumer = buffer.getBuffer(rendertype); model.renderToBuffer(stack, vertexconsumer, paLights, 1, 1, 1, 1, 1); // I don't want the render to happen here since it doesn't use the renderer //model.render(p, 1f, pTicks, stack, buffer, paLights); I want to render the model using this It is certainly getting closer though. Probably. I am still worried that even if pContext is initialized this new instance of the renderer class will still hit me with the classic and all too familiar "can't use static method in non-static context"
    • Hello, I am learning how to create Multipart Entities and I tried creating a PartEntity based on the EnderDragonPart code. However, when I tested summoning the entity in the game, the PartEntity appeared at position x 0, y 0, z 0 within the game. I tried to make it follow the main entity, and after testing again, the part entity followed the main entity but seemed to teleport back to x 0, y 0, z 0 every tick (I'm just guessing). I don't know how to fix this can someone help me? My github https://github.com/SteveKK666/Forge-NewWorld-1.20.1/tree/master/src/main/java/net/kk/newworldmod/entity/custom Illustration  https://drive.google.com/file/d/157SPvyQCE8GcsRXyQQkD4Dyhalz6LjBn/view?usp=drive_link Sorry for my English; I’m not very good at it. 
    • its still crashing with the same message
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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