[TUTORIAL] Rendering an Entity in a GUI

Started by Rikurob on Sun, 08/21/2022 - 19:20

Topic category: Advanced modding

Last seen on 07:52, 21. Nov 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 07:52, 21. Nov 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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