Skip to content

Commit bdde553

Browse files
committed
Added workaround for wrong positions when changing the scale
1 parent 82fd012 commit bdde553

File tree

2 files changed

+60
-39
lines changed

2 files changed

+60
-39
lines changed

src/main/java/info/ata4/minecraft/dragon/server/entity/EntityTameableDragon.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,15 @@ public double getAttackDamage() {
912912
* @param scale
913913
*/
914914
public void setScalePublic(float scale) {
915+
double posXTmp = posX;
916+
double posYTmp = posY;
917+
double posZTmp = posZ;
918+
915919
setScale(scale);
920+
921+
// workaround for a vanilla bug; the position is apparently not set correcty
922+
// after changing the entity size, causing asynchronous server/client positioning
923+
setPosition(posXTmp, posYTmp, posZTmp);
916924
}
917925

918926
@Override

src/main/java/info/ata4/minecraft/dragon/server/entity/helper/DragonLifeStageHelper.java

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ public DragonLifeStage getLifeStage() {
8989
public float getScale() {
9090
// constant size for egg stage
9191
if (isEgg()) {
92-
return 0.20f;
92+
return 0.9f / EntityTameableDragon.BASE_WIDTH;
9393
}
9494

95+
// use relative distance from the current age to the egg age as scale
9596
return 1 - (dragon.getGrowingAge() / (float) DragonLifeStage.EGG.ageLimit);
9697
}
9798

@@ -121,12 +122,12 @@ public void transformToEgg() {
121122
/**
122123
* Sets a new life stage for the dragon.
123124
*
124-
* @param lifeStage new life stage
125+
* @param lifeStage
125126
*/
126127
public final void setLifeStage(DragonLifeStage lifeStage) {
127128
L.trace("setLifeStage({})", lifeStage);
128-
// onNewLifeStage will be triggered next tick
129129
dragon.setGrowingAge(lifeStage.ageLimit);
130+
updateLifeStage();
130131
}
131132

132133
/**
@@ -180,54 +181,66 @@ public void onLivingUpdate() {
180181
// dragon.setGrowingAge((int) ((((Math.sin(Math.toRadians(dragon.ticksExisted))) + 1) * 0.5) * EGG.ageLimit));
181182
// }
182183

184+
updateLifeStage();
185+
updateEgg();
186+
updateScale();
187+
}
188+
189+
private void updateLifeStage() {
183190
// trigger event when a new life stage was reached
184191
DragonLifeStage lifeStage = getLifeStage();
185192
if (lifeStagePrev != lifeStage) {
186193
onNewLifeStage(lifeStage, lifeStagePrev);
187194
lifeStagePrev = lifeStage;
188195
}
196+
}
197+
198+
private void updateEgg() {
199+
if (!isEgg()) {
200+
return;
201+
}
189202

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();
216220
}
217221

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+
}
226228
}
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);
229238
}
230239

240+
private void updateScale() {
241+
dragon.setScalePublic(getScale());
242+
}
243+
231244
@Override
232245
public void onDeath() {
233246
if (dragon.isClient() && isEgg()) {

0 commit comments

Comments
 (0)