From 3ffbe9d248b49c9d0c48e6abd2db036475caa877 Mon Sep 17 00:00:00 2001 From: AViewFromTheTop <87103914+AViewFromTheTop@users.noreply.github.com> Date: Thu, 5 Dec 2024 19:42:23 -0500 Subject: [PATCH] Fix Ostriches --- .../wilderwild/client/WWModelLayers.java | 7 ++++ .../client/model/OstrichInbredModel.java | 5 +++ .../wilderwild/client/model/OstrichModel.java | 9 +++++ .../renderer/entity/OstrichRenderer.java | 36 +++++++++++++------ src/main/resources/wilderwild.accesswidener | 4 +++ 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/frozenblock/wilderwild/client/WWModelLayers.java b/src/main/java/net/frozenblock/wilderwild/client/WWModelLayers.java index f9c56de7c..972602c1b 100644 --- a/src/main/java/net/frozenblock/wilderwild/client/WWModelLayers.java +++ b/src/main/java/net/frozenblock/wilderwild/client/WWModelLayers.java @@ -62,8 +62,11 @@ public final class WWModelLayers { public static final ModelLayerLocation TUMBLEWEED = new ModelLayerLocation(WWConstants.id("tumbleweed"), "main"); public static final ModelLayerLocation CRAB = new ModelLayerLocation(WWConstants.id("crab"), "main"); public static final ModelLayerLocation OSTRICH = new ModelLayerLocation(WWConstants.id("ostrich"), "main"); + public static final ModelLayerLocation OSTRICH_BABY = new ModelLayerLocation(WWConstants.id("ostrich_baby"), "main"); public static final ModelLayerLocation OSTRICH_INBRED = new ModelLayerLocation(WWConstants.id("ostrich"), "inbred"); + public static final ModelLayerLocation OSTRICH_BABY_INBRED = new ModelLayerLocation(WWConstants.id("ostrich_baby"), "inbred"); public static final ModelLayerLocation OSTRICH_SADDLE = new ModelLayerLocation(WWConstants.id("ostrich"), "saddle"); + public static final ModelLayerLocation OSTRICH_BABY_SADDLE = new ModelLayerLocation(WWConstants.id("ostrich_baby"), "saddle"); public static final ModelLayerLocation SCORCHED = new ModelLayerLocation(WWConstants.id("scorched"), "main"); // BOATS @@ -90,9 +93,13 @@ public static void init() { EntityModelLayerRegistry.registerModelLayer(CRAB, CrabModel::createBodyLayer); EntityRendererRegistry.register(WWEntityTypes.OSTRICH, OstrichRenderer::new); + EntityModelLayerRegistry.registerModelLayer(OSTRICH, OstrichModel::createBodyLayer); + EntityModelLayerRegistry.registerModelLayer(OSTRICH_BABY, OstrichModel::createBabyBodyLayer); EntityModelLayerRegistry.registerModelLayer(OSTRICH_INBRED, OstrichInbredModel::createBodyLayer); + EntityModelLayerRegistry.registerModelLayer(OSTRICH_BABY_INBRED, OstrichInbredModel::createBabyBodyLayer); EntityModelLayerRegistry.registerModelLayer(OSTRICH_SADDLE, OstrichModel::createBodyLayer); + EntityModelLayerRegistry.registerModelLayer(OSTRICH_BABY_SADDLE, OstrichModel::createBabyBodyLayer); EntityRendererRegistry.register(WWEntityTypes.SCORCHED, ScorchedRenderer::new); EntityModelLayerRegistry.registerModelLayer(SCORCHED, SpiderModel::createSpiderBodyLayer); diff --git a/src/main/java/net/frozenblock/wilderwild/client/model/OstrichInbredModel.java b/src/main/java/net/frozenblock/wilderwild/client/model/OstrichInbredModel.java index 789159cc3..f571ab934 100644 --- a/src/main/java/net/frozenblock/wilderwild/client/model/OstrichInbredModel.java +++ b/src/main/java/net/frozenblock/wilderwild/client/model/OstrichInbredModel.java @@ -296,6 +296,11 @@ public static LayerDefinition createBodyLayer() { return LayerDefinition.create(meshdefinition, 128, 64); } + @NotNull + public static LayerDefinition createBabyBodyLayer() { + return createBodyLayer().apply(OstrichModel.BABY_TRANSFORMER); + } + private static void animateLeg(@NotNull ModelPart leg, @NotNull ModelPart foot, float limbSwing, float limbSwingAmount, float animOffset) { float fastAngle = limbSwing * 0.3331F + animOffset; float angleSin = Math.sin(-fastAngle); diff --git a/src/main/java/net/frozenblock/wilderwild/client/model/OstrichModel.java b/src/main/java/net/frozenblock/wilderwild/client/model/OstrichModel.java index e8f2a7665..f0ebed512 100644 --- a/src/main/java/net/frozenblock/wilderwild/client/model/OstrichModel.java +++ b/src/main/java/net/frozenblock/wilderwild/client/model/OstrichModel.java @@ -19,6 +19,7 @@ package net.frozenblock.wilderwild.client.model; import net.frozenblock.wilderwild.client.renderer.entity.state.OstrichRenderState; +import net.minecraft.client.model.BabyModelTransform; import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.model.geom.PartPose; @@ -26,12 +27,15 @@ import net.minecraft.client.model.geom.builders.CubeListBuilder; import net.minecraft.client.model.geom.builders.LayerDefinition; import net.minecraft.client.model.geom.builders.MeshDefinition; +import net.minecraft.client.model.geom.builders.MeshTransformer; import net.minecraft.client.model.geom.builders.PartDefinition; import net.minecraft.util.Mth; import org.jetbrains.annotations.NotNull; import org.joml.Math; +import java.util.Set; public class OstrichModel extends EntityModel { + public static final MeshTransformer BABY_TRANSFORMER = new BabyModelTransform(true, 10F, 4F, Set.of("neck")); private static final float NECK_DELAY = 0F; private static final float OLD_NECK_DELAY = 0.0416375F; private static final float NECK_BASE_SWING = 0.175F * 0.5F; @@ -107,6 +111,11 @@ public static LayerDefinition createBodyLayer() { return LayerDefinition.create(meshdefinition, 128, 64); } + @NotNull + public static LayerDefinition createBabyBodyLayer() { + return createBodyLayer().apply(BABY_TRANSFORMER); + } + private static void animateLeg(@NotNull ModelPart leg, @NotNull ModelPart foot, float limbSwing, float limbSwingAmount, float animOffset) { float fastAngle = limbSwing * 0.3331F + animOffset; float angleSin = Math.sin(-fastAngle); diff --git a/src/main/java/net/frozenblock/wilderwild/client/renderer/entity/OstrichRenderer.java b/src/main/java/net/frozenblock/wilderwild/client/renderer/entity/OstrichRenderer.java index fd4a61e37..178c9e79b 100644 --- a/src/main/java/net/frozenblock/wilderwild/client/renderer/entity/OstrichRenderer.java +++ b/src/main/java/net/frozenblock/wilderwild/client/renderer/entity/OstrichRenderer.java @@ -27,33 +27,49 @@ import net.frozenblock.wilderwild.entity.Ostrich; import net.minecraft.client.model.EntityModel; import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.entity.AgeableMobRenderer; import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.client.renderer.entity.MobRenderer; import net.minecraft.client.renderer.entity.layers.SaddleLayer; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.NotNull; import org.joml.Math; -public class OstrichRenderer extends MobRenderer> { +public class OstrichRenderer extends AgeableMobRenderer> { private static final ResourceLocation OSTRICH_LOCATION = WWConstants.id("textures/entity/ostrich/ostrich.png"); private static final ResourceLocation OSTRICH_SADDLE_LOCATION = WWConstants.id("textures/entity/ostrich/ostrich_saddle.png"); - private boolean isInbred = false; - private final EntityModel normalModel = this.getModel(); + private final EntityModel normalModel; + private final EntityModel normalBabyModel; private final EntityModel inbredModel; + private final EntityModel inbredBabyModel; public OstrichRenderer(EntityRendererProvider.Context context) { - super(context, new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH)), 0.75F); + super(context, new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH)), new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH_BABY)), 0.75F); + + this.normalModel = this.adultModel; + this.normalBabyModel = this.babyModel; + this.inbredModel = new OstrichInbredModel(context.bakeLayer(WWModelLayers.OSTRICH_INBRED)); - this.addLayer(new SaddleLayer<>(this, new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH_SADDLE)), OSTRICH_SADDLE_LOCATION)); + this.inbredBabyModel = new OstrichInbredModel(context.bakeLayer(WWModelLayers.OSTRICH_BABY_INBRED)); + + this.addLayer( + new SaddleLayer<>( + this, + new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH_SADDLE)), + new OstrichModel(context.bakeLayer(WWModelLayers.OSTRICH_BABY_SADDLE)), + OSTRICH_SADDLE_LOCATION + ) + ); } @Override public void render(@NotNull OstrichRenderState renderState, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) { - boolean isOstrichInbred = renderState.isInbred; - if (this.isInbred != isOstrichInbred) { - this.model = !isOstrichInbred ? this.normalModel : this.inbredModel; - this.isInbred = isOstrichInbred; + if (renderState.isInbred) { + this.adultModel = this.inbredModel; + this.babyModel = this.inbredBabyModel; + } else { + this.adultModel = this.normalModel; + this.babyModel = this.normalBabyModel; } super.render(renderState, poseStack, multiBufferSource, packedLight); } diff --git a/src/main/resources/wilderwild.accesswidener b/src/main/resources/wilderwild.accesswidener index 1d71c96ab..1994d6d91 100644 --- a/src/main/resources/wilderwild.accesswidener +++ b/src/main/resources/wilderwild.accesswidener @@ -77,6 +77,10 @@ accessible field net/minecraft/client/renderer/entity/layers/LivingEntityEmissiv accessible field net/minecraft/client/renderer/entity/layers/LivingEntityEmissiveLayer drawSelector Lnet/minecraft/client/renderer/entity/layers/LivingEntityEmissiveLayer$DrawSelector; accessible field net/minecraft/client/renderer/entity/layers/LivingEntityEmissiveLayer texture Lnet/minecraft/resources/ResourceLocation; accessible field net/minecraft/client/renderer/entity/layers/LivingEntityEmissiveLayer bufferProvider Ljava/util/function/Function; +accessible field net/minecraft/client/renderer/entity/AgeableMobRenderer adultModel Lnet/minecraft/client/model/EntityModel; +mutable field net/minecraft/client/renderer/entity/AgeableMobRenderer adultModel Lnet/minecraft/client/model/EntityModel; +accessible field net/minecraft/client/renderer/entity/AgeableMobRenderer babyModel Lnet/minecraft/client/model/EntityModel; +mutable field net/minecraft/client/renderer/entity/AgeableMobRenderer babyModel Lnet/minecraft/client/model/EntityModel; # Mobs accessible method net/minecraft/world/effect/MobEffect (Lnet/minecraft/world/effect/MobEffectCategory;I)V