Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
Fixing bugs and having player model centered in flight!
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKronicle committed Oct 14, 2022
1 parent 8f4062c commit f498f2e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Quaternion;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3f;

import java.util.List;
Expand All @@ -26,6 +28,9 @@ public class PlayerHud extends BoxHudEntry {

private float lastYawOffset = 0;
private float yawOffset = 0;
private float lastYOffset = 0;
private float yOffset = 0;


public PlayerHud() {
super(62, 94, true);
Expand All @@ -47,9 +52,11 @@ public void renderPlayer(double x, double y, float delta) {
return;
}

float lerpY = (lastYOffset + ((yOffset - lastYOffset) * delta));

MatrixStack matrixStack = RenderSystem.getModelViewStack();
matrixStack.push();
matrixStack.translate(x, y, 1050);
matrixStack.translate(x, y - lerpY, 1050);
matrixStack.scale(1, 1, -1);

RenderSystem.applyModelViewMatrix();
Expand Down Expand Up @@ -104,6 +111,31 @@ public boolean tickable() {
public void tick() {
lastYawOffset = yawOffset;
yawOffset *= .93f;
lastYOffset = yOffset;
if (client.player != null && client.player.isInSwimmingPose()) {
float rawPitch = client.player.isTouchingWater() ? -90.0F - client.player.getPitch() : -90.0F;
float pitch = MathHelper.lerp(client.player.getLeaningPitch(1), 0.0F, rawPitch);
float height = client.player.getHeight();
// sin = opposite / hypotenuse
float offset = (float) (Math.sin(Math.toRadians(pitch)) * height);
yOffset = Math.abs(offset) + 35;
} else if (client.player != null && client.player.isFallFlying()) {
// Elytra!

float j = (float)client.player.getRoll() + 1;
float k = MathHelper.clamp(j * j / 100.0F, 0.0F, 1.0F);

float pitch = k * (-90.0F - client.player.getPitch()) + 90;
float height = client.player.getHeight();
// sin = opposite / hypotenuse
float offset = (float) (Math.sin(Math.toRadians(pitch)) * height) * 50;
yOffset = 35 - offset;
if (pitch < 0) {
yOffset -= ((1 / (1 + Math.exp(-pitch / 4))) - .5) * 20;
}
} else {
yOffset *= .8;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public void onEntityAttack(Entity attacked) {
}

public void onEntityDamage(Entity entity) {
if (client.player == null) {
return;
}
if (entity.getId() == client.player.getId()) {
target = -1;
count = 0;
Expand Down

0 comments on commit f498f2e

Please sign in to comment.