Jump to content

[1.7.10] [Solved] Cannot be cast to net.minecraft.inventory.Container?


Recommended Posts

Posted

First of all, I have 12 GUI's that work perfectly fine.

I made a new GUI that's just a copy of one of the ones that work and added lots of stuff to it.

However, even though its structure is basically the same and it's registered the same way, it gives the error in the title when trying to open it from an item.

I can't figure out for the life of me what the problem is.

 

GUI that crashes:

 

  Reveal hidden contents

 

 

GUI that works fine:

 

  Reveal hidden contents

 

 

Container:

 

  Reveal hidden contents

 

 

ServerProxy (GuiHandler):

 

  Reveal hidden contents

 

Posted
  On 4/29/2015 at 9:37 PM, Ms_Raven said:

Well then how is that that all the others work?

Your if-chain (why no switch?) is falling back to this line:

return new FCGuiContainer(player);

, which means not of your if-statements are true, so the ID must be incorrect. Show where you open your gui.

  Quote

Actually I am stupid. Reading the title helps.

 

Your getServerGuiElement method must always return a Container. This error means you returned something else.

Which always makes me wondering: why does the
getServerGuiElement

allows you to return basically anything (a

Object

), and not an instance of

Container

by just changing the return type to

Container

(same goes for

getClientGuiElement

)?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

But that still doesn't explain why this is the only one that does not work when it's the same as all the others...

 

This is how I'm opening the gui:

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
	if (!player.capabilities.isCreativeMode)
	{
		--stack.stackSize;
	}
	if (!world.isRemote)
	{
		int i = (int)player.posX;
		int j = (int)player.posY;
		int k = (int)player.posZ;
		player.openGui(Main.instance, Main.GuiTravellerOver, world, i, j, k);
	}
	return stack;
}

 

And these are the id's in Main, which are all correct...

	public static int FGuideHome= 0;
	public static int FGuidePage1 = 1;
	public static int FGuidePage2 = 2;
	public static int FGuidePage3 = 3;
	public static int FGuidePage4 = 4;
	public static int FGuidePage5 = 5;
	public static int FGuidePage6 = 6;
	public static int FGuidePage7 = 7;
	public static int FGuidePage8 = 8;
	public static int FGuidePage9 = 9;
	//public static int SanityBar = 10;
	//public static int FuelBar = 11;
	public static int GuiBackpack = 12;
	public static int GuiTravellerOver = 13;
	//public static int GuiTravellerOther = 14;
	//public static int GuiTravellerNether = 15;

Posted

STILL doesn't explain why that works and all the others don't.....

 

This is the crash:

  Reveal hidden contents

 

Posted
  On 4/29/2015 at 10:06 PM, Ms_Raven said:

STILL doesn't explain why that works and all the others don't.....

 

This is the crash:

  Reveal hidden contents

 

The other work because you actually return the proper thing in the proper method.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

I am kinda lost, why are youu returning FCGuiContainer in both client and server? What's up with those namings anyway?

 

In both server and client you are using FCGuidePage"X" which extends GuiContainer which is NOT Container and is actually only for client (it's GUI).

 

As to you "explanation" - your code will probably crash at some point. :D

 

Container is for SERVER

GuiContainer is for CLIENT

 

You can make gui that is only client-side - then you return gui for client and null for server. You can't really (pointless) do other way around.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

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.