Improved checks, area collision checks, etc

This commit is contained in:
Shoghi Cervantes 2015-05-29 14:47:46 +02:00
parent f20d5b2c69
commit 74917923b6
7 changed files with 44 additions and 36 deletions

View File

@ -268,7 +268,7 @@ class Block extends Position implements Metadatable{
protected $meta = 0; protected $meta = 0;
/** @var AxisAlignedBB */ /** @var AxisAlignedBB */
protected $boundingBox = null; public $boundingBox = null;
/** /**
* Backwards-compatibility with old way to define block properties * Backwards-compatibility with old way to define block properties
@ -724,11 +724,11 @@ class Block extends Position implements Metadatable{
* @return array * @return array
*/ */
public function getDrops(Item $item){ public function getDrops(Item $item){
if(!isset(self::$list[$this->id])){ //Unknown blocks if(!isset(self::$list[$this->getId()])){ //Unknown blocks
return []; return [];
}else{ }else{
return [ return [
[$this->id, $this->meta, 1], [$this->getId(), $this->getDamage(), 1],
]; ];
} }
} }
@ -764,20 +764,20 @@ class Block extends Position implements Metadatable{
* @return string * @return string
*/ */
public function __toString(){ 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 * Checks for collision against an AxisAlignedBB
* *
* @param AxisAlignedBB $bb * @param AxisAlignedBB $bb
* @param Block[] $list *
* @return bool
*/ */
public function collidesWithBB(AxisAlignedBB $bb, &$list = []){ public function collidesWithBB(AxisAlignedBB $bb){
$bb2 = $this->getBoundingBox(); $bb2 = $this->getBoundingBox();
if($bb2 !== null and $bb->intersectsWith($bb2)){
$list[] = $bb2; return $bb2 !== null and $bb->intersectsWith($bb2);
}
} }
/** /**

View File

@ -236,13 +236,13 @@ abstract class Door extends Transparent{
$next = $this->getSide($face[(($direction + 2) % 4)]); $next = $this->getSide($face[(($direction + 2) % 4)]);
$next2 = $this->getSide($face[$direction]); $next2 = $this->getSide($face[$direction]);
$metaUp = 0x08; $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; $metaUp |= 0x01;
} }
$this->meta = $player->getDirection() & 0x03; $this->setDamage($player->getDirection() & 0x03);
$this->getLevel()->setBlock($block, $this, true, true); //Bottom $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; return true;
} }
@ -250,14 +250,14 @@ abstract class Door extends Transparent{
} }
public function onBreak(Item $item){ public function onBreak(Item $item){
if(($this->meta & 0x08) === 0x08){ if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getId() === $this->id){ if($down->getId() === $this->getId()){
$this->getLevel()->setBlock($down, new Air(), true); $this->getLevel()->setBlock($down, new Air(), true);
} }
}else{ }else{
$up = $this->getSide(1); $up = $this->getSide(1);
if($up->getId() === $this->id){ if($up->getId() === $this->getId()){
$this->getLevel()->setBlock($up, new Air(), true); $this->getLevel()->setBlock($up, new Air(), true);
} }
} }
@ -267,11 +267,11 @@ abstract class Door extends Transparent{
} }
public function onActivate(Item $item, Player $player = null){ public function onActivate(Item $item, Player $player = null){
if(($this->meta & 0x08) === 0x08){ //Top if(($this->getDamage() & 0x08) === 0x08){ //Top
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getId() === $this->id){ if($down->getId() === $this->getId()){
$meta = $down->getDamage() ^ 0x04; $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); $players = $this->getLevel()->getChunkPlayers($this->x >> 4, $this->z >> 4);
if($player instanceof Player){ if($player instanceof Player){
unset($players[$player->getLoaderId()]); unset($players[$player->getLoaderId()]);

View File

@ -310,7 +310,7 @@ abstract class Liquid extends Transparent{
$this->getLevel()->useBreakOn($block); $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()); $this->getLevel()->scheduleUpdate($block, $this->tickRate());
} }
} }

View File

@ -149,7 +149,7 @@ abstract class Stair extends Transparent{
public function getDrops(Item $item){ public function getDrops(Item $item){
if($item->isPickaxe() >= 1){ if($item->isPickaxe() >= 1){
return [ return [
[$this->id, 0, 1], [$this->getId(), 0, 1],
]; ];
}else{ }else{
return []; return [];

View File

@ -54,6 +54,7 @@ class GarbageCollectorCommand extends VanillaCommand{
$chunksCollected += $diff[0] - count($level->getChunks()); $chunksCollected += $diff[0] - count($level->getChunks());
$entitiesCollected += $diff[1] - count($level->getEntities()); $entitiesCollected += $diff[1] - count($level->getEntities());
$tilesCollected += $diff[2] - count($level->getTiles()); $tilesCollected += $diff[2] - count($level->getTiles());
$level->clearCache(true);
} }
$cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector(); $cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector();

View File

@ -1246,6 +1246,7 @@ abstract class Entity extends Location implements Metadatable{
if($this instanceof Player){ if($this instanceof Player){
if(!$this->onGround or $movY != 0){ if(!$this->onGround or $movY != 0){
$bb = clone $this->boundingBox; $bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 0.5;
$bb->minY -= 1; $bb->minY -= 1;
if(count($this->level->getCollisionBlocks($bb)) > 0){ if(count($this->level->getCollisionBlocks($bb)) > 0){
$this->onGround = true; $this->onGround = true;

View File

@ -786,9 +786,18 @@ class Level implements ChunkManager, Metadatable{
public function clearCache($full = false){ public function clearCache($full = false){
if($full){ if($full){
$this->chunkCache = []; $this->chunkCache = [];
$this->blockCache = [];
}else{
if(count($this->chunkCache) > 1024){
$this->chunkCache = [];
}
if(count($this->blockCache) > 65535){
$this->chunkCache = [];
}
} }
$this->blockCache = [];
} }
private function tickChunks(){ private function tickChunks(){
@ -992,14 +1001,12 @@ class Level implements ChunkManager, Metadatable{
$collides = []; $collides = [];
$v = $this->temporalVector; for($z = $minZ; $z <= $maxZ; ++$z){
for($x = $minX; $x <= $maxX; ++$x){
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ for($y = $minY; $y <= $maxY; ++$y){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){ $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z));
for($v->y = $minY - 1; $v->y <= $maxY; ++$v->y){ if($block->getId() !== 0 and $block->collidesWithBB($bb)){
$block = $this->getBlock($v); $collides[] = $block;
if($block->getId() !== 0){
$block->collidesWithBB($bb, $collides);
} }
} }
} }
@ -1039,14 +1046,13 @@ class Level implements ChunkManager, Metadatable{
$maxZ = Math::ceilFloat($bb->maxZ); $maxZ = Math::ceilFloat($bb->maxZ);
$collides = []; $collides = [];
$v = $this->temporalVector;
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){ for($z = $minZ; $z <= $maxZ; ++$z){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){ for($x = $minX; $x <= $maxX; ++$x){
for($v->y = $minY - 1; $v->y < $maxY; ++$v->y){ for($y = $minY; $y <= $maxY; ++$y){
$block = $this->getBlock($v); $block = $this->getBlock($this->temporalVector->setComponents($x, $y, $z));
if($block->getId() !== 0){ if($block->getId() !== 0 and $block->collidesWithBB($bb)){
$block->collidesWithBB($bb, $collides); $collides[] = $block->getBoundingBox();
} }
} }
} }