Skip to content

Commit

Permalink
Fix Ostriches
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 6, 2024
1 parent 85d5198 commit 3ffbe9d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
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;
import net.minecraft.client.model.geom.builders.CubeDeformation;
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<OstrichRenderState> {
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ostrich, OstrichRenderState, EntityModel<OstrichRenderState>> {
public class OstrichRenderer extends AgeableMobRenderer<Ostrich, OstrichRenderState, EntityModel<OstrichRenderState>> {
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<OstrichRenderState> normalModel = this.getModel();
private final EntityModel<OstrichRenderState> normalModel;
private final EntityModel<OstrichRenderState> normalBabyModel;
private final EntityModel<OstrichRenderState> inbredModel;
private final EntityModel<OstrichRenderState> 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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/wilderwild.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (Lnet/minecraft/world/effect/MobEffectCategory;I)V
Expand Down

0 comments on commit 3ffbe9d

Please sign in to comment.