Skip to content

Commit

Permalink
implement #71
Browse files Browse the repository at this point in the history
  • Loading branch information
alRex-U committed May 6, 2022
1 parent 68f26d8 commit d9a0c6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alrex.parcool.client.animation.Animator;
import com.alrex.parcool.client.animation.PlayerModelTransformer;
import com.alrex.parcool.client.input.KeyBindings;
import com.alrex.parcool.common.action.impl.ClingToCliff;
import com.alrex.parcool.common.capability.Parkourability;
import com.mojang.blaze3d.matrix.MatrixStack;
Expand All @@ -11,6 +12,9 @@
import net.minecraftforge.client.event.RenderPlayerEvent;

public class ClingToCliffAnimator extends Animator {
private int oldTick = 0;
private int movementValue = 0;

@Override
public void animate(RenderPlayerEvent.Pre event, AbstractClientPlayerEntity player, Parkourability parkourability) {
ClingToCliff clingToCliff = parkourability.getClingToCliff();
Expand All @@ -23,18 +27,28 @@ public void animate(RenderPlayerEvent.Pre event, AbstractClientPlayerEntity play
PlayerRenderer renderer = event.getRenderer();
PlayerModel<AbstractClientPlayerEntity> model = renderer.getModel();

boolean usePartialTick = false;
if (KeyBindings.getKeyRight().isDown() ^ KeyBindings.getKeyLeft().isDown()) {
if (getTick() != oldTick) {
oldTick = getTick();
usePartialTick = true;
movementValue += 1;
}
}
double movement = Math.sin(Math.toRadians((movementValue + (usePartialTick ? 0 : partial)) * 15)) * 45;

stack.pushPose();
{
PlayerModelTransformer.wrap(player, model, getTick(), partial)
.rotateRightArm(
(float) Math.toRadians(20.0F),
(float) -Math.toRadians(player.yBodyRot),
(float) Math.toRadians(0.0F)
0
)
.rotateLeftArm(
(float) Math.toRadians(20.0F),
(float) -Math.toRadians(player.yBodyRot),
(float) Math.toRadians(0.0F)
0
).render(
stack,
event.getBuffers(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ public void onClientTick(PlayerEntity player, Parkourability parkourability, Sta
stamina.consume(parkourability.getActionInfo().getStaminaConsumptionClimbUp(), parkourability.getActionInfo());
}
if (cling) {
player.setDeltaMovement(0, 0, 0);
if (KeyBindings.getKeyLeft().isDown() && KeyBindings.getKeyRight().isDown()) {
player.setDeltaMovement(0, 0, 0);
} else {
Vector3d wallDirection = WorldUtil.getWall(player);
if (wallDirection != null) {
Vector3d vec = wallDirection.yRot((float) (Math.PI / 2)).normalize().scale(0.1);
if (KeyBindings.getKeyLeft().isDown()) player.setDeltaMovement(vec);
else if (KeyBindings.getKeyRight().isDown()) player.setDeltaMovement(vec.reverse());
else player.setDeltaMovement(0, 0, 0);
}
}
}
}
if (cling) {
Expand All @@ -76,7 +86,9 @@ public void onRender(TickEvent.RenderTickEvent event, PlayerEntity player, Parko
if (cling) {
Vector3d wall = WorldUtil.getWall(player);
if (wall != null) {
player.yRot = (float) VectorUtil.toYawDegree(wall.normalize());
float yRot = (float) VectorUtil.toYawDegree(wall.normalize());
player.yRot = yRot;
player.setYBodyRot(yRot);
}
}
}
Expand Down

0 comments on commit d9a0c6d

Please sign in to comment.