Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Dec 14, 2024
1 parent 0195942 commit 26314db
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class MixinClientPlayerInteractionManager {
@Shadow
private float currentBreakingProgress;

@Inject(method = "getBlockBreakingProgress", at = @At(value = "HEAD"), cancellable = true)
@Inject(method = "getBlockBreakingProgress", at = @At(value = "RETURN"), cancellable = true)
private void animatium$oldBlockMiningProgress(CallbackInfoReturnable<Integer> cir) {
if (AnimatiumConfig.oldBlockMiningProgress) {
cir.setReturnValue((int) (this.currentBreakingProgress * 10.0f) - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.llamalad7.mixinextras.sugar.Local;
import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.mixins.accessor.CameraAccessor;
import me.mixces.animatium.util.HandUtils;
import me.mixces.animatium.util.PlayerUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
Expand All @@ -20,7 +20,6 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
Expand All @@ -33,12 +32,12 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) {
}

@Inject(method = "render(Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;peek()Lnet/minecraft/client/util/math/MatrixStack$Entry;", ordinal = 0))
private void animatium$oldFishingBobberPosition(FishingBobberEntityState fishingBobberEntityState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
private void animatium$oldFishingBobberPosition(FishingBobberEntityState fishingBobberEntityState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
if (AnimatiumConfig.oldFishingBobberPosition) {
assert MinecraftClient.getInstance().player != null;
int multiplier = HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher);
int multiplier = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher);
//TODO: Fix line
matrixStack.translate(multiplier * 0.5F, 0.0F, 0.0F);
matrices.translate(multiplier * 0.5F, 0.0F, 0.0F);
}
}

Expand All @@ -47,9 +46,10 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) {
if (AnimatiumConfig.fishingRodLineInterpolation) {
CameraAccessor cameraAccessor = (CameraAccessor) dispatcher.camera;
float eyeHeight = MathHelper.lerp(v, cameraAccessor.getLastCameraY(), cameraAccessor.getCameraY());
return this.animatium$getCameraPosVec(instance, v, eyeHeight);
return PlayerUtils.lerpPlayerWithEyeHeight(instance, v, eyeHeight);
} else {
return original.call(instance, v);
}
return original.call(instance, v);
}

@ModifyExpressionValue(method = "getHandPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isInSneakingPose()Z"))
Expand All @@ -70,15 +70,7 @@ protected MixinFishingBobberEntityRenderer(EntityRendererFactory.Context ctx) {
@ModifyArg(method = "updateRenderState(Lnet/minecraft/entity/projectile/FishingBobberEntity;Lnet/minecraft/client/render/entity/state/FishingBobberEntityState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/FishingBobberEntityRenderer;getHandPos(Lnet/minecraft/entity/player/PlayerEntity;FF)Lnet/minecraft/util/math/Vec3d;"), index = 1)
private float animatium$fixCastLineSwing(float f) {
assert MinecraftClient.getInstance().player != null;
int multiplier = HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher);
int multiplier = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher);
return f * (AnimatiumConfig.fixCastLineSwing ? multiplier : 1);
}

