project uses tabs instead of spaces(as in CONTRIBUTING.md)

This commit is contained in:
GameHerobrine 2022-12-26 07:01:28 +03:00
parent f00318b6ed
commit 62571f26cd
115 changed files with 2291 additions and 2364 deletions

View file

@ -81,13 +81,13 @@ class AchievementAPI{
], ],
]; ];
private $server; private $server;
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
/** /**
* Add an achievement * Add an achievement
* @param string $achievementId * @param string $achievementId
@ -157,47 +157,47 @@ class AchievementAPI{
} }
} }
public function viewAchievements($cmd, $params, $issuer, $alias) public function viewAchievements($cmd, $params, $issuer, $alias)
{ {
if(!($issuer instanceof Player) && !isset($params[0])){ if(!($issuer instanceof Player) && !isset($params[0])){
return "Please enter a nickname."; return "Please enter a nickname.";
} else{ } else{
if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){ if(isset($params[0]) && ($this->server->api->ban->isOp($issuer->username) || ! ($issuer instanceof Player))){
$player = $this->server->api->player->get($params[0]); $player = $this->server->api->player->get($params[0]);
if($player instanceof Player){ if($player instanceof Player){
$data = $player->data; $data = $player->data;
} else{ } else{
$data = $this->server->api->player->getOffline(trim($params[0]), false); $data = $this->server->api->player->getOffline(trim($params[0]), false);
} }
} else{ } else{
$data = $issuer->achievements; $data = $issuer->achievements;
} }
} }
if($data === false){ if($data === false){
return "Player {$params[0]} is not found."; return "Player {$params[0]} is not found.";
} }
if($data instanceof Config){ if($data instanceof Config){
$achs = $data->get("achievements"); $achs = $data->get("achievements");
}else{ }else{
$achs = $data; $achs = $data;
} }
if(count($achs) <= 0){ if(count($achs) <= 0){
return "Player {$params[0]} unlocked 0 achievements"; return "Player {$params[0]} unlocked 0 achievements";
} }
$output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): "; $output = "Unlocked Achievements(".count($achs)."/".count(self::$achievements)."): ";
foreach($achs as $achievement => $unlocked){ foreach($achs as $achievement => $unlocked){
if($unlocked && isset(self::$achievements[$achievement])){ if($unlocked && isset(self::$achievements[$achievement])){
$info = self::$achievements[$achievement]; $info = self::$achievements[$achievement];
$output .= "{$info["name"]}, "; $output .= "{$info["name"]}, ";
} }
} }
return substr($output, 0, - 2); return substr($output, 0, - 2);
} }
public function init(){ public function init(){
$this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]); $this->server->api->console->register("ach", "<player>", [$this, "viewAchievements"]);
$this->server->api->console->alias("getplayerachievements", "ach"); $this->server->api->console->alias("getplayerachievements", "ach");
$this->server->api->console->cmdWhitelist("ach"); $this->server->api->console->cmdWhitelist("ach");
} }
} }

View file

@ -50,7 +50,7 @@ class BanAPI{
* @param string $cmd Command to Whitelist * @param string $cmd Command to Whitelist
*/ */
public function cmdWhitelist($cmd){ public function cmdWhitelist($cmd){
$this->server->api->console->cmdWhitelist($cmd); $this->server->api->console->cmdWhitelist($cmd);
} }
/** /**
@ -67,21 +67,21 @@ class BanAPI{
} }
break; break;
case "player.block.break": case "player.block.break":
/** /**
* @var Player $player * @var Player $player
*/ */
$player = $data["player"]; $player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$t = new Vector2($data["target"]->x, $data["target"]->z); $t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->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){ if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){
return false; return false;
} }
} }
return; return;
case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area. case "player.block.place"://Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
$player = $data["player"]; $player = $data["player"];
if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){ if(!$this->isOp($player->iusername) && $player->level->getName() === $this->server->api->level->getDefault()){
$t = new Vector2($data["block"]->x, $data["block"]->z); $t = new Vector2($data["block"]->x, $data["block"]->z);
$s = new Vector2($this->server->spawn->x, $this->server->spawn->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){ if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true){

View file

@ -435,7 +435,7 @@ class BlockAPI{
$item = $player->getSlot($player->slot); $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($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); $this->cancelAction($target, $player);
return $this->cancelAction($block, $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.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){ 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); $this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
@ -532,7 +532,7 @@ class BlockAPI{
$this->server->api->entity->updateRadius($pos, 1); $this->server->api->entity->updateRadius($pos, 1);
}elseif($level === BLOCK_UPDATE_RANDOM){ }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->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; return $level;
} }

View file

@ -12,7 +12,7 @@ class ChatAPI{
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]); $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("me", "<action ...>", [$this, "commandHandler"]);
$this->server->api->console->register("say", "<message ...>", [$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->cmdWhitelist("me");
$this->server->api->console->alias("msg", "tell"); $this->server->api->console->alias("msg", "tell");
} }

View file

@ -25,13 +25,13 @@ class ConsoleAPI{
$this->cmdWhitelist("help"); $this->cmdWhitelist("help");
$this->cmdWhitelist("status"); $this->cmdWhitelist("status");
} }
/** /**
* Whitelists a CMD so everyone can issue it - Even non OPs. * Whitelists a CMD so everyone can issue it - Even non OPs.
* @param string $cmd Command to Whitelist * @param string $cmd Command to Whitelist
*/ */
public function cmdWhitelist($cmd){ 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){ public function register($cmd, $help, $callback){
@ -304,11 +304,11 @@ class ConsoleLoop extends Thread{
} }
while(!$this->stop){ while(!$this->stop){
$this->line = $this->readLine(); $this->line = $this->readLine();
$this->synchronized(function($t) { $this->synchronized(function($t) {
$this->wait(); $this->wait();
$this->line = false; $this->line = false;
}, $this); }, $this);
} }
if(!extension_loaded("readline")){ if(!extension_loaded("readline")){

View file

@ -1,113 +1,113 @@
<?php <?php
class EntityAPI{ class EntityAPI{
public $entities; public $entities;
private $server; private $server;
private $eCnt = 1; private $eCnt = 1;
function __construct(){ function __construct(){
$this->entities = []; $this->entities = [];
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals"); $this->serverSpawnAnimals = $this->server->api->getProperty("spawn-animals");
$this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs"); $this->serverSpawnMobs = $this->server->api->getProperty("spawn-mobs");
} }
public function init(){ public function init(){
$this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]); $this->server->api->console->register("summon", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]); $this->server->api->console->register("spawnmob", "<mob>", [$this, "commandHandler"]);
$this->server->api->console->register("despawn", "", [$this, "CommandHandler"]); $this->server->api->console->register("despawn", "", [$this, "CommandHandler"]);
} }
public function commandHandler($cmd, $args, $issuer, $alias){ public function commandHandler($cmd, $args, $issuer, $alias){
$mob = [ $mob = [
"chicken" => 10, "chicken" => 10,
"cow" => 11, "cow" => 11,
"pig" => 12, "pig" => 12,
"sheep" => 13, "sheep" => 13,
"zombie" => 32, "zombie" => 32,
"creeper" => 33, "creeper" => 33,
"skeleton" => 34, "skeleton" => 34,
"spider" => 35, "spider" => 35,
"pigman" => 36 "pigman" => 36
]; ];
$output = ""; $output = "";
switch($cmd){ switch($cmd){
case "summon": case "summon":
case "spawnmob": case "spawnmob":
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
$output .= "Please run this command in-game."; $output .= "Please run this command in-game.";
break; break;
} }
if((count($args) < 1) or (count($args) > 3)){ if((count($args) < 1) or (count($args) > 3)){
$output .= "Usage: /$cmd <mob> [amount] [baby]"; $output .= "Usage: /$cmd <mob> [amount] [baby]";
break; break;
} }
if(is_int($args[0])) $type = $args[0]; if(is_int($args[0])) $type = $args[0];
else $type = $mob[strtolower($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)){ if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){
$output .= "Unknown mob."; $output .= "Unknown mob.";
break; break;
} }
$mobName = ucfirst(array_flip($mob)[$type]); $mobName = ucfirst(array_flip($mob)[$type]);
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){ if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
$output .= "$mobName cannot be a baby!"; $output .= "$mobName cannot be a baby!";
break; break;
} }
$x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP); $x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP);
$y = round($issuer->entity->y, 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); $z = round($issuer->entity->z, 2, PHP_ROUND_HALF_UP);
$level = $issuer->entity->level; $level = $issuer->entity->level;
$pos = new Position($x, $y, $z, $level); $pos = new Position($x, $y, $z, $level);
if(count($args) === 1){//summon <mob> if(count($args) === 1){//summon <mob>
$this->summon($pos, ENTITY_MOB, $type); $this->summon($pos, ENTITY_MOB, $type);
$output .= "$mobName spawned in $x, $y, $z."; $output .= "$mobName spawned in $x, $y, $z.";
break; break;
} }
elseif(is_numeric($args[1])){//summon <mob> [amount] elseif(is_numeric($args[1])){//summon <mob> [amount]
$amount = (int) $args[1]; $amount = (int) $args[1];
if($amount > 100){ if($amount > 100){
$output .= "Cannot spawn > 100 mobs"; $output .= "Cannot spawn > 100 mobs";
break; break;
} }
$isBaby = false; $isBaby = false;
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby] if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
$isBaby = true; $isBaby = true;
} }
for($cnt = $amount; $cnt > 0; --$cnt){ for($cnt = $amount; $cnt > 0; --$cnt){
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]); $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
} }
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z."; $output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
break; break;
} }
elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby] elseif(strtolower($args[1]) == "baby"){//summon <mob> [baby]
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]); $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]);
$output .= "Baby $mobName spawned in $x, $y, $z."; $output .= "Baby $mobName spawned in $x, $y, $z.";
break; break;
} }
break; break;
case "despawn": case "despawn":
$cnt = 0; $cnt = 0;
if(!isset($args[0])){ if(!isset($args[0])){
$output .= "/despawn <all or (mobs,objects,items,fallings)>"; $output .= "/despawn <all or (mobs,objects,items,fallings)>";
break; break;
}else{ }else{
if($args[0] === "all"){ if($args[0] === "all"){
$cnt = 0; $cnt = 0;
foreach($this->entities as $e){ foreach($this->entities as $e){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning
$this->remove($e->eid); $this->remove($e->eid);
$cnt++; $cnt++;
} }
} }
}else{ }else{
$array = explode(",", strtolower($args[0])); $array = explode(",", strtolower($args[0]));
if(count($array) > 4){ if(count($array) > 4){
@ -123,173 +123,173 @@ class EntityAPI{
$despawning = substr($list, 0, -4); $despawning = substr($list, 0, -4);
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";"); $l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
if($l !== false and $l !== true){ if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]); $e = $this->get($e["EID"]);
if($e instanceof Entity){ if($e instanceof Entity){
$this->remove($e->eid); $this->remove($e->eid);
$cnt++; $cnt++;
} }
} }
} }
} }
} }
$output = "$cnt entities have been despawned!"; $output = "$cnt entities have been despawned!";
break; break;
} }
return $output; return $output;
} }
public function summon(Position $pos, $class, $type, Array $data = []){ public function summon(Position $pos, $class, $type, Array $data = []){
$entity = $this->add($pos->level, $class, $type, [ $entity = $this->add($pos->level, $class, $type, [
"x" => $pos->x, "x" => $pos->x,
"y" => $pos->y, "y" => $pos->y,
"z" => $pos->z "z" => $pos->z
] + $data); ] + $data);
$this->spawnToAll($entity, $pos->level); $this->spawnToAll($entity, $pos->level);
} }
public function add(Level $level, $class, $type = 0, $data = []){ public function add(Level $level, $class, $type = 0, $data = []){
$eid = $this->eCnt++; $eid = $this->eCnt++;
$efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class); $efl = EntityRegistry::$entityList->getEntityFromTypeAndClass($type, $class);
if($efl instanceof PropertyEntity){ if($efl instanceof PropertyEntity){
$class = $efl->getEntityName(); $class = $efl->getEntityName();
$this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data); $this->entities[$eid] = new $class($level, $eid, $efl->getEntityClass(), $efl->getEntityType(), $data);
}else{ }else{
$this->entities[$eid] = new Entity($level, $eid, $class, $type, $data); $this->entities[$eid] = new Entity($level, $eid, $class, $type, $data);
} }
$level->entityList[$eid] = &$this->entities[$eid]; $level->entityList[$eid] = &$this->entities[$eid];
$this->server->handle("entity.add", $this->entities[$eid]); $this->server->handle("entity.add", $this->entities[$eid]);
return $this->entities[$eid]; return $this->entities[$eid];
} }
public function spawnToAll(Entity $e){ public function spawnToAll(Entity $e){
foreach($this->server->api->player->getAll($e->level) as $player){ 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){ if($player->eid !== false and $player->eid !== $e->eid and $e->class !== ENTITY_PLAYER and $e instanceof Entity){
$e->spawn($player); $e->spawn($player);
} }
} }
} }
public function get($eid){ public function get($eid){
if(isset($this->entities[$eid])){ if(isset($this->entities[$eid])){
return $this->entities[$eid]; return $this->entities[$eid];
} }
return false; return false;
} }
public function remove($eid){ public function remove($eid){
if(isset($this->entities[$eid])){ if(isset($this->entities[$eid])){
$this->entities[$eid]->closed = true; $this->entities[$eid]->closed = true;
if($this->entities[$eid]->isPlayer()){ if($this->entities[$eid]->isPlayer()){
$pk = new RemovePlayerPacket; $pk = new RemovePlayerPacket;
$pk->eid = $eid; $pk->eid = $eid;
$pk->clientID = 0; $pk->clientID = 0;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
}else{ }else{
$pk = new RemoveEntityPacket; $pk = new RemoveEntityPacket;
$pk->eid = $eid; $pk->eid = $eid;
$this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk); $this->server->api->player->broadcastPacket($this->entities[$eid]->level->players, $pk);
} }
$this->server->api->dhandle("entity.remove", $this->entities[$eid]); $this->server->api->dhandle("entity.remove", $this->entities[$eid]);
unset($this->entities[$eid]->level->entityList[$eid]); unset($this->entities[$eid]->level->entityList[$eid]);
unset($this->entities[$eid]); unset($this->entities[$eid]);
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";"); $this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
} }
} }
public function updateRadius(Position $center, $radius = 15, $class = false){ 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;"); $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){ public function getRadius(Position $center, $radius = 15, $class = false){
$entities = []; $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;"); $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){ if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]); $e = $this->get($e["EID"]);
if($e instanceof Entity){ if($e instanceof Entity){
$entities[$e->eid] = $e; $entities[$e->eid] = $e;
} }
} }
} }
return $entities; return $entities;
} }
public function heal($eid, $heal, $cause){ public function heal($eid, $heal, $cause){
$this->harm($eid, -$heal, $cause); $this->harm($eid, -$heal, $cause);
} }
public function harm($eid, $attack, $cause, $force = false){ public function harm($eid, $attack, $cause, $force = false){
$e = $this->get($eid); $e = $this->get($eid);
if($e === false or $e->dead === true){ if($e === false or $e->dead === true){
return false; return false;
} }
$e->setHealth($e->getHealth() - $attack, $cause, $force); $e->setHealth($e->getHealth() - $attack, $cause, $force);
} }
public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){ public function dropRawPos(Position $pos, $item, $speedX, $speedY, $speedZ){
if($item->getID() === AIR or $item->count <= 0){ if($item->getID() === AIR or $item->count <= 0){
return; return;
} }
$data = [ $data = [
"x" => $pos->x, "x" => $pos->x,
"y" => $pos->y, "y" => $pos->y,
"z" => $pos->z, "z" => $pos->z,
"level" => $pos->level, "level" => $pos->level,
"speedX" => $speedX, "speedX" => $speedX,
"speedY" => $speedY, "speedY" => $speedY,
"speedZ" => $speedZ, "speedZ" => $speedZ,
"item" => $item, "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,
]; ];
if($this->server->api->handle("item.drop", $data) !== false){ if($this->server->api->handle("item.drop", $data) !== false){
for($count = $item->count; $count > 0;){ for($count = $item->count; $count > 0;){
$item->count = min($item->getMaxStackSize(), $count); $item->count = min($item->getMaxStackSize(), $count);
$count -= $item->count; $count -= $item->count;
$e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data); $e = $this->add($pos->level, ENTITY_ITEM, $item->getID(), $data);
$this->spawnToAll($e); $this->spawnToAll($e);
$this->server->api->handle("entity.motion", $e); $this->server->api->handle("entity.motion", $e);
} }
} }
} }
public function spawnAll(Player $player){ public function drop(Position $pos, Item $item){
foreach($this->getAll($player->level) as $e){ if($item->getID() === AIR or $item->count <= 0){
if($e->class !== ENTITY_PLAYER){ return;
$e->spawn($player); }
} $data = [
} "x" => $pos->x + mt_rand(-10, 10) / 50,
} "y" => $pos->y + 0.19,
"z" => $pos->z + mt_rand(-10, 10) / 50,
public function getAll($level = null){ "level" => $pos->level,
if($level instanceof Level){ "speedX" => Utils::randomFloat() * 0.2 - 0.1,
return $level->entityList; "speedY" => 0.2,
} "speedZ" => Utils::randomFloat() * 0.2 - 0.1,
return $this->entities; "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;
}
} }

