@@ -89,9 +89,10 @@ public DragonLifeStage getLifeStage() {
89
89
public float getScale () {
90
90
// constant size for egg stage
91
91
if (isEgg ()) {
92
- return 0.20f ;
92
+ return 0.9f / EntityTameableDragon . BASE_WIDTH ;
93
93
}
94
94
95
+ // use relative distance from the current age to the egg age as scale
95
96
return 1 - (dragon .getGrowingAge () / (float ) DragonLifeStage .EGG .ageLimit );
96
97
}
97
98
@@ -121,12 +122,12 @@ public void transformToEgg() {
121
122
/**
122
123
* Sets a new life stage for the dragon.
123
124
*
124
- * @param lifeStage new life stage
125
+ * @param lifeStage
125
126
*/
126
127
public final void setLifeStage (DragonLifeStage lifeStage ) {
127
128
L .trace ("setLifeStage({})" , lifeStage );
128
- // onNewLifeStage will be triggered next tick
129
129
dragon .setGrowingAge (lifeStage .ageLimit );
130
+ updateLifeStage ();
130
131
}
131
132
132
133
/**
@@ -180,54 +181,66 @@ public void onLivingUpdate() {
180
181
// dragon.setGrowingAge((int) ((((Math.sin(Math.toRadians(dragon.ticksExisted))) + 1) * 0.5) * EGG.ageLimit));
181
182
// }
182
183
184
+ updateLifeStage ();
185
+ updateEgg ();
186
+ updateScale ();
187
+ }
188
+
189
+ private void updateLifeStage () {
183
190
// trigger event when a new life stage was reached
184
191
DragonLifeStage lifeStage = getLifeStage ();
185
192
if (lifeStagePrev != lifeStage ) {
186
193
onNewLifeStage (lifeStage , lifeStagePrev );
187
194
lifeStagePrev = lifeStage ;
188
195
}
196
+ }
197
+
198
+ private void updateEgg () {
199
+ if (!isEgg ()) {
200
+ return ;
201
+ }
189
202
190
- if (isEgg ()) {
191
- int age = dragon .getGrowingAge ();
192
-
193
- // animate egg wiggle based on the time the eggs take to hatch
194
- int eggAge = DragonLifeStage .EGG .ageLimit ;
195
- int hatchAge = DragonLifeStage .HATCHLING .ageLimit ;
196
- float chance = (age - eggAge ) / (float ) (hatchAge - eggAge );
197
-
198
- // wait until the egg is nearly hatched
199
- if (chance > 0.66f ) {
200
- // reduce chance so it can run every tick
201
- chance /= 60 ;
202
-
203
- if (eggWiggleX > 0 ) {
204
- eggWiggleX --;
205
- } else if (rand .nextFloat () < chance ) {
206
- eggWiggleX = rand .nextBoolean () ? 10 : 20 ;
207
- playEggCrackEffect ();
208
- }
209
-
210
- if (eggWiggleZ > 0 ) {
211
- eggWiggleZ --;
212
- } else if (rand .nextFloat () < chance ) {
213
- eggWiggleZ = rand .nextBoolean () ? 10 : 20 ;
214
- playEggCrackEffect ();
215
- }
203
+ int age = dragon .getGrowingAge ();
204
+
205
+ // animate egg wiggle based on the time the eggs take to hatch
206
+ int eggAge = DragonLifeStage .EGG .ageLimit ;
207
+ int hatchAge = DragonLifeStage .HATCHLING .ageLimit ;
208
+ float chance = (age - eggAge ) / (float ) (hatchAge - eggAge );
209
+
210
+ // wait until the egg is nearly hatched
211
+ if (chance > 0.66f ) {
212
+ // reduce chance so it can run every tick
213
+ chance /= 60 ;
214
+
215
+ if (eggWiggleX > 0 ) {
216
+ eggWiggleX --;
217
+ } else if (rand .nextFloat () < chance ) {
218
+ eggWiggleX = rand .nextBoolean () ? 10 : 20 ;
219
+ playEggCrackEffect ();
216
220
}
217
221
218
- // spawn generic particles
219
- double px = dragon .posX + (rand .nextDouble () - 0.5 );
220
- double py = dragon .posY + (rand .nextDouble () - 0.5 );
221
- double pz = dragon .posZ + (rand .nextDouble () - 0.5 );
222
- double ox = (rand .nextDouble () - 0.5 ) * 2 ;
223
- double oy = (rand .nextDouble () - 0.5 ) * 2 ;
224
- double oz = (rand .nextDouble () - 0.5 ) * 2 ;
225
- dragon .worldObj .spawnParticle ("portal" , px , py , pz , ox , oy , oz );
222
+ if (eggWiggleZ > 0 ) {
223
+ eggWiggleZ --;
224
+ } else if (rand .nextFloat () < chance ) {
225
+ eggWiggleZ = rand .nextBoolean () ? 10 : 20 ;
226
+ playEggCrackEffect ();
227
+ }
226
228
}
227
-
228
- dragon .setScalePublic (getScale ());
229
+
230
+ // spawn generic particles
231
+ double px = dragon .posX + (rand .nextDouble () - 0.5 );
232
+ double py = dragon .posY + (rand .nextDouble () - 0.5 );
233
+ double pz = dragon .posZ + (rand .nextDouble () - 0.5 );
234
+ double ox = (rand .nextDouble () - 0.5 ) * 2 ;
235
+ double oy = (rand .nextDouble () - 0.5 ) * 2 ;
236
+ double oz = (rand .nextDouble () - 0.5 ) * 2 ;
237
+ dragon .worldObj .spawnParticle ("portal" , px , py , pz , ox , oy , oz );
229
238
}
230
239
240
+ private void updateScale () {
241
+ dragon .setScalePublic (getScale ());
242
+ }
243
+
231
244
@ Override
232
245
public void onDeath () {
233
246
if (dragon .isClient () && isEgg ()) {
0 commit comments