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

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

 

 

  • 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

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...

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.