View file

@ -1,10 +1,10 @@
<?php <?php
class LevelAPI{ class LevelAPI{
/** /**
* @var Level[] * @var Level[]
*/ */
public $levels; public $levels;
private $server, $default; private $server, $default;
public function __construct(){ public function __construct(){

View file

@ -19,7 +19,7 @@ class PlayerAPI{
$this->registerCmd("spawn"); $this->registerCmd("spawn");
$this->registerCmd("ping"); $this->registerCmd("ping");
$this->server->api->console->alias("lag", "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("who", "list");
$this->server->api->console->alias("suicide", "kill"); $this->server->api->console->alias("suicide", "kill");
$this->server->api->console->alias("tppos", "tp"); $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 = new Config(DATA_PATH . "players/" . $iname . ".yml", CONFIG_YAML, $default);
$data->save(); $data->save();
}else{ }else{
return false; return false;
} }
} }

View file

@ -27,7 +27,7 @@ class PluginAPI extends stdClass{
$this->server->api->console->register("version", "", [$this, "commandHandler"]); $this->server->api->console->register("version", "", [$this, "commandHandler"]);
$this->server->api->console->cmdWhitelist("version"); $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 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("pl", "plugins");
$this->server->api->console->alias("ver", "version"); $this->server->api->console->alias("ver", "version");
@ -65,7 +65,7 @@ class PluginAPI extends stdClass{
public function __destruct(){ public function __destruct(){
foreach($this->plugins as $p){ 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); unset($this->plugins);
} }
@ -163,7 +163,7 @@ class PluginAPI extends stdClass{
$aver = CURRENT_API_VERSION; $aver = CURRENT_API_VERSION;
if($pluginInfo["api"] != $aver){ 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/"; $phr = "phar://$filePath/";

View file

@ -898,14 +898,14 @@ class Player{
} }
} }
public function makeInvisibleForOnePlayer(Player $player){ public function makeInvisibleForOnePlayer(Player $player){
$pk = new RemoveEntityPacket; $pk = new RemoveEntityPacket;
$pk->eid = $this->entity->eid; $pk->eid = $this->entity->eid;
$player->dataPacket($pk); $player->dataPacket($pk);
} }
public function makeInvisibleForAllPlayers(){ public function makeInvisibleForAllPlayers(){
$pk = new RemoveEntityPacket; $pk = new RemoveEntityPacket;
$pk->eid = $this->entity->eid; $pk->eid = $this->entity->eid;
$this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk); $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), $pk);
} }
public function getGamemode(){ public function getGamemode(){
switch($this->gamemode){ switch($this->gamemode){
@ -959,10 +959,10 @@ class Player{
} }
if($this->gamemode === SPECTATOR){ if($this->gamemode === SPECTATOR){
$this->makeInvisibleForAllPlayers(); $this->makeInvisibleForAllPlayers();
} }
if($this->gamemode === CREATIVE){ if($this->gamemode === CREATIVE){
$this->server->api->player->spawnToAllPlayers($this); $this->server->api->player->spawnToAllPlayers($this);
} }
$this->inventory = $inv; $this->inventory = $inv;
@ -1315,17 +1315,17 @@ class Player{
return; return;
} }
if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 !== ProtocolInfo::CURRENT_PROTOCOL){
if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){ if($packet->protocol1 < ProtocolInfo::CURRENT_PROTOCOL){
$pk = new LoginStatusPacket; $pk = new LoginStatusPacket;
$pk->status = 1; $pk->status = 1;
$this->directDataPacket($pk); $this->directDataPacket($pk);
}else{ }else{
$pk = new LoginStatusPacket; $pk = new LoginStatusPacket;
$pk->status = 2; $pk->status = 2;
$this->directDataPacket($pk); $this->directDataPacket($pk);
} }
$this->close("Incorrect protocol #" . $packet->protocol1, false); $this->close("Incorrect protocol #" . $packet->protocol1, false);
return; 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"){ 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); $this->close("Bad username", false);
@ -1485,7 +1485,7 @@ class Player{
$this->sendArmor(); $this->sendArmor();
$array = explode("@n", (string)$this->server->motd); $array = explode("@n", (string)$this->server->motd);
foreach($array as $msg){ foreach($array as $msg){
$this->sendChat($msg."\n"); $this->sendChat($msg."\n");
} }
$this->sendInventory(); $this->sendInventory();
@ -1799,7 +1799,7 @@ class Player{
$target = $this->server->api->entity->get($packet->target); $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){ 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["targetentity"] = $packet->target;
$data["entity"] = $this; $data["entity"] = $this;
if($this->server->handle("player.interact", $data) !== false){ if($this->server->handle("player.interact", $data) !== false){
$target->interactWith($this->entity, $packet->action); $target->interactWith($this->entity, $packet->action);
} }
@ -1900,18 +1900,18 @@ class Player{
$data["item"] = $packet->item; $data["item"] = $packet->item;
$data["player"] = $this; $data["player"] = $this;
if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){ if($this->blocked === false and $this->server->handle("player.drop", $data) !== false){
$f1 = 0.3; $f1 = 0.3;
$sX = -sin(($this->entity->yaw / 180) * M_PI) * cos(($this->entity->pitch / 180) * M_PI) * $f1; $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; $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; $sY = -sin(($this->entity->pitch / 180) * M_PI) * $f1 + 0.1;
$f1 = 0.02; $f1 = 0.02;
$f3 = $this->entity->random->nextFloat() * M_PI * 2.0; $f3 = $this->entity->random->nextFloat() * M_PI * 2.0;
$f1 *= $this->entity->random->nextFloat(); $f1 *= $this->entity->random->nextFloat();
$sX += cos($f3) * $f1; $sX += cos($f3) * $f1;
$sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1;
$sZ += sin($f3) * $f1; $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->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); $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false);
} }
if($this->entity->inAction === true){ if($this->entity->inAction === true){
@ -2167,20 +2167,20 @@ class Player{
} }
break; break;
case ProtocolInfo::PLAYER_INPUT_PACKET: case ProtocolInfo::PLAYER_INPUT_PACKET:
break; //TODO player input- break; //TODO player input-
default: default:
console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2); console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2);
break; break;
} }
} }
/** /**
* Get an Item which is currently held by player * Get an Item which is currently held by player
* @return Item * @return Item
*/ */
public function getHeldItem(){ public function getHeldItem(){
return $this->getSlot($this->slot); return $this->getSlot($this->slot);
} }
public function stopSleep(){ public function stopSleep(){

View file

@ -2,7 +2,7 @@
class PocketMinecraftServer{ 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; public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
/** /**
* @var ServerAPI * @var ServerAPI
@ -70,7 +70,7 @@ class PocketMinecraftServer{
console("[INFO] Loading extra.properties..."); console("[INFO] Loading extra.properties...");
$this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [ $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, [
"version" => "5", "version" => "5",
"experemental-mob-features" => false, "experemental-mob-features" => false,
"enable-nether-reactor" => true, "enable-nether-reactor" => true,
"enable-explosions" => true, "enable-explosions" => true,
"enable-rail-connection" => false, "enable-rail-connection" => false,
@ -84,7 +84,7 @@ class PocketMinecraftServer{
]); ]);
Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features"); Entity::$updateOnTick = $this->extraprops->get("experemental-mob-features");
if(Entity::$updateOnTick){ 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"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config
@ -451,31 +451,31 @@ class PocketMinecraftServer{
} }
} }
public function process() public function process()
{ {
$lastLoop = 0; $lastLoop = 0;
while($this->stop === false){ while($this->stop === false){
$packet = $this->interface->readPacket(); $packet = $this->interface->readPacket();
if($packet instanceof Packet){ if($packet instanceof Packet){
$this->packetHandler($packet); $this->packetHandler($packet);
$lastLoop = 0; $lastLoop = 0;
} elseif($this->tick() > 0){ } elseif($this->tick() > 0){
$lastLoop = 0; $lastLoop = 0;
} else{ } else{
++ $lastLoop; ++ $lastLoop;
if($lastLoop < 16){ if($lastLoop < 16){
usleep(1); usleep(1);
} elseif($lastLoop < 128){ } elseif($lastLoop < 128){
usleep(100); usleep(100);
} elseif($lastLoop < 256){ } elseif($lastLoop < 256){
usleep(512); usleep(512);
} else{ } else{
usleep(10000); usleep(10000);
} }
} }
$this->tick(); $this->tick();
} }
} }
public function packetHandler(Packet $packet){ public function packetHandler(Packet $packet){
$data =& $packet; $data =& $packet;
@ -568,7 +568,7 @@ class PocketMinecraftServer{
unset($this->tickMeasure[key($this->tickMeasure)]); unset($this->tickMeasure[key($this->tickMeasure)]);
++$this->ticks; ++$this->ticks;
foreach($this->api->level->levels as $l){ foreach($this->api->level->levels as $l){
$l->onTick($this); $l->onTick($this);
} }
return $this->tickerFunction($time); return $this->tickerFunction($time);
} }

View file

@ -1,40 +1,40 @@
<?php <?php
class ArrayList{ class ArrayList{
public $arr = []; public $arr = [];
public function add(IElement $e){ public function add(IElement $e){
$this->arr[$e->__toString()] = $e; $this->arr[$e->__toString()] = $e;
return $this; return $this;
} }
public function addAll($es){ public function addAll($es){
foreach($es as $e){ foreach($es as $e){
$this->add($this->add($e)); $this->add($this->add($e));
} }
} }
public function getFirst(){ public function getFirst(){
return array_values($this->arr)[0]; return array_values($this->arr)[0];
} }
public function remove(IElement $e){ public function remove(IElement $e){
unset($this->arr[$e->__toString()]); unset($this->arr[$e->__toString()]);
return $this; return $this;
} }
public function __isset($e){ public function __isset($e){
return isset($this->arr[$e->__toString()]); return isset($this->arr[$e->__toString()]);
} }
public function has(IElement $e){ public function has(IElement $e){
return isset($this->arr[$e->__toString()]); return isset($this->arr[$e->__toString()]);
} }
public function sortWith($func){ public function sortWith($func){
return uasort($this->arr, $func); return uasort($this->arr, $func);
} }
public function countElements(){ public function countElements(){
return count($this->arr); return count($this->arr);
} }
} }

View file

@ -2,6 +2,6 @@
interface IElement interface IElement
{ {
public function __toString(); public function __toString();
} }

View file

@ -2,6 +2,6 @@
interface ITileNavigator interface ITileNavigator
{ {
public function navigate(PathTile $from, PathTile $to); public function navigate(PathTile $from, PathTile $to);
} }

View file

@ -2,11 +2,11 @@
class PHPUtils class PHPUtils
{ {
public static function removeElementFromArray(&$arr, $element, $reindex = true){ public static function removeElementFromArray(&$arr, $element, $reindex = true){
if (($key = array_search($element, $arr)) !== false) { if (($key = array_search($element, $arr)) !== false) {
unset($arr[$key]); unset($arr[$key]);
if($reindex) $arr = array_values($arr); if($reindex) $arr = array_values($arr);
} }
} }
} }

View file

@ -2,26 +2,26 @@
class PathTile implements IElement class PathTile implements IElement
{ {
public $x, $y; public $x, $y;
public function __construct($x, $y){ public function __construct($x, $y){
$this->x = $x; $this->x = $x;
$this->y = $y; $this->y = $y;
} }
public function equals(PathTile $t){ public function equals(PathTile $t){
return $t->x === $this->x && $t->y === $this->y; return $t->x === $this->x && $t->y === $this->y;
} }
public function addOffset($offset){ public function addOffset($offset){
$this->x += $offset[0]; $this->x += $offset[0];
$this->y += $offset[1]; $this->y += $offset[1];
return $this; return $this;
} }
public function __toString(){ public function __toString(){
return $this->x.":".$this->y; return $this->x.":".$this->y;
} }
} }

View file

@ -2,37 +2,37 @@
class PathTileXYZ extends PathTile class PathTileXYZ extends PathTile
{ {
public $x, $y, $z; public $x, $y, $z;
/** /**
* @var Level * @var Level
*/ */
public $level; public $level;
public function __construct($x, $y, $z, $level){ public function __construct($x, $y, $z, $level){
$this->x = floor($x); $this->x = floor($x);
$this->y = floor($y); $this->y = floor($y);
$this->z = floor($z); $this->z = floor($z);
$this->level = $level; $this->level = $level;
} }
public function equals(PathTile $t){ public function equals(PathTile $t){
return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z; return $t->x === $this->x && $t->y === $this->y && $t->z === $this->z;
} }
public function asVector(){ public function asVector(){
return new Vector3($this->x, $this->y, $this->z); return new Vector3($this->x, $this->y, $this->z);
} }
public function addOffset($offset){ public function addOffset($offset){
$this->x += $offset[0]; $this->x += $offset[0];
$this->y += $offset[1]; $this->y += $offset[1];
$this->z += $offset[2]; $this->z += $offset[2];
return $this; return $this;
} }
public function __toString(){ public function __toString(){
return $this->x.":".$this->y.":".$this->z; return $this->x.":".$this->y.":".$this->z;
} }
} }

View file

@ -2,15 +2,15 @@
class TileNavigator implements ITileNavigator class TileNavigator implements ITileNavigator
{ {
private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm; private $blockedProvider, $neighborProvider, $distanceAlgorithm, $heuristicAlgorithm;
public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){ public function __construct(IBlockedProvider $blockedProvider, INeighborProvider $neighborProvider, IDistanceAlgorithm $distanceAlgorithm, IDistanceAlgorithm $heuristicAlgorithm){
$this->blockedProvider = $blockedProvider; $this->blockedProvider = $blockedProvider;
$this->neighborProvider = $neighborProvider; $this->neighborProvider = $neighborProvider;
$this->distanceAlgorithm = $distanceAlgorithm; $this->distanceAlgorithm = $distanceAlgorithm;
$this->heuristicAlgorithm = $heuristicAlgorithm; $this->heuristicAlgorithm = $heuristicAlgorithm;
} }
public function reconstructPath($path, $current){ public function reconstructPath($path, $current){
$totalPath = [$current]; $totalPath = [$current];
while (isset($path[(string)$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(array_unique($path) as $k => $p) console($k.":".$p);
//foreach($totalPath as $k => $p) console($k.":".$p); //foreach($totalPath as $k => $p) console($k.":".$p);
array_pop($totalPath); array_pop($totalPath);
return array_reverse($totalPath); return array_reverse($totalPath);
} }
public function navigate(PathTile $from, PathTile $to) public function navigate(PathTile $from, PathTile $to)
{ {
$closed = new ArrayList(); $closed = new ArrayList();
$open = new ArrayList(); $open = new ArrayList();
$open->add($from); $open->add($from);
$path = []; //new Dictionary<Tile, Tile>(); $path = []; //new Dictionary<Tile, Tile>();
$gScore = []; //new Dictionary<Tile, double>(); $gScore = []; //new Dictionary<Tile, double>();
$gScore[(string) $from] = 0; $gScore[(string) $from] = 0;
/** /**
* @var array[Tile] $fScore * @var array[Tile] $fScore
*/ */
$fScore = [];//new Dictionary<Tile, double>(); $fScore = [];//new Dictionary<Tile, double>();
$fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to); $fScore[(string) $from] = $this->heuristicAlgorithm->calculate($from, $to);
if($this->blockedProvider->isBlocked($to)){ if($this->blockedProvider->isBlocked($to)){
return null; 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; $visited = [];
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor); while($open->countElements() > 0)
{
if (!$open->has($neighbor)) //sleep(1);
{ $open->sortWith(function($k, $k1) use ($fScore){
$open->add($neighbor); return $fScore[(string)$k] === $fScore[(string)$k1] ? 0 : ($fScore[(string)$k] > $fScore[(string)$k1] ? 1 : -1);
} });
else if ($tentativeG >= $gScore[(string) $neighbor]) $current = $open->getFirst();
{ if ($current->equals($to)){
continue; return $this->reconstructPath($path, $current);
} }
$path[(string) $neighbor] = $current; $open->remove($current);
$gScore[(string) $neighbor] = $tentativeG; $closed->add($current);
$fScore[(string) $neighbor] = $gScore[(string) $neighbor] + $this->heuristicAlgorithm->calculate($neighbor, $to); foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
} {
} if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
{
return null; 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;
}
} }

View file

@ -2,6 +2,6 @@
interface IDistanceAlgorithm interface IDistanceAlgorithm
{ {
public function calculate(PathTile $from, PathTile $to); public function calculate(PathTile $from, PathTile $to);
} }

View file

@ -2,13 +2,13 @@
class ManhattanHeuristic3D implements IDistanceAlgorithm 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){ if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
return Utils::manh_distance($from->asVector(), $to->asVector()); return Utils::manh_distance($from->asVector(), $to->asVector());
} }
return 666; return 666;
} }
} }

