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

[1.7.2] GUI doesn't work in multiplayer


laserflip
 Share

Recommended Posts

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.