laserflip Posted April 23, 2016 Share Posted April 23, 2016 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 Quote Link to comment Share on other sites More sharing options...
Draco18s Posted April 23, 2016 Share Posted April 23, 2016 Hahahaha 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); } Quote 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 More sharing options...
Choonster Posted April 23, 2016 Share Posted April 23, 2016 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 . Quote 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 More sharing options...
laserflip Posted April 24, 2016 Author Share Posted April 24, 2016 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); } Quote Link to comment Share on other sites More sharing options...
gegy1000 Posted April 24, 2016 Share Posted April 24, 2016 Change your '!world.isRemote' to 'world.isRemote'. World#isRemote is true on the client-side and false on the server-side. Quote Link to comment Share on other sites More sharing options...
laserflip Posted April 24, 2016 Author Share Posted April 24, 2016 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.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.