mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Fixed #1926 Teleport to non-generated chunks
This commit is contained in:
parent
472431752b
commit
bf5630dc0d
@ -59,6 +59,7 @@ use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\SimpleTransactionGroup;
|
||||
use pocketmine\inventory\StonecutterShapelessRecipe;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\format\FullChunk;
|
||||
use pocketmine\level\format\LevelProvider;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\Position;
|
||||
@ -1344,7 +1345,16 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
|
||||
$this->updateFallState($dy, $this->onGround);
|
||||
|
||||
if(!$this->setPositionAndRotation($newPos, $packet->yaw, $packet->pitch)){
|
||||
$revert = false;
|
||||
|
||||
if($this->chunk === null or !$this->chunk->isGenerated()){
|
||||
$chunk = $this->getLevel()->getChunkAt($newPos->x >> 4, $newPos->z >> 4);
|
||||
if(!($chunk instanceof FullChunk) or !$chunk->isGenerated()){
|
||||
$revert = true;
|
||||
}
|
||||
}
|
||||
|
||||
if($revert or !$this->setPositionAndRotation($newPos, $packet->yaw, $packet->pitch)){
|
||||
$pk = new MovePlayerPacket();
|
||||
$pk->eid = 0;
|
||||
$pk->x = $this->x;
|
||||
|
@ -211,6 +211,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
public static function getXZ($hash, &$x, &$z){
|
||||
list($x, $z) = explode(":", $hash);
|
||||
$x = (int) $x;
|
||||
$z = (int) $z;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,169 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
use pocketmine\level\generator\noise\Perlin;
|
||||
use pocketmine\level\generator\noise\Simplex;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\network\raknet\Packet;
|
||||
use pocketmine\utils\Binary;
|
||||
use pocketmine\utils\Random;
|
||||
|
||||
if(\Phar::running(true) !== ""){
|
||||
@define("pocketmine\\PATH", \Phar::running(true)."/");
|
||||
}else{
|
||||
@define("pocketmine\\PATH", \getcwd() . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
if(!class_exists("SplClassLoader", false)){
|
||||
require_once(\pocketmine\PATH . "src/spl/SplClassLoader.php");
|
||||
}
|
||||
|
||||
|
||||
$autoloader = new \SplClassLoader();
|
||||
$autoloader->add("pocketmine", array(
|
||||
\pocketmine\PATH . "src"
|
||||
));
|
||||
$autoloader->register(true);
|
||||
@define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? Binary::BIG_ENDIAN : Binary::LITTLE_ENDIAN));
|
||||
@define("INT32_MASK", is_int(0xffffffff) ? 0xffffffff : -1);
|
||||
|
||||
echo "=== PocketMine Benchmark suite ===\n";
|
||||
echo "[*] uname -a: ".php_uname("a")."\n";
|
||||
if(extension_loaded("pocketmine")){
|
||||
echo "[*] PocketMine native PHP extension v".phpversion("pocketmine")." loaded.\n";
|
||||
}
|
||||
|
||||
$iterations = 200000;
|
||||
$score = 0;
|
||||
$tests = 0;
|
||||
|
||||
echo "[*] Using $iterations iterations\n";
|
||||
|
||||
|
||||
$expect = 0.2;
|
||||
echo "[*] Measuring Random integer generation [$expect]... ";
|
||||
$random = new Random(1337);
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$random->nextSignedInt();
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 0.95;
|
||||
echo "[*] Measuring Simplex noise (8 octaves) [$expect]... ";
|
||||
$noise = new Simplex(new Random(0), 8, 0.5, 8);
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$noise->getNoise2D($i, $i ^ 0xdead);
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 2.9;
|
||||
echo "[*] Measuring Perlin noise (8 octaves) [$expect]... ";
|
||||
$noise = new Perlin(new Random(0), 8, 0.5, 8);
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$noise->getNoise2D($i, $i ^ 0xdead);
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 0.6;
|
||||
echo "[*] Measuring Vector3 creation & distance [$expect]... ";
|
||||
$vector = new Vector3(1337, 31337, 0xff);
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$vector->distance(new Vector3(600, 300, 600));
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 0.4;
|
||||
echo "[*] Measuring AA Bounding Box [$expect]... ";
|
||||
$bb = new AxisAlignedBB(12, 219, 21, 15, 59, 51);
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$bb = $bb->getOffsetBoundingBox(1, 2, -1);
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 2.5;
|
||||
echo "[*] Measuring file operations [$expect]... ";
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
@file_exists("./$i.example");
|
||||
}
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 3.75;
|
||||
echo "[*] Measuring Simple Packet decoding [$expect]... ";
|
||||
$packet = hex2bin("8401000000000815");
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
$pk = new Packet(ord($packet{0}));
|
||||
$pk->buffer =& $packet;
|
||||
$pk->decode();
|
||||
}
|
||||
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
|
||||
$expect = 0.1;
|
||||
echo "[*] Measuring microtime() operations [$expect]... ";
|
||||
$start = microtime(true);
|
||||
for($i = $iterations; $i > 0; --$i){
|
||||
microtime(true);
|
||||
}
|
||||
|
||||
$taken = microtime(true) - $start;
|
||||
$score += 1000 * ($taken / $expect);
|
||||
++$tests;
|
||||
echo round($taken, 6)."s\n";
|
||||
|
||||
echo "\n\n[*] Total score (~1000 good; less is better): ".round($score / $tests, 3)."\n";
|
||||
|
||||
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
use pocketmine\Utils;
|
||||
|
||||
$testErrors = 0;
|
||||
|
||||
/**
|
||||
* Runs a test
|
||||
*
|
||||
* @param $name string test name
|
||||
* @param $output mixed test output
|
||||
* @param $expected mixed expected output (with type-check)
|
||||
*/
|
||||
function testCase($name, $output, $expected){
|
||||
global $testErrors;
|
||||
if($output === $expected){
|
||||
console("[TEST] $name: " . Utils\TextFormat::GREEN . "Ok.");
|
||||
}else{
|
||||
console("[TEST] $name: " . Utils\TextFormat::RED . "Error.");
|
||||
console("Expected " . print_r($expected, true) . ", got " . print_r($output, true));
|
||||
++$testErrors;
|
||||
}
|
||||
}
|
||||
|
||||
if(!class_exists("\\pocketmine\\Server", false)){
|
||||
define("NO_THREADS", true);
|
||||
define("PARENT_API_EXISTENT", true);
|
||||
require_once(dirname(__FILE__) . "/../PocketMine/PocketMine.php");
|
||||
console(Utils\TextFormat::GREEN . "[TEST] Starting tests");
|
||||
testCase("dummy", \pocketmine\dummy(), null);
|
||||
$t = new ServerSuiteTest;
|
||||
echo PHP_EOL;
|
||||
if($testErrors === 0){
|
||||
console(Utils\TextFormat::GREEN . "[TEST] No errors. Test complete.");
|
||||
exit(0);
|
||||
}else{
|
||||
console(Utils\TextFormat::RED . "[TEST] Errors found.");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
class ServerSuiteTest{
|
||||
public function __construct(){
|
||||
//binary things
|
||||
testCase("Utils\\Binary::readTriad", Utils\Binary::readTriad("\x02\x01\x03"), 131331);
|
||||
testCase("Utils\\Binary::readInt", Utils\Binary::readInt("\xff\x02\x01\x03"), -16645885);
|
||||
testCase("Utils\\Binary::readFloat", abs(Utils\Binary::readFloat("\x49\x02\x01\x03") - 532496.1875) < 0.0001, true);
|
||||
testCase("Utils\\Binary::readDouble", abs(Utils\Binary::readDouble("\x41\x02\x03\x04\x05\x06\x07\x08") - 147552.5024529) < 0.0001, true);
|
||||
testCase("Utils\\Binary::readTriad", Utils\Binary::readLong("\x41\x02\x03\x04\x05\x06\x07\x08"), "4684309878217770760");
|
||||
|
||||
//PocketMine-MP server startup
|
||||
global $server;
|
||||
$server = new \pocketmine\ServerAPI();
|
||||
$server->load();
|
||||
testCase("event attached", is_integer($server->event("server.start", array($this, "hook"))), true);
|
||||
$server->init();
|
||||
}
|
||||
|
||||
public function hook(){
|
||||
testCase("event fired", true, true);
|
||||
$server = \pocketmine\Server::getInstance();
|
||||
testCase("defaultgamemode", $server->getGamemode(), "survival");
|
||||
|
||||
|
||||
//Everything done!
|
||||
$server->close();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user