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, I made a simple GUI on an " on item right click ", it works perfectly in singleplayer but in multiplayer, nothing appears.. the GUI doesn't work but there's no error, crash or anything.

 

Here is my item :

 

package laserflip33.ordreduphenix.common;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class Livre1 extends Item
{
@SideOnly(Side.CLIENT)
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if(!world.isRemote)
	{
		Minecraft.getMinecraft().displayGuiScreen(new GuiLivre1());
	 }
    return super.onItemRightClick(stack, world, player);
}

}

 

And here is my GUI :

package laserflip33.ordreduphenix.common;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import scala.swing.SingleRefCollection.Ref;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.util.ResourceLocation;

public class GuiLivre1 extends GuiScreen
{
int guiWidth= 256;
int guiHeight= 256;

	@Override                                                               
		public void drawScreen(int x, int y, float ticks )
		{
			int guix =(width - guiWidth) /2 ;
			int guiy =(height - guiHeight) /2;

			mc.renderEngine.bindTexture(new ResourceLocation(ModPhenix.MODID,"textures/gui/guiLivre.png"));

			drawTexturedModalRect(guix, guiy, 0, 0, guiWidth, guiHeight);

			fontRendererObj.drawString("\u00a70" + "\u00a7o" + "Lever le voile du futur", guix + 17, guiy + 55, 0x404040 );

		super.drawScreen(x, y, ticks);
	}

	@Override
	public boolean doesGuiPauseGame()
	{
		return false;
	}
}

 

Thank you very much for your help :)

Hahahaha xD

This is priceless.

 

	@SideOnly(Side.CLIENT)  //make sure this method does not exist on a dedicated server
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if(!world.isRemote) //if we're on the server thread...
	{
		//...then access the client side class!
		Minecraft.getMinecraft().displayGuiScreen(new GuiLivre1());
	}
    return super.onItemRightClick(stack, world, player);
}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Do not use

@SideOnly

on methods unless the super method is a vanilla method already marked as

@SideOnly

. This post explains why in more detail.

 

World#isRemote

is

true

on the client and

false

on the server. You're currently trying to display the GUI on the server, which won't work.

 

Side note: If your GUI has an inventory, it must be opened on the server through

EntityPlayer#openGUI

/

IGuiHandler

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Do not use

@SideOnly

on methods unless the super method is a vanilla method already marked as

@SideOnly

. This post explains why in more detail.

 

World#isRemote

is

true

on the client and

false

on the server. You're currently trying to display the GUI on the server, which won't work.

 

Side note: If your GUI has an inventory, it must be opened on the server through

EntityPlayer#openGUI

/

IGuiHandler

.

 

Thank you very much for the explanation and the link, so interesting. So right now I understand that I tried to display the GUI on the server instead of the client, but I don't know how to display on Client Side.

 

I of course tried many things but it still doesn't work..

 

It should works like that, but it doesn't :

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
	if(!world.isRemote)
	{
		Minecraft.getMinecraft().displayGuiScreen(new GuiLivre1());
	 }
    return super.onItemRightClick(stack, world, player);
}

Change your '!world.isRemote' to 'world.isRemote'. World#isRemote is true on the client-side and false on the server-side.

  • Author

You will also have to wrap the call to

displayGuiScreen

through your client proxy, otherwise you will crash dedicated servers.

 

Thank you, so now I've that :

 

Item who opens GUI :

public class Livre1 extends Item
{
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) 
{
	if(world.isRemote)
	{
		ModPhenix.proxy.openMyGui();
	}
    return super.onItemRightClick(stack, world, player);
}

}

 

ClientProxy :

public class ClientProxy extends CommonProxy 
{
public static int tesrRenderId;

@Override
public void registerRender()
{
MinecraftForge.EVENT_BUS.register(new TickClientHandler());
}

@Override
public void openMyGui()
{
     Minecraft.getMinecraft().displayGuiScreen(new GuiLivre1());
}
}

 

CommonProxy :

public class CommonProxy 
{
public void registerRender()
{

}

public void openMyGui()
{

}
}

 

GUI :

public class GuiLivre1 extends GuiScreen
{
int guiWidth= 256;
int guiHeight= 256;

	@Override                                                               
		public void drawScreen(int x, int y, float ticks )
		{
			int guix =(width - guiWidth) /2 ;
			int guiy =(height - guiHeight) /2;

			mc.renderEngine.bindTexture(new ResourceLocation(ModPhenix.MODID,"textures/gui/guiLivre.png"));

			drawTexturedModalRect(guix, guiy, 0, 0, guiWidth, guiHeight);

			fontRendererObj.drawString("\u00a70" + "\u00a7o" + "Lever le voile du futur", guix + 17, guiy + 55, 0x404040 );

		super.drawScreen(x, y, ticks);
	}

	@Override
	public boolean doesGuiPauseGame()
	{
		return false;
	}
}

 

It should be correct, I did what you tell me but it doesn't work.. :/

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.