View file

@ -2,11 +2,11 @@
class ManhattanHeuristicAlgorithm implements IDistanceAlgorithm class ManhattanHeuristicAlgorithm implements IDistanceAlgorithm
{ {
public function calculate(PathTile $from, PathTile $to) public function calculate(PathTile $from, PathTile $to)
{ {
return abs($from->x - $to->x) + abs($from->y - $to->y); return abs($from->x - $to->x) + abs($from->y - $to->y);
} }
} }

View file

@ -2,13 +2,13 @@
class Pythagoras3D implements IDistanceAlgorithm 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){ if($from instanceof PathTileXYZ && $to instanceof PathTileXYZ){
return Utils::distance_noroot($from->asVector(), $to->asVector()); return Utils::distance_noroot($from->asVector(), $to->asVector());
} }
return 666; return 666;
} }
} }

View file

@ -2,10 +2,10 @@
class PythagorasAlgorithm implements IDistanceAlgorithm class PythagorasAlgorithm implements IDistanceAlgorithm
{ {
public function calculate(PathTile $from, PathTile $to) public function calculate(PathTile $from, PathTile $to)
{ {
return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2)); return sqrt(pow($to->x - $from->x, 2) + pow($to->y - $from->y, 2));
} }
} }

View file

@ -1,17 +1,17 @@
<?php <?php
class DiagonalNeighborProvider implements INeighborProvider class DiagonalNeighborProvider implements INeighborProvider
{ {
private static $neighbors = array([ 0, -1 ], [ 1, 0 ], [ 0, 1 ], [ -1, 0 ], [ -1, -1 ], [ 1, -1 ], [ 1, 1 ], [ -1, 1 ]); 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) public function getNeighbors(PathTile $tile)
{ {
$result = []; $result = [];
foreach(self::$neighbors as $offset){ foreach(self::$neighbors as $offset){
$t = clone $tile; $t = clone $tile;
$result[] = $t->addOffset($offset); $result[] = $t->addOffset($offset);
} }
return $result; return $result;
} }
} }

View file

@ -2,9 +2,9 @@
class EmptyBlockedProvider implements IBlockedProvider class EmptyBlockedProvider implements IBlockedProvider
{ {
public function isBlocked(PathTile $tile) public function isBlocked(PathTile $tile)
{ {
return false; return false;
} }
} }

View file

@ -2,11 +2,11 @@
interface IBlockedProvider interface IBlockedProvider
{ {
/** /**
* @param Tile $tile * @param Tile $tile
* *
* @return boolean * @return boolean
*/ */
public function isBlocked(PathTile $tile); public function isBlocked(PathTile $tile);
} }

View file

@ -2,6 +2,6 @@
interface INeighborProvider interface INeighborProvider
{ {
public function getNeighbors(PathTile $tile); public function getNeighbors(PathTile $tile);
} }

View file

@ -3,14 +3,14 @@
class MCBlockedProvider implements IBlockedProvider class MCBlockedProvider implements IBlockedProvider
{ {
public function isBlocked(PathTile $tile) public function isBlocked(PathTile $tile)
{ {
if($tile instanceof PathTileXYZ){ if($tile instanceof PathTileXYZ){
$b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z); $b = $tile->level->getBlockWithoutVector($tile->x, $tile->y, $tile->z);
return $b instanceof Block && $b->isSolid; return $b instanceof Block && $b->isSolid;
} }
return false; return false;
} }
} }

View file

@ -2,21 +2,21 @@
class MCDiagonalProvider implements INeighborProvider 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 ]); 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) public function getNeighbors(PathTile $tile)
{ {
if($tile instanceof PathTileXYZ){ if($tile instanceof PathTileXYZ){
$result = []; $result = [];
foreach(self::$neighbors as $offset){ foreach(self::$neighbors as $offset){
$t = clone $tile; $t = clone $tile;
$result[] = $t->addOffset($offset); $result[] = $t->addOffset($offset);
} }
return $result; return $result;
} }
return []; return [];
} }
} }

View file

@ -14,46 +14,46 @@ rm bin.7z
echo "["$(date +%k:%M)"] Downloading PHP..." echo "["$(date +%k:%M)"] Downloading PHP..."
arch=$(uname -m) arch=$(uname -m)
if [[ $arch == x86_64* ]]; then if [[ $arch == x86_64* ]]; then
echo "X64 Architecture" echo "X64 Architecture"
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
tar -xvf NC_bin.tar.gz tar -xvf NC_bin.tar.gz
rm NC_bin.tar.gz rm NC_bin.tar.gz
elif [[ $arch == i*86 ]]; then elif [[ $arch == i*86 ]]; then
echo "X32 Architecture" echo "X32 Architecture"
wget https://owouwu.ru/NC_bin.tar.gz > /dev/null wget https://owouwu.ru/NC_bin.tar.gz > /dev/null
tar -xvf NC_bin.tar.gz tar -xvf NC_bin.tar.gz
rm NC_bin.tar.gz rm NC_bin.tar.gz
elif [[ $arch == arm* ]] || [[ $arch = aarch* ]]; then elif [[ $arch == arm* ]] || [[ $arch = aarch* ]]; then
echo "ARM Architecture" echo "ARM Architecture"
wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null wget https://owouwu.ru/NCArm_bin.tar.gz > /dev/null
tar -xvf NCArm_bin.tar.gz tar -xvf NCArm_bin.tar.gz
rm NCArm_bin.tar.gz rm NCArm_bin.tar.gz
fi fi
if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then if [ $(./bin/php5/bin/php -r 'echo "yes";' 2>/dev/null) == "yes" ]; then
OPCACHE_PATH="$(find $(pwd) -name opcache.so)" OPCACHE_PATH="$(find $(pwd) -name opcache.so)"
XDEBUG_PATH="$(find $(pwd) -name xdebug.so)" XDEBUG_PATH="$(find $(pwd) -name xdebug.so)"
echo "" > "./bin/php5/bin/php.ini" echo "" > "./bin/php5/bin/php.ini"
#UOPZ_PATH="$(find $(pwd) -name uopz.so)" #UOPZ_PATH="$(find $(pwd) -name uopz.so)"
#echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini" #echo "zend_extension=\"$UOPZ_PATH\"" >> "./bin/php5/bin/php.ini"
echo "zend_extension=\"$OPCACHE_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 "zend_extension=\"$XDEBUG_PATH\"" >> "./bin/php5/bin/php.ini"
echo "opcache.enable=1" >> "./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.enable_cli=1" >> "./bin/php5/bin/php.ini"
echo "opcache.save_comments=0" >> "./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.fast_shutdown=1" >> "./bin/php5/bin/php.ini"
echo "opcache.max_accelerated_files=4096" >> "./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.interned_strings_buffer=8" >> "./bin/php5/bin/php.ini"
echo "opcache.memory_consumption=128" >> "./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 "opcache.optimization_level=0xffffffff" >> "./bin/php5/bin/php.ini"
echo "date.timezone=$TIMEZONE" >> "./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 "short_open_tag=0" >> "./bin/php5/bin/php.ini"
echo "asp_tags=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.readonly=0" >> "./bin/php5/bin/php.ini"
echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini" echo "phar.require_hash=1" >> "./bin/php5/bin/php.ini"
echo "done" echo "done"
alldone=yes alldone=yes
else else
echo "Invalid PHP build detected" echo "Invalid PHP build detected"
fi fi
echo "Done, starting..." echo "Done, starting..."
echo "Wait >15 seconds..." echo "Wait >15 seconds..."

View file

