Jump to content

Recommended Posts

Posted

I have this code, which is suppose to open a GUI if the player has -1 as a race.

package net.rpg.handler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.rpg.RPG;
import net.rpg.helper.DataHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class WorldEventHandler {
@SubscribeEvent
public void EntityJoinWorldEvent(EntityJoinWorldEvent event) {
	if(!event.world.isRemote && event.entity instanceof EntityPlayer) {
		EntityPlayer p = (EntityPlayer) event.entity;
		DataHelper.load(event.world);
		if(DataHelper.getRace(p.getDisplayName()) == -1) {
			p.openGui(RPG.instance, 1, p.worldObj, 0, 0, 0);
		}
	}
}
}

 

The problem is, it crashes. I'm guessing it crashes because maybe the player is unready to open GUIs?

 

Crashlog:

 

---- Minecraft Crash Report ----
// Ouch. That hurt 

Time: 1/28/14 11:10 PM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:81)
at net.minecraft.network.NetworkManager.processReadPackets(NetworkManager.java:200)
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:81)
at net.minecraft.network.NetworkManager.processReadPackets(NetworkManager.java:200)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@60ad4fe0
Stacktrace:
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_17, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 863061448 bytes (823 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 401 (22456 bytes; 0 MB) allocated, 364 (20384 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.01-pre FML v7.2.109.1019 Minecraft Forge 10.12.0.1019 5 mods loaded, 5 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.109.1019} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1019.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.0.1019} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1019.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
rpg{1.0} [RPG] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
poe{Build 1} [World of Poe] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 141 (7896 bytes; 0 MB) allocated, 104 (5824 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player686'/35, l='New World', x=191.50, y=71.00, z=246.50]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

 

Is there any other way to open a GUI when a player first joins?

Kain

Posted

Are you sure the crash is caused by trying to open the gui and not by anything going on in your DataHelper class? Try putting println's between each of your lines and see which ones print before the game crashes; that will at least let you know if it truly is the gui that's causing the crash.

EntityPlayer p = (EntityPlayer) event.entity;
System.out.println("DataHelper pre-load");
DataHelper.load(event.world);
System.out.println("DataHelper post-load");
if(DataHelper.getRace(p.getDisplayName()) == -1) {
System.out.println("Opening race gui");
p.openGui(RPG.instance, 1, p.worldObj, 0, 0, 0);
}

Something like that.

 

If it is, you may want to use the player's position when opening the gui and see if that makes any difference:

p.openGui(RPG.instance, 1, p.worldObj, p.posX, p.posY, p.posZ);

Posted

I added prints:

 

package net.rpg.handler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.rpg.RPG;
import net.rpg.helper.DataHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class WorldEventHandler {
@SubscribeEvent
public void EntityJoinWorldEvent(EntityJoinWorldEvent event) {
	if(!event.world.isRemote && event.entity instanceof EntityPlayer) {
		EntityPlayer p = (EntityPlayer) event.entity;
		DataHelper.load(event.world);
		System.out.println("1");
		if(DataHelper.getRace(p.getDisplayName()) == -1) {
			System.out.println("2");
			p.openGui(RPG.instance, 1, p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ);
			System.out.println("3");
		}
	}
}
}

 

 

It printed all of them. Also, the position has no effect at all.

 

Here's my GuiHandler:

 

package net.rpg.handler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.rpg.container.ContainerRaceSelection;
import net.rpg.container.ContainerStats;
import net.rpg.gui.GuiRaceSelection;
import net.rpg.gui.GuiStats;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	switch(ID) {
	case (0):
		return new ContainerStats(player);
	case (1):
		return new ContainerRaceSelection(player);
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	switch(ID) {
	case (0):
		return new GuiStats(player);
	case (1):
		return new GuiRaceSelection(player);
	}
	return null;
}
}

 

 

Here's my container

 

package net.rpg.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;

public class ContainerRaceSelection extends Container {
public ContainerRaceSelection(EntityPlayer p) {
}

@Override
public boolean canInteractWith(EntityPlayer p) {
	return true;
}
}

 

 

And here's my gui

 

package net.rpg.gui;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.rpg.container.ContainerRaceSelection;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiRaceSelection extends GuiContainer {
private static final ResourceLocation texture = new ResourceLocation("rpg:textures/gui/blank.png");
private EntityPlayer p;

public GuiRaceSelection(EntityPlayer p) {
	super(new ContainerRaceSelection(p));
	this.p = p;
}

@Override
protected void func_146979_b(int p_146979_1_, int p_146979_2_) {
	String s = "Race Selection";
	this.field_146289_q.drawString(s, this.field_146999_f / 2 - this.field_146289_q.getStringWidth(s) / 2, 6, 4210752);
	s = "~~~~~~~~~~~~~~~~~~~~~~~~";
	this.field_146289_q.drawString(s, this.field_146999_f / 2 - this.field_146289_q.getStringWidth(s) / 2, 17, 4210752);
}

@Override
protected void func_146976_a(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.field_146297_k.getTextureManager().bindTexture(texture);
	int k = (this.field_146294_l - this.field_146999_f) / 2;
	int l = (this.field_146295_m - this.field_147000_g) / 2;
	this.drawTexturedModalRect(k, l, 0, 0, this.field_146999_f, this.field_147000_g);
}
}

 

Kain

Posted

Crashlog:

 

---- Minecraft Crash Report ----
// Ouch. That hurt 

Time: 1/28/14 11:10 PM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:81)
at net.minecraft.network.NetworkManager.processReadPackets(NetworkManager.java:200)
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:81)
at net.minecraft.network.NetworkManager.processReadPackets(NetworkManager.java:200)

-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@60ad4fe0
Stacktrace:
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:762)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:650)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:528)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:787)

-- System Details --
Details:
Minecraft Version: 1.7.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_17, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 863061448 bytes (823 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 401 (22456 bytes; 0 MB) allocated, 364 (20384 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.01-pre FML v7.2.109.1019 Minecraft Forge 10.12.0.1019 5 mods loaded, 5 mods active
mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.2.109.1019} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.0.1019.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.12.0.1019} [Minecraft Forge] (forgeSrc-1.7.2-10.12.0.1019.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
rpg{1.0} [RPG] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
poe{Build 1} [World of Poe] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 141 (7896 bytes; 0 MB) allocated, 104 (5824 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player686'/35, l='New World', x=191.50, y=71.00, z=246.50]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'

 

Kain

Posted

Ok, I've switched events. Now, the event is registered on the server and not the client.

@SubscribeEvent
public void EntitySpawnEvent(LivingSpawnEvent event) {
	if(event.entity instanceof EntityPlayer) {
		System.out.println("1");
		EntityPlayer player = (EntityPlayer) event.entity;
		if(!player.worldObj.isRemote) {
			System.out.println("2");
			if(DataHelper.getRace(player.getDisplayName()) == -1) {
				System.out.println("3");
				player.openGui(RPG.instance, 0, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
			}
		}
	}
}

 

For some reason, it never detects the player. There was a print behind the first if statement but it was spamming the console.

Kain

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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