Player Avatar in GUI

Started by FishyHard on

Topic category: User side tutorials

Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • 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
Joined Jul 2022
Points:

User statistics:

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

Joined Jan 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Doesnt work for me, just…
Sat, 01/14/2023 - 21:18

Doesnt work for me, just throws errors.

 

 

Build info: MCreator 2022.2.34517, forge-1.16.5, 64-bit, 15776 MB, Windows 10, JVM 17.0.3, JAVA_HOME: C:\Users\abdha\Desktop\Mcreator 2022\MCreator\jdk, started on: 2023-01-14-22:17:07

> Task :compileJava
C:\Users\abdha\MCreatorWorkspaces\CraftImpact(1.16.5 final)\src\main\java\net\honkai\honkaimod\gui\StatsDisplayTestGuiWindow.java:25: error: cannot find symbol import com.mojang.blaze3d.platform.Lighting;
^
symbol: class Lighting
location: package com.mojang.blaze3d.platform
C:\Users\abdha\MCreatorWorkspaces\CraftImpact(1.16.5 final)\src\main\java\net\honkai\honkaimod\gui\StatsDisplayTestGuiWindow.java:28: error: cannot find symbol import net.minecraft.client.renderer.MultiBufferSource;
^
symbol: class MultiBufferSource
location: package net.minecraft.client.renderer
C:\Users\abdha\MCreatorWorkspaces\CraftImpact(1.16.5 final)\src\main\java\net\honkai\honkaimod\gui\StatsDisplayTestGuiWindow.java:29: error: cannot find symbol import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
^
symbol: class EntityRenderDispatcher
location: package net.minecraft.client.renderer.entity
C:\Users\abdha\MCreatorWorkspaces\CraftImpact(1.16.5 final)\src\main\java\net\honkai\honkaimod\gui\StatsDisplayTestGuiWindow.java:211: error: cannot find symbol EntityRendererManager entityrenderermanager = Minecraft.getInstance().getRenderManager();
^
symbol: class EntityRendererManager
location: class net.honkai.honkaimod.gui.StatsDisplayTestGuiWindow
C:\Users\abdha\MCreatorWorkspaces\CraftImpact(1.16.5 final)\src\main\java\net\honkai\honkaimod\gui\StatsDisplayTestGuiWindow.java:215: error: package IRenderTypeBuffer does not exist IRenderTypeBuffer.Impl irendertypebuffer$impl = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
^
5 errors
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
1 actionable task: 1 executed