mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Further cleanup to general AABB handling
This commit is contained in:
parent
d5ae4ad141
commit
b2201c8c59
@ -74,10 +74,7 @@ class Anvil extends Fallable{
|
||||
}
|
||||
|
||||
public function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$inset = 0.125;
|
||||
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||
return $bb->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, false)), $inset);
|
||||
return AxisAlignedBB::one()->squash(Facing::axis(Facing::rotate($this->facing, Facing::AXIS_Y, false)), 1 / 8);
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
|
@ -80,7 +80,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -714,7 +714,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
* @return AxisAlignedBB|null
|
||||
*/
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
return new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||
return AxisAlignedBB::one();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,8 +69,8 @@ class Cactus extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
static $shrinkSize = 0.0625;
|
||||
return new AxisAlignedBB($shrinkSize, $shrinkSize, $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize, 1 - $shrinkSize);
|
||||
static $shrinkSize = 1 / 16;
|
||||
return AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize);
|
||||
}
|
||||
|
||||
public function onEntityCollide(Entity $entity) : void{
|
||||
|
@ -66,16 +66,10 @@ class Cake extends Transparent implements FoodSource{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$f = $this->bites * 0.125; //1 slice width
|
||||
|
||||
return new AxisAlignedBB(
|
||||
0.0625 + $f,
|
||||
0,
|
||||
0.0625,
|
||||
1 - 0.0625,
|
||||
0.5,
|
||||
1 - 0.0625
|
||||
);
|
||||
return AxisAlignedBB::one()
|
||||
->contract(1 / 16, 0, 1 / 16)
|
||||
->trim(Facing::UP, 0.5)
|
||||
->trim(Facing::WEST, $this->bites / 8);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -40,7 +40,7 @@ class Carpet extends Flowable{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -69,7 +69,7 @@ class Chest extends Transparent{
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
//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{
|
||||
|
@ -74,10 +74,10 @@ class CocoaBlock extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$bb = new AxisAlignedBB(0, (7 - $this->age * 2) / 16, 0, 1, 0.75, 1);
|
||||
|
||||
return $bb
|
||||
return AxisAlignedBB::one()
|
||||
->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($this->facing, (11 - $this->age * 2) / 16); //outward face
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\Player;
|
||||
|
||||
class DaylightSensor extends Transparent{
|
||||
@ -82,7 +83,7 @@ class DaylightSensor extends Transparent{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -93,8 +93,9 @@ abstract class Door extends Transparent{
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$this->updateStateFromOtherHalf();
|
||||
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, 2, 1);
|
||||
return $bb->trim($this->open ? Facing::rotate($this->facing, Facing::AXIS_Y, !$this->hingeRight) : $this->facing, 13 / 16);
|
||||
return AxisAlignedBB::one()
|
||||
->extend(Facing::UP, 1)
|
||||
->trim($this->open ? Facing::rotate($this->facing, Facing::AXIS_Y, !$this->hingeRight) : $this->facing, 13 / 16);
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
|
@ -27,6 +27,7 @@ use pocketmine\inventory\EnchantInventory;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\TieredTool;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\tile\EnchantTable as TileEnchantTable;
|
||||
@ -70,7 +71,7 @@ class EnchantingTable extends Transparent{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -77,14 +77,7 @@ class EndPortalFrame extends Solid{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
return new AxisAlignedBB(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
$this->eye ? 1 : 0.8125,
|
||||
1
|
||||
);
|
||||
return AxisAlignedBB::one()->trim(Facing::UP, 3 / 16);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -83,7 +83,7 @@ class EndRod extends Flowable{
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$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){
|
||||
if($axis === $myAxis){
|
||||
continue;
|
||||
|
@ -64,7 +64,7 @@ class Farmland extends Transparent{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -64,8 +64,7 @@ class FenceGate extends Transparent{
|
||||
return null;
|
||||
}
|
||||
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, 1.5, 1);
|
||||
return $bb->squash(Facing::axis($this->facing), 6 / 16);
|
||||
return AxisAlignedBB::one()->extend(Facing::UP, 0.5)->squash(Facing::axis($this->facing), 6 / 16);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -60,8 +60,7 @@ class FlowerPot extends Flowable{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
static $f = 0.3125;
|
||||
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.375, 1 - $f);
|
||||
return AxisAlignedBB::one()->contract(3 / 16, 0, 3 / 16)->trim(Facing::UP, 5 / 8);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -45,7 +45,7 @@ class GrassPath extends Transparent{
|
||||
}
|
||||
|
||||
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{
|
||||
|
@ -79,8 +79,7 @@ class Ladder extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||
return $bb->trim($this->facing, 13 / 16);
|
||||
return AxisAlignedBB::one()->trim($this->facing, 13 / 16);
|
||||
}
|
||||
|
||||
|
||||
|
@ -65,8 +65,7 @@ class Skull extends Flowable{
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
//TODO: different bounds depending on attached face
|
||||
static $f = 0.25;
|
||||
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.5, 1 - $f);
|
||||
return AxisAlignedBB::one()->contract(0.25, 0, 0.25)->trim(Facing::UP, 0.5);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -101,10 +101,6 @@ abstract class Slab extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
if($this->top){
|
||||
return new AxisAlignedBB(0, 0.5, 0, 1, 1, 1);
|
||||
}else{
|
||||
return new AxisAlignedBB(0, 0, 0, 1, 0.5, 1);
|
||||
}
|
||||
return AxisAlignedBB::one()->trim($this->top ? Facing::DOWN : Facing::UP, 0.5);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
|
||||
class SoulSand extends Solid{
|
||||
|
||||
@ -46,6 +47,6 @@ class SoulSand extends Solid{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
return new AxisAlignedBB(0, 0, 0, 1, 1 - 0.125, 1);
|
||||
return AxisAlignedBB::one()->trim(Facing::UP, 1 / 8);
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +73,7 @@ class Trapdoor extends Transparent{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||
return $bb->trim($this->open ? $this->facing : ($this->top ? Facing::DOWN : Facing::UP), 13 / 16);
|
||||
return AxisAlignedBB::one()->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{
|
||||
|
@ -46,8 +46,7 @@ class WaterLily extends Flowable{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||
static $f = 0.0625;
|
||||
return new AxisAlignedBB($f, 0, $f, 1 - $f, 0.015625, 1 - $f);
|
||||
return AxisAlignedBB::one()->contract(1 / 16, 0, 1 / 16)->trim(Facing::UP, 63 / 64);
|
||||
}
|
||||
|
||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, Player $player = null) : bool{
|
||||
|
@ -238,7 +238,7 @@ class Explosion{
|
||||
$ev = new BlockUpdateEvent($this->level->getBlockAt($sideBlock->x, $sideBlock->y, $sideBlock->z));
|
||||
$ev->call();
|
||||
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();
|
||||
}
|
||||
$ev->getBlock()->onNearbyBlockChange();
|
||||
|
@ -1546,7 +1546,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$ev = new BlockUpdateEvent($block);
|
||||
$ev->call();
|
||||
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();
|
||||
}
|
||||
$ev->getBlock()->onNearbyBlockChange();
|
||||
|
Loading…
x
Reference in New Issue
Block a user