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

Hey guys!

 

The title says it all,

 

I am trying to create a GUI where the user will choose his/her race and that choice will be embedded into their player data.

 

I've done the GUI etc... Just trying to figure out how to do what I want on new world creation, any idea?

@SubscribeEvent
public void playerLoggedIn(PlayerLoggedInEvent event){
    if(event.player.getEntityData().hasKey("checkWorld")){
        return;
    }
    event.player.getEntityData().setBoolean("checkWorld", true);
    System.out.println("Open your GUI");
}

  • Author

Do I have to create any external files for the entity data stuff? Or will that code work on its own?

  • Author

It is printing the message, but it is not opening my GUI :(

 

Here is what I'm doing:

 

Minecraft mc = Minecraft.getMinecraft();
mc.displayGuiScreen(new GuiSelectHouse());

  • Author

Using player.openGui(params);... now getting this error:

 

java.lang.ClassCastException: io.ryanshah.got.gui.GuiSelectHouse cannot be cast to net.minecraft.inventory.Container
at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:241) ~[NetworkRegistry.class:?]
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75) ~[FMLNetworkHandler.class:?]
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2510) ~[EntityPlayer.class:?]
at io.ryanshah.got.event.GOTEventHandler.playerLoggedIn(GOTEventHandler.java:16) ~[GOTEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler_4_GOTEventHandler_playerLoggedIn_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?]
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:?]
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:?]
at cpw.mods.fml.common.FMLCommonHandler.firePlayerLoggedIn(FMLCommonHandler.java:498) ~[FMLCommonHandler.class:?]
at net.minecraft.server.management.ServerConfigurationManager.initializeConnectionToPlayer(ServerConfigurationManager.java:156) ~[serverConfigurationManager.class:?]
at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:172) ~[NetworkDispatcher.class:?]
at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:436) ~[NetworkDispatcher.class:?]
at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:17) ~[HandshakeCompletionHandler.class:?]
at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) ~[HandshakeCompletionHandler.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:80) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) [NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:716) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]

 

Any idea? Everything is registered..

 

here is my EventHandler:

 

package io.ryanshah.got.event;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent;

public class GOTEventHandler
{
@SubscribeEvent
public void playerLoggedIn(PlayerLoggedInEvent event){
    if(event.player.getEntityData().hasKey("checkWorld")){
        return;
    }
    event.player.getEntityData().setBoolean("checkWorld", true);
    
    event.player.openGui(CoreMod.instance, 0, event.player.worldObj, (int)event.player.posX, (int)event.player.posY, (int)event.player.posZ);
    
    System.out.println(event.player.getEntityData().getBoolean("checkWorld"));
    System.out.println("Open your GUI");
}
}

  • Author

package io.ryanshah.got.gui;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
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) {
	/*if(ID == 0) {
		return new GuiSelectHouse();
	} else {
		return null;
	}*/
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0) {
		return new GuiSelectHouse();
	} else {
		return null;
	}
}
}

 

And here is my GUI File if you need it:

 

package io.ryanshah.got.gui;

import java.util.ArrayList;

import net.minecraft.client.gui.GuiScreen;

public class GuiSelectHouse extends GuiScreen
{
    public GuiSelectHouse() {
    	
    }
    
    public void updateScreen() {
    	super.updateScreen();
    }
    
    public void drawScreen(int par1, int par2, float par3){
    	drawDefaultBackground();
    	
    	drawCenteredString(this.fontRendererObj, "Select a house to join for the rest of time!", this.width / 2, 40, 16777215);
    	
    	super.drawScreen(par1, par2, par3);
    }
}

  • Author

@diesieben07

 

Even when creating a container and stuff, It still doesn't show... so thats not the problem :/

  • Author

Here is how I instantiate my gui in my GuiHandler:

 

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	if(ID == 0) {
		return new GuiSelectHouse(new ContainerSelectHouse());
	}
	return null;
}

 

Here is my GuiSelectHouse:

 

package io.ryanshah.got.gui;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;

public class GuiSelectHouse extends GuiContainer
{
    public GuiSelectHouse(Container par1Container) {
	super(par1Container);
}
    
public void updateScreen() {
    	super.updateScreen();
    }
    
    public void drawScreen(int par1, int par2, float par3){
    	//drawDefaultBackground();
    	
    	drawCenteredString(this.fontRendererObj, "Select a house to join for the rest of time!", this.width / 2, 40, 16777215);
    	
    	super.drawScreen(par1, par2, par3);
    }
    
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
	drawDefaultBackground();
}
}

 

and here is my ContainerSelectHouse:

 

package io.ryanshah.got.gui;

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

public class ContainerSelectHouse extends Container
{
@Override
public boolean canInteractWith(EntityPlayer var1) {
	return true;
}	
}

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.