Topic category: Advanced modding
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.
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:
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.
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.
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:
Harder Way:
Step 1:
Step 2:
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!
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?
MCreator 2023.1 solution:
RETURN (NULL) get static entity of type (entity)
(return block should have color of sky blue)
how would i render a specific item(with some NBT) in 2023.1???
i want this in 2022.1 (1.18.2) PLEASEE
Where do I put step 5? In the screem.java?
Nothing appears to me