Skip to content

Commit

Permalink
some more progress!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 20, 2024
1 parent 5a74465 commit 04403a0
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 86 deletions.
29 changes: 15 additions & 14 deletions src/main/java/com/mixces/legacyanimations/LegacyAnimations.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ public void onInitialize()
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3), false);
return 1;
})
.then(CommandManager.argument("roll", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
final float value2 = FloatArgumentType.getFloat(context, "y");
final float value3 = FloatArgumentType.getFloat(context, "z");
final float value4 = FloatArgumentType.getFloat(context, "roll");
TransformHook.translationX = value;
TransformHook.translationY = value2;
TransformHook.translationZ = value3;
TransformHook.rotationY = value4;
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " roll: " + value4), false);
return 1;
})
)))));
// .then(CommandManager.argument("roll", FloatArgumentType.floatArg())
// .executes(context -> {
// final float value = FloatArgumentType.getFloat(context, "x");
// final float value2 = FloatArgumentType.getFloat(context, "y");
// final float value3 = FloatArgumentType.getFloat(context, "z");
// final float value4 = FloatArgumentType.getFloat(context, "roll");
// TransformHook.translationX = value;
// TransformHook.translationY = value2;
// TransformHook.translationZ = value3;
// TransformHook.rotationY = value4;
// context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2 + " z: " + value3 + " roll: " + value4), false);
// return 1;
// })
// )
))));
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mixces.legacyanimations.duck;

import net.minecraft.util.math.Vec3d;

public interface EntityInterface
{

Vec3d legacyAnimations$getCameraPosVec(float tickDelta, float eyeHeight);

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.mixces.legacyanimations.hook;

import com.mixces.legacyanimations.mixin.interfaces.BasicBakedModelInterface;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BasicBakedModel;
import net.minecraft.client.texture.Sprite;

public class GlintModelHook
{

//todo: hijack model with custom sprite :/
// public static BakedModel getGlint(BakedModel model)
// {
// return (BakedModel) BasicBakedModelInterface.Builder(model.useAmbientOcclusion(), model.isSideLit(), model.hasDepth(), model.getTransformation(), model.getOverrides());
// return (BakedModel) IBasicBakedModelMixin.Builder(model.useAmbientOcclusion(), model.isSideLit(), model.hasDepth(), model.getTransformation(), model.getOverrides());
// }
//
// public static class JustUV extends Sprite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ public abstract class BuiltinModelItemRendererMixin
{

//todo: re-write shields
// @ModifyExpressionValue(
// method = "render",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z",
// ordinal = 0
// )
// )
// private boolean legacyAnimations$disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay)
// {
// if (LegacyAnimationsSettings.CONFIG.instance().hideShields && TransformationModeUtils.isValidPerspective(mode))
// {
// return original;
// }
// return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction());
// }
@ModifyExpressionValue(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z",
ordinal = 0
)
)
private boolean legacyAnimations$disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay)
{
if (!LegacyAnimationsSettings.CONFIG.instance().hideShields || !TransformationModeUtils.isValidPerspective(mode))
{
return original;
}
return ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction());
}

}
22 changes: 21 additions & 1 deletion src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.duck.EntityInterface;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(Entity.class)
public abstract class EntityMixin
public abstract class EntityMixin implements EntityInterface
{

//todo: revert swimming mechanic (double jump to leave)

@Shadow public double prevX;
@Shadow public double prevY;
@Shadow public double prevZ;
@Shadow public abstract double getX();
@Shadow public abstract double getY();
@Shadow public abstract double getZ();

@ModifyReturnValue(
method = "getPose",
at = @At(
Expand All @@ -35,4 +46,13 @@ public abstract class EntityMixin
return original;
}

@Override
public Vec3d legacyAnimations$getCameraPosVec(float tickDelta, float eyeHeight) {
final double d = MathHelper.lerp(tickDelta, prevX, getX());
final double e = MathHelper.lerp(tickDelta, prevY, getY()) + (double) eyeHeight;
final double f = MathHelper.lerp(tickDelta, prevZ, getZ());

return new Vec3d(d, e, f);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.duck.EntityInterface;
import com.mixces.legacyanimations.mixin.interfaces.ICameraMixin;
import com.mixces.legacyanimations.util.HandUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -12,12 +16,11 @@
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.item.Items;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(FishingBobberEntityRenderer.class)
Expand Down Expand Up @@ -54,17 +57,21 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx)
matrixStack.translate(HandUtils.INSTANCE.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F);
}

//todo: cameraVecPos bullshit and left handed rod line
// @Redirect(
// method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/entity/player/PlayerEntity;getStandingEyeHeight()F"
// )
// )
// public float useInterpolatedEyeHeight(PlayerEntity instance) {
// return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((CameraInterface) dispatcher.camera).getLastCameraY(), ((CameraInterface) dispatcher.camera).getCameraY());
// }
@WrapOperation(
method = "getHandPos",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/player/PlayerEntity;getCameraPosVec(F)Lnet/minecraft/util/math/Vec3d;"
)
)
public Vec3d legacyAnimations$useInterpolatedEyeHeight(PlayerEntity instance, float v, Operation<Vec3d> original)
{
final float lastCameraY = ((ICameraMixin) dispatcher.camera).getLastCameraY();
final float cameraY = ((ICameraMixin) dispatcher.camera).getCameraY();
final float eyeHeight = MathHelper.lerp(v, lastCameraY, cameraY);

return ((EntityInterface) instance).legacyAnimations$getCameraPosVec(v, eyeHeight);
}

