Started by
FishyHard
on
Topic category: User side tutorials
Player Avatar in GUI
Tutorial For 1.16.5
1 - Finish your GUI that you need only to add Player Avatar
2 - Edit your GUI code, the one that ends up: GuiWindow.java
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;
4 - Add attributes:
private float xMouse;
private float yMouse;
5 - At the end of class 'render':
this.xMouse = mouseX;
this.yMouse = mouseY;
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);
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();
}
8
8 - Save and lock code. (Ctrl + w; Ctrl + s)
9 - If you want to change Player Position play around with these numbers
10 - If you want to change Player Size play around with these 2 numbers (Don't touch third number with - )
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
Is It Possible To Type Another "Living Entity" Instead Of The Player?
Haven't tried.
Doesnt work for me, just throws errors.