mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
Entity collisions, bounding boxes for entites and blocks
This commit is contained in:
parent
9154c0fc3d
commit
1448fd21b9
19 changed files with 265 additions and 118 deletions
|
|
@ -1867,17 +1867,17 @@ class Player{
|
|||
$slot = $this->getSlot($this->slot);
|
||||
switch($slot->getID()){
|
||||
case WOODEN_SWORD:
|
||||
case GOLDEN_SWORD:
|
||||
$damage = 5;
|
||||
case GOLDEN_SWORD: //damage is correct
|
||||
$damage = 4;
|
||||
break;
|
||||
case STONE_SWORD:
|
||||
$damage = 6;
|
||||
$damage = 5;
|
||||
break;
|
||||
case IRON_SWORD:
|
||||
$damage = 8;
|
||||
$damage = 6;
|
||||
break;
|
||||
case DIAMOND_SWORD:
|
||||
$damage = 10;
|
||||
$damage = 7;
|
||||
break;
|
||||
|
||||
case WOODEN_AXE:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ abstract class Creature extends Living{
|
|||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:1, "generic");
|
||||
$this->update();
|
||||
//$this->setName((isset($mobs[$this->type]) ? $mobs[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
$this->width = 1;
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ class Entity extends Position{
|
|||
const TYPE = -1;
|
||||
const CLASS_TYPE = -1;
|
||||
|
||||
public $isCollidable;
|
||||
public $canBeAttacked;
|
||||
|
||||
/**
|
||||
* @var AxisAlignedBB
|
||||
*/
|
||||
public $boundingBox;
|
||||
public $age;
|
||||
public $air;
|
||||
public $spawntime;
|
||||
|
|
@ -43,7 +47,8 @@ class Entity extends Position{
|
|||
public $lastUpdate;
|
||||
public $linkedEntity = null;
|
||||
public $check = true;
|
||||
public $size = 1;
|
||||
public $width = 1;
|
||||
public $height = 1;
|
||||
public $random;
|
||||
public $inAction = false;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
|
|
@ -83,11 +88,13 @@ class Entity extends Position{
|
|||
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"]:0;
|
||||
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"]:0;
|
||||
$this->position = array("level" => $this->level, "x" => &$this->x, "y" => &$this->y, "z" => &$this->z, "yaw" => &$this->yaw, "pitch" => &$this->pitch);
|
||||
$this->height = 0.98;
|
||||
switch($this->class){
|
||||
case ENTITY_PLAYER:
|
||||
$this->player = $this->data["player"];
|
||||
$this->setHealth($this->health, "generic");
|
||||
$this->size = 1.2;
|
||||
$this->width = 1.2;
|
||||
$this->height = 1.9;
|
||||
$this->canBeAttacked = true;
|
||||
break;
|
||||
case ENTITY_ITEM:
|
||||
|
|
@ -100,13 +107,13 @@ class Entity extends Position{
|
|||
}
|
||||
$this->setHealth(5, "generic");
|
||||
$this->server->schedule(6010, array($this, "update")); //Despawn
|
||||
$this->update();
|
||||
$this->size = 0.75;
|
||||
$this->height = 0.75;
|
||||
$this->width = 0.75;
|
||||
break;
|
||||
case ENTITY_FALLING:
|
||||
$this->setHealth(PHP_INT_MAX, "generic");
|
||||
$this->update();
|
||||
$this->size = 0.98;
|
||||
$this->height = 0.98;
|
||||
$this->width = 0.98;
|
||||
break;
|
||||
case ENTITY_OBJECT:
|
||||
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
|
||||
|
|
@ -114,13 +121,17 @@ class Entity extends Position{
|
|||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
|
||||
$this->setHealth(1, "generic");
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
$this->width = 1;
|
||||
$this->height = 1;
|
||||
if($this->type === OBJECT_SNOWBALL){
|
||||
$this->server->schedule(1210, array($this, "update")); //Despawn
|
||||
$this->update();
|
||||
//$this->update();
|
||||
}
|
||||
break;
|
||||
}
|
||||
$this->radius = &$this->width / 2;
|
||||
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||
$this->update();
|
||||
$this->updateLast();
|
||||
$this->updatePosition();
|
||||
if($this->y < 0 and $this->class !== ENTITY_PLAYER){
|
||||
|
|
@ -131,24 +142,59 @@ class Entity extends Position{
|
|||
|
||||
/**
|
||||
* @param mixed $e Entity instance or EID
|
||||
* @return string|false if failed
|
||||
*/
|
||||
public static function getNameOf($e){
|
||||
if($e instanceof Entity){
|
||||
return $e->getName();
|
||||
}elseif(($ent = ServerAPI::request()->api->entity->get($e)) != false){
|
||||
return $ent->getName();
|
||||
}
|
||||
}
|
||||
public static function getSizeOf($e){
|
||||
if($e instanceof Entity){
|
||||
return $e->getSize();
|
||||
}elseif(($ent = ServerAPI::request()->api->entity->get($e)) != false){
|
||||
return $ent->getSize();
|
||||
}elseif(($e = ServerAPI::request()->api->entity->get($e)) != false){
|
||||
return $e->getName();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSize(){
|
||||
return $this->size;
|
||||
/**
|
||||
* @param mixed $e Entity instance or EID
|
||||
* @return number|false if failed
|
||||
*/
|
||||
|
||||
public static function getHeightOf($e){
|
||||
if($e instanceof Entity){
|
||||
return $e->getHeight();
|
||||
}elseif(($e = ServerAPI::request()->api->entity->get($e)) != false){
|
||||
return $e->getHeight();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $e Entity instance or EID
|
||||
* @return number|false if failed
|
||||
*/
|
||||
|
||||
public static function getWidthOf($e){
|
||||
if($e instanceof Entity){
|
||||
return $e->getWidth();
|
||||
}elseif(($e = ServerAPI::request()->api->entity->get($e)) != false){
|
||||
return $e->getWidth();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an entity height
|
||||
* @return number
|
||||
*/
|
||||
public function getHeight($a){
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an entity width
|
||||
* @return number
|
||||
*/
|
||||
public function getWidth(){
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function lookOn($target){
|
||||
|
|
@ -349,20 +395,20 @@ class Entity extends Position{
|
|||
}
|
||||
|
||||
if($this->isStatic === false){
|
||||
$startX = floor($this->x - 0.5 - $this->size - 1);
|
||||
$startX = floor($this->x - 0.5 - $this->width - 1);
|
||||
//prefix for flying when player on fence
|
||||
$y = floor($this->y - 1);
|
||||
$yC = ceil($this->y - 1);
|
||||
$startZ = floor($this->z - 0.5 - $this->size - 1);
|
||||
$endX = ceil($this->x - 0.5 + $this->size + 1);
|
||||
$endZ = ceil($this->z - 0.5 + $this->size + 1);
|
||||
$startZ = floor($this->z - 0.5 - $this->width - 1);
|
||||
$endX = ceil($this->x - 0.5 + $this->width + 1);
|
||||
$endZ = ceil($this->z - 0.5 + $this->width + 1);
|
||||
$support = false;
|
||||
$isFlying = true;
|
||||
for($z = $startZ; $z <= $endZ; ++$z){
|
||||
for($x = $startX; $x <= $endX; ++$x){
|
||||
$v = new Vector3($x, $y, $z);
|
||||
$v1 = new Vector3($x, $yC, $z);
|
||||
if($this->isSupport($v, $this->size)){
|
||||
if($this->isSupport($v, $this->width)){
|
||||
$b = $this->level->getBlock($v);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
|
|
@ -371,7 +417,7 @@ class Entity extends Position{
|
|||
}elseif(($b instanceof LiquidBlock) or $b->getID() === COBWEB or $b->getID() === LADDER or $b->getID() === FENCE or $b->getID() === STONE_WALL or $b->getID() === IRON_BARS){
|
||||
$isFlying = false;
|
||||
}
|
||||
}elseif($this->isSupport($v1, $this->size)){
|
||||
}elseif($this->isSupport($v1, $this->width)){
|
||||
$b = $this->level->getBlock($v1);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
|
|
@ -390,6 +436,14 @@ class Entity extends Position{
|
|||
$update = false;
|
||||
if(($this->class !== ENTITY_OBJECT and $this->type !== OBJECT_PRIMEDTNT) or $support === false){
|
||||
$drag = 0.2;
|
||||
$blocks = $this->level->getCubes($this->boundingBox->getOffsetBoundingBox($this->speedX, $this->speedY, $this->speedZ));
|
||||
|
||||
foreach($blocks as $b){
|
||||
$this->speedX = $b->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
$this->speedY = $b->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
$this->speedZ = $b->calculateZOffset($this->boundingBox, $this->speedZ);
|
||||
}
|
||||
|
||||
if($this->speedX != 0){
|
||||
$this->speedX -= $this->speedX * $drag;
|
||||
$this->x += $this->speedX;
|
||||
|
|
@ -430,10 +484,13 @@ class Entity extends Position{
|
|||
$this->y = $ny;
|
||||
$update = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if($support === false){
|
||||
$this->speedY -= 0.8;
|
||||
$this->speedY -= 0.08;
|
||||
|
||||
$update = true;
|
||||
}else{
|
||||
//$this->speedX = 0;
|
||||
|
|
@ -742,13 +799,18 @@ class Entity extends Position{
|
|||
$this->pitch += $pitch;
|
||||
$this->pitch %= 90;
|
||||
$this->server->query("UPDATE entities SET x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
$this->updateAABB();
|
||||
}
|
||||
|
||||
public function updateAABB(){
|
||||
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
|
||||
}
|
||||
|
||||
public function updatePosition(){
|
||||
$this->server->query("UPDATE entities SET level = '".$this->level->getName()."', x = ".$this->x.", y = ".$this->y.", z = ".$this->z.", pitch = ".$this->pitch.", yaw = ".$this->yaw." WHERE EID = ".$this->eid.";");
|
||||
$this->sendMoveUpdate();
|
||||
$this->sendMotion();
|
||||
|
||||
$this->updateAABB();
|
||||
}
|
||||
|
||||
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false){
|
||||
|
|
@ -900,8 +962,6 @@ class Entity extends Position{
|
|||
|
||||
$this->knockBack($d, $d1);
|
||||
$this->sendMotion();
|
||||
//$this->move(new Vector3($this->speedX, $this->speedY, $this->speedZ));
|
||||
//$this->sendMoveUpdate();
|
||||
}
|
||||
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player)){
|
||||
$points = 0;
|
||||
|
|
@ -997,7 +1057,10 @@ class Entity extends Position{
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function setSize($w, $h){
|
||||
$this->width = $w;
|
||||
$this->height = $h;
|
||||
}
|
||||
|
||||
public function knockBack($d, $d1)
|
||||
{
|
||||
|
|
@ -1022,5 +1085,27 @@ class Entity extends Position{
|
|||
public function __toString(){
|
||||
return "Entity(x={$this->x},y={$this->y},z={$this->z},level=".$this->level->getName().",class={$this->class},type={$this->type})";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Deprecated methods.
|
||||
* Those methods were left only for compability with older plugins
|
||||
*/
|
||||
/**
|
||||
* @deprecated Use {@link getHeightOf} or {@link getWidthOf} instead
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function getSizeOf($e){
|
||||
throw new Exception("Use getHeightOf or getWidthOf method instead of this.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link getHeight} or {@link getWidth} instead
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getSize(){
|
||||
throw new Exception("Use getHeight or getWidth method instead of this.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -7,9 +7,9 @@ class Chicken extends Animal{
|
|||
$server = ServerAPI::request();
|
||||
$server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
|
||||
$this->update();
|
||||
$this->setName('Chicken');
|
||||
$this->size = $this->isBaby() ? 0.35 : 0.7;
|
||||
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class Cow extends Animal{
|
|||
const TYPE = MOB_COW;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9 , $this->isBaby() ? 0.7 : 1.4);
|
||||
$this->setName('Cow');
|
||||
$this->size = $this->isBaby() ? 0.65 : 1.4;
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === WHEAT;
|
||||
|
|
|
|||
|
|
@ -5,12 +5,10 @@ class Pig extends Animal{
|
|||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
|
||||
$this->pathFinder = new Pathfinder($this);
|
||||
$this->update();
|
||||
$this->server = ServerAPI::request();
|
||||
//$this->server->schedule(60, array($this, "testMovement"));
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
|
||||
$this->setName('Pig');
|
||||
$this->size = $this->isBaby() ? 0.60 : 1.1875;
|
||||
$this->update();
|
||||
}
|
||||
public function isFood($id){
|
||||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
|
|
@ -21,43 +19,4 @@ class Pig extends Animal{
|
|||
array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, mt_rand(0,2)),
|
||||
);
|
||||
}
|
||||
public function testMovement(){ //test movement, move 1 block each 10 seconds, looks terrible ingame
|
||||
$this->pathFinder->updateEntityPos(ceil($this->x), ceil($this->y), ceil($this->z));
|
||||
$this->path = $this->pathFinder->buildTo(new Vector3(ceil($this->x) + mt_rand(0,4), ceil($this->y), ceil($this->z) + mt_rand(0,4)));
|
||||
$this->followPath();
|
||||
}
|
||||
|
||||
public function followPath(){
|
||||
$point = null;
|
||||
if($this->path instanceof Path){
|
||||
$point = $this->path->increaseIndexAndGetPoint();
|
||||
}else{
|
||||
$this->server->schedule(40, array($this, "testMovement"), false);
|
||||
return;
|
||||
}
|
||||
if($point != null){
|
||||
console($point);
|
||||
$xDiff = $point->x - $this->x;
|
||||
$zDiff = $point->z - $this->z;
|
||||
console($this);
|
||||
$this->move(new Vector3($xDiff, 0, $zDiff), $this->yaw, $this->pitch);
|
||||
$this->updateMovement();
|
||||
$this->handleUpdate($this);
|
||||
$this->server->schedule(10, array($this, "followPath"), false);
|
||||
}else{
|
||||
$this->server->schedule(40, array($this, "testMovement"), false);
|
||||
}
|
||||
|
||||
}
|
||||
public function handleUpdate($entity){
|
||||
$players = $this->server->api->player->getAll($entity->level);
|
||||
$pk = new MoveEntityPacket_PosRot;
|
||||
$pk->eid = $entity->eid;
|
||||
$pk->x = $entity->x;
|
||||
$pk->y = $entity->y;
|
||||
$pk->z = $entity->z;
|
||||
$pk->yaw = $entity->yaw;
|
||||
$pk->pitch = $entity->pitch;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ class Sheep extends Animal{
|
|||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
||||
$this->update();
|
||||
$this->setName('Sheep');
|
||||
$this->size = $this->isBaby() ? 0.65 : 1.3;
|
||||
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ class Creeper extends Monster{
|
|||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:20, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:16, "generic");
|
||||
$this->setName('Creeper');
|
||||
$this->size = 1.6; //not original
|
||||
$this->setSize(0.6, 1.7);
|
||||
$this->update();
|
||||
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ class PigZombie extends Monster{
|
|||
const TYPE = MOB_PIGMAN;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 20, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setSize(0.3, 1.95);
|
||||
$this->setName('Pigman');
|
||||
$this->size = 1.8; //not original
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class Skeleton extends Monster{
|
|||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 20, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
|
||||
$this->setName('Skeleton');
|
||||
$this->size = 1.9;
|
||||
$this->setSize(0.6, 1.99);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class Spider extends Monster{
|
|||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:20, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
|
||||
$this->setName('Spider');
|
||||
$this->size = 0.6; //not original
|
||||
$this->setSize(1.4, 0.9);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class Zombie extends Monster{
|
|||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 20, "generic");
|
||||
$this->update();
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
|
||||
$this->setName('Zombie');
|
||||
$this->size = 1.95;
|
||||
$this->setSize(0.6, 1.95);
|
||||
$this->update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class Minecart extends Vehicle{
|
|||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
|
||||
$this->setHealth(1, "generic");
|
||||
//$this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
|
||||
$this->size = 1;
|
||||
$this->width = 1;
|
||||
/*$this->moveVector[Entity::NORTH] = new Vector3(-1, 0, 0);
|
||||
$this->moveVector[Entity::SOUTH] = new Vector3(1, 0, 0);
|
||||
$this->moveVector[Entity::EAST] = new Vector3(0, 0, -1);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class Painting extends Hanging{
|
|||
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
|
||||
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
|
||||
$this->setHealth(1, "generic");
|
||||
$this->size = 1;
|
||||
$this->width = 1;
|
||||
$this->isStatic = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ abstract class Block extends Position{
|
|||
protected $meta;
|
||||
protected $name;
|
||||
protected $breakTime;
|
||||
public $boundingBox;
|
||||
protected $hardness;
|
||||
public $isActivable = false;
|
||||
public $breakable = true;
|
||||
|
|
@ -159,6 +160,7 @@ abstract class Block extends Position{
|
|||
$this->name = $name;
|
||||
$this->breakTime = 0.20;
|
||||
$this->hardness = 10;
|
||||
$this->boundingBox = new AxisAlignedBB($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
|
||||
}
|
||||
|
||||
final public function getHardness(){
|
||||
|
|
@ -184,6 +186,7 @@ abstract class Block extends Position{
|
|||
$this->x = (int) $v->x;
|
||||
$this->y = (int) $v->y;
|
||||
$this->z = (int) $v->z;
|
||||
$this->boundingBox->setBounds($this->x, $this->y, $this->z, $this->x + 1, $this->y + 1, $this->z + 1);
|
||||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ class AxisAlignedBB{
|
|||
|
||||
return $z;
|
||||
}
|
||||
|
||||
|
||||
public function intersectsWith(AxisAlignedBB $bb){
|
||||
if($bb->maxX > $this->minX and $bb->minX < $this->maxX){
|
||||
if($bb->maxY > $this->minY and $bb->minY < $this->maxY){
|
||||
|
|
@ -190,7 +190,17 @@ class AxisAlignedBB{
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function isXYZInside($x, $y, $z){
|
||||
if($x <= $this->minX or $x >= $this->maxX){
|
||||
return false;
|
||||
}
|
||||
if($y <= $this->minY or $y >= $this->maxY){
|
||||
return false;
|
||||
}
|
||||
|
||||
return $z > $this->minZ and $z < $this->maxZ;
|
||||
}
|
||||
public function isVectorInside(Vector3 $vector){
|
||||
if($vector->x <= $this->minX or $vector->x >= $this->maxX){
|
||||
return false;
|
||||
|
|
@ -294,4 +304,9 @@ class AxisAlignedBB{
|
|||
|
||||
return MovingObjectPosition::fromBlock(0, 0, 0, $f, $vector);
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -170,7 +170,11 @@ class Vector3{
|
|||
$this->x * $v->y - $this->y * $v->x
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public static function fromArray($arr){
|
||||
return new Vector3($arr[0], $arr[1], $arr[2]);
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return "Vector3(x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,8 +38,6 @@ class Utils{
|
|||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
public static function hasEmoji($s){
|
||||
return preg_match(Utils::emojiRegex, $s, $matches);
|
||||
}
|
||||
|
|
@ -50,7 +48,25 @@ class Utils{
|
|||
return sha1(strtolower($variable));
|
||||
}
|
||||
}
|
||||
|
||||
public function xrange($start, $limit, $step = 1) {
|
||||
if ($start <= $limit) {
|
||||
if ($step <= 0) {
|
||||
throw new LogicException('Step must be positive');
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $limit; $i += $step) {
|
||||
yield $i;
|
||||
}
|
||||
} else {
|
||||
if ($step >= 0) {
|
||||
throw new LogicException('Step must be negative');
|
||||
}
|
||||
|
||||
for ($i = $start; $i >= $limit; $i += $step) {
|
||||
yield $i;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function getUniqueID($raw = false, $extra = ""){
|
||||
$machine = php_uname("a");
|
||||
$machine .= file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : "";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,12 @@
|
|||
|
||||
class Level{
|
||||
|
||||
public $entities, $tiles, $blockUpdates, $nextSave, $players = [], $level;
|
||||
/**
|
||||
* List of entities in this world
|
||||
* @var array
|
||||
*/
|
||||
public $entities;
|
||||
public $tiles, $blockUpdates, $nextSave, $players = [], $level;
|
||||
private $time, $startCheck, $startTime, $server, $name, $usedChunks, $changedBlocks, $changedCount, $stopTime;
|
||||
|
||||
public function __construct(PMFLevel $level, Config $entities, Config $tiles, Config $blockUpdates, $name){
|
||||
|
|
@ -27,7 +32,35 @@ class Level{
|
|||
public function close(){
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
|
||||
public function getCubes(AxisAlignedBB $aABB) {
|
||||
$aABBs = [];
|
||||
$x0 = (int)$aABB->minX;
|
||||
$x1 = (int)($aABB->maxX + 1.0);
|
||||
$y0 = (int)$aABB->minY;
|
||||
$y1 = (int)($aABB->maxY + 1.0);
|
||||
$z0 = (int)$aABB->minZ;
|
||||
$z1 = (int)($aABB->maxZ + 1.0);
|
||||
$x0 = $x0 < 0 ? 0 : $x0;
|
||||
$y0 = $y0 < 0 ? 0 : $y0;
|
||||
$z0 = $z0 < 0 ? 0 : $z0;
|
||||
$x1 = $x1 > 256 ? 256 : $x1;
|
||||
$y1 = $y1 > 128 ? 128 : $y1;
|
||||
$z1 = $z1 > 256 ? 256 : $z1;
|
||||
|
||||
for($x = $x0; $x < $x1; ++$x) {
|
||||
for($y = $y0; $y < $y1; ++$y) {
|
||||
for($z = $z0; $z < $z1; ++$z) {
|
||||
$b = $this->getBlockWithoutVector($x, $y, $z);
|
||||
if($b != false && $b->isSolid) {
|
||||
$aABBs[] = $b->boundingBox;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aABBs;
|
||||
}
|
||||
public function __destruct(){
|
||||
if(isset($this->level)){
|
||||
$this->save(false, false);
|
||||
|
|
@ -35,7 +68,7 @@ class Level{
|
|||
unset($this->level);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function save($force = false, $extra = true){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
@ -187,14 +220,29 @@ class Level{
|
|||
public function freeChunk($X, $Z, Player $player){
|
||||
unset($this->usedChunks[$X . "." . $Z][$player->CID]);
|
||||
}
|
||||
|
||||
|
||||
public function checkCollisionsFor(Entity $e){
|
||||
if($e->level->getName() != $this->getName()){
|
||||
return false; //not the same world
|
||||
}
|
||||
foreach($this->entities as $e1){
|
||||
if($e->boundingBox->intersectsWith($e1->boundingBox) && $e1->isCollidable){
|
||||
$e->onCollideWith($e1);
|
||||
$e1->onCollideWith($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public function isObstructed($e){
|
||||
|
||||
}
|
||||
|
||||
public function checkThings(){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
$this->players = $this->server->api->player->getAll($this);
|
||||
|
||||
|
||||
if(count($this->changedCount) > 0){
|
||||
arsort($this->changedCount);
|
||||
$resendChunks = [];
|
||||
|
|
@ -452,13 +500,29 @@ class Level{
|
|||
}
|
||||
return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param number $x
|
||||
* @param number $y
|
||||
* @param number $z
|
||||
* @return GenericBlock | false if failed
|
||||
*/
|
||||
|
||||
public function getBlockWithoutVector($x, $y, $z){
|
||||
$b = $this->level->getBlock($x, $y, $z);
|
||||
return BlockAPI::get($b[0], $b[1], new Position($x, $y, $z, $this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Recommended to use {@link getBlockWithoutVector()} if you dont have the vector
|
||||
* @param Vector3 $pos
|
||||
* @return Block|false if failed
|
||||
*/
|
||||
public function getBlock(Vector3 $pos){
|
||||
if(!isset($this->level) or ($pos instanceof Position) and $pos->level !== $this){
|
||||
return false;
|
||||
}
|
||||
$b = $this->level->getBlock($pos->x, $pos->y, $pos->z);
|
||||
return BlockAPI::get($b[0], $b[1], new Position($pos->x, $pos->y, $pos->z, $this));
|
||||
return $this->getBlockWithoutVector($pos->x, $pos->y, $pos->z);
|
||||
}
|
||||
|
||||
public function setSpawn(Vector3 $pos){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue