From 26e3032a3df2280c46bafc2ccd15ab0a241033cd Mon Sep 17 00:00:00 2001 From: Crystal Spider Date: Thu, 23 Jan 2025 10:38:26 +0100 Subject: [PATCH] Minor changes to the renderer. --- .../entity/player/FancyPlayerRenderer.java | 113 +++++++++--------- .../entity/player/FancyPlayerWidget.java | 14 +-- .../entity/player/model/FancyPlayerModel.java | 3 +- .../entity/player/state/Rotation.java | 64 ++++++++++ 4 files changed, 127 insertions(+), 67 deletions(-) create mode 100644 common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/state/Rotation.java diff --git a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerRenderer.java b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerRenderer.java index defb050..1aa52cb 100644 --- a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerRenderer.java +++ b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerRenderer.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import it.crystalnest.fancy_entity_renderer.entity.player.model.FancyPlayerModel; +import it.crystalnest.fancy_entity_renderer.entity.player.state.Rotation; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; @@ -17,39 +18,6 @@ public class FancyPlayerRenderer extends PlayerRenderer { - @NotNull - public volatile PlayerSkin skin = DefaultPlayerSkin.getDefaultSkin(); - public boolean isCrouching = false; - public boolean isBaby = false; - public boolean isGlowing = false; - @Nullable - public Parrot.Variant leftShoulderParrot = null; - @Nullable - public Parrot.Variant rightShoulderParrot = null; - - public float leftArmXRot = 0F; - public float leftArmYRot = 0F; - public float leftArmZRot = 0F; - - public float rightArmXRot = 0F; - public float rightArmYRot = 0F; - public float rightArmZRot = 0F; - - public float leftLegXRot = 0F; - public float leftLegYRot = 0F; - public float leftLegZRot = 0F; - - public float rightLegXRot = 0F; - public float rightLegYRot = 0F; - public float rightLegZRot = 0F; - - public float headXRot = 0F; - public float headYRot = 0F; - public float headZRot = 0F; - - public float bodyXRot = 0F; - public float bodyYRot = 0F; - private static final EntityRendererProvider.Context RENDER_CONTEXT = new EntityRendererProvider.Context( Minecraft.getInstance().getEntityRenderDispatcher(), Minecraft.getInstance().getItemModelResolver(), @@ -60,52 +28,81 @@ public class FancyPlayerRenderer extends PlayerRenderer { new EquipmentAssetManager(), Minecraft.getInstance().font ); + + private final Rotation leftArmRot = new Rotation(); + + private final Rotation rightArmRot = new Rotation(); + + private final Rotation leftLegRot = new Rotation(); + + private final Rotation rightLegRot = new Rotation(); + + private final Rotation headRot = new Rotation(); + + private final Rotation bodyRot = new Rotation(); + + public PlayerSkin skin = DefaultPlayerSkin.getDefaultSkin(); + + public boolean isCrouching = false; + + public boolean isBaby; + + public boolean isGlowing = false; + + @Nullable + public Parrot.Variant leftShoulderParrot = null; + + @Nullable + public Parrot.Variant rightShoulderParrot = null; + public FancyPlayerRenderer(boolean isSlim, boolean isBaby) { super(RENDER_CONTEXT, false); model = new FancyPlayerModel(isSlim, isBaby); + this.isBaby = isBaby; } public void updatePlayerProperties(@NotNull PlayerRenderState state) { - - state.skin = this.skin; - state.isCrouching = this.isCrouching; - state.parrotOnLeftShoulder = this.leftShoulderParrot; - state.parrotOnRightShoulder = this.rightShoulderParrot; + state.skin = skin; + state.isCrouching = isCrouching; + state.parrotOnLeftShoulder = leftShoulderParrot; + state.parrotOnRightShoulder = rightShoulderParrot; state.nameTag = null; state.nameTagAttachment = null; state.customName = null; - state.isBaby = this.isBaby; - state.appearsGlowing = this.isGlowing; + state.isBaby = isBaby; + state.appearsGlowing = isGlowing; state.isSpectator = false; state.ageInTicks = 1000; state.walkAnimationPos = 0.0F; state.walkAnimationSpeed = 0.0F; - state.pose = this.isCrouching ? Pose.CROUCHING : Pose.STANDING; + state.pose = isCrouching ? Pose.CROUCHING : Pose.STANDING; + state.isUpsideDown = true; // X and Y rotations are switched for some reason - this.model.leftArm.xRot = this.leftArmXRot; - this.model.leftArm.yRot = this.leftArmYRot; - this.model.leftArm.zRot = this.leftArmZRot; + model.leftArm.xRot = leftArmRot.getX(); + model.leftArm.yRot = leftArmRot.getY(); + model.leftArm.zRot = leftArmRot.getZ(); - this.model.rightArm.xRot = this.rightArmXRot; - this.model.rightArm.yRot = this.rightArmYRot; - this.model.rightArm.zRot = this.rightArmZRot; + model.rightArm.xRot = rightArmRot.getX(); + model.rightArm.yRot = rightArmRot.getY(); + model.rightArm.zRot = rightArmRot.getZ(); - this.model.leftLeg.xRot = this.leftLegXRot; - this.model.leftLeg.yRot = this.leftLegYRot; - this.model.leftLeg.zRot = this.leftLegZRot; + model.leftLeg.xRot = leftLegRot.getX(); + model.leftLeg.yRot = leftLegRot.getY(); + model.leftLeg.zRot = leftLegRot.getZ(); - this.model.rightLeg.xRot = this.rightLegXRot; - this.model.rightLeg.yRot = this.rightLegYRot; - this.model.rightLeg.zRot = this.rightLegZRot; + model.rightLeg.xRot = rightLegRot.getX(); + model.rightLeg.yRot = rightLegRot.getY(); + model.rightLeg.zRot = rightLegRot.getZ(); - this.model.root().xRot = this.bodyXRot; - this.model.root().yRot = this.bodyYRot; + model.root().xRot = bodyRot.getX(); + model.root().yRot = bodyRot.getY(); + model.root().zRot = bodyRot.getZ(); - this.model.head.xRot = this.headXRot; - this.model.head.yRot = this.headYRot; - this.model.head.zRot = this.headZRot; + model.head.xRot = headRot.getX(); + model.head.yRot = headRot.getY(); + model.head.zRot = headRot.getZ(); } @Override diff --git a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerWidget.java b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerWidget.java index 6fa28da..448feae 100644 --- a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerWidget.java +++ b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/FancyPlayerWidget.java @@ -12,17 +12,19 @@ import org.jetbrains.annotations.NotNull; public class FancyPlayerWidget extends AbstractWidget { - private float rotationX = 0F; - - private float rotationY = 0F; - private final PlayerRenderState renderState = new PlayerRenderState(); private final FancyPlayerRenderer renderer = new FancyPlayerRenderer(true, true); + private float rotationX = 0F; + + private float rotationY = 0F; + public FancyPlayerWidget(int x, int y, int width, int height) { super(x, y, width, height, CommonComponents.EMPTY); renderer.isGlowing = true; + renderer.isBaby = false; + renderer.isCrouching = true; } @Override @@ -31,12 +33,10 @@ protected void renderWidget(GuiGraphics gfx, int mouseX, int mouseY, float parti gfx.pose().translate(getX() + getWidth() / 2.0F, (float) (getY() + getHeight()), 100.0F); float f = getHeight() / 2.125F; gfx.pose().scale(f, f, f); -// gfx.pose().translate(0.0F, -0.0625F, 0.0F); + gfx.pose().translate(0.0F, -0.0625F, 0.0F); gfx.pose().rotateAround(Axis.XP.rotationDegrees(this.rotationX), 0.0F, -1.0625F, 0.0F); gfx.pose().mulPose(Axis.YP.rotationDegrees(this.rotationY)); gfx.flush(); - gfx.pose().scale(1.0F, 1.0F, -1.0F); - gfx.pose().translate(0.0F, -1.501F, 0.0F); Lighting.setupForEntityInInventory(Axis.XP.rotationDegrees(this.rotationX)); gfx.drawSpecial(src -> renderer.render(renderState, gfx.pose(), src, 15728880)); Lighting.setupFor3DItems(); diff --git a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/model/FancyPlayerModel.java b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/model/FancyPlayerModel.java index c897dd0..f67d706 100644 --- a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/model/FancyPlayerModel.java +++ b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/model/FancyPlayerModel.java @@ -6,8 +6,8 @@ import net.minecraft.client.model.geom.builders.LayerDefinition; public class FancyPlayerModel extends PlayerModel { - private static final LayerDefinition FANCY_PLAYER = LayerDefinition.create(createMesh(CubeDeformation.NONE, false), 64, 64); + private static final LayerDefinition FANCY_PLAYER_SLIM = LayerDefinition.create(createMesh(CubeDeformation.NONE, true), 64, 64); public FancyPlayerModel(boolean isSlim, boolean isBaby) { @@ -21,5 +21,4 @@ private static ModelPart getModelPart(boolean isSlim, boolean isBaby) { } return layerDefinition.bakeRoot(); } - } diff --git a/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/state/Rotation.java b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/state/Rotation.java new file mode 100644 index 0000000..9ae3378 --- /dev/null +++ b/common/src/main/java/it/crystalnest/fancy_entity_renderer/entity/player/state/Rotation.java @@ -0,0 +1,64 @@ +package it.crystalnest.fancy_entity_renderer.entity.player.state; + +import java.util.Objects; + +public class Rotation { + private float x; + private float y; + private float z; + + public Rotation(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + public Rotation() { + this(0, 0, 0); + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + public float getZ() { + return z; + } + + public void setZ(float z) { + this.z = z; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Rotation rotation)) { + return false; + } + return Float.compare(x, rotation.x) == 0 && Float.compare(y, rotation.y) == 0 && Float.compare(z, rotation.z) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(x, y, z); + } + + @Override + public String toString() { + return "Rotation{x=" + x + ", y=" + y + ", z=" + z + "}"; + } +}