Jump to content

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


Teotoo

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 4 months later...

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ho installato Forge 1.20.2, ho cliccato col tasto sinistro due volte su installer.jar, non si apre e crea solo un file .log Il file contiene: JVM info: Oracle Corporation - 1.8.0_401 - 25.401-b10 java.net.preferIPv4Stack=true Current Time: 27/02/2024 18:18:10 Host: files.minecraftforge.net [51.79.83.165] Host: maven.minecraftforge.net [51.79.83.165] Host: libraries.minecraft.net [13.107.213.45, 13.107.246.45] Host: launchermeta.mojang.com [13.107.246.45, 13.107.213.45] Host: piston-meta.mojang.com [13.107.246.45, 13.107.213.45] java.net.UnknownHostException: authserver.mojang.com     at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)     at java.net.InetAddress$2.lookupAllHostAddr(Unknown Source)     at java.net.InetAddress.getAddressesFromNameService(Unknown Source)     at java.net.InetAddress.getAllByName0(Unknown Source)     at java.net.InetAddress.getAllByName(Unknown Source)     at java.net.InetAddress.getAllByName(Unknown Source)     at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:290)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120) Exception in thread "main"  java.lang.NullPointerException     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:120)
    • Suddenly the installer stopped working, both forge and neoforge, I've tested it on almost all versions of java and it didn't solve my problem.] Here is the log that appears after trying to open the file: JVM info: Oracle Corporation - 21.0.2 - 21.0.2+13-LTS-58 java.net.preferIPv4Stack=true Current Time: 27/02/2024 13:55:14 Host: maven.neoforged.net [172.67.165.187, 104.21.89.226] Host: libraries.minecraft.net [13.107.246.33, 13.107.213.33] Host: launchermeta.mojang.com [13.107.246.33, 13.107.213.33] Host: piston-meta.mojang.com [13.107.246.33, 13.107.213.33] java.net.UnknownHostException: Este host nᅢᆪo ᅢᄅ conhecido (authserver.mojang.com)     at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)     at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:52)     at java.base/java.net.InetAddress$PlatformResolver.lookupByName(InetAddress.java:1211)     at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1828)     at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:1139)     at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1818)     at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1688)     at net.minecraftforge.installer.DownloadUtils.getIps(DownloadUtils.java:296)     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:124) Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because the return value of "net.minecraftforge.installer.DownloadUtils.getIps(String)" is null     at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:124)   If anyone knows how to solve this please tell me.
  • Topics

×
×
  • Create New...

Important Information

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