Skip to content

Commit

Permalink
Update various features!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed May 2, 2024
1 parent eccba25 commit 87824da
Show file tree
Hide file tree
Showing 28 changed files with 248 additions and 334 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id 'io.freefair.lombok' version '8.6'
}

version = project.mod_version
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/mixces/legacyanimations/hook/EntityHook.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.sugar.Local;
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.VertexConsumerProvider;
import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ArmorFeatureRenderer.class)
public abstract class ArmorFeatureRendererMixin {
public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extends BipedEntityModel<T>> {

@Redirect(
@Unique public T legacyAnimations$entity;

@Inject(
method = "renderArmor",
at = @At(
value = "HEAD"
)
)
private void legacyAnimations$setEntity(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) {
legacyAnimations$entity = entity;
}

@ModifyArg(
method = "renderArmorParts",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;"
target = "Lnet/minecraft/client/render/VertexConsumerProvider;getBuffer(Lnet/minecraft/client/render/RenderLayer;)Lnet/minecraft/client/render/VertexConsumer;"
)
)
private RenderLayer useEntityLayerRenderer(Identifier texture) {
private RenderLayer legacyAnimations$useEntityLayerRenderer(RenderLayer var1, @Local(ordinal = 0, argsOnly = true) Identifier overlay) {
if (LegacyAnimationsSettings.CONFIG.instance().armorTint) {
return RenderLayer.getEntityCutoutNoCullZOffset(texture);
return RenderLayer.getEntityCutoutNoCullZOffset(overlay);
}
return RenderLayer.getArmorCutoutNoCull(texture);
return var1;
}

@ModifyArg(
Expand All @@ -36,11 +55,16 @@ private RenderLayer useEntityLayerRenderer(Identifier texture) {
),
index = 3
)
private int useDamageUVOverlay(int par3) {
private int legacyAnimations$useDamageUVOverlay(int par3) {
if (LegacyAnimationsSettings.CONFIG.instance().armorTint) {
return OverlayTexture.packUv(OverlayTexture.getU(0.0F), OverlayTexture.getV(EntityHook.isEntityDying()));
return OverlayTexture.packUv(OverlayTexture.getU(0.0F), OverlayTexture.getV(isEntityDying(legacyAnimations$entity)));
}
return par3;
}

@Unique
private boolean isEntityDying(T entity) {
return entity.deathTime > 0 || entity.hurtTime > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ public abstract class BipedEntityModelMixin<T extends LivingEntity> {
@Shadow @Final public ModelPart rightArm;
@Shadow @Final public ModelPart leftArm;
@Shadow @Final public ModelPart head;
@Shadow @Final public ModelPart rightLeg;
@Shadow @Final public ModelPart leftLeg;

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "JUMP",
opcode = Opcodes.IF_ACMPEQ,
ordinal = 0
value = "FIELD",
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;rightArmPose:Lnet/minecraft/client/render/entity/model/BipedEntityModel$ArmPose;",
opcode = Opcodes.GETFIELD,
ordinal = 1
)
)
private void fixIncorrectArmPlacement(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
private void legacyAnimations$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;
Expand All @@ -48,48 +51,105 @@ private void fixIncorrectArmPlacement(T livingEntity, float f, float g, float h,
}
}

@ModifyConstant(
@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
constant = @Constant(
floatValue = 12.2F
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;leftLeg:Lnet/minecraft/client/model/ModelPart;"
),
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;rightLeg:Lnet/minecraft/client/model/ModelPart;",
ordinal = 7
),
to = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;body:Lnet/minecraft/client/model/ModelPart;",
ordinal = 2
)
)
)
private float oldSneakValue1(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 9.0F : constant;
private void legacyAnimations$oldSneakValue1(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
rightLeg.pivotY = 9.0f;
}
}

@ModifyConstant(
@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;head:Lnet/minecraft/client/model/ModelPart;"
),
slice = @Slice(
from = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pitch:F",
ordinal = 15
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;leftLeg:Lnet/minecraft/client/model/ModelPart;",
ordinal = 7
),
to = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F",
ordinal = 6
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;leftArm:Lnet/minecraft/client/model/ModelPart;",
ordinal = 7
)
),
constant = @Constant(
floatValue = 0.0F
)
)
private float oldSneakValue2(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 0.1F : constant;
private void legacyAnimations$oldSneakValue2(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
leftLeg.pivotY = 9.0f;
}
}

@ModifyConstant(
@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
constant = @Constant(
floatValue = 4.2F
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;leftLeg:Lnet/minecraft/client/model/ModelPart;",
ordinal = 9
)
)
private float oldSneakValue3(float constant) {
return LegacyAnimationsSettings.CONFIG.instance().oldSneaking ? 1.0F : constant;
private void legacyAnimations$oldSneakValue3(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
rightLeg.pivotZ = 0.1f;
}
}

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;head:Lnet/minecraft/client/model/ModelPart;",
ordinal = 5
)
)
private void legacyAnimations$oldSneakValue4(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
leftLeg.pivotZ = 0.1f;
}
}

