[TUTORIAL] Rendering an Entity in a GUI

Started by Rikurob on

Topic category: Advanced modding

Last seen on 06:22, 13. Mar 2023
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[TUTORIAL] Rendering an Entity in a GUI
Mon, 08/22/2022 - 14:31 (edited)

This is a little complicated depending on what you want to do. The minecraft player is easy, other entities are a little harder. If it is a bound gui it is also easier as you return the entity. You can get an entity's UUID on right click and save it as an nbt and then call for each entity in a radius if it's uuid=nbtValue set your target entity to that entity. I figured this out by experimenting with code I took from the default Minecraft Inventory. These are snippets from my upcoming mod Personas so the values portray that. I had to use this method as I didn't want my GUI bound to the entity.

Step 1: Make and setup your GUI how you want without the Entity, leaving a spot where you want it to go.

Step 2: Open your GUINameScreen.java and setup your imports, these are all mine below minus my procedures.

Image

You also need to import any procedures you execute here.

Step 3: Find the following class:

    protected void renderBg(PoseStack ms, float partialTicks, int gx, int gy) {

 

Step 4: Under this class, add the following:

Declare your target entity

//This to set the entity with a procedure (My example uses this)
Entity targetEntity = GetEntityProcedure.execute(world, x, y, z, entity); //This is the procedure I use to set my target entity
//Or this for the Player (Player Inventory uses this)
Entity targetEntity = this.minecraft.player;
//Or this for using bound gui entity (I think, I am unsure about this one, have to test it still)
Entity targetEntity = entity;

Test/Render Target Entity through the renderEntityInInventory class that will be declared in the next step.

 if(targetEntity instanceof LivingEntity) {
            LivingEntity livingEntityTarget = (LivingEntity) targetEntity ;
            renderEntityInInventory(this.leftPos+ 51, this.topPos+94, 30, (float)(this.leftPos + 51) - this.xMouse, (float)(this.topPos + 25) - this.yMouse, livingEntityTarget);
        }

Mine looks Like this:

Image

For the Procedure to get the entity, I handled like how I said above, and returned the entity. I can post that code if someone needs.

Step 5: Add and edit the necessary values in this class below, and your finished.

Image

Step 6 (Optional): To add more entities, repeat steps 2 and 3.

If you need help figuring this out let me know below and I'll try to do what I can.

Edited by Rikurob on Mon, 08/22/2022 - 14:31
Last seen on 06:22, 13. Mar 2023
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
REVISION + PROCEDURES TO…
Tue, 08/23/2022 - 04:41

REVISION + PROCEDURES TO HELP:

So, to get a container, instead of using entity, as that returns the player, do the below process with procedures, and call the return procedure equal to the entity as in the example. Until I figure out a better way to do this. This way though you can set any entity you click that you want to appear in you GUI.

The harder way uses the UUID plugin, or you can optionally code that yourself with using the code "entity.getUUID().toString()" to replace the UUID procedure lines.

 

These are examples that I made for my upcoming mod to make Chest for Don't Starve in Minecraft.

Simple Way:

Image

Harder Way:

Step 1:

Image

 

Step 2:

Image

Last seen on 13:53, 4. Mar 2023
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Could you possibly paste the…
Sun, 02/26/2023 - 15:35

Could you possibly paste the raw text from the

renderEntityInInventory function? I am having trouble typing it as I keep mispelling things.

Thanks in advance!

Last seen on 13:21, 4. Jun 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In MCreator 2023.1 there's…
Sun, 02/26/2023 - 17:11

In MCreator 2023.1 there's an option to do it without coding. Still, I have a question - how to do it, so entity ALWAYS shows up in GUI?

Last seen on 13:21, 4. Jun 2023
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
MCreator 2023.1 solution…
Fri, 03/17/2023 - 11:25

MCreator 2023.1 solution:
RETURN (NULL) get static entity of type (entity)
(return block should have color of sky blue)

Last seen on 14:48, 11. Jul 2023
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how would i render a…
Tue, 04/04/2023 - 08:33

how would i render a specific item(with some NBT) in 2023.1???

Last seen on 19:27, 20. Mar 2024
Joined Dec 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
i want this in 2022.1 (1.18…
Tue, 12/12/2023 - 02:34

i want this in 2022.1 (1.18.2) PLEASEE