This commit is contained in:
ArkQuark 2022-06-21 16:32:42 +03:00
commit a810d5aeae
15 changed files with 43 additions and 21 deletions

View file

@ -148,7 +148,7 @@ class ChatAPI{
} }
$message["player"] = ""; $message["player"] = "";
} }
$container = new Container($message, $whitelist, $blacklist);
$this->server->handle("server.chat", new Container($message, $whitelist, $blacklist)); $this->server->handle("server.chat", $container);
} }
} }

View file

@ -159,7 +159,7 @@ class ServerAPI{
$this->server->api = $this; $this->server->api = $this;
self::$serverRequest = $this->server; self::$serverRequest = $this->server;
$this->server->send2Discord("[INFO] Starting Minecraft PE server version ".CURRENT_MINECRAFT_VERSION); $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); console("[INFO] NostalgiaCore is distributed under the LGPL License", true, true, 0);
$this->loadProperties(); $this->loadProperties();

View file

@ -1158,7 +1158,7 @@ class Player{
case ProtocolInfo::REQUEST_CHUNK_PACKET: case ProtocolInfo::REQUEST_CHUNK_PACKET:
case ProtocolInfo::ANIMATE_PACKET: case ProtocolInfo::ANIMATE_PACKET:
case ProtocolInfo::SET_HEALTH_PACKET: case ProtocolInfo::SET_HEALTH_PACKET:
continue 2; break;
} }
} }
$this->received[$p->messageIndex] = true; $this->received[$p->messageIndex] = true;
@ -1192,6 +1192,7 @@ class Player{
$cnt = $this->send($data); $cnt = $this->send($data);
if(isset($this->chunkCount[$count])){ if(isset($this->chunkCount[$count])){
unset($this->chunkCount[$count]); unset($this->chunkCount[$count]);
if(!is_null($cnt) and !is_null($cnt[0]))
$this->chunkCount[$cnt[0]] = true; $this->chunkCount[$cnt[0]] = true;
} }
} }

View file

@ -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/pmf/PMF.php");
require_once(FILE_PATH."/src/entity/Entity.php"); require_once(FILE_PATH."/src/entity/Entity.php");
require_once(FILE_PATH."/src/entity/Damageable.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/Living.php");
require_once(FILE_PATH."/src/entity/Creature.php"); require_once(FILE_PATH."/src/entity/Creature.php");
require_once(FILE_PATH."/src/entity/Ageable.php"); require_once(FILE_PATH."/src/entity/Ageable.php");

View file

