Skip to content

Commit

Permalink
armor trim damage tint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 17, 2024
1 parent 6041220 commit 1489560
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.VertexConsumer;
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.texture.Sprite;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
Expand Down Expand Up @@ -51,8 +55,31 @@ public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extend
return RenderLayer.getEntityCutoutNoCullZOffset(overlay);
}

@WrapOperation(
method = "renderTrim",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/texture/Sprite;getTextureSpecificVertexConsumer(Lnet/minecraft/client/render/VertexConsumer;)Lnet/minecraft/client/render/VertexConsumer;"
)
)
private VertexConsumer legacyAnimations$useEntityLayerRenderer2(Sprite instance, VertexConsumer consumer, Operation<VertexConsumer> original, @Local(ordinal = 0, argsOnly = true) VertexConsumerProvider vertexConsumers)
{
if (!LegacyAnimationsSettings.CONFIG.instance().armorTint)
{
return original.call(instance, consumer);
}

if (legacyAnimations$entity.deathTime > 0 || legacyAnimations$entity.hurtTime > 0) {
return instance.getTextureSpecificVertexConsumer(vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCullZOffset(instance.getAtlasId())));
}
return original.call(instance, consumer);
}

@ModifyArg(
method = "renderArmorParts",
method = {
"renderArmorParts",
"renderTrim"
},
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"
Expand All @@ -65,13 +92,10 @@ public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extend
{
return par3;
}
return OverlayTexture.packUv(OverlayTexture.getU(0.0F), OverlayTexture.getV(isEntityDying(legacyAnimations$entity)));
}

