Skip to content

Commit

Permalink
1.0.2 fixed bug: camera cannot animate during holding item in first-p…
Browse files Browse the repository at this point in the history
…erson perspective
  • Loading branch information
LouisQuepierts committed Aug 1, 2024
1 parent 91bea56 commit 3609bd8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mapping_version=2023.09.03-1.20.1
mod_id=simple_animator
mod_name=SimpleAnimator
mod_license=MIT
mod_version=1.0.1
mod_version=1.0.2
mod_group_id=net.quepierts
mod_authors=
mod_description=
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void tick(float time) {
}
}

public void process(PlayerModel<AbstractClientPlayer> model) {
public void update(PlayerModel<AbstractClientPlayer> model) {
if (this.animation == null)
return;

Expand All @@ -135,7 +135,10 @@ public void process(PlayerModel<AbstractClientPlayer> model) {
shouldUpdate = false;
processed = true;
}
}

public void process(PlayerModel<AbstractClientPlayer> model) {
this.update(model);
process(ModelBone.HEAD, model.head);
process(ModelBone.BODY, model.body);
process(ModelBone.LEFT_ARM, model.leftArm);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package net.quepierts.simple_animator.core.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.PlayerModel;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.client.renderer.ItemInHandRenderer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.quepierts.simple_animator.core.SimpleAnimator;
import net.quepierts.simple_animator.core.client.ClientAnimator;
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(ItemInHandRenderer.class)
public class ItemInHandRendererMixin {
@Shadow @Final private EntityRenderDispatcher entityRenderDispatcher;

@Inject(
method = "renderArmWithItem",
at = @At(
value = "INVOKE",
target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V",
shift = At.Shift.AFTER
)
)
public void update(AbstractClientPlayer pPlayer, float pPartialTicks, float pPitch, InteractionHand pHand, float pSwingProgress, ItemStack pStack, float pEquippedProgress, PoseStack pPoseStack, MultiBufferSource pBuffer, int pCombinedLight, CallbackInfo ci) {
if (!pStack.isEmpty()) {
ClientAnimator animator = SimpleAnimator.getInstance().getClient().getClientAnimatorManager().getAnimator(pPlayer.getUUID());

if (animator != null && animator.isRunning()) {
PlayerRenderer playerrenderer = (PlayerRenderer)this.entityRenderDispatcher.getRenderer(pPlayer);
PlayerModel<AbstractClientPlayer> model = playerrenderer.getModel();
float yaw = pPlayer.yHeadRot - pPlayer.yBodyRot;
float pitch = pPlayer.getXRot();
model.setupAnim(pPlayer, 0.0F, 0.0F, 0.0F, yaw, pitch);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.UUID;

@OnlyIn(Dist.CLIENT)
public class ClientProxy extends CommonProxy {
public final ClientPlayerNavigator navigator;

Expand Down Expand Up @@ -84,7 +83,7 @@ public void onClientTick(TickEvent.ClientTickEvent event) {

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (navigator.isNavigating() && event.phase == TickEvent.Phase.END && event.player instanceof LocalPlayer player) {
if (navigator.isNavigating() && event.phase == TickEvent.Phase.END && event.player instanceof LocalPlayer) {
navigator.tick();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/simple_animator.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"CameraMixin",
"CapeLayerMixin",
"EntityMixin",
"ItemInHandRendererMixin",
"LivingEntityRendererMixin",
"MouseHandlerMixin",
"PlayerModelMixin",
Expand Down

0 comments on commit 3609bd8

Please sign in to comment.