@ -28,12 +28,12 @@ mkdir -p $COMPILEDIR
if [ "$COMPILE_LINUX_32BIT" = "true" ]; if [ "$COMPILE_LINUX_32BIT" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/32bit
cd $COMPILEDIR/linux/32bit cd $COMPILEDIR/linux/32bit
CFLAGS=-m32 march=i686 mtune=generic $SCRIPT CFLAGS=-m32 march=i686 mtune=generic $SCRIPT
cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/ cp -r $COMPILEDIR/linux/32bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/32bit/
if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/linux/32bit/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -41,12 +41,12 @@ fi
if [ "$COMPILE_LINUX_64BIT" = "true" ]; if [ "$COMPILE_LINUX_64BIT" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit mkdir -p {$COMPILEDIR,$ARCHIVE}/linux/64bit
cd $COMPILEDIR/linux/64bit cd $COMPILEDIR/linux/64bit
$SCRIPT $SCRIPT
cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/ cp -r $COMPILEDIR/linux/64bit/{install.log,bin/*,install_data/*} $ARCHIVE/linux/64bit/
if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/linux/64bit/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -54,9 +54,9 @@ fi
if [ "$COMPILE_MAC" = "true" ]; if [ "$COMPILE_MAC" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/mac mkdir -p {$COMPILEDIR,$ARCHIVE}/mac
cd $COMPILEDIR/mac cd $COMPILEDIR/mac
curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
cd libtool-2.4.2 cd libtool-2.4.2
./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null ./configure --prefix="$COMPILEDIR/mac/libtool" > /dev/null
@ -66,9 +66,9 @@ then
rm -rf libtool-2.4.2 rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool" export LIBTOOL="$COMPILEDIR/mac/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize" export LIBTOOLIZE="$COMPILEDIR/mac/libtool/bin/libtoolize"
$SCRIPT mac curl $SCRIPT mac curl
cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/ cp -r $COMPILEDIR/mac/{install.log,bin/*,install_data/*} $ARCHIVE/mac/
if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/mac/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -76,12 +76,12 @@ fi
if [ "$COMPILE_RPI" = "true" ]; if [ "$COMPILE_RPI" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi mkdir -p {$COMPILEDIR,$ARCHIVE}/rpi
cd $COMPILEDIR/rpi cd $COMPILEDIR/rpi
$SCRIPT rpi $SCRIPT rpi
cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/ cp -r $COMPILEDIR/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/rpi/
if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/rpi/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -89,12 +89,12 @@ fi
if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ]; if [ "$CROSSCOMPILE_ANDROID_ARMV6" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6 mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv6
cd $COMPILEDIR/crosscompile/android-armv6 cd $COMPILEDIR/crosscompile/android-armv6
$SCRIPT crosscompile android-armv6 $SCRIPT crosscompile android-armv6
cp -r $COMPILEDIR/crosscompile/android-armv6/{install.log,bin/*,install_data/*} $ARCHIVE/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 if [ ! -f $COMPILEDIR/crosscompile/android-armv6/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -102,12 +102,12 @@ fi
if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ]; if [ "$CROSSCOMPILE_ANDROID_ARMV7" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7 mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/android-armv7
cd $COMPILEDIR/crosscompile/android-armv7 cd $COMPILEDIR/crosscompile/android-armv7
$SCRIPT crosscompile android-armv7 $SCRIPT crosscompile android-armv7
cp -r $COMPILEDIR/crosscompile/android-armv7/{install.log,bin/*,install_data/*} $ARCHIVE/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 if [ ! -f $COMPILEDIR/crosscompile/android-armv7/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -115,8 +115,8 @@ fi
if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ]; if [ "$CROSSCOMPILE_IOS_ARMV6" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6 mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv6
cd $COMPILEDIR/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 curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
cd libtool-2.4.2 cd libtool-2.4.2
./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv6/libtool" > /dev/null
@ -126,9 +126,9 @@ then
rm -rf libtool-2.4.2 rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool" export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv6/libtool/bin/libtoolize"
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT 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/ 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 if [ ! -f $COMPILEDIR/crosscompile/ios-armv6/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -136,8 +136,8 @@ fi
if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ]; if [ "$CROSSCOMPILE_IOS_ARMV7" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7 mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/ios-armv7
cd $COMPILEDIR/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 curl -L http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz | tar -xz > /dev/null
cd libtool-2.4.2 cd libtool-2.4.2
./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null ./configure --prefix="$COMPILEDIR/crosscompile/ios-armv7/libtool" > /dev/null
@ -147,9 +147,9 @@ then
rm -rf libtool-2.4.2 rm -rf libtool-2.4.2
export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool" export LIBTOOL="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtool"
export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize" export LIBTOOLIZE="$COMPILEDIR/crosscompile/ios-armv7/libtool/bin/libtoolize"
PATH="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:$PATH" $SCRIPT 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/ 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 if [ ! -f $COMPILEDIR/crosscompile/ios-armv7/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -157,12 +157,12 @@ fi
if [ "$CROSSCOMPILE_RPI" = "true" ]; if [ "$CROSSCOMPILE_RPI" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/rpi
cd $COMPILEDIR/crosscompile/rpi cd $COMPILEDIR/crosscompile/rpi
$SCRIPT crosscompile rpi $SCRIPT crosscompile rpi
cp -r $COMPILEDIR/crosscompile/rpi/{install.log,bin/*,install_data/*} $ARCHIVE/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 if [ ! -f $COMPILEDIR/crosscompile/rpi/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi
@ -170,12 +170,12 @@ fi
if [ "$CROSSCOMPILE_MAC" = "true" ]; if [ "$CROSSCOMPILE_MAC" = "true" ];
then then
mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac mkdir -p {$COMPILEDIR,$ARCHIVE}/crosscompile/mac
cd $COMPILEDIR/crosscompile/mac cd $COMPILEDIR/crosscompile/mac
$SCRIPT crosscompile mac curl $SCRIPT crosscompile mac curl
cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/ cp -r $COMPILEDIR/crosscompile/mac/{install.log,bin/*,install_data/*} $ARCHIVE/crosscompile/mac/
if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then if [ ! -f $COMPILEDIR/crosscompile/mac/bin/php5/bin/php ]; then
exit 1 exit 1
fi fi

View file

@ -5,58 +5,58 @@ move methods
*/ */
abstract class Animal extends Creature implements Ageable, Breedable{ abstract class Animal extends Creature implements Ageable, Breedable{
public $parent; public $parent;
public $inLove; //do NOT add it into metadata, it doesnt send it to player public $inLove; //do NOT add it into metadata, it doesnt send it to player
public $age; public $age;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){ public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0); $this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){ if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
$this->setAge(-24000); $this->setAge(-24000);
} }
$this->ai->addTask(new TaskTempt()); $this->ai->addTask(new TaskTempt());
} }
public function isBaby(){ public function isBaby(){
return $this->getAge() < 0; return $this->getAge() < 0;
} }
public function breed(){ public function breed(){
$c = $this->spawnChild(); $c = $this->spawnChild();
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){ if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){
$c->parent = &$this; $c->parent = &$this;
$this->server->api->entity->spawnToAll($c); $this->server->api->entity->spawnToAll($c);
} }
} }
public function update(){ public function update(){
parent::update(); parent::update();
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal $age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
if($age >= 0 && $this->isBaby()){ if($age >= 0 && $this->isBaby()){
$this->setAge($age); $this->setAge($age);
$this->updateMetadata(); $this->updateMetadata();
}else{ }else{
$this->setAge($age); $this->setAge($age);
} }
} }
public function getAge(){ public function getAge(){
return $this->age; return $this->age;
} }
public function setAge($i){ public function setAge($i){
$this->age = $i; $this->age = $i;
} }
public function spawnChild() public function spawnChild()
{ {
return $this->server->api->entity->add($this->level, $this->class, $this->type, [ return $this->server->api->entity->add($this->level, $this->class, $this->type, [
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1), "x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
"y" => $this->y, "y" => $this->y,
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1), "z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
"IsBaby" => true, "IsBaby" => true,
"Age" => -24000, "Age" => -24000,
]); ]);
} }
public function getMetadata(){ public function getMetadata(){
@ -66,33 +66,33 @@ abstract class Animal extends Creature implements Ageable, Breedable{
} }
public function createSaveData(){ public function createSaveData(){
$data = parent::createSaveData(); $data = parent::createSaveData();
$data["IsBaby"] = $this->isBaby(); $data["IsBaby"] = $this->isBaby();
$data["Age"] = $this->getAge(); $data["Age"] = $this->getAge();
return $data; return $data;
} }
public function isInLove(){ public function isInLove(){
return $this->inLove > 0; return $this->inLove > 0;
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem(); $slot = $e->player->getHeldItem();
if($this->isFood($slot->getID())){ if($this->isFood($slot->getID())){
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1); $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
$this->inLove = 600; //600 ticks, original mehod from mcpe $this->inLove = 600; //600 ticks, original mehod from mcpe
return true; return true;
} }
} }
parent::interactWith($e, $action); parent::interactWith($e, $action);
} }
public function counterUpdate(){ public function counterUpdate(){
parent::counterUpdate(); parent::counterUpdate();
if($this->isInLove()){ if($this->isInLove()){
--$this->inLove; --$this->inLove;
} }
} }
public function getDrops(){ public function getDrops(){

View file

@ -25,30 +25,30 @@ abstract class Creature extends Living{
} }
public function update(){ public function update(){
if($this->onGround){ if($this->onGround){
/*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){ /*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)); $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))){ if($this->path != null && (is_array($this->path) && count($this->path) <= 0 || $this->currentIndex >= count($this->path))){
$this->path = null; $this->path = null;
$this->currentIndex = 0; $this->currentIndex = 0;
$this->currentNode = false; $this->currentNode = false;
}elseif($this->path != null && ($this->currentNode == false || $this->ai->mobController->moveTo($this->currentNode->x, $this->currentNode->y, $this->currentNode->z) === 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++]; $this->currentNode = $this->path[$this->currentIndex++];
}*/ }*/
} }
parent::update(); parent::update();
} }
public function createSaveData(){ public function createSaveData(){
$data = parent::createSaveData(); $data = parent::createSaveData();
$data["State"] = @$this->getState(); $data["State"] = @$this->getState();
return $data; return $data;
} }
public function getSpeedModifer(){ 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){ public function spawn($player){

View file

@ -69,7 +69,7 @@ class Entity extends Position
public $radius; public $radius;
public $inAction = false; public $inAction = false;
public $hasKnockback; public $hasKnockback;
public $onGround; public $onGround;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()) function __construct(Level $level, $eid, $class, $type = 0, $data = array())
@ -624,7 +624,7 @@ class Entity extends Position
break; break;
} }
if($b != false && $b->boundingBox->intersectsWith($aABB) && $b->isSolid && $this->isMoving()){ 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); $this->speedZ = $b->boundingBox->calculateZOffset($this->boundingBox, $this->speedZ);
$lastY = $this->speedY; $lastY = $this->speedY;
$this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY); $this->speedY = $b->boundingBox->calculateYOffset($this->boundingBox, $this->speedY);
@ -638,34 +638,34 @@ class Entity extends Position
} }
if(!$support){ if(!$support){
for($z = $startZ; $z <= $endZ; ++ $z){ for($z = $startZ; $z <= $endZ; ++ $z){
for($x = $startX; $x <= $endX; ++ $x){ for($x = $startX; $x <= $endX; ++ $x){
$v = new Vector3($x, $y, $z); $v = new Vector3($x, $y, $z);
$v1 = new Vector3($x, $yC, $z); $v1 = new Vector3($x, $yC, $z);
if($this->isSupport($v, $this->width)){ if($this->isSupport($v, $this->width)){
$b = $this->level->getBlock($v); $b = $this->level->getBlock($v);
if($b->isSolid === true){ if($b->isSolid === true){
$support = true; $support = true;
$isFlying = false; $isFlying = false;
break; 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){ } 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; $isFlying = false;
} }
} elseif($this->isSupport($v1, $this->width)){ } elseif($this->isSupport($v1, $this->width)){
$b = $this->level->getBlock($v1); $b = $this->level->getBlock($v1);
if($b->isSolid === true){ if($b->isSolid === true){
$support = true; $support = true;
$isFlying = false; $isFlying = false;
break; 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){ } 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; $isFlying = false;
} }
} }
} }
if($support === true){ if($support === true){
break; break;
} }
} }
} }
if($this->speedX != 0){ if($this->speedX != 0){
$this->x += $this->speedX; $this->x += $this->speedX;

View file

@ -1,21 +1,21 @@
<?php <?php
abstract class Living extends Entity implements Damageable{ abstract class Living extends Entity implements Damageable{
public $target, $ai; public $target, $ai;
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){ public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->target = false; $this->target = false;
$this->ai = new EntityAI($this); $this->ai = new EntityAI($this);
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$this->canBeAttacked = true; $this->canBeAttacked = true;
$this->hasGravity = true; $this->hasGravity = true;
$this->hasKnockback = true; $this->hasKnockback = true;
} }
public function update(){ public function update(){
if($this->idleTime <= 0) { if($this->idleTime <= 0) {
$this->ai->updateTasks(); $this->ai->updateTasks();
} }
parent::update(); parent::update();
} }
} }

View file

@ -1,13 +1,13 @@
<?php <?php
abstract class WalkingEntity extends Entity{ abstract class WalkingEntity extends Entity{
/** /**
* @param int $tickDiff * @param int $tickDiff
* *
* @return null|Vector3 * @return null|Vector3
*/ */
} }

View file