@Unique
private boolean isEntityDying(T entity)
{
return entity.deathTime > 0 || entity.hurtTime > 0;
return OverlayTexture.packUv(
OverlayTexture.getU(0.0F),
OverlayTexture.getV(legacyAnimations$entity.deathTime > 0 || legacyAnimations$entity.hurtTime > 0)
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public abstract class BipedEntityModelMixin<T extends LivingEntity>
{

//todo: thorough investigation needed

@Shadow public BipedEntityModel.ArmPose leftArmPose;
@Shadow public BipedEntityModel.ArmPose rightArmPose;
@Shadow @Final public ModelPart rightArm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import org.spongepowered.asm.mixin.injection.At;

@Mixin(BuiltinModelItemRenderer.class)
public class BuiltinModelItemRendererMixin
public abstract class BuiltinModelItemRendererMixin
{

//todo: re-write shields

@ModifyExpressionValue(
method = "render",
at = @At(
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/com/mixces/legacyanimations/mixin/CameraMixin.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mixces.legacyanimations.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import org.objectweb.asm.Opcodes;
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(Camera.class)
public abstract class CameraMixin
Expand All @@ -17,20 +17,28 @@ public abstract class CameraMixin
@Shadow private float cameraY;
@Shadow private Entity focusedEntity;

@Inject(
@WrapOperation(
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)
private void legacyAnimations$addOldSneakCalculation(Camera instance, float value, Operation<Void> original)
{
if (!LegacyAnimationsSettings.CONFIG.instance().oldSneaking)
{
original.call(instance, value);
}

if (focusedEntity.getStandingEyeHeight() < cameraY)
{
cameraY = focusedEntity.getStandingEyeHeight();
ci.cancel();
}
else
{
original.call(instance, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
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.util.math.BlockPos;
import net.minecraft.util.math.Direction;
Expand All @@ -19,6 +20,8 @@ public abstract class ClientPlayerInteractionManagerMixin

@Shadow @Final private MinecraftClient client;
@Shadow public abstract boolean isBreakingBlock();
@Shadow public abstract void cancelBlockBreaking();
@Shadow private float currentBreakingProgress;

@ModifyExpressionValue(
method = "updateBlockBreakingProgress",
Expand All @@ -29,7 +32,11 @@ public abstract class ClientPlayerInteractionManagerMixin
)
public boolean legacyAnimations$fixBreakingBlockCheck(boolean original)
{
return (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage || isBreakingBlock()) && original;
if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
{
return original;
}
return original && isBreakingBlock();
}

@Inject(
Expand All @@ -42,8 +49,25 @@ public abstract class ClientPlayerInteractionManagerMixin
cancellable = true)
public void legacyAnimations$cancelIllegalDestroy(BlockPos pos, Direction direction, CallbackInfoReturnable<Boolean> cir)
{
if (LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage && client.player != null && client.player.isUsingItem())
if (!LegacyAnimationsSettings.CONFIG.instance().punchDuringUsage)
{
return;
}

final ClientPlayerEntity player = MinecraftClient.getInstance().player;

if (player == null)
{
return;
}

if (player.isUsingItem() && player.canModifyBlocks())
{
if (currentBreakingProgress > 0.0f)
{
cancelBlockBreaking();
}

cir.setReturnValue(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(DebugHud.class)
public class DebugHudMixin
public abstract class DebugHudMixin
{

@WrapWithCondition(
Expand Down
27 changes: 11 additions & 16 deletions src/main/java/com/mixces/legacyanimations/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
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;

@Mixin(Entity.class)
public class EntityMixin
public abstract class EntityMixin
{

@Final @Shadow private EntityType<?> type;
@Final @Shadow protected DataTracker dataTracker;
@Final @Shadow protected static TrackedData<EntityPose> POSE;
//todo: revert swimming mechanic

@ModifyReturnValue(
method = "getPose",
Expand All @@ -28,14 +21,16 @@ public class EntityMixin
)
public EntityPose legacyAnimations$revertSwimPose(EntityPose original)
{
Entity entity = (Entity) (Object) this;
if (LegacyAnimationsSettings.CONFIG.instance().oldSwim && type == EntityType.PLAYER && entity.isSwimming())
if (!LegacyAnimationsSettings.CONFIG.instance().oldSwim)
{
EntityPose pose = dataTracker.get(POSE);
if (pose == EntityPose.SWIMMING) {
pose = EntityPose.STANDING;
}
return pose;
return original;
}

final Entity entity = (Entity) (Object) this;

if (entity.isSwimming())
{
return EntityPose.STANDING;
}
return original;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.FishingBobberEntity;
import net.minecraft.item.Items;
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)
Expand All @@ -37,13 +39,22 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx)
)
public void legacyAnimations$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)
if (!LegacyAnimationsSettings.CONFIG.instance().oldProjectiles)
{
matrixStack.translate(HandUtils.INSTANCE.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F);
return;
}

final ClientPlayerEntity player = MinecraftClient.getInstance().player;

if (player == null)
{
return;
}

matrixStack.translate(HandUtils.INSTANCE.handMultiplier(player, dispatcher) * 0.25F, 0.0F, 0.0F);
}

//todo: cameraVecPos bullshit and left handed rod line
// @Redirect(
// method = "render(Lnet/minecraft/entity/projectile/FishingBobberEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V",
// at = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand Down Expand Up @@ -36,9 +37,13 @@ protected FlyingItemEntityRendererMixin(EntityRendererFactory.Context ctx)
target = "Lnet/minecraft/entity/Entity;age:I"
)
)
public int legacyAnimations$disableCleanView(Entity instance, Operation<Integer> original)
public int legacyAnimations$disableDelay(Entity instance, Operation<Integer> original)
{
return LegacyAnimationsSettings.CONFIG.instance().oldProjectiles ? original.call(instance) + 2 : original.call(instance);
if (!LegacyAnimationsSettings.CONFIG.instance().oldProjectiles)
{
return original.call(instance);
}
return original.call(instance) + 2;
}

@Inject(
Expand All @@ -50,12 +55,16 @@ protected FlyingItemEntityRendererMixin(EntityRendererFactory.Context ctx)
)
public void legacyAnimations$shiftProjectile(T entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles)
if (!LegacyAnimationsSettings.CONFIG.instance().oldProjectiles)
{
matrices.translate((!dispatcher.gameOptions.getPerspective().isFrontView() ? 1 : -1) * 0.25F, 0.0F, 0.0F);
return;
}

matrices.translate((!dispatcher.gameOptions.getPerspective().isFrontView() ? 1 : -1) * 0.25F, 0.0F, 0.0F);
}

//todo: shit is missing in left handed mode

@ModifyArg(
method = "render",
at = @At(
Expand All @@ -66,19 +75,28 @@ protected FlyingItemEntityRendererMixin(EntityRendererFactory.Context ctx)
)
private float legacyAnimations$rotateProjectileAccordingly(float deg)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles && MinecraftClient.getInstance().player != null)
if (LegacyAnimationsSettings.CONFIG.instance().oldProjectiles)
{
return deg;
}

final ClientPlayerEntity player = MinecraftClient.getInstance().player;

if (player == null)
{
return deg;
}

final boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher);

if (dispatcher.gameOptions.getPerspective().isFrontView())
{
return isLeftHand ? deg : deg - 180.0F;
}
else
{
boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher);
if (!dispatcher.gameOptions.getPerspective().isFrontView())
{
return isLeftHand ? deg - 180.0F : deg;
}
else
{
return isLeftHand ? deg : deg - 180.0F;
}
return isLeftHand ? deg - 180.0F : deg;
}
return deg;
}

}

0 comments on commit 1489560

Please sign in to comment.