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:

 

  Reveal hidden contents

 

 

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:

 

  Reveal hidden contents

 

 

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

 

Here's my GuiHandler:

 

  Reveal hidden contents

 

 

Here's my container

 

  Reveal hidden contents

 

 

And here's my gui

 

  Reveal hidden contents

 

Kain

Posted
  On 1/29/2014 at 4:14 AM, TLHPoE said:

Crashlog:

 

  Reveal hidden contents

 

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.

Announcements



×
×
  • Create New...

Important Information

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