better drop, added new setting from nc0.10

This commit is contained in:
GameHerobrine 2023-12-16 10:11:48 +03:00
parent e8528755ab
commit 7eec621f90
7 changed files with 63 additions and 65 deletions

View file

@ -138,7 +138,8 @@ class ServerAPI{
"enable-rcon" => false,
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
"auto-save" => true,
"chunk-send-delay-ticks" => 5,
"chunk-send-delay-ticks" => PocketMinecraftServer::$chukSendDelay,
"chunk-loading-radius" => PocketMinecraftServer::$chunkLoadingRadius,
]);
Biome::init();
$this->parseProperties();
@ -154,6 +155,12 @@ class ServerAPI{
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
PocketMinecraftServer::$chukSendDelay = $this->getProperty("chunk-send-delay-ticks");
PocketMinecraftServer::$chunkLoadingRadius = $this->getProperty("chunk-loading-radius");
if(PocketMinecraftServer::$chunkLoadingRadius < 4){
ConsoleAPI::warn("Players may not be able to join if chunk loading radius is less than 4!");
}
if($this->getProperty("upnp-forwarding") == true){
console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("server-port"));

View file

@ -449,34 +449,20 @@ class Player{
$this->prevChunkX = $X;
$this->prevChunkZ = $Z;
$this->chunksOrder = [];
//if($this->level->generatorType != 0) $chunkToUnload = $this->chunksLoaded;
$startX = $this->level->generatorType === 1 ? $X - 4 : 0;
$stopX = $this->level->generatorType === 1 ? $X + 4 : 15;
$startZ = $this->level->generatorType === 1 ? $Z - 4 : 0;
$stopZ = $this->level->generatorType === 1 ? $Z + 4 : 15;
$startX = $this->level->generatorType === 1 ? $X - PocketMinecraftServer::$chunkLoadingRadius : 0;
$stopX = $this->level->generatorType === 1 ? $X + PocketMinecraftServer::$chunkLoadingRadius : 15;
$startZ = $this->level->generatorType === 1 ? $Z - PocketMinecraftServer::$chunkLoadingRadius : 0;
$stopZ = $this->level->generatorType === 1 ? $Z + PocketMinecraftServer::$chunkLoadingRadius : 15;
for($x = $startX; $x <= $stopX; ++$x){
for($z = $startZ; $z <= $stopZ; ++$z){
$d = $x . ":" . $z;
//if($this->level->generatorType != 0) unset($chunkToUnload[$d]);
//if($x < 0 || $x > 15 || $z < 0 || $z > 15) continue;
if(!isset($this->chunksLoaded[$d])){
$this->chunksOrder[$d] = abs($x - $X) + abs($z - $Z);
}
}
}
asort($this->chunksOrder);
/*arsort($chunkToUnload);
if($this->level->generatorType != 0){
foreach($chunkToUnload as $chunk => $useless){
$chunkI = explode(":", $chunk);
$cX = $chunkI[0];
$cZ = $chunkI[1];
//console("Unloading chunk $cX:$cZ");
unset($this->chunksLoaded[$chunk]);
$this->level->freeChunk($cX, $cZ, $this);
$this->dataPacket(new UnloadChunkPacket($cX, $cZ));
}
}*/
$this->reload = true;

View file

@ -1,7 +1,7 @@
<?php
class PocketMinecraftServer{
public static $chukSendDelay = 5;
public static $chukSendDelay = 5, $chunkLoadingRadius = 4;
public $tCnt, $ticks;
public $extraprops, $serverID, $interface, $database, $version, $invisible, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $port, $saveEnabled;
/**

View file

@ -3,8 +3,8 @@
class Entity extends Position
{
const TYPE = - 1;
const CLASS_TYPE = - 1;
const TYPE = -1;
const CLASS_TYPE = -1;
const MIN_POSSIBLE_SPEED = 1/8000; //anything below will send 0 to player
public $counter = 0;
@ -76,6 +76,8 @@ class Entity extends Position
public $onGround, $inWater;
public $carryoverDamage;
public $gravity;
public $delayBeforePickup;
function __construct(Level $level, $eid, $class, $type = 0, $data = array())
{
$this->random = new Random();
@ -354,19 +356,20 @@ class Entity extends Position
$hasUpdate = Entity::$updateOnTick ? $this->class === ENTITY_MOB : false; // force true for mobs
$time = microtime(true);
if($this->class === ENTITY_PLAYER and ($this->player instanceof Player) and $this->player->spawned === true and $this->player->blocked !== true && ! $this->dead){
$myBB = $this->boundingBox->grow(1, 0.5, 1);
foreach($this->server->api->entity->getRadius($this, 2, ENTITY_ITEM) as $item){ //TODO vanilla method of searching/radius
if(!$item->closed && $item->spawntime > 0 && ($time - $item->spawntime) >= 0.6){
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
"eid" => $this->player->eid,
"player" => $this->player,
"entity" => $item,
"block" => $item->type,
"meta" => $item->meta,
"target" => $item->eid
)) !== false){
$item->close();
// $item->spawntime = 0;
// $this->server->schedule(15, array($item, "close"));
if(!$item->closed && $item->spawntime > 0 && $item->delayBeforePickup == 0){
if($item->boundingBox->intersectsWith($myBB)){
if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array(
"eid" => $this->player->eid,
"player" => $this->player,
"entity" => $item,
"block" => $item->type,
"meta" => $item->meta,
"target" => $item->eid
)) !== false){
$item->close();
}
}
}
}
@ -492,8 +495,7 @@ class Entity extends Position
return $hasUpdate;
}
public function updateEntityMovement(){}
public function isInVoid(){
return $this->y < -1.6;
@ -571,6 +573,7 @@ class Entity extends Position
}
}
if(!$this->isPlayer()){
$this->updateEntityMovement();
$update = false;
if($this->speedX > -self::MIN_POSSIBLE_SPEED && $this->speedX < self::MIN_POSSIBLE_SPEED){
$this->speedX = 0;
@ -669,9 +672,6 @@ class Entity extends Position
$this->speedY -= $this->inWater ? 0.02 : $this->gravity; // TODO: fix packet spam
$update = true;
} elseif($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) {
@ -720,19 +720,9 @@ class Entity extends Position
$hasUpdate = true;
}
}
if($this->knockbackTime > 0){
--$this->knockbackTime;
}
if($this->moveTime > 0){
-- $this->moveTime;
}
if($this->lookTime > 0){
-- $this->lookTime;
}
if($this->idleTime > 0){
-- $this->idleTime;
}
$this->counterUpdate();
if($this->lastHeadYaw != $this->headYaw){
$this->sendHeadYaw();
}
@ -747,7 +737,25 @@ class Entity extends Position
$this->needsUpdate = $hasUpdate;
$this->lastUpdate = $now;
}
public function counterUpdate(){
if($this->knockbackTime > 0){
--$this->knockbackTime;
}
if($this->moveTime > 0){
-- $this->moveTime;
}
if($this->lookTime > 0){
-- $this->lookTime;
}
if($this->idleTime > 0){
-- $this->idleTime;
}
if($this->delayBeforePickup > 0){
--$this->delayBeforePickup;
}
}
public function updateMovement()
{
if($this->closed === true){

View file

@ -30,22 +30,22 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
unset($this->ai);
unset($this->parent);
}
public function update(){
if($this->closed) return;
public function updateEntityMovement(){
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
$this->ai->updateTasks();
}
$this->ai->mobController->rotateTick();
//$this->ai->mobController->movementTick();
/*if(self::$entityPushing){
$this->collideHandler();
}*/
if($this->onGround){
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
//}
$this->pathFollower->followPath();
//$this->pathFollower->followPath();
}
parent::update();
}
public function sendMoveUpdate(){
@ -53,6 +53,5 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
return;
}
parent::sendMoveUpdate();
}
}

