From 1e80dffd198c84e6dea71e685a0172d7316079a9 Mon Sep 17 00:00:00 2001 From: DeltaHelios Date: Tue, 18 Jun 2024 21:27:16 +0300 Subject: [PATCH] Plate poses --- .../main/java/com/parzivail/pswg/Client.java | 1 + .../features/plate/PlateItemRenderer.java | 42 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/projects/pswg/src/main/java/com/parzivail/pswg/Client.java b/projects/pswg/src/main/java/com/parzivail/pswg/Client.java index 38ede328d..462c55cc5 100644 --- a/projects/pswg/src/main/java/com/parzivail/pswg/Client.java +++ b/projects/pswg/src/main/java/com/parzivail/pswg/Client.java @@ -353,6 +353,7 @@ public void onInitializeClient() ICustomItemRenderer.register(ThermalDetonatorItem.class, ThermalDetonatorItemRenderer.INSTANCE); ICustomItemRenderer.register(PlateItem.class, PlateItemRenderer.INSTANCE); + ICustomPoseItem.register(PlateItem.class, PlateItemRenderer.INSTANCE); // TODO: ICustomSkyRenderer.register(SwgDimensions.Tatooine.WORLD_KEY.getValue(), new TatooineSkyRenderer()); diff --git a/projects/pswg/src/main/java/com/parzivail/pswg/features/plate/PlateItemRenderer.java b/projects/pswg/src/main/java/com/parzivail/pswg/features/plate/PlateItemRenderer.java index 8675f77b4..3121b6579 100644 --- a/projects/pswg/src/main/java/com/parzivail/pswg/features/plate/PlateItemRenderer.java +++ b/projects/pswg/src/main/java/com/parzivail/pswg/features/plate/PlateItemRenderer.java @@ -1,22 +1,26 @@ package com.parzivail.pswg.features.plate; import com.parzivail.p3d.P3dManager; -import com.parzivail.p3d.P3dModel; +import com.parzivail.pswg.container.SwgItems; import com.parzivail.util.client.render.ICustomItemRenderer; +import com.parzivail.util.client.render.ICustomPoseItem; import com.parzivail.util.math.MathUtil; import net.minecraft.client.render.RenderLayer; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; +import net.minecraft.util.Hand; +import net.minecraft.util.math.MathHelper; import org.joml.Quaternionf; import java.util.ArrayList; import java.util.List; -public class PlateItemRenderer implements ICustomItemRenderer +public class PlateItemRenderer implements ICustomItemRenderer, ICustomPoseItem { public static final PlateItemRenderer INSTANCE = new PlateItemRenderer(); @Override @@ -66,4 +70,38 @@ public void render(LivingEntity player, ItemStack stack, ModelTransformationMode matrices.pop(); } + + @Override + public void modifyPose(LivingEntity entity, Hand hand, ItemStack stack, BipedEntityModel model, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch, float tickDelta) + { + if (entity.getStackInHand(Hand.MAIN_HAND).isOf(SwgItems.Plate.PlateItem) && entity.getStackInHand(Hand.OFF_HAND).isOf(SwgItems.Plate.PlateItem)) + poseDual(model, limbAngle, limbDistance); + else if (entity.getStackInHand(Hand.MAIN_HAND).isOf(SwgItems.Plate.PlateItem)) + poseRight(model, limbAngle, limbDistance); + else if (entity.getStackInHand(Hand.OFF_HAND).isOf(SwgItems.Plate.PlateItem)) + poseLeft(model, limbAngle, limbDistance); + } + + private void poseLeft(BipedEntityModel model, float limbAngle, float limbDistance) + { + var limbBounce = limbDistance * MathHelper.sin(limbAngle / 2f) * 0.05f; + model.leftArm.pitch = -1.35F + model.head.pitch + limbBounce; + model.leftArm.yaw = 0.1F + model.head.yaw; + } + + private void poseRight(BipedEntityModel model, float limbAngle, float limbDistance) + { + var limbBounce = limbDistance * MathHelper.sin(limbAngle / 2f) * 0.05f; + model.rightArm.pitch = -1.35F + model.head.pitch + limbBounce; + model.rightArm.yaw = 0.1F + model.head.yaw; + } + + private void poseDual(BipedEntityModel model, float limbAngle, float limbDistance) + { + var limbBounce = limbDistance * MathHelper.sin(limbAngle / 2f) * 0.05f; + model.rightArm.pitch = -1.35F + model.head.pitch + limbBounce; + model.rightArm.yaw = 0.1F + model.head.yaw; + model.leftArm.pitch = -1.35F + model.head.pitch + limbBounce; + model.leftArm.yaw = 0.1F + model.head.yaw; + } }