Posted May 12, 201510 yr I'm trying to allow the player to call up a gui from a book, by method of ItemRightclick, but I'm not sure what's wrong. I have all of my items in one class for their unlocalized names, so I think that's part of the problem, though I thought there should be a way to have them all call up the same gui. My class file for the gui. package guis; import lib.RefStrings; import org.lwjgl.opengl.GL11; import net.minecraft.client.gui.GuiScreen; import net.minecraft.util.ResourceLocation; public class CoreGuideGui extends GuiScreen { //Change the height to ideal length later int guiWidth = 150; int guiHeight= 150; @Override public void drawScreen(int x, int y, float ticks) { int guiX = (width - guiWidth)/2; int guiY = (height - guiHeight)/2; //Changes color, this is optional. If I can figure out how to make one gui, then change all their colors, use this. If not, remove it. GL11.glColor4f(1,1,1,1); //May be an issue here, but this is supposed to obtain the image for my gui. mc.renderEngine.bindTexture(new ResourceLocation(RefStrings.MODID, "textures/gui/testgui.png")); drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight); super.drawScreen(x, y, ticks); } } My code inside my Item class public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(!world.isRemote){ Minecraft.getMinecraft().displayGuiScreen(new CoreGuideGui()); } return onItemRightClick(item, world, player); }
May 12, 201510 yr Author Ohhhhhh, I forgot super! Thanks, I'll make those changes and see if that fixes it.
May 23, 201510 yr Author Okay, I'll admit I'm still unsure as to how to get the Minecraft class to run though the client class. Should I just insert my code into my clientproxy class, or make a new class entirely? public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(world.isRemote){ Minecraft.getMinecraft().displayGuiScreen(new CoreGuideGui()); } return super.onItemRightClick(item, world, player); } Here's what it currently looks like.
May 23, 201510 yr Author @SideOnly(Side.CLIENT) public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player){ if(world.isRemote){ Minecraft.getMinecraft().displayGuiScreen(new CoreGuideGui()); } return null; Alright, I added the @SideOnly, but I'm still not getting the desired results. Is there a mistake elsewhere that I need to fix?
May 24, 201510 yr You can't use direct call to Minecraft class, because it has annotation @SideOnly(Side.CLIENT), meaning that Minecraft class is not packed during compilation with dedicated server, so if you even try to reference it, even if you don't use it on server (with world.isRemote condition), dedicated server will crash with java.lang.classnotfoundexception, because that class don't even exists. So, you have to call it through SidedProxy. Something like this: public class CommonProxy { public void displayGui(short guiId) { //NO-OP } } public class ClientProxy extends CommonProxy { @Override public void displayGui(short guiId) { switch(guiId) { case 0: Minecraft.getMinecraft().displayGuiScreen(new GuiTest()); break; } } } Edit: Fixed the code, thanks to diesieben07 for pointing to my mistake
May 24, 201510 yr Yeah, right. GuiScreen is Client-Sided too. But that could be solved it by using enum or numerical IDs.
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.