Fixed a wide range of bugs with floating-point coordinates getting incorrectly int-casted

This causes lots of bugs in negative coordinates.

This fixes #1789 after world load & save.
This commit is contained in:
Dylan K. Taylor
2018-02-15 10:27:42 +00:00
parent 4e9e285e37
commit e7e4645c0b
7 changed files with 31 additions and 29 deletions

View File

@ -233,7 +233,7 @@ class Explosion{
$pk->position = $this->source->asVector3();
$pk->radius = $this->size;
$pk->records = $send;
$this->level->addChunkPacket($source->x >> 4, $source->z >> 4, $pk);
$this->level->addChunkPacket($source->getFloorX() >> 4, $source->getFloorZ() >> 4, $pk);
$this->level->addParticle(new HugeExplodeSeedParticle($source));
$this->level->broadcastLevelSoundEvent($source, LevelSoundEventPacket::SOUND_EXPLODE);

View File

@ -478,7 +478,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){
foreach($pk as $e){
$this->addChunkPacket($sound->x >> 4, $sound->z >> 4, $e);
$this->addChunkPacket($sound->getFloorX() >> 4, $sound->getFloorZ() >> 4, $e);
}
}else{
$this->server->batchPackets($players, $pk, false);
@ -493,7 +493,7 @@ class Level implements ChunkManager, Metadatable{
if($players === null){
foreach($pk as $e){
$this->addChunkPacket($particle->x >> 4, $particle->z >> 4, $e);
$this->addChunkPacket($particle->getFloorX() >> 4, $particle->getFloorZ() >> 4, $e);
}
}else{
$this->server->batchPackets($players, $pk, false);
@ -513,7 +513,7 @@ class Level implements ChunkManager, Metadatable{
$pk->data = $data;
if($pos !== null){
$pk->position = $pos->asVector3();
$this->addChunkPacket($pos->x >> 4, $pos->z >> 4, $pk);
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk);
}else{
$pk->position = null;
$this->addGlobalPacket($pk);
@ -538,7 +538,7 @@ class Level implements ChunkManager, Metadatable{
$pk->unknownBool = $unknown;
$pk->disableRelativeVolume = $disableRelativeVolume;
$pk->position = $pos->asVector3();
$this->addChunkPacket($pos->x >> 4, $pos->z >> 4, $pk);
$this->addChunkPacket($pos->getFloorX() >> 4, $pos->getFloorZ() >> 4, $pk);
}
public function getAutoSave() : bool{
@ -987,8 +987,8 @@ class Level implements ChunkManager, Metadatable{
$randRange = (int) ($randRange > $this->chunkTickRadius ? $this->chunkTickRadius : $randRange);
foreach($this->loaders as $loader){
$chunkX = $loader->getX() >> 4;
$chunkZ = $loader->getZ() >> 4;
$chunkX = (int) floor($loader->getX()) >> 4;
$chunkZ = (int) floor($loader->getZ()) >> 4;
$index = Level::chunkHash($chunkX, $chunkZ);
$existingLoaders = max(0, $this->chunkTickList[$index] ?? 0);

View File

@ -89,9 +89,9 @@ abstract class BaseLevelProvider implements LevelProvider{
}
public function setSpawn(Vector3 $pos){
$this->levelData->setInt("SpawnX", (int) $pos->x);
$this->levelData->setInt("SpawnY", (int) $pos->y);
$this->levelData->setInt("SpawnZ", (int) $pos->z);
$this->levelData->setInt("SpawnX", $pos->getFloorX());
$this->levelData->setInt("SpawnY", $pos->getFloorY());
$this->levelData->setInt("SpawnZ", $pos->getFloorZ());
}
public function doGarbageCollection(){