Jump to content

[1.7.10] Issue with calling a gui w/ Item


trueBlueCrafter

Recommended Posts

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

}

 

 

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

@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?

Link to comment
Share on other sites

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

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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