Well hello. I have been having issues with my gui button. I want it to do something to the player when clicked. Everytime i try it it crashes. here is my Gui class:[EDIT]Can the Gui actually change variables?? Do I have to use the Container?
package theRobots.interfaces;import org.lwjgl.opengl.GL11;import theRobots.TileEntity.TileEntityAltar;import theRobots.TileEntity.TileEntityHealing;import theRobots.containers.HealingContainer;import net.minecraft.client.Minecraft;import net.minecraft.client.gui.GuiButton;import net.minecraft.client.gui.inventory.GuiContainer;import net.minecraft.entity.player.EntityPlayer;import net.minecraft.entity.player.InventoryPlayer;import net.minecraft.inventory.Container;import net.minecraft.util.ResourceLocation;import net.minecraft.util.StatCollector;public class GuiHealing extends GuiContainer{EntityPlayer player;GuiButton button;private static final ResourceLocation textures = new ResourceLocation("random", "textures/gui/altarGui.png");public GuiHealing(InventoryPlayer inventory, TileEntityHealing altar) {super(new HealingContainer(inventory, altar));xSize = 175;ySize = 165;}@Overrideprotected void drawGuiContainerForegroundLayer(int par1, int par2) {fontRenderer.drawString(StatCollector.translateToLocal("What do you want, Mortal?"), 20, 4, 0x404040);}@Overrideprotected void drawGuiContainerBackgroundLayer(float f, int i, int j) {GL11.glColor4f(1, 1, 1, 1);Minecraft.getMinecraft().getTextureManager().bindTexture(textures);this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);}@Overridepublic void initGui() {super.initGui();buttonList.clear();buttonList.add(new GuiButton(0, guiLeft + 20, guiTop + 50, 50, 20, "Heal"));}@Overrideprotected void actionPerformed(GuiButton button) {EntityPlayer player = this.player;}@Overrideprotected void mouseClicked(int x, int y, int button) {EntityPlayer player = this.player;boolean shouldHeal = false;if(button == 0){shouldHeal = true;if(shouldHeal == true){player.heal(4f);}}}@Overridepublic void updateScreen() {initGui();}}
Oh yeah i forgot. Okay I made the button's id to be 100 then when i went in game to test it, it printed its id, 100. Now when I add player.heal(4f), it crashes with this error.
java.lang.NullPointerException
at theRobots.interfaces.GuiHealing.actionPerformed(GuiHealing.java:63)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:120)
at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:482)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1566)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)
at net.minecraft.client.Minecraft.run(Minecraft.java:838)
at net.minecraft.client.main.Main.main(Main.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at theRobots.interfaces.GuiHealing.actionPerformed(GuiHealing.java:63)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:120)
at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:482)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)
// My bad.
Time: 20/03/14 4:27 PM
Description: Updating screen events
java.lang.NullPointerException
at theRobots.interfaces.GuiHealing.actionPerformed(GuiHealing.java:63)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:120)
at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:482)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:1566)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:910)
at net.minecraft.client.Minecraft.run(Minecraft.java:838)
at net.minecraft.client.main.Main.main(Main.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at theRobots.interfaces.GuiHealing.actionPerformed(GuiHealing.java:63)
at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:120)
at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:482)
at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:208)
at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:176)
-- Affected screen --
Details:
Screen name: theRobots.interfaces.GuiHealing
-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player208'/34, l='MpServer', x=-209.29, y=5.62, z=64.55]]
Chunk stats: MultiplayerChunkCache: 225
Level seed: 0
Level generator: ID 01 - flat, ver 0. Features enabled: false
Level generator options:
Level spawn location: World: (-205,4,53), Chunk: (at 3,0,5 in -13,3; contains blocks -208,0,48 to -193,255,63), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Level time: 3774 game time, 3774 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: survival (ID 0). Hardcore: false. Cheats: false
Forced entities: 5 total; [EntitySlime['Slime'/0, l='MpServer', x=-270.16, y=4.00, z=120.78], EntityClientPlayerMP['Player208'/34, l='MpServer', x=-209.29, y=5.62, z=64.55], EntitySheep['Sheep'/8, l='MpServer', x=-189.13, y=4.00, z=85.72], EntitySlime['Slime'/9, l='MpServer', x=-177.19, y=4.00, z=114.34], EntityChicken['Chicken'/31, l='MpServer', x=-152.50, y=4.00, z=-11.50]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2312)
at net.minecraft.client.Minecraft.run(Minecraft.java:856)
at net.minecraft.client.main.Main.main(Main.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:131)
at net.minecraft.launchwrapper.Launch.main(Launch.java:27)
-- System Details --
Details:
Minecraft Version: 1.6.4
Operating System: Windows 7 (x86) version 6.1
Java Version: 1.7.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
Memory: 792408720 bytes (755 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 2598 (145488 bytes; 0 MB) allocated, 2 (112 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
FML: MCP v8.11 FML v6.4.49.965 Minecraft Forge 9.11.1.965 4 mods loaded, 4 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{6.4.49.965} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{9.11.1.965} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
random{0.0.1} [Artifact Exploration] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Launched Version: 1.6
LWJGL: 2.9.0
OpenGL: Intel(R) HD Graphics 4000 GL version 4.0.0 - Build 9.17.10.2843, Intel
Is Modded: Definitely; Client brand changed to 'fml,forge'
Type: Client (map_client.txt)
Resource Pack: Default
Current Language: English (US)
Profiler Position: N/A (disabled)
Vec3 Pool Size: 195 (10920 bytes; 0 MB) allocated, 17 (952 bytes; 0 MB) used
the action preformed code looks like this:
That won't work. The player will return null unless you have it in the constructor.
Mods I work on and maintain:
TabbyChat | Mine Little Pony
My Blog