mirror of
https://github.com/Minestom/Minestom.git
synced 2025-04-04 03:05:56 +02:00
Fix worldborder size on resize + test (#937)
This commit is contained in:
parent
6aa999aa77
commit
0d93faf0db
@ -210,14 +210,15 @@ public class WorldBorder {
|
||||
double diameterDelta = newDiameter - oldDiameter;
|
||||
long elapsedTime = System.currentTimeMillis() - lerpStartTime;
|
||||
double percentage = (double) elapsedTime / (double) speed;
|
||||
percentage = Math.max(percentage, 1);
|
||||
this.currentDiameter = oldDiameter + (diameterDelta * percentage);
|
||||
|
||||
// World border finished lerp
|
||||
if (percentage == 1) {
|
||||
if (percentage > 0.99) {
|
||||
this.lerpStartTime = 0;
|
||||
this.speed = 0;
|
||||
this.oldDiameter = newDiameter;
|
||||
this.currentDiameter = newDiameter;
|
||||
} else {
|
||||
this.currentDiameter = oldDiameter + (diameterDelta * percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.api.Env;
|
||||
import net.minestom.server.api.EnvTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@EnvTest
|
||||
public class WorldBorderIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void setWorldborderSize(Env env) {
|
||||
Instance instance = env.createFlatInstance();
|
||||
|
||||
instance.getWorldBorder().setDiameter(50.0);
|
||||
assertEquals(50.0, instance.getWorldBorder().getDiameter());
|
||||
instance.getWorldBorder().setDiameter(10.0);
|
||||
assertEquals(10.0, instance.getWorldBorder().getDiameter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resizeWorldBorder(Env env) throws InterruptedException {
|
||||
Instance instance = env.createFlatInstance();
|
||||
|
||||
instance.getWorldBorder().setDiameter(50.0);
|
||||
|
||||
instance.getWorldBorder().setDiameter(10.0, 1);
|
||||
assertEquals(50.0, instance.getWorldBorder().getDiameter());
|
||||
|
||||
Thread.sleep(10);
|
||||
instance.getWorldBorder().update();
|
||||
assertEquals(10.0, instance.getWorldBorder().getDiameter());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user