Skip to content

Commit

Permalink
feat: ✨ Updated backpack layer rendering code to use body rotations /…
Browse files Browse the repository at this point in the history
… translations so that it would be more compatible with mods that animate players / mobs like EMF
  • Loading branch information
P3pp3rF1y committed Nov 21, 2024
1 parent 0d1f1cd commit c86c72a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 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 @@ loader_version_range=[4,)
mod_id=sophisticatedbackpacks
mod_name=Sophisticated Backpacks
mod_license=GNU General Public License v3.0
mod_version=3.20.24
mod_version=3.20.25
mod_group_id=sophisticatedbackpacks
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional backpacks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@ public BackpackLayerRenderer(RenderLayerParent<T, M> entityRendererIn) {
}

@Override
public void render(PoseStack matrixStack, MultiBufferSource buffer, int packedLight, T entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
public void render(PoseStack poseStack, MultiBufferSource buffer, int packedLight, T entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (entity instanceof AbstractClientPlayer player) {
PlayerInventoryProvider.get().getBackpackFromRendered(player).ifPresent(backpackRenderInfo -> {
matrixStack.pushPose();
poseStack.pushPose();
ItemStack backpack = backpackRenderInfo.getBackpack();
IBackpackModel model = BackpackModelManager.getBackpackModel(backpack.getItem());
EquipmentSlot equipmentSlot = model.getRenderEquipmentSlot();
boolean wearsArmor = (equipmentSlot != EquipmentSlot.CHEST || !backpackRenderInfo.isArmorSlot()) && !player.getInventory().armor.get(equipmentSlot.getIndex()).isEmpty();
renderBackpack(getParentModel(), player, matrixStack, buffer, packedLight, backpack, wearsArmor, model);
matrixStack.popPose();
renderBackpack(getParentModel(), player, poseStack, buffer, packedLight, backpack, wearsArmor, model);
poseStack.popPose();
});
} else {
poseStack.pushPose();
ItemStack chestStack = entity.getItemBySlot(EquipmentSlot.CHEST);
if (chestStack.getItem() instanceof BackpackItem) {
renderBackpack(getParentModel(), entity, matrixStack, buffer, packedLight, chestStack, false, BackpackModelManager.getBackpackModel(chestStack.getItem()));
renderBackpack(getParentModel(), entity, poseStack, buffer, packedLight, chestStack, false, BackpackModelManager.getBackpackModel(chestStack.getItem()));
}
poseStack.popPose();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.AgeableListModel;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.*;
Expand Down Expand Up @@ -447,13 +448,12 @@ public EquipmentSlot getRenderEquipmentSlot() {
}

@Override
public <L extends LivingEntity, M extends EntityModel<L>> void translateRotateAndScale(M parentModel, LivingEntity livingEntity, PoseStack matrixStack, boolean wearsArmor) {
if (livingEntity.isCrouching()) {
matrixStack.translate(0D, 0.2D, 0D);
matrixStack.mulPose(Axis.XP.rotationDegrees(90F / (float) Math.PI));
public <L extends LivingEntity, M extends EntityModel<L>> void translateRotateAndScale(M parentModel, LivingEntity livingEntity, PoseStack poseStack, boolean wearsArmor) {
if (parentModel instanceof HumanoidModel<?> humanoidModel) {
humanoidModel.body.translateAndRotate(poseStack);
}

matrixStack.mulPose(Axis.YP.rotationDegrees(180));
poseStack.mulPose(Axis.YP.rotationDegrees(180));
float zOffset = wearsArmor ? -0.35f : -0.3f;
float yOffset = -0.75f;

Expand All @@ -462,19 +462,19 @@ public <L extends LivingEntity, M extends EntityModel<L>> void translateRotateAn
yOffset = CHILD_Y_OFFSET;
}

matrixStack.translate(0, yOffset, zOffset);
poseStack.translate(0, yOffset, zOffset);

if (livingEntity instanceof Player) {
return;
}

if (livingEntity.isBaby()) {
matrixStack.scale(CHILD_SCALE, CHILD_SCALE, CHILD_SCALE);
poseStack.scale(CHILD_SCALE, CHILD_SCALE, CHILD_SCALE);
}

if (entityTranslations.containsKey(livingEntity.getType())) {
Vec3 translVector = entityTranslations.get(livingEntity.getType());
matrixStack.translate(translVector.x(), translVector.y(), translVector.z());
poseStack.translate(translVector.x(), translVector.y(), translVector.z());
}
}

Expand Down

0 comments on commit c86c72a

Please sign in to comment.