@ -3,7 +3,7 @@
TODO: TODO:
move methods move methods
*/ */
class Animal extends Creature implements Ageable{ abstract class Animal extends Creature implements Ageable, Breedable{
public function isBaby(){ public function isBaby(){
return $this->data["IsBaby"]; return $this->data["IsBaby"];
} }

5
src/entity/Breedable.php Normal file
View file

@ -0,0 +1,5 @@
<?php
interface Breedable{
public function isFood($id); //original name
}

View file

@ -6,12 +6,14 @@ class Chicken extends Animal{
parent::__construct($level, $eid, $class, $type, $data); parent::__construct($level, $eid, $class, $type, $data);
$server = ServerAPI::request(); $server = ServerAPI::request();
$server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg")); $server->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->update();
//$this->setName('Chicken'); //$this->setName('Chicken');
$this->size = $this->isBaby() ? 0.35 : 0.7; $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(){ 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)); 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")); $this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));

View file

@ -9,7 +9,9 @@ class Cow extends Animal{
//$this->setName('Cow'); //$this->setName('Cow');
$this->size = $this->isBaby() ? 0.65 : 1.4; $this->size = $this->isBaby() ? 0.65 : 1.4;
} }
public function isFood($id){
return $id === WHEAT;
}
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? array() : return $this->isBaby() ? array() :

View file

@ -8,7 +8,9 @@ class Pig extends Animal{
//$this->setName('Pig'); //$this->setName('Pig');
$this->size = $this->isBaby() ? 0.60 : 1.1875; $this->size = $this->isBaby() ? 0.60 : 1.1875;
} }
public function isFood($id){
return $id === POTATO || $id === CARROT || $id === BEETROOT;
}
public function getDrops(){ public function getDrops(){
return $this->isBaby() ? array() : return $this->isBaby() ? array() :
array( array(

View file

@ -16,6 +16,11 @@ class Sheep extends Animal{
array(WOOL, $this->data["Color"] & 0x0F, 1), array(WOOL, $this->data["Color"] & 0x0F, 1),
); );
} }
public function isFood($id){
return $id === WHEAT;
}
public function getMetadata(){ public function getMetadata(){
$d = parent::getMetadata(); $d = parent::getMetadata();
if(!isset($this->data["Sheared"])){ if(!isset($this->data["Sheared"])){

View file

@ -168,21 +168,21 @@ class RCONInstance extends Thread{
if($this->{"status".$n} !== -1 and $this->stop !== true){ if($this->{"status".$n} !== -1 and $this->stop !== true){
if($this->{"status".$n} === 0 and $this->{"timeout".$n} < microtime(true)){ //Timeout if($this->{"status".$n} === 0 and $this->{"timeout".$n} < microtime(true)){ //Timeout
$this->{"status".$n} = -1; $this->{"status".$n} = -1;
continue 2; break;
} }
$p = $this->readPacket($client, $size, $requestID, $packetType, $payload); $p = $this->readPacket($client, $size, $requestID, $packetType, $payload);
if($p === false){ if($p === false){
$this->{"status".$n} = -1; $this->{"status".$n} = -1;
continue 2; break;
}elseif($p === null){ }elseif($p === null){
continue 2; break;
} }
switch($packetType){ switch($packetType){
case 3: //Login case 3: //Login
if($this->{"status".$n} !== 0){ if($this->{"status".$n} !== 0){
$this->{"status".$n} = -1; $this->{"status".$n} = -1;
continue 2; break;
} }
if($payload === $this->password){ if($payload === $this->password){
@socket_getpeername($client, $addr, $port); @socket_getpeername($client, $addr, $port);
@ -194,13 +194,13 @@ class RCONInstance extends Thread{
}else{ }else{
$this->{"status".$n} = -1; $this->{"status".$n} = -1;
$this->writePacket($client, -1, 2, ""); $this->writePacket($client, -1, 2, "");
continue 2; break;
} }
break; break;
case 2: //Command case 2: //Command
if($this->{"status".$n} !== 1){ if($this->{"status".$n} !== 1){
$this->{"status".$n} = -1; $this->{"status".$n} = -1;
continue 2; break;
} }
if(strlen($payload) > 0){ if(strlen($payload) > 0){
$this->cmd = ltrim($payload); $this->cmd = ltrim($payload);

View file

@ -420,6 +420,7 @@ class PMFLevel extends PMF{
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$aY = $y - ($Y << 4); $aY = $y - ($Y << 4);
#Need to fix. But idk how.
$b = ord($this->chunks[$index][$Y][(int) ($aY + ($aX << 5) + ($aZ << 9))]); $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))]); $m = ord($this->chunks[$index][$Y][(int) (($aY >> 1) + 16 + ($aX << 5) + ($aZ << 9))]);
if(($y & 1) === 0){ if(($y & 1) === 0){

View file

@ -602,10 +602,10 @@ class Utils{
public static function writeLong($value){ public static function writeLong($value){
$x = ""; $x = "";
if($value[0] === "-"){ if(strval($value[0]) === "-"){
$negative = true; $negative = true;
$value = bcadd($value, "1"); $value = bcadd($value, "1");
if($value[0] === "-"){ if(strval($value[0]) === "-"){
$value = substr($value, 1); $value = substr($value, 1);
} }
}else{ }else{

View file

@ -56,10 +56,13 @@ class Explosion{
$e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
$server->api->entity->spawnToAll($e); $server->api->entity->spawnToAll($e);
}elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){ }elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){
foreach($block->getDrops($this->air, $this->nullPlayer) as $drop){ $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 $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); $this->level->level->setBlockID($block->x, $block->y, $block->z, 0);
$send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z);
return $send; return $send;

View file

@ -603,7 +603,7 @@ class NetherReactorStructure{
case " ": case " ":
$block = $level->getBlock(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ))->getID(); $block = $level->getBlock(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ))->getID();
if($block == 0){ if($block == 0){
continue 2; break;
} }
$level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ), new AirBlock()); $level->setBlockRaw(new Vector3($x - 8 + $offsetX, $y - 1 + $layerCount, $z - 8 + $offsetZ), new AirBlock());
break; break;