From 7051520607ed1f20c464fb2ad26fad8f9cfce6e1 Mon Sep 17 00:00:00 2001 From: Mixces Date: Thu, 18 Jul 2024 21:03:31 -0500 Subject: [PATCH] minor re-write of code part 2! + Old Item Positions! --- .../legacyanimations/LegacyAnimations.java | 54 +++++++- .../config/LegacyAnimationsSettings.java | 12 ++ .../legacyanimations/hook/GlintModelHook.java | 41 ++++++ .../legacyanimations/hook/TransformHook.java | 15 +++ .../mixin/HeldItemRendererMixin.java | 124 +++++++++++------- .../mixin/ItemRendererMixin.java | 2 +- .../mixin/RenderPhaseMixin.java | 19 +++ .../mixin/ShieldItemMixin.java | 86 ++++++++++++ .../mixin/SwordItemMixin.java | 69 ++++++++++ .../mixin/VertexConsumerMixin.java | 47 +++++++ .../interfaces/BasicBakedModelInterface.java | 19 +++ .../legacyanimations/util/HandUtils.java | 13 +- .../legacyanimations/util/ItemUtils.java | 35 ++++- .../legacyanimations/util/ServerUtils.java | 2 +- .../resources/legacyanimations.accesswidener | 5 +- .../resources/legacyanimations.mixins.json | 4 + 16 files changed, 482 insertions(+), 65 deletions(-) create mode 100644 src/main/java/com/mixces/legacyanimations/hook/GlintModelHook.java create mode 100644 src/main/java/com/mixces/legacyanimations/hook/TransformHook.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/RenderPhaseMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/ShieldItemMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/VertexConsumerMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/interfaces/BasicBakedModelInterface.java diff --git a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java index b884196..c6260ff 100644 --- a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java +++ b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java @@ -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 { @@ -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; + }) + ))))); + }); } } \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java b/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java index a6e868e..8f312d7 100644 --- a/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java +++ b/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java @@ -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; @@ -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")) diff --git a/src/main/java/com/mixces/legacyanimations/hook/GlintModelHook.java b/src/main/java/com/mixces/legacyanimations/hook/GlintModelHook.java new file mode 100644 index 0000000..edbd648 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/hook/GlintModelHook.java @@ -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; +// } +// +// } + +} diff --git a/src/main/java/com/mixces/legacyanimations/hook/TransformHook.java b/src/main/java/com/mixces/legacyanimations/hook/TransformHook.java new file mode 100644 index 0000000..b8e12aa --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/hook/TransformHook.java @@ -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; + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java index 7fc5a67..76f919e 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java @@ -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; @@ -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", @@ -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 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; +// } + } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java index 201c210..ff58f1e 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java @@ -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 diff --git a/src/main/java/com/mixces/legacyanimations/mixin/RenderPhaseMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/RenderPhaseMixin.java new file mode 100644 index 0000000..ccf6ed4 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/RenderPhaseMixin.java @@ -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"); + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ShieldItemMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ShieldItemMixin.java new file mode 100644 index 0000000..89d1905 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/ShieldItemMixin.java @@ -0,0 +1,86 @@ +package com.mixces.legacyanimations.mixin; + +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ShieldItem; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; +import net.minecraft.world.World; +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.CallbackInfoReturnable; + +@Mixin(ShieldItem.class) +public class ShieldItemMixin { + + @Inject( + method = "getUseAction", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + public void legacyAnimations$getUseAction(ItemStack stack, CallbackInfoReturnable cir) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return; + } + + if (!ItemUtils.INSTANCE.isSwordInMainHand()) + { + return; + } + + cir.setReturnValue(UseAction.NONE); + } + + @Inject( + method = "getMaxUseTime", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + public void legacyAnimations$lowerMaxUseTime(ItemStack stack, CallbackInfoReturnable cir) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return; + } + + if (!ItemUtils.INSTANCE.isSwordInMainHand()) + { + return; + } + + cir.setReturnValue(0); + } + + @Inject( + method = "use", + at = @At( + value = "HEAD" + ), + cancellable = true + ) + public void disableUseWithSword(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return; + } + + if (!ItemUtils.INSTANCE.isSwordInMainHand()) + { + return; + } + + cir.setReturnValue(TypedActionResult.pass(user.getStackInHand(hand))); + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java new file mode 100644 index 0000000..8e0c96d --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java @@ -0,0 +1,69 @@ +package com.mixces.legacyanimations.mixin; + +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.*; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.UseAction; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(SwordItem.class) +public class SwordItemMixin extends Item +{ + + public SwordItemMixin(Settings settings) + { + super(settings); + } + + @Override + public UseAction getUseAction(ItemStack stack) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return UseAction.NONE; + } + + if (ItemUtils.INSTANCE.isShieldInOffHand()) + { + return UseAction.BLOCK; + } + return UseAction.NONE; + } + + @Override + public int getMaxUseTime(ItemStack stack) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return 0; + } + + if (ItemUtils.INSTANCE.isShieldInOffHand()) + { + return 72000; + } + return 0; + } + + @Override + public TypedActionResult use(World world, PlayerEntity user, Hand hand) + { + if (!LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) + { + return TypedActionResult.pass(user.getStackInHand(hand)); + } + + if (ItemUtils.INSTANCE.isShieldInOffHand()) + { + ItemStack itemStack = user.getStackInHand(hand); + user.setCurrentHand(hand); + return TypedActionResult.consume(itemStack); + } + return TypedActionResult.pass(user.getStackInHand(hand)); + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/VertexConsumerMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/VertexConsumerMixin.java new file mode 100644 index 0000000..12c2314 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/VertexConsumerMixin.java @@ -0,0 +1,47 @@ +package com.mixces.legacyanimations.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import com.mixces.legacyanimations.util.TransformationModeUtils; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.util.math.Vec3i; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(VertexConsumer.class) +public interface VertexConsumerMixin { + + //todo: maybe there's a better way? + @ModifyArgs( + method = "quad(Lnet/minecraft/client/util/math/MatrixStack$Entry;Lnet/minecraft/client/render/model/BakedQuad;[FFFFF[IIZ)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/util/math/MatrixStack$Entry;transformNormal(FFFLorg/joml/Vector3f;)Lorg/joml/Vector3f;" + ) + ) + default void legacyAnimations$modifyNormal(Args args, @Local(ordinal = 0) Vec3i vec3i) + { + if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) + { + return; + } + + if (TransformationModeUtils.getTransformationMode() != ModelTransformationMode.GROUND) + { + return; + } + + if (ItemUtils.INSTANCE.getModel().hasDepth()) + { + return; + } + + args.set(1, (float) args.get(2)); + args.set(2, (float) args.get(1)); + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/interfaces/BasicBakedModelInterface.java b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/BasicBakedModelInterface.java new file mode 100644 index 0000000..72a4da5 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/interfaces/BasicBakedModelInterface.java @@ -0,0 +1,19 @@ +package com.mixces.legacyanimations.mixin.interfaces; + +import net.minecraft.client.render.model.BasicBakedModel; +import net.minecraft.client.render.model.json.ModelOverrideList; +import net.minecraft.client.render.model.json.ModelTransformation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(BasicBakedModel.Builder.class) +public interface BasicBakedModelInterface { + + @SuppressWarnings("unused") + @Invoker("") + static BasicBakedModel.Builder Builder + (boolean usesAo, boolean isSideLit, boolean hasDepth, ModelTransformation transformation, ModelOverrideList itemPropertyOverrides) { + return null; + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java index 72bd027..4f0743a 100644 --- a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java @@ -14,12 +14,13 @@ public class HandUtils public int handMultiplier(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { - Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); - boolean bl = hand == Hand.MAIN_HAND; - Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite(); - boolean bl2 = arm == Arm.RIGHT; - boolean isFirstPerson = dispatcher.gameOptions.getPerspective().isFirstPerson(); - int perspectiveMultiplier = isFirstPerson ? 1 : -1; + final Hand hand = MoreObjects.firstNonNull(player.preferredHand, Hand.MAIN_HAND); + final boolean bl = hand == Hand.MAIN_HAND; + final Arm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite(); + final boolean bl2 = arm == Arm.RIGHT; + final boolean isFirstPerson = dispatcher.gameOptions.getPerspective().isFirstPerson(); + final int perspectiveMultiplier = isFirstPerson ? 1 : -1; + return bl2 ? perspectiveMultiplier : -perspectiveMultiplier; } diff --git a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java index 93b4313..f166250 100644 --- a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java @@ -8,17 +8,18 @@ import net.minecraft.component.DataComponentTypes; import net.minecraft.item.FishingRodItem; import net.minecraft.item.ItemStack; +import net.minecraft.item.ShieldItem; import net.minecraft.item.SwordItem; import net.minecraft.util.UseAction; +@Setter +@Getter public class ItemUtils { public static ItemUtils INSTANCE = new ItemUtils(); - @Getter - @Setter - private static BakedModel model; + private BakedModel model; public boolean isValidItem(ItemStack heldStack, UseAction action) { @@ -40,9 +41,35 @@ public boolean isValidHeldItem(ItemStack heldStack) return heldStack.getItem() instanceof SwordItem || heldStack.getItem() instanceof FishingRodItem; } + public boolean isSwordInMainHand() { + final ClientPlayerEntity player = MinecraftClient.getInstance().player; + + if (player == null) + { + return false; + } + + return player.getMainHandStack().getItem() instanceof SwordItem; + } + + public boolean isShieldInOffHand() { + final ClientPlayerEntity player = MinecraftClient.getInstance().player; + + if (player == null) + { + return false; + } + + return player.getOffHandStack().getItem() instanceof ShieldItem; + } + public boolean isUsing(ClientPlayerEntity player) { - return ServerUtils.INSTANCE.isOnHypixel() ? MinecraftClient.getInstance().options.useKey.isPressed() : player.isUsingItem(); + if (ServerUtils.INSTANCE.isOnHypixel()) + { + return MinecraftClient.getInstance().options.useKey.isPressed(); + } + return player.isUsingItem(); } } diff --git a/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java b/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java index 4fc030f..e3ed6af 100644 --- a/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java +++ b/src/main/java/com/mixces/legacyanimations/util/ServerUtils.java @@ -8,7 +8,7 @@ public class ServerUtils public static ServerUtils INSTANCE = new ServerUtils(); - public final ServerInfo server = MinecraftClient.getInstance().getCurrentServerEntry(); + private final ServerInfo server = MinecraftClient.getInstance().getCurrentServerEntry(); public boolean isOnHypixel() { diff --git a/src/main/resources/legacyanimations.accesswidener b/src/main/resources/legacyanimations.accesswidener index 9346e0d..cde06d8 100644 --- a/src/main/resources/legacyanimations.accesswidener +++ b/src/main/resources/legacyanimations.accesswidener @@ -1,3 +1,4 @@ -accessWidener v1 named +accessWidener v2 named -accessible class net/minecraft/client/gui/hud/InGameHud$HeartType \ No newline at end of file +accessible class net/minecraft/client/render/model/BasicBakedModel$Builder +accessible class net/minecraft/client/gui/hud/InGameHud$HeartType diff --git a/src/main/resources/legacyanimations.mixins.json b/src/main/resources/legacyanimations.mixins.json index a5f3151..d669171 100644 --- a/src/main/resources/legacyanimations.mixins.json +++ b/src/main/resources/legacyanimations.mixins.json @@ -22,7 +22,11 @@ "MinecraftClientMixin", "PlayerEntityMixin", "PlayerEntityRendererMixin", + "RenderPhaseMixin", + "ShieldItemMixin", + "SwordItemMixin", "VertexConsumerMixin", + "interfaces.BasicBakedModelInterface", "interfaces.CameraInterface", "interfaces.EntityInterface", "interfaces.LivingEntityInterface"