Posted December 17, 20177 yr Hello, I would like to open a GuiScreen when the player login but currently the Gui doesn't open when the player connects EventHandler : (register with FMLCommonHandler.instance().bus().register(eventHandler);) Spoiler @SubscribeEvent public void JoinWorld(EntityJoinWorldEvent event) { if (event.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.getEntity(); if (player.world.isRemote) { player.openGui(IdPlayer.instance, ModGuiHandler.LANGUAGE, player.world, (int) player.posX, (int) player.posY, (int) player.posZ); } } } GuiHandler : Spoiler public class ModGuiHandler implements IGuiHandler { public static final int LANGUAGE = 0; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case LANGUAGE: return new GuiLanguage(); default: return null; } } } Gui : Spoiler public class GuiLanguage extends GuiScreen { private static final ResourceLocation BG_TEXTURE = new ResourceLocation(Reference.MODID, "textures/gui/idbackgroundlanguage.png"); protected final int xSize = 256; protected final int ySize = 256; private int guiLeft; private int guiTop; // button private final int fr = 0; private final int en = 1; private final int valid = 2; // variable private String validString; @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { GlStateManager.color(1, 1, 1, 1); mc.getTextureManager().bindTexture(BG_TEXTURE); int x = (width - this.xSize) / 2; int y = (height - this.ySize) / 2; drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); super.drawScreen(mouseX, mouseY, partialTicks); } @Override public boolean doesGuiPauseGame() { return false; } @Override public void initGui() { this.guiLeft = (this.width - this.xSize) / 2; this.guiTop = (this.height - this.ySize) / 2; this.buttonList.clear(); this.buttonList.add(new GuiButton(this.fr, this.guiLeft + 74, this.guiTop + 118, 50, 15, "Francais")); this.buttonList.add(new GuiButton(this.en, this.guiLeft + 131, this.guiTop + 118, 50, 15, "English")); super.initGui(); } @Override protected void actionPerformed(GuiButton button) throws IOException { switch (button.id) { case fr: validString = "valider"; break; case en: validString = "valid"; break; default: break; } this.buttonList.clear(); this.buttonList.add(new GuiButton(this.fr, this.guiLeft + 74, this.guiTop + 118, 50, 15, "Francais")); this.buttonList.add(new GuiButton(this.en, this.guiLeft + 131, this.guiTop + 118, 50, 15, "English")); this.buttonList.add(new GuiButton(this.valid, this.guiLeft + 103, this.guiTop + 148, 50, 15, validString)); } }
December 17, 20177 yr Author I used IGuiHandler because I read EntityJoinWorldEvent it's a server event and GuiScreen it's only client (so it's for this reason I used player.openGui) This Gui show a menu for choose language. I would like to open this GUI when player join the server for the first time
December 17, 20177 yr Author Ty for information, but do you have an exemple to use packet (I never used this before)
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.