Skip to content

Commit

Permalink
minor re-write of code!
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixces committed Jul 18, 2024
1 parent 1489560 commit 77ac79a
Show file tree
Hide file tree
Showing 24 changed files with 321 additions and 207 deletions.
16 changes: 9 additions & 7 deletions src/main/java/com/mixces/legacyanimations/LegacyAnimations.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public class LegacyAnimations implements ModInitializer
public void onInitialize()
{
LegacyAnimationsSettings.CONFIG.load();
ClientTickEvents.END_WORLD_TICK.register(world ->
{
if (MinecraftClient.getInstance().player != null)
{
MinecraftClient.getInstance().player.calculateDimensions();
}
});
// ClientTickEvents.END_WORLD_TICK.register(world ->
// {
// if (MinecraftClient.getInstance().player == null)
// {
// return;
// }
//
// MinecraftClient.getInstance().player.calculateDimensions();
// });
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extend
value = "HEAD"
)
)
private void legacyAnimations$setEntity(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci)
private void legacyAnimations$captureEntity(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci)
{
legacyAnimations$entity = entity;
}
Expand All @@ -46,7 +46,7 @@ public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extend
target = "Lnet/minecraft/client/render/VertexConsumerProvider;getBuffer(Lnet/minecraft/client/render/RenderLayer;)Lnet/minecraft/client/render/VertexConsumer;"
)
)
private RenderLayer legacyAnimations$useEntityLayerRenderer(RenderLayer var1, @Local(ordinal = 0, argsOnly = true) Identifier overlay)
private RenderLayer legacyAnimations$useEntityLayerRendererArmor(RenderLayer var1, @Local(ordinal = 0, argsOnly = true) Identifier overlay)
{
if (!LegacyAnimationsSettings.CONFIG.instance().armorTint)
{
Expand All @@ -62,7 +62,7 @@ public abstract class ArmorFeatureRendererMixin<T extends LivingEntity, A extend
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)
private VertexConsumer legacyAnimations$useEntityLayerRendererTrim(Sprite instance, VertexConsumer consumer, Operation<VertexConsumer> original, @Local(ordinal = 0, argsOnly = true) VertexConsumerProvider vertexConsumers)
{
if (!LegacyAnimationsSettings.CONFIG.instance().armorTint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ public abstract class BuiltinModelItemRendererMixin
{

//todo: re-write shields

@ModifyExpressionValue(
method = "render",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z",
ordinal = 0
)
)
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 original;
}
return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction());
}
// @ModifyExpressionValue(
// method = "render",
// at = @At(
// value = "INVOKE",
// target = "Lnet/minecraft/item/ItemStack;isOf(Lnet/minecraft/item/Item;)Z",
// ordinal = 0
// )
// )
// 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 original;
// }
// return !ItemUtils.INSTANCE.isValidItem(stack, stack.getUseAction());
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
public abstract class ClientPlayerInteractionManagerMixin
{

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

@ModifyExpressionValue(
method = "updateBlockBreakingProgress",
Expand Down Expand Up @@ -54,7 +54,7 @@ public abstract class ClientPlayerInteractionManagerMixin
return;
}

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

if (player == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public abstract class EntityMixin
{

//todo: revert swimming mechanic
//todo: revert swimming mechanic (double jump to leave)

@ModifyReturnValue(
method = "getPose",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected FishingBobberEntityRendererMixin(EntityRendererFactory.Context ctx)
// )
// )
// public float useInterpolatedEyeHeight(PlayerEntity instance) {
// return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((AccessorCamera) dispatcher.camera).getLastCameraY(), ((AccessorCamera) dispatcher.camera).getCameraY());
// return MathHelper.lerp(dispatcher.camera.getLastTickDelta(), ((CameraInterface) dispatcher.camera).getLastCameraY(), ((CameraInterface) dispatcher.camera).getCameraY());
// }

@ModifyExpressionValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public class GameRendererMixin
)
private void legacyAnimations$addOldPitchRotation(MatrixStack matrices, float tickDelta, CallbackInfo ci, @Local(ordinal = 0) PlayerEntity playerEntity)
{
if (LegacyAnimationsSettings.CONFIG.instance().oldViewBob)
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));
return;
}

final float prevPlayerPitch = ((PlayerPitchInterface) playerEntity).legacyAnimations$getPrevPlayerPitch();
final float playerPitch = ((PlayerPitchInterface) playerEntity).legacyAnimations$getPlayerPitch();
final float h = MathHelper.lerp(tickDelta, prevPlayerPitch, playerPitch);

matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(h));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
public abstract class HeldItemRendererMixin
{

//todo: re-write the whole thing :)
@Shadow protected abstract void applySwingOffset(MatrixStack matrices, Arm arm, float swingProgress);
@Shadow private float equipProgressOffHand;
@Shadow private ItemStack mainHand;
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/com/mixces/legacyanimations/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@
import net.minecraft.util.UseAction;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@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<Boolean> original)
{
ClientPlayerEntity player = MinecraftClient.getInstance().player;
if (player != null) {
ItemStack mainStack = player.getMainHandStack();
UseAction action = mainStack.getUseAction();
if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.INSTANCE.isValidItem(mainStack, action))
{
return original.call(itemStack) || itemStack.isOf(Items.SHIELD);
}
}
return original.call(itemStack);
}
//todo: shield shit
// @WrapOperation(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z"))
// private boolean cancelOffhandHotbar(ItemStack itemStack, Operation<Boolean> original)
// {
// ClientPlayerEntity player = MinecraftClient.getInstance().player;
// if (player != null) {
// ItemStack mainStack = player.getMainHandStack();
// UseAction action = mainStack.getUseAction();
// if (LegacyAnimationsSettings.CONFIG.instance().hideShieldHotbar && ItemUtils.INSTANCE.isValidItem(mainStack, action))
// {
// return original.call(itemStack) || itemStack.isOf(Items.SHIELD);
// }
// }
// return original.call(itemStack);
// }