@ -2,74 +2,74 @@
class EntityAI class EntityAI
{ {
/** /**
* @var MobController * @var MobController
*/ */
public $mobController; public $mobController;
/** /**
* @var Living * @var Living
*/ */
public $entity; public $entity;
/** /**
* @var TaskBase[] * @var TaskBase[]
*/ */
protected $tasks; protected $tasks;
public $lastTask; public $lastTask;
public $counter = 0; public $counter = 0;
public function __construct($entity){ public function __construct($entity){
$this->entity = $entity; $this->entity = $entity;
$this->tasks = []; $this->tasks = [];
$this->mobController = new MobController($entity); $this->mobController = new MobController($entity);
} }
/** /**
* Add a task for entity * Add a task for entity
* @param TaskBase $task * @param TaskBase $task
*/ */
public function addTask(TaskBase $task){ public function addTask(TaskBase $task){
console("[DEBUG] Adding new task...",true, true, 2); console("[DEBUG] Adding new task...",true, true, 2);
$this->tasks[$task->__toString()] = $task; $this->tasks[$task->__toString()] = $task;
} }
/** /**
* *
* @param mixed $id classname * @param mixed $id classname
* @return TaskBase | false * @return TaskBase | false
*/ */
public function getTask($id){ public function getTask($id){
return isset($this->tasks[$id]) ? $this->tasks[$id] : false; return isset($this->tasks[$id]) ? $this->tasks[$id] : false;
} }
public function isStarted($id){ public function isStarted($id){
$task = @$this->getTask($id); $task = @$this->getTask($id);
return $task instanceof TaskBase && $task->isStarted; return $task instanceof TaskBase && $task->isStarted;
} }
public function updateTasks(){ public function updateTasks(){
if($this->counter % 3 != 0){ if($this->counter % 3 != 0){
return; return;
} }
foreach($this->tasks as $t){ foreach($this->tasks as $t){
if(!$t->isStarted && $t->canBeExecuted($this)){ if(!$t->isStarted && $t->canBeExecuted($this)){
$t->isStarted = true; $t->isStarted = true;
$t->onStart($this); $t->onStart($this);
} }
if($t->isStarted){ if($t->isStarted){
$t->onUpdate($this); $t->onUpdate($this);
if($t->selfCounter <= 0){ if($t->selfCounter <= 0){
$t->isStarted = false; $t->isStarted = false;
$t->onEnd($this); $t->onEnd($this);
} }
} }
} }
} }
public function __destruct(){ public function __destruct(){
unset($this->entity); unset($this->entity);
} }
} }

View file

@ -2,70 +2,70 @@
class MobController class MobController
{ {
/** /**
* @var Entity * @var Entity
*/ */
public $entity; public $entity;
public function __construct($e){ public function __construct($e){
$this->entity = $e; $this->entity = $e;
} }
public function moveNonInstant($x, $y, $z){ public function moveNonInstant($x, $y, $z){
if($x == 0 && $y == 0 && $z == 0){ if($x == 0 && $y == 0 && $z == 0){
return false; //failed return false; //failed
} }
$ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0)); $ox = ($x > 0 ? 1 : ($x < 0 ? -1 : 0));
$oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0)); $oy = ($y > 0 ? 1 : ($y < 0 ? -1 : 0));
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0)); $oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
$this->entity->moveEntityWithOffset($ox, $oy, $oz); $this->entity->moveEntityWithOffset($ox, $oy, $oz);
$this->faceEntity($this->entity->add($ox, $oy, $oz)); $this->faceEntity($this->entity->add($ox, $oy, $oz));
$pk = new RotateHeadPacket(); //TODO headYaw auto update $pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $this->entity->eid; $pk->eid = $this->entity->eid;
$pk->yaw = $this->entity->yaw; $pk->yaw = $this->entity->yaw;
$this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk); $this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk);
return true; return true;
} }
public function moveTo($x, $y, $z){ public function moveTo($x, $y, $z){
return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z)); return $this->moveNonInstant($x - floor($this->entity->x), $y - floor($this->entity->y), $z - floor($this->entity->z));
} }
public function faceEntity(Vector3 $v){ public function faceEntity(Vector3 $v){
$d = $v->subtract($this->entity)->normalize(); $d = $v->subtract($this->entity)->normalize();
$dx = $d->x; $dx = $d->x;
$dz = $d->z; $dz = $d->z;
$tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz)); $tan = $dz == 0 ? 0 : (90 - rad2deg($dx / $dz));
$thetaOffset = $dz < 0 ? 90 : 270; $thetaOffset = $dz < 0 ? 90 : 270;
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan); $this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
} }
public function lookOffset($x, $y, $z, $pitch = true){ public function lookOffset($x, $y, $z, $pitch = true){
$tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/ $tan = $z == 0 ? 0 : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
$thetaOffset = $z < 0 ? 90 : 270; $thetaOffset = $z < 0 ? 90 : 270;
$calcYaw = $tan + $thetaOffset; $calcYaw = $tan + $thetaOffset;
$this->entity->yaw = $calcYaw; $this->entity->yaw = $calcYaw;
if($pitch){ if($pitch){
$diff = sqrt($x * $x + $z * $z); $diff = sqrt($x * $x + $z * $z);
$calcPitch = rad2deg(atan($y / $diff)); $calcPitch = rad2deg(atan($y / $diff));
$this->entity->pitch = $this->entity->type === MOB_CHICKEN ? -$calcPitch : $calcPitch; $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.";"); $this->entity->server->query("UPDATE entities SET pitch = ".$this->entity->pitch.", yaw = ".$this->entity->yaw." WHERE EID = ".$this->entity->eid.";");
return true; return true;
} }
public function lookOn($x, $y = 0, $z = 0, $pitch = true){ public function lookOn($x, $y = 0, $z = 0, $pitch = true){
if($x instanceof Vector3){ if($x instanceof Vector3){
return $this->lookOn($x->x, $x->y + $x->getEyeHeight(), $x->z, $pitch); 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); return $this->lookOffset($x - $this->entity->x, ($this->entity->y + $this->entity->height) - $y, $z - $this->entity->z, $pitch);
} }
public function __destruct(){ public function __destruct(){
unset($this->entity); unset($this->entity);
} }
} }

View file

@ -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.";");
}
}

View file

@ -2,46 +2,46 @@
abstract class TaskBase abstract class TaskBase
{ {
public $isStarted = false, $selfCounter = 0; public $isStarted = false, $selfCounter = 0;
/** /**
* Executed when entity starts task. It is recommended to set counter here. * Executed when entity starts task. It is recommended to set counter here.
* @param EntityAI $ai * @param EntityAI $ai
*/ */
abstract function onStart(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. * Every tick until counter will be not equal to 0. It is recommended to update value of counter here.
* @param EntityAI $ai * @param EntityAI $ai
*/ */
abstract function onUpdate(EntityAI $ai); abstract function onUpdate(EntityAI $ai);
/** /**
* On task end. * On task end.
* @param EntityAI $ai * @param EntityAI $ai
*/ */
abstract function onEnd(EntityAI $ai); abstract function onEnd(EntityAI $ai);
/** /**
* Can start the task * Can start the task
* @param EntityAI $ai * @param EntityAI $ai
*/ */
abstract function canBeExecuted(EntityAI $ai); abstract function canBeExecuted(EntityAI $ai);
/** /**
* @return number ticks * @return number ticks
*/ */
function getIdleTimeAfterEnd(){ function getIdleTimeAfterEnd(){
return 0; return 0;
} }
function reset(){ function reset(){
$this->isStarted = false; $this->isStarted = false;
$this->selfCounter = 0; $this->selfCounter = 0;
} }
final function __toString(){ final function __toString(){
return get_class($this); return get_class($this);
} }
} }

View file

@ -2,35 +2,35 @@
class TaskLookAround extends TaskBase class TaskLookAround extends TaskBase
{ {
private $rotation; private $rotation;
public function onStart(EntityAI $ai) public function onStart(EntityAI $ai)
{ {
$this->selfCounter = 1; $this->selfCounter = 1;
$this->rotation = mt_rand(-120, 120); $this->rotation = mt_rand(-120, 120);
} }
public function onEnd(EntityAI $ai) public function onEnd(EntityAI $ai)
{ {
$ai->entity->idleTime = mt_rand(20, 40); $ai->entity->idleTime = mt_rand(20, 40);
} }
public function canBeExecuted(EntityAI $ai) public function canBeExecuted(EntityAI $ai)
{ {
return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/ return !$ai->entity->isMoving() && Utils::randomFloat() < 0.02 && !$ai->isStarted("TaskLookAtPlayer") && !$ai->isStarted("TaskTempt"); /*Vanilla value*/
} }
public function onUpdate(EntityAI $ai) public function onUpdate(EntityAI $ai)
{ {
if($this->rotation === 0){ if($this->rotation === 0){
$this->selfCounter = 0; $this->selfCounter = 0;
} }
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation); $v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
$ai->entity->yaw += $v; $ai->entity->yaw += $v;
$pk = new RotateHeadPacket(); //TODO headYaw auto update $pk = new RotateHeadPacket(); //TODO headYaw auto update
$pk->eid = $ai->entity->eid; $pk->eid = $ai->entity->eid;
$pk->yaw = $ai->entity->yaw; $pk->yaw = $ai->entity->yaw;
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk); $ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
$this->rotation -= $v; $this->rotation -= $v;
} }
} }

View file

@ -2,39 +2,39 @@
class TaskRandomWalk extends TaskBase class TaskRandomWalk extends TaskBase
{ {
private $x, $z; private $x, $z;
public function onStart(EntityAI $ai) public function onStart(EntityAI $ai)
{ {
$this->x = mt_rand(-10, 10); $this->x = mt_rand(-10, 10);
$this->z = mt_rand(-10, 10); $this->z = mt_rand(-10, 10);
if($this->x === 0 && $this->z === 0){ if($this->x === 0 && $this->z === 0){
$this->reset(); $this->reset();
return false; return false;
} }
$this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z))); $this->selfCounter = floor(5 * Utils::distance($ai->entity, $ai->entity->add($this->x, 0, $this->z)));
} }
public function onEnd(EntityAI $ai) public function onEnd(EntityAI $ai)
{ {
$this->x = $this->z = 0; $this->x = $this->z = 0;
} }
public function onUpdate(EntityAI $ai) public function onUpdate(EntityAI $ai)
{ {
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
return false; //TODO Better way: block movement return false; //TODO Better way: block movement
} }
--$this->selfCounter; --$this->selfCounter;
$ai->mobController->moveNonInstant($this->x, 0, $this->z); $ai->mobController->moveNonInstant($this->x, 0, $this->z);
} }
public function canBeExecuted(EntityAI $ai) public function canBeExecuted(EntityAI $ai)
{ {
if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) { if($ai->entity instanceof Creeper && $ai->entity->isIgnited()) {
return false; return false;
} }
return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0; return !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskLookAtPlayer") && mt_rand(0, 120) == 0;
} }
} }

View file

