diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index 539ae018..3589361f 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -148,7 +148,7 @@ class ChatAPI{ } $message["player"] = ""; } - - $this->server->handle("server.chat", new Container($message, $whitelist, $blacklist)); + $container = new Container($message, $whitelist, $blacklist); + $this->server->handle("server.chat", $container); } } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index a3804b38..5f710b49 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -159,7 +159,7 @@ class ServerAPI{ $this->server->api = $this; self::$serverRequest = $this->server; $this->server->send2Discord("[INFO] Starting Minecraft PE server version ".CURRENT_MINECRAFT_VERSION); - console("[INFO] This server is running NostalgiaCore version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.")", true, true, 0); + console("[INFO] This server is running NostalgiaCore version ".($version->isDev() ? FORMAT_YELLOW:"").MAJOR_VERSION.FORMAT_RESET." \"".CODENAME."\" (MCPE: ".CURRENT_MINECRAFT_VERSION.") (API ".CURRENT_API_VERSION.") (PHP ".PHP_VERSION.")", true, true, 0); console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0); $this->loadProperties(); diff --git a/src/Player.php b/src/Player.php index ae4924a8..b8c5dd06 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1158,7 +1158,7 @@ class Player{ case ProtocolInfo::REQUEST_CHUNK_PACKET: case ProtocolInfo::ANIMATE_PACKET: case ProtocolInfo::SET_HEALTH_PACKET: - continue 2; + break; } } $this->received[$p->messageIndex] = true; @@ -1192,6 +1192,7 @@ class Player{ $cnt = $this->send($data); if(isset($this->chunkCount[$count])){ unset($this->chunkCount[$count]); + if(!is_null($cnt) and !is_null($cnt[0])) $this->chunkCount[$cnt[0]] = true; } } @@ -2508,4 +2509,4 @@ class PlayerNull extends Player{ public function __construct(){ } -} \ No newline at end of file +} diff --git a/src/dependencies.php b/src/dependencies.php index 9b9383a0..1388012e 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -97,6 +97,7 @@ require_once(FILE_PATH."/src/world/Position.php"); require_once(FILE_PATH."/src/pmf/PMF.php"); require_once(FILE_PATH."/src/entity/Entity.php"); require_once(FILE_PATH."/src/entity/Damageable.php"); +require_once(FILE_PATH."/src/entity/Breedable.php"); require_once(FILE_PATH."/src/entity/Living.php"); require_once(FILE_PATH."/src/entity/Creature.php"); require_once(FILE_PATH."/src/entity/Ageable.php"); diff --git a/src/entity/Animal.php b/src/entity/Animal.php index c6fc9641..063ceef9 100644 --- a/src/entity/Animal.php +++ b/src/entity/Animal.php @@ -3,7 +3,7 @@ TODO: move methods */ -class Animal extends Creature implements Ageable{ +abstract class Animal extends Creature implements Ageable, Breedable{ public function isBaby(){ return $this->data["IsBaby"]; } diff --git a/src/entity/Breedable.php b/src/entity/Breedable.php new file mode 100644 index 00000000..b6bd1467 --- /dev/null +++ b/src/entity/Breedable.php @@ -0,0 +1,5 @@ +schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg")); - $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:4, "generic"); + $this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic"); $this->update(); //$this->setName('Chicken'); $this->size = $this->isBaby() ? 0.35 : 0.7; } - + public function isFood($id){ + return $id === PUMPKIN_SEEDS || $id === MELON_SEEDS || $id === BEETROOT_SEEDS || $id === WHEAT_SEEDS; + } public function dropAnEgg(){ ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG,0,1)); $this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg")); diff --git a/src/entity/animal/Cow.php b/src/entity/animal/Cow.php index 15782589..08501949 100644 --- a/src/entity/animal/Cow.php +++ b/src/entity/animal/Cow.php @@ -9,7 +9,9 @@ class Cow extends Animal{ //$this->setName('Cow'); $this->size = $this->isBaby() ? 0.65 : 1.4; } - + public function isFood($id){ + return $id === WHEAT; + } public function getDrops(){ return $this->isBaby() ? array() : diff --git a/src/entity/animal/Pig.php b/src/entity/animal/Pig.php index 5d7c5088..19bcc6ee 100644 --- a/src/entity/animal/Pig.php +++ b/src/entity/animal/Pig.php @@ -8,7 +8,9 @@ class Pig extends Animal{ //$this->setName('Pig'); $this->size = $this->isBaby() ? 0.60 : 1.1875; } - + public function isFood($id){ + return $id === POTATO || $id === CARROT || $id === BEETROOT; + } public function getDrops(){ return $this->isBaby() ? array() : array( diff --git a/src/entity/animal/Sheep.php b/src/entity/animal/Sheep.php index a01b4e15..ae03247b 100644 --- a/src/entity/animal/Sheep.php +++ b/src/entity/animal/Sheep.php @@ -16,6 +16,11 @@ class Sheep extends Animal{ array(WOOL, $this->data["Color"] & 0x0F, 1), ); } + + public function isFood($id){ + return $id === WHEAT; + } + public function getMetadata(){ $d = parent::getMetadata(); if(!isset($this->data["Sheared"])){ diff --git a/src/network/RCON.php b/src/network/RCON.php index 4d0123c5..c88a6223 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -168,21 +168,21 @@ class RCONInstance extends Thread{ if($this->{"status".$n} !== -1 and $this->stop !== true){ if($this->{"status".$n} === 0 and $this->{"timeout".$n} < microtime(true)){ //Timeout $this->{"status".$n} = -1; - continue 2; + break; } $p = $this->readPacket($client, $size, $requestID, $packetType, $payload); if($p === false){ $this->{"status".$n} = -1; - continue 2; + break; }elseif($p === null){ - continue 2; + break; } switch($packetType){ case 3: //Login if($this->{"status".$n} !== 0){ $this->{"status".$n} = -1; - continue 2; + break; } if($payload === $this->password){ @socket_getpeername($client, $addr, $port); @@ -194,13 +194,13 @@ class RCONInstance extends Thread{ }else{ $this->{"status".$n} = -1; $this->writePacket($client, -1, 2, ""); - continue 2; + break; } break; case 2: //Command if($this->{"status".$n} !== 1){ $this->{"status".$n} = -1; - continue 2; + break; } if(strlen($payload) > 0){ $this->cmd = ltrim($payload); diff --git a/src/pmf/Level.php b/src/pmf/Level.php index a78e31f6..53189ac7 100644 --- a/src/pmf/Level.php +++ b/src/pmf/Level.php @@ -420,6 +420,7 @@ class PMFLevel extends PMF{ $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $aY = $y - ($Y << 4); + #Need to fix. But idk how. $b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]); $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]); if(($y & 1) === 0){ diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 83cebcc1..1de9fd35 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -602,10 +602,10 @@ class Utils{ public static function writeLong($value){ $x = ""; - if($value[0] === "-"){ + if(strval($value[0]) === "-"){ $negative = true; $value = bcadd($value, "1"); - if($value[0] === "-"){ + if(strval($value[0]) === "-"){ $value = substr($value, 1); } }else{ diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 9a050773..e785654b 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -56,8 +56,11 @@ class Explosion{ $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); $server->api->entity->spawnToAll($e); }elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){ - foreach($block->getDrops($this->air, $this->nullPlayer) as $drop){ - $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count + $tmp = $block->getDrops($this->air, $this->nullPlayer); + if(is_array($tmp)){ + foreach($tmp as $drop){ + $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count + } } } $this->level->level->setBlockID($block->x, $block->y, $block->z, 0); diff --git a/src/world/generator/object/NetherReactorStructure.php b/src/world/generator/object/NetherReactorStructure.php index 7174c4ae..031a905c 100644 --- a/src/world/generator/object/NetherReactorStructure.php +++ b/src/world/generator/object/NetherReactorStructure.php @@ -603,7 +603,7 @@ class NetherReactorStructure{ case " ": $block = $level->getBlock(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ))->getID(); if($block == 0){ - continue 2; + break; } $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ), new AirBlock()); break;