Added variable size
Added variable and dynamic hitbox Added dynamic growth times Ony Achillobator test
This commit is contained in:
+1
-6
@@ -9,18 +9,13 @@ import software.bernie.geckolib.renderer.GeoEntityRenderer;
|
||||
|
||||
|
||||
public class AchillobatorRenderer extends GeoEntityRenderer<AchillobatorEntity> {
|
||||
private final float animalScale = 1.0F;
|
||||
public AchillobatorRenderer(EntityRendererProvider.Context renderManager) {
|
||||
super(renderManager, new AchillobatorModel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scaleModelForRender(float widthScale, float heightScale, PoseStack poseStack, AchillobatorEntity animatable, BakedGeoModel model, boolean isReRender, float partialTick, int packedLight, int packedOverlay) {
|
||||
poseStack.scale(animalScale, animalScale, animalScale);
|
||||
if(animatable.isBaby()) {
|
||||
float growthProgress = Mth.clamp((24000.0F + animatable.getSyncedAge()) / 24000.0F, 0.0F, 1.0F);
|
||||
float scale = Mth.lerp(growthProgress, 0.2F, 1.0F);
|
||||
float scale = animatable.getTotalModelScale();
|
||||
poseStack.scale(scale, scale, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,18 @@ import software.bernie.geckolib.animation.*;
|
||||
public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
private AnimatableInstanceCache cache = new SingletonAnimatableInstanceCache(this);
|
||||
|
||||
public static final int BABY_TO_ADULT_AGE_TICKS = 240;
|
||||
private static final float MIN_ANIMAL_SCALE = 0.92F;
|
||||
private static final float MAX_ANIMAL_SCALE = 1.08F;
|
||||
|
||||
private float lastDimensionsScale = 1.0F;
|
||||
|
||||
private static final EntityDataAccessor<Integer> VARIANT =
|
||||
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.INT);
|
||||
private static final EntityDataAccessor<Integer> DATA_SYNCED_AGE =
|
||||
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.INT);
|
||||
private static final EntityDataAccessor<Float> DATA_ANIMAL_SCALE =
|
||||
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.FLOAT);
|
||||
|
||||
// Procedural tail sway state (client-side use for rendering)
|
||||
private float tailSwayOffset; // Smoothed offset in range roughly [-1, 1]
|
||||
@@ -103,6 +111,11 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
return new DinoAIConfig(0.3D, 1.1D, 1.5D, 100, 100, 0.05f, 0.1f, 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBaby(boolean baby) {
|
||||
this.setAge(baby ? -BABY_TO_ADULT_AGE_TICKS : 0);
|
||||
}
|
||||
|
||||
public static AttributeSupplier.Builder createAttributes() {
|
||||
return Animal.createLivingAttributes()
|
||||
.add(Attributes.MAX_HEALTH, 30D)
|
||||
@@ -121,6 +134,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
if (child instanceof AchillobatorEntity baby) {
|
||||
AchillobatorVariant randomVariant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||
baby.setVariant(randomVariant);
|
||||
baby.setBaby(true);
|
||||
}
|
||||
return child;
|
||||
}
|
||||
@@ -179,6 +193,8 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
}
|
||||
}
|
||||
|
||||
updateDynamicDimensions();
|
||||
|
||||
if (!level().isClientSide) {
|
||||
if (mouthAnimCooldown > 0) {
|
||||
mouthAnimCooldown--;
|
||||
@@ -244,6 +260,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
super.defineSynchedData();
|
||||
this.entityData.define(VARIANT, 0);
|
||||
this.entityData.define(DATA_SYNCED_AGE, 0);
|
||||
this.entityData.define(DATA_ANIMAL_SCALE, 1.0F);
|
||||
}
|
||||
/*?} else {*/
|
||||
/*@Override
|
||||
@@ -251,6 +268,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
super.defineSynchedData(pBuilder);
|
||||
pBuilder.define(VARIANT, 0);
|
||||
pBuilder.define(DATA_SYNCED_AGE, 0);
|
||||
pBuilder.define(DATA_ANIMAL_SCALE, 1.0F);
|
||||
}
|
||||
*//*?}*/
|
||||
|
||||
@@ -258,6 +276,41 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
return this.entityData.get(DATA_SYNCED_AGE);
|
||||
}
|
||||
|
||||
public float getAnimalScale() {
|
||||
return this.entityData.get(DATA_ANIMAL_SCALE);
|
||||
}
|
||||
|
||||
private void setAnimalScale(float animalScale) {
|
||||
this.entityData.set(DATA_ANIMAL_SCALE, animalScale);
|
||||
}
|
||||
|
||||
public float getGrowthScale() {
|
||||
if (!this.isBaby()) {
|
||||
return 1.0F;
|
||||
}
|
||||
|
||||
int age = this.level().isClientSide ? this.getSyncedAge() : this.getAge();
|
||||
float growthProgress = Mth.clamp((BABY_TO_ADULT_AGE_TICKS + age) / (float) BABY_TO_ADULT_AGE_TICKS, 0.0F, 1.0F);
|
||||
return Mth.lerp(growthProgress, 0.2F, 1.0F);
|
||||
}
|
||||
|
||||
public float getTotalModelScale() {
|
||||
return this.getAnimalScale() * this.getGrowthScale();
|
||||
}
|
||||
|
||||
private void updateDynamicDimensions() {
|
||||
float dimensionsScale = this.getTotalModelScale();
|
||||
if (Math.abs(dimensionsScale - this.lastDimensionsScale) > 0.01F) {
|
||||
this.lastDimensionsScale = dimensionsScale;
|
||||
this.refreshDimensions();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityDimensions getDimensions(Pose pose) {
|
||||
return this.getType().getDimensions().scale(this.getTotalModelScale());
|
||||
}
|
||||
|
||||
public int getTypeVariant() {
|
||||
return this.entityData.get(VARIANT);
|
||||
}
|
||||
@@ -280,12 +333,16 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
public void addAdditionalSaveData(CompoundTag pCompound) {
|
||||
super.addAdditionalSaveData(pCompound);
|
||||
pCompound.putInt("Variant", this.getTypeVariant());
|
||||
pCompound.putFloat("AnimalScale", this.getAnimalScale());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readAdditionalSaveData(CompoundTag pCompound) {
|
||||
super.readAdditionalSaveData(pCompound);
|
||||
this.entityData.set(VARIANT, pCompound.getInt("Variant"));
|
||||
if (pCompound.contains("AnimalScale")) {
|
||||
this.setAnimalScale(pCompound.getFloat("AnimalScale"));
|
||||
}
|
||||
}
|
||||
|
||||
/*? if <=1.20.1 {*/
|
||||
@@ -293,6 +350,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor pLevel, DifficultyInstance pDifficulty, MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pDataTag) {
|
||||
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||
this.setVariant(variant);
|
||||
this.setAnimalScale(Mth.nextFloat(this.random, MIN_ANIMAL_SCALE, MAX_ANIMAL_SCALE));
|
||||
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData, pDataTag);
|
||||
}
|
||||
/*?} else {*/
|
||||
@@ -300,6 +358,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
|
||||
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||
this.setVariant(variant);
|
||||
this.setAnimalScale(Mth.nextFloat(this.random, MIN_ANIMAL_SCALE, MAX_ANIMAL_SCALE));
|
||||
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
|
||||
}
|
||||
*//*?}*/
|
||||
|
||||
Reference in New Issue
Block a user