From 5349f16464d6093ab75061fa8e38e3cd9fb169ac Mon Sep 17 00:00:00 2001 From: RainBowSheepx Date: Fri, 17 Jun 2022 19:03:50 +0300 Subject: [PATCH 1/9] Fix TNT --- src/world/Explosion.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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); From 7ec27bfb046151c8fe15351fb705b09c666477d1 Mon Sep 17 00:00:00 2001 From: RainBowSheepx Date: Fri, 17 Jun 2022 19:45:40 +0300 Subject: [PATCH 2/9] Chat fixed, Negative fixed --- src/API/ChatAPI.php | 4 ++-- src/Player.php | 1 + src/pmf/Level.php | 1 + src/utils/Utils.php | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) 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/Player.php b/src/Player.php index 8af5a81b..af908761 100755 --- a/src/Player.php +++ b/src/Player.php @@ -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; } } 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..fde308f8 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{ From d7bfd96739ae9f4bf3a55c7a5002a2a5270baaf9 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Fri, 17 Jun 2022 19:49:36 +0300 Subject: [PATCH 3/9] early breeding classes, it still doesnt work although it might be implemented later --- src/dependencies.php | 1 + src/entity/Animal.php | 2 +- src/entity/Breedable.php | 5 +++++ src/entity/animal/Chicken.php | 6 ++++-- src/entity/animal/Cow.php | 4 +++- src/entity/animal/Pig.php | 4 +++- src/entity/animal/Sheep.php | 5 +++++ 7 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 src/entity/Breedable.php 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"])){ From e6bce73cc56219cdd9126c303ce85c31c39dc874 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Sun, 19 Jun 2022 23:54:17 +0300 Subject: [PATCH 4/9] Update Utils.php --- src/utils/Utils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/Utils.php b/src/utils/Utils.php index fde308f8..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(strval($value)[0] === "-"){ + if(strval($value[0]) === "-"){ $negative = true; $value = bcadd($value, "1"); - if(strval($value)[0] === "-"){ + if(strval($value[0]) === "-"){ $value = substr($value, 1); } }else{ From 2a1e8b9d2c703498d83b18813e04af1eb061d3e0 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:07:03 +0300 Subject: [PATCH 5/9] Update Player.php --- src/Player.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Player.php b/src/Player.php index af908761..aeb3cec7 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; @@ -2508,4 +2508,4 @@ class PlayerNull extends Player{ public function __construct(){ } -} \ No newline at end of file +} From 50756dc53aad4101db49149764e2766e44df6b77 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:09:17 +0300 Subject: [PATCH 6/9] Update RCON.php --- src/network/RCON.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/RCON.php b/src/network/RCON.php index 4d0123c5..74c3253d 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -168,14 +168,14 @@ 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; }elseif($p === null){ - continue 2; + break; } switch($packetType){ @@ -200,7 +200,7 @@ class RCONInstance extends Thread{ case 2: //Command if($this->{"status".$n} !== 1){ $this->{"status".$n} = -1; - continue 2; + break; } if(strlen($payload) > 0){ $this->cmd = ltrim($payload); From b99daa20c84156b98655251aa8dd31f3e9d456b8 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:12:12 +0300 Subject: [PATCH 7/9] Update RCON.php --- src/network/RCON.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/RCON.php b/src/network/RCON.php index 74c3253d..c88a6223 100644 --- a/src/network/RCON.php +++ b/src/network/RCON.php @@ -173,7 +173,7 @@ class RCONInstance extends Thread{ $p = $this->readPacket($client, $size, $requestID, $packetType, $payload); if($p === false){ $this->{"status".$n} = -1; - continue 2; + break; }elseif($p === null){ break; } @@ -182,7 +182,7 @@ class RCONInstance extends Thread{ 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,7 +194,7 @@ class RCONInstance extends Thread{ }else{ $this->{"status".$n} = -1; $this->writePacket($client, -1, 2, ""); - continue 2; + break; } break; case 2: //Command From 1193932ab3563bbdf626855ba6150687a00aefc1 Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Mon, 20 Jun 2022 00:12:59 +0300 Subject: [PATCH 8/9] Update NetherReactorStructure.php --- src/world/generator/object/NetherReactorStructure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From be6edb1948180875a34ef81ebaf94cb0bacc43bf Mon Sep 17 00:00:00 2001 From: RainBowSheepx Date: Mon, 20 Jun 2022 14:04:59 +0300 Subject: [PATCH 9/9] Show PHP version --- src/API/ServerAPI.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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();