Skip to content

Commit

Permalink
Plate poses
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaHelios committed Jun 18, 2024
1 parent a2dafad commit 1e80dff
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions projects/pswg/src/main/java/com/parzivail/pswg/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<? extends LivingEntity> 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<? extends LivingEntity> 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<? extends LivingEntity> 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<? extends LivingEntity> 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;
}
}

0 comments on commit 1e80dff

Please sign in to comment.