Skip to content

Commit 0907aed

Browse files
committed
Fixed Entity/Block issues on negative coordinates, closes #2100
1 parent 0a29e66 commit 0907aed

File tree

5 files changed

+38
-39
lines changed

5 files changed

+38
-39
lines changed

src/pocketmine/entity/Entity.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use pocketmine\level\Level;
4040
use pocketmine\level\Position;
4141
use pocketmine\math\AxisAlignedBB;
42+
use pocketmine\math\Math;
4243
use pocketmine\math\Vector3 as Vector3;
4344
use pocketmine\metadata\Metadatable;
4445
use pocketmine\metadata\MetadataValue;
@@ -752,20 +753,13 @@ public function isInsideOfSolid(){
752753
$z = ((($i >> 2) % 2) - 0.5) * $this->width * 0.8;
753754
$block = $this->getLevel()->getBlock((new Vector3($this->x + $x, $this->y + $this->getEyeHeight() + $y, $this->z + $z))->floor());
754755

755-
if($block->isSolid){
756+
$bb = $block->getBoundingBox();
757+
758+
if($bb !== null and $block->isSolid and $bb->intersectsWith($this->getBoundingBox())){
756759
return true;
757760
}
758761
}
759762
return false;
760-
761-
$block = $this->getLevel()->getBlock($pos = (new Vector3($this->x, $y = ($this->y + $this->getEyeHeight()), $this->z))->floor());
762-
763-
if($block instanceof Water){
764-
$f = ($pos->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
765-
return $y < $f;
766-
}
767-
768-
return false;
769763
}
770764

771765
public function collision(){
@@ -994,12 +988,12 @@ public function move($dx, $dy, $dz){
994988
}
995989

996990
protected function checkBlockCollision(){
997-
$minX = floor($this->boundingBox->minX - 0.001);
998-
$minY = floor($this->boundingBox->minY - 0.001);
999-
$minZ = floor($this->boundingBox->minZ - 0.001);
1000-
$maxX = floor($this->boundingBox->maxX + 0.001);
1001-
$maxY = floor($this->boundingBox->maxY + 0.001);
1002-
$maxZ = floor($this->boundingBox->maxZ + 0.001);
991+
$minX = Math::floorFloat($this->boundingBox->minX - 0.001);
992+
$minY = Math::floorFloat($this->boundingBox->minY - 0.001);
993+
$minZ = Math::floorFloat($this->boundingBox->minZ - 0.001);
994+
$maxX = Math::floorFloat($this->boundingBox->maxX + 0.001);
995+
$maxY = Math::floorFloat($this->boundingBox->maxY + 0.001);
996+
$maxZ = Math::floorFloat($this->boundingBox->maxZ + 0.001);
1003997

1004998
for($z = $minZ; $z <= $maxZ; ++$z){
1005999
for($x = $minX; $x <= $maxX; ++$x){

src/pocketmine/entity/FallingBlock.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public function onUpdate(){
6969
return false;
7070
}
7171

72+
if($this->ticksLived === 1){
73+
$block = $this->level->getBlock($this->floor());
74+
if($block->getID() != $this->blockId){
75+
$this->kill();
76+
return true;
77+
}
78+
$this->level->setBlock($this->floor(), Block::get(0, true));
79+
80+
}
81+
7282
$this->motionY -= $this->gravity;
7383

7484
$this->move($this->motionX, $this->motionY, $this->motionZ);
@@ -81,16 +91,6 @@ public function onUpdate(){
8191

8292
$pos = $this->floor();
8393

84-
if($this->ticksLived === 1){
85-
$block = $this->level->getBlock($pos);
86-
if($block->getID() != $this->blockId){
87-
$this->kill();
88-
return true;
89-
}
90-
$this->level->setBlock($pos, Block::get(0, true));
91-
92-
}
93-
9494
if($this->onGround){
9595
$this->kill();
9696
$block = $this->level->getBlock($pos);

src/pocketmine/level/Level.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
use pocketmine\level\format\LevelProvider;
6868
use pocketmine\level\generator\Generator;
6969
use pocketmine\math\AxisAlignedBB;
70+
use pocketmine\math\Math;
7071
use pocketmine\math\Vector2;
7172
use pocketmine\math\Vector3;
7273
use pocketmine\metadata\BlockMetadataStore;
@@ -700,12 +701,12 @@ public function scheduleUpdate(Vector3 $pos, $delay){
700701
* @return Block[]
701702
*/
702703
public function getCollisionBlocks(AxisAlignedBB $bb){
703-
$minX = floor($bb->minX);
704-
$minY = floor($bb->minY);
705-
$minZ = floor($bb->minZ);
706-
$maxX = floor($bb->maxX + 1);
707-
$maxY = floor($bb->maxY + 1);
708-
$maxZ = floor($bb->maxZ + 1);
704+
$minX = Math::floorFloat($bb->minX);
705+
$minY = Math::floorFloat($bb->minY);
706+
$minZ = Math::floorFloat($bb->minZ);
707+
$maxX = Math::floorFloat($bb->maxX + 1);
708+
$maxY = Math::floorFloat($bb->maxY + 1);
709+
$maxZ = Math::floorFloat($bb->maxZ + 1);
709710

710711
$collides = [];
711712

@@ -738,12 +739,12 @@ public function isFullBlock(Vector3 $pos){
738739
* @return AxisAlignedBB[]
739740
*/
740741
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb){
741-
$minX = floor($bb->minX);
742-
$minY = floor($bb->minY);
743-
$minZ = floor($bb->minZ);
744-
$maxX = floor($bb->maxX + 1);
745-
$maxY = floor($bb->maxY + 1);
746-
$maxZ = floor($bb->maxZ + 1);
742+
$minX = Math::floorFloat($bb->minX);
743+
$minY = Math::floorFloat($bb->minY);
744+
$minZ = Math::floorFloat($bb->minZ);
745+
$maxX = Math::floorFloat($bb->maxX + 1);
746+
$maxY = Math::floorFloat($bb->maxY + 1);
747+
$maxZ = Math::floorFloat($bb->maxZ + 1);
747748

748749
$collides = [];
749750

src/pocketmine/math/Math.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727

2828
abstract class Math{
2929

30+
public static function floorFloat($n){
31+
$i = (int) $n;
32+
return $n >= $i ? $i : $i - 1;
33+
}
3034
}

src/pocketmine/math/Vector3.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function ceil(){
123123
}
124124

125125
public function floor(){
126-
return new Vector3((int) $this->x, (int) $this->y, (int) $this->z);
126+
return new Vector3(Math::floorFloat($this->x), Math::floorFloat($this->y), Math::floorFloat($this->z));
127127
}
128128

129129
public function round(){

0 commit comments

Comments
 (0)