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"] = "";
}
$this->server->handle("server.chat", new Container($message, $whitelist, $blacklist));
$container = new Container($message, $whitelist, $blacklist);
$this->server->handle("server.chat", $container);
}
}

View file

@ -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();

View file

@ -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(){
}
}
}

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/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");

View file

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

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);
$server = ServerAPI::request();
$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->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"));

View file

@ -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() :

View file

@ -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(

View file

@ -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"])){

View file

@ -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);

View file

@ -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){

View file

@ -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{

View file

@ -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);

View file

@ -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;