how to add player avatar in GUI

Started by Doo89 on

Topic category: User side tutorials

Last seen on 04:41, 24. Apr 2024
Joined Aug 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to add player avatar in GUI
Fri, 02/04/2022 - 14:20 (edited)

exemple

1 - Completely realize your GUI

2 - Edit your GUI code, the one that ends up: Screen.java

exemple

3 - At the end of the imports, add:

import com.mojang.blaze3d.platform.Lighting;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.entity.LivingEntity;

4 - Add attributes:

	private float xMouse; 
	private float yMouse;

(After:)

private final Player entity;

Doo89

5 - At the end of class 'render':

  this.xMouse = mouseX;
  this.yMouse = mouseY;

6 - At the end of class 'renderBg':

renderEntityInInventory(this.leftPos + 30, this.topPos + 70, 30, this.leftPos + 30 - this.xMouse, (float)(this.topPos + 70 - 50) - this.yMouse, this.minecraft.player);

exemple

7 - Before the last }, paste this method:

public static void renderEntityInInventory(int leftPos, int topPos, int height, float LookH, float LookV, LivingEntity player) {
      float f = (float)Math.atan((double)(LookH / 40.0F));
      float f1 = (float)Math.atan((double)(LookV / 40.0F));
      PoseStack posestack = RenderSystem.getModelViewStack();
      posestack.pushPose();
      posestack.translate((double)leftPos, (double)topPos, 1050.0D);
      posestack.scale(1.0F, 1.0F, -1.0F);
      RenderSystem.applyModelViewMatrix();
      PoseStack posestack1 = new PoseStack();
      posestack1.translate(0.0D, 0.0D, 1000.0D);
      posestack1.scale((float)height, (float)height, (float)height);
      Quaternion quaternion = Vector3f.ZP.rotationDegrees(180.0F);
      Quaternion quaternion1 = Vector3f.XP.rotationDegrees(f1 * 20.0F);
      quaternion.mul(quaternion1);
      posestack1.mulPose(quaternion);
      float f2 = player.yBodyRot;
      float f3 = player.getYRot();
      float f4 = player.getXRot();
      float f5 = player.yHeadRotO;
      float f6 = player.yHeadRot;
      player.yBodyRot = 180.0F + f * 20.0F;
      player.setYRot(180.0F + f * 40.0F);
      player.setXRot(-f1 * 20.0F);
      player.yHeadRot = player.getYRot();
      player.yHeadRotO = player.getYRot();
      Lighting.setupForEntityInInventory();
      EntityRenderDispatcher entityrenderdispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
      quaternion1.conj();
      entityrenderdispatcher.overrideCameraOrientation(quaternion1);
      entityrenderdispatcher.setRenderShadow(false);
      MultiBufferSource.BufferSource multibuffersource$buffersource = Minecraft.getInstance().renderBuffers().bufferSource();
      RenderSystem.runAsFancy(() -> {
         entityrenderdispatcher.render(player, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, posestack1, multibuffersource$buffersource, 15728880);
      });
      multibuffersource$buffersource.endBatch();
      entityrenderdispatcher.setRenderShadow(true);
      player.yBodyRot = f2;
      player.setYRot(f3);
      player.setXRot(f4);
      player.yHeadRotO = f5;
      player.yHeadRot = f6;
      posestack.popPose();
      RenderSystem.applyModelViewMatrix();
      Lighting.setupFor3DItems();
}

8 - Save and lock code.

9 - Test and adjust x and y position:

adjust

Inspiration from the KinderrKill Youtube channel:

https://www.youtube.com/c/KinderrKill/

Thanks KinderrKill.

Sorry for my english.

Edited by Doo89 on Fri, 02/04/2022 - 14:20
Last seen on 16:06, 23. Apr 2024
Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
What do you mean "before the…
Mon, 09/26/2022 - 02:01

What do you mean "before the last }"? could you add a image

Last seen on 19:56, 23. Apr 2024
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This kind of confuses me. Is…
Wed, 09/28/2022 - 19:05

This kind of confuses me. Is there any way you can make a video on this? Cuz I love that you made this, but I don't understand.

Last seen on 21:23, 11. Mar 2023
Joined Jun 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
whats so confusing? it all…
Sat, 10/01/2022 - 14:11

whats so confusing? it all works for me 1.18.2

Last seen on 19:56, 23. Apr 2024
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Oh yeah, I didn't realize…
Tue, 11/08/2022 - 14:51

Oh yeah, I didn't realize this was 1.18. Is there a way to do this in 1.16.5?

Last seen on 09:08, 15. Apr 2023
Joined Dec 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Great tutorial!
Wed, 11/23/2022 - 14:11

Great tutorial!

Last seen on 19:10, 23. Apr 2024
Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Good tutorial! Can you make…
Sat, 02/11/2023 - 10:43

Good tutorial! Can you make a tutorial on how to do the same with the mob please?