Skip to content

Commit

Permalink
Add cape customization + fix sneaking bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jan 19, 2025
1 parent c0097ef commit 68b1041
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ modmenu_version=13.0.0
yacl_version=3.6.2+1.21.4-fabric

# Mod Properties
mod_version=1.0.0-dev-36
mod_version=1.0.0-dev-37
maven_group=btw.mixces
archives_base_name=animatium
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package btw.mixces.animatium.mixins.model.item;

import btw.mixces.animatium.AnimatiumClient;
import btw.mixces.animatium.config.AnimatiumConfig;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.world.entity.ElytraAnimationState;
import net.minecraft.world.entity.LivingEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ElytraAnimationState.class)
public class MixinElytraAnimationState {
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isCrouching()Z"))
private boolean animatium$sneakAnimationWhileFlying(LivingEntity instance, Operation<Boolean> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getSneakAnimationWhileFlying()) {
return instance.isShiftKeyDown();
} else {
return original.call(instance);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package btw.mixces.animatium.mixins.model.item;

import btw.mixces.animatium.AnimatiumClient;
import btw.mixces.animatium.config.AnimatiumConfig;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.client.model.ElytraModel;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(ElytraModel.class)
public class MixinElytraModel {
@ModifyExpressionValue(method = "setupAnim(Lnet/minecraft/client/renderer/entity/state/HumanoidRenderState;)V", at = @At(value = "CONSTANT", args = "floatValue=3.0"))
private float animatium$fixSneakTranslationWhileFlying(float original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldSneakingFeetPosition()) {
return 0.0F;
} else {
return original;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class MixinIsUsingItem {
if (AnimatiumConfig.instance().getDisableItemUsingTextureInGui() && ItemUtils.isRangedWeaponItem(stack) && displayContext == ItemDisplayContext.GUI) {
return false;
} else if (AnimatiumConfig.instance().getFixItemUseTextureCheck()) {
return livingEntity != null && livingEntity.isUsingItem() && livingEntity.getItemInHand(livingEntity.getUsedItemHand()) == stack;
return livingEntity != null && livingEntity.getUseItem() == stack;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
Expand Down Expand Up @@ -65,8 +66,16 @@ protected MixinFishingHookRenderer(EntityRendererProvider.Context context) {
}

@ModifyExpressionValue(method = "getPlayerHandPos", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isCrouching()Z"))
private boolean animatium$noMoveFishingRodLine(boolean original) {
return (!AnimatiumClient.getEnabled() || !AnimatiumConfig.instance().getNoMoveFishingRodLine()) && original;
private boolean animatium$noMoveFishingRodLine(boolean original, @Local(argsOnly = true) Player player) {
if (AnimatiumClient.getEnabled()) {
if (AnimatiumConfig.instance().getNoMoveFishingRodLine()) {
return false;
} else {
// Use sneak flag check instead of pose check
return player.isShiftKeyDown();
}
}
return original;
}

@ModifyExpressionValue(method = "getPlayerHandPos", at = @At(value = "CONSTANT", args = "doubleValue=0.8"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class MixinHumanoidMobRenderer {
@WrapOperation(method = "extractHumanoidRenderState", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;isCrouching()Z"))
private static boolean animatium$sneakAnimationWhileFlying(LivingEntity instance, Operation<Boolean> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getSneakAnimationWhileFlying()) {
return instance.isCrouching() || instance.isShiftKeyDown();
return instance.isShiftKeyDown();
} else {
return original.call(instance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@

import btw.mixces.animatium.AnimatiumClient;
import btw.mixces.animatium.config.AnimatiumConfig;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.client.renderer.entity.state.PlayerRenderState;
import net.minecraft.util.Mth;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(PlayerRenderer.class)
public abstract class MixinPlayerRenderer {
@WrapOperation(method = "extractCapeState", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;rotLerp(FFF)F"))
private static float animatium$changeLerpMethod(float delta, float start, float end, Operation<Float> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldCapeMovement()) {
return Mth.lerp(delta, start, end);
} else {
return original.call(delta, start, end);
}
}

@ModifyArg(method = "extractCapeState", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;clamp(FFF)F", ordinal = 1), index = 2)
private static float animatium$uncapRotation(float original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldCapeMovement()) {
return Float.MAX_VALUE;
} else {
return original;
}
}

@WrapWithCondition(method = "extractCapeState", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/renderer/entity/state/PlayerRenderState;capeLean:F", ordinal = 1))
private static boolean animatium$dontAssignLeanField(PlayerRenderState instance, float value) {
return !AnimatiumClient.getEnabled() || !AnimatiumConfig.instance().getOldCapeMovement();
}

@WrapWithCondition(method = "extractCapeState", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/renderer/entity/state/PlayerRenderState;capeLean2:F", ordinal = 1))
private static boolean animatium$dontAssignLean2Field(PlayerRenderState instance, float value) {
return !AnimatiumClient.getEnabled() || !AnimatiumConfig.instance().getOldCapeMovement();
}

@WrapOperation(method = "getRenderOffset(Lnet/minecraft/client/renderer/entity/state/PlayerRenderState;)Lnet/minecraft/world/phys/Vec3;", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/state/PlayerRenderState;isCrouching:Z"))
private boolean animatium$fixSneakingFeetPosition(PlayerRenderState instance, Operation<Boolean> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getFixSneakingFeetPosition()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package btw.mixces.animatium.mixins.renderer.entity.layer;

import btw.mixces.animatium.AnimatiumClient;
import btw.mixces.animatium.config.AnimatiumConfig;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.layers.CapeLayer;
import net.minecraft.client.renderer.entity.state.PlayerRenderState;
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.CallbackInfo;

@Mixin(CapeLayer.class)
public abstract class MixinCapeLayer {
@Shadow
@Final
private HumanoidModel<PlayerRenderState> model;

@ModifyExpressionValue(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/layers/CapeLayer;hasLayer(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/client/resources/model/EquipmentClientInfo$LayerType;)Z", ordinal = 1))
private boolean animatium$removeChestplateCheck(boolean original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getCapeChestplateTranslation()) {
return false;
} else {
return original;
}
}

@Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/MultiBufferSource;getBuffer(Lnet/minecraft/client/renderer/RenderType;)Lcom/mojang/blaze3d/vertex/VertexConsumer;"))
private void animatium$capeSneakingOffset(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, PlayerRenderState playerRenderState, float f, float g, CallbackInfo ci) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldCapePosition() && playerRenderState.isCrouching) {
poseStack.translate(0.0F, playerRenderState.scale * 2.0F / 16.0F, 0.0F);
}
}

@Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/client/renderer/entity/state/PlayerRenderState;FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/HumanoidModel;setupAnim(Lnet/minecraft/client/renderer/entity/state/HumanoidRenderState;)V", shift = At.Shift.AFTER))
private void animatium$capeSwingRotation(PoseStack poseStack, MultiBufferSource multiBufferSource, int i, PlayerRenderState playerRenderState, float f, float g, CallbackInfo ci) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getCapeSwingRotation()) {
model.body.yRot = 0;
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/btw/mixces/animatium/AnimatiumClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AnimatiumClient : ClientModInitializer {

// Info
const val VERSION = 1.0
val DEVELOPMENT_VERSION = Optional.ofNullable(36)
val DEVELOPMENT_VERSION = Optional.ofNullable(37)

@JvmStatic
fun getInfoPayload(): AnimatiumInfoPayloadPacket {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class AnimatiumConfig {
@SerialEntry var oldDeathLimbs = true
@SerialEntry var fixBowArmMovement = true
@SerialEntry var oldDamageTilt = true
// (Movement) Cape
@SerialEntry var oldCapeMovement = true
@SerialEntry var capeSwingRotation = true
@SerialEntry var capeChestplateTranslation = true
@SerialEntry var oldCapePosition = false

// (Screen)
@SerialEntry var showCrosshairInThirdperson = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,55 @@ object MovementConfigCategory {
category.group(sneakingGroup.build())
}

run {
val capeGroup = OptionGroup.createBuilder()
capeGroup.name(Component.translatable("animatium.category.movement.group.cape"))
capeGroup.option(
Option.createBuilder<Boolean>()
.name(Component.translatable("animatium.oldCapeMovement"))
.description(OptionDescription.of(Component.translatable("animatium.oldCapeMovement.description")))
.binding(
defaults.oldCapeMovement,
{ config.oldCapeMovement },
{ newVal -> config.oldCapeMovement = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
capeGroup.option(
Option.createBuilder<Boolean>()
.name(Component.translatable("animatium.capeSwingRotation"))
.description(OptionDescription.of(Component.translatable("animatium.capeSwingRotation.description")))
.binding(
defaults.capeSwingRotation,
{ config.capeSwingRotation },
{ newVal -> config.capeSwingRotation = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
capeGroup.option(
Option.createBuilder<Boolean>()
.name(Component.translatable("animatium.capeChestplateTranslation"))
.description(OptionDescription.of(Component.translatable("animatium.capeChestplateTranslation.description")))
.binding(
defaults.capeChestplateTranslation,
{ config.capeChestplateTranslation },
{ newVal -> config.capeChestplateTranslation = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
capeGroup.option(
Option.createBuilder<Boolean>()
.name(Component.translatable("animatium.oldCapePosition"))
.description(OptionDescription.of(Component.translatable("animatium.oldCapePosition.description")))
.binding(
defaults.oldCapePosition,
{ config.oldCapePosition },
{ newVal -> config.oldCapePosition = newVal })
.controller(TickBoxControllerBuilder::create)
.build()
)
category.group(capeGroup.build())
}

// Other
run {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/animatium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"level.item.MixinItem",
"level.item.MixinItemStack",
"model.entity.MixinHumanoidModel",
"model.item.MixinElytraAnimationState",
"model.item.MixinElytraModel",
"model.item.MixinFishingRodCast",
"model.item.MixinIsUsingItem",
"model.item.MixinItemModelResolver",
Expand All @@ -42,6 +44,7 @@
"renderer.entity.MixinItemEntityRenderer",
"renderer.entity.MixinLivingEntityRenderer",
"renderer.entity.MixinPlayerRenderer",
"renderer.entity.layer.MixinCapeLayer",
"renderer.entity.layer.MixinEquipmentLayerRenderer",
"renderer.entity.layer.MixinHumanoidArmorLayer",
"renderer.item.MixinItemFrameRenderer",
Expand Down
17 changes: 13 additions & 4 deletions src/main/resources/assets/animatium/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"animatium.oldSneakAnimationInterpolation.description": "Brings back the <=1.7.x sneaking camera animation interpolation.",
"animatium.fakeOldSneakEyeHeight": "Fake the old sneaking eye height",
"animatium.fakeOldSneakEyeHeight.description": "Changes the sneak eye height to be as it was in <=1.13.2 visually.",
"animatium.fixSneakingFeetPosition": "Fix sneaking model offset (<=1.11)",
"animatium.fixSneakingFeetPosition.description": "Fixes the sneaking model offset to be like <=1.11.x.",
"animatium.oldSneakingFeetPosition": "Bring back the old sneaking feet position",
"animatium.oldSneakingFeetPosition.description": "Fixes the sneaking model offset to be like <1.14?",
"animatium.fixSneakingFeetPosition": "Fix sneaking feet position (<1.14)",
"animatium.fixSneakingFeetPosition.description": "Fixes the sneaking model offset to be like <1.14",
"animatium.oldSneakingFeetPosition": "Bring back old sneaking model offset (<=1.7.x)",
"animatium.oldSneakingFeetPosition.description": "Brings back the sneaking model offset from <=1.7.x.",
"animatium.syncPlayerModelWithEyeHeight": "Synchronize the player model to the eye height",
"animatium.syncPlayerModelWithEyeHeight.description": "Synchronizes the player model to the eye height like in <=1.7.x.",
"animatium.sneakAnimationWhileFlying": "Show the sneaking animation whilst flying in third-person",
Expand All @@ -83,6 +83,15 @@
"animatium.fixBowArmMovement.description": "Restores old player body movement in third-person when using the bow like in <=1.7?",
"animatium.oldDamageTilt": "Bring back old damage tilt logic",
"animatium.oldDamageTilt.description": "Reverts the damage tilt to it's old logic which will tilt in one direction <1.19.4.",
"animatium.category.movement.group.cape": "Cape",
"animatium.oldCapeMovement": "Old cape model movement",
"animatium.oldCapeMovement.description": "Changes the cape model movement to be how it used to be in <=1.12.x.",
"animatium.capeSwingRotation": "Don't move cape while swinging arm",
"animatium.capeSwingRotation.description": "Stops the cape from swinging in unison with the body while the player is swinging their arm like in <=1.20.x.",
"animatium.capeChestplateTranslation": "Don't move cape while chestplate is equipped",
"animatium.capeChestplateTranslation.description": "Stops equipping a chestplate causing the cape to be translated a few pixels away like in <=1.15.x",
"animatium.oldCapePosition": "Old cape sneaking position",
"animatium.oldCapePosition.description": "Positions the cape while sneaking similarly to <=1.7.x",

"animatium.category.screen": "Screen",
"animatium.showCrosshairInThirdperson": "Show crosshair in third-person",
Expand Down

0 comments on commit 68b1041

Please sign in to comment.