mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-17 11:18:52 +00:00
Improved checks, area collision checks, etc
This commit is contained in:
parent
f20d5b2c69
commit
74917923b6
@ -268,7 +268,7 @@ class Block extends Position implements Metadatable{
|
||||
protected $meta = 0;
|
||||
|
||||
/** @var AxisAlignedBB */
|
||||
protected $boundingBox = null;
|
||||
public $boundingBox = null;
|
||||
|
||||
/**
|
||||
* Backwards-compatibility with old way to define block properties
|
||||
@ -724,11 +724,11 @@ class Block extends Position implements Metadatable{
|
||||
* @return array
|
||||
*/
|
||||
public function getDrops(Item $item){
|
||||
if(!isset(self::$list[$this->id])){ //Unknown blocks
|
||||
if(!isset(self::$list[$this->getId()])){ //Unknown blocks
|
||||
return [];
|
||||
}else{
|
||||
return [
|
||||
[$this->id, $this->meta, 1],
|
||||
[$this->getId(), $this->getDamage(), 1],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -764,20 +764,20 @@ class Block extends Position implements Metadatable{
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(){
|
||||
return "Block[" . $this->getName() . "] (" . $this->id . ":" . $this->meta . ")";
|
||||
return "Block[" . $this->getName() . "] (" . $this->getId() . ":" . $this->getDamage() . ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for collision against an AxisAlignedBB
|
||||
*
|
||||
* @param AxisAlignedBB $bb
|
||||
* @param Block[] $list
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){
|
||||
public function collidesWithBB(AxisAlignedBB $bb){
|
||||
$bb2 = $this->getBoundingBox();
|
||||
if($bb2 !== null and $bb->intersectsWith($bb2)){
|
||||
$list[] = $bb2;
|
||||
}
|
||||
|
||||
return $bb2 !== null and $bb->intersectsWith($bb2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,13 +236,13 @@ abstract class Door extends Transparent{
|
||||
$next = $this->getSide($face[(($direction + 2) % 4)]);
|
||||
$next2 = $this->getSide($face[$direction]);
|
||||
$metaUp = 0x08;
|
||||
if($next->getId() === $this->id or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
|
||||
if($next->getId() === $this->getId() or ($next2->isTransparent() === false and $next->isTransparent() === true)){ //Door hinge
|
||||
$metaUp |= 0x01;
|
||||
}
|
||||
|
||||
$this->meta = $player->getDirection() & 0x03;
|
||||
$this->setDamage($player->getDirection() & 0x03);
|
||||
$this->getLevel()->setBlock($block, $this, true, true); //Bottom
|
||||
$this->getLevel()->setBlock($blockUp, $b = Block::get($this->id, $metaUp), true); //Top
|
||||
$this->getLevel()->setBlock($blockUp, $b = Block::get($this->getId(), $metaUp), true); //Top
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -250,14 +250,14 @@ abstract class Door extends Transparent{
|
||||
}
|
||||
|
||||
public function onBreak(Item $item){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
if(($this->getDamage() & 0x08) === 0x08){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getId() === $this->id){
|
||||
if($down->getId() === $this->getId()){
|
||||
$this->getLevel()->setBlock($down, new Air(), true);
|
||||
}
|
||||
}else{
|
||||
$up = $this->getSide(1);
|
||||
if($up->getId() === $this->id){
|
||||
if($up->getId() === $this->getId()){
|
||||
$this->getLevel()->setBlock($up, new Air(), true);
|
||||
}
|
||||
}
|
||||
@ -267,11 +267,11 @@ abstract class Door extends Transparent{
|
||||
}
|
||||
|
||||
public function onActivate(Item $item, Player $player = null){
|
||||
if(($this->meta & 0x08) === 0x08){ //Top
|
||||
if(($this->getDamage() & 0x08) === 0x08){ //Top
|
||||
$down = $this->getSide(0);
|
||||
if($down->getId() === $this->id){
|
||||
if($down->getId() === $this->getId()){
|
||||
$meta = $down->getDamage() ^ 0x04;
|
||||
$this->getLevel()->setBlock($down, Block::get($this->id, $meta), true);
|
||||
$this->getLevel()->setBlock($down, Block::get($this->getId(), $meta), true);
|
||||
$players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4);
|
||||
if($player instanceof Player){
|
||||
unset($players[$player->getLoaderId()]);
|
||||
|
@ -310,7 +310,7 @@ abstract class Liquid extends Transparent{
|
||||
$this->getLevel()->useBreakOn($block);
|
||||
}
|
||||
|
||||
$this->getLevel()->setBlock($block, Block::get($this->id, $newFlowDecay), true);
|
||||
$this->getLevel()->setBlock($block, Block::get($this->getId(), $newFlowDecay), true);
|
||||
$this->getLevel()->scheduleUpdate($block, $this->tickRate());
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ abstract class Stair extends Transparent{
|
||||
public function getDrops(Item $item){
|
||||
if($item->isPickaxe() >= 1){
|
||||
return [
|
||||
[$this->id, 0, 1],
|
||||
[$this->getId(), 0, 1],
|
||||
];
|
||||
}else{
|
||||
return [];
|
||||
|
@ -54,6 +54,7 @@ class GarbageCollectorCommand extends VanillaCommand{
|
||||
$chunksCollected += $diff[0] - count($level->getChunks());
|
||||
$entitiesCollected += $diff[1] - count($level->getEntities());
|
||||
$tilesCollected += $diff[2] - count($level->getTiles());
|
||||
$level->clearCache(true);
|
||||
}
|
||||
|
||||
$cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector();
|
||||
|
@ -1246,6 +1246,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if($this instanceof Player){
|
||||
if(!$this->onGround or $movY != 0){
|
||||
$bb = clone $this->boundingBox;
|
||||
$bb->maxY = $bb->minY + 0.5;
|
||||
$bb->minY -= 1;
|
||||
if(count($this->level->getCollisionBlocks($bb)) > 0){
|
||||
$this->onGround = true;
|
||||
|
@ -786,9 +786,18 @@ class Level implements ChunkManager, Metadatable{
|
||||
public function clearCache($full = false){
|
||||
if($full){
|
||||
$this->chunkCache = [];
|
||||
$this->blockCache = [];
|
||||
}else{
|
||||
if(count($this->chunkCache) > 1024){
|
||||
$this->chunkCache = [];
|
||||
}
|
||||
|
||||
if(count($this->blockCache) > 65535){
|
||||
$this->chunkCache = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->blockCache = [];
|
||||
}
|
||||
|
||||
private function tickChunks(){
|
||||
@ -992,14 +1001,12 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
$collides = [];
|
||||
|
||||
$v = $this->temporalVector;
|
||||
|
||||
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
|
||||
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||
for($v->y = $minY - 1; $v->y <= $maxY; ++$v->y){
|
||||
$block = $this->getBlock($v);
|
||||
if($block->getId() !== 0){
|
||||
$block->collidesWithBB($bb, $collides);
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z));
|
||||
if($block->getId() !== 0 and $block->collidesWithBB($bb)){
|
||||
$collides[] = $block;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1039,14 +1046,13 @@ class Level implements ChunkManager, Metadatable{
|
||||
$maxZ = Math::ceilFloat($bb->maxZ);
|
||||
|
||||
$collides = [];
|
||||
$v = $this->temporalVector;
|
||||
|
||||
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
|
||||
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){
|
||||
$block = $this->getBlock($v);
|
||||
if($block->getId() !== 0){
|
||||
$block->collidesWithBB($bb, $collides);
|
||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||
for($x = $minX; $x <= $maxX; ++$x){
|
||||
for($y = $minY; $y <= $maxY; ++$y){
|
||||
$block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z));
|
||||
if($block->getId() !== 0 and $block->collidesWithBB($bb)){
|
||||
$collides[] = $block->getBoundingBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user