@Unique
private Vec3d animatium$getCameraPosVec(PlayerEntity entity, float tickDelta, float eyeHeight) {
double d = MathHelper.lerp(tickDelta, entity.prevX, entity.getX());
double e = MathHelper.lerp(tickDelta, entity.prevY, entity.getY()) + eyeHeight;
double f = MathHelper.lerp(tickDelta, entity.prevZ, entity.getZ());
return new Vec3d(d, e, f);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.mixces.animatium.mixins;

import me.mixces.animatium.config.AnimatiumConfig;
import me.mixces.animatium.util.HandUtils;
import me.mixces.animatium.util.PlayerUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderer;
Expand All @@ -23,10 +23,11 @@ protected MixinFlyingItemEntityRenderer(EntityRendererFactory.Context ctx) {
}

@Inject(method = "render(Lnet/minecraft/client/render/entity/state/FlyingItemEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderState;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V"))
private void animatium$oldProjectilePosition(FlyingItemEntityRenderState flyingItemEntityRenderState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
private void animatium$oldProjectilePosition(FlyingItemEntityRenderState flyingItemEntityRenderState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
if (AnimatiumConfig.oldProjectilePosition) {
assert MinecraftClient.getInstance().player != null;
matrixStack.translate(HandUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher) * 0.25F, 0.0F, 0.25F);
int direction = PlayerUtils.handMultiplier(MinecraftClient.getInstance().player, dispatcher);
matrices.translate(direction * 0.25F, 0.0F, 0.25F);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ public abstract class MixinHeldItemRenderer {

@WrapOperation(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;scale(FFF)V", ordinal = 1))
private void animatium$postBowTransform(MatrixStack instance, float x, float y, float z, Operation<Void> original, @Local(argsOnly = true) AbstractClientPlayerEntity player, @Local(argsOnly = true) Hand hand) {
final Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite();
final int direction = arm == Arm.RIGHT ? 1 : -1;
if (AnimatiumConfig.tiltItemPositions) {
final Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite();
final int direction = arm == Arm.RIGHT ? 1 : -1;
instance.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * -335));
instance.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * -50.0F));
original.call(instance, x, y, z);
}

original.call(instance, x, y, z);
if (AnimatiumConfig.tiltItemPositions) {
instance.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(direction * 50.0F));
instance.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(direction * 335));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
@Mixin(LivingEntityRenderer.class)
public abstract class MixinLivingEntityRenderer<S extends LivingEntityRenderState> {
@Inject(method = "render(Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V", ordinal = 1))
private void animatium$syncPlayerModelWithEyeHeight(S livingEntityRenderState, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
private void animatium$syncPlayerModelWithEyeHeight(S livingEntityRenderState, MatrixStack matrices, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) {
if (AnimatiumConfig.syncPlayerModelWithEyeHeight) {
MinecraftClient client = MinecraftClient.getInstance();
ClientPlayerEntity player = client.player;
if (livingEntityRenderState instanceof PlayerEntityRenderState state && player != null && state.id == player.getId()) {
Camera camera = client.gameRenderer.getCamera();
CameraAccessor cameraAccessor = (CameraAccessor) camera;
float cameraLerpValue = MathHelper.lerp(camera.getLastTickDelta(), cameraAccessor.getLastCameraY(), cameraAccessor.getCameraY());
matrixStack.translate(0.0F, PlayerEntity.STANDING_DIMENSIONS.eyeHeight() - cameraLerpValue, 0.0F);
matrices.translate(0.0F, PlayerEntity.STANDING_DIMENSIONS.eyeHeight() - cameraLerpValue, 0.0F);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/mixces/animatium/mixins/MixinWorldRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public abstract class MixinWorldRenderer {
private SkyRendering skyRendering;

@Inject(method = "method_62215", at = @At(value = "TAIL"))
private void animatium$oldBlueVoidSky(Fog fog, DimensionEffects.SkyType skyType, float tickDelta, DimensionEffects dimensionEffects, CallbackInfo ci, @Local MatrixStack matrixStack) {
private void animatium$oldBlueVoidSky(Fog fog, DimensionEffects.SkyType skyType, float tickDelta, DimensionEffects dimensionEffects, CallbackInfo ci, @Local MatrixStack matrices) {
if (AnimatiumConfig.oldBlueVoidSky && skyType != DimensionEffects.SkyType.END) {
assert this.client.player != null;
assert this.world != null;
// can't get it via local, so have to re-get it this way
int skyColor = this.world.getSkyColor(this.client.gameRenderer.getCamera().getPos(), tickDelta);
this.animatium$renderSkyBlueVoid(matrixStack, skyColor, this.client.player.getCameraPosVec(tickDelta).y - animatium$getHorizonHeight(this.world));
this.animatium$renderSkyBlueVoid(matrices, skyColor, this.client.player.getCameraPosVec(tickDelta).y - animatium$getHorizonHeight(this.world));
}
}

Expand All @@ -66,7 +66,7 @@ public abstract class MixinWorldRenderer {
}

@Unique
private void animatium$renderSkyBlueVoid(MatrixStack matrixStack, int skyColor, double depth) {
private void animatium$renderSkyBlueVoid(MatrixStack matrices, int skyColor, double depth) {
// TODO/NOTE: If Statement is a fix for it showing below y 0/-64, supposedly/(not entirely) accurate functionality
if (depth >= 0.0) {
ShaderProgram shaderProgram = RenderSystem.setShader(ShaderProgramKeys.POSITION);
Expand All @@ -79,14 +79,14 @@ public abstract class MixinWorldRenderer {
RenderSystem.setShaderColor(skyColorVec.x, skyColorVec.y, skyColorVec.z, 1.0F);
}

matrixStack.push();
matrixStack.multiplyPositionMatrix(RenderSystem.getModelViewMatrix());
matrixStack.translate(0.0F, -((float) (depth - 16.0)), 0.0F);
matrices.push();
matrices.multiplyPositionMatrix(RenderSystem.getModelViewMatrix());
matrices.translate(0.0F, -((float) (depth - 16.0)), 0.0F);
SkyRenderingAccessor skyRenderingAccessor = (SkyRenderingAccessor) this.skyRendering;
skyRenderingAccessor.getDarkSkyBuffer().bind();
skyRenderingAccessor.getDarkSkyBuffer().draw(matrixStack.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), shaderProgram);
skyRenderingAccessor.getDarkSkyBuffer().draw(matrices.peek().getPositionMatrix(), RenderSystem.getProjectionMatrix(), shaderProgram);
VertexBuffer.unbind();
matrixStack.pop();
matrices.pop();

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import com.google.common.base.MoreObjects;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;

public class HandUtils {
public class PlayerUtils {
public static int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) {
Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND);
Arm arm = hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite();
int i = dispatcher.gameOptions.getPerspective().isFirstPerson() ? 1 : -1;
return arm == Arm.RIGHT ? i : -i;
}

public static Vec3d lerpPlayerWithEyeHeight(PlayerEntity entity, float tickDelta, float eyeHeight) {
double d = MathHelper.lerp(tickDelta, entity.prevX, entity.getX());
double e = MathHelper.lerp(tickDelta, entity.prevY, entity.getY()) + eyeHeight;
double f = MathHelper.lerp(tickDelta, entity.prevZ, entity.getZ());
return new Vec3d(d, e, f);
}
}

0 comments on commit 26314db

Please sign in to comment.