This commit is contained in:
GameHerobrine 2023-12-19 22:34:04 +03:00
parent 6d430c3440
commit b84093e4ce
25 changed files with 48 additions and 163 deletions

View file

@ -35,7 +35,6 @@ class ServerAPI{
*/
public $entity;
//TODO: Instead of hard-coding functions, use PHPDoc-compatible methods to load APIs.
/**
* @var TimeAPI
*/
@ -104,7 +103,6 @@ class ServerAPI{
}
}
$version = new VersionString();
console("[INFO] Starting Minecraft PE server version " . FORMAT_AQUA . CURRENT_MINECRAFT_VERSION);
console("[INFO] Loading properties...");
@ -161,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 . ") (PHP " . PHP_VERSION . ")", true, true, 0);
console("[INFO] This server is running NostalgiaCore version " . 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

@ -2234,7 +2234,7 @@ class Player{
$tile->setSlot($packet->slot, $item);
}
break;
case ProtocolInfo::SEND_INVENTORY_PACKET: //TODO, Mojang, enable this ´^_^`
case ProtocolInfo::SEND_INVENTORY_PACKET:
if($this->spawned === false){
break;
}
@ -2283,7 +2283,7 @@ class Player{
$this->entity->linkedEntity->sendMoveUpdate();
}
break; //TODO player input-
break;
default:
console("[DEBUG] Unhandled 0x" . dechex($packet->pid()) . " data packet for " . $this->username . " (" . $this->clientID . "): " . print_r($packet, true), true, true, 2);
break;

View file

@ -29,8 +29,6 @@ class PocketMinecraftServer{
private function load(){
global $dolog;
$this->version = new VersionString();
/*if(defined("DEBUG") and DEBUG >= 0){
@cli_set_process_title("NostalgiaCore ".MAJOR_VERSION);
}*/

View file

@ -7,7 +7,6 @@ if(ini_get("date.timezone") == ""){ //No Timezone set
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
$time = time();
$time -= $time % 60;
//TODO: Parse different time & date formats by region. ¬¬ world
//Example: USA
exec("time.exe /T", $hour);
$i = array_map("intval", explode(":", trim($hour[0])));

View file

@ -1,8 +1,5 @@
<?php
/*
TODO:
move methods
*/
abstract class Animal extends Creature implements Ageable, Breedable{
public $parent;
@ -104,11 +101,11 @@ abstract class Animal extends Creature implements Ageable, Breedable{
public function interactWith(Entity $e, $action){
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
$slot = $e->player->getHeldItem();
if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby()){ //TODO check vanilla
if($this->isFood($slot->getID()) && $this->inLove <= 0 && !$this->isBaby()){
if(($e->player->gamemode & 0x01) === SURVIVAL){
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
}
$this->inLove = 600; //600 ticks, original mehod from mcpe
$this->inLove = 600;
return true;
}
}

View file

@ -1,8 +1,5 @@
<?php
/*
TODO:
move methods
*/
abstract class Creature extends Living{
const CLASS_TYPE = ENTITY_MOB;

View file

@ -154,21 +154,19 @@ class Entity extends Position
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
$this->setHealth(1, "generic");
$this->stepHeight = false;
// $this->setName((isset($objects[$this->type]) ? $objects[$this->type]:$this->type));
$this->width = 1;
$this->height = 1;
if($this->type === OBJECT_SNOWBALL){
$this->server->schedule(1210, array(
$this,
"update"
)); // Despawn
// $this->update();
));
}
break;
}
$this->radius = $this->width / 2;
$this->boundingBox = new AxisAlignedBB($this->x - $this->radius, $this->y, $this->z - $this->radius, $this->x + $this->radius, $this->y + $this->height, $this->z + $this->radius);
//$this->update();
$this->updateLast();
$this->updatePosition();
if($this->isInVoid()){
@ -281,24 +279,6 @@ class Entity extends Position
return $this->width;
}
public function lookOn(Vector3 $target)
{
$horizontal = sqrt(pow(($target->x - $this->x), 2) + pow(($target->z - $this->z), 2));
$vertical = $target->y - ($this->y + - 0.5); /* 0.5 = $entity->getEyeHeight() */
$pitch = - asin($horizontal) / M_PI * 180; // negative is up, positive is down
$xDist = $target->x - $this->x;
$zDist = $target->z - $this->z;
$yaw = atan2($zDist, $xDist) / M_PI * 180 - 90;
if($yaw < 0){
$yaw += 360.0;
}
$this->yaw = $yaw;
$this->pitch = $pitch;
$this->server->query("UPDATE entities SET pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";");
}
public function getDrops()
{
if($this->class === ENTITY_PLAYER and $this->player instanceof Player and ($this->player->gamemode & 0x01) === 0){
@ -407,8 +387,7 @@ class Entity extends Position
$endX = ceil($this->boundingBox->maxX);
$endY = ceil($this->boundingBox->maxY);
$endZ = ceil($this->boundingBox->maxZ);
$waterDone = false;
//$bup = new AxisAlignedBB($startX, $startY + 1, $startZ, $endX, $endY, $endZ);
if(!($this instanceof Painting) && !($this->isPlayer() && $this->player->isSleeping !== false)){ //TODO better way to fix
for($i = 0; $i < 8; ++$i){
$x = ((($i >> 0) % 2) - 0.5) * $this->width * 0.8;
@ -597,7 +576,7 @@ class Entity extends Position
$this->fallDistance = 0;
}
if($b != 0){
$blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this); //StaticBlock::getBoundingBoxForBlockCoords($b, $x, $y, $z);
$blockBounds = Block::$class[$b]::getCollisionBoundingBoxes($this->level, $x, $y, $z, $this);
foreach($blockBounds as $blockBound){
$this->speedY = $blockBound->calculateYOffset($this->boundingBox, $this->speedY);
$this->speedX = $blockBound->calculateXOffset($this->boundingBox, $this->speedX);
@ -640,12 +619,6 @@ class Entity extends Position
}
$this->boundingBox->offset(0, 0, $this->speedZ);
//$this->speedY = -$this->stepHeight;
//foreach($aaBBs as $bb){ //TODO optimize
// $this->speedY = $bb->calculateYOffset($this->boundingBox, $this->speedY);
//}
//$this->boundingBox->offset(0, $this->speedY, 0);
if ($cx*$cx + $cz*$cz >= $this->speedX*$this->speedX + $this->speedZ*$this->speedZ)
{
$this->speedX = $cx;
@ -702,9 +675,6 @@ class Entity extends Position
if($this->lastX != $this->x || $this->lastZ != $this->z || $this->lastY != $this->z){
// $this->speedX = 0;
// $this->speedY = 0;
// $this->speedZ = 0;
$this->server->api->handle("entity.move", $this);
$update = true;
}elseif ($this->lastYaw != $this->yaw || $this->lastPitch != $this->pitch || $this->lastHeadYaw != $this->headYaw) {
@ -748,13 +718,11 @@ class Entity extends Position
$this->fallStart = $this->y;
}
if(!$this->onGround && ($prevGroundState /*|| $this->y > $this->fallStart*/)){
if(!$this->onGround && $prevGroundState){
$this->fallStart = $this->y;
}
//if($prevGroundState != $this->onGround){
// $this->player->sendChat("I am now" . ($this->onGround ? 'on Ground' : 'not on Ground')." and fd: ".$this->fallDistance);
//}
$this->updateFallState(Utils::getSign($this->speedY)*0.1);
$this->updateFallState(($this->speedY <=> 0)*0.1);
if($this->onGround) $this->fallDistance = 0;
$hasUpdate = true;
}
@ -763,9 +731,6 @@ class Entity extends Position
$this->counterUpdate();
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
if($this->isPlayer() || $update){
$this->updateMovement();
}
@ -829,8 +794,6 @@ class Entity extends Position
if($this->server->api->handle("entity.move", $this) === false){
if($this->class === ENTITY_PLAYER){
$this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
} else{
//TODO fix $this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
}
} else{
$players = $this->server->api->player->getAll($this->level);
@ -1157,17 +1120,9 @@ class Entity extends Position
{
$this->server->query("UPDATE entities SET level = '" . $this->level->getName() . "', x = " . $this->x . ", y = " . $this->y . ", z = " . $this->z . ", pitch = " . $this->pitch . ", yaw = " . $this->yaw . " WHERE EID = " . $this->eid . ";");
$this->sendMoveUpdate();
// $this->sendMotion();
$this->updateAABB();
}
public function sendHeadYaw(){
/*$pk = new RotateHeadPacket;
$pk->eid = $this->eid;
$pk->yaw = $this->headYaw;
$this->server->api->player->broadcastPacket($this->level->players, $pk);*/
}
public function setPosition(Vector3 $pos, $yaw = false, $pitch = false)
{
if($pos instanceof Position and $pos->level instanceof Level and $this->level !== $pos->level){
@ -1306,7 +1261,6 @@ class Entity extends Position
$this->last[3] = $this->yaw;
$this->last[4] = $this->pitch;
$this->last[5] = microtime(true);
//$this->lastHeadYaw = $this->headYaw;
}
public function getPosition($round = false)
@ -1328,10 +1282,9 @@ class Entity extends Position
for ($d1 = $entity->z - $this->z; $d * $d + $d1 * $d1 < 0.0001; $d1 = (lcg_value() - lcg_value()) * 0.01) {
$d = (lcg_value() - lcg_value()) * 0.01;
}
// attackedAtYaw = (float)((Math.atan2($d1, $d) * 180D) / 3.1415927410125732D) >
$this->knockBack($d, $d1);
$this->knockbackTime = 10;
$this->sendMotion();
}
@ -1355,23 +1308,11 @@ class Entity extends Position
return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause);
}
public function sendMotion()
{
/*$pk = new SetEntityMotionPacket();
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$this->server->api->player->broadcastPacket($this->level->players, $pk);*/
}
public function linkEntity(Entity $e, $type)
{
//if($e->isPlayer()){
$this->linkedEntity = $e;
$e->linkedEntity = $this;
$this->server->api->dhandle("entity.link", ["rider" => $e->eid, "riding" => $this->eid, "type" => 0]);
//}
}
public function isPlayer()
@ -1543,7 +1484,6 @@ class Entity extends Position
if($this->speedY > 0.4){
$this->speedY = 0.4;
}
//$this->speedY /= 2;
}
public function getHealth()

View file

@ -42,7 +42,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
return true;
}
public function collideHandler(){
$this->level->applyCallbackToNearbyEntities($this, [$this, "applyCollision"], 2); //TODO radiuses
}
public function applyCollision(Entity $collided){

View file

@ -23,7 +23,7 @@ class TaskDestroyServerPerformance extends TaskTempt
if(Utils::distance_noroot($this->target, $ai->entity) > 100){
$ai->mobController->moveTo($this->target->x, floor($ai->entity->y), $this->target->z, false);
}else{
//TODO move away
}
$ai->mobController->lookOn($this->target);

View file

@ -29,7 +29,7 @@ class TaskTempt extends TaskBase
public function canBeExecuted(EntityAI $ai)
{
if(!($ai->entity instanceof Breedable) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){ //TODO Work with path
if(!($ai->entity instanceof Breedable) || $ai->entity->inPanic || $ai->isStarted("TaskMate")){
return false;
}
$target = $this->findTarget($ai->entity, 10);

View file

@ -15,7 +15,7 @@ class Creeper extends Monster{
}
public function getAttackDamage(){
return 0; //TODO special attack
return 0;
}
public function setIgnited($v = null){

View file

@ -26,7 +26,7 @@ class LiquidBlock extends TransparentBlock{
return array();
}
public function getLiquidHeight(){ //TODO lava,water meta
public function getLiquidHeight(){
return (($this->meta >= 8 ? 0 : $this->meta)+1) / 9;
}
}

View file

@ -58,12 +58,11 @@ class NetherReactorBlock extends SolidBlock{
}
private function decay($x, $y, $z, $aOne, $aTwo, $aThree, $bOne, $bTwo, $bThree, $cOne, $cTwo, $cThree) {
for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are? TODO simplify if possible(makes server lag)
for($a = $aOne; $a < $aTwo; $a += $aThree) {
for($b = $bOne; $b < $bTwo; $b += $bThree) {
for($c = $cOne; $c < $cTwo; $c += $cThree) {
if ($this->level->level->getBlockID($x+$a, $y+$b, $z+$c) === NETHERRACK && lcg_value() > 0.75){
//$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock());
$this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0); //TODO might be better to set not directly?
$this->level->fastSetBlockUpdate($x+$a, $y+$b, $z+$c, 0, 0);
}
}
}
@ -192,7 +191,7 @@ class NetherReactorBlock extends SolidBlock{
$b = $this->level->level->getBlockID($x + $offsetX, $y + $yOffset, $z + $offsetZ);
switch($char){
case "G":
if($b === GOLD_BLOCK){ //TODO make it use structure class
if($b === GOLD_BLOCK){
break;
}
return false;

View file

@ -1,19 +1,21 @@
<?php
class SlabBlock extends TransparentBlock{
public static $NAMES = [
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
3 => "Cobblestone",
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
7 => "",
];
public function __construct($meta = 0){
parent::__construct(SLAB, $meta, "Slab");
$names = array( //TODO make it static
0 => "Stone",
1 => "Sandstone",
2 => "Wooden",
3 => "Cobblestone",
4 => "Brick",
5 => "Stone Brick",
6 => "Quartz",
7 => "",
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Slab";
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . self::$NAMES[$this->meta & 0x07] . " Slab";
if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true;
}else{

View file

@ -68,7 +68,7 @@ class PaintingItem extends Item{
$validMotives[] = $motive;
}
}
$motive = $validMotives[array_rand($validMotives)]; //TODO simplify if possible
$motive = $validMotives[array_rand($validMotives)];
$data = array(
"x" => $target->x,
"y" => $target->y,

View file

@ -9,7 +9,7 @@ class FlintSteelItem extends ItemTool{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($player->gamemode & 0x01) === 0 and $this->useOn($block) and $this->getMetadata() >= $this->getMaxDurability()){
$player->setSlot($player->slot, new Item(AIR, 0, 0), false); //TODO check
$player->setSlot($player->slot, new Item(AIR, 0, 0), false);
}
if($block->getID() === AIR and ($target instanceof SolidBlock)){
$level->setBlock($block, new FireBlock(), true, false, true);

View file

@ -1,20 +0,0 @@
<?php
class Vector3Pos extends Vector3
{
public $x, $y, $z;
public function __construct(&$x, &$y, &$z){
$this->x = &$x;
$this->y = &$y;
$this->z = &$z;
}
public function addToValues($v){
$this->x += $v->x;
$this->y += $v->y;
$this->z += $v->z;
return $this;
}
}

View file

@ -518,7 +518,7 @@ class PMFLevel extends PMF{
}
public function doSaveRound(){
foreach($this->chunks as $index => $chunk){ //TODO fix variables($X, $Z are undefined)
foreach($this->chunks as $index => $chunk){
$this->getXZ($index, $X, $Z);
$this->saveChunk($X, $Z);
}

View file

@ -47,7 +47,7 @@ class RailLogic
if($logic != null && $this->connectsTo($logic)){
$this->railPositions[$ind] = new Vector3($logic->x, $logic->y, $logic->z);
}else{
unset($this->railPositions[$ind--]); //TODO check?
unset($this->railPositions[$ind--]);
$this->railPositions = array_values($this->railPositions); //reindexing
}
}
@ -63,7 +63,6 @@ class RailLogic
}
public function canConnectTo(RailLogic $rail){
//return this.isRailChunkPositionCorrect(par1BlockBaseRailLogic) ? true : (this.railChunkPosition.size() == 2 ? false : (this.railChunkPosition.isEmpty() ? true : true));
return $this->connectsTo($rail) ? true : (count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true));
}

View file

@ -73,7 +73,7 @@ class Utils{
return $angle < 0 ? $angle + 360 : $angle - 180;
}
public static function getSign($v){
return $v > 0 ? 1 : ($v < 0 ? -1 : 0);
return $v <=> 0;
}
public static function clampDegrees($v){

View file

@ -1,18 +0,0 @@
<?php
//TODO remove at all
class VersionString{
private $development = false;
public function __construct($version = MAJOR_VERSION){
$this->development = Utils::endsWith($version, "dev");
}
public function isDev(){
return $this->development === true;
}
public function __toString(){
return MAJOR_VERSION;
}
}

View file

@ -25,7 +25,7 @@ class MobSpawner{
$phase = $this->server->api->time->getPhase($this->level);
if(self::$spawnAnimals && ($phase == "day" || $phase == "sunrise")){ //Animal
$type = mt_rand(10, 13);
$baby = false; //TODO baby
$baby = false;
$grassOnly = true;
}elseif(self::$spawnMobs && ($phase == "night" || $phase == "sunset")){ //Monster, true night
$type = mt_rand(32, 35);

View file

@ -32,12 +32,9 @@ class NoiseGeneratorPerlin extends NoiseGenerator{
$d3 = $d + $this->xCoord;
$d4 = $d1 + $this->yCoord;
$d5 = $d2 + $this->zCoord;
$i = (int) $d3;
$j = (int) $d4;
$k = (int) $d5;
if($d3 < $i) --$i;
if($d4 < $j) --$j;
if($d5 < $k) --$k;
$i = floor($d3);
$j = floor($d4);
$k = floor($d5);
$l = $i & 0xff;
$i1 = $j & 0xff;
$j1 = $k & 0xff;

View file

@ -98,13 +98,11 @@ class VanillaGenerator implements LevelGenerator
for($i8 = 0; $i8 < 8; ++$i8){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), REDSTONE_ORE, 7);
}
//for($i9 = 0; $i9 < 1; ++$i9){ //TODO loop is not neccessary
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), DIAMOND_ORE, 7);
//}
//for($i10 = 0; $i10 < 1; ++$i10){
OreFeature::place($this->level, $this->rand, $chunkXWorld + $this->rand->nextInt(16), $this->rand->nextInt(16) + $this->rand->nextInt(16), $chunkZWorld + $this->rand->nextInt(16), LAPIS_ORE, 6);
//}
//sample= (int) ((((this.treeNoise.getValue(chunkXWorld * 0.5f, chunkZWorld * 0.5f) / 8.0f) + (this.rand.nextFloat() * 4.0f)) + 4.0f) / 3.0f);
$sample = (int) (((($this->treeNoise->getValue($chunkXWorld * 0.5, $chunkZWorld * 0.5) / 8) + ($this->rand->nextFloat() * 4)) + 4) / 3);
$treesAmount = $this->rand->nextInt(10) == 0;
if($biome == Biome::$forest) $treesAmount += $sample + 2;
@ -166,7 +164,6 @@ class VanillaGenerator implements LevelGenerator
}
$this->level->level->chunkChange[$index][-1] = true;
//console($this->level->level->getBlockID($chunkX*16, 20, $chunkZ*16));
}
public function populateLevel()