@ModifyExpressionValue(
method = "getHandPos",
Expand All @@ -73,9 +80,37 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx)
target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z"
)
)
public boolean legacyAnimations$fixWrongRodLine(boolean original, PlayerEntity player, float f, float tickDelta)
public boolean legacyAnimations$removeUselessCondition(boolean original, PlayerEntity player, float f, float tickDelta)
{
return original || !player.getOffHandStack().isOf(Items.FISHING_ROD);
return true;
}

// /**
// * @author a
// * @reason a
// */
// @Overwrite
// private Vec3d getHandPos(PlayerEntity player, float f, float tickDelta)
// {
// final float eyeHeight = MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((ICameraMixin) dispatcher.camera).getLastCameraY(), ((ICameraMixin) dispatcher.camera).getCameraY());
//
// int i = player.getMainArm() == Arm.RIGHT ? 1 : -1;
// if (!this.dispatcher.gameOptions.getPerspective().isFirstPerson() || player != MinecraftClient.getInstance().player)
// {
// float g = MathHelper.lerp(tickDelta, player.prevBodyYaw, player.bodyYaw) * ((float)Math.PI / 180);
// double d = MathHelper.sin(g);
// double e = MathHelper.cos(g);
// float h = player.getScale();
// double j = (double)i * 0.35 * (double)h;
// double k = 0.8 * (double)h;
// float l = player.isInSneakingPose() ? -0.1875f : 0.0f;
// return ((EntityInterface) player).legacyAnimations$getCameraPosVec(tickDelta, eyeHeight).add(-e * j - d * k, (double)l - 0.45 * (double)h, -d * j + e * k);
// }
// double m = 960.0 / (double) this.dispatcher.gameOptions.getFov().getValue();
// Vec3d vec3d = this.dispatcher.camera.getProjection().getPosition((float)i * 0.525f, -0.1F).multiply(m).rotateY(f * 0.5f).rotateX(-f * 0.7f).rotateZ(f * 0.5f).add(TransformHook.translationX, TransformHook.translationY, TransformHook.translationZ);
//// vec3d;
//
// return ((EntityInterface) player).legacyAnimations$getCameraPosVec(tickDelta, eyeHeight).add(vec3d);
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mixces.legacyanimations.mixin;

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.util.ItemUtils;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer;
import net.minecraft.client.render.model.json.ModelTransformationMode;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm;
import net.minecraft.util.math.RotationAxis;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(HeldItemFeatureRenderer.class)
public class HeldItemFeatureRendererMixin {

// @Inject(
// method = "renderItem",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"
// )
// )
// private void legacyAnimations$swordBlockTransform(LivingEntity entity, ItemStack stack, ModelTransformationMode transformationMode, Arm arm, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
// {
// if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
// {
// return;
// }
//
// if (!ItemUtils.INSTANCE.isSwordInMainHand(stack) || !ItemUtils.INSTANCE.isShieldInOffHand(stack))
// {
// return;
// }
//
// matrices.translate(0.05f, 0.0f, -0.1f);
// matrices.multiply(RotationAxis.POSITIVE_Y.rotation(-50.0F));
// matrices.multiply(RotationAxis.POSITIVE_X.rotation(-10.0F));
// matrices.multiply(RotationAxis.POSITIVE_Z.rotation(-60.0F));
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.FishingRodItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
Expand All @@ -36,7 +35,6 @@ public abstract class HeldItemRendererMixin
@Shadow private ItemStack offHand;
@Shadow @Final private EntityRenderDispatcher entityRenderDispatcher;

//todo: unfuck bow position!
@Inject(
method = "renderFirstPersonItem",
at = @At(
Expand All @@ -53,9 +51,8 @@ public abstract class HeldItemRendererMixin

final int l = HandUtils.INSTANCE.handMultiplier((ClientPlayerEntity) player, entityRenderDispatcher);

matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * -335));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * -50.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * -335.0F));
matrices.translate(0.0F, 0.5F, 0.0F);
}

