diff --git a/gradle.properties b/gradle.properties index d49fd5c..bd7372b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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= diff --git a/src/main/java/net/quepierts/simple_animator/core/client/ClientAnimator.java b/src/main/java/net/quepierts/simple_animator/core/client/ClientAnimator.java index d9d3734..9b74699 100644 --- a/src/main/java/net/quepierts/simple_animator/core/client/ClientAnimator.java +++ b/src/main/java/net/quepierts/simple_animator/core/client/ClientAnimator.java @@ -117,7 +117,7 @@ public void tick(float time) { } } - public void process(PlayerModel model) { + public void update(PlayerModel model) { if (this.animation == null) return; @@ -135,7 +135,10 @@ public void process(PlayerModel model) { shouldUpdate = false; processed = true; } + } + public void process(PlayerModel model) { + this.update(model); process(ModelBone.HEAD, model.head); process(ModelBone.BODY, model.body); process(ModelBone.LEFT_ARM, model.leftArm); diff --git a/src/main/java/net/quepierts/simple_animator/core/mixin/ItemInHandRendererMixin.java b/src/main/java/net/quepierts/simple_animator/core/mixin/ItemInHandRendererMixin.java new file mode 100644 index 0000000..137262d --- /dev/null +++ b/src/main/java/net/quepierts/simple_animator/core/mixin/ItemInHandRendererMixin.java @@ -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 model = playerrenderer.getModel(); + float yaw = pPlayer.yHeadRot - pPlayer.yBodyRot; + float pitch = pPlayer.getXRot(); + model.setupAnim(pPlayer, 0.0F, 0.0F, 0.0F, yaw, pitch); + } + } + } +} diff --git a/src/main/java/net/quepierts/simple_animator/core/proxy/ClientProxy.java b/src/main/java/net/quepierts/simple_animator/core/proxy/ClientProxy.java index dee98ee..8159cef 100644 --- a/src/main/java/net/quepierts/simple_animator/core/proxy/ClientProxy.java +++ b/src/main/java/net/quepierts/simple_animator/core/proxy/ClientProxy.java @@ -23,7 +23,6 @@ import java.util.UUID; -@OnlyIn(Dist.CLIENT) public class ClientProxy extends CommonProxy { public final ClientPlayerNavigator navigator; @@ -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(); } } diff --git a/src/main/resources/simple_animator.mixins.json b/src/main/resources/simple_animator.mixins.json index 0508244..a8375d6 100644 --- a/src/main/resources/simple_animator.mixins.json +++ b/src/main/resources/simple_animator.mixins.json @@ -10,6 +10,7 @@ "CameraMixin", "CapeLayerMixin", "EntityMixin", + "ItemInHandRendererMixin", "LivingEntityRendererMixin", "MouseHandlerMixin", "PlayerModelMixin",