Skip to content

Commit

Permalink
Minor changes to the renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Jan 23, 2025
1 parent bcc25af commit 26e3032
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -21,5 +21,4 @@ private static ModelPart getModelPart(boolean isSlim, boolean isBaby) {
}
return layerDefinition.bakeRoot();
}

}
Original file line number Diff line number Diff line change
@@ -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 + "}";
}
}

0 comments on commit 26e3032

Please sign in to comment.