added force-20-tps as extra property

This commit is contained in:
GameHerobrine 2023-11-23 13:23:19 +03:00
parent 657beafb2a
commit f3228ece20
2 changed files with 40 additions and 27 deletions

View file

@ -11,7 +11,7 @@ class PocketMinecraftServer{
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0; private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread; public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
public static $FORCE_20_TPS = false;
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){ function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
$this->port = (int) $port; $this->port = (int) $port;
$this->doTick = true; $this->doTick = true;
@ -90,14 +90,19 @@ class PocketMinecraftServer{
"mob-despawn-ticks" => 18000, "mob-despawn-ticks" => 18000,
"16x16x16_chunk_sending" => false, "16x16x16_chunk_sending" => false,
"experimental-mob-ai" => false, "experimental-mob-ai" => false,
"force-20-tps" => false,
]); ]);
Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending"); Player::$smallChunks = $this->extraprops->get("16x16x16_chunk_sending");
Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs");
Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks");
self::$FORCE_20_TPS = $this->extraprops->get("force-20-tps");
PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data"); PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data");
MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai"); MobController::$ADVANCED = $this->extraprops->get("experimental-mob-ai");
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
if(self::$FORCE_20_TPS){
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
}
if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-msg") == true){
if($this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled."); console("[INFO] Discord Logger is enabled.");
@ -467,6 +472,14 @@ class PocketMinecraftServer{
public function process() public function process()
{ {
$lastLoop = 0; $lastLoop = 0;
if(self::$FORCE_20_TPS){
while($this->stop === false){
$packet = $this->interface->readPacket();
if($packet instanceof Packet) $this->packetHandler($packet);
$this->tick();
}
}else{
while($this->stop === false){ while($this->stop === false){
$packet = $this->interface->readPacket(); $packet = $this->interface->readPacket();
if($packet instanceof Packet){ if($packet instanceof Packet){
@ -490,6 +503,9 @@ class PocketMinecraftServer{
} }
} }
}
public function packetHandler(Packet $packet){ public function packetHandler(Packet $packet){
$data =& $packet; $data =& $packet;
$CID = PocketMinecraftServer::clientID($packet->ip, $packet->port); $CID = PocketMinecraftServer::clientID($packet->ip, $packet->port);

View file

@ -638,13 +638,10 @@ class Entity extends Position
if($update === true){ if($update === true){
$hasUpdate = true; $hasUpdate = true;
if(($this->server->ticks % 4 === 0 && $this->class === ENTITY_ITEM) || $this->class != ENTITY_ITEM){ //update item speed every 4 ticks
//$this->server->api->handle("entity.motion", $this);
$this->lastSpeedZ = $this->speedZ; $this->lastSpeedZ = $this->speedZ;
$this->lastSpeedY = $this->speedY; $this->lastSpeedY = $this->speedY;
$this->lastSpeedX = $this->speedX; $this->lastSpeedX = $this->speedX;
} }
}
$this->updateFallState($this->speedY); $this->updateFallState($this->speedY);
} elseif($this->player instanceof Player){ } elseif($this->player instanceof Player){
$prevGroundState = $this->onGround; $prevGroundState = $this->onGround;