From fce792a3a9006791bc5b288228da93ffca670d98 Mon Sep 17 00:00:00 2001 From: Mixces Date: Sun, 10 Mar 2024 00:02:15 -0600 Subject: [PATCH] More features! --- settings.gradle | 4 +- .../legacyanimations/LegacyAnimations.java | 7 + .../config/LegacyAnimationsSettings.java | 125 ++++++++++------ .../duck/PlayerPitchInterface.java | 9 ++ .../legacyanimations/hook/EntityHook.java | 13 ++ .../mixin/ArmorFeatureRendererMixin.java | 46 ++++++ .../mixin/BipedEntityModelMixin.java | 136 ++++++++++-------- .../mixin/BuiltinModelItemRendererMixin.java | 44 +++--- .../ClientPlayerInteractionManagerMixin.java | 46 +++--- .../legacyanimations/mixin/DebugHudMixin.java | 17 ++- .../legacyanimations/mixin/EntityMixin.java | 10 +- .../mixin/EntityRenderDispatcherMixin.java | 30 ++++ .../FishingBobberEntityRendererMixin.java | 23 +++ .../mixin/FlyingItemEntityRendererMixin.java | 36 ++++- .../mixin/FoodComponentAccessor.java | 12 ++ .../mixin/GameRendererMixin.java | 39 +++++ .../mixin/HeldItemRendererMixin.java | 27 +++- .../mixin/InGameHudMixin.java | 28 +++- .../legacyanimations/mixin/InvokerEntity.java | 15 ++ .../mixin/ItemEntityRendererMixin.java | 61 ++++++++ .../mixin/ItemRendererMixin.java | 72 ++++++++++ .../mixin/LivingEntityInvoker.java | 5 +- .../mixin/LivingEntityMixin.java | 55 ++++++- .../mixin/LivingEntityRendererMixin.java | 6 +- .../mixin/MinecraftClientMixin.java | 84 +++++------ .../mixin/PlayerEntityMixin.java | 54 ++++++- .../mixin/PlayerEntityRendererMixin.java | 20 +++ .../mixin/SwordItemMixin.java | 2 + .../legacyanimations/util/HandUtils.java | 29 ++++ .../legacyanimations/util/ItemUtils.java | 40 ++++++ .../util/TransformationModeUtils.java | 39 +++++ src/main/resources/fabric.mod.json | 3 +- .../resources/legacyanimations.mixins.json | 15 +- 33 files changed, 936 insertions(+), 216 deletions(-) create mode 100644 src/main/java/com/mixces/legacyanimations/duck/PlayerPitchInterface.java create mode 100644 src/main/java/com/mixces/legacyanimations/hook/EntityHook.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/EntityRenderDispatcherMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/FoodComponentAccessor.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java create mode 100644 src/main/java/com/mixces/legacyanimations/util/HandUtils.java create mode 100644 src/main/java/com/mixces/legacyanimations/util/ItemUtils.java create mode 100644 src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java diff --git a/settings.gradle b/settings.gradle index 75c4d72..a40d6ea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,4 +7,6 @@ pluginManagement { mavenCentral() gradlePluginPortal() } -} \ No newline at end of file +} + +rootProject.name = "LegacyAnimations" \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java index db4a5b0..7ed7288 100644 --- a/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java +++ b/src/main/java/com/mixces/legacyanimations/LegacyAnimations.java @@ -2,12 +2,19 @@ import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.client.MinecraftClient; public class LegacyAnimations implements ModInitializer { @Override public void onInitialize() { LegacyAnimationsSettings.CONFIG.load(); + ClientTickEvents.END_WORLD_TICK.register(world -> { + if (MinecraftClient.getInstance().player != null) { + MinecraftClient.getInstance().player.calculateDimensions(); + } + }); } } \ 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 c9bbd80..1f611af 100644 --- a/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java +++ b/src/main/java/com/mixces/legacyanimations/config/LegacyAnimationsSettings.java @@ -20,42 +20,34 @@ public class LegacyAnimationsSettings { .build()) .build(); - @SerialEntry - public boolean punchDuringUsage = 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; - @SerialEntry - public boolean hideShieldHotbar = true; - @SerialEntry - public boolean noCooldown = true; - @SerialEntry - public boolean oldSneaking = true; - @SerialEntry - public boolean oldWalking = true; - @SerialEntry - public boolean oldDeath = true; - @SerialEntry - public boolean oldSwim = true; - @SerialEntry - public boolean oldHearts = true; - @SerialEntry - public boolean oldDebug = true; - @SerialEntry - public boolean perspectiveCrosshair = true; - @SerialEntry - public boolean oldProjectiles = true; + @SerialEntry public boolean punchDuringUsage = 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; + @SerialEntry public boolean hideShieldHotbar = true; + @SerialEntry public boolean noCooldown = true; + @SerialEntry public boolean oldSneaking = true; + @SerialEntry public boolean oldWalking = true; + @SerialEntry public boolean oldDeath = true; + @SerialEntry public boolean oldSwim = true; + @SerialEntry public boolean oldHearts = true; + @SerialEntry public boolean oldDebug = true; + @SerialEntry public boolean perspectiveCrosshair = true; + @SerialEntry public boolean oldProjectiles = true; + @SerialEntry public boolean oldViewBob = true; + @SerialEntry public boolean noDropSwing = true; + @SerialEntry public boolean fastItems = true; + @SerialEntry public boolean armorTint = true; @SuppressWarnings("deprecation") 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("Old Animations")) + .name(Text.literal("Block-Hitting")) + .option(Option.createBuilder(boolean.class) .name(Text.literal("Punching Blocks Whilst Using Items Animation")) .description(OptionDescription.of(Text.of("Brings back the old block-hitting animation to swords/bows/consumable/blocks!"))) @@ -86,18 +78,51 @@ public static Screen configScreen(Screen parent) { .binding(defaults.hideShieldHotbar, () -> config.hideShieldHotbar, newVal -> config.hideShieldHotbar = newVal) .controller(TickBoxControllerBuilder::create) .build()) - .option(Option.createBuilder(boolean.class) - .name(Text.literal("Remove Swing Cooldown Animation")) - .description(OptionDescription.of(Text.of("Visually removes the swing cooldown animation!"))) - .binding(defaults.noCooldown, () -> config.noCooldown, newVal -> config.noCooldown = newVal) - .controller(TickBoxControllerBuilder::create) - .build()) + .build()) + + .category(ConfigCategory.createBuilder() + .name(Text.literal("Sneaking Mechanics")) + .option(Option.createBuilder(boolean.class) .name(Text.literal("Old Sneaking Animation Descent")) .description(OptionDescription.of(Text.of("Makes the descent of the sneaking animation faster than it's ascent."))) .binding(defaults.oldSneaking, () -> config.oldSneaking, newVal -> config.oldSneaking = newVal) .controller(TickBoxControllerBuilder::create) .build()) + .build()) + + .category(ConfigCategory.createBuilder() + .name(Text.literal("GUI Tweaks")) + + .option(Option.createBuilder(boolean.class) + .name(Text.literal("Old Debug Menu")) + .description(OptionDescription.of(Text.of("Removes the background of the F3 menu text and uses text shadow instead."))) + .binding(defaults.oldDebug, () -> config.oldDebug, newVal -> config.oldDebug = newVal) + .controller(TickBoxControllerBuilder::create) + .build()) + .option(Option.createBuilder(boolean.class) + .name(Text.literal("Old Health Flashing")) + .description(OptionDescription.of(Text.of("Brings back the old hotbar health flashing appearance."))) + .binding(defaults.oldHearts, () -> config.oldHearts, newVal -> config.oldHearts = newVal) + .controller(TickBoxControllerBuilder::create) + .build()) + .option(Option.createBuilder(boolean.class) + .name(Text.literal("Third Person Mode Crosshair")) + .description(OptionDescription.of(Text.of("Brings back the crosshair in third person mode."))) + .binding(defaults.perspectiveCrosshair, () -> config.perspectiveCrosshair, newVal -> config.perspectiveCrosshair = newVal) + .controller(TickBoxControllerBuilder::create) + .build()) + .build()) + + .category(ConfigCategory.createBuilder() + .name(Text.literal("Entity Animations")) + + .option(Option.createBuilder(boolean.class) + .name(Text.literal("Armor Damage Tint")) + .description(OptionDescription.of(Text.of("Tints the armor while taking damage."))) + .binding(defaults.armorTint, () -> config.armorTint, newVal -> config.armorTint = newVal) + .controller(TickBoxControllerBuilder::create) + .build()) .option(Option.createBuilder(boolean.class) .name(Text.literal("Old Backwards Walking Animation")) .description(OptionDescription.of(Text.of("Reverts the backwards walking animation to it's former glory."))) @@ -116,22 +141,27 @@ public static Screen configScreen(Screen parent) { .binding(defaults.oldSwim, () -> config.oldSwim, newVal -> config.oldSwim = newVal) .controller(TickBoxControllerBuilder::create) .build()) + .build()) + + .category(ConfigCategory.createBuilder() + .name(Text.literal("Miscellaneous")) + .option(Option.createBuilder(boolean.class) - .name(Text.literal("Old Debug Menu")) - .description(OptionDescription.of(Text.of("Removes the background of the F3 menu text and uses text shadow instead."))) - .binding(defaults.oldDebug, () -> config.oldDebug, newVal -> config.oldDebug = newVal) + .name(Text.literal("Remove Swing Cooldown Animation")) + .description(OptionDescription.of(Text.of("Removes the swing animation played when dropping/throwing items!"))) + .binding(defaults.noDropSwing, () -> config.noDropSwing, newVal -> config.noDropSwing = newVal) .controller(TickBoxControllerBuilder::create) .build()) .option(Option.createBuilder(boolean.class) - .name(Text.literal("Old Health Flashing")) - .description(OptionDescription.of(Text.of("Brings back the old hotbar health flashing appearance."))) - .binding(defaults.oldHearts, () -> config.oldHearts, newVal -> config.oldHearts = newVal) + .name(Text.literal("Remove Swing Animation on Throwing Items")) + .description(OptionDescription.of(Text.of("Visually removes the swing cooldown animation!"))) + .binding(defaults.noCooldown, () -> config.noCooldown, newVal -> config.noCooldown = newVal) .controller(TickBoxControllerBuilder::create) .build()) .option(Option.createBuilder(boolean.class) - .name(Text.literal("Third Person Mode Crosshair")) - .description(OptionDescription.of(Text.of("Brings back the crosshair in third person mode."))) - .binding(defaults.perspectiveCrosshair, () -> config.perspectiveCrosshair, newVal -> config.perspectiveCrosshair = newVal) + .name(Text.literal("Old View Bobbing")) + .description(OptionDescription.of(Text.of("Changes the held item's position while moving based on the player's yaw"))) + .binding(defaults.oldViewBob, () -> config.oldViewBob, newVal -> config.oldViewBob = newVal) .controller(TickBoxControllerBuilder::create) .build()) .option(Option.createBuilder(boolean.class) @@ -140,7 +170,14 @@ public static Screen configScreen(Screen parent) { .binding(defaults.oldProjectiles, () -> config.oldProjectiles, newVal -> config.oldProjectiles = newVal) .controller(TickBoxControllerBuilder::create) .build()) + .option(Option.createBuilder(boolean.class) + .name(Text.literal("Fast/2D Items")) + .description(OptionDescription.of(Text.of("Reverts the projectile's positions back to the older style."))) + .binding(defaults.fastItems, () -> config.fastItems, newVal -> config.fastItems = newVal) + .controller(TickBoxControllerBuilder::create) + .build()) .build()) + )).generateScreen(parent); } diff --git a/src/main/java/com/mixces/legacyanimations/duck/PlayerPitchInterface.java b/src/main/java/com/mixces/legacyanimations/duck/PlayerPitchInterface.java new file mode 100644 index 0000000..66037af --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/duck/PlayerPitchInterface.java @@ -0,0 +1,9 @@ +package com.mixces.legacyanimations.duck; + +public interface PlayerPitchInterface { + + float legacyAnimations$getPrevPlayerPitch(); + + float legacyAnimations$getPlayerPitch(); + +} diff --git a/src/main/java/com/mixces/legacyanimations/hook/EntityHook.java b/src/main/java/com/mixces/legacyanimations/hook/EntityHook.java new file mode 100644 index 0000000..4abc06b --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/hook/EntityHook.java @@ -0,0 +1,13 @@ +package com.mixces.legacyanimations.hook; + +import net.minecraft.entity.LivingEntity; + +public class EntityHook { + + public static LivingEntity entity; + + public static boolean isEntityDying() { + return entity.deathTime > 0 || entity.hurtTime > 0; + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java new file mode 100644 index 0000000..40c6e5e --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/ArmorFeatureRendererMixin.java @@ -0,0 +1,46 @@ +package com.mixces.legacyanimations.mixin; + +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.hook.EntityHook; +import net.minecraft.client.render.OverlayTexture; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ArmorFeatureRenderer.class) +public abstract class ArmorFeatureRendererMixin { + + @Redirect( + method = "renderArmorParts", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;" + ) + ) + private RenderLayer useEntityLayerRenderer(Identifier texture) { + if (LegacyAnimationsSettings.CONFIG.instance().armorTint) { + return RenderLayer.getEntityCutoutNoCullZOffset(texture); + } + return RenderLayer.getArmorCutoutNoCull(texture); + } + + @ModifyArg( + method = "renderArmorParts", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;IIFFFF)V" + ), + index = 3 + ) + private int useDamageUVOverlay(int par3) { + if (LegacyAnimationsSettings.CONFIG.instance().armorTint) { + return OverlayTexture.packUv(OverlayTexture.getU(0.0F), OverlayTexture.getV(EntityHook.isEntityDying())); + } + return par3; + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/BipedEntityModelMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/BipedEntityModelMixin.java index 34b1630..b2a4d86 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/BipedEntityModelMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/BipedEntityModelMixin.java @@ -1,14 +1,10 @@ package com.mixces.legacyanimations.mixin; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.WrapWithCondition; -import com.llamalad7.mixinextras.sugar.Local; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Arm; -import net.minecraft.util.Hand; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -19,45 +15,11 @@ @Mixin(BipedEntityModel.class) public abstract class BipedEntityModelMixin { - @Shadow protected abstract void positionRightArm(T entity); - @Shadow protected abstract void positionLeftArm(T entity); @Shadow public BipedEntityModel.ArmPose leftArmPose; @Shadow public BipedEntityModel.ArmPose rightArmPose; - - @ModifyExpressionValue( - method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/entity/LivingEntity;isUsingItem()Z", - ordinal = 0 - ) - ) - public boolean removeCondition(boolean original) { - return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking && original; - } - - @WrapWithCondition( - method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionRightArm(Lnet/minecraft/entity/LivingEntity;)V" - ) - ) - public boolean removeMethodCall1(BipedEntityModel instance, T entity) { - return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking; - } - - @WrapWithCondition( - method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionLeftArm(Lnet/minecraft/entity/LivingEntity;)V" - ) - ) - public boolean removeMethodCall2(BipedEntityModel instance, T entity) { - return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking; - } - + @Shadow @Final public ModelPart rightArm; + @Shadow @Final public ModelPart leftArm; + @Shadow @Final public ModelPart head; @Inject( method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V", @@ -67,25 +29,21 @@ public boolean removeMethodCall2(BipedEntityModel instance, T entity) { ordinal = 0 ) ) - private void positionRightArm_oldBowSwing(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) { - if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) { - boolean bl3 = livingEntity.getMainArm() == Arm.RIGHT; - if (livingEntity.isUsingItem()) { - boolean bl4 = livingEntity.getActiveHand() == Hand.MAIN_HAND; - if (bl4 == bl3) { - positionRightArm(livingEntity); - } else { - positionLeftArm(livingEntity); - } - } else { - boolean bl4 = bl3 ? leftArmPose.isTwoHanded() : rightArmPose.isTwoHanded(); - if (bl3 != bl4) { - positionLeftArm(livingEntity); - positionRightArm(livingEntity); - } else { - positionRightArm(livingEntity); - positionLeftArm(livingEntity); - } + private void fixIncorrectArmPlacement(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) { + if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) { + rightArm.roll = 0.0F; + leftArm.roll = 0.0F; + if (rightArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW) { + rightArm.yaw = -0.1F + head.yaw; + leftArm.yaw = 0.1F + head.yaw + 0.4F; + rightArm.pitch = (float) (-Math.PI / 2) + head.pitch; + leftArm.pitch = (float) (-Math.PI / 2) + head.pitch; + } + if (leftArmPose == BipedEntityModel.ArmPose.BOW_AND_ARROW) { + rightArm.yaw = -0.1F + head.yaw - 0.4F; + leftArm.yaw = 0.1F + head.yaw; + rightArm.pitch = (float) (-Math.PI / 2) + head.pitch; + leftArm.pitch = (float) (-Math.PI / 2) + head.pitch; } } } @@ -156,7 +114,7 @@ private float oldSneakValue3(float constant) { target = "Lnet/minecraft/client/model/ModelPart;pivotY:F" ) ) - public boolean removeFields1(ModelPart instance, float value) { + public boolean removeConflictingFields(ModelPart instance, float value) { return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking; } @@ -186,4 +144,60 @@ public boolean removeFields2(ModelPart instance, float value) { return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking; } + @Redirect( + method = "positionBlockingArm", + at = @At( + value = "FIELD", + opcode = Opcodes.PUTFIELD, + target = "Lnet/minecraft/client/model/ModelPart;pitch:F" + ) + ) + public void oldBlockingArmPitch(ModelPart instance, float value) { + if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) { + instance.pitch = instance.pitch * 0.5F - (float) (Math.PI / 3); + } else { + instance.pitch = value; + } + } + + @Redirect( + method = "positionBlockingArm", + at = @At( + value = "FIELD", + opcode = Opcodes.PUTFIELD, + target = "Lnet/minecraft/client/model/ModelPart;yaw:F" + ) + ) + public void oldBlockingArmYaw(ModelPart instance, float value) { + if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) { + instance.yaw = 0.0F; + } else { + instance.yaw = value; + } + } + + @ModifyArg( + method = "positionLeftArm", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionBlockingArm(Lnet/minecraft/client/model/ModelPart;Z)V" + ), + index = 0 + ) + private ModelPart switchBlockingArm(ModelPart arm) { + return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? rightArm : arm; + } + + @ModifyArg( + method = "positionRightArm", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;positionBlockingArm(Lnet/minecraft/client/model/ModelPart;Z)V" + ), + index = 0 + ) + private ModelPart switchBlockingArm2(ModelPart arm) { + return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? leftArm : arm; + } + } \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java index 22446e8..f02edd1 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/BuiltinModelItemRendererMixin.java @@ -1,26 +1,38 @@ package com.mixces.legacyanimations.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import com.mixces.legacyanimations.util.TransformationModeUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.item.BuiltinModelItemRenderer; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.util.UseAction; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; @Mixin(BuiltinModelItemRenderer.class) public class BuiltinModelItemRendererMixin { -// @Inject(method = "render", at = @At(value = "HEAD"), cancellable = true) -// private void render_disableShield(ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, CallbackInfo ci) { -// if (LegacyAnimationsSettings.CONFIG.instance().hideShields) { -// if ( -// mode == ModelTransformationMode.FIRST_PERSON_LEFT_HAND || -// mode == ModelTransformationMode.FIRST_PERSON_RIGHT_HAND || -// mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || -// mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND -// ) -// { -// if (stack.isOf(Items.SHIELD)) { -// ci.cancel(); -// } -// } -// } -// } + @ModifyExpressionValue( + method = "render", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z", + ordinal = 0 + ) + ) + private boolean disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { + if (LegacyAnimationsSettings.CONFIG.instance().hideShields && MinecraftClient.getInstance().player != null && TransformationModeUtils.isValidPerspective(mode)) { + ItemStack heldStack = MinecraftClient.getInstance().player.getMainHandStack(); + UseAction action = heldStack.getUseAction(); + if (ItemUtils.isValidItem(heldStack, action)) + return false; + } + return original; + } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java index 35a889d..7ca1d9b 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/ClientPlayerInteractionManagerMixin.java @@ -1,35 +1,47 @@ package com.mixces.legacyanimations.mixin; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerInteractionManager; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(ClientPlayerInteractionManager.class) public abstract class ClientPlayerInteractionManagerMixin { -// @Shadow @Final private MinecraftClient client; -// @Shadow private int blockBreakingCooldown; - + @Shadow @Final private MinecraftClient client; @Shadow public abstract boolean isBreakingBlock(); - @ModifyExpressionValue(method = "updateBlockBreakingProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isCurrentlyBreaking(Lnet/minecraft/util/math/BlockPos;)Z")) + @ModifyExpressionValue( + method = "updateBlockBreakingProgress", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isCurrentlyBreaking(Lnet/minecraft/util/math/BlockPos;)Z" + ) + ) public boolean fixBreakingBlockCheck(boolean original) { - return original && isBreakingBlock(); + return (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage || isBreakingBlock()) && original; } -// @SuppressWarnings("ConstantConditions") -// @Inject(method = "updateBlockBreakingProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;syncSelectedSlot()V", shift = At.Shift.AFTER), cancellable = true) -// public void updateBlockBreakingProgress_cancelDestroy(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { -// if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && client.player.isUsingItem()) { -// cancelBlockBreaking(); -// blockBreakingCooldown = 5; -// cir.setReturnValue(true); -// } -// } - -// @Shadow public abstract void cancelBlockBreaking(); -// @Shadow protected abstract boolean isCurrentlyBreaking(BlockPos pos); + @Inject( + method = "updateBlockBreakingProgress", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;syncSelectedSlot()V", + shift = At.Shift.AFTER + ), + cancellable = true) + public void cancelIllegalDestroy(BlockPos pos, Direction direction, CallbackInfoReturnable cir) { + if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && client.player != null && client.player.isUsingItem()) { + cir.setReturnValue(true); + } + } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/DebugHudMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/DebugHudMixin.java index 024ffbc..8fb32c8 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/DebugHudMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/DebugHudMixin.java @@ -11,12 +11,25 @@ @Mixin(DebugHud.class) public class DebugHudMixin { - @WrapWithCondition(method = "drawText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V")) + @WrapWithCondition( + method = "drawText", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/DrawContext;fill(IIIII)V" + ) + ) private boolean removeDebugBackground(DrawContext instance, int x1, int y1, int x2, int y2, int color) { return !LegacyAnimationsSettings.CONFIG.instance().oldDebug; } - @ModifyArg(method = "drawText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawText(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;IIIZ)I"), index = 5) + @ModifyArg( + method = "drawText", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/DrawContext;drawText(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;IIIZ)I" + ), + index = 5 + ) private boolean addDebugShadow(boolean shadow) { return LegacyAnimationsSettings.CONFIG.instance().oldDebug; } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java index 4767e52..0fe06a3 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java @@ -19,9 +19,15 @@ public class EntityMixin { @Final @Shadow protected DataTracker dataTracker; @Final @Shadow protected static TrackedData POSE; - @ModifyReturnValue(method = "getPose", at = @At("RETURN")) + @ModifyReturnValue( + method = "getPose", + at = @At( + value = "RETURN" + ) + ) public EntityPose revertSwimPose(EntityPose original) { - if (LegacyAnimationsSettings.CONFIG.instance().oldSwim && type == EntityType.PLAYER) { + Entity entity = (Entity) (Object) this; + if (LegacyAnimationsSettings.CONFIG.instance().oldSwim && type == EntityType.PLAYER && entity.isSwimming()) { EntityPose pose = dataTracker.get(POSE); if (pose == EntityPose.SWIMMING) { pose = EntityPose.STANDING; diff --git a/src/main/java/com/mixces/legacyanimations/mixin/EntityRenderDispatcherMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/EntityRenderDispatcherMixin.java new file mode 100644 index 0000000..df21211 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/EntityRenderDispatcherMixin.java @@ -0,0 +1,30 @@ +package com.mixces.legacyanimations.mixin; + +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.hook.EntityHook; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +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(EntityRenderDispatcher.class) +public class EntityRenderDispatcherMixin { + + @Inject( + method = "render", + at = @At( + value = "HEAD" + ) + ) + private void getLivingEntity(E entity, double x, double y, double z, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { + if (LegacyAnimationsSettings.CONFIG.instance().armorTint && entity instanceof LivingEntity) { + EntityHook.entity = (LivingEntity) entity; + } + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java index 4132678..f00460e 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/FishingBobberEntityRendererMixin.java @@ -1,14 +1,22 @@ package com.mixces.legacyanimations.mixin; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.HandUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.FishingBobberEntityRenderer; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.FishingBobberEntity; import net.minecraft.util.math.MathHelper; 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) public abstract class FishingBobberEntityRendererMixin extends EntityRenderer { @@ -17,6 +25,21 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx) { super(ctx); } + @Inject( + 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/client/util/math/MatrixStack;peek()Lnet/minecraft/client/util/math/MatrixStack$Entry;", + ordinal = 0 + ) + ) + public void shiftRodBob(FishingBobberEntity fishingBobberEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci) { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles && player != null) { + matrixStack.translate(HandUtils.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F); + } + } + @Redirect( method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At( diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java index bb82257..fca4a3d 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/FlyingItemEntityRendererMixin.java @@ -3,18 +3,28 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.HandUtils; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.FlyingItemEntityRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; +import net.minecraft.entity.FlyingItemEntity; import org.objectweb.asm.Opcodes; 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.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(FlyingItemEntityRenderer.class) -public class FlyingItemEntityRendererMixin { +public abstract class FlyingItemEntityRendererMixin extends EntityRenderer { + + protected FlyingItemEntityRendererMixin(EntityRendererFactory.Context ctx) { + super(ctx); + } @WrapOperation( method = "render", @@ -25,7 +35,7 @@ public class FlyingItemEntityRendererMixin { ) ) public int disableCleanView(Entity instance, Operation original) { - return LegacyAnimationsSettings.CONFIG.instance().oldProjectiles ? 2 : original.call(instance); + return LegacyAnimationsSettings.CONFIG.instance().oldProjectiles ? original.call(instance) + 2 : original.call(instance); } @Inject( @@ -37,8 +47,28 @@ public int disableCleanView(Entity instance, Operation original) { ) public void shiftProjectile(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) { if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles) { - matrices.translate(0.25F, 0.0F, 0.0F); + matrices.translate((!dispatcher.gameOptions.getPerspective().isFrontView() ? 1 : -1) * 0.25F, 0.0F, 0.0F); + } + } + + @ModifyArg( + method = "render", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/math/RotationAxis;rotationDegrees(F)Lorg/joml/Quaternionf;" + ), + index = 0 + ) + private float rotateProjectileAccordingly(float deg) { + if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles && MinecraftClient.getInstance().player != null) { + boolean isLeftHand = HandUtils.isLeftHand(MinecraftClient.getInstance().player, dispatcher); + if (!dispatcher.gameOptions.getPerspective().isFrontView()) { + return isLeftHand ? deg - 180.0F : deg; + } else { + return isLeftHand ? deg : deg - 180.0F; + } } + return deg; } } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/FoodComponentAccessor.java b/src/main/java/com/mixces/legacyanimations/mixin/FoodComponentAccessor.java new file mode 100644 index 0000000..0869353 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/FoodComponentAccessor.java @@ -0,0 +1,12 @@ +package com.mixces.legacyanimations.mixin; + +import net.minecraft.item.FoodComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(FoodComponent.class) +public interface FoodComponentAccessor { + + @Accessor boolean getAlwaysEdible(); + +} \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java new file mode 100644 index 0000000..c326d09 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/GameRendererMixin.java @@ -0,0 +1,39 @@ +package com.mixces.legacyanimations.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.duck.PlayerPitchInterface; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.MathHelper; +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(GameRenderer.class) +public class GameRendererMixin { + + @Inject( + method = "bobView", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V", + ordinal = 1, + shift = At.Shift.AFTER + ) + ) + private void addOldPitchRotation(MatrixStack matrices, float tickDelta, CallbackInfo ci, @Local(ordinal = 0) PlayerEntity playerEntity) { + if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) { + float h = MathHelper.lerp( + tickDelta, + ((PlayerPitchInterface) playerEntity).legacyAnimations$getPrevPlayerPitch(), + ((PlayerPitchInterface) playerEntity).legacyAnimations$getPlayerPitch() + ); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(h)); + } + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java index 3beee04..7cb9e8d 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/HeldItemRendererMixin.java @@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Slice; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -23,6 +24,8 @@ public abstract class HeldItemRendererMixin { @Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress); + @Shadow private float equipProgressOffHand; + @Shadow private ItemStack mainHand; @Inject( method = "renderFirstPersonItem", @@ -30,8 +33,7 @@ public abstract class HeldItemRendererMixin { value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyEquipOffset(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/Arm;F)V", shift = At.Shift.AFTER - ) - , + ), slice = @Slice( from = @At( value = "INVOKE", @@ -43,8 +45,7 @@ public abstract class HeldItemRendererMixin { ) ) ) - private void 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) { + private void 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) { applySwingOffset(matrices, arm, swingProgress); } @@ -70,10 +71,26 @@ public float removeCoolDownSpeed(ClientPlayerEntity instance, float v, Operation } // @Inject(method = "resetEquipProgress", at = @At("HEAD"), cancellable = true) -// private void resetEquipProgress_removeDelay(Hand hand, CallbackInfo ci) { +// private void removeStartDelay(Hand hand, CallbackInfo ci) { // if (LegacyAnimationsSettings.CONFIG.instance().noCooldown) { // ci.cancel(); // } // } + @ModifyArg( + method = "updateHeldItems", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/math/MathHelper;clamp(FFF)F", + ordinal = 3 + ), + index = 0 + ) + private float conditionallyUpdateShield(float value, @Local(ordinal = 0) ItemStack itemStack) { + if (LegacyAnimationsSettings.CONFIG.instance().hideShields) { + return (mainHand == itemStack ? 1.0F : 0.0F) - equipProgressOffHand; + } + return value; + } + } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java index bf59212..f8affd1 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java @@ -2,21 +2,35 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.WrapWithCondition; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.UseAction; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.At; @Mixin(InGameHud.class) public abstract class InGameHudMixin { -// @WrapOperation(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) -// private boolean cancelOffhandHotbar(ItemStack itemStack, Operation original) { -// ClientPlayerEntity player = MinecraftClient.getInstance().player; -// assert player != null; -// return original.call(itemStack) || LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && player.getOffHandStack().isOf(Items.SHIELD); -// } + @WrapOperation(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z")) + private boolean cancelOffhandHotbar(ItemStack itemStack, Operation original) { + ClientPlayerEntity player = MinecraftClient.getInstance().player; + if (player != null) { + ItemStack stack = player.getMainHandStack(); + UseAction action = stack.getUseAction(); + if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.isValidItem(stack, action)) { + return original.call(itemStack) || player.getOffHandStack().isOf(Items.SHIELD); + } + } + return original.call(itemStack); + } @WrapWithCondition( method = "renderHealthBar", diff --git a/src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java b/src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java new file mode 100644 index 0000000..10430f3 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/InvokerEntity.java @@ -0,0 +1,15 @@ +package com.mixces.legacyanimations.mixin; + +import net.minecraft.entity.Entity; +import net.minecraft.util.math.Vec3d; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(Entity.class) +public interface InvokerEntity { + + @Invoker Vec3d invokeGetVelocity(); + + @Invoker boolean invokeIsOnGround(); + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java new file mode 100644 index 0000000..b4fe4b8 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemEntityRendererMixin.java @@ -0,0 +1,61 @@ +package com.mixces.legacyanimations.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.HandUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.render.entity.ItemEntityRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.ItemEntity; +import net.minecraft.util.math.RotationAxis; +import org.joml.Quaternionf; +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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ItemEntityRenderer.class) +public abstract class ItemEntityRendererMixin extends EntityRenderer { + + protected ItemEntityRendererMixin(EntityRendererFactory.Context ctx) { + super(ctx); + } + + @ModifyArg( + method = "render(Lnet/minecraft/entity/ItemEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V" + ) + ) + private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boolean bl) { + return LegacyAnimationsSettings.CONFIG.instance().fastItems && !bl ? dispatcher.getRotation() : quaternion; + } + + @Inject( + method = "render(Lnet/minecraft/entity/ItemEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V", + shift = At.Shift.AFTER + ) + ) + private void rotateItemAccordingly(ItemEntity itemEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, CallbackInfo ci, @Local(ordinal = 0) boolean bl) { + if (LegacyAnimationsSettings.CONFIG.instance().fastItems && MinecraftClient.getInstance().player != null && !bl) { + if (dispatcher.gameOptions.getPerspective().isFrontView()) { + if (HandUtils.isLeftHand(MinecraftClient.getInstance().player, dispatcher)) { + matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); + } + } else { + if (HandUtils.isRightHand(MinecraftClient.getInstance().player, dispatcher)) { + matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180)); + } + } + } + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java new file mode 100644 index 0000000..3f96777 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/mixin/ItemRendererMixin.java @@ -0,0 +1,72 @@ +package com.mixces.legacyanimations.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.HandUtils; +import com.mixces.legacyanimations.util.TransformationModeUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.BakedQuad; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Direction; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +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; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; +import java.util.stream.Collectors; + +@Mixin(ItemRenderer.class) +public class ItemRendererMixin { + + @Shadow @Final private MinecraftClient client; + + @ModifyArg(method = "renderBakedItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;renderBakedItemQuads(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;Ljava/util/List;Lnet/minecraft/item/ItemStack;II)V", ordinal = 1), index = 2) + private List changeToSprite(List quads, @Local(ordinal = 0) BakedModel model) { + if (LegacyAnimationsSettings.CONFIG.instance().fastItems && client.player != null && TransformationModeUtils.shouldBeSprite() && !model.hasDepth()) { + boolean isLeftHand = HandUtils.isLeftHand(client.player, client.getEntityRenderDispatcher()); + boolean isFrontView = client.getEntityRenderDispatcher().gameOptions.getPerspective().isFrontView(); + Direction perspectiveFace = legacyAnimations$determineDirection(isFrontView, isLeftHand); + if (TransformationModeUtils.getTransformationMode() == ModelTransformationMode.GROUND) { + return legacyAnimations$filterQuadsByDirection(quads, perspectiveFace); + } + return legacyAnimations$filterQuadsByDirection(quads, Direction.SOUTH); + } + return quads; + } + + @Inject( + method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", + at = @At( + value = "HEAD" + ) + ) + private void getTransformationMode(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { + if (LegacyAnimationsSettings.CONFIG.instance().fastItems) { + TransformationModeUtils.transformationMode = renderMode; + } + } + + @Unique + private static Direction legacyAnimations$determineDirection(boolean isFrontView, boolean isLeftHand) { + if (isFrontView) { + return isLeftHand ? Direction.SOUTH : Direction.NORTH; + } + return isLeftHand ? Direction.NORTH : Direction.SOUTH; + } + + @Unique + private static List legacyAnimations$filterQuadsByDirection(List quads, Direction face) { + return quads.stream().filter(baked -> baked.getFace() == face).collect(Collectors.toList()); + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java index 3c7596a..b754efb 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityInvoker.java @@ -7,7 +7,8 @@ @Mixin(LivingEntity.class) public interface LivingEntityInvoker { - @Invoker("getHandSwingDuration") - int getHandSwing(); + @Invoker int invokeGetHandSwingDuration(); + + @Invoker float invokeGetHealth(); } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java index 0369de8..4ae5cb4 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityMixin.java @@ -1,13 +1,19 @@ package com.mixces.legacyanimations.mixin; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.duck.PlayerPitchInterface; import net.minecraft.entity.LivingEntity; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.*; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(LivingEntity.class) -public abstract class LivingEntityMixin { +public abstract class LivingEntityMixin implements PlayerPitchInterface { + + @Unique public float legacyAnimations$prevCameraPitch; + @Unique public float legacyAnimations$cameraPitch; // @ModifyConstant(method = "isBlocking", constant = @Constant(intValue = 5)) // private int isBlocking_fixSync(int constant) { @@ -17,11 +23,52 @@ public abstract class LivingEntityMixin { // return constant; // } - @ModifyConstant(method = "tick", constant = @Constant(floatValue = 180.0f, ordinal = 0)) + @ModifyConstant( + method = "tick", + constant = @Constant( + floatValue = 180.0f + ), + slice = @Slice( + from = @At( + value = "INVOKE", + target = "Lnet/minecraft/util/math/MathHelper;abs(F)F" + ), + to = @At( + value = "FIELD", + opcode = Opcodes.GETFIELD, + target = "Lnet/minecraft/entity/LivingEntity;handSwingProgress:F" + ) + ) + ) private float revertBackwardsWalk(float constant) { if (LegacyAnimationsSettings.CONFIG.instance().oldWalking) return 0.0F; return constant; } + @Inject( + method = "baseTick", + at = @At( + value = "FIELD", + opcode = Opcodes.GETFIELD, + target = "Lnet/minecraft/entity/LivingEntity;hurtTime:I", + ordinal = 0 + ) + ) + private void setPrevCameraPitch(CallbackInfo ci) { + if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) { + legacyAnimations$prevCameraPitch = legacyAnimations$cameraPitch; + } + } + + @Override + public float legacyAnimations$getPrevPlayerPitch() { + return legacyAnimations$prevCameraPitch; + } + + @Override + public float legacyAnimations$getPlayerPitch() { + return legacyAnimations$cameraPitch; + } + } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java index f2c2fe5..4dc5e5a 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/LivingEntityRendererMixin.java @@ -3,9 +3,9 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.Camera; -import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.*; import net.minecraft.client.render.entity.LivingEntityRenderer; +import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(LivingEntityRenderer.class) -public abstract class LivingEntityRendererMixin { +public abstract class LivingEntityRendererMixin> { @ModifyExpressionValue( method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", diff --git a/src/main/java/com/mixces/legacyanimations/mixin/MinecraftClientMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/MinecraftClientMixin.java index 77dc9a4..a35fd0a 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/MinecraftClientMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/MinecraftClientMixin.java @@ -4,58 +4,62 @@ import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.client.particle.ParticleManager; -import net.minecraft.client.render.RenderTickCounter; -import net.minecraft.client.world.ClientWorld; import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +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.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(MinecraftClient.class) public class MinecraftClientMixin { - @Shadow public ClientPlayerInteractionManager interactionManager; - @Shadow public HitResult crosshairTarget; - @Shadow public ClientWorld world; - @Shadow @Final public ParticleManager particleManager; - @Shadow public ClientPlayerEntity player; + @ModifyExpressionValue( + method = "doItemUse", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z" + ) + ) + private boolean interruptBlockBreaking(boolean original) { + return !LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && original; + } - @Inject(method = "handleBlockBreaking", at = @At("HEAD")) - public void handleBlockBreaking_blockHitAnimation(boolean breaking, CallbackInfo ci) { - if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && player.isUsingItem()) { - interactionManager.cancelBlockBreaking(); - if (breaking && crosshairTarget != null && crosshairTarget.getType() == HitResult.Type.BLOCK) { - Hand hand = player.preferredHand; - BlockHitResult blockHitResult = (BlockHitResult) crosshairTarget; - Direction direction = blockHitResult.getSide(); - BlockPos blockPos = blockHitResult.getBlockPos(); - if (!world.getBlockState(blockPos).isAir()) { - particleManager.addBlockBreakingParticles(blockPos, direction); - if (!player.handSwinging || player.handSwingTicks >= ((LivingEntityInvoker) player).getHandSwing() / 2 || - player.handSwingTicks < 0) { - player.handSwingTicks = -1; - player.handSwinging = true; - player.preferredHand = hand; - } - } - } + @Redirect( + method = "handleBlockBreaking", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z" + ) + ) + private boolean allowWhileUsingItem(ClientPlayerEntity instance) { + if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage) { + return !instance.canModifyBlocks(); } + return instance.isUsingItem(); } - @Shadow @Final private RenderTickCounter renderTickCounter; + @Redirect( + method = "handleBlockBreaking", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V" + ) + ) + private void swapForFakeSwing(ClientPlayerEntity instance, Hand hand) { + if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && instance.isUsingItem()) { + legacyAnimations$fakeSwingHand(instance, hand); + } else { + instance.swingHand(hand); + } + } - @ModifyExpressionValue(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z")) - private boolean interruptBlockBreaking(boolean original) { - return !LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && original; + @Unique + private static void legacyAnimations$fakeSwingHand(ClientPlayerEntity player, Hand hand) { + if (!player.handSwinging || player.handSwingTicks >= ((LivingEntityInvoker) player).invokeGetHandSwingDuration() / 2 || player.handSwingTicks < 0) { + player.handSwingTicks = -1; + player.handSwinging = true; + player.preferredHand = hand; + } } } \ No newline at end of file diff --git a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java index 6e3435e..82cf0ae 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityMixin.java @@ -2,17 +2,24 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.mixces.legacyanimations.config.LegacyAnimationsSettings; +import com.mixces.legacyanimations.util.ItemUtils; +import net.minecraft.block.SlabBlock; +import net.minecraft.block.StairsBlock; import net.minecraft.entity.player.PlayerEntity; +import org.objectweb.asm.Opcodes; 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(PlayerEntity.class) -public abstract class PlayerEntityMixin { +public abstract class PlayerEntityMixin extends LivingEntityMixin { // @Inject(method = "resetLastAttackedTicks", at = @At("HEAD"), cancellable = true) // private void resetLastAttackedTicks_removeDelay(CallbackInfo ci) { // ci.cancel(); // } + @ModifyReturnValue( method = "getActiveEyeHeight", at = @At( @@ -20,8 +27,49 @@ public abstract class PlayerEntityMixin { ordinal = 1 ) ) - private float increaseEyeHeight(float constant) { - return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 1.54F : constant; + private float modifyEyeHeight(float constant) { + if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) { + if (ItemUtils.getBlock(0, 1, 0) instanceof SlabBlock || ItemUtils.getBlock(0, 1, 0) instanceof StairsBlock) { + return constant; + } else { + return constant + 0.27F; + } + } + return constant; + } + + @Inject( + method = "tickMovement", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/player/PlayerEntity;strideDistance:F", + opcode = Opcodes.PUTFIELD, + shift = At.Shift.AFTER + ) + ) + private void getPitchFromVelocity(CallbackInfo ci) { + if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob) { + PlayerEntity entity = (PlayerEntity) (Object) this; + double velocityY = ((InvokerEntity) entity).invokeGetVelocity().y; + float f1 = (float) (Math.atan(-velocityY * 0.2F) * 15.0F); + if (((InvokerEntity) entity).invokeIsOnGround() || ((LivingEntityInvoker) entity).invokeGetHealth() <= 0.0F) { + f1 = 0.0F; + } + legacyAnimations$cameraPitch += (f1 - legacyAnimations$cameraPitch) * 0.8F; + } } +// @Redirect( +// method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", +// at = @At( +// value = "INVOKE", +// target = "Lnet/minecraft/entity/player/PlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V" +// ) +// ) +// private void removeSwingAnimation2(PlayerEntity instance, Hand hand) { +// if (!LegacyAnimationsSettings.CONFIG.instance().noDropSwing) { +// instance.swingHand(hand); +// } +// } + } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java index bede18f..4ba065f 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/PlayerEntityRendererMixin.java @@ -1,7 +1,13 @@ package com.mixces.legacyanimations.mixin; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; +import com.mixces.legacyanimations.config.LegacyAnimationsSettings; import net.minecraft.client.render.entity.PlayerEntityRenderer; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; @Mixin(PlayerEntityRenderer.class) public class PlayerEntityRendererMixin { @@ -13,4 +19,18 @@ public class PlayerEntityRendererMixin { // } // } +// @ModifyExpressionValue( +// method = "getArmPose", +// at = @At( +// value = "INVOKE", +// target = "Lnet/minecraft/item/ItemStack;isEmpty()Z" +// ) +// ) +// private static boolean removeBlockArm(boolean original, @Local(ordinal = 0) ItemStack itemStack) { +// if (LegacyAnimationsSettings.CONFIG.instance().hideShields) { +// return original || itemStack.isOf(Items.SHIELD); +// } +// return original; +// } + } diff --git a/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java b/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java index 82c42c9..92ba9e3 100644 --- a/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java +++ b/src/main/java/com/mixces/legacyanimations/mixin/SwordItemMixin.java @@ -1,7 +1,9 @@ package com.mixces.legacyanimations.mixin; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraft.item.SwordItem; +import net.minecraft.util.UseAction; import org.spongepowered.asm.mixin.Mixin; @Mixin(SwordItem.class) diff --git a/src/main/java/com/mixces/legacyanimations/util/HandUtils.java b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java new file mode 100644 index 0000000..22d51d1 --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/util/HandUtils.java @@ -0,0 +1,29 @@ +package com.mixces.legacyanimations.util; + +import com.google.common.base.MoreObjects; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.util.Arm; +import net.minecraft.util.Hand; + +public class HandUtils { + + public static 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; + return bl2 ? perspectiveMultiplier : -perspectiveMultiplier; + } + + public static boolean isLeftHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { + return handMultiplier(player, dispatcher) == -1; + } + + public static boolean isRightHand(ClientPlayerEntity player, EntityRenderDispatcher dispatcher) { + return handMultiplier(player, dispatcher) == 1; + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java new file mode 100644 index 0000000..e0abd9c --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/util/ItemUtils.java @@ -0,0 +1,40 @@ +package com.mixces.legacyanimations.util; + +import com.mixces.legacyanimations.mixin.FoodComponentAccessor; +import net.minecraft.block.Block; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.world.ClientWorld; +import net.minecraft.item.FishingRodItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.SwordItem; +import net.minecraft.util.UseAction; +import net.minecraft.util.math.BlockPos; + +public class ItemUtils { + + public static boolean isValidItem(ItemStack heldStack, UseAction action) { + if (isValidHeldItem(heldStack) || + (action == UseAction.EAT && heldStack.getItem().getFoodComponent() != null && + ((FoodComponentAccessor) heldStack.getItem().getFoodComponent()).getAlwaysEdible())) { + return true; + } else if (action != UseAction.EAT) { + return action != UseAction.NONE; + } + return false; + } + + public static boolean isValidHeldItem(ItemStack heldStack) { + return heldStack.getItem() instanceof SwordItem || heldStack.getItem() instanceof FishingRodItem; + } + + public static Block getBlock(int x, int y, int z) { + ClientWorld world = MinecraftClient.getInstance().world; + ClientPlayerEntity player = MinecraftClient.getInstance().player; + if (player != null && MinecraftClient.getInstance().world != null) { + return world.getBlockState(new BlockPos(player.getBlockPos().getX() + x, player.getBlockPos().getY() + y, player.getBlockPos().getZ() + z)).getBlock(); + } + return null; + } + +} diff --git a/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java b/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java new file mode 100644 index 0000000..8d718ed --- /dev/null +++ b/src/main/java/com/mixces/legacyanimations/util/TransformationModeUtils.java @@ -0,0 +1,39 @@ +package com.mixces.legacyanimations.util; + +import net.minecraft.client.render.model.json.ModelTransformationMode; + +import java.util.EnumSet; + +public class TransformationModeUtils { + + public static ModelTransformationMode transformationMode; + private static final EnumSet cameraTypes = + EnumSet.of( + ModelTransformationMode.GROUND, + ModelTransformationMode.FIXED + ); + + public static boolean isValidPerspective(ModelTransformationMode mode) { + return mode == ModelTransformationMode.FIRST_PERSON_LEFT_HAND || + mode == ModelTransformationMode.FIRST_PERSON_RIGHT_HAND || + mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || + mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND; + } + + public static ModelTransformationMode getTransformationMode() { + return transformationMode; + } + + public static boolean shouldBeSprite() { + return shouldNotHaveGlint() || isRenderingInGUI(); + } + + public static boolean isRenderingInGUI() { + return transformationMode == ModelTransformationMode.GUI; + } + + public static boolean shouldNotHaveGlint() { + return cameraTypes.contains(transformationMode); + } + +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 684f9c9..b035472 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,7 +6,8 @@ "description": "Brings back the legacy animations and visuals from versions before 1.9!", "authors": [ "Mixces", - "Microcontrollers" + "Microcontrollers", + "ImToggle" ], "contact": { "homepage": "https://github.com/Mixces", diff --git a/src/main/resources/legacyanimations.mixins.json b/src/main/resources/legacyanimations.mixins.json index 5404fd8..43e8c6e 100644 --- a/src/main/resources/legacyanimations.mixins.json +++ b/src/main/resources/legacyanimations.mixins.json @@ -3,15 +3,24 @@ "package": "com.mixces.legacyanimations.mixin", "compatibilityLevel": "JAVA_17", "client": [ + "AccessorCamera", + "ArmorFeatureRendererMixin", "BipedEntityModelMixin", "BuiltinModelItemRendererMixin", "CameraMixin", "ClientPlayerInteractionManagerMixin", "DebugHudMixin", + "EntityMixin", + "EntityRenderDispatcherMixin", "FishingBobberEntityRendererMixin", "FlyingItemEntityRendererMixin", + "FoodComponentAccessor", + "GameRendererMixin", "HeldItemRendererMixin", "InGameHudMixin", + "InvokerEntity", + "ItemEntityRendererMixin", + "ItemRendererMixin", "LivingEntityInvoker", "LivingEntityMixin", "LivingEntityRendererMixin", @@ -22,9 +31,5 @@ ], "injectors": { "defaultRequire": 1 - }, - "mixins": [ - "AccessorCamera", - "EntityMixin" - ] + } } \ No newline at end of file