@WrapWithCondition(
method = "renderHealthBar",
Expand All @@ -57,7 +59,11 @@ private boolean cancelOffhandHotbar(ItemStack itemStack, Operation<Boolean> orig
)
private boolean legacyAnimations$removePerspectiveCheck(boolean original)
{
return LegacyAnimationsSettings.CONFIG.instance().perspectiveCrosshair || original;
if (!LegacyAnimationsSettings.CONFIG.instance().perspectiveCrosshair)
{
return original;
}
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ protected ItemEntityRendererMixin(EntityRendererFactory.Context ctx)
target = "Lnet/minecraft/client/util/math/MatrixStack;multiply(Lorg/joml/Quaternionf;)V"
)
)
private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boolean bl)
private Quaternionf legacyAnimations$facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boolean bl)
{
return LegacyAnimationsSettings.CONFIG.instance().fastItems && !bl ? dispatcher.getRotation() : quaternion;
if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) {
return quaternion;
}

if (bl)
{
return quaternion;
}
return dispatcher.getRotation();
}

@Inject(
Expand All @@ -47,23 +55,35 @@ private Quaternionf facePlayer(Quaternionf quaternion, @Local(ordinal = 0) boole
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)
private void legacyAnimations$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 (!LegacyAnimationsSettings.CONFIG.instance().fastItems)
{
if (dispatcher.gameOptions.getPerspective().isFrontView())
return;
}

if (MinecraftClient.getInstance().player == null)
{
return;
}

if (bl)
{
return;
}

if (dispatcher.gameOptions.getPerspective().isFrontView())
{
if (HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher))
{
if (HandUtils.INSTANCE.isLeftHand(MinecraftClient.getInstance().player, dispatcher))
{
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180));
}
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180));
}
else
}
else
{
if (HandUtils.INSTANCE.isRightHand(MinecraftClient.getInstance().player, dispatcher))
{
if (HandUtils.INSTANCE.isRightHand(MinecraftClient.getInstance().player, dispatcher))
{
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180));
}
matrixStack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.mixces.legacyanimations.config.LegacyAnimationsSettings;
import com.mixces.legacyanimations.util.HandUtils;
import com.mixces.legacyanimations.util.ItemUtils;
import com.mixces.legacyanimations.util.TransformationModeUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.VertexConsumerProvider;
Expand Down Expand Up @@ -31,23 +32,6 @@ 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<BakedQuad> legacyAnimations$changeToSprite(List<BakedQuad> quads, @Local(ordinal = 0, argsOnly = true) BakedModel model)
{
if (LegacyAnimationsSettings.CONFIG.instance().fastItems && client.player != null && TransformationModeUtils.shouldBeSprite() && !model.hasDepth())
{
boolean isLeftHand = HandUtils.INSTANCE.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(
Expand All @@ -56,10 +40,37 @@ public class ItemRendererMixin
)
private void legacyAnimations$getTransformationMode(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci)
{
if (LegacyAnimationsSettings.CONFIG.instance().fastItems)
TransformationModeUtils.setTransformationMode(renderMode);
ItemUtils.setModel(model);
}

//todo: unfuck left handed sprites and re-write code
@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<BakedQuad> legacyAnimations$changeToSprite(List<BakedQuad> quads, @Local(ordinal = 0, argsOnly = true) BakedModel model)
{
if (!LegacyAnimationsSettings.CONFIG.instance().fastItems) {
return quads;
}

if (client.player == null)
{
return quads;
}

if (!TransformationModeUtils.shouldBeSprite() || model.hasDepth())
{
return quads;
}

final boolean isLeftHand = HandUtils.INSTANCE.isLeftHand(client.player, client.getEntityRenderDispatcher());
final boolean isFrontView = client.getEntityRenderDispatcher().gameOptions.getPerspective().isFrontView();
final Direction perspectiveFace = legacyAnimations$determineDirection(isFrontView, isLeftHand);

if (TransformationModeUtils.getTransformationMode() == ModelTransformationMode.GROUND)
{
TransformationModeUtils.setTransformationMode(renderMode);
return legacyAnimations$filterQuadsByDirection(quads, perspectiveFace);
}
return legacyAnimations$filterQuadsByDirection(quads, Direction.SOUTH);
}

@Unique
Expand Down
Loading

0 comments on commit 77ac79a

Please sign in to comment.