Further cleanup to general AABB handling

This commit is contained in:
Dylan K. Taylor 2018-11-24 19:17:03 +00:00
parent d5ae4ad141
commit b2201c8c59
25 changed files with 36 additions and 58 deletions

View File

@ -74,10 +74,7 @@ class Anvil extends Fallable{
} }
public function recalculateBoundingBox() : ?AxisAlignedBB{ public function recalculateBoundingBox() : ?AxisAlignedBB{
$inset = 0.125; return AxisAlignedBB::one()->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, false)), 1 / 8);
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
return $bb->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, false)), $inset);
} }
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{

View File

@ -80,7 +80,7 @@ class Bed extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 0.5625, 1); return AxisAlignedBB::one()->trim(Facing::UP, 7 / 16);
} }
public function isHeadPart() : bool{ public function isHeadPart() : bool{

View File

@ -714,7 +714,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return AxisAlignedBB|null * @return AxisAlignedBB|null
*/ */
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 1, 1); return AxisAlignedBB::one();
} }
/** /**

View File

@ -69,8 +69,8 @@ class Cactus extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
static $shrinkSize = 0.0625; static $shrinkSize = 1 / 16;
return new AxisAlignedBB($shrinkSize, $shrinkSize, $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize); return AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize);
} }
public function onEntityCollide(Entity $entity) : void{ public function onEntityCollide(Entity $entity) : void{

View File

@ -66,16 +66,10 @@ class Cake extends Transparent implements FoodSource{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$f = $this->bites * 0.125; //1 slice width return AxisAlignedBB::one()
->contract(1 / 16, 0, 1 / 16)
return new AxisAlignedBB( ->trim(Facing::UP, 0.5)
0.0625 + $f, ->trim(Facing::WEST, $this->bites / 8);
0,
0.0625,
1 - 0.0625,
0.5,
1 - 0.0625
);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -40,7 +40,7 @@ class Carpet extends Flowable{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 0.0625, 1); return AxisAlignedBB::one()->trim(Facing::UP, 15 / 16);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -69,7 +69,7 @@ class Chest extends Transparent{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
//these are slightly bigger than in PC //these are slightly bigger than in PC
return new AxisAlignedBB(0.025, 0, 0.025, 0.975, 0.95, 0.975); return AxisAlignedBB::one()->contract(0.025, 0, 0.025)->trim(Facing::UP, 0.05);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -74,10 +74,10 @@ class CocoaBlock extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$bb = new AxisAlignedBB(0, (7 - $this->age * 2) / 16, 0, 1, 0.75, 1); return AxisAlignedBB::one()
return $bb
->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, true)), (6 - $this->age) / 16) //sides ->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, true)), (6 - $this->age) / 16) //sides
->trim(Facing::DOWN, (7 - $this->age * 2) / 16)
->trim(Facing::UP, 0.25)
->trim(Facing::opposite($this->facing), 1 / 16) //gap between log and pod ->trim(Facing::opposite($this->facing), 1 / 16) //gap between log and pod
->trim($this->facing, (11 - $this->age * 2) / 16); //outward face ->trim($this->facing, (11 - $this->age * 2) / 16); //outward face
} }

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\Player; use pocketmine\Player;
class DaylightSensor extends Transparent{ class DaylightSensor extends Transparent{
@ -82,7 +83,7 @@ class DaylightSensor extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 0.5, 1); return AxisAlignedBB::one()->trim(Facing::UP, 0.5);
} }
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{

View File

@ -93,8 +93,9 @@ abstract class Door extends Transparent{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$this->updateStateFromOtherHalf(); $this->updateStateFromOtherHalf();
$bb = new AxisAlignedBB(0, 0, 0, 1, 2, 1); return AxisAlignedBB::one()
return $bb->trim($this->open ? Facing::rotate($this->facing, Facing::AXIS_Y, !$this->hingeRight) : $this->facing, 13 / 16); ->extend(Facing::UP, 1)
->trim($this->open ? Facing::rotate($this->facing, Facing::AXIS_Y, !$this->hingeRight) : $this->facing, 13 / 16);
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{

View File

@ -27,6 +27,7 @@ use pocketmine\inventory\EnchantInventory;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\item\TieredTool; use pocketmine\item\TieredTool;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\Player; use pocketmine\Player;
use pocketmine\tile\EnchantTable as TileEnchantTable; use pocketmine\tile\EnchantTable as TileEnchantTable;
@ -70,7 +71,7 @@ class EnchantingTable extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 0.75, 1); return AxisAlignedBB::one()->trim(Facing::UP, 0.25);
} }
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{

View File

@ -77,14 +77,7 @@ class EndPortalFrame extends Solid{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB( return AxisAlignedBB::one()->trim(Facing::UP, 3 / 16);
0,
0,
0,
1,
$this->eye ? 1 : 0.8125,
1
);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -83,7 +83,7 @@ class EndRod extends Flowable{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$myAxis = Facing::axis($this->facing); $myAxis = Facing::axis($this->facing);
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); $bb = AxisAlignedBB::one();
foreach([Facing::AXIS_Y, Facing::AXIS_Z, Facing::AXIS_X] as $axis){ foreach([Facing::AXIS_Y, Facing::AXIS_Z, Facing::AXIS_X] as $axis){
if($axis === $myAxis){ if($axis === $myAxis){
continue; continue;

View File

@ -64,7 +64,7 @@ class Farmland extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 1, 1); //TODO: y max should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) return AxisAlignedBB::one(); //TODO: this should be trimmed at the top by 1/16, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
} }
public function onNearbyBlockChange() : void{ public function onNearbyBlockChange() : void{

View File

@ -64,8 +64,7 @@ class FenceGate extends Transparent{
return null; return null;
} }
$bb = new AxisAlignedBB(0, 0, 0, 1, 1.5, 1); return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16);
return $bb->squash(Facing::axis($this->facing), 6 / 16);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -60,8 +60,7 @@ class FlowerPot extends Flowable{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
static $f = 0.3125; return AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8);
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.375, 1 - $f);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -45,7 +45,7 @@ class GrassPath extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 1, 1); //TODO: y max should be 0.9375, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109) return AxisAlignedBB::one(); //TODO: this should be trimmed at the top by 1/16, but MCPE currently treats them as a full block (https://bugs.mojang.com/browse/MCPE-12109)
} }
public function getHardness() : float{ public function getHardness() : float{

View File

@ -79,8 +79,7 @@ class Ladder extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); return AxisAlignedBB::one()->trim($this->facing, 13 / 16);
return $bb->trim($this->facing, 13 / 16);
} }

View File

@ -65,8 +65,7 @@ class Skull extends Flowable{
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
//TODO: different bounds depending on attached face //TODO: different bounds depending on attached face
static $f = 0.25; return AxisAlignedBB::one()->contract(0.25, 0, 0.25)->trim(Facing::UP, 0.5);
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.5, 1 - $f);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -101,10 +101,6 @@ abstract class Slab extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
if($this->top){ return AxisAlignedBB::one()->trim($this->top ? Facing::DOWN : Facing::UP, 0.5);
return new AxisAlignedBB(0, 0.5, 0, 1, 1, 1);
}else{
return new AxisAlignedBB(0, 0, 0, 1, 0.5, 1);
}
} }
} }

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
class SoulSand extends Solid{ class SoulSand extends Solid{
@ -46,6 +47,6 @@ class SoulSand extends Solid{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
return new AxisAlignedBB(0, 0, 0, 1, 1 - 0.125, 1); return AxisAlignedBB::one()->trim(Facing::UP, 1 / 8);
} }
} }

View File

@ -73,8 +73,7 @@ class Trapdoor extends Transparent{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1); return AxisAlignedBB::one()->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16);
return $bb->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -46,8 +46,7 @@ class WaterLily extends Flowable{
} }
protected function recalculateBoundingBox() : ?AxisAlignedBB{ protected function recalculateBoundingBox() : ?AxisAlignedBB{
static $f = 0.0625; return AxisAlignedBB::one()->contract(1 / 16, 0, 1 / 16)->trim(Facing::UP, 63 / 64);
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.015625, 1 - $f);
} }
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{ public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{

View File

@ -238,7 +238,7 @@ class Explosion{
$ev = new BlockUpdateEvent($this->level->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z)); $ev = new BlockUpdateEvent($this->level->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z));
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
foreach($this->level->getNearbyEntities(new AxisAlignedBB($sideBlock->x - 1, $sideBlock->y - 1, $sideBlock->z - 1, $sideBlock->x + 2, $sideBlock->y + 2, $sideBlock->z + 2)) as $entity){ foreach($this->level->getNearbyEntities(AxisAlignedBB::one()->offset($sideBlock->x, $sideBlock->y, $sideBlock->z)->expand(1, 1, 1)) as $entity){
$entity->onNearbyBlockChange(); $entity->onNearbyBlockChange();
} }
$ev->getBlock()->onNearbyBlockChange(); $ev->getBlock()->onNearbyBlockChange();

View File

@ -1546,7 +1546,7 @@ class Level implements ChunkManager, Metadatable{
$ev = new BlockUpdateEvent($block); $ev = new BlockUpdateEvent($block);
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
foreach($this->getNearbyEntities(new AxisAlignedBB($block->x - 1, $block->y - 1, $block->z - 1, $block->x + 2, $block->y + 2, $block->z + 2)) as $entity){ foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($block->x, $block->y, $block->z)->expand(1, 1, 1)) as $entity){
$entity->onNearbyBlockChange(); $entity->onNearbyBlockChange();
} }
$ev->getBlock()->onNearbyBlockChange(); $ev->getBlock()->onNearbyBlockChange();