mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
project uses tabs instead of spaces(as in CONTRIBUTING.md)
This commit is contained in:
parent
f00318b6ed
commit
62571f26cd
115 changed files with 2291 additions and 2364 deletions
|
|
@ -81,13 +81,13 @@ class AchievementAPI{
|
|||
],
|
||||
|
||||
];
|
||||
|
||||
|
||||
private $server;
|
||||
|
||||
function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
$this->server = ServerAPI::request();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an achievement
|
||||
* @param string $achievementId
|
||||
|
|
@ -157,47 +157,47 @@ class AchievementAPI{
|
|||
}
|
||||
}
|
||||
|
||||
public function viewAchievements($cmd, $params, $issuer, $alias)
|
||||
{
|
||||
if(!($issuer instanceof Player) && !isset($params[0])){
|
||||
return "Please enter a nickname.";
|
||||
} else{
|
||||
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
|
||||
$player = $this->server->api->player->get($params[0]);
|
||||
if($player instanceof Player){
|
||||
$data = $player->data;
|
||||
} else{
|
||||
$data = $this->server->api->player->getOffline(trim($params[0]), false);
|
||||
}
|
||||
} else{
|
||||
$data = $issuer->achievements;
|
||||
}
|
||||
}
|
||||
if($data === false){
|
||||
return "Player {$params[0]} is not found.";
|
||||
}
|
||||
if($data instanceof Config){
|
||||
$achs = $data->get("achievements");
|
||||
}else{
|
||||
$achs = $data;
|
||||
}
|
||||
|
||||
if(count($achs) <= 0){
|
||||
return "Player {$params[0]} unlocked 0 achievements";
|
||||
}
|
||||
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
|
||||
foreach($achs as $achievement => $unlocked){
|
||||
if($unlocked && isset(self::$achievements[$achievement])){
|
||||
$info = self::$achievements[$achievement];
|
||||
$output .= "{$info["name"]}, ";
|
||||
}
|
||||
}
|
||||
return substr($output, 0, - 2);
|
||||
}
|
||||
public function viewAchievements($cmd, $params, $issuer, $alias)
|
||||
{
|
||||
if(!($issuer instanceof Player) && !isset($params[0])){
|
||||
return "Please enter a nickname.";
|
||||
} else{
|
||||
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
|
||||
$player = $this->server->api->player->get($params[0]);
|
||||
if($player instanceof Player){
|
||||
$data = $player->data;
|
||||
} else{
|
||||
$data = $this->server->api->player->getOffline(trim($params[0]), false);
|
||||
}
|
||||
} else{
|
||||
$data = $issuer->achievements;
|
||||
}
|
||||
}
|
||||
if($data === false){
|
||||
return "Player {$params[0]} is not found.";
|
||||
}
|
||||
if($data instanceof Config){
|
||||
$achs = $data->get("achievements");
|
||||
}else{
|
||||
$achs = $data;
|
||||
}
|
||||
|
||||
if(count($achs) <= 0){
|
||||
return "Player {$params[0]} unlocked 0 achievements";
|
||||
}
|
||||
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
|
||||
foreach($achs as $achievement => $unlocked){
|
||||
if($unlocked && isset(self::$achievements[$achievement])){
|
||||
$info = self::$achievements[$achievement];
|
||||
$output .= "{$info["name"]}, ";
|
||||
}
|
||||
}
|
||||
return substr($output, 0, - 2);
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
|
||||
$this->server->api->console->alias("getplayerachievements", "ach");
|
||||
$this->server->api->console->cmdWhitelist("ach");
|
||||
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
|
||||
$this->server->api->console->alias("getplayerachievements", "ach");
|
||||
$this->server->api->console->cmdWhitelist("ach");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class BanAPI{
|
|||
* @param string $cmd Command to Whitelist
|
||||
*/
|
||||
public function cmdWhitelist($cmd){
|
||||
$this->server->api->console->cmdWhitelist($cmd);
|
||||
$this->server->api->console->cmdWhitelist($cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -67,21 +67,21 @@ class BanAPI{
|
|||
}
|
||||
break;
|
||||
case "player.block.break":
|
||||
/**
|
||||
* @var Player $player
|
||||
*/
|
||||
$player = $data["player"];
|
||||
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
|
||||
$t = new Vector2($data["target"]->x, $data["target"]->z);
|
||||
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
|
||||
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
/**
|
||||
* @var Player $player
|
||||
*/
|
||||
$player = $data["player"];
|
||||
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
|
||||
$t = new Vector2($data["target"]->x, $data["target"]->z);
|
||||
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
|
||||
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
|
||||
$player = $data["player"];
|
||||
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
|
||||
$player = $data["player"];
|
||||
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
|
||||
$t = new Vector2($data["block"]->x, $data["block"]->z);
|
||||
$s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
|
||||
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
|
||||
|
|
|
|||
|
|
@ -435,7 +435,7 @@ class BlockAPI{
|
|||
$item = $player->getSlot($player->slot);
|
||||
|
||||
if($target->getID() === AIR and $this->server->api->dhandle("player.block.place.invalid", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){ //If no block exists or not allowed in CREATIVE
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
$this->cancelAction($target, $player);
|
||||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
|
|
@ -443,7 +443,7 @@ class BlockAPI{
|
|||
|
||||
if($this->server->api->dhandle("player.block.touch", ["type" => "place", "player" => $player, "block" => $block, "target" => $target, "item" => $item]) === false){
|
||||
if($this->server->api->dhandle("player.block.place.bypass", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== true){
|
||||
return $this->cancelAction($block, $player);
|
||||
return $this->cancelAction($block, $player);
|
||||
}
|
||||
}
|
||||
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
|
||||
|
|
@ -532,7 +532,7 @@ class BlockAPI{
|
|||
$this->server->api->entity->updateRadius($pos, 1);
|
||||
}elseif($level === BLOCK_UPDATE_RANDOM){
|
||||
//$this->nextRandomUpdate($pos); old version, change back if any issues will start to happen with this one(please note that old version makes a lot of lag)
|
||||
$this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
|
||||
$this->scheduleBlockUpdate($pos, (mt_rand(25, 75) + Utils::getRandomUpdateTicks() * 0.05) / 0.05, BLOCK_UPDATE_RANDOM);
|
||||
}
|
||||
return $level;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class ChatAPI{
|
|||
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->cmdWhitelist("tell");
|
||||
$this->server->api->console->cmdWhitelist("tell");
|
||||
$this->server->api->console->cmdWhitelist("me");
|
||||
$this->server->api->console->alias("msg", "tell");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ class ConsoleAPI{
|
|||
$this->cmdWhitelist("help");
|
||||
$this->cmdWhitelist("status");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whitelists a CMD so everyone can issue it - Even non OPs.
|
||||
* @param string $cmd Command to Whitelist
|
||||
*/
|
||||
public function cmdWhitelist($cmd){
|
||||
$this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true;
|
||||
$this->server->api->ban->cmdWhitelist[strtolower(trim($cmd))] = true;
|
||||
}
|
||||
|
||||
public function register($cmd, $help, $callback){
|
||||
|
|
@ -304,11 +304,11 @@ class ConsoleLoop extends Thread{
|
|||
}
|
||||
|
||||
while(!$this->stop){
|
||||
$this->line = $this->readLine();
|
||||
$this->synchronized(function($t) {
|
||||
$this->wait();
|
||||
$this->line = false;
|
||||
}, $this);
|
||||
$this->line = $this->readLine();
|
||||
$this->synchronized(function($t) {
|
||||
$this->wait();
|
||||
$this->line = false;
|
||||
}, $this);
|
||||
}
|
||||
|
||||
if(!extension_loaded("readline")){
|
||||
|
|
|
|||
|
|
@ -1,113 +1,113 @@
|
|||
<?php
|
||||
|
||||
class EntityAPI{
|
||||
public $entities;
|
||||
private $server;
|
||||
private $eCnt = 1;
|
||||
|
||||
function __construct(){
|
||||
$this->entities = [];
|
||||
$this->server = ServerAPI::request();
|
||||
|
||||
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
|
||||
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
|
||||
}
|
||||
|
||||
|
||||
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||
$mob = [
|
||||
"chicken" => 10,
|
||||
"cow" => 11,
|
||||
"pig" => 12,
|
||||
"sheep" => 13,
|
||||
|
||||
"zombie" => 32,
|
||||
"creeper" => 33,
|
||||
"skeleton" => 34,
|
||||
"spider" => 35,
|
||||
"pigman" => 36
|
||||
];
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "summon":
|
||||
case "spawnmob":
|
||||
if(!($issuer instanceof Player)){
|
||||
$output .= "Please run this command in-game.";
|
||||
break;
|
||||
}
|
||||
if((count($args) < 1) or (count($args) > 3)){
|
||||
$output .= "Usage: /$cmd <mob> [amount] [baby]";
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_int($args[0])) $type = $args[0];
|
||||
else $type = $mob[strtolower($args[0])];
|
||||
if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){
|
||||
$output .= "Unknown mob.";
|
||||
break;
|
||||
}
|
||||
$mobName = ucfirst(array_flip($mob)[$type]);
|
||||
|
||||
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
|
||||
$output .= "$mobName cannot be a baby!";
|
||||
break;
|
||||
}
|
||||
|
||||
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
|
||||
$y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP);
|
||||
$z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
|
||||
$level = $issuer->entity->level;
|
||||
$pos = new Position($x, $y, $z, $level);
|
||||
|
||||
if(count($args) === 1){//summon <mob>
|
||||
$this->summon($pos, ENTITY_MOB, $type);
|
||||
$output .= "$mobName spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
elseif(is_numeric($args[1])){//summon <mob> [amount]
|
||||
$amount = (int) $args[1];
|
||||
if($amount > 100){
|
||||
$output .= "Cannot spawn > 100 mobs";
|
||||
break;
|
||||
}
|
||||
$isBaby = false;
|
||||
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
|
||||
$isBaby = true;
|
||||
}
|
||||
|
||||
for($cnt = $amount; $cnt > 0; --$cnt){
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
|
||||
}
|
||||
|
||||
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
|
||||
$output .= "Baby $mobName spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "despawn":
|
||||
$cnt = 0;
|
||||
public $entities;
|
||||
private $server;
|
||||
private $eCnt = 1;
|
||||
|
||||
function __construct(){
|
||||
$this->entities = [];
|
||||
$this->server = ServerAPI::request();
|
||||
|
||||
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
|
||||
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
|
||||
}
|
||||
|
||||
public function init(){
|
||||
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
|
||||
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
|
||||
}
|
||||
|
||||
|
||||
public function commandHandler($cmd, $args, $issuer, $alias){
|
||||
$mob = [
|
||||
"chicken" => 10,
|
||||
"cow" => 11,
|
||||
"pig" => 12,
|
||||
"sheep" => 13,
|
||||
|
||||
"zombie" => 32,
|
||||
"creeper" => 33,
|
||||
"skeleton" => 34,
|
||||
"spider" => 35,
|
||||
"pigman" => 36
|
||||
];
|
||||
$output = "";
|
||||
switch($cmd){
|
||||
case "summon":
|
||||
case "spawnmob":
|
||||
if(!($issuer instanceof Player)){
|
||||
$output .= "Please run this command in-game.";
|
||||
break;
|
||||
}
|
||||
if((count($args) < 1) or (count($args) > 3)){
|
||||
$output .= "Usage: /$cmd <mob> [amount] [baby]";
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_int($args[0])) $type = $args[0];
|
||||
else $type = $mob[strtolower($args[0])];
|
||||
if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){
|
||||
$output .= "Unknown mob.";
|
||||
break;
|
||||
}
|
||||
$mobName = ucfirst(array_flip($mob)[$type]);
|
||||
|
||||
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
|
||||
$output .= "$mobName cannot be a baby!";
|
||||
break;
|
||||
}
|
||||
|
||||
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
|
||||
$y = round($issuer->entity->y, 2, PHP_ROUND_HALF_UP);
|
||||
$z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
|
||||
$level = $issuer->entity->level;
|
||||
$pos = new Position($x, $y, $z, $level);
|
||||
|
||||
if(count($args) === 1){//summon <mob>
|
||||
$this->summon($pos, ENTITY_MOB, $type);
|
||||
$output .= "$mobName spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
elseif(is_numeric($args[1])){//summon <mob> [amount]
|
||||
$amount = (int) $args[1];
|
||||
if($amount > 100){
|
||||
$output .= "Cannot spawn > 100 mobs";
|
||||
break;
|
||||
}
|
||||
$isBaby = false;
|
||||
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
|
||||
$isBaby = true;
|
||||
}
|
||||
|
||||
for($cnt = $amount; $cnt > 0; --$cnt){
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
|
||||
}
|
||||
|
||||
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
|
||||
$output .= "Baby $mobName spawned in $x, $y, $z.";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "despawn":
|
||||
$cnt = 0;
|
||||
if(!isset($args[0])){
|
||||
$output .= "/despawn <all or (mobs,objects,items,fallings)>";
|
||||
break;
|
||||
}else{
|
||||
if($args[0] === "all"){
|
||||
$cnt = 0;
|
||||
foreach($this->entities as $e){
|
||||
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
|
||||
$this->remove($e->eid);
|
||||
$cnt++;
|
||||
}
|
||||
}
|
||||
$cnt = 0;
|
||||
foreach($this->entities as $e){
|
||||
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
|
||||
$this->remove($e->eid);
|
||||
$cnt++;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$array = explode(",", strtolower($args[0]));
|
||||
if(count($array) > 4){
|
||||
|
|
@ -123,173 +123,173 @@ class EntityAPI{
|
|||
$despawning = substr($list, 0, -4);
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$this->remove($e->eid);
|
||||
$cnt++;
|
||||
}
|
||||
}
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$this->remove($e->eid);
|
||||
$cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output = "$cnt entities have been despawned!";
|
||||
break;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function summon(Position $pos, $class, $type, Array $data = []){
|
||||
$entity = $this->add($pos->level, $class, $type, [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z
|
||||
] + $data);
|
||||
$this->spawnToAll($entity, $pos->level);
|
||||
}
|
||||
|
||||
public function add(Level $level, $class, $type = 0, $data = []){
|
||||
$eid = $this->eCnt++;
|
||||
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
|
||||
if($efl instanceof PropertyEntity){
|
||||
$class = $efl->getEntityName();
|
||||
$this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data);
|
||||
}else{
|
||||
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
|
||||
}
|
||||
$level->entityList[$eid] = &$this->entities[$eid];
|
||||
$this->server->handle("entity.add", $this->entities[$eid]);
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
$this->entities[$eid]->closed = true;
|
||||
|
||||
$output = "$cnt entities have been despawned!";
|
||||
break;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function summon(Position $pos, $class, $type, Array $data = []){
|
||||
$entity = $this->add($pos->level, $class, $type, [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z
|
||||
] + $data);
|
||||
$this->spawnToAll($entity, $pos->level);
|
||||
}
|
||||
|
||||
public function add(Level $level, $class, $type = 0, $data = []){
|
||||
$eid = $this->eCnt++;
|
||||
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
|
||||
if($efl instanceof PropertyEntity){
|
||||
$class = $efl->getEntityName();
|
||||
$this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data);
|
||||
}else{
|
||||
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
|
||||
}
|
||||
$level->entityList[$eid] = &$this->entities[$eid];
|
||||
$this->server->handle("entity.add", $this->entities[$eid]);
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
|
||||
public function spawnToAll(Entity $e){
|
||||
foreach($this->server->api->player->getAll($e->level) as $player){
|
||||
if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
return $this->entities[$eid];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function remove($eid){
|
||||
if(isset($this->entities[$eid])){
|
||||
$this->entities[$eid]->closed = true;
|
||||
if($this->entities[$eid]->isPlayer()){
|
||||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $eid;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $eid;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
|
||||
$pk = new RemovePlayerPacket;
|
||||
$pk->eid = $eid;
|
||||
$pk->clientID = 0;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
}else{
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $eid;
|
||||
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
|
||||
}
|
||||
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
|
||||
unset($this->entities[$eid]->level->entityList[$eid]);
|
||||
unset($this->entities[$eid]);
|
||||
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRadius(Position $center, $radius = 15, $class = false){
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
}
|
||||
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$entities = [];
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$entities[$e->eid] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function heal($eid, $heal, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
public function harm($eid, $attack, $cause, $force = false){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
return false;
|
||||
}
|
||||
$e->setHealth($e->getHealth() - $attack, $cause, $force);
|
||||
}
|
||||
|
||||
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z,
|
||||
"level" => $pos->level,
|
||||
"speedX" => $speedX,
|
||||
"speedY" => $speedY,
|
||||
"speedZ" => $speedZ,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function drop(Position $pos, Item $item){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = [
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"speedY" => 0.2,
|
||||
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"item" => $item,
|
||||
unset($this->entities[$eid]);
|
||||
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRadius(Position $center, $radius = 15, $class = false){
|
||||
$this->server->query("UPDATE entities SET hasUpdate = 1 WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
}
|
||||
|
||||
public function getRadius(Position $center, $radius = 15, $class = false){
|
||||
$entities = [];
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
|
||||
if($l !== false and $l !== true){
|
||||
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
|
||||
$e = $this->get($e["EID"]);
|
||||
if($e instanceof Entity){
|
||||
$entities[$e->eid] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function heal($eid, $heal, $cause){
|
||||
$this->harm($eid, -$heal, $cause);
|
||||
}
|
||||
|
||||
public function harm($eid, $attack, $cause, $force = false){
|
||||
$e = $this->get($eid);
|
||||
if($e === false or $e->dead === true){
|
||||
return false;
|
||||
}
|
||||
$e->setHealth($e->getHealth() - $attack, $cause, $force);
|
||||
}
|
||||
|
||||
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = [
|
||||
"x" => $pos->x,
|
||||
"y" => $pos->y,
|
||||
"z" => $pos->z,
|
||||
"level" => $pos->level,
|
||||
"speedX" => $speedX,
|
||||
"speedY" => $speedY,
|
||||
"speedZ" => $speedZ,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
foreach($this->getAll($player->level) as $e){
|
||||
if($e->class !== ENTITY_PLAYER){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
return $level->entityList;
|
||||
}
|
||||
return $this->entities;
|
||||
}
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function drop(Position $pos, Item $item){
|
||||
if($item->getID() === AIR or $item->count <= 0){
|
||||
return;
|
||||
}
|
||||
$data = [
|
||||
"x" => $pos->x + mt_rand(-10, 10) / 50,
|
||||
"y" => $pos->y + 0.19,
|
||||
"z" => $pos->z + mt_rand(-10, 10) / 50,
|
||||
"level" => $pos->level,
|
||||
"speedX" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"speedY" => 0.2,
|
||||
"speedZ" => Utils::randomFloat() * 0.2 - 0.1,
|
||||
"item" => $item,
|
||||
];
|
||||
if($this->server->api->handle("item.drop", $data) !== false){
|
||||
for($count = $item->count; $count > 0;){
|
||||
$item->count = min($item->getMaxStackSize(), $count);
|
||||
$count -= $item->count;
|
||||
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
|
||||
$this->spawnToAll($e);
|
||||
$this->server->api->handle("entity.motion", $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnAll(Player $player){
|
||||
foreach($this->getAll($player->level) as $e){
|
||||
if($e->class !== ENTITY_PLAYER){
|
||||
$e->spawn($player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll($level = null){
|
||||
if($level instanceof Level){
|
||||
return $level->entityList;
|
||||
}
|
||||
return $this->entities;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<?php
|
||||
|
||||
class LevelAPI{
|
||||
/**
|
||||
* @var Level[]
|
||||
*/
|
||||
public $levels;
|
||||
/**
|
||||
* @var Level[]
|
||||
*/
|
||||
public $levels;
|
||||
private $server, $default;
|
||||
|
||||
public function __construct(){
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class PlayerAPI{
|
|||
$this->registerCmd("spawn");
|
||||
$this->registerCmd("ping");
|
||||
$this->server->api->console->alias("lag", "ping");
|
||||
$this->server->api->console->alias("gm", "gamemode");
|
||||
$this->server->api->console->alias("gm", "gamemode");
|
||||
$this->server->api->console->alias("who", "list");
|
||||
$this->server->api->console->alias("suicide", "kill");
|
||||
$this->server->api->console->alias("tppos", "tp");
|
||||
|
|
@ -392,7 +392,7 @@ class PlayerAPI{
|
|||
$data = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
|
||||
$data->save();
|
||||
}else{
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class PluginAPI extends stdClass{
|
|||
$this->server->api->console->register("version", "", [$this, "commandHandler"]);
|
||||
$this->server->api->console->cmdWhitelist("version");
|
||||
if($this->server->extraprops->get("query-plugins")){ //allow players to also view plugins ingame, since query makes names public
|
||||
$this->server->api->console->cmdWhitelist("plugins");
|
||||
$this->server->api->console->cmdWhitelist("plugins");
|
||||
}
|
||||
$this->server->api->console->alias("pl", "plugins");
|
||||
$this->server->api->console->alias("ver", "version");
|
||||
|
|
@ -65,7 +65,7 @@ class PluginAPI extends stdClass{
|
|||
|
||||
public function __destruct(){
|
||||
foreach($this->plugins as $p){
|
||||
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
|
||||
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
|
||||
}
|
||||
unset($this->plugins);
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ class PluginAPI extends stdClass{
|
|||
|
||||
$aver = CURRENT_API_VERSION;
|
||||
if($pluginInfo["api"] != $aver){
|
||||
console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})");
|
||||
console("[WARNING] API is not the same as Core, might cause bugs({$pluginInfo["api"]} != {$aver})");
|
||||
}
|
||||
|
||||
$phr = "phar://$filePath/";
|
||||
|
|
|
|||
|
|
@ -898,14 +898,14 @@ class Player{
|
|||
}
|
||||
}
|
||||
public function makeInvisibleForOnePlayer(Player $player){
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $this->entity->eid;
|
||||
$player->dataPacket($pk);
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $this->entity->eid;
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
public function makeInvisibleForAllPlayers(){
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $this->entity->eid;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
$pk = new RemoveEntityPacket;
|
||||
$pk->eid = $this->entity->eid;
|
||||
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
|
||||
}
|
||||
public function getGamemode(){
|
||||
switch($this->gamemode){
|
||||
|
|
@ -959,10 +959,10 @@ class Player{
|
|||
}
|
||||
|
||||
if($this->gamemode === SPECTATOR){
|
||||
$this->makeInvisibleForAllPlayers();
|
||||
$this->makeInvisibleForAllPlayers();
|
||||
}
|
||||
if($this->gamemode === CREATIVE){
|
||||
$this->server->api->player->spawnToAllPlayers($this);
|
||||
$this->server->api->player->spawnToAllPlayers($this);
|
||||
}
|
||||
|
||||
$this->inventory = $inv;
|
||||
|
|
@ -1315,17 +1315,17 @@ class Player{
|
|||
return;
|
||||
}
|
||||
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
|
||||
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 1;
|
||||
$this->directDataPacket($pk);
|
||||
}else{
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 2;
|
||||
$this->directDataPacket($pk);
|
||||
}
|
||||
$this->close("Incorrect protocol #" . $packet->protocol1, false);
|
||||
return;
|
||||
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 1;
|
||||
$this->directDataPacket($pk);
|
||||
}else{
|
||||
$pk = new LoginStatusPacket;
|
||||
$pk->status = 2;
|
||||
$this->directDataPacket($pk);
|
||||
}
|
||||
$this->close("Incorrect protocol #" . $packet->protocol1, false);
|
||||
return;
|
||||
}
|
||||
if(preg_match('#[^a-zA-Z0-9_]#', $this->username) > 0 or $this->username === "" or $this->iusername === "rcon" or $this->iusername === "console" or $this->iusername === "server"){
|
||||
$this->close("Bad username", false);
|
||||
|
|
@ -1485,7 +1485,7 @@ class Player{
|
|||
$this->sendArmor();
|
||||
$array = explode("@n", (string)$this->server->motd);
|
||||
foreach($array as $msg){
|
||||
$this->sendChat($msg."\n");
|
||||
$this->sendChat($msg."\n");
|
||||
}
|
||||
|
||||
$this->sendInventory();
|
||||
|
|
@ -1799,7 +1799,7 @@ class Player{
|
|||
$target = $this->server->api->entity->get($packet->target);
|
||||
if($target instanceof Entity and $this->entity instanceof Entity and $this->gamemode !== VIEW and $this->blocked === false and ($target instanceof Entity) and $this->entity->distance($target) <= 8){
|
||||
$data["targetentity"] = $packet->target;
|
||||
$data["entity"] = $this;
|
||||
$data["entity"] = $this;
|
||||
if($this->server->handle("player.interact", $data) !== false){
|
||||
$target->interactWith($this->entity, $packet->action);
|
||||
}
|
||||
|
|
@ -1900,18 +1900,18 @@ class Player{
|
|||
$data["item"] = $packet->item;
|
||||
$data["player"] = $this;
|
||||
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
|
||||
$f1 = 0.3;
|
||||
$sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1;
|
||||
$f1 = 0.02;
|
||||
$f3 = $this->entity->random->nextFloat() * M_PI * 2.0;
|
||||
$f1 *= $this->entity->random->nextFloat();
|
||||
$sX += cos($f3) * $f1;
|
||||
$sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1;
|
||||
$sZ += sin($f3) * $f1;
|
||||
|
||||
$this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ);
|
||||
$f1 = 0.3;
|
||||
$sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sZ = cos(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1;
|
||||
$sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1;
|
||||
$f1 = 0.02;
|
||||
$f3 = $this->entity->random->nextFloat() * M_PI * 2.0;
|
||||
$f1 *= $this->entity->random->nextFloat();
|
||||
$sX += cos($f3) * $f1;
|
||||
$sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1;
|
||||
$sZ += sin($f3) * $f1;
|
||||
|
||||
$this->server->api->entity->dropRawPos(new Position($this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $this->level), $packet->item, $sX, $sY, $sZ);
|
||||
$this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false);
|
||||
}
|
||||
if($this->entity->inAction === true){
|
||||
|
|
@ -2167,20 +2167,20 @@ class Player{
|
|||
}
|
||||
break;
|
||||
case ProtocolInfo::PLAYER_INPUT_PACKET:
|
||||
break; //TODO player input-
|
||||
break; //TODO player input-
|
||||
default:
|
||||
console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an Item which is currently held by player
|
||||
* @return Item
|
||||
*/
|
||||
|
||||
public function getHeldItem(){
|
||||
return $this->getSlot($this->slot);
|
||||
return $this->getSlot($this->slot);
|
||||
}
|
||||
|
||||
public function stopSleep(){
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class PocketMinecraftServer{
|
||||
|
||||
public $tCnt, $ticks;
|
||||
public $tCnt, $ticks;
|
||||
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
|
||||
/**
|
||||
* @var ServerAPI
|
||||
|
|
@ -70,7 +70,7 @@ class PocketMinecraftServer{
|
|||
console("[INFO] Loading extra.properties...");
|
||||
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
|
||||
"version" => "5",
|
||||
"experemental-mob-features" => false,
|
||||
"experemental-mob-features" => false,
|
||||
"enable-nether-reactor" => true,
|
||||
"enable-explosions" => true,
|
||||
"enable-rail-connection" => false,
|
||||
|
|
@ -84,7 +84,7 @@ class PocketMinecraftServer{
|
|||
]);
|
||||
Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features");
|
||||
if(Entity::$updateOnTick){
|
||||
console("[WARNING] Experemental mob features are enabled. Unpredictable behavior.");
|
||||
console("[WARNING] Experemental mob features are enabled. Unpredictable behavior.");
|
||||
}
|
||||
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
|
||||
RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config
|
||||
|
|
@ -451,31 +451,31 @@ class PocketMinecraftServer{
|
|||
}
|
||||
}
|
||||
|
||||
public function process()
|
||||
{
|
||||
$lastLoop = 0;
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
} elseif($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
} else{
|
||||
++ $lastLoop;
|
||||
if($lastLoop < 16){
|
||||
usleep(1);
|
||||
} elseif($lastLoop < 128){
|
||||
usleep(100);
|
||||
} elseif($lastLoop < 256){
|
||||
usleep(512);
|
||||
} else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
$this->tick();
|
||||
}
|
||||
}
|
||||
public function process()
|
||||
{
|
||||
$lastLoop = 0;
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$lastLoop = 0;
|
||||
} elseif($this->tick() > 0){
|
||||
$lastLoop = 0;
|
||||
} else{
|
||||
++ $lastLoop;
|
||||
if($lastLoop < 16){
|
||||
usleep(1);
|
||||
} elseif($lastLoop < 128){
|
||||
usleep(100);
|
||||
} elseif($lastLoop < 256){
|
||||
usleep(512);
|
||||
} else{
|
||||
usleep(10000);
|
||||
}
|
||||
}
|
||||
$this->tick();
|
||||
}
|
||||
}
|
||||
|
||||
public function packetHandler(Packet $packet){
|
||||
$data =& $packet;
|
||||
|
|
@ -568,7 +568,7 @@ class PocketMinecraftServer{
|
|||
unset($this->tickMeasure[key($this->tickMeasure)]);
|
||||
++$this->ticks;
|
||||
foreach($this->api->level->levels as $l){
|
||||
$l->onTick($this);
|
||||
$l->onTick($this);
|
||||
}
|
||||
return $this->tickerFunction($time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,40 @@
|
|||
<?php
|
||||
|
||||
class ArrayList{
|
||||
public $arr = [];
|
||||
public function add(IElement $e){
|
||||
$this->arr[$e->__toString()] = $e;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAll($es){
|
||||
foreach($es as $e){
|
||||
$this->add($this->add($e));
|
||||
}
|
||||
}
|
||||
|
||||
public function getFirst(){
|
||||
return array_values($this->arr)[0];
|
||||
}
|
||||
|
||||
public function remove(IElement $e){
|
||||
unset($this->arr[$e->__toString()]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __isset($e){
|
||||
return isset($this->arr[$e->__toString()]);
|
||||
}
|
||||
|
||||
public function has(IElement $e){
|
||||
return isset($this->arr[$e->__toString()]);
|
||||
}
|
||||
|
||||
public function sortWith($func){
|
||||
return uasort($this->arr, $func);
|
||||
}
|
||||
|
||||
public function countElements(){
|
||||
return count($this->arr);
|
||||
}
|
||||
public $arr = [];
|
||||
public function add(IElement $e){
|
||||
$this->arr[$e->__toString()] = $e;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addAll($es){
|
||||
foreach($es as $e){
|
||||
$this->add($this->add($e));
|
||||
}
|
||||
}
|
||||
|
||||
public function getFirst(){
|
||||
return array_values($this->arr)[0];
|
||||
}
|
||||
|
||||
public function remove(IElement $e){
|
||||
unset($this->arr[$e->__toString()]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __isset($e){
|
||||
return isset($this->arr[$e->__toString()]);
|
||||
}
|
||||
|
||||
public function has(IElement $e){
|
||||
return isset($this->arr[$e->__toString()]);
|
||||
}
|
||||
|
||||
public function sortWith($func){
|
||||
return uasort($this->arr, $func);
|
||||
}
|
||||
|
||||
public function countElements(){
|
||||
return count($this->arr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface IElement
|
||||
{
|
||||
public function __toString();
|
||||
public function __toString();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface ITileNavigator
|
||||
{
|
||||
public function navigate(PathTile $from, PathTile $to);
|
||||
public function navigate(PathTile $from, PathTile $to);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
class PHPUtils
|
||||
{
|
||||
public static function removeElementFromArray(&$arr, $element, $reindex = true){
|
||||
if (($key = array_search($element, $arr)) !== false) {
|
||||
unset($arr[$key]);
|
||||
if($reindex) $arr = array_values($arr);
|
||||
}
|
||||
}
|
||||
public static function removeElementFromArray(&$arr, $element, $reindex = true){
|
||||
if (($key = array_search($element, $arr)) !== false) {
|
||||
unset($arr[$key]);
|
||||
if($reindex) $arr = array_values($arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,26 +2,26 @@
|
|||
|
||||
class PathTile implements IElement
|
||||
{
|
||||
public $x, $y;
|
||||
|
||||
public function __construct($x, $y){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function equals(PathTile $t){
|
||||
return $t->x === $this->x && $t->y === $this->y;
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->x.":".$this->y;
|
||||
}
|
||||
public $x, $y;
|
||||
|
||||
public function __construct($x, $y){
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
||||
public function equals(PathTile $t){
|
||||
return $t->x === $this->x && $t->y === $this->y;
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->x.":".$this->y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,37 +2,37 @@
|
|||
|
||||
class PathTileXYZ extends PathTile
|
||||
{
|
||||
public $x, $y, $z;
|
||||
|
||||
/**
|
||||
* @var Level
|
||||
*/
|
||||
public $level;
|
||||
|
||||
public function __construct($x, $y, $z, $level){
|
||||
$this->x = floor($x);
|
||||
$this->y = floor($y);
|
||||
$this->z = floor($z);
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function equals(PathTile $t){
|
||||
return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z;
|
||||
}
|
||||
|
||||
public function asVector(){
|
||||
return new Vector3($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
$this->z += $offset[2];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->x.":".$this->y.":".$this->z;
|
||||
}
|
||||
public $x, $y, $z;
|
||||
|
||||
/**
|
||||
* @var Level
|
||||
*/
|
||||
public $level;
|
||||
|
||||
public function __construct($x, $y, $z, $level){
|
||||
$this->x = floor($x);
|
||||
$this->y = floor($y);
|
||||
$this->z = floor($z);
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
public function equals(PathTile $t){
|
||||
return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z;
|
||||
}
|
||||
|
||||
public function asVector(){
|
||||
return new Vector3($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
$this->z += $offset[2];
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString(){
|
||||
return $this->x.":".$this->y.":".$this->z;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
class TileNavigator implements ITileNavigator
|
||||
{
|
||||
private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm;
|
||||
public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){
|
||||
$this->blockedProvider = $blockedProvider;
|
||||
$this->neighborProvider = $neighborProvider;
|
||||
$this->distanceAlgorithm = $distanceAlgorithm;
|
||||
$this->heuristicAlgorithm = $heuristicAlgorithm;
|
||||
}
|
||||
|
||||
public function reconstructPath($path, $current){
|
||||
private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm;
|
||||
public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){
|
||||
$this->blockedProvider = $blockedProvider;
|
||||
$this->neighborProvider = $neighborProvider;
|
||||
$this->distanceAlgorithm = $distanceAlgorithm;
|
||||
$this->heuristicAlgorithm = $heuristicAlgorithm;
|
||||
}
|
||||
|
||||
public function reconstructPath($path, $current){
|
||||
$totalPath = [$current];
|
||||
while (isset($path[(string)$current]))
|
||||
{
|
||||
|
|
@ -20,67 +20,67 @@ class TileNavigator implements ITileNavigator
|
|||
//foreach(array_unique($path) as $k => $p) console($k.":".$p);
|
||||
//foreach($totalPath as $k => $p) console($k.":".$p);
|
||||
array_pop($totalPath);
|
||||
return array_reverse($totalPath);
|
||||
}
|
||||
|
||||
public function navigate(PathTile $from, PathTile $to)
|
||||
{
|
||||
$closed = new ArrayList();
|
||||
$open = new ArrayList();
|
||||
$open->add($from);
|
||||
$path = []; //new Dictionary<Tile, Tile>();
|
||||
$gScore = []; //new Dictionary<Tile, double>();
|
||||
$gScore[(string) $from] = 0;
|
||||
/**
|
||||
* @var array[Tile] $fScore
|
||||
*/
|
||||
$fScore = [];//new Dictionary<Tile, double>();
|
||||
$fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to);
|
||||
if($this->blockedProvider->isBlocked($to)){
|
||||
return null;
|
||||
}
|
||||
$visited = [];
|
||||
while($open->countElements() > 0)
|
||||
{
|
||||
//sleep(1);
|
||||
$open->sortWith(function($k, $k1) use ($fScore){
|
||||
return $fScore[(string)$k] === $fScore[(string)$k1] ? 0 : ($fScore[(string)$k] > $fScore[(string)$k1] ? 1 : -1);
|
||||
});
|
||||
$current = $open->getFirst();
|
||||
if ($current->equals($to)){
|
||||
return $this->reconstructPath($path, $current);
|
||||
}
|
||||
$open->remove($current);
|
||||
$closed->add($current);
|
||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||
{
|
||||
if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(in_array($neighbor, $visited)){
|
||||
continue;
|
||||
return array_reverse($totalPath);
|
||||
}
|
||||
|
||||
public function navigate(PathTile $from, PathTile $to)
|
||||
{
|
||||
$closed = new ArrayList();
|
||||
$open = new ArrayList();
|
||||
$open->add($from);
|
||||
$path = []; //new Dictionary<Tile, Tile>();
|
||||
$gScore = []; //new Dictionary<Tile, double>();
|
||||
$gScore[(string) $from] = 0;
|
||||
/**
|
||||
* @var array[Tile] $fScore
|
||||
*/
|
||||
$fScore = [];//new Dictionary<Tile, double>();
|
||||
$fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to);
|
||||
if($this->blockedProvider->isBlocked($to)){
|
||||
return null;
|
||||
}
|
||||
$visited[] = $neighbor;
|
||||
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||
|
||||
if (!$open->has($neighbor))
|
||||
{
|
||||
$open->add($neighbor);
|
||||
}
|
||||
else if ($tentativeG >= $gScore[(string) $neighbor])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$path[(string) $neighbor] = $current;
|
||||
$gScore[(string) $neighbor] = $tentativeG;
|
||||
$fScore[(string) $neighbor] = $gScore[(string) $neighbor] + $this->heuristicAlgorithm->calculate($neighbor, $to);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
$visited = [];
|
||||
while($open->countElements() > 0)
|
||||
{
|
||||
//sleep(1);
|
||||
$open->sortWith(function($k, $k1) use ($fScore){
|
||||
return $fScore[(string)$k] === $fScore[(string)$k1] ? 0 : ($fScore[(string)$k] > $fScore[(string)$k1] ? 1 : -1);
|
||||
});
|
||||
$current = $open->getFirst();
|
||||
if ($current->equals($to)){
|
||||
return $this->reconstructPath($path, $current);
|
||||
}
|
||||
$open->remove($current);
|
||||
$closed->add($current);
|
||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||
{
|
||||
if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(in_array($neighbor, $visited)){
|
||||
continue;
|
||||
}
|
||||
$visited[] = $neighbor;
|
||||
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||
|
||||
if (!$open->has($neighbor))
|
||||
{
|
||||
$open->add($neighbor);
|
||||
}
|
||||
else if ($tentativeG >= $gScore[(string) $neighbor])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$path[(string) $neighbor] = $current;
|
||||
$gScore[(string) $neighbor] = $tentativeG;
|
||||
$fScore[(string) $neighbor] = $gScore[(string) $neighbor] + $this->heuristicAlgorithm->calculate($neighbor, $to);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface IDistanceAlgorithm
|
||||
{
|
||||
public function calculate(PathTile $from, PathTile $to);
|
||||
public function calculate(PathTile $from, PathTile $to);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
class ManhattanHeuristic3D implements IDistanceAlgorithm
|
||||
{
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
|
||||
return Utils::manh_distance($from->asVector(), $to->asVector());
|
||||
}
|
||||
return 666;
|
||||
}
|
||||
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
|
||||
return Utils::manh_distance($from->asVector(), $to->asVector());
|
||||
}
|
||||
return 666;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
class ManhattanHeuristicAlgorithm implements IDistanceAlgorithm
|
||||
{
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
return abs($from->x - $to->x) + abs($from->y - $to->y);
|
||||
}
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
return abs($from->x - $to->x) + abs($from->y - $to->y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
class Pythagoras3D implements IDistanceAlgorithm
|
||||
{
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
|
||||
return Utils::distance_noroot($from->asVector(), $to->asVector());
|
||||
}
|
||||
return 666;
|
||||
}
|
||||
if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
|
||||
return Utils::distance_noroot($from->asVector(), $to->asVector());
|
||||
}
|
||||
return 666;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
class PythagorasAlgorithm implements IDistanceAlgorithm
|
||||
{
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2));
|
||||
}
|
||||
public function calculate(PathTile $from, PathTile $to)
|
||||
{
|
||||
return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
class DiagonalNeighborProvider implements INeighborProvider
|
||||
{
|
||||
private static $neighbors = array([ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ -1, -1 ], [ 1, -1 ], [ 1, 1 ], [ -1, 1 ]);
|
||||
|
||||
public function getNeighbors(PathTile $tile)
|
||||
{
|
||||
$result = [];
|
||||
foreach(self::$neighbors as $offset){
|
||||
$t = clone $tile;
|
||||
$result[] = $t->addOffset($offset);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
private static $neighbors = array([ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ -1, -1 ], [ 1, -1 ], [ 1, 1 ], [ -1, 1 ]);
|
||||
|
||||
public function getNeighbors(PathTile $tile)
|
||||
{
|
||||
$result = [];
|
||||
foreach(self::$neighbors as $offset){
|
||||
$t = clone $tile;
|
||||
$result[] = $t->addOffset($offset);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
class EmptyBlockedProvider implements IBlockedProvider
|
||||
{
|
||||
public function isBlocked(PathTile $tile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public function isBlocked(PathTile $tile)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
interface IBlockedProvider
|
||||
{
|
||||
/**
|
||||
* @param Tile $tile
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBlocked(PathTile $tile);
|
||||
/**
|
||||
* @param Tile $tile
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBlocked(PathTile $tile);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface INeighborProvider
|
||||
{
|
||||
public function getNeighbors(PathTile $tile);
|
||||
public function getNeighbors(PathTile $tile);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
class MCBlockedProvider implements IBlockedProvider
|
||||
{
|
||||
public function isBlocked(PathTile $tile)
|
||||
public function isBlocked(PathTile $tile)
|
||||
{
|
||||
if($tile instanceof PathTileXYZ){
|
||||
$b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z);
|
||||
return $b instanceof Block && $b->isSolid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if($tile instanceof PathTileXYZ){
|
||||
$b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z);
|
||||
return $b instanceof Block && $b->isSolid;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
class MCDiagonalProvider implements INeighborProvider
|
||||
{
|
||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]);
|
||||
public function getNeighbors(PathTile $tile)
|
||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]);
|
||||
public function getNeighbors(PathTile $tile)
|
||||
{
|
||||
|
||||
if($tile instanceof PathTileXYZ){
|
||||
$result = [];
|
||||
foreach(self::$neighbors as $offset){
|
||||
$t = clone $tile;
|
||||
$result[] = $t->addOffset($offset);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
if($tile instanceof PathTileXYZ){
|
||||
$result = [];
|
||||
foreach(self::$neighbors as $offset){
|
||||
$t = clone $tile;
|
||||
$result[] = $t->addOffset($offset);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,46 +14,46 @@ rm bin.7z
|
|||
echo "["$(date +%k:%M)"] Downloading PHP..."
|
||||
arch=$(uname -m)
|
||||
if [[ $arch == x86_64* ]]; then
|
||||
echo "X64 Architecture"
|
||||
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
|
||||
echo "X64 Architecture"
|
||||
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
|
||||
tar -xvf NC_bin.tar.gz
|
||||
rm NC_bin.tar.gz
|
||||
elif [[ $arch == i*86 ]]; then
|
||||
echo "X32 Architecture"
|
||||
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
|
||||
echo "X32 Architecture"
|
||||
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
|
||||
tar -xvf NC_bin.tar.gz
|
||||
rm NC_bin.tar.gz
|
||||
elif [[ $arch == arm* ]] || [[ $arch = aarch* ]]; then
|
||||
echo "ARM Architecture"
|
||||
wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null
|
||||
echo "ARM Architecture"
|
||||
wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null
|
||||
tar -xvf NCArm_bin.tar.gz
|
||||
rm NCArm_bin.tar.gz
|
||||
fi
|
||||
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
|
||||
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
|
||||
XDEBUG_PATH="$(find $(pwd) -name xdebug.so)"
|
||||
echo "" > "./bin/php5/bin/php.ini"
|
||||
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
|
||||
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "zend_extension=\"$XDEBUG_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
|
||||
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
|
||||
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "phar.readonly=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "done"
|
||||
alldone=yes
|
||||
OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
|
||||
XDEBUG_PATH="$(find $(pwd) -name xdebug.so)"
|
||||
echo "" > "./bin/php5/bin/php.ini"
|
||||
#UOPZ_PATH="$(find $(pwd) -name uopz.so)"
|
||||
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "zend_extension=\"$OPCACHE_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "zend_extension=\"$XDEBUG_PATH\"" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.enable=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.enable_cli=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.save_comments=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.max_accelerated_files=4096" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.memory_consumption=128" >> "./bin/php5/bin/php.ini"
|
||||
echo "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
|
||||
echo "date.timezone=$TIMEZONE" >> "./bin/php5/bin/php.ini"
|
||||
echo "short_open_tag=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "asp_tags=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "phar.readonly=0" >> "./bin/php5/bin/php.ini"
|
||||
echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini"
|
||||
echo "done"
|
||||
alldone=yes
|
||||
else
|
||||
echo "Invalid PHP build detected"
|
||||
echo "Invalid PHP build detected"
|
||||
fi
|
||||
echo "Done, starting..."
|
||||
echo "Wait >15 seconds..."
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ mkdir -p $COMPILEDIR
|
|||
|
||||
if [ "$COMPILE_LINUX_32BIT" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit
|
||||
cd $COMPILEDIR/linux/32bit
|
||||
|
||||
CFLAGS=-m32 march=i686 mtune=generic $SCRIPT
|
||||
|
||||
cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit
|
||||
cd $COMPILEDIR/linux/32bit
|
||||
|
||||
CFLAGS=-m32 march=i686 mtune=generic $SCRIPT
|
||||
|
||||
cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/
|
||||
if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -41,12 +41,12 @@ fi
|
|||
|
||||
if [ "$COMPILE_LINUX_64BIT" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit
|
||||
cd $COMPILEDIR/linux/64bit
|
||||
|
||||
$SCRIPT
|
||||
|
||||
cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit
|
||||
cd $COMPILEDIR/linux/64bit
|
||||
|
||||
$SCRIPT
|
||||
|
||||
cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/
|
||||
if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -54,9 +54,9 @@ fi
|
|||
|
||||
if [ "$COMPILE_MAC" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/mac
|
||||
cd $COMPILEDIR/mac
|
||||
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/mac
|
||||
cd $COMPILEDIR/mac
|
||||
|
||||
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
|
||||
cd libtool-2.4.2
|
||||
./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null
|
||||
|
|
@ -66,9 +66,9 @@ then
|
|||
rm -rf libtool-2.4.2
|
||||
export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool"
|
||||
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
|
||||
$SCRIPT mac curl
|
||||
|
||||
cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/
|
||||
$SCRIPT mac curl
|
||||
|
||||
cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/
|
||||
if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -76,12 +76,12 @@ fi
|
|||
|
||||
if [ "$COMPILE_RPI" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi
|
||||
cd $COMPILEDIR/rpi
|
||||
|
||||
$SCRIPT rpi
|
||||
|
||||
cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi
|
||||
cd $COMPILEDIR/rpi
|
||||
|
||||
$SCRIPT rpi
|
||||
|
||||
cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/
|
||||
if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -89,12 +89,12 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6
|
||||
cd $COMPILEDIR/crosscompile/android-armv6
|
||||
|
||||
$SCRIPT crosscompile android-armv6
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6
|
||||
cd $COMPILEDIR/crosscompile/android-armv6
|
||||
|
||||
$SCRIPT crosscompile android-armv6
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv6/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -102,12 +102,12 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7
|
||||
cd $COMPILEDIR/crosscompile/android-armv7
|
||||
|
||||
$SCRIPT crosscompile android-armv7
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7
|
||||
cd $COMPILEDIR/crosscompile/android-armv7
|
||||
|
||||
$SCRIPT crosscompile android-armv7
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/android-armv7/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -115,8 +115,8 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6
|
||||
cd $COMPILEDIR/crosscompile/ios-armv6
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6
|
||||
cd $COMPILEDIR/crosscompile/ios-armv6
|
||||
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
|
||||
cd libtool-2.4.2
|
||||
./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null
|
||||
|
|
@ -126,9 +126,9 @@ then
|
|||
rm -rf libtool-2.4.2
|
||||
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool"
|
||||
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize"
|
||||
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/
|
||||
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv6
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/ios-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv6/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -136,8 +136,8 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7
|
||||
cd $COMPILEDIR/crosscompile/ios-armv7
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7
|
||||
cd $COMPILEDIR/crosscompile/ios-armv7
|
||||
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
|
||||
cd libtool-2.4.2
|
||||
./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null
|
||||
|
|
@ -147,9 +147,9 @@ then
|
|||
rm -rf libtool-2.4.2
|
||||
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool"
|
||||
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize"
|
||||
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/
|
||||
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT crosscompile ios-armv7
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/ios-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/ios-armv7/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -157,12 +157,12 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_RPI" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi
|
||||
cd $COMPILEDIR/crosscompile/rpi
|
||||
|
||||
$SCRIPT crosscompile rpi
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi
|
||||
cd $COMPILEDIR/crosscompile/rpi
|
||||
|
||||
$SCRIPT crosscompile rpi
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/rpi/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -170,12 +170,12 @@ fi
|
|||
|
||||
if [ "$CROSSCOMPILE_MAC" = "true" ];
|
||||
then
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac
|
||||
cd $COMPILEDIR/crosscompile/mac
|
||||
|
||||
$SCRIPT crosscompile mac curl
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/
|
||||
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac
|
||||
cd $COMPILEDIR/crosscompile/mac
|
||||
|
||||
$SCRIPT crosscompile mac curl
|
||||
|
||||
cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/
|
||||
if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -5,58 +5,58 @@ move methods
|
|||
*/
|
||||
abstract class Animal extends Creature implements Ageable, Breedable{
|
||||
|
||||
public $parent;
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public $age;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
|
||||
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
|
||||
$this->setAge(-24000);
|
||||
}
|
||||
$this->ai->addTask(new TaskTempt());
|
||||
}
|
||||
|
||||
public $parent;
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public $age;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
|
||||
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
|
||||
$this->setAge(-24000);
|
||||
}
|
||||
$this->ai->addTask(new TaskTempt());
|
||||
}
|
||||
|
||||
public function isBaby(){
|
||||
return $this->getAge() < 0;
|
||||
}
|
||||
|
||||
public function breed(){
|
||||
$c = $this->spawnChild();
|
||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){
|
||||
$c->parent = &$this;
|
||||
$this->server->api->entity->spawnToAll($c);
|
||||
}
|
||||
$c = $this->spawnChild();
|
||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){
|
||||
$c->parent = &$this;
|
||||
$this->server->api->entity->spawnToAll($c);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
parent::update();
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
$this->updateMetadata();
|
||||
}else{
|
||||
$this->setAge($age);
|
||||
}
|
||||
parent::update();
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
$this->updateMetadata();
|
||||
}else{
|
||||
$this->setAge($age);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAge(){
|
||||
return $this->age;
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
public function setAge($i){
|
||||
$this->age = $i;
|
||||
$this->age = $i;
|
||||
}
|
||||
|
||||
public function spawnChild()
|
||||
{
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"y" => $this->y,
|
||||
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"IsBaby" => true,
|
||||
"Age" => -24000,
|
||||
]);
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"y" => $this->y,
|
||||
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"IsBaby" => true,
|
||||
"Age" => -24000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
|
|
@ -66,33 +66,33 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function isInLove(){
|
||||
return $this->inLove > 0;
|
||||
return $this->inLove > 0;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID())){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
$this->inLove = 600; //600 ticks, original mehod from mcpe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID())){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
$this->inLove = 600; //600 ticks, original mehod from mcpe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function counterUpdate(){
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -25,30 +25,30 @@ abstract class Creature extends Living{
|
|||
}
|
||||
|
||||
public function update(){
|
||||
if($this->onGround){
|
||||
/*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
|
||||
$this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level));
|
||||
}
|
||||
if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){
|
||||
$this->path = null;
|
||||
$this->currentIndex = 0;
|
||||
$this->currentNode = false;
|
||||
}elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false)){
|
||||
$this->currentNode = $this->path[$this->currentIndex++];
|
||||
}*/
|
||||
}
|
||||
parent::update();
|
||||
|
||||
if($this->onGround){
|
||||
/*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
|
||||
$this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level));
|
||||
}
|
||||
if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){
|
||||
$this->path = null;
|
||||
$this->currentIndex = 0;
|
||||
$this->currentNode = false;
|
||||
}elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === false)){
|
||||
$this->currentNode = $this->path[$this->currentIndex++];
|
||||
}*/
|
||||
}
|
||||
parent::update();
|
||||
|
||||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["State"] = @$this->getState();
|
||||
return $data;
|
||||
$data = parent::createSaveData();
|
||||
$data["State"] = @$this->getState();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getSpeedModifer(){
|
||||
return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7);
|
||||
return $this->speedModifer * ($this->inPanic ? 1.4 : 0.7);
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class Entity extends Position
|
|||
public $radius;
|
||||
public $inAction = false;
|
||||
public $hasKnockback;
|
||||
|
||||
|
||||
public $onGround;
|
||||
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
|
||||
|
|
@ -624,7 +624,7 @@ class Entity extends Position
|
|||
break;
|
||||
}
|
||||
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid && $this->isMoving()){
|
||||
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
$this->speedX = $b->boundingBox->calculateXOffset($this->boundingBox, $this->speedX);
|
||||
$this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
|
||||
$lastY = $this->speedY;
|
||||
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
|
||||
|
|
@ -638,34 +638,34 @@ class Entity extends Position
|
|||
|
||||
}
|
||||
if(!$support){
|
||||
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->width)){
|
||||
$b = $this->level->getBlock($v);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} 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->width)){
|
||||
$b = $this->level->getBlock($v1);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($support === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
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->width)){
|
||||
$b = $this->level->getBlock($v);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} 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->width)){
|
||||
$b = $this->level->getBlock($v1);
|
||||
if($b->isSolid === true){
|
||||
$support = true;
|
||||
$isFlying = false;
|
||||
break;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($support === true){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($this->speedX != 0){
|
||||
$this->x += $this->speedX;
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
<?php
|
||||
|
||||
abstract class Living extends Entity implements Damageable{
|
||||
public $target, $ai;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->target = false;
|
||||
$this->ai = new EntityAI($this);
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->canBeAttacked = true;
|
||||
$this->hasGravity = true;
|
||||
$this->hasKnockback = true;
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->idleTime <= 0) {
|
||||
$this->ai->updateTasks();
|
||||
}
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public $target, $ai;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||
$this->target = false;
|
||||
$this->ai = new EntityAI($this);
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->canBeAttacked = true;
|
||||
$this->hasGravity = true;
|
||||
$this->hasKnockback = true;
|
||||
}
|
||||
|
||||
public function update(){
|
||||
if($this->idleTime <= 0) {
|
||||
$this->ai->updateTasks();
|
||||
}
|
||||
parent::update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
abstract class WalkingEntity extends Entity{
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param int $tickDiff
|
||||
*
|
||||
* @return null|Vector3
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param int $tickDiff
|
||||
*
|
||||
* @return null|Vector3
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -2,74 +2,74 @@
|
|||
|
||||
class EntityAI
|
||||
{
|
||||
/**
|
||||
* @var MobController
|
||||
*/
|
||||
public $mobController;
|
||||
/**
|
||||
* @var Living
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
/**
|
||||
* @var TaskBase[]
|
||||
*/
|
||||
protected $tasks;
|
||||
|
||||
public $lastTask;
|
||||
|
||||
public $counter = 0;
|
||||
|
||||
public function __construct($entity){
|
||||
$this->entity = $entity;
|
||||
$this->tasks = [];
|
||||
$this->mobController = new MobController($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task for entity
|
||||
* @param TaskBase $task
|
||||
*/
|
||||
public function addTask(TaskBase $task){
|
||||
console("[DEBUG] Adding new task...",true, true, 2);
|
||||
$this->tasks[$task->__toString()] = $task;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param mixed $id classname
|
||||
* @return TaskBase | false
|
||||
*/
|
||||
public function getTask($id){
|
||||
return isset($this->tasks[$id]) ? $this->tasks[$id] : false;
|
||||
}
|
||||
|
||||
public function isStarted($id){
|
||||
$task = @$this->getTask($id);
|
||||
return $task instanceof TaskBase && $task->isStarted;
|
||||
}
|
||||
/**
|
||||
* @var MobController
|
||||
*/
|
||||
public $mobController;
|
||||
/**
|
||||
* @var Living
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
/**
|
||||
* @var TaskBase[]
|
||||
*/
|
||||
protected $tasks;
|
||||
|
||||
public $lastTask;
|
||||
|
||||
public $counter = 0;
|
||||
|
||||
public function __construct($entity){
|
||||
$this->entity = $entity;
|
||||
$this->tasks = [];
|
||||
$this->mobController = new MobController($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task for entity
|
||||
* @param TaskBase $task
|
||||
*/
|
||||
public function addTask(TaskBase $task){
|
||||
console("[DEBUG] Adding new task...",true, true, 2);
|
||||
$this->tasks[$task->__toString()] = $task;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param mixed $id classname
|
||||
* @return TaskBase | false
|
||||
*/
|
||||
public function getTask($id){
|
||||
return isset($this->tasks[$id]) ? $this->tasks[$id] : false;
|
||||
}
|
||||
|
||||
public function isStarted($id){
|
||||
$task = @$this->getTask($id);
|
||||
return $task instanceof TaskBase && $task->isStarted;
|
||||
}
|
||||
|
||||
public function updateTasks(){
|
||||
if($this->counter % 3 != 0){
|
||||
return;
|
||||
}
|
||||
foreach($this->tasks as $t){
|
||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||
$t->isStarted = true;
|
||||
$t->onStart($this);
|
||||
}
|
||||
if($t->isStarted){
|
||||
$t->onUpdate($this);
|
||||
if($t->selfCounter <= 0){
|
||||
$t->isStarted = false;
|
||||
$t->onEnd($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
|
||||
public function updateTasks(){
|
||||
if($this->counter % 3 != 0){
|
||||
return;
|
||||
}
|
||||
foreach($this->tasks as $t){
|
||||
if(!$t->isStarted && $t->canBeExecuted($this)){
|
||||
$t->isStarted = true;
|
||||
$t->onStart($this);
|
||||
}
|
||||
if($t->isStarted){
|
||||
$t->onUpdate($this);
|
||||
if($t->selfCounter <= 0){
|
||||
$t->isStarted = false;
|
||||
$t->onEnd($this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,70 +2,70 @@
|
|||
|
||||
class MobController
|
||||
{
|
||||
/**
|
||||
* @var Entity
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
public function __construct($e){
|
||||
$this->entity = $e;
|
||||
}
|
||||
|
||||
public function moveNonInstant($x, $y, $z){
|
||||
if($x == 0 && $y == 0 && $z == 0){
|
||||
return false; //failed
|
||||
}
|
||||
|
||||
$ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0));
|
||||
$oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0));
|
||||
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
|
||||
$this->entity->moveEntityWithOffset($ox, $oy, $oz);
|
||||
$this->faceEntity($this->entity->add($ox, $oy, $oz));
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $this->entity->eid;
|
||||
$pk->yaw = $this->entity->yaw;
|
||||
$this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function moveTo($x, $y, $z){
|
||||
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z));
|
||||
}
|
||||
|
||||
public function faceEntity(Vector3 $v){
|
||||
$d = $v->subtract($this->entity)->normalize();
|
||||
$dx = $d->x;
|
||||
$dz = $d->z;
|
||||
|
||||
$tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz));
|
||||
$thetaOffset = $dz < 0 ? 90 : 270;
|
||||
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
||||
}
|
||||
|
||||
public function lookOffset($x, $y, $z, $pitch = true){
|
||||
$tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
|
||||
$thetaOffset = $z < 0 ? 90 : 270;
|
||||
$calcYaw = $tan + $thetaOffset;
|
||||
$this->entity->yaw = $calcYaw;
|
||||
if($pitch){
|
||||
$diff = sqrt($x * $x + $z * $z);
|
||||
$calcPitch = rad2deg(atan($y / $diff));
|
||||
$this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch;
|
||||
}
|
||||
|
||||
$this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";");
|
||||
return true;
|
||||
}
|
||||
|
||||
public function lookOn($x, $y = 0, $z = 0, $pitch = true){
|
||||
if($x instanceof Vector3){
|
||||
return $this->lookOn($x->x, $x->y + $x->getEyeHeight(), $x->z, $pitch);
|
||||
}
|
||||
return $this->lookOffset($x - $this->entity->x, ($this->entity->y + $this->entity->height) - $y, $z - $this->entity->z, $pitch);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
/**
|
||||
* @var Entity
|
||||
*/
|
||||
public $entity;
|
||||
|
||||
public function __construct($e){
|
||||
$this->entity = $e;
|
||||
}
|
||||
|
||||
public function moveNonInstant($x, $y, $z){
|
||||
if($x == 0 && $y == 0 && $z == 0){
|
||||
return false; //failed
|
||||
}
|
||||
|
||||
$ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0));
|
||||
$oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0));
|
||||
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
|
||||
$this->entity->moveEntityWithOffset($ox, $oy, $oz);
|
||||
$this->faceEntity($this->entity->add($ox, $oy, $oz));
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $this->entity->eid;
|
||||
$pk->yaw = $this->entity->yaw;
|
||||
$this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function moveTo($x, $y, $z){
|
||||
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z));
|
||||
}
|
||||
|
||||
public function faceEntity(Vector3 $v){
|
||||
$d = $v->subtract($this->entity)->normalize();
|
||||
$dx = $d->x;
|
||||
$dz = $d->z;
|
||||
|
||||
$tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz));
|
||||
$thetaOffset = $dz < 0 ? 90 : 270;
|
||||
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
||||
}
|
||||
|
||||
public function lookOffset($x, $y, $z, $pitch = true){
|
||||
$tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
|
||||
$thetaOffset = $z < 0 ? 90 : 270;
|
||||
$calcYaw = $tan + $thetaOffset;
|
||||
$this->entity->yaw = $calcYaw;
|
||||
if($pitch){
|
||||
$diff = sqrt($x * $x + $z * $z);
|
||||
$calcPitch = rad2deg(atan($y / $diff));
|
||||
$this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch;
|
||||
}
|
||||
|
||||
$this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";");
|
||||
return true;
|
||||
}
|
||||
|
||||
public function lookOn($x, $y = 0, $z = 0, $pitch = true){
|
||||
if($x instanceof Vector3){
|
||||
return $this->lookOn($x->x, $x->y + $x->getEyeHeight(), $x->z, $pitch);
|
||||
}
|
||||
return $this->lookOffset($x - $this->entity->x, ($this->entity->y + $this->entity->height) - $y, $z - $this->entity->z, $pitch);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
unset($this->entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,73 +0,0 @@
|
|||
<?php
|
||||
class PathNavigator
|
||||
{
|
||||
const PATH_COMPLETED = 0x1;
|
||||
const PATH_CONTINUE = 0x2;
|
||||
const PATH_CANT_CONTINUE = 0x3;
|
||||
public $entity;
|
||||
/**
|
||||
* @var Node
|
||||
*/
|
||||
private $getTo;
|
||||
public $currentPointIndex;
|
||||
public function __construct(Creature &$entity){
|
||||
$this->entity = $entity;
|
||||
$this->currentPointIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
public function reset(){
|
||||
$this->currentPointIndex = 0;
|
||||
}
|
||||
/**
|
||||
* @param Node[] $path
|
||||
*/
|
||||
public function followPath($path){ //TODO remove local var
|
||||
if(!$this->canContinue()){
|
||||
console($this->getTo);
|
||||
console($this->entity);
|
||||
$diffX = $this->getTo->x - $this->entity->x;
|
||||
$diffY = 0; //todo ?
|
||||
$diffZ = $this->getTo->z - $this->entity->z;
|
||||
|
||||
$this->entity->moveEntityWithOffset(Utils::getSign($diffX), Utils::getSign($diffY), Utils::getSign($diffZ));
|
||||
return self::PATH_CANT_CONTINUE;
|
||||
}
|
||||
$index = $this->currentPointIndex++;
|
||||
if($index >= count($path)){
|
||||
$this->onPathEnd();
|
||||
console("COMPLETED");
|
||||
return self::PATH_COMPLETED;
|
||||
}
|
||||
$node = $path[$index];
|
||||
|
||||
$this->getTo = $node;
|
||||
|
||||
$diffX = $node->x - $this->entity->x;
|
||||
$diffY = 0; //todo ?
|
||||
$diffZ = $node->z - $this->entity->z;
|
||||
|
||||
$this->entity->moveEntityWithOffset(Utils::getSign($diffX), Utils::getSign($diffY), Utils::getSign($diffZ));
|
||||
|
||||
return self::PATH_CONTINUE;
|
||||
}
|
||||
|
||||
public function canContinue(){
|
||||
return empty($this->getTo) || (floor($this->entity->x) == floor($this->getTo->x) && floor($this->entity->z) == floor($this->getTo->z));
|
||||
}
|
||||
|
||||
public function onPathEnd(){
|
||||
$this->currentPointIndex = 0;
|
||||
unset($this->getTo);
|
||||
}
|
||||
|
||||
public function testLook($pos){
|
||||
$x = $pos->x - $this->entity->x;
|
||||
$y = $pos->y - $this->entity->y;
|
||||
$z = $pos->z - $this->entity->z;
|
||||
$this->entity->yaw = -atan2($this->entity->speedX, $this->entity->speedZ) * 180 / M_PI;
|
||||
$this->entity->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt(pow($x, 2) + pow($z, 2))));
|
||||
$this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2,46 +2,46 @@
|
|||
|
||||
abstract class TaskBase
|
||||
{
|
||||
public $isStarted = false, $selfCounter = 0;
|
||||
|
||||
/**
|
||||
* Executed when entity starts task. It is recommended to set counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onStart(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Every tick until counter will be not equal to 0. It is recommended to update value of counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onUpdate(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* On task end.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onEnd(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Can start the task
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function canBeExecuted(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* @return number ticks
|
||||
*/
|
||||
function getIdleTimeAfterEnd(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reset(){
|
||||
$this->isStarted = false;
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
|
||||
final function __toString(){
|
||||
return get_class($this);
|
||||
}
|
||||
public $isStarted = false, $selfCounter = 0;
|
||||
|
||||
/**
|
||||
* Executed when entity starts task. It is recommended to set counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onStart(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Every tick until counter will be not equal to 0. It is recommended to update value of counter here.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onUpdate(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* On task end.
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function onEnd(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* Can start the task
|
||||
* @param EntityAI $ai
|
||||
*/
|
||||
abstract function canBeExecuted(EntityAI $ai);
|
||||
|
||||
/**
|
||||
* @return number ticks
|
||||
*/
|
||||
function getIdleTimeAfterEnd(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
function reset(){
|
||||
$this->isStarted = false;
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
|
||||
final function __toString(){
|
||||
return get_class($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,35 +2,35 @@
|
|||
|
||||
class TaskLookAround extends TaskBase
|
||||
{
|
||||
private $rotation;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
$this->rotation = mt_rand(-120, 120);
|
||||
}
|
||||
private $rotation;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->selfCounter = 1;
|
||||
$this->rotation = mt_rand(-120, 120);
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$ai->entity->idleTime = mt_rand(20, 40);
|
||||
}
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$ai->entity->idleTime = mt_rand(20, 40);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
|
||||
}
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($this->rotation === 0){
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
|
||||
$ai->entity->yaw += $v;
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$this->rotation -= $v;
|
||||
|
||||
}
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($this->rotation === 0){
|
||||
$this->selfCounter = 0;
|
||||
}
|
||||
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
|
||||
$ai->entity->yaw += $v;
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$this->rotation -= $v;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,39 +2,39 @@
|
|||
|
||||
class TaskRandomWalk extends TaskBase
|
||||
{
|
||||
private $x, $z;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-10, 10);
|
||||
$this->z = mt_rand(-10, 10);
|
||||
if($this->x === 0 && $this->z === 0){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
}
|
||||
private $x, $z;
|
||||
public function onStart(EntityAI $ai)
|
||||
{
|
||||
$this->x = mt_rand(-10, 10);
|
||||
$this->z = mt_rand(-10, 10);
|
||||
if($this->x === 0 && $this->z === 0){
|
||||
$this->reset();
|
||||
return false;
|
||||
}
|
||||
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
|
||||
}
|
||||
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->x = $this->z = 0;
|
||||
}
|
||||
public function onEnd(EntityAI $ai)
|
||||
{
|
||||
$this->x = $this->z = 0;
|
||||
}
|
||||
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
--$this->selfCounter;
|
||||
$ai->mobController->moveNonInstant($this->x, 0, $this->z);
|
||||
}
|
||||
public function onUpdate(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false; //TODO Better way: block movement
|
||||
}
|
||||
--$this->selfCounter;
|
||||
$ai->mobController->moveNonInstant($this->x, 0, $this->z);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false;
|
||||
}
|
||||
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
{
|
||||
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
|
||||
return false;
|
||||
}
|
||||
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class Chicken extends Animal{
|
|||
const TYPE = MOB_CHICKEN;
|
||||
public $timeUntilEgg;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
|
||||
$this->setName('Chicken');
|
||||
|
|
@ -17,11 +17,11 @@ class Chicken extends Animal{
|
|||
}
|
||||
|
||||
public function update(){
|
||||
parent::update();
|
||||
if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){
|
||||
$this->dropAnEgg();
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
}
|
||||
parent::update();
|
||||
if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){
|
||||
$this->dropAnEgg();
|
||||
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
|
||||
}
|
||||
}
|
||||
|
||||
public function dropAnEgg(){
|
||||
|
|
|
|||
|
|
@ -16,15 +16,15 @@ class Cow extends Animal{
|
|||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket
|
||||
$e->player->addItem(BUCKET, 1, 1, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket
|
||||
$e->player->addItem(BUCKET, 1, 1, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -15,47 +15,47 @@ class Pig extends Animal implements Rideable{
|
|||
* @return boolean
|
||||
*/
|
||||
public function isSaddled(){
|
||||
return (boolean) $this->getState();
|
||||
return (boolean) $this->getState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $value
|
||||
*/
|
||||
public function setSaddled($value = null){
|
||||
$this->setState($value === null ? !$this->getState() : $value);
|
||||
$this->setState($value === null ? !$this->getState() : $value);
|
||||
}
|
||||
|
||||
public function canRide($e){
|
||||
return $this->isSaddled() && !($this->linkedEntity instanceof Entity);
|
||||
return $this->isSaddled() && !($this->linkedEntity instanceof Entity);
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action)
|
||||
{
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isRiding && $this->linkedEntity->eid = $e->eid){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$e->isRiding = false;
|
||||
$this->linkedEntity = 0;
|
||||
return true;
|
||||
}
|
||||
if($slot->getID() === SADDLE){
|
||||
if(!$this->isSaddled()){
|
||||
$e->player->removeItem($slot->getID(), 0, 1);
|
||||
$this->setSaddled(1);
|
||||
}
|
||||
return true; //avoid further interactions
|
||||
}
|
||||
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
public function interactWith(Entity $e, $action)
|
||||
{
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isRiding && $this->linkedEntity->eid = $e->eid){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$e->isRiding = false;
|
||||
$this->linkedEntity = 0;
|
||||
return true;
|
||||
}
|
||||
if($slot->getID() === SADDLE){
|
||||
if(!$this->isSaddled()){
|
||||
$e->player->removeItem($slot->getID(), 0, 1);
|
||||
$this->setSaddled(1);
|
||||
}
|
||||
return true; //avoid further interactions
|
||||
}
|
||||
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function isFood($id){
|
||||
return $id === POTATO || $id === CARROT || $id === BEETROOT;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
class Sheep extends Animal{
|
||||
public $color;
|
||||
public $color;
|
||||
const TYPE = MOB_SHEEP;
|
||||
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
|
|
@ -20,10 +20,10 @@ class Sheep extends Animal{
|
|||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["Color"] = @$this->data["Color"];
|
||||
$data["Sheared"] = @$this->data["Sheared"];
|
||||
return $data;
|
||||
$data = parent::createSaveData();
|
||||
$data["Color"] = @$this->data["Color"];
|
||||
$data["Sheared"] = @$this->data["Sheared"];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function eatGrass(){
|
||||
|
|
@ -41,16 +41,16 @@ class Sheep extends Animal{
|
|||
}
|
||||
|
||||
public function setSheared($v = null){
|
||||
$this->data["Sheared"] = $v === null ? !$this->isSheared() : $v;
|
||||
$this->updateMetadata();
|
||||
$this->data["Sheared"] = $v === null ? !$this->isSheared() : $v;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
|
||||
public function isSheared(){
|
||||
return $this->data["Sheared"];
|
||||
return $this->data["Sheared"];
|
||||
}
|
||||
|
||||
public function getColor(){
|
||||
return $this->data["Color"] & 16; //color === 16 -> color = 0, color === 17 -> color = 1 ...
|
||||
return $this->data["Color"] & 16; //color === 16 -> color = 0, color === 17 -> color = 1 ...
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
@ -64,21 +64,21 @@ class Sheep extends Animal{
|
|||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === SHEARS){
|
||||
if(!$this->isSheared()){
|
||||
$this->setSheared(1);
|
||||
$this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)));
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === SHEARS){
|
||||
if(!$this->isSheared()){
|
||||
$this->setSheared(1);
|
||||
$this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)));
|
||||
//$this->server->schedule(20, [$this, "eatGrass"]);
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
if($slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
|
|
@ -93,19 +93,19 @@ class Sheep extends Animal{
|
|||
public function sheepColor(){ //a method from 0.8.1
|
||||
$c = mt_rand(0,100);
|
||||
if($c <= 4){
|
||||
return 0xF; //white
|
||||
return 0xF; //white
|
||||
}
|
||||
if($c <= 9){
|
||||
return 0x7;
|
||||
return 0x7;
|
||||
}
|
||||
if($c <= 14){
|
||||
return 0x8;
|
||||
return 0x8;
|
||||
}
|
||||
if($c <= 17){
|
||||
return 0xC;
|
||||
return 0xC;
|
||||
}
|
||||
if(mt_rand(0, 500)){
|
||||
return 0x0;
|
||||
return 0x0;
|
||||
}
|
||||
return 0x0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,28 +16,28 @@ class Creeper extends Monster{
|
|||
|
||||
|
||||
public function setIgnited($v = null){
|
||||
$this->setState($v === null ? !$this->getState() : $v);
|
||||
$this->setState($v === null ? !$this->getState() : $v);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function isIgnited(){
|
||||
return (boolean)$this->getState();
|
||||
return (boolean)$this->getState();
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){
|
||||
if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
$this->ignite();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){
|
||||
if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
|
||||
}
|
||||
$this->ignite();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function ignite(){
|
||||
|
|
@ -55,16 +55,16 @@ class Creeper extends Monster{
|
|||
parent::update();
|
||||
}
|
||||
|
||||
public function explode()
|
||||
{
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
$this->setIgnited(0);
|
||||
$explosion = new Explosion($this, 3);
|
||||
$explosion->explode();
|
||||
$this->close();
|
||||
}
|
||||
public function explode()
|
||||
{
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
$this->setIgnited(0);
|
||||
$explosion = new Explosion($this, 3);
|
||||
$explosion->explode();
|
||||
$this->close();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -11,28 +11,28 @@ class Skeleton extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
return false;
|
||||
}
|
||||
|
||||
for($y = $this->y; $y < 129; $y++){
|
||||
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
|
||||
if($block->isSolid){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if($block->getID() === AIR){
|
||||
$this->fire = 160; //Value from 0.8.1
|
||||
$this->updateMetadata();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
return false;
|
||||
}
|
||||
|
||||
for($y = $this->y; $y < 129; $y++){
|
||||
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
|
||||
if($block->isSolid){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if($block->getID() === AIR){
|
||||
$this->fire = 160; //Value from 0.8.1
|
||||
$this->updateMetadata();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
$this->updateBurning();
|
||||
parent::update();
|
||||
$this->updateBurning();
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -11,28 +11,28 @@ class Zombie extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
return false;
|
||||
}
|
||||
|
||||
for($y = $this->y; $y < 129; $y++){
|
||||
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
|
||||
if($block->isSolid){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if($block->getID() === AIR){
|
||||
$this->fire = 160; //Value from 0.8.1
|
||||
$this->updateMetadata();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
return false;
|
||||
}
|
||||
|
||||
for($y = $this->y; $y < 129; $y++){
|
||||
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
|
||||
if($block->isSolid){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if($block->getID() === AIR){
|
||||
$this->fire = 160; //Value from 0.8.1
|
||||
$this->updateMetadata();
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
$this->updateBurning();
|
||||
parent::update();
|
||||
$this->updateBurning();
|
||||
parent::update();
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
|
|
@ -20,23 +20,23 @@ class Arrow extends Projectile{
|
|||
|
||||
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
|
||||
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
|
||||
$d /= $f2;
|
||||
$d1 /= $f2;
|
||||
$d2 /= $f2;
|
||||
$d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075
|
||||
$d1 += $this->random->nextGaussian() * 0.0075 * $f1;
|
||||
$d2 += $this->random->nextGaussian() * 0.0075 * $f1;
|
||||
$d *= $f;
|
||||
$d1 *= $f;
|
||||
$d2 *= $f;
|
||||
$this->speedX = $d;
|
||||
$this->speedY = $d1;
|
||||
$this->speedZ = $d2;
|
||||
$f3 = sqrt($d * $d + $d2 * $d2);
|
||||
$this->yaw = (atan2($d, $d2) * 180) / M_PI;
|
||||
$this->pitch = (atan2($d1, $f3) * 180) / M_PI;
|
||||
$d /= $f2;
|
||||
$d1 /= $f2;
|
||||
$d2 /= $f2;
|
||||
$d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075
|
||||
$d1 += $this->random->nextGaussian() * 0.0075 * $f1;
|
||||
$d2 += $this->random->nextGaussian() * 0.0075 * $f1;
|
||||
$d *= $f;
|
||||
$d1 *= $f;
|
||||
$d2 *= $f;
|
||||
$this->speedX = $d;
|
||||
$this->speedY = $d1;
|
||||
$this->speedZ = $d2;
|
||||
$f3 = sqrt($d * $d + $d2 * $d2);
|
||||
$this->yaw = (atan2($d, $d2) * 180) / M_PI;
|
||||
$this->pitch = (atan2($d1, $f3) * 180) / M_PI;
|
||||
$this->update();
|
||||
//TODO i guess? $ticksInGround = 0;
|
||||
//TODO i guess? $ticksInGround = 0;
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -49,24 +49,24 @@ class Minecart extends Vehicle{
|
|||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$this->linkedEntity = 0;
|
||||
$e->isRiding = false;
|
||||
return true;
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){
|
||||
$this->linkedEntity = $e;
|
||||
$e->isRiding = true;
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
|
||||
return true;
|
||||
}
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
|
||||
$this->linkedEntity = 0;
|
||||
$e->isRiding = false;
|
||||
return true;
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function canRide($e)
|
||||
{
|
||||
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
||||
}
|
||||
public function canRide($e)
|
||||
{
|
||||
return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@ class Painting extends Hanging{
|
|||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
|
||||
$data["Motive"] = $this->data["Motive"];
|
||||
|
||||
return $data;
|
||||
$data = parent::createSaveData();
|
||||
|
||||
$data["Motive"] = $this->data["Motive"];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function spawn($player){
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ class TripodCamera extends Entity{
|
|||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){
|
||||
if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){
|
||||
//todo
|
||||
$this->server->schedule(40, [$this, "close"]);
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ abstract class Block extends Position{
|
|||
return $this->id;
|
||||
}
|
||||
public function setMetadata($i){
|
||||
$this->meta = $i;
|
||||
$this->meta = $i;
|
||||
}
|
||||
final public function getMetadata(){
|
||||
return $this->meta & 0x0F;
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ class Item{
|
|||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
|
|
@ -217,11 +217,11 @@ class Item{
|
|||
|
||||
public function useOn($object, $force = false){
|
||||
if($force){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
@ -303,7 +303,7 @@ class Item{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return Item::DEF_DAMAGE;
|
||||
return Item::DEF_DAMAGE;
|
||||
}
|
||||
|
||||
public function getDestroySpeed(Block $block, Player $player){
|
||||
|
|
|
|||
|
|
@ -1,27 +1,27 @@
|
|||
<?php
|
||||
|
||||
class DoorBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function onUpdate($type){
|
||||
/**
|
||||
* @param int $type
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
public function onUpdate($type){
|
||||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false);
|
||||
if($this->getID() == 64) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(324, 0, 1));
|
||||
elseif($this->getID() == 71) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(330, 0, 1));
|
||||
if($this->getID() == 64) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(324, 0, 1));
|
||||
elseif($this->getID() == 71) ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y, $this->z+0.5, $this->level), BlockAPI::getItem(330, 0, 1));
|
||||
if($this->getSide(1) instanceof DoorBlock){
|
||||
$this->level->setBlock($this->getSide(1), new AirBlock(), false);
|
||||
}
|
||||
|
|
@ -32,19 +32,19 @@ class DoorBlock extends TransparentBlock{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param integer $face
|
||||
* @param integer $fx
|
||||
* @param integer $fy
|
||||
* @param integer $fz
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param integer $face
|
||||
* @param integer $fx
|
||||
* @param integer $fy
|
||||
* @param integer $fz
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($face === 1){
|
||||
$blockUp = $this->getSide(1);
|
||||
$blockDown = $this->getSide(0);
|
||||
|
|
@ -73,13 +73,13 @@ class DoorBlock extends TransparentBlock{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player){
|
||||
if(($this->meta & 0x08) === 0x08){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === $this->id){
|
||||
|
|
@ -95,13 +95,13 @@ class DoorBlock extends TransparentBlock{
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player){
|
||||
if(($this->meta & 0x08) === 0x08){ //Top
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === $this->id){
|
||||
|
|
|
|||
|
|
@ -1,29 +1,29 @@
|
|||
<?php
|
||||
|
||||
class FallableBlock extends SolidBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->hasPhysics = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param int $face
|
||||
* @param int $fx
|
||||
* @param int $fy
|
||||
* @param int $fz
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param int $face
|
||||
* @param int $fx
|
||||
* @param int $fy
|
||||
* @param int $fz
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
|
||||
return $ret;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class FlowableBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isFlowable = true;
|
||||
$this->isFullBlock = false;
|
||||
|
|
|
|||
|
|
@ -2,57 +2,57 @@
|
|||
|
||||
|
||||
class GenericBlock extends Block{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param integer $face
|
||||
* @param integer $fx
|
||||
* @param integer $fy
|
||||
* @param integer $fz
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param integer $face
|
||||
* @param integer $fx
|
||||
* @param integer $fy
|
||||
* @param integer $fz
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
return $this->level->setBlock($this, $this, true, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBreakable(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isBreakable(Item $item, Player $player){
|
||||
return ($this->breakable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function onBreak(Item $item, Player $player){
|
||||
return $this->level->setBlock($this, new AirBlock(), true, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $type
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onUpdate($type){
|
||||
/**
|
||||
* @param integer $type
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onUpdate($type){
|
||||
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(0);
|
||||
if($down->getID() === AIR or ($down instanceof LiquidBlock)){
|
||||
|
|
@ -73,13 +73,13 @@ class GenericBlock extends Block{
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function onActivate(Item $item, Player $player){
|
||||
return $this->isActivable;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class LiquidBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isLiquid = true;
|
||||
$this->breakable = false;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class SolidBlock extends GenericBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isSolid = true;
|
||||
$this->isFullBlock = true;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class StairBlock extends TransparentBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
if(($this->meta & 0x04) === 0x04){
|
||||
$this->isFullBlock = true;
|
||||
|
|
@ -16,19 +16,19 @@ class StairBlock extends TransparentBlock{
|
|||
$this->hardness = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param int $face
|
||||
* @param int $fx
|
||||
* @param int $fy
|
||||
* @param int $fz
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
* @param Block $block
|
||||
* @param Block $target
|
||||
* @param int $face
|
||||
* @param int $fx
|
||||
* @param int $fy
|
||||
* @param int $fz
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 0,
|
||||
1 => 2,
|
||||
|
|
@ -43,13 +43,13 @@ class StairBlock extends TransparentBlock{
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDrops(Item $item, Player $player){
|
||||
/**
|
||||
* @param Item $item
|
||||
* @param Player $player
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->getPickaxeLevel() >= 1){
|
||||
return array(
|
||||
array($this->id, 0, 1),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
class TransparentBlock extends GenericBlock{
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param string $name
|
||||
*/
|
||||
public function __construct($id, $meta = 0, $name = "Unknown"){
|
||||
parent::__construct($id, $meta, $name);
|
||||
$this->isActivable = false;
|
||||
$this->breakable = true;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
class SignPostBlock extends TransparentBlock{
|
||||
|
||||
private $faces = array(
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
|
||||
|
||||
private $faces = array(
|
||||
2 => 2,
|
||||
3 => 3,
|
||||
4 => 4,
|
||||
5 => 5,
|
||||
);
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(SIGN_POST, $meta, "Sign Post");
|
||||
$this->isSolid = false;
|
||||
|
|
@ -17,13 +17,13 @@ class SignPostBlock extends TransparentBlock{
|
|||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isSolid && $face !== 0){
|
||||
if($target->isSolid && $face !== 0){
|
||||
if(!isset($this->faces[$face])){
|
||||
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
|
||||
$this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true);
|
||||
return true;
|
||||
}else{
|
||||
$this->meta = $this->faces[$face];
|
||||
$this->meta = $this->faces[$face];
|
||||
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class TrapdoorBlock extends TransparentBlock{
|
|||
}
|
||||
|
||||
public function canAttachTo(Block $target){
|
||||
$id = $target->getID();
|
||||
return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock);
|
||||
$id = $target->getID();
|
||||
return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock);
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
|
|
|
|||
|
|
@ -97,8 +97,8 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
|
|||
$tlevel = $sb->meta & 0x06;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($sb, new AirBlock(), false, false, true);
|
||||
}
|
||||
|
|
@ -107,10 +107,10 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
|
|||
if($b instanceof LavaBlock){
|
||||
$tlevel = $b->meta & 0x06;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($b, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,126 +1,126 @@
|
|||
<?php
|
||||
|
||||
class WaterBlock extends LiquidBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(WATER, $meta, "Water");
|
||||
$this->hardness = 500;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getSourceCount(){
|
||||
$count = 0;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
if( $this->getSide($side) instanceof WaterBlock ){
|
||||
$b = $this->getSide($side);
|
||||
$level = $b->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function checkLava(){
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
if($side == 1){
|
||||
continue;
|
||||
}
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof LavaBlock){
|
||||
$level = $b->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
$this->level->setBlock($b, new ObsidianBlock(), false, false, true);
|
||||
}else{
|
||||
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFrom(){
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
$level = $this->meta & 0x07;
|
||||
if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){
|
||||
return $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
//return false;
|
||||
$newId = $this->id;
|
||||
$level = $this->meta & 0x07;
|
||||
if($type !== BLOCK_UPDATE_NORMAL){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->checkLava();
|
||||
|
||||
$falling = $this->meta >> 3;
|
||||
$down = $this->getSide(0);
|
||||
|
||||
$from = $this->getFrom();
|
||||
//Has Source or Its Source
|
||||
if($from !== null || $level == 0x00){
|
||||
if($down instanceof AirBlock || $down instanceof WaterBlock){
|
||||
$this->level->setBlock($down, new WaterBlock(0x00), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}elseif($level !== 0x07){{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
if( $this->getSourceCount() >= 2 && $level != 0x00){
|
||||
$this->level->setBlock($this, new WaterBlock(0), false, false, true);
|
||||
}
|
||||
}elseif($b->isFlowable === true){
|
||||
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//Extend Remove for Left Waters
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$sb = $this->getSide($side);
|
||||
if($sb instanceof WaterBlock){
|
||||
$tlevel = $sb->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($sb, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
$b = $this->getSide(0)->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($b, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(WATER, $meta, "Water");
|
||||
$this->hardness = 500;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function getSourceCount(){
|
||||
$count = 0;
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
if( $this->getSide($side) instanceof WaterBlock ){
|
||||
$b = $this->getSide($side);
|
||||
$level = $b->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
public function checkLava(){
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
if($side == 1){
|
||||
continue;
|
||||
}
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof LavaBlock){
|
||||
$level = $b->meta & 0x07;
|
||||
if($level == 0x00){
|
||||
$this->level->setBlock($b, new ObsidianBlock(), false, false, true);
|
||||
}else{
|
||||
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getFrom(){
|
||||
for($side = 0; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
$level = $this->meta & 0x07;
|
||||
if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){
|
||||
return $b;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onUpdate($type){
|
||||
//return false;
|
||||
$newId = $this->id;
|
||||
$level = $this->meta & 0x07;
|
||||
if($type !== BLOCK_UPDATE_NORMAL){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->checkLava();
|
||||
|
||||
$falling = $this->meta >> 3;
|
||||
$down = $this->getSide(0);
|
||||
|
||||
$from = $this->getFrom();
|
||||
//Has Source or Its Source
|
||||
if($from !== null || $level == 0x00){
|
||||
if($down instanceof AirBlock || $down instanceof WaterBlock){
|
||||
$this->level->setBlock($down, new WaterBlock(0x00), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}elseif($level !== 0x07){{
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$b = $this->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
if( $this->getSourceCount() >= 2 && $level != 0x00){
|
||||
$this->level->setBlock($this, new WaterBlock(0), false, false, true);
|
||||
}
|
||||
}elseif($b->isFlowable === true){
|
||||
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, true);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//Extend Remove for Left Waters
|
||||
for($side = 2; $side <= 5; ++$side){
|
||||
$sb = $this->getSide($side);
|
||||
if($sb instanceof WaterBlock){
|
||||
$tlevel = $sb->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($sb, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
$b = $this->getSide(0)->getSide($side);
|
||||
if($b instanceof WaterBlock){
|
||||
$tlevel = $b->meta & 0x07;
|
||||
if($tlevel != 0x00){
|
||||
for ($s = 0; $s <= 5; $s++) {
|
||||
$ssb = $sb->getSide($s);
|
||||
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($b, new AirBlock(), false, false, true);
|
||||
}
|
||||
}
|
||||
//ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL);
|
||||
}
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -49,12 +49,12 @@ class NetherReactorBlock extends SolidBlock{
|
|||
}
|
||||
|
||||
public function getDrops(Item $item, Player $player){
|
||||
if($item->getPickaxeLevel() >= 1){
|
||||
return array(
|
||||
[DIAMOND, 0, 3],
|
||||
[IRON_INGOT, 0, 6],
|
||||
);
|
||||
}
|
||||
if($item->getPickaxeLevel() >= 1){
|
||||
return array(
|
||||
[DIAMOND, 0, 3],
|
||||
[IRON_INGOT, 0, 6],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class FenceGateBlock extends TransparentBlock{
|
|||
);
|
||||
}
|
||||
public function onActivate(Item $item, Player $player){
|
||||
$this->meta ^= 0x04;
|
||||
$this->meta ^= 0x04;
|
||||
$this->level->setBlock($this, $this, true, false, true);
|
||||
$players = ServerAPI::request()->api->player->getAll($this->level);
|
||||
unset($players[$player->CID]);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class RailBlock extends FlowableBlock{
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(RAIL, $meta, "Rail");
|
||||
parent::__construct(RAIL, $meta, "Rail");
|
||||
$this->hardness = 0.7;
|
||||
$this->isFullBlock = false;
|
||||
$this->isSolid = false;
|
||||
|
|
@ -11,25 +11,25 @@ class RailBlock extends FlowableBlock{
|
|||
public static $shouldconnectrails = false;
|
||||
|
||||
private function isRailBlock($id){
|
||||
return $id === RAIL || $id === POWERED_RAIL;
|
||||
}
|
||||
return $id === RAIL || $id === POWERED_RAIL;
|
||||
}
|
||||
|
||||
private function isValidRailMeta($meta){
|
||||
return !($meta < 0 || $meta > 10);
|
||||
}
|
||||
return !($meta < 0 || $meta > 10);
|
||||
}
|
||||
|
||||
private function canConnectRail($block) {
|
||||
if(!($block instanceof RailBlock)) return null;
|
||||
if($this->distanceSquared($block) > 2) return null;
|
||||
$result = $this->checkRail($this);
|
||||
if(count($result) === 2) return null;
|
||||
return $result;
|
||||
}
|
||||
if(!($block instanceof RailBlock)) return null;
|
||||
if($this->distanceSquared($block) > 2) return null;
|
||||
$result = $this->checkRail($this);
|
||||
if(count($result) === 2) return null;
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function checkRail($rail){//fixed
|
||||
if(!($rail instanceof RailBlock)) return null;
|
||||
$damage = $rail->meta;
|
||||
if ($damage < 0 || $damage > 10) return null;
|
||||
if(!($rail instanceof RailBlock)) return null;
|
||||
$damage = $rail->meta;
|
||||
if ($damage < 0 || $damage > 10) return null;
|
||||
$delta = array(
|
||||
array(array(0, 1), array(0, -1)),
|
||||
array(array(1, 0), array(-1, 0)),
|
||||
|
|
@ -44,70 +44,70 @@ class RailBlock extends FlowableBlock{
|
|||
array(array(-1, 0), array(0, -1)),
|
||||
array(array(0, -1), array(1, 0))
|
||||
);
|
||||
$deltaY = array(0, 1, -1);
|
||||
$blocks = $delta[$damage];
|
||||
$connected = array();
|
||||
$deltaY = array(0, 1, -1);
|
||||
$blocks = $delta[$damage];
|
||||
$connected = array();
|
||||
|
||||
foreach($deltaY as $y){
|
||||
$v3 = new Vector3(
|
||||
$rail->getFloorX() + $blocks[0][0],
|
||||
$rail->getFloorY() + $y,
|
||||
$rail->getFloorZ() + $blocks[0][1]
|
||||
);
|
||||
$railBlock = $rail->level->getBlock($v3);
|
||||
$idToConnect = $railBlock->getID();
|
||||
$metaToConnect = $railBlock->getMetadata();
|
||||
if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
|
||||
$xDiff = $this->getFloorX() - $v3->getFloorX();
|
||||
$zDiff = $this->getFloorZ() - $v3->getFloorZ();
|
||||
foreach($blocks as $xz) {
|
||||
if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
|
||||
$connected[] = $v3;
|
||||
}
|
||||
}
|
||||
foreach($deltaY as $y){
|
||||
$v3 = new Vector3(
|
||||
$rail->getFloorX() + $blocks[1][0],
|
||||
$rail->getFloorY() + $y,
|
||||
$rail->getFloorZ() + $blocks[1][1]
|
||||
);
|
||||
$railBlock = $rail->level->getBlock($v3);
|
||||
$idToConnect = $railBlock->getID();
|
||||
$metaToConnect = $railBlock->getMetadata();
|
||||
if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
|
||||
$xDiff = $this->getFloorX() - $v3->getFloorX();
|
||||
$zDiff = $this->getFloorZ() - $v3->getFloorZ();
|
||||
foreach($blocks as $xz){
|
||||
if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
|
||||
$connected[] = $v3;
|
||||
}
|
||||
}
|
||||
return $connected;
|
||||
}
|
||||
foreach($deltaY as $y){
|
||||
$v3 = new Vector3(
|
||||
$rail->getFloorX() + $blocks[0][0],
|
||||
$rail->getFloorY() + $y,
|
||||
$rail->getFloorZ() + $blocks[0][1]
|
||||
);
|
||||
$railBlock = $rail->level->getBlock($v3);
|
||||
$idToConnect = $railBlock->getID();
|
||||
$metaToConnect = $railBlock->getMetadata();
|
||||
if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
|
||||
$xDiff = $this->getFloorX() - $v3->getFloorX();
|
||||
$zDiff = $this->getFloorZ() - $v3->getFloorZ();
|
||||
foreach($blocks as $xz) {
|
||||
if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
|
||||
$connected[] = $v3;
|
||||
}
|
||||
}
|
||||
foreach($deltaY as $y){
|
||||
$v3 = new Vector3(
|
||||
$rail->getFloorX() + $blocks[1][0],
|
||||
$rail->getFloorY() + $y,
|
||||
$rail->getFloorZ() + $blocks[1][1]
|
||||
);
|
||||
$railBlock = $rail->level->getBlock($v3);
|
||||
$idToConnect = $railBlock->getID();
|
||||
$metaToConnect = $railBlock->getMetadata();
|
||||
if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
|
||||
$xDiff = $this->getFloorX() - $v3->getFloorX();
|
||||
$zDiff = $this->getFloorZ() - $v3->getFloorZ();
|
||||
foreach($blocks as $xz){
|
||||
if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
|
||||
$connected[] = $v3;
|
||||
}
|
||||
}
|
||||
return $connected;
|
||||
}
|
||||
|
||||
private function connectRail($rail){
|
||||
$connected = $this->canConnectRail($rail);
|
||||
if ($connected === null || count($connected) === 0) return;
|
||||
if(count($connected) === 1){
|
||||
$v3 = $connected[0]->subtract($this);
|
||||
$this->meta = ($v3->y !== 1) ? ($v3->x === 0 ? 0 : 1) : (int) ($v3->z === 0 ? ($v3->x / -2) + 2.5 : ($v3->z / 2) + 4.5);
|
||||
}elseif(count(connected) === 2){
|
||||
$subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0));
|
||||
for ($i = 0; $i < count($connected); $i++) {
|
||||
$subtract[$i] = $connected[$i]->subtract($this);
|
||||
}
|
||||
if (abs($subtract[0]->x) === abs($subtract[1]->z) && abs($subtract[1]->x) === abs($subtract[0]->z)){
|
||||
$v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this));
|
||||
$this->meta = $v3->x === 1 ? ($v3->z === 1 ? 6 : 9) : ($v3->z === 1 ? 7 : 8);
|
||||
}elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){
|
||||
$v3 = $subtract[0]->y === 1 ? $subtract[0] : $subtract[1];
|
||||
$this->meta = $v3->x === 0 ? ($v3->z === -1 ? 4 : 5) : ($v3->x === 1 ? 2 : 3);
|
||||
}else{
|
||||
$this->meta = $subtract[0]->x === 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($rail, new RailBlock($this->meta), true, true);
|
||||
}
|
||||
$connected = $this->canConnectRail($rail);
|
||||
if ($connected === null || count($connected) === 0) return;
|
||||
if(count($connected) === 1){
|
||||
$v3 = $connected[0]->subtract($this);
|
||||
$this->meta = ($v3->y !== 1) ? ($v3->x === 0 ? 0 : 1) : (int) ($v3->z === 0 ? ($v3->x / -2) + 2.5 : ($v3->z / 2) + 4.5);
|
||||
}elseif(count(connected) === 2){
|
||||
$subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0));
|
||||
for ($i = 0; $i < count($connected); $i++) {
|
||||
$subtract[$i] = $connected[$i]->subtract($this);
|
||||
}
|
||||
if (abs($subtract[0]->x) === abs($subtract[1]->z) && abs($subtract[1]->x) === abs($subtract[0]->z)){
|
||||
$v3 = $connected[0]->subtract($this)->add($connected[1]->subtract($this));
|
||||
$this->meta = $v3->x === 1 ? ($v3->z === 1 ? 6 : 9) : ($v3->z === 1 ? 7 : 8);
|
||||
}elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){
|
||||
$v3 = $subtract[0]->y === 1 ? $subtract[0] : $subtract[1];
|
||||
$this->meta = $v3->x === 0 ? ($v3->z === -1 ? 4 : 5) : ($v3->x === 1 ? 2 : 3);
|
||||
}else{
|
||||
$this->meta = $subtract[0]->x === 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
$this->level->setBlock($rail, new RailBlock($this->meta), true, true);
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$down = $this->getSide(0);
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ class BeetrootBlock extends FlowableBlock{
|
|||
$drops[] = array(BEETROOT, 0, 1);
|
||||
}
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
|
||||
$drops[] = array(BEETROOT_SEEDS, 0, 1);
|
||||
}
|
||||
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
|
||||
$drops[] = array(BEETROOT_SEEDS, 0, 1);
|
||||
}
|
||||
}
|
||||
return $drops;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class CarrotBlock extends FlowableBlock{
|
|||
}
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
|
||||
$drops[] = array(CARROT, 0, 1);
|
||||
$drops[] = array(CARROT, 0, 1);
|
||||
}
|
||||
}
|
||||
return $drops;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TallGrassBlock extends FlowableBlock{
|
|||
if($type === BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(0)->isTransparent === true){//Replace with common break method
|
||||
$this->level->setBlock($this, new AirBlock(), false, false, true);
|
||||
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS));
|
||||
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS));
|
||||
return BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,11 +60,11 @@ class WheatBlock extends FlowableBlock{
|
|||
$drops[] = array(WHEAT, 0, 1);
|
||||
$drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3));
|
||||
}else{
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
|
||||
$drops[] = array(WHEAT_SEEDS, 0, 1);
|
||||
}
|
||||
}
|
||||
for($i = 0; $i < 3; ++$i){
|
||||
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
|
||||
$drops[] = array(WHEAT_SEEDS, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $drops;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class DirtBlock extends SolidBlock{
|
|||
$x = $this->x;
|
||||
$y = $this->y;
|
||||
$z = $this->z;
|
||||
|
||||
|
||||
if($this->getBlockID($x+1, $y, $z+1) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z) == 2) return true;
|
||||
if($this->getBlockID($x+1, $y, $z-1) == 2) return true;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class DoubleSlabBlock extends SolidBlock{
|
|||
4 => "Brick",
|
||||
5 => "Stone Brick",
|
||||
6 => "Quartz",
|
||||
7 => "Smooth Stone",
|
||||
7 => "Smooth Stone",
|
||||
);
|
||||
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
|
||||
$this->hardness = 30;
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{
|
|||
return 15;
|
||||
}
|
||||
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 1,
|
||||
1 => 2,
|
||||
2 => 3,
|
||||
3 => 0,
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$faces = array(
|
||||
0 => 1,
|
||||
1 => 2,
|
||||
2 => 3,
|
||||
3 => 0,
|
||||
);
|
||||
$this->meta = $faces[$player->entity->getDirection()];
|
||||
$this->level->setBlock($block, $this, true, false, true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
abstract class ItemAxe extends ItemTool
|
||||
{
|
||||
public function isAxe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function isAxe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
abstract class ItemHoe extends ItemTool
|
||||
{
|
||||
public function isHoe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
public function isHoe(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
abstract class ItemPickaxe extends ItemTool
|
||||
{
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return true;
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isPickaxe(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
class ItemShovel extends ItemTool
|
||||
{
|
||||
public function isShovel(){
|
||||
return true;
|
||||
}
|
||||
public function isShovel(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
abstract class ItemSword extends ItemTool
|
||||
{
|
||||
|
||||
public function isSword(){
|
||||
return true;
|
||||
}
|
||||
public function isSword(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
abstract class ItemTool extends Item
|
||||
{
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function isTool(){
|
||||
return true;
|
||||
}
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Entity) and !$this->isSword()){
|
||||
$this->meta += 2;
|
||||
}else{
|
||||
$this->meta++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class PaintingItem extends Item{
|
|||
array("Flaming Skull", 4, 4),
|
||||
);
|
||||
private static $direction = array(2, 0, 1, 3);
|
||||
private static $right = array(4, 5, 3, 2);
|
||||
private static $right = array(4, 5, 3, 2);
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
if($target->isTransparent === false and $face > 1 and $block->isSolid === false){
|
||||
|
|
@ -56,17 +56,17 @@ class PaintingItem extends Item{
|
|||
for($y = 0; $y <= $motive[2]; $y++){
|
||||
if ($target->getSide(PaintingItem::$right[$face - 2], $x)->isTransparent || $target->getSide(1, $y)->isTransparent
|
||||
|| $block->getSide(PaintingItem::$right[$face - 2], $x)->isSolid || $block->getSide(1, $y)->isSolid) {
|
||||
$valid = false;
|
||||
$valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!$valid){
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($valid) {
|
||||
$validMotives[] = $motive;
|
||||
}
|
||||
$validMotives[] = $motive;
|
||||
}
|
||||
}
|
||||
$motive = $validMotives[array_rand($validMotives)];
|
||||
$data = array(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
class SignItem extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(SIGN, 0, $count, "Sign");
|
||||
parent::__construct(SIGN, 0, $count, "Sign");
|
||||
$this->block = BlockAPI::get(SIGN_POST);
|
||||
$this->maxStackSize = 16;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,18 +8,18 @@ class SpawnEggItem extends Item{
|
|||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG;
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y,
|
||||
"z" => $block->z + 0.5,
|
||||
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0
|
||||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
-- $this->count;
|
||||
}
|
||||
return true;
|
||||
$ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG;
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y,
|
||||
"z" => $block->z + 0.5,
|
||||
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0
|
||||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
-- $this->count;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ class DiamondAxeItem extends ItemAxe{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 6;
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ class DiamondPickaxeItem extends ItemPickaxe{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 5;
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,6 @@ class DiamondShovelItem extends ItemShovel{
|
|||
parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel");
|
||||
}
|
||||
public function getDamageAgainstOf($e){
|
||||
return 4;
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ class DiamondSwordItem extends ItemSword{
|
|||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword");
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,11 +21,11 @@ class FlintSteelItem extends ItemTool{
|
|||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Creeper) and $this->id === FLINT_STEEL){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
if(($object instanceof Creeper) and $this->id === FLINT_STEEL){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}else{
|
||||
return parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,6 @@ class GoldenAxeItem extends ItemAxe{
|
|||
parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe");
|
||||
}
|
||||
public function getDamageAgainstOf($e){
|
||||
return 3;
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ class GoldenPickaxeItem extends ItemPickaxe{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ class GoldenSwordItem extends ItemSword{
|
|||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword");
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
public function getDamageAgainstOf($e)
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ class IronAxeItem extends ItemAxe{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 5;
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,6 @@ class IronSwordItem extends ItemSword{
|
|||
parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword");
|
||||
}
|
||||
public function getDamageAgainstOf($e){
|
||||
return 6;
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,10 +6,10 @@ class ShearsItem extends ItemTool{
|
|||
}
|
||||
|
||||
public function useOn($object, $force = false){
|
||||
if(($object instanceof Sheep) and $this->id === SHEARS){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}
|
||||
parent::useOn($object, $force);
|
||||
if(($object instanceof Sheep) and $this->id === SHEARS){
|
||||
$this->meta++;
|
||||
return true;
|
||||
}
|
||||
parent::useOn($object, $force);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ class StoneShovelItem extends ItemShovel{
|
|||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel");
|
||||
}
|
||||
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,6 +6,6 @@ class WoodenPickaxeItem extends ItemPickaxe{
|
|||
}
|
||||
|
||||
public function getDamageAgainstOf($e){
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
@ -192,14 +192,14 @@ class AxisAlignedBB{
|
|||
}
|
||||
|
||||
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;
|
||||
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){
|
||||
|
|
@ -306,7 +306,7 @@ class AxisAlignedBB{
|
|||
}
|
||||
|
||||
public function __toString(){
|
||||
return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}";
|
||||
return "min: {$this->minX}, {$this->minY}, {$this->minZ}, max: {$this->maxX}, {$this->maxY}, {$this->maxZ}";
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue