Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Open GUI on new world creation


Recommended Posts

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?

Link to post
Share on other sites
@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");
}

Link to post
Share on other sites

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

Link to post
Share on other sites

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

Link to post
Share on other sites

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

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I have made a custom armor piece and have given it a texture for when you hold it. I have also made a custom armor material but I dont know how to make it so that when you where the armor you see a custom texture.
    • Probably only the main block should hold all the data, that way you don't have things spread out.
    • It hasn't been changed in a long time and should be updated.  But no, it's not overly aggressive. People don't read it. Look at all the support threads. 90% of them are "okay i have this issue", no debug.log in sight.
    • I solved it by copying the .gradle folder from another laptop where it works to run the client!
    • I am currently drawing a compass to my ingame gui as follows: private static void renderCompass(MatrixStack matrixStack, int width, int height) { TextureDrawer.drawGuiTexture(matrixStack, width / 2 - 110, 10, 0, 37, 221, 14); int rot; boolean f0 = mc.player.yRot < 0.0f; if(f0) rot = -MathHelper.floor(mc.player.yRot % 360); else rot = MathHelper.floor(mc.player.yRot % 360); boolean f1 = rot > 0 && rot < 180; boolean f2 = rot <= 270 && rot >= 90; boolean f3 = rot <= 180 && rot >= 0; AtomicInteger targetAngle = new AtomicInteger(-1); mc.player.getCapability(ISkyrimPlayerDataProvider.SKYRIM_PLAYER_DATA_CAPABILITY).ifPresent(cap -> { if(cap.getCurrentTarget() != null && cap.getCurrentTarget().isAlive()) { Vector3d playerPos = mc.player.getLookAngle(); Vector3d targetPos = cap.getCurrentTarget().position(); Vector3d norm = playerPos.subtract(targetPos); double angleDir = (Math.atan2(norm.z, norm.x) / 2 / Math.PI * 360 + 360) % 360; double angleLook = (Math.atan2(playerPos.z, playerPos.x) / 2 / Math.PI * 360 + 360) % 360; targetAngle.set((int)(angleDir - angleLook + 360) % 360); } else targetAngle.set(-1); }); int targetEntityAngle = targetAngle.get(); if(targetEntityAngle > 0 && targetEntityAngle <= 90) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle, 14, 105, 52, 6, 6); else if(targetEntityAngle > 90 && targetEntityAngle <= 180) TextureDrawer.drawGuiTexture(matrixStack, width / 2 - targetEntityAngle + 90, 14, 105, 52, 6, 6); if (rot == 0) { drawCenteredString(matrixStack, fontRenderer, "S", width / 2, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "E", (width / 2) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, "W", (width / 2) + 90, 13, 16777215); } else if (!f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 - rot) + 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 - rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "E" : "", (width / 2 - rot) - 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "W" : "", (width / 2 - rot) + 90, 13, 16777215); } else if(f0) { drawCenteredString(matrixStack, fontRenderer, f2 ? "N" : "", (width / 2 + rot) - 180, 13, 16777215); if (!f1) rot -= 360; drawCenteredString(matrixStack, fontRenderer, !f2 ? "S" : "", width / 2 + rot, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, !f3 ? "W" : "", (width / 2 + rot) + 90, 13, 16777215); drawCenteredString(matrixStack, fontRenderer, f3 ? "E" : "", (width / 2 + rot) - 90, 13, 16777215); } } What I'm trying to do is only render the entity texture (the calls including targetEntityAngle) when it is in compass view.  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.