View file

@ -448,7 +448,7 @@ class Level{
$p = $this->server->clients[$cid] ?? false;
if($p instanceof Player){
$dist = abs($xz[0] - (((int)$p->entity->x) >> 4)) + abs($xz[1] - (((int)$p->entity->z) >> 4));
if($dist > 8){
if($dist > PocketMinecraftServer::$chunkLoadingRadius*2){
//ConsoleAPI::debug("{$p->player} freeing chunk: {$xz[0]} {$xz[1]}");
$this->freeChunk($xz[0], $xz[1], $p);
$p->stopUsingChunk($xz[0], $xz[1]);

View file

@ -54,7 +54,7 @@ class ExperimentalGenerator implements NewLevelGenerator{
public function init(Level $level, Random $random){
$this->level = $level;
$this->random = $random;//new MersenneTwister();
$this->random = $random;
$this->random->setSeed($this->level->level->getSeed());
$this->noiseBase = new NoiseGeneratorPerlin($this->random, 4);
$this->selector = new BiomeSelector($this->random, BiomeSelector::$biomes[BIOME_PLAINS]);
@ -154,8 +154,6 @@ class ExperimentalGenerator implements NewLevelGenerator{
$chunk .= (($noiseValue > 0) ? "\x01" : (($y <= $this->waterHeight) ? "\x09" : "\x00"));
}
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
//$chunk .= str_repeat("\xff", 16);
//$chunk .= str_repeat("\xff", 16);
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //light
$chunk .= "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; //more light
}