Skip to content

Commit

Permalink
minor re-write of code part 2! + Old Item Positions!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 19, 2024
1 parent 77ac79a commit 7051520
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 65 deletions.
54 changes: 52 additions & 2 deletions src/main/java/com/mixces/legacyanimations/LegacyAnimations.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.mixces.legacyanimations;

import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.hook.TransformHook;
import com.mojang.brigadier.arguments.FloatArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.text.Text;

public class LegacyAnimations implements ModInitializer
{
Expand All @@ -21,6 +24,53 @@ public void onInitialize()
//
// MinecraftClient.getInstance().player.calculateDimensions();
// });

CommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess, environment) ->
{
dispatcher.register(CommandManager.literal("legacyanimations")
.then(CommandManager.argument("x", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
TransformHook.translationX = value;
context.getSource().sendFeedback(() -> Text.literal("x: " + value), false);
return 1;
})
.then(CommandManager.argument("y", FloatArgumentType.floatArg())
.executes(context -> {
final float value = FloatArgumentType.getFloat(context, "x");
final float value2 = FloatArgumentType.getFloat(context, "y");
TransformHook.translationX = value;
TransformHook.translationY = value2;
context.getSource().sendFeedback(() -> Text.literal("x: " + value + " y: " + value2), false);
return 1;
})
.then(CommandManager.argument("z", 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");
TransformHook.translationX = value;
TransformHook.translationY = value2;
TransformHook.translationZ = value3;
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;
})
)))));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class LegacyAnimationsSettings {
.build();

@SerialEntry public boolean punchDuringUsage = true;
@SerialEntry public boolean itemPositions = true;
@SerialEntry public boolean oldSwordBlock = true; // TODO: this prevents an item in offhand (e.g., bow) from being used. Also causes to walk slow despite not actually blocking, may trigger ACs
// @SerialEntry public boolean blockWithShieldOnly = true; // this fixes the aforementioned issue by requiring a shield in offhand
@SerialEntry public boolean hideShields = true;
Expand All @@ -46,6 +47,17 @@ public static Screen configScreen(Screen parent) {
return YetAnotherConfigLib.create(CONFIG, ((defaults, config, builder) -> builder
.title(Text.literal("Old Animations"))

.category(ConfigCategory.createBuilder()
.name(Text.literal("Item Positions"))

.option(Option.createBuilder(boolean.class)
.name(Text.literal("Old Item Positions"))
.description(OptionDescription.of(Text.of("Brings back the old item positions!")))
.binding(defaults.itemPositions, () -> config.itemPositions, newVal -> config.itemPositions = newVal)
.controller(TickBoxControllerBuilder::create)
.build())
.build())

.category(ConfigCategory.createBuilder()
.name(Text.literal("Block-Hitting"))

Expand Down
41 changes: 41 additions & 0 deletions src/main/java/com/mixces/legacyanimations/hook/GlintModelHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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());
// }
//
// public static class JustUV extends Sprite
// {
//
// public static final JustUV INSTANCE = new JustUV();
//
// protected JustUV()
// {
// super(null, null, 1, 1, 1, 1);
// }
//
// @Override
// public float getFrameU(float frame)
// {
// return -frame / 16;
// }
//
// @Override
// public float getFrameV(float frame)
// {
// return frame / 16;
// }
//
// }

}
15 changes: 15 additions & 0 deletions src/main/java/com/mixces/legacyanimations/hook/TransformHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mixces.legacyanimations.hook;

public class TransformHook {

public static Float translationX = 0.0F;
public static Float translationY = 0.0F;
public static Float translationZ = 0.0F;
public static Float rotationX = 0.0F;
public static Float rotationY = 0.0F;
public static Float rotationZ = 0.0F;
// public static Float scalingX;
// public static Float scalingY;
// public static Float scalingZ;

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

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.util.ItemUtils;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.item.HeldItemRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ShieldItem;
import net.minecraft.item.SwordItem;
import net.minecraft.util.Arm;
import net.minecraft.util.Hand;
import net.minecraft.util.math.RotationAxis;
Expand All @@ -33,7 +28,6 @@ public abstract class HeldItemRendererMixin
@Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress);
@Shadow private float equipProgressOffHand;
@Shadow private ItemStack mainHand;
@Shadow private ItemStack offHand;

@Inject(
method = "renderFirstPersonItem",
Expand All @@ -55,86 +49,118 @@ public abstract class HeldItemRendererMixin
)
private void legacyAnimations$addSwingOffset(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci, @Local Arm arm)
{
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
{
applySwingOffset(matrices, arm, swingProgress);
return;
}

applySwingOffset(matrices, arm, swingProgress);
}

@Inject(
method = "renderFirstPersonItem",
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",
ordinal = 1
target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyEquipOffset(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/Arm;F)V",
ordinal = 4,
shift = At.Shift.AFTER
)
)
private void legacyAnimations$addSwordBlock(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
private void legacyAnimations$addBlockTranslation(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock && item.getItem() instanceof SwordItem && player.getOffHandStack().getItem() instanceof ShieldItem && ItemUtils.INSTANCE.isUsing((ClientPlayerEntity) player))
if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock)
{
return;
}

if (!ItemUtils.INSTANCE.isSwordInMainHand() || !ItemUtils.INSTANCE.isShieldInOffHand())
{
boolean bl = hand == Hand.MAIN_HAND;
Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
boolean bl2 = arm == Arm.RIGHT;
int l = bl2 ? 1 : -1;
matrices.translate(l * -0.14142136F, 0.08F, 0.14142136F);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 13.365F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * 78.05F));
return;
}

