mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 06:09:57 +00:00
Make Thin use dynamic state properties
This commit is contained in:
parent
0fec58730b
commit
fcd81ada04
@ -27,80 +27,71 @@ use pocketmine\math\AxisAlignedBB;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
|
||||||
abstract class Thin extends Transparent{
|
abstract class Thin extends Transparent{
|
||||||
|
/** @var bool[] facing => dummy */
|
||||||
|
protected $connections = [];
|
||||||
|
|
||||||
|
public function readStateFromWorld() : void{
|
||||||
|
parent::readStateFromWorld();
|
||||||
|
|
||||||
|
foreach(Facing::HORIZONTAL as $facing){
|
||||||
|
$side = $this->getSide($facing);
|
||||||
|
//FIXME: currently there's no proper way to tell if a block is a full-block, so we check the bounding box size
|
||||||
|
if($side instanceof Thin or ($bb = $side->getBoundingBox()) !== null and $bb->getAverageEdgeLength() >= 1){
|
||||||
|
$this->connections[$facing] = true;
|
||||||
|
}else{
|
||||||
|
unset($this->connections[$facing]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||||
$width = 0.5 - 0.125 / 2;
|
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||||
|
foreach(Facing::HORIZONTAL as $facing){
|
||||||
return new AxisAlignedBB(
|
if(!isset($this->connections[$facing])){
|
||||||
($this->canConnect($this->getSide(Facing::WEST)) ? 0 : $width),
|
$bb->trim($facing, 7 / 16);
|
||||||
0,
|
}
|
||||||
($this->canConnect($this->getSide(Facing::NORTH)) ? 0 : $width),
|
}
|
||||||
1 - ($this->canConnect($this->getSide(Facing::EAST)) ? 0 : $width),
|
return $bb;
|
||||||
1,
|
|
||||||
1 - ($this->canConnect($this->getSide(Facing::SOUTH)) ? 0 : $width)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateCollisionBoxes() : array{
|
protected function recalculateCollisionBoxes() : array{
|
||||||
$inset = 0.5 - 0.125 / 2;
|
$inset = 7 / 16;
|
||||||
|
|
||||||
/** @var AxisAlignedBB[] $bbs */
|
/** @var AxisAlignedBB[] $bbs */
|
||||||
$bbs = [];
|
$bbs = [];
|
||||||
|
|
||||||
$connectWest = $this->canConnect($this->getSide(Facing::WEST));
|
if(isset($this->connections[Facing::WEST]) or isset($this->connections[Facing::EAST])){
|
||||||
$connectEast = $this->canConnect($this->getSide(Facing::EAST));
|
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||||
|
$bb->squash(Facing::AXIS_Z, $inset);
|
||||||
|
|
||||||
if($connectWest or $connectEast){
|
if(!isset($this->connections[Facing::WEST])){
|
||||||
//X axis (west/east)
|
$bb->trim(Facing::WEST, $inset);
|
||||||
$bbs[] = new AxisAlignedBB(
|
}elseif(!isset($this->connections[Facing::EAST])){
|
||||||
($connectWest ? 0 : $inset),
|
$bb->trim(Facing::EAST, $inset);
|
||||||
0,
|
}
|
||||||
$inset,
|
$bbs[] = $bb;
|
||||||
1 - ($connectEast ? 0 : $inset),
|
|
||||||
1,
|
|
||||||
1 - $inset
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$connectNorth = $this->canConnect($this->getSide(Facing::NORTH));
|
if(isset($this->connections[Facing::NORTH]) or isset($this->connections[Facing::SOUTH])){
|
||||||
$connectSouth = $this->canConnect($this->getSide(Facing::SOUTH));
|
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||||
|
$bb->squash(Facing::AXIS_X, $inset);
|
||||||
|
|
||||||
if($connectNorth or $connectSouth){
|
if(!isset($this->connections[Facing::NORTH])){
|
||||||
//Z axis (north/south)
|
$bb->trim(Facing::NORTH, $inset);
|
||||||
$bbs[] = new AxisAlignedBB(
|
}elseif(!isset($this->connections[Facing::SOUTH])){
|
||||||
$inset,
|
$bb->trim(Facing::SOUTH, $inset);
|
||||||
0,
|
}
|
||||||
($connectNorth ? 0 : $inset),
|
$bbs[] = $bb;
|
||||||
1 - $inset,
|
|
||||||
1,
|
|
||||||
1 - ($connectSouth ? 0 : $inset)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($bbs)){
|
if(empty($bbs)){
|
||||||
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
|
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
|
||||||
|
$bb = new AxisAlignedBB(0, 0, 0, 1, 1, 1);
|
||||||
return [
|
return [
|
||||||
new AxisAlignedBB(
|
$bb->contract($inset, 0, $inset)
|
||||||
$inset,
|
|
||||||
0,
|
|
||||||
$inset,
|
|
||||||
1 - $inset,
|
|
||||||
1,
|
|
||||||
1 - $inset
|
|
||||||
)
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bbs;
|
return $bbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canConnect(Block $block) : bool{
|
|
||||||
if($block instanceof Thin){
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME: currently there's no proper way to tell if a block is a full-block, so we check the bounding box size
|
|
||||||
$bb = $block->getBoundingBox();
|
|
||||||
return $bb !== null and $bb->getAverageEdgeLength() >= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user