Player Avatar in GUI

Started by FishyHard on Tue, 10/04/2022 - 20:28

Topic category: User side tutorials

Last seen on 21:52, 28. Nov 2022
Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Player Avatar in GUI
Sun, 10/09/2022 - 15:46 (edited)

Player Avatar in GUI

Tutorial For 1.16.5
After

1 - Finish your GUI that you need only to add Player Avatar

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

2

3 - At the end of the imports, add:

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

3

4 - Add attributes:

private float xMouse;
private float yMouse;

4

 

5 - At the end of class 'render':

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

5

6 - At the end of class 'drawGuiContainerBackgroundLayer':

renderEntityInInventory(this.guiLeft + 88, this.guiTop + 125, 30, this.guiLeft + 88 - this.xMouse, (float) (this.guiTop + 125 - 50) - this.yMouse, this.minecraft.player);

6

7 - public static void renderEntityInInventory(int posX, int posY, int scale, float mouseX, float mouseY, LivingEntity livingEntity) {
      float f = (float)Math.atan((double)(mouseX / 40.0F));
      float f1 = (float)Math.atan((double)(mouseY / 40.0F));
      RenderSystem.pushMatrix();
      RenderSystem.translatef((float)posX, (float)posY, 1050.0F);
      RenderSystem.scalef(1.0F, 1.0F, -1.0F);
      MatrixStack matrixstack = new MatrixStack();
      matrixstack.translate(0.0D, 0.0D, 1000.0D);
      matrixstack.scale((float)scale, (float)scale, (float)scale);
      Quaternion quaternion = Vector3f.ZP.rotationDegrees(180.0F);
      Quaternion quaternion1 = Vector3f.XP.rotationDegrees(f1 * 20.0F);
      quaternion.multiply(quaternion1);
      matrixstack.rotate(quaternion);
      float f2 = livingEntity.renderYawOffset;
      float f3 = livingEntity.rotationYaw;
      float f4 = livingEntity.rotationPitch;
      float f5 = livingEntity.prevRotationYawHead;
      float f6 = livingEntity.rotationYawHead;
      livingEntity.renderYawOffset = 180.0F + f * 20.0F;
      livingEntity.rotationYaw = 180.0F + f * 40.0F;
      livingEntity.rotationPitch = -f1 * 20.0F;
      livingEntity.rotationYawHead = livingEntity.rotationYaw;
      livingEntity.prevRotationYawHead = livingEntity.rotationYaw;
      EntityRendererManager entityrenderermanager = Minecraft.getInstance().getRenderManager();
      quaternion1.conjugate();
      entityrenderermanager.setCameraOrientation(quaternion1);
      entityrenderermanager.setRenderShadow(false);
      IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
      RenderSystem.runAsFancy(() -> {
         entityrenderermanager.renderEntityStatic(livingEntity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, matrixstack, irendertypebuffer$impl, 15728880);
      });
      irendertypebuffer$impl.finish();
      entityrenderermanager.setRenderShadow(true);
      livingEntity.renderYawOffset = f2;
      livingEntity.rotationYaw = f3;
      livingEntity.rotationPitch = f4;
      livingEntity.prevRotationYawHead = f5;
      livingEntity.rotationYawHead = f6;
      RenderSystem.popMatrix();
   }

78

8 - Save and lock code. (Ctrl + w; Ctrl + s)

9 - If you want to change Player Position play around with these numbers
9
10 - If you want to change Player Size play around with these 2 numbers (Don't touch third number with - )
10

Credits:
Main Tutorial (Not 1.16.5) - https://mcreator.net/forum/83739/how-add-player-avatar-gui
Help from Kleiders - https://mcreator.net/user/291988/urielito3010

Edited by FishyHard on Sun, 10/09/2022 - 15:46
Last seen on 21:27, 28. Nov 2022
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Is It Possible To Type…
Wed, 10/26/2022 - 07:27

Is It Possible To Type Another "Living Entity" Instead Of The Player?

Last seen on 21:52, 28. Nov 2022
Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Haven't tried.
Sun, 10/30/2022 - 18:30

Haven't tried.