Jump to content

Open a Gui specifically for an instance of an entity - i.e managing inventories.


Recommended Posts

Posted

Hi there;

 

I can't for the life of me figure out how to open gui's for non-tile entity entities.

I'm sure I'm being rather dumb in this, but I was wondering if someone could shed some light on how to do this?

I'm calling the gui like so:

player.openGui(Teo_Main.instance, Teo_GuiInventory.ID, world, (int)player.posX, (int)player.posY, (int)player.posZ);

 

Also being unable to "locate" the entity means I can't display the gui, as the inventory of the entity obviously changes between instances of the entity, hence I need to pass in the player and entity inventory.

 

I've looked in the player classes; the player uses displayGuiWhatever, I've also tried opening the gui with ye olde modloader method:

ModLoader.openGUI(player, new GuiMLBPegasus());

I've even tried FMLClientHandler's:

FMLClientHandler.instance().displayGuiScreen(player, gui);

 

I've also checked EntityMinecart, but that's just a glorified player.displayGuiScreen method.

 

To no avail. I'm sure it's something very stupidly easy. If it was a tile entity, it would be a lot simpler :D Could someone point me in the right direction?

Thanks in advance.

Posted

What are you exactly trying to accomplish that doesn't work for you?

Calling displayGuiScreen does nothing more than just display a gui screen. What this gui screen then displays is up to its own implementation.

 

Are you having problems displaying a gui screen? Cause calling displayGuiScreen should work fine.

Any logic past that has nothing to do with displaying the gui screen and should be handled in the actual implementation of the gui.

 

So for a custom inventory screen I'd imagine you'd just want to call displayGuiScreen, but your GuiMLBPegasus() constructor probably should contain an argument for the inventory object, so it can access it and display its contents.

Posted

What's in the gui screens has been fine since I first added them in 1.2.something. My issue is that the screens themselves aren't showing, for some reason. I couldn't call vanilla screens either, when attempting to do so just to check I wasn't going insane

 

EDIT: I just tried opening both GuiWinGame() and GuiInventory() (using FMLClientHandler.displayGuiScreen()) as an example of a screen which *should* open, and they didn't work either.

 

Potentially useful info: I'm using FML version 3.0.150.334. No errors were thrown when I try call a gui screen; rather, they just don't appear.

 

Edit num2:

Okay, so after hunting down the trail of displayGuiScreen to it's declaration in FMLClientHandler, it appears to be working if I call the method without FMLClientHandler - that is, (where mc == ModLoader.getMinecraftInstance();), with mc.displayGuiScreen(). I'm not sure why FMLClientHandler doesn't work for me, but for the moment, at least gui's are actually showing.

Posted

Strange. What build of Forge are you using?

I'm on FML 3.0.98.304 / Forge 4.0.0.217 and calling this works perfectly fine:

FMLClientHandler.instance().displayGuiScreen(entityPlayer, new FireCraftGuiClassChange());

Posted

I'm using Forge version 4.0.0.232, if I recall correctly. It's very weird, no? I even copy&pasted your code (replacing the gui class), and it didn't work - so it's definitely not my typing ><

 

Interestingly again, it was working, but now I get errors in vanilla minecraft classes when opening the guis. (not even a mention of any of my classes, or FML/Forge classes).

 

I think I'll use Forge Version 217, and see if that fixes things.

 

Edit: Just tried it with forge 217, it didn't make any difference to FMLClientHandler. It's rather frustrating that I'm getting given no error messages.

 

I'm gonna redownload everything, and see if that helps.

Posted

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

 

The issue is that (at least it would appear that) you can't call a gui with parameters to acquire the instance of a specific entity - I'm perfectly aware that that's how it should be done, but how do you grab the instance of the entity the player is interacting with? If it was a tile entity, yes, you could simply do

TileEntity te = world.getBlockTileEntity(x, y, z);

and then check it's an instance of your own tile entity, and that's fine, but from what i've seen, there's no way to get a specific instance of a mob entity. I suppose you could use world.getEntitiesWithinAABB, and check for instances of the mob, but that would mess up if there was more than one instance of the mob.

 

Which is why I looked into EntityMinecart, but that uses EntityPlayer's displaychest method.

Posted

Whats stopping you from using the EntityID?

 

As the ID parameter in player.openGui()? If yes, it sounds like I wouldn't be able to have multiple gui's...Unless I was to make a meta-gui, I suppose.

 

Or am I being incredibly stupid?

Posted

You do realize

That x/y/z

Are nothing more then ints

...

that are sent to your client function...

They can be whatever the fuck you want.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

You do realize

That x/y/z

Are nothing more then ints

...

that are sent to your client function...

They can be whatever the fuck you want.

 

[me=Teotoo]facepalms[/me]

Wow. How'd I miss that. Thanks!

  • 4 months later...
Posted

Ooooh ok, I didn't undertand the reply, i got it, you can give the entityId by passing it as one of the int parameters!

 

Sorry for disturbing and thanks for reply.

If yo want to say thanks, push the button!

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.