@ -4,7 +4,7 @@ class Chicken extends Animal{
const TYPE = MOB_CHICKEN; const TYPE = MOB_CHICKEN;
public $timeUntilEgg; public $timeUntilEgg;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ 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); parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setName('Chicken'); $this->setName('Chicken');
@ -17,11 +17,11 @@ class Chicken extends Animal{
} }
public function update(){ public function update(){
parent::update(); parent::update();
if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){ if($this->timeUntilEgg-- <= 0 && !$this->isBaby()){
$this->dropAnEgg(); $this->dropAnEgg();
$this->timeUntilEgg = mt_rand(0,6000) + 6000; $this->timeUntilEgg = mt_rand(0,6000) + 6000;
} }
} }
public function dropAnEgg(){ public function dropAnEgg(){

View file

@ -16,15 +16,15 @@ class Cow extends Animal{
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem(); $slot = $e->player->getHeldItem();
if($slot->getID() === BUCKET && $slot->getMetadata() === 0){ if($slot->getID() === BUCKET && $slot->getMetadata() === 0){
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket $e->player->removeItem($slot->getID(), $slot->getMetadata(), 1, true); //remove only 1 bucket
$e->player->addItem(BUCKET, 1, 1, true); $e->player->addItem(BUCKET, 1, 1, true);
return true; return true;
} }
} }
parent::interactWith($e, $action); parent::interactWith($e, $action);
} }
public function getDrops(){ public function getDrops(){

View file

@ -15,47 +15,47 @@ class Pig extends Animal implements Rideable{
* @return boolean * @return boolean
*/ */
public function isSaddled(){ public function isSaddled(){
return (boolean) $this->getState(); return (boolean) $this->getState();
} }
/** /**
* @param boolean $value * @param boolean $value
*/ */
public function setSaddled($value = null){ public function setSaddled($value = null){
$this->setState($value === null ? !$this->getState() : $value); $this->setState($value === null ? !$this->getState() : $value);
} }
public function canRide($e){ public function canRide($e){
return $this->isSaddled() && !($this->linkedEntity instanceof Entity); return $this->isSaddled() && !($this->linkedEntity instanceof Entity);
} }
public function interactWith(Entity $e, $action) public function interactWith(Entity $e, $action)
{ {
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem(); $slot = $e->player->getHeldItem();
if($this->canRide($e)){ if($this->canRide($e)){
$this->linkedEntity = $e; $this->linkedEntity = $e;
$e->isRiding = true; $e->isRiding = true;
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
return true; return true;
} }
if($e->isRiding && $this->linkedEntity->eid = $e->eid){ if($e->isRiding && $this->linkedEntity->eid = $e->eid){
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
$e->isRiding = false; $e->isRiding = false;
$this->linkedEntity = 0; $this->linkedEntity = 0;
return true; return true;
} }
if($slot->getID() === SADDLE){ if($slot->getID() === SADDLE){
if(!$this->isSaddled()){ if(!$this->isSaddled()){
$e->player->removeItem($slot->getID(), 0, 1); $e->player->removeItem($slot->getID(), 0, 1);
$this->setSaddled(1); $this->setSaddled(1);
} }
return true; //avoid further interactions return true; //avoid further interactions
} }
} }
return parent::interactWith($e, $action); return parent::interactWith($e, $action);
} }
public function isFood($id){ public function isFood($id){
return $id === POTATO || $id === CARROT || $id === BEETROOT; return $id === POTATO || $id === CARROT || $id === BEETROOT;

View file

@ -1,7 +1,7 @@
<?php <?php
class Sheep extends Animal{ class Sheep extends Animal{
public $color; public $color;
const TYPE = MOB_SHEEP; const TYPE = MOB_SHEEP;
function __construct(Level $level, $eid, $class, $type = 0, $data = []){ function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
@ -20,10 +20,10 @@ class Sheep extends Animal{
} }
public function createSaveData(){ public function createSaveData(){
$data = parent::createSaveData(); $data = parent::createSaveData();
$data["Color"] = @$this->data["Color"]; $data["Color"] = @$this->data["Color"];
$data["Sheared"] = @$this->data["Sheared"]; $data["Sheared"] = @$this->data["Sheared"];
return $data; return $data;
} }
public function eatGrass(){ public function eatGrass(){
@ -41,16 +41,16 @@ class Sheep extends Animal{
} }
public function setSheared($v = null){ public function setSheared($v = null){
$this->data["Sheared"] = $v === null ? !$this->isSheared() : $v; $this->data["Sheared"] = $v === null ? !$this->isSheared() : $v;
$this->updateMetadata(); $this->updateMetadata();
} }
public function isSheared(){ public function isSheared(){
return $this->data["Sheared"]; return $this->data["Sheared"];
} }
public function getColor(){ 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(){ public function getDrops(){
@ -64,21 +64,21 @@ class Sheep extends Animal{
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem(); $slot = $e->player->getHeldItem();
if($slot->getID() === SHEARS){ if($slot->getID() === SHEARS){
if(!$this->isSheared()){ if(!$this->isSheared()){
$this->setSheared(1); $this->setSheared(1);
$this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3))); $this->server->api->entity->drop($this, BlockAPI::getItem(WOOL, $this->getColor(), mt_rand(1, 3)));
//$this->server->schedule(20, [$this, "eatGrass"]); //$this->server->schedule(20, [$this, "eatGrass"]);
if($slot->getMetadata() >= $slot->getMaxDurability()){ if($slot->getMetadata() >= $slot->getMaxDurability()){
$this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); $this->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
} }
} }
return true; return true;
} }
} }
return parent::interactWith($e, $action); return parent::interactWith($e, $action);
} }
public function getMetadata(){ public function getMetadata(){
@ -93,19 +93,19 @@ class Sheep extends Animal{
public function sheepColor(){ //a method from 0.8.1 public function sheepColor(){ //a method from 0.8.1
$c = mt_rand(0,100); $c = mt_rand(0,100);
if($c <= 4){ if($c <= 4){
return 0xF; //white return 0xF; //white
} }
if($c <= 9){ if($c <= 9){
return 0x7; return 0x7;
} }
if($c <= 14){ if($c <= 14){
return 0x8; return 0x8;
} }
if($c <= 17){ if($c <= 17){
return 0xC; return 0xC;
} }
if(mt_rand(0, 500)){ if(mt_rand(0, 500)){
return 0x0; return 0x0;
} }
return 0x0; return 0x0;
} }

View file

@ -16,28 +16,28 @@ class Creeper extends Monster{
public function setIgnited($v = null){ public function setIgnited($v = null){
$this->setState($v === null ? !$this->getState() : $v); $this->setState($v === null ? !$this->getState() : $v);
} }
/** /**
* @return boolean * @return boolean
*/ */
public function isIgnited(){ public function isIgnited(){
return (boolean)$this->getState(); return (boolean)$this->getState();
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem(); $slot = $e->player->getHeldItem();
if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){ if($slot->getID() === FLINT_AND_STEEL && !$this->isIgnited()){
if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){ if($slot->useOn($e) and $slot->getMetadata() >= $slot->getMaxDurability()){
$e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true); $e->player->removeItem($slot->getID(), $slot->getMetadata(), $slot->count, true);
} }
$this->ignite(); $this->ignite();
return true; return true;
} }
} }
return parent::interactWith($e, $action); return parent::interactWith($e, $action);
} }
public function ignite(){ public function ignite(){
@ -55,16 +55,16 @@ class Creeper extends Monster{
parent::update(); parent::update();
} }
public function explode() public function explode()
{ {
if($this->closed){ if($this->closed){
return false; return false;
} }
$this->setIgnited(0); $this->setIgnited(0);
$explosion = new Explosion($this, 3); $explosion = new Explosion($this, 3);
$explosion->explode(); $explosion->explode();
$this->close(); $this->close();
} }
public function getDrops(){ public function getDrops(){
return [ return [

View file

@ -11,28 +11,28 @@ class Skeleton extends Monster{
} }
public function updateBurning(){ public function updateBurning(){
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
return false; return false;
} }
for($y = $this->y; $y < 129; $y++){ for($y = $this->y; $y < 129; $y++){
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
if($block->isSolid){ if($block->isSolid){
return false; return false;
} }
} }
if($block->getID() === AIR){ if($block->getID() === AIR){
$this->fire = 160; //Value from 0.8.1 $this->fire = 160; //Value from 0.8.1
$this->updateMetadata(); $this->updateMetadata();
return true; return true;
}else{ }else{
return false; return false;
} }
} }
public function update(){ public function update(){
$this->updateBurning(); $this->updateBurning();
parent::update(); parent::update();
} }
public function getDrops(){ public function getDrops(){

View file

@ -11,28 +11,28 @@ class Zombie extends Monster{
} }
public function updateBurning(){ public function updateBurning(){
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){ if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
return false; return false;
} }
for($y = $this->y; $y < 129; $y++){ for($y = $this->y; $y < 129; $y++){
$block = $this->level->getBlockWithoutVector($this->x, $y, $this->z); $block = $this->level->getBlockWithoutVector($this->x, $y, $this->z);
if($block->isSolid){ if($block->isSolid){
return false; return false;
} }
} }
if($block->getID() === AIR){ if($block->getID() === AIR){
$this->fire = 160; //Value from 0.8.1 $this->fire = 160; //Value from 0.8.1
$this->updateMetadata(); $this->updateMetadata();
return true; return true;
}else{ }else{
return false; return false;
} }
} }
public function update(){ public function update(){
$this->updateBurning(); $this->updateBurning();
parent::update(); parent::update();
} }
public function getDrops(){ public function getDrops(){

View file

@ -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 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); $f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
$d /= $f2; $d /= $f2;
$d1 /= $f2; $d1 /= $f2;
$d2 /= $f2; $d2 /= $f2;
$d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075 $d += $this->random->nextGaussian() * 0.0075 * $f1; //0.0074999998323619366 replaced with 0.0075
$d1 += $this->random->nextGaussian() * 0.0075 * $f1; $d1 += $this->random->nextGaussian() * 0.0075 * $f1;
$d2 += $this->random->nextGaussian() * 0.0075 * $f1; $d2 += $this->random->nextGaussian() * 0.0075 * $f1;
$d *= $f; $d *= $f;
$d1 *= $f; $d1 *= $f;
$d2 *= $f; $d2 *= $f;
$this->speedX = $d; $this->speedX = $d;
$this->speedY = $d1; $this->speedY = $d1;
$this->speedZ = $d2; $this->speedZ = $d2;
$f3 = sqrt($d * $d + $d2 * $d2); $f3 = sqrt($d * $d + $d2 * $d2);
$this->yaw = (atan2($d, $d2) * 180) / M_PI; $this->yaw = (atan2($d, $d2) * 180) / M_PI;
$this->pitch = (atan2($d1, $f3) * 180) / M_PI; $this->pitch = (atan2($d1, $f3) * 180) / M_PI;
$this->update(); $this->update();
//TODO i guess? $ticksInGround = 0; //TODO i guess? $ticksInGround = 0;
} }
public function spawn($player){ public function spawn($player){

View file

@ -49,24 +49,24 @@ class Minecart extends Vehicle{
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){ if($action === InteractPacket::ACTION_HOLD && $e->isPlayer() && $this->canRide($e)){
$this->linkedEntity = $e; $this->linkedEntity = $e;
$e->isRiding = true; $e->isRiding = true;
$this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE); $this->linkEntity($e, SetEntityLinkPacket::TYPE_RIDE);
return true; return true;
} }
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE); $this->linkEntity($e, SetEntityLinkPacket::TYPE_REMOVE);
$this->linkedEntity = 0; $this->linkedEntity = 0;
$e->isRiding = false; $e->isRiding = false;
return true; return true;
} }
parent::interactWith($e, $action); parent::interactWith($e, $action);
} }
public function canRide($e) public function canRide($e)
{ {
return !($this->linkedEntity instanceof Entity) && !$e->isRiding; return !($this->linkedEntity instanceof Entity) && !$e->isRiding;
} }
} }

View file

@ -20,11 +20,11 @@ class Painting extends Hanging{
} }
public function createSaveData(){ public function createSaveData(){
$data = parent::createSaveData(); $data = parent::createSaveData();
$data["Motive"] = $this->data["Motive"]; $data["Motive"] = $this->data["Motive"];
return $data; return $data;
} }
public function spawn($player){ public function spawn($player){

View file

@ -9,10 +9,10 @@ class TripodCamera extends Entity{
} }
public function interactWith(Entity $e, $action){ public function interactWith(Entity $e, $action){
if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){ if($e->isPlayer() and $action === InteractPacket::ACTION_HOLD){
//todo //todo
$this->server->schedule(40, [$this, "close"]); $this->server->schedule(40, [$this, "close"]);
} }
parent::interactWith($e, $action); parent::interactWith($e, $action);
} }
} }

View file

