Blocks now save their bounding box, fixed entity block collision check

This commit is contained in:
Shoghi Cervantes 2014-10-29 15:43:23 +01:00
parent 6f64af3066
commit 289bc56b4b
26 changed files with 64 additions and 30 deletions

View File

@ -2163,9 +2163,12 @@ class Server{
Vector3::clearVectorList();
Position::clearPositionList();
AxisAlignedBB::clearBoundingBoxPool();
if(($this->tickCounter % 4) === 0){
if(($this->tickCounter % 20) === 0){
Event::clearAllPools();
foreach($this->levels as $level){
$level->clearCache();
}
AxisAlignedBB::clearBoundingBoxPool();
}
Timings::$serverTickTimer->stopTiming();

View File

@ -35,7 +35,7 @@ class Bed extends Transparent{
$this->hardness = 1;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y,

View File

@ -528,6 +528,9 @@ class Block extends Position implements Metadatable{
public $z = 0;
public $frictionFactor = 0.6;
/** @var AxisAlignedBB */
protected $boundingBox = null;
public static function init(){
if(count(self::$list) === 0){
self::$list = [
@ -897,6 +900,17 @@ class Block extends Position implements Metadatable{
* @return AxisAlignedBB
*/
public function getBoundingBox(){
if($this->boundingBox !== null){
return $this->boundingBox;
}else{
return $this->boundingBox = $this->recalculateBoundingBox();
}
}
/**
* @return AxisAlignedBB
*/
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,
$this->y,

View File

@ -42,7 +42,7 @@ class Cactus extends Transparent{
$this->hardness = 2;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x + 0.0625,

View File

@ -37,7 +37,7 @@ class Cake extends Transparent{
$this->hardness = 2.5;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = (1 + $this->getDamage() * 2) / 16;

View File

@ -53,7 +53,7 @@ class Carpet extends Flowable{
$this->isSolid = true;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -42,7 +42,7 @@ class Chest extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x + 0.0625,

View File

@ -52,7 +52,7 @@ abstract class Door extends Transparent{
return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0);
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.1875;
$damage = $this->getFullDamage();

View File

@ -29,7 +29,7 @@ class EndPortal extends Solid{
$this->hardness = 18000000;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -30,7 +30,7 @@ class Farmland extends Solid{
$this->hardness = 3;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -31,7 +31,7 @@ class Fence extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$flag = $this->canConnect($this->getSide(2));
$flag1 = $this->canConnect($this->getSide(3));

View File

@ -38,7 +38,7 @@ class FenceGate extends Transparent{
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return null;

View File

@ -43,7 +43,7 @@ class Ladder extends Transparent{
$entity->onGround = true;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.125;

View File

@ -47,7 +47,7 @@ class Slab extends Transparent{
$this->hardness = 30;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(

View File

@ -30,7 +30,7 @@ class SoulSand extends Solid{
$this->hardness = 2.5;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
return AxisAlignedBB::getBoundingBoxFromPool(
$this->x,

View File

@ -113,7 +113,7 @@ abstract class Stair extends Transparent{
}
*/
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->getDamage() & 0x04) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(

View File

@ -36,7 +36,7 @@ class StoneWall extends Transparent{
$this->hardness = 30;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$flag = $this->canConnect($this->getSide(2));
$flag1 = $this->canConnect($this->getSide(3));

View File

@ -29,7 +29,7 @@ abstract class Thin extends Transparent{
public $isFullBlock = false;
public $isSolid = false;
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f = 0.4375;
$f1 = 0.5625;

View File

@ -37,7 +37,7 @@ class Trapdoor extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$damage = $this->getDamage();

View File

@ -43,7 +43,7 @@ class Vine extends Transparent{
$entity->fallDistance = 0;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
$f1 = 1;
$f2 = 1;

View File

@ -45,7 +45,7 @@ class WoodSlab extends Transparent{
$this->hardness = 15;
}
public function getBoundingBox(){
protected function recalculateBoundingBox(){
if(($this->meta & 0x08) > 0){
return AxisAlignedBB::getBoundingBoxFromPool(

View File

@ -1040,9 +1040,9 @@ abstract class Entity extends Location implements Metadatable{
$vector = Vector3::createVector(0, 0, 0);
$v = Vector3::createVector(0, 0, 0);
for($v->z = $minZ; $v->z < $maxZ; ++$v->z){
for($v->x = $minX; $v->x < $maxX; ++$v->x){
for($v->y = $minY; $v->y < $maxY; ++$v->y){
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
$block = $this->level->getBlock($v);
if($block !== null and $block->hasEntityCollision){
$block->onEntityCollide($this);

View File

@ -69,9 +69,26 @@ abstract class Living extends Entity implements Damageable{
}
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
if($this->attackTime > 0){
$lastCause = $this->getLastDamageCause();
if($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage){
if($source instanceof EntityDamageEvent){
$source->setCancelled();
$this->server->getPluginManager()->callEvent($source);
$damage = $source->getFinalDamage();
if($source->isCancelled()){
return;
}
}else{
return;
}
}
}elseif($source instanceof EntityDamageEvent){
$this->server->getPluginManager()->callEvent($source);
$damage = $source->getFinalDamage();
if($source->isCancelled()){
return;
}
}

View File

@ -50,7 +50,7 @@ abstract class Event{
* @return string
*/
final public function getEventName(){
return $this->eventName !== null ? static::class : $this->eventName;
return $this->eventName != null ? get_class($this) : $this->eventName;
}
/**

View File

@ -517,10 +517,6 @@ class Level implements ChunkManager, Metadatable{
$this->tickChunks();
$this->timings->doTickTiles->stopTiming();
if(($currentTick % 200) === 0){
$this->blockCache = [];
}
if(count($this->changedCount) > 0){
if(count($this->players) > 0){
foreach($this->changedCount as $index => $mini){
@ -571,6 +567,10 @@ class Level implements ChunkManager, Metadatable{
$this->timings->doTick->stopTiming();
}
public function clearCache(){
$this->blockCache = [];
}
private function tickChunks(){
if($this->chunksPerTick <= 0 or count($this->players) === 0){
return;

View File

@ -38,7 +38,7 @@ abstract class DataPacket extends \stdClass{
}
public static function cleanPool(){
if(static::$next > 4096){
if(static::$next > 16384){
static::$pool = [];
}
static::$next = 0;