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> {
|
public class AchillobatorRenderer extends GeoEntityRenderer<AchillobatorEntity> {
|
||||||
private final float animalScale = 1.0F;
|
|
||||||
public AchillobatorRenderer(EntityRendererProvider.Context renderManager) {
|
public AchillobatorRenderer(EntityRendererProvider.Context renderManager) {
|
||||||
super(renderManager, new AchillobatorModel());
|
super(renderManager, new AchillobatorModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scaleModelForRender(float widthScale, float heightScale, PoseStack poseStack, AchillobatorEntity animatable, BakedGeoModel model, boolean isReRender, float partialTick, int packedLight, int packedOverlay) {
|
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);
|
float scale = animatable.getTotalModelScale();
|
||||||
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);
|
|
||||||
poseStack.scale(scale, scale, scale);
|
poseStack.scale(scale, scale, scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -46,10 +46,18 @@ import software.bernie.geckolib.animation.*;
|
|||||||
public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
||||||
private AnimatableInstanceCache cache = new SingletonAnimatableInstanceCache(this);
|
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 =
|
private static final EntityDataAccessor<Integer> VARIANT =
|
||||||
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.INT);
|
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.INT);
|
||||||
private static final EntityDataAccessor<Integer> DATA_SYNCED_AGE =
|
private static final EntityDataAccessor<Integer> DATA_SYNCED_AGE =
|
||||||
SynchedEntityData.defineId(AchillobatorEntity.class, EntityDataSerializers.INT);
|
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)
|
// Procedural tail sway state (client-side use for rendering)
|
||||||
private float tailSwayOffset; // Smoothed offset in range roughly [-1, 1]
|
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);
|
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() {
|
public static AttributeSupplier.Builder createAttributes() {
|
||||||
return Animal.createLivingAttributes()
|
return Animal.createLivingAttributes()
|
||||||
.add(Attributes.MAX_HEALTH, 30D)
|
.add(Attributes.MAX_HEALTH, 30D)
|
||||||
@@ -121,6 +134,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
if (child instanceof AchillobatorEntity baby) {
|
if (child instanceof AchillobatorEntity baby) {
|
||||||
AchillobatorVariant randomVariant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
AchillobatorVariant randomVariant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||||
baby.setVariant(randomVariant);
|
baby.setVariant(randomVariant);
|
||||||
|
baby.setBaby(true);
|
||||||
}
|
}
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@@ -179,6 +193,8 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDynamicDimensions();
|
||||||
|
|
||||||
if (!level().isClientSide) {
|
if (!level().isClientSide) {
|
||||||
if (mouthAnimCooldown > 0) {
|
if (mouthAnimCooldown > 0) {
|
||||||
mouthAnimCooldown--;
|
mouthAnimCooldown--;
|
||||||
@@ -244,6 +260,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
super.defineSynchedData();
|
super.defineSynchedData();
|
||||||
this.entityData.define(VARIANT, 0);
|
this.entityData.define(VARIANT, 0);
|
||||||
this.entityData.define(DATA_SYNCED_AGE, 0);
|
this.entityData.define(DATA_SYNCED_AGE, 0);
|
||||||
|
this.entityData.define(DATA_ANIMAL_SCALE, 1.0F);
|
||||||
}
|
}
|
||||||
/*?} else {*/
|
/*?} else {*/
|
||||||
/*@Override
|
/*@Override
|
||||||
@@ -251,6 +268,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
super.defineSynchedData(pBuilder);
|
super.defineSynchedData(pBuilder);
|
||||||
pBuilder.define(VARIANT, 0);
|
pBuilder.define(VARIANT, 0);
|
||||||
pBuilder.define(DATA_SYNCED_AGE, 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);
|
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() {
|
public int getTypeVariant() {
|
||||||
return this.entityData.get(VARIANT);
|
return this.entityData.get(VARIANT);
|
||||||
}
|
}
|
||||||
@@ -280,12 +333,16 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
public void addAdditionalSaveData(CompoundTag pCompound) {
|
public void addAdditionalSaveData(CompoundTag pCompound) {
|
||||||
super.addAdditionalSaveData(pCompound);
|
super.addAdditionalSaveData(pCompound);
|
||||||
pCompound.putInt("Variant", this.getTypeVariant());
|
pCompound.putInt("Variant", this.getTypeVariant());
|
||||||
|
pCompound.putFloat("AnimalScale", this.getAnimalScale());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readAdditionalSaveData(CompoundTag pCompound) {
|
public void readAdditionalSaveData(CompoundTag pCompound) {
|
||||||
super.readAdditionalSaveData(pCompound);
|
super.readAdditionalSaveData(pCompound);
|
||||||
this.entityData.set(VARIANT, pCompound.getInt("Variant"));
|
this.entityData.set(VARIANT, pCompound.getInt("Variant"));
|
||||||
|
if (pCompound.contains("AnimalScale")) {
|
||||||
|
this.setAnimalScale(pCompound.getFloat("AnimalScale"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*? if <=1.20.1 {*/
|
/*? 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) {
|
public SpawnGroupData finalizeSpawn(ServerLevelAccessor pLevel, DifficultyInstance pDifficulty, MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pDataTag) {
|
||||||
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||||
this.setVariant(variant);
|
this.setVariant(variant);
|
||||||
|
this.setAnimalScale(Mth.nextFloat(this.random, MIN_ANIMAL_SCALE, MAX_ANIMAL_SCALE));
|
||||||
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData, pDataTag);
|
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData, pDataTag);
|
||||||
}
|
}
|
||||||
/*?} else {*/
|
/*?} else {*/
|
||||||
@@ -300,6 +358,7 @@ public class AchillobatorEntity extends DinoEntityBase implements GeoEntity {
|
|||||||
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
|
public SpawnGroupData finalizeSpawn(ServerLevelAccessor level, DifficultyInstance difficulty, MobSpawnType spawnType, @Nullable SpawnGroupData spawnGroupData) {
|
||||||
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
AchillobatorVariant variant = Util.getRandom(AchillobatorVariant.values(), this.random);
|
||||||
this.setVariant(variant);
|
this.setVariant(variant);
|
||||||
|
this.setAnimalScale(Mth.nextFloat(this.random, MIN_ANIMAL_SCALE, MAX_ANIMAL_SCALE));
|
||||||
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
|
return super.finalizeSpawn(level, difficulty, spawnType, spawnGroupData);
|
||||||
}
|
}
|
||||||
*//*?}*/
|
*//*?}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user