final boolean bl = hand == Hand.MAIN_HAND;
final Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
final boolean bl2 = arm == Arm.RIGHT;
final int l = bl2 ? 1 : -1;

matrices.translate(l * -0.14142136F, 0.08F, 0.14142136F);
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-102.25F));
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 13.365F));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(l * 78.05F));
}

@WrapWithCondition(
@Inject(
method = "renderFirstPersonItem",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/util/math/MatrixStack;translate(FFF)V",
ordinal = 12
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",
ordinal = 1
)
)
private boolean legacyAnimations$disableSwingTranslation(MatrixStack instance, float x, float y, float z, AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light)
private void legacyAnimations$oldItemPositions(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack item, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
{
return !LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock || !(item.getItem() instanceof SwordItem) || !(player.getOffHandStack().getItem() instanceof ShieldItem) || !ItemUtils.INSTANCE.isUsing((ClientPlayerEntity) player);
if (!LegacyAnimationsSettings.CONFIG.instance().itemPositions) {
return;
}

final boolean bl = hand == Hand.MAIN_HAND;
final Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
final boolean bl2 = arm == Arm.RIGHT;
final int l = bl2 ? 1 : -1;

final float scale = 0.7585F / 0.86F;
matrices.scale(scale, scale, scale);
matrices.translate(l * -0.084F, 0.059F, 0.08F);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(l * 5.0F));
}

@WrapOperation(
@ModifyExpressionValue(
method = "updateHeldItems",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/network/ClientPlayerEntity;getAttackCooldownProgress(F)F"
)
)
public float legacyAnimations$removeCoolDownSpeed(ClientPlayerEntity instance, float v, Operation<Float> original)
public float legacyAnimations$removeCoolDownSpeed(float original)
{
if (LegacyAnimationsSettings.CONFIG.instance().noCooldown)
return 1.0F;
return original.call(instance, v);
}

@Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true)
private void legacyAnimations$removeStartDelay(Hand hand, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().noCooldown) {
ci.cancel();
if (!LegacyAnimationsSettings.CONFIG.instance().noCooldown) {
return original;
}
return 1.0f;
}

@ModifyArg(
method = "updateHeldItems",
@Inject(
method = "resetEquipProgress",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F",
ordinal = 3
value = "HEAD"
),
index = 0
cancellable = true
)
private float legacyAnimations$conditionallyUpdateShield(float value, @Local(ordinal = 0) ItemStack itemStack)
private void legacyAnimations$removeStartDelay(Hand hand, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().hideShields && offHand.getItem() instanceof ShieldItem)
{
return (mainHand == itemStack ? 1.0F : 0.0F) - equipProgressOffHand;
if (!LegacyAnimationsSettings.CONFIG.instance().noCooldown) {
return;
}
return value;

ci.cancel();
}

// @ModifyArg(
// method = "updateHeldItems",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F",
// ordinal = 3
// ),
// index = 0
// )
// private float legacyAnimations$conditionallyUpdateShield(float value, @Local(ordinal = 0) ItemStack itemStack)
// {
// if (LegacyAnimationsSettings.CONFIG.instance().hideShields && ItemUtils.INSTANCE.isShieldInOffHand())
// {
// return (mainHand == itemStack ? 1.0F : 0.0F) - equipProgressOffHand;
// }
// return value;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ItemRendererMixin
private void legacyAnimations$getTransformationMode(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci)
{
TransformationModeUtils.setTransformationMode(renderMode);
ItemUtils.setModel(model);
ItemUtils.INSTANCE.setModel(model);
}

//todo: unfuck left handed sprites and re-write code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mixces.legacyanimations.mixin;

import net.minecraft.client.render.RenderPhase;
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(RenderPhase.class)
public class RenderPhaseMixin
{

@Inject(method = "setupGlintTexturing", at = @At(value = "HEAD"))
private static void legacyAnimations$injectGlint(float scale, CallbackInfo ci)
{
// System.out.println("glint rendering");
}

}
Loading

0 comments on commit 7051520

Please sign in to comment.