@Inject(
method = "setAngles(Lnet/minecraft/entity/LivingEntity;FFFFF)V",
at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/client/render/entity/model/BipedEntityModel;body:Lnet/minecraft/client/model/ModelPart;",
ordinal = 2
)
)
private void legacyAnimations$oldSneakValue5(T livingEntity, float f, float g, float h, float i, float j, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking) {
head.pivotY = 1.0f;
}
}

@WrapWithCondition(
Expand All @@ -114,7 +174,7 @@ private float oldSneakValue3(float constant) {
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F"
)
)
public boolean removeConflictingFields(ModelPart instance, float value) {
public boolean legacyAnimations$removeConflictingFields1(ModelPart instance, float value) {
return !LegacyAnimationsSettings.CONFIG.instance().oldSneaking;
}

Expand All @@ -140,39 +200,20 @@ public boolean removeConflictingFields(ModelPart instance, float value) {
target = "Lnet/minecraft/client/model/ModelPart;pivotY:F"
)
)
public boolean removeFields2(ModelPart instance, float value) {
public boolean legacyAnimations$removeConflictingFields2(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(
@Inject(
method = "positionBlockingArm",
at = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/model/ModelPart;yaw:F"
value = "TAIL"
)
)
public void oldBlockingArmYaw(ModelPart instance, float value) {
public void legacyAnimations$oldBlockingArm(ModelPart arm, boolean rightArm, CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock) {
instance.yaw = 0.0F;
} else {
instance.yaw = value;
arm.pitch = arm.pitch * 0.5F - (float) (Math.PI / 3);
arm.yaw = 0.0F;
}
}

Expand All @@ -184,7 +225,7 @@ public void oldBlockingArmYaw(ModelPart instance, float value) {
),
index = 0
)
private ModelPart switchBlockingArm(ModelPart arm) {
private ModelPart legacyAnimations$switchBlockingArm1(ModelPart arm) {
return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? rightArm : arm;
}

Expand All @@ -196,7 +237,7 @@ private ModelPart switchBlockingArm(ModelPart arm) {
),
index = 0
)
private ModelPart switchBlockingArm2(ModelPart arm) {
private ModelPart legacyAnimations$switchBlockingArm2(ModelPart arm) {
return LegacyAnimationsSettings.CONFIG.instance().oldSwordBlock ? leftArm : arm;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
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;

Expand All @@ -25,12 +23,9 @@ public class BuiltinModelItemRendererMixin {
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.INSTANCE.isValidItem(heldStack, action))
return false;
private boolean legacyAnimations$disableShieldRendering(boolean original, ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (LegacyAnimationsSettings.CONFIG.instance().hideShields && TransformationModeUtils.isValidPerspective(mode)) {
return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction());
}
return original;
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/mixces/legacyanimations/mixin/CameraMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ public abstract class CameraMixin {
@Shadow private float cameraY;
@Shadow private Entity focusedEntity;

@Inject(method = "updateEyeHeight", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/client/render/Camera;cameraY:F"), cancellable = true)
private void addOldSneakCalculation(CallbackInfo ci) {
@Inject(
method = "updateEyeHeight",
at = @At(
value = "FIELD",
opcode = Opcodes.PUTFIELD,
target = "Lnet/minecraft/client/render/Camera;cameraY:F"
),
cancellable = true
)
private void legacyAnimations$addOldSneakCalculation(CallbackInfo ci) {
if (LegacyAnimationsSettings.CONFIG.instance().oldSneaking && focusedEntity.getStandingEyeHeight() < cameraY) {
cameraY = focusedEntity.getStandingEyeHeight();
ci.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public abstract class ClientPlayerInteractionManagerMixin {
target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isCurrentlyBreaking(Lnet/minecraft/util/math/BlockPos;)Z"
)
)
public boolean fixBreakingBlockCheck(boolean original) {
public boolean legacyAnimations$fixBreakingBlockCheck(boolean original) {
return (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage || isBreakingBlock()) && original;
}

Expand All @@ -38,7 +38,7 @@ public boolean fixBreakingBlockCheck(boolean original) {
shift = At.Shift.AFTER
),
cancellable = true)
public void cancelIllegalDestroy(BlockPos pos, Direction direction, CallbackInfoReturnable<Boolean> cir) {
public void legacyAnimations$cancelIllegalDestroy(BlockPos pos, Direction direction, CallbackInfoReturnable<Boolean> cir) {
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && client.player != null && client.player.isUsingItem()) {
cir.setReturnValue(true);
}
Expand Down
Loading

0 comments on commit 87824da

Please sign in to comment.