@ -175,7 +175,7 @@ abstract class Block extends Position{
return $this->id; return $this->id;
} }
public function setMetadata($i){ public function setMetadata($i){
$this->meta = $i; $this->meta = $i;
} }
final public function getMetadata(){ final public function getMetadata(){
return $this->meta & 0x0F; return $this->meta & 0x0F;

View file

@ -153,7 +153,7 @@ class Item{
} }
public function isPickaxe(){ public function isPickaxe(){
return false; return false;
} }
public function getName(){ public function getName(){
@ -217,11 +217,11 @@ class Item{
public function useOn($object, $force = false){ public function useOn($object, $force = false){
if($force){ if($force){
if(($object instanceof Entity) and !$this->isSword()){ if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2; $this->meta += 2;
}else{ }else{
$this->meta++; $this->meta++;
} }
return true; return true;
} }
return false; return false;
@ -303,7 +303,7 @@ class Item{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return Item::DEF_DAMAGE; return Item::DEF_DAMAGE;
} }
public function getDestroySpeed(Block $block, Player $player){ public function getDestroySpeed(Block $block, Player $player){

View file

@ -1,27 +1,27 @@
<?php <?php
class DoorBlock extends TransparentBlock{ class DoorBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->isSolid = false; $this->isSolid = false;
} }
/** /**
* @param int $type * @param int $type
* *
* @return bool|int * @return bool|int
*/ */
public function onUpdate($type){ public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method if($this->getSide(0)->getID() === AIR){ //Replace with common break method
$this->level->setBlock($this, new AirBlock(), false); $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)); 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)); 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){ if($this->getSide(1) instanceof DoorBlock){
$this->level->setBlock($this->getSide(1), new AirBlock(), false); $this->level->setBlock($this->getSide(1), new AirBlock(), false);
} }
@ -32,19 +32,19 @@ class DoorBlock extends TransparentBlock{
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* @param Block $block * @param Block $block
* @param Block $target * @param Block $target
* @param integer $face * @param integer $face
* @param integer $fx * @param integer $fx
* @param integer $fy * @param integer $fy
* @param integer $fz * @param integer $fz
* *
* @return boolean * @return boolean
*/ */
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 1){ if($face === 1){
$blockUp = $this->getSide(1); $blockUp = $this->getSide(1);
$blockDown = $this->getSide(0); $blockDown = $this->getSide(0);
@ -73,13 +73,13 @@ class DoorBlock extends TransparentBlock{
return false; return false;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return boolean * @return boolean
*/ */
public function onBreak(Item $item, Player $player){ public function onBreak(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){ if(($this->meta & 0x08) === 0x08){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === $this->id){ if($down->getID() === $this->id){
@ -95,13 +95,13 @@ class DoorBlock extends TransparentBlock{
return true; return true;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return boolean * @return boolean
*/ */
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
if(($this->meta & 0x08) === 0x08){ //Top if(($this->meta & 0x08) === 0x08){ //Top
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === $this->id){ if($down->getID() === $this->id){

View file

@ -1,29 +1,29 @@
<?php <?php
class FallableBlock extends SolidBlock{ class FallableBlock extends SolidBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->hasPhysics = true; $this->hasPhysics = true;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* @param Block $block * @param Block $block
* @param Block $target * @param Block $target
* @param int $face * @param int $face
* @param int $fx * @param int $fx
* @param int $fy * @param int $fy
* @param int $fz * @param int $fz
* *
* @return mixed * @return mixed
*/ */
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;

View file

@ -1,12 +1,12 @@
<?php <?php
class FlowableBlock extends TransparentBlock{ class FlowableBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->isFlowable = true; $this->isFlowable = true;
$this->isFullBlock = false; $this->isFullBlock = false;

View file

@ -2,57 +2,57 @@
class GenericBlock extends Block{ class GenericBlock extends Block{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* @param Block $block * @param Block $block
* @param Block $target * @param Block $target
* @param integer $face * @param integer $face
* @param integer $fx * @param integer $fx
* @param integer $fy * @param integer $fy
* @param integer $fz * @param integer $fz
* *
* @return mixed * @return mixed
*/ */
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
return $this->level->setBlock($this, $this, true, false, true); return $this->level->setBlock($this, $this, true, false, true);
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return boolean * @return boolean
*/ */
public function isBreakable(Item $item, Player $player){ public function isBreakable(Item $item, Player $player){
return ($this->breakable); return ($this->breakable);
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return mixed * @return mixed
*/ */
public function onBreak(Item $item, Player $player){ public function onBreak(Item $item, Player $player){
return $this->level->setBlock($this, new AirBlock(), true, false, true); return $this->level->setBlock($this, new AirBlock(), true, false, true);
} }
/** /**
* @param integer $type * @param integer $type
* *
* @return boolean * @return boolean
*/ */
public function onUpdate($type){ public function onUpdate($type){
if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){ if($this->hasPhysics === true and $type === BLOCK_UPDATE_NORMAL){
$down = $this->getSide(0); $down = $this->getSide(0);
if($down->getID() === AIR or ($down instanceof LiquidBlock)){ if($down->getID() === AIR or ($down instanceof LiquidBlock)){
@ -73,13 +73,13 @@ class GenericBlock extends Block{
return false; return false;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return boolean * @return boolean
*/ */
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
return $this->isActivable; return $this->isActivable;
} }
} }

View file

@ -1,12 +1,12 @@
<?php <?php
class LiquidBlock extends TransparentBlock{ class LiquidBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->isLiquid = true; $this->isLiquid = true;
$this->breakable = false; $this->breakable = false;

View file

@ -1,12 +1,12 @@
<?php <?php
class SolidBlock extends GenericBlock{ class SolidBlock extends GenericBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->isSolid = true; $this->isSolid = true;
$this->isFullBlock = true; $this->isFullBlock = true;

View file

@ -1,12 +1,12 @@
<?php <?php
class StairBlock extends TransparentBlock{ class StairBlock extends TransparentBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
if(($this->meta & 0x04) === 0x04){ if(($this->meta & 0x04) === 0x04){
$this->isFullBlock = true; $this->isFullBlock = true;
@ -16,19 +16,19 @@ class StairBlock extends TransparentBlock{
$this->hardness = 30; $this->hardness = 30;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* @param Block $block * @param Block $block
* @param Block $target * @param Block $target
* @param int $face * @param int $face
* @param int $fx * @param int $fx
* @param int $fy * @param int $fy
* @param int $fz * @param int $fz
* *
* @return bool|mixed * @return bool|mixed
*/ */
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array( $faces = array(
0 => 0, 0 => 0,
1 => 2, 1 => 2,
@ -43,13 +43,13 @@ class StairBlock extends TransparentBlock{
return true; return true;
} }
/** /**
* @param Item $item * @param Item $item
* @param Player $player * @param Player $player
* *
* @return array * @return array
*/ */
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->getPickaxeLevel() >= 1){ if($item->getPickaxeLevel() >= 1){
return array( return array(
array($this->id, 0, 1), array($this->id, 0, 1),

View file

@ -1,12 +1,12 @@
<?php <?php
class TransparentBlock extends GenericBlock{ class TransparentBlock extends GenericBlock{
/** /**
* @param int $id * @param int $id
* @param int $meta * @param int $meta
* @param string $name * @param string $name
*/ */
public function __construct($id, $meta = 0, $name = "Unknown"){ public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name); parent::__construct($id, $meta, $name);
$this->isActivable = false; $this->isActivable = false;
$this->breakable = true; $this->breakable = true;

View file

@ -1,14 +1,14 @@
<?php <?php
class SignPostBlock extends TransparentBlock{ class SignPostBlock extends TransparentBlock{
private $faces = array( private $faces = array(
2 => 2, 2 => 2,
3 => 3, 3 => 3,
4 => 4, 4 => 4,
5 => 5, 5 => 5,
); );
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(SIGN_POST, $meta, "Sign Post"); parent::__construct(SIGN_POST, $meta, "Sign Post");
$this->isSolid = false; $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){ 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])){ if(!isset($this->faces[$face])){
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F; $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); $this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true);
return true; return true;
}else{ }else{
$this->meta = $this->faces[$face]; $this->meta = $this->faces[$face];
$this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true)); $this->level->setBlock($block, BlockAPI::get(WALL_SIGN, $this->meta, true, false, true));
return true; return true;
} }

View file

@ -13,8 +13,8 @@ class TrapdoorBlock extends TransparentBlock{
} }
public function canAttachTo(Block $target){ public function canAttachTo(Block $target){
$id = $target->getID(); $id = $target->getID();
return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock); 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){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -97,8 +97,8 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
$tlevel = $sb->meta & 0x06; $tlevel = $sb->meta & 0x06;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); 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); $this->level->setBlock($sb, new AirBlock(), false, false, true);
} }
@ -107,10 +107,10 @@ class LavaBlock extends LiquidBlock implements LightingBlock{
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
$tlevel = $b->meta & 0x06; $tlevel = $b->meta & 0x06;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 40, BLOCK_UPDATE_NORMAL); 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); $this->level->setBlock($b, new AirBlock(), false, false, true);
} }
} }

View file

@ -1,126 +1,126 @@
<?php <?php
class WaterBlock extends LiquidBlock{ class WaterBlock extends LiquidBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water"); parent::__construct(WATER, $meta, "Water");
$this->hardness = 500; $this->hardness = 500;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true); $ret = $this->level->setBlock($this, $this, true, false, true);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL);
return $ret; return $ret;
} }
public function getSourceCount(){ public function getSourceCount(){
$count = 0; $count = 0;
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
if( $this->getSide($side) instanceof WaterBlock ){ if( $this->getSide($side) instanceof WaterBlock ){
$b = $this->getSide($side); $b = $this->getSide($side);
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$count++; $count++;
} }
} }
} }
return $count; return $count;
} }
public function checkLava(){ public function checkLava(){
for($side = 0; $side <= 5; ++$side){ for($side = 0; $side <= 5; ++$side){
if($side == 1){ if($side == 1){
continue; continue;
} }
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof LavaBlock){ if($b instanceof LavaBlock){
$level = $b->meta & 0x07; $level = $b->meta & 0x07;
if($level == 0x00){ if($level == 0x00){
$this->level->setBlock($b, new ObsidianBlock(), false, false, true); $this->level->setBlock($b, new ObsidianBlock(), false, false, true);
}else{ }else{
$this->level->setBlock($b, new CobblestoneBlock(), false, false, true); $this->level->setBlock($b, new CobblestoneBlock(), false, false, true);
} }
return true; return true;
} }
} }
return false; return false;
} }
public function getFrom(){ public function getFrom(){
for($side = 0; $side <= 5; ++$side){ for($side = 0; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){ if( ($tlevel + 1) == $level || ($side == 0x01 && $level == 0x01 )){
return $b; return $b;
} }
} }
} }
return null; return null;
} }
public function onUpdate($type){ public function onUpdate($type){
//return false; //return false;
$newId = $this->id; $newId = $this->id;
$level = $this->meta & 0x07; $level = $this->meta & 0x07;
if($type !== BLOCK_UPDATE_NORMAL){ if($type !== BLOCK_UPDATE_NORMAL){
return false; return false;
} }
$this->checkLava(); $this->checkLava();
$falling = $this->meta >> 3; $falling = $this->meta >> 3;
$down = $this->getSide(0); $down = $this->getSide(0);
$from = $this->getFrom(); $from = $this->getFrom();
//Has Source or Its Source //Has Source or Its Source
if($from !== null || $level == 0x00){ if($from !== null || $level == 0x00){
if($down instanceof AirBlock || $down instanceof WaterBlock){ if($down instanceof AirBlock || $down instanceof WaterBlock){
$this->level->setBlock($down, new WaterBlock(0x00), false, false, true); $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); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
}elseif($level !== 0x07){{ }elseif($level !== 0x07){{
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$b = $this->getSide($side); $b = $this->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
if( $this->getSourceCount() >= 2 && $level != 0x00){ if( $this->getSourceCount() >= 2 && $level != 0x00){
$this->level->setBlock($this, new WaterBlock(0), false, false, true); $this->level->setBlock($this, new WaterBlock(0), false, false, true);
} }
}elseif($b->isFlowable === true){ }elseif($b->isFlowable === true){
$this->level->setBlock($b, new WaterBlock($level + 1), false, false, 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); ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL);
} }
} }
} }
} }
}else{ }else{
//Extend Remove for Left Waters //Extend Remove for Left Waters
for($side = 2; $side <= 5; ++$side){ for($side = 2; $side <= 5; ++$side){
$sb = $this->getSide($side); $sb = $this->getSide($side);
if($sb instanceof WaterBlock){ if($sb instanceof WaterBlock){
$tlevel = $sb->meta & 0x07; $tlevel = $sb->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); 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); $this->level->setBlock($sb, new AirBlock(), false, false, true);
} }
} }
$b = $this->getSide(0)->getSide($side); $b = $this->getSide(0)->getSide($side);
if($b instanceof WaterBlock){ if($b instanceof WaterBlock){
$tlevel = $b->meta & 0x07; $tlevel = $b->meta & 0x07;
if($tlevel != 0x00){ if($tlevel != 0x00){
for ($s = 0; $s <= 5; $s++) { for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s); $ssb = $sb->getSide($s);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); 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); $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); //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); $this->level->setBlock($this, new AirBlock(), false, false, true);
} }
return false; return false;
} }
} }

View file

@ -49,12 +49,12 @@ class NetherReactorBlock extends SolidBlock{
} }
public function getDrops(Item $item, Player $player){ public function getDrops(Item $item, Player $player){
if($item->getPickaxeLevel() >= 1){ if($item->getPickaxeLevel() >= 1){
return array( return array(
[DIAMOND, 0, 3], [DIAMOND, 0, 3],
[IRON_INGOT, 0, 6], [IRON_INGOT, 0, 6],
); );
} }
} }
private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) { private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) {

View file

@ -28,7 +28,7 @@ class FenceGateBlock extends TransparentBlock{
); );
} }
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$this->meta ^= 0x04; $this->meta ^= 0x04;
$this->level->setBlock($this, $this, true, false, true); $this->level->setBlock($this, $this, true, false, true);
$players = ServerAPI::request()->api->player->getAll($this->level); $players = ServerAPI::request()->api->player->getAll($this->level);
unset($players[$player->CID]); unset($players[$player->CID]);

View file

@ -2,7 +2,7 @@
class RailBlock extends FlowableBlock{ class RailBlock extends FlowableBlock{
public function __construct($meta = 0){ public function __construct($meta = 0){
parent::__construct(RAIL, $meta, "Rail"); parent::__construct(RAIL, $meta, "Rail");
$this->hardness = 0.7; $this->hardness = 0.7;
$this->isFullBlock = false; $this->isFullBlock = false;
$this->isSolid = false; $this->isSolid = false;
@ -11,25 +11,25 @@ class RailBlock extends FlowableBlock{
public static $shouldconnectrails = false; public static $shouldconnectrails = false;
private function isRailBlock($id){ private function isRailBlock($id){
return $id === RAIL || $id === POWERED_RAIL; return $id === RAIL || $id === POWERED_RAIL;
} }
private function isValidRailMeta($meta){ private function isValidRailMeta($meta){
return !($meta < 0 || $meta > 10); return !($meta < 0 || $meta > 10);
} }
private function canConnectRail($block) { private function canConnectRail($block) {
if(!($block instanceof RailBlock)) return null; if(!($block instanceof RailBlock)) return null;
if($this->distanceSquared($block) > 2) return null; if($this->distanceSquared($block) > 2) return null;
$result = $this->checkRail($this); $result = $this->checkRail($this);
if(count($result) === 2) return null; if(count($result) === 2) return null;
return $result; return $result;
} }
private function checkRail($rail){//fixed private function checkRail($rail){//fixed
if(!($rail instanceof RailBlock)) return null; if(!($rail instanceof RailBlock)) return null;
$damage = $rail->meta; $damage = $rail->meta;
if ($damage < 0 || $damage > 10) return null; if ($damage < 0 || $damage > 10) return null;
$delta = array( $delta = array(
array(array(0, 1), array(0, -1)), array(array(0, 1), array(0, -1)),
array(array(1, 0), array(-1, 0)), array(array(1, 0), array(-1, 0)),
@ -44,70 +44,70 @@ class RailBlock extends FlowableBlock{
array(array(-1, 0), array(0, -1)), array(array(-1, 0), array(0, -1)),
array(array(0, -1), array(1, 0)) array(array(0, -1), array(1, 0))
); );
$deltaY = array(0, 1, -1); $deltaY = array(0, 1, -1);
$blocks = $delta[$damage]; $blocks = $delta[$damage];
$connected = array(); $connected = array();
foreach($deltaY as $y){ foreach($deltaY as $y){
$v3 = new Vector3( $v3 = new Vector3(
$rail->getFloorX() + $blocks[0][0], $rail->getFloorX() + $blocks[0][0],
$rail->getFloorY() + $y, $rail->getFloorY() + $y,
$rail->getFloorZ() + $blocks[0][1] $rail->getFloorZ() + $blocks[0][1]
); );
$railBlock = $rail->level->getBlock($v3); $railBlock = $rail->level->getBlock($v3);
$idToConnect = $railBlock->getID(); $idToConnect = $railBlock->getID();
$metaToConnect = $railBlock->getMetadata(); $metaToConnect = $railBlock->getMetadata();
if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; if (!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
$xDiff = $this->getFloorX() - $v3->getFloorX(); $xDiff = $this->getFloorX() - $v3->getFloorX();
$zDiff = $this->getFloorZ() - $v3->getFloorZ(); $zDiff = $this->getFloorZ() - $v3->getFloorZ();
foreach($blocks as $xz) { foreach($blocks as $xz) {
if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; if($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
$connected[] = $v3; $connected[] = $v3;
} }
} }
foreach($deltaY as $y){ foreach($deltaY as $y){
$v3 = new Vector3( $v3 = new Vector3(
$rail->getFloorX() + $blocks[1][0], $rail->getFloorX() + $blocks[1][0],
$rail->getFloorY() + $y, $rail->getFloorY() + $y,
$rail->getFloorZ() + $blocks[1][1] $rail->getFloorZ() + $blocks[1][1]
); );
$railBlock = $rail->level->getBlock($v3); $railBlock = $rail->level->getBlock($v3);
$idToConnect = $railBlock->getID(); $idToConnect = $railBlock->getID();
$metaToConnect = $railBlock->getMetadata(); $metaToConnect = $railBlock->getMetadata();
if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue; if(!$this->isRailBlock($idToConnect) || !$this->isValidRailMeta($metaToConnect)) continue;
$xDiff = $this->getFloorX() - $v3->getFloorX(); $xDiff = $this->getFloorX() - $v3->getFloorX();
$zDiff = $this->getFloorZ() - $v3->getFloorZ(); $zDiff = $this->getFloorZ() - $v3->getFloorZ();
foreach($blocks as $xz){ foreach($blocks as $xz){
if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue; if ($xz[0] !== $xDiff || $xz[1] !== $zDiff) continue;
$connected[] = $v3; $connected[] = $v3;
} }
} }
return $connected; return $connected;
} }
private function connectRail($rail){ private function connectRail($rail){
$connected = $this->canConnectRail($rail); $connected = $this->canConnectRail($rail);
if ($connected === null || count($connected) === 0) return; if ($connected === null || count($connected) === 0) return;
if(count($connected) === 1){ if(count($connected) === 1){
$v3 = $connected[0]->subtract($this); $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); $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){ }elseif(count(connected) === 2){
$subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0)); $subtract = array(new Vector3(0, 0, 0),new Vector3(0, 0, 0));
for ($i = 0; $i < count($connected); $i++) { for ($i = 0; $i < count($connected); $i++) {
$subtract[$i] = $connected[$i]->subtract($this); $subtract[$i] = $connected[$i]->subtract($this);
} }
if (abs($subtract[0]->x) === abs($subtract[1]->z) && abs($subtract[1]->x) === abs($subtract[0]->z)){ 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)); $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); $this->meta = $v3->x === 1 ? ($v3->z === 1 ? 6 : 9) : ($v3->z === 1 ? 7 : 8);
}elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){ }elseif ($subtract[0]->y === 1 || $subtract[1]->y === 1){
$v3 = $subtract[0]->y === 1 ? $subtract[0] : $subtract[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); $this->meta = $v3->x === 0 ? ($v3->z === -1 ? 4 : 5) : ($v3->x === 1 ? 2 : 3);
}else{ }else{
$this->meta = $subtract[0]->x === 0 ? 0 : 1; $this->meta = $subtract[0]->x === 0 ? 0 : 1;
} }
} }
$this->level->setBlock($rail, new RailBlock($this->meta), true, true); $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){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0); $down = $this->getSide(0);