@Inject(
Expand All @@ -75,9 +72,8 @@ public abstract class HeldItemRendererMixin

final int l = HandUtils.INSTANCE.handMultiplier((ClientPlayerEntity) player, entityRenderDispatcher);

matrices.translate(0.0F, -0.5F, 0.0F);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 50.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * 335.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * 335));
}

@Inject(
Expand Down Expand Up @@ -152,12 +148,13 @@ public abstract class HeldItemRendererMixin
return;
}

final int l = HandUtils.INSTANCE.handMultiplier((ClientPlayerEntity) player, entityRenderDispatcher);

if (ItemUtils.INSTANCE.shouldRotateAroundWhenRendering(item, true))
{
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 180.0F));
}

final int l = HandUtils.INSTANCE.handMultiplier((ClientPlayerEntity) player, entityRenderDispatcher);
final float scale = 0.7585F / 0.86F;

matrices.scale(scale, scale, scale);
Expand Down Expand Up @@ -207,7 +204,7 @@ public abstract class HeldItemRendererMixin
// )
// private float legacyAnimations$conditionallyUpdateShield(float value, @Local(ordinal = 0) ItemStack itemStack)
// {
// if (LegacyAnimationsSettings.CONFIG.instance().hideShields && ItemUtils.INSTANCE.isShieldInOffHand())
// if (LegacyAnimationsSettings.CONFIG.instance().hideShields && ItemUtils.INSTANCE.isShieldInOffHand(offHand))
// {
// return (mainHand == itemStack ? 1.0F : 0.0F) - equipProgressOffHand;
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.hook.TransformHook;
import com.mixces.legacyanimations.util.HandUtils;
import com.mixces.legacyanimations.util.ItemUtils;
import com.mixces.legacyanimations.util.TransformationModeUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.BakedModel;
Expand Down Expand Up @@ -67,13 +69,20 @@ public class ItemRendererMixin
return;
}

final ClientPlayerEntity player = client.player;

if (player == null)
{
return;
}

if (ItemUtils.INSTANCE.shouldRotateAroundWhenRendering(stack,true))
{
if (renderMode == ModelTransformationMode.FIRST_PERSON_LEFT_HAND || renderMode == ModelTransformationMode.FIRST_PERSON_RIGHT_HAND)
{
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180.0F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(50.0F));

matrices.translate(0.096F, 0.117F, -0.097F);
//todo: add more translations
}
}
Expand Down
Loading

0 comments on commit 04403a0

Please sign in to comment.