mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Blocks now save their bounding box, fixed entity block collision check
This commit is contained in:
parent
6f64af3066
commit
289bc56b4b
@ -2163,9 +2163,12 @@ class Server{
|
|||||||
|
|
||||||
Vector3::clearVectorList();
|
Vector3::clearVectorList();
|
||||||
Position::clearPositionList();
|
Position::clearPositionList();
|
||||||
AxisAlignedBB::clearBoundingBoxPool();
|
if(($this->tickCounter % 20) === 0){
|
||||||
if(($this->tickCounter % 4) === 0){
|
|
||||||
Event::clearAllPools();
|
Event::clearAllPools();
|
||||||
|
foreach($this->levels as $level){
|
||||||
|
$level->clearCache();
|
||||||
|
}
|
||||||
|
AxisAlignedBB::clearBoundingBoxPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
Timings::$serverTickTimer->stopTiming();
|
Timings::$serverTickTimer->stopTiming();
|
||||||
|
@ -35,7 +35,7 @@ class Bed extends Transparent{
|
|||||||
$this->hardness = 1;
|
$this->hardness = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
$this->y,
|
$this->y,
|
||||||
|
@ -528,6 +528,9 @@ class Block extends Position implements Metadatable{
|
|||||||
public $z = 0;
|
public $z = 0;
|
||||||
public $frictionFactor = 0.6;
|
public $frictionFactor = 0.6;
|
||||||
|
|
||||||
|
/** @var AxisAlignedBB */
|
||||||
|
protected $boundingBox = null;
|
||||||
|
|
||||||
public static function init(){
|
public static function init(){
|
||||||
if(count(self::$list) === 0){
|
if(count(self::$list) === 0){
|
||||||
self::$list = [
|
self::$list = [
|
||||||
@ -897,6 +900,17 @@ class Block extends Position implements Metadatable{
|
|||||||
* @return AxisAlignedBB
|
* @return AxisAlignedBB
|
||||||
*/
|
*/
|
||||||
public function getBoundingBox(){
|
public function getBoundingBox(){
|
||||||
|
if($this->boundingBox !== null){
|
||||||
|
return $this->boundingBox;
|
||||||
|
}else{
|
||||||
|
return $this->boundingBox = $this->recalculateBoundingBox();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return AxisAlignedBB
|
||||||
|
*/
|
||||||
|
protected function recalculateBoundingBox(){
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
$this->y,
|
$this->y,
|
||||||
|
@ -42,7 +42,7 @@ class Cactus extends Transparent{
|
|||||||
$this->hardness = 2;
|
$this->hardness = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x + 0.0625,
|
$this->x + 0.0625,
|
||||||
|
@ -37,7 +37,7 @@ class Cake extends Transparent{
|
|||||||
$this->hardness = 2.5;
|
$this->hardness = 2.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$f = (1 + $this->getDamage() * 2) / 16;
|
$f = (1 + $this->getDamage() * 2) / 16;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Carpet extends Flowable{
|
|||||||
$this->isSolid = true;
|
$this->isSolid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
|
@ -42,7 +42,7 @@ class Chest extends Transparent{
|
|||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x + 0.0625,
|
$this->x + 0.0625,
|
||||||
|
@ -52,7 +52,7 @@ abstract class Door extends Transparent{
|
|||||||
return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0);
|
return $first & 0x07 | ($flag ? 8 : 0) | ($flag1 ? 0x10 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$f = 0.1875;
|
$f = 0.1875;
|
||||||
$damage = $this->getFullDamage();
|
$damage = $this->getFullDamage();
|
||||||
|
@ -29,7 +29,7 @@ class EndPortal extends Solid{
|
|||||||
$this->hardness = 18000000;
|
$this->hardness = 18000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
|
@ -30,7 +30,7 @@ class Farmland extends Solid{
|
|||||||
$this->hardness = 3;
|
$this->hardness = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
|
@ -31,7 +31,7 @@ class Fence extends Transparent{
|
|||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$flag = $this->canConnect($this->getSide(2));
|
$flag = $this->canConnect($this->getSide(2));
|
||||||
$flag1 = $this->canConnect($this->getSide(3));
|
$flag1 = $this->canConnect($this->getSide(3));
|
||||||
|
@ -38,7 +38,7 @@ class FenceGate extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
if(($this->getDamage() & 0x04) > 0){
|
if(($this->getDamage() & 0x04) > 0){
|
||||||
return null;
|
return null;
|
||||||
|
@ -43,7 +43,7 @@ class Ladder extends Transparent{
|
|||||||
$entity->onGround = true;
|
$entity->onGround = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$f = 0.125;
|
$f = 0.125;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Slab extends Transparent{
|
|||||||
$this->hardness = 30;
|
$this->hardness = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
if(($this->meta & 0x08) > 0){
|
if(($this->meta & 0x08) > 0){
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
|
@ -30,7 +30,7 @@ class SoulSand extends Solid{
|
|||||||
$this->hardness = 2.5;
|
$this->hardness = 2.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
$this->x,
|
$this->x,
|
||||||
|
@ -113,7 +113,7 @@ abstract class Stair extends Transparent{
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
if(($this->getDamage() & 0x04) > 0){
|
if(($this->getDamage() & 0x04) > 0){
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
|
@ -36,7 +36,7 @@ class StoneWall extends Transparent{
|
|||||||
$this->hardness = 30;
|
$this->hardness = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$flag = $this->canConnect($this->getSide(2));
|
$flag = $this->canConnect($this->getSide(2));
|
||||||
$flag1 = $this->canConnect($this->getSide(3));
|
$flag1 = $this->canConnect($this->getSide(3));
|
||||||
|
@ -29,7 +29,7 @@ abstract class Thin extends Transparent{
|
|||||||
public $isFullBlock = false;
|
public $isFullBlock = false;
|
||||||
public $isSolid = false;
|
public $isSolid = false;
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$f = 0.4375;
|
$f = 0.4375;
|
||||||
$f1 = 0.5625;
|
$f1 = 0.5625;
|
||||||
|
@ -37,7 +37,7 @@ class Trapdoor extends Transparent{
|
|||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$damage = $this->getDamage();
|
$damage = $this->getDamage();
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class Vine extends Transparent{
|
|||||||
$entity->fallDistance = 0;
|
$entity->fallDistance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
$f1 = 1;
|
$f1 = 1;
|
||||||
$f2 = 1;
|
$f2 = 1;
|
||||||
|
@ -45,7 +45,7 @@ class WoodSlab extends Transparent{
|
|||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBoundingBox(){
|
protected function recalculateBoundingBox(){
|
||||||
|
|
||||||
if(($this->meta & 0x08) > 0){
|
if(($this->meta & 0x08) > 0){
|
||||||
return AxisAlignedBB::getBoundingBoxFromPool(
|
return AxisAlignedBB::getBoundingBoxFromPool(
|
||||||
|
@ -1040,9 +1040,9 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
$vector = Vector3::createVector(0, 0, 0);
|
$vector = Vector3::createVector(0, 0, 0);
|
||||||
$v = Vector3::createVector(0, 0, 0);
|
$v = Vector3::createVector(0, 0, 0);
|
||||||
|
|
||||||
for($v->z = $minZ; $v->z < $maxZ; ++$v->z){
|
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
|
||||||
for($v->x = $minX; $v->x < $maxX; ++$v->x){
|
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
|
||||||
for($v->y = $minY; $v->y < $maxY; ++$v->y){
|
for($v->y = $minY; $v->y <= $maxY; ++$v->y){
|
||||||
$block = $this->level->getBlock($v);
|
$block = $this->level->getBlock($v);
|
||||||
if($block !== null and $block->hasEntityCollision){
|
if($block !== null and $block->hasEntityCollision){
|
||||||
$block->onEntityCollide($this);
|
$block->onEntityCollide($this);
|
||||||
|
@ -69,9 +69,26 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||||
|
|
||||||
|
|
||||||
if($this->attackTime > 0){
|
if($this->attackTime > 0){
|
||||||
$lastCause = $this->getLastDamageCause();
|
$lastCause = $this->getLastDamageCause();
|
||||||
if($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage){
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ abstract class Event{
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
final public function getEventName(){
|
final public function getEventName(){
|
||||||
return $this->eventName !== null ? static::class : $this->eventName;
|
return $this->eventName != null ? get_class($this) : $this->eventName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,10 +517,6 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->tickChunks();
|
$this->tickChunks();
|
||||||
$this->timings->doTickTiles->stopTiming();
|
$this->timings->doTickTiles->stopTiming();
|
||||||
|
|
||||||
if(($currentTick % 200) === 0){
|
|
||||||
$this->blockCache = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count($this->changedCount) > 0){
|
if(count($this->changedCount) > 0){
|
||||||
if(count($this->players) > 0){
|
if(count($this->players) > 0){
|
||||||
foreach($this->changedCount as $index => $mini){
|
foreach($this->changedCount as $index => $mini){
|
||||||
@ -571,6 +567,10 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->timings->doTick->stopTiming();
|
$this->timings->doTick->stopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clearCache(){
|
||||||
|
$this->blockCache = [];
|
||||||
|
}
|
||||||
|
|
||||||
private function tickChunks(){
|
private function tickChunks(){
|
||||||
if($this->chunksPerTick <= 0 or count($this->players) === 0){
|
if($this->chunksPerTick <= 0 or count($this->players) === 0){
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@ abstract class DataPacket extends \stdClass{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanPool(){
|
public static function cleanPool(){
|
||||||
if(static::$next > 4096){
|
if(static::$next > 16384){
|
||||||
static::$pool = [];
|
static::$pool = [];
|
||||||
}
|
}
|
||||||
static::$next = 0;
|
static::$next = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user