remove World->isFullBlock(), add Block->isFullCube(), clean up some BB mess

This commit is contained in:
Dylan K. Taylor 2019-08-15 16:22:54 +01:00
parent e29ac514d7
commit 73b2669712
4 changed files with 16 additions and 20 deletions

View File

@ -83,6 +83,7 @@ This version features substantial changes to the network system, improving coher
- `Block->asItem()`: returns an itemstack corresponding to the block - `Block->asItem()`: returns an itemstack corresponding to the block
- `Block->isSameState()`: returns whether the block is the same as the parameter, including state information - `Block->isSameState()`: returns whether the block is the same as the parameter, including state information
- `Block->isSameType()`: returns whether the block is the same as the parameter, without state information - `Block->isSameType()`: returns whether the block is the same as the parameter, without state information
- `Block->isFullCube()`
- The following hooks have been added: - The following hooks have been added:
- `Block->onAttack()`: called when a player in survival left-clicks the block to try to start breaking it - `Block->onAttack()`: called when a player in survival left-clicks the block to try to start breaking it
- `Block->onPostPlace()`: called directly after placement in the world, handles things like rail connections and chest pairing - `Block->onPostPlace()`: called directly after placement in the world, handles things like rail connections and chest pairing
@ -673,7 +674,7 @@ This version features substantial changes to the network system, improving coher
- `World->unregisterChunkListener()` - `World->unregisterChunkListener()`
- The following API methods have been removed: - The following API methods have been removed:
- `ChunkLoader->getLoaderId()` (now object ID is used) - `ChunkLoader->getLoaderId()` (now object ID is used)
- `World->isFullBlock()`
- The following API methods have changed signatures: - The following API methods have changed signatures:
- `World->addParticle()` now has the signature `addParticle(Vector3 $pos, Particle $particle, ?Player[] $players = null) : void` - `World->addParticle()` now has the signature `addParticle(Vector3 $pos, Particle $particle, ?Player[] $players = null) : void`
- `World->addSound()` now has the signature `addSound(?Vector3 $pos, Sound $sound, ?Player[] $players = null) : void` - `World->addSound()` now has the signature `addSound(?Vector3 $pos, Sound $sound, ?Player[] $players = null) : void`

View File

@ -46,6 +46,7 @@ use pocketmine\world\Position;
use pocketmine\world\World; use pocketmine\world\World;
use function array_merge; use function array_merge;
use function assert; use function assert;
use function count;
use function dechex; use function dechex;
use const PHP_INT_MAX; use const PHP_INT_MAX;
@ -713,6 +714,15 @@ class Block{
return AxisAlignedBB::one(); return AxisAlignedBB::one();
} }
/**
* @return bool
*/
public function isFullCube() : bool{
$bb = $this->getCollisionBoxes();
return count($bb) === 1 and $bb[0]->getAverageEdgeLength() >= 1; //TODO: average length 1 != cube
}
/** /**
* @param Vector3 $pos1 * @param Vector3 $pos1
* @param Vector3 $pos2 * @param Vector3 $pos2

View File

@ -35,8 +35,7 @@ class Thin extends Transparent{
foreach(Facing::HORIZONTAL as $facing){ foreach(Facing::HORIZONTAL as $facing){
$side = $this->getSide($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 $side->isFullCube()){
if($side instanceof Thin or ($bb = $side->getBoundingBox()) !== null and $bb->getAverageEdgeLength() >= 1){
$this->connections[$facing] = true; $this->connections[$facing] = true;
}else{ }else{
unset($this->connections[$facing]); unset($this->connections[$facing]);

View File

@ -1120,20 +1120,6 @@ class World implements ChunkManager{
return $collides; return $collides;
} }
/**
* @param Block $pos
*
* @return bool
*/
public function isFullBlock(Block $pos) : bool{
if($pos->isSolid()){
return true;
}
$bb = $pos->getBoundingBox();
return $bb !== null and $bb->getAverageEdgeLength() >= 1;
}
/** /**
* @param Entity $entity * @param Entity $entity
* @param AxisAlignedBB $bb * @param AxisAlignedBB $bb
@ -2565,7 +2551,7 @@ class World implements ChunkManager{
$y = (int) min($max - 2, $v->y); $y = (int) min($max - 2, $v->y);
$wasAir = $this->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::AIR; //TODO: bad hack, clean up $wasAir = $this->getBlockAt($x, $y - 1, $z)->getId() === BlockLegacyIds::AIR; //TODO: bad hack, clean up
for(; $y > 0; --$y){ for(; $y > 0; --$y){
if($this->isFullBlock($this->getBlockAt($x, $y, $z))){ if($this->getBlockAt($x, $y, $z)->isFullCube()){
if($wasAir){ if($wasAir){
$y++; $y++;
break; break;
@ -2576,8 +2562,8 @@ class World implements ChunkManager{
} }
for(; $y >= 0 and $y < $max; ++$y){ for(; $y >= 0 and $y < $max; ++$y){
if(!$this->isFullBlock($this->getBlockAt($x, $y + 1, $z))){ if(!$this->getBlockAt($x, $y + 1, $z)->isFullCube()){
if(!$this->isFullBlock($this->getBlockAt($x, $y, $z))){ if(!$this->getBlockAt($x, $y, $z)->isFullCube()){
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this); return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this);
} }
}else{ }else{