View file

@ -59,9 +59,9 @@ class BeetrootBlock extends FlowableBlock{
$drops[] = array(BEETROOT, 0, 1); $drops[] = array(BEETROOT, 0, 1);
} }
for($i = 0; $i < 3; ++$i){ for($i = 0; $i < 3; ++$i){
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
$drops[] = array(BEETROOT_SEEDS, 0, 1); $drops[] = array(BEETROOT_SEEDS, 0, 1);
} }
} }
return $drops; return $drops;
} }

View file

@ -60,7 +60,7 @@ class CarrotBlock extends FlowableBlock{
} }
for($i = 0; $i < 3; ++$i){ for($i = 0; $i < 3; ++$i){
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 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; return $drops;

View file

@ -17,7 +17,7 @@ class TallGrassBlock extends FlowableBlock{
if($type === BLOCK_UPDATE_NORMAL){ if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){//Replace with common break method if($this->getSide(0)->isTransparent === true){//Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true); $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; return BLOCK_UPDATE_NORMAL;
} }
} }

View file

@ -60,11 +60,11 @@ class WheatBlock extends FlowableBlock{
$drops[] = array(WHEAT, 0, 1); $drops[] = array(WHEAT, 0, 1);
$drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3)); $drops[] = array(WHEAT_SEEDS, 0, mt_rand(0, 3));
}else{ }else{
for($i = 0; $i < 3; ++$i){ for($i = 0; $i < 3; ++$i){
if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7 if(mt_rand(0,15) <= $this->meta){ //a way from 1.4.7
$drops[] = array(WHEAT_SEEDS, 0, 1); $drops[] = array(WHEAT_SEEDS, 0, 1);
} }
} }
} }
return $drops; return $drops;

View file

@ -40,7 +40,7 @@ class DirtBlock extends SolidBlock{
$x = $this->x; $x = $this->x;
$y = $this->y; $y = $this->y;
$z = $this->z; $z = $this->z;
if($this->getBlockID($x+1, $y, $z+1) == 2) return true; 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) == 2) return true;
if($this->getBlockID($x+1, $y, $z-1) == 2) return true; if($this->getBlockID($x+1, $y, $z-1) == 2) return true;

View file

@ -11,7 +11,7 @@ class DoubleSlabBlock extends SolidBlock{
4 => "Brick", 4 => "Brick",
5 => "Stone Brick", 5 => "Stone Brick",
6 => "Quartz", 6 => "Quartz",
7 => "Smooth Stone", 7 => "Smooth Stone",
); );
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab"; $this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
$this->hardness = 30; $this->hardness = 30;

View file

@ -10,15 +10,15 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{
return 15; return 15;
} }
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array( $faces = array(
0 => 1, 0 => 1,
1 => 2, 1 => 2,
2 => 3, 2 => 3,
3 => 0, 3 => 0,
); );
$this->meta = $faces[$player->entity->getDirection()]; $this->meta = $faces[$player->entity->getDirection()];
$this->level->setBlock($block, $this, true, false, true); $this->level->setBlock($block, $this, true, false, true);
return true; return true;
} }
} }

View file

@ -2,10 +2,10 @@
abstract class ItemAxe extends ItemTool abstract class ItemAxe extends ItemTool
{ {
public function isAxe(){ public function isAxe(){
return true; return true;
} }
} }

View file

@ -2,17 +2,17 @@
abstract class ItemHoe extends ItemTool abstract class ItemHoe extends ItemTool
{ {
public function isHoe(){ public function isHoe(){
return true; return true;
} }
public function useOn($object, $force = false){ public function useOn($object, $force = false){
if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){ if(($object instanceof Block) and ($object->getID() === GRASS or $object->getID() === DIRT)){
$this->meta++; $this->meta++;
return true; return true;
}else{ }else{
return parent::useOn($object, $force); return parent::useOn($object, $force);
} }
} }
} }

View file

@ -2,12 +2,12 @@
abstract class ItemPickaxe extends ItemTool abstract class ItemPickaxe extends ItemTool
{ {
public function isTool(){ public function isTool(){
return true; return true;
} }
public function isPickaxe(){ public function isPickaxe(){
return true; return true;
} }
} }

View file

@ -2,8 +2,8 @@
class ItemShovel extends ItemTool class ItemShovel extends ItemTool
{ {
public function isShovel(){ public function isShovel(){
return true; return true;
} }
} }

View file

@ -3,8 +3,8 @@
abstract class ItemSword extends ItemTool abstract class ItemSword extends ItemTool
{ {
public function isSword(){ public function isSword(){
return true; return true;
} }
} }

View file

@ -2,16 +2,16 @@
abstract class ItemTool extends Item abstract class ItemTool extends Item
{ {
public function isTool(){ public function isTool(){
return true; return true;
} }
public function useOn($object, $force = false){ public function useOn($object, $force = false){
if(($object instanceof Entity) and !$this->isSword()){ if(($object instanceof Entity) and !$this->isSword()){
$this->meta += 2; $this->meta += 2;
}else{ }else{
$this->meta++; $this->meta++;
} }
return true; return true;
} }
} }

View file

@ -29,7 +29,7 @@ class PaintingItem extends Item{
array("Flaming Skull", 4, 4), array("Flaming Skull", 4, 4),
); );
private static $direction = array(2, 0, 1, 3); 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){ 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){ 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++){ for($y = 0; $y <= $motive[2]; $y++){
if ($target->getSide(PaintingItem::$right[$face - 2], $x)->isTransparent || $target->getSide(1, $y)->isTransparent 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) { || $block->getSide(PaintingItem::$right[$face - 2], $x)->isSolid || $block->getSide(1, $y)->isSolid) {
$valid = false; $valid = false;
break; break;
} }
} }
if(!$valid){ if(!$valid){
break; break;
} }
} }
if ($valid) { if ($valid) {
$validMotives[] = $motive; $validMotives[] = $motive;
} }
} }
$motive = $validMotives[array_rand($validMotives)]; $motive = $validMotives[array_rand($validMotives)];
$data = array( $data = array(

View file

@ -2,7 +2,7 @@
class SignItem extends Item{ class SignItem extends Item{
public function __construct($meta = 0, $count = 1){ 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->block = BlockAPI::get(SIGN_POST);
$this->maxStackSize = 16; $this->maxStackSize = 16;
} }

View file

@ -8,18 +8,18 @@ class SpawnEggItem extends Item{
} }
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ 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; $ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG;
$data = array( $data = array(
"x" => $block->x + 0.5, "x" => $block->x + 0.5,
"y" => $block->y, "y" => $block->y,
"z" => $block->z + 0.5, "z" => $block->z + 0.5,
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0 "IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0
); );
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); $e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
ServerAPI::request()->api->entity->spawnToAll($e); ServerAPI::request()->api->entity->spawnToAll($e);
if(($player->gamemode & 0x01) === 0){ if(($player->gamemode & 0x01) === 0){
-- $this->count; -- $this->count;
} }
return true; return true;
} }
} }

View file

@ -6,6 +6,6 @@ class DiamondAxeItem extends ItemAxe{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 6; return 6;
} }
} }

View file

@ -6,6 +6,6 @@ class DiamondPickaxeItem extends ItemPickaxe{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 5; return 5;
} }
} }

View file

@ -5,6 +5,6 @@ class DiamondShovelItem extends ItemShovel{
parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel"); parent::__construct(DIAMOND_SHOVEL, $meta, $count, "Diamond Shovel");
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 4; return 4;
} }
} }

View file

@ -4,9 +4,9 @@ class DiamondSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){ public function __construct($meta = 0, $count = 1){
parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword"); parent::__construct(DIAMOND_SWORD, $meta, $count, "Diamond Sword");
} }
public function getDamageAgainstOf($e) public function getDamageAgainstOf($e)
{ {
return 7; return 7;
} }
} }

View file

@ -21,11 +21,11 @@ class FlintSteelItem extends ItemTool{
} }
public function useOn($object, $force = false){ public function useOn($object, $force = false){
if(($object instanceof Creeper) and $this->id === FLINT_STEEL){ if(($object instanceof Creeper) and $this->id === FLINT_STEEL){
$this->meta++; $this->meta++;
return true; return true;
}else{ }else{
return parent::useOn($object, $force); return parent::useOn($object, $force);
} }
} }
} }

View file

@ -5,6 +5,6 @@ class GoldenAxeItem extends ItemAxe{
parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe"); parent::__construct(GOLDEN_AXE, $meta, $count, "Golden Axe");
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 3; return 3;
} }
} }

View file

@ -6,6 +6,6 @@ class GoldenPickaxeItem extends ItemPickaxe{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 2; return 2;
} }
} }

View file

@ -4,9 +4,9 @@ class GoldenSwordItem extends ItemSword{
public function __construct($meta = 0, $count = 1){ public function __construct($meta = 0, $count = 1){
parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword"); parent::__construct(GOLDEN_SWORD, $meta, $count, "Golden Sword");
} }
public function getDamageAgainstOf($e) public function getDamageAgainstOf($e)
{ {
return 4; return 4;
} }
} }

View file

@ -6,6 +6,6 @@ class IronAxeItem extends ItemAxe{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 5; return 5;
} }
} }

View file

@ -5,6 +5,6 @@ class IronSwordItem extends ItemSword{
parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword"); parent::__construct(IRON_SWORD, $meta, $count, "Iron Sword");
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 6; return 6;
} }
} }

View file

@ -6,10 +6,10 @@ class ShearsItem extends ItemTool{
} }
public function useOn($object, $force = false){ public function useOn($object, $force = false){
if(($object instanceof Sheep) and $this->id === SHEARS){ if(($object instanceof Sheep) and $this->id === SHEARS){
$this->meta++; $this->meta++;
return true; return true;
} }
parent::useOn($object, $force); parent::useOn($object, $force);
} }
} }

View file

@ -4,9 +4,9 @@ class StoneShovelItem extends ItemShovel{
public function __construct($meta = 0, $count = 1){ public function __construct($meta = 0, $count = 1){
parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel"); parent::__construct(STONE_SHOVEL, $meta, $count, "Stone Shovel");
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 2; return 2;
} }
} }

View file

@ -6,6 +6,6 @@ class WoodenPickaxeItem extends ItemPickaxe{
} }
public function getDamageAgainstOf($e){ public function getDamageAgainstOf($e){
return 2; return 2;
} }
} }

View file

@ -180,7 +180,7 @@ class AxisAlignedBB{
return $z; return $z;
} }
public function intersectsWith(AxisAlignedBB $bb){ public function intersectsWith(AxisAlignedBB $bb){
if($bb->maxX > $this->minX and $bb->minX < $this->maxX){ if($bb->maxX > $this->minX and $bb->minX < $this->maxX){
if($bb->maxY > $this->minY and $bb->minY < $this->maxY){ if($bb->maxY > $this->minY and $bb->minY < $this->maxY){
@ -192,14 +192,14 @@ class AxisAlignedBB{
} }
public function isXYZInside($x, $y, $z){ public function isXYZInside($x, $y, $z){
if($x <= $this->minX or $x >= $this->maxX){ if($x <= $this->minX or $x >= $this->maxX){
return false; return false;
} }
if($y <= $this->minY or $y >= $this->maxY){ if($y <= $this->minY or $y >= $this->maxY){
return false; return false;
} }
return $z > $this->minZ and $z < $this->maxZ; return $z > $this->minZ and $z < $this->maxZ;
} }
public function isVectorInside(Vector3 $vector){ public function isVectorInside(Vector3 $vector){
if($vector->x <= $this->minX or $vector->x >= $this->maxX){ if($vector->x <= $this->minX or $vector->x >= $this->maxX){
@ -306,7 +306,7 @@ class AxisAlignedBB{
} }
public function __toString(){ 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