Jump to content

[1.14.4] GUI Without Container?


JayZX535

Recommended Posts

Hey all,

 

I'm working on implementing a lore book to my mod.  It works similarly to vanilla books, except the text is all predefined.  As such, I'm trying to figure out how to create and access a GUI for it.  My question is, I'm not sure if I need to use a container for it, or if it even needs serverside access at all.  I'm planning on using info that's drawn from the mod's lang file and a player capability (which I've already coded to sync to the client), and it shouldn't need to send any info back to the server (nothing the player can edit except the currently viewed page, which I can easily handle via the client) so if I'm understanding everything right, it doesn't actually need to pull any data from the server.  As such, I'm not sure if I need to use a container at all, or if I should just make it a screen.  However, I want to ensure that I'm doing this properly.

 

I see that ClientPlayerEntity uses the following method... (which is called from the book items)

public void openBook(ItemStack stack, Hand hand) {
      Item item = stack.getItem();
      if (item == Items.WRITABLE_BOOK) {
         this.mc.displayGuiScreen(new EditBookScreen(this, stack, hand));
      }
   }

 

So I'm guessing I may need to do something like that.  Is this.mc.displayGUIScreen() the right method to use for modded GUIs?  Do I need to register the GUI anywhere, or if it's not linked to a container can I just open it like this?  I assume I need a client safe method to call to open this, so I'm guessing I should run that method through my proxy for safety?  Is there anything I should be aware of when it comes to using a client-only screen, and is there any reason I might still want to opt to use a container in this case?  If the method is clientside only, is there anything special I need to do to block movement (or anything else noteworthy)?

 

Thanks, and have a great day.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

If you just want a client-side GUI all you need to do is extend the Screen class and call displayGuiScreen. Just make sure to use DistExecutor (and possibly World#isRemote) to run it on the client only.

Thanks for the confirmation!  Works like a charm on both server and client.  Ended up using both checks just to be extra certain and it all seems just fine.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

Nothing to do with "extra certain". They do different things, you should learn what these things do.

I'm aware they do different things and I'm aware of what they do.  I'm being "extra certain" by covering both possibilities.

Link to comment
Share on other sites

DistExecutor is used for physical side, whether you are using a minecraft client or dedicated server (in this case, this is the relevant information as only physical clients do rendering)

 

isRemote references the logical side, where true is the logical client. Logical client just means if it's not running the gameserver instance on that thread, so isRemote could return false on clients on the server thread. Also, isRemote checks do not properly avoid classloading, unlike DistExecutor which avoids them by utilizing the double supplier trick.

Link to comment
Share on other sites

Just now, diesieben07 said:

Just as a note, it doesn't actually do this properly.

Does it not? I've used the double supplier trick in a lot of code and it's all worked just fine on dedicated servers.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

So, if you e.g. do:


ClientWorld world = Minecraft.getMinecraft().world 

The JVM has to check that the type of Minecraft#world (ClientWorld) is actually assignable to ClientWorld. In this case this is trivial, because obviously ClientWorld is-a ClientWorld.

 

In this case the JVM can verify this code without loading any classes (i.e. it doesn't need to load ClientWorld). Your class (containing the two static methods for the lambdas) loads fine, even on the server.

Out of curiosity, wouldn't this trigger the class loading of Minecraft since a method of Minecraft is being invoked?

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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.