mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Renaming "Level" -> "World" (#2907)
This has been a pain point for a long time due to the misleading nature of the name "level". It's also confusing when trying to do things like getting the XP level of the player or such, and also does not translate well to other languages. This transition was already executed on the UI some time ago (language strings) and now it's time for the same change to occur on the API. This will burn a lot of plugins, but they'll acclimatize. Despite the scary size of this PR, there isn't actually so many changes to make. Most of this came from renaming `Position->getLevel()` to `Position->getWorld()`, or cosmetic changes like changing variable names or doc comments.
This commit is contained in:
parent
427e334426
commit
3cd6e12e71
@ -18,7 +18,7 @@ before_script:
|
|||||||
- cd ..
|
- cd ..
|
||||||
- git clone https://github.com/pmmp/ext-chunkutils2.git chunkutils
|
- git clone https://github.com/pmmp/ext-chunkutils2.git chunkutils
|
||||||
- cd chunkutils
|
- cd chunkutils
|
||||||
- git checkout 5c96eeea7667ef15aa684b6a455a2a46699aff37
|
- git checkout d8d762a597ac0da6f333f862096d6af0e6286b75
|
||||||
- phpize
|
- phpize
|
||||||
- ./configure && make && make install
|
- ./configure && make && make install
|
||||||
- cd ..
|
- cd ..
|
||||||
|
@ -214,14 +214,14 @@ class MemoryManager{
|
|||||||
$this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB",
|
$this->server->getLogger()->debug(sprintf("[Memory Manager] %sLow memory triggered, limit %gMB, using %gMB",
|
||||||
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
|
$global ? "Global " : "", round(($limit / 1024) / 1024, 2), round(($memory / 1024) / 1024, 2)));
|
||||||
if($this->lowMemClearWorldCache){
|
if($this->lowMemClearWorldCache){
|
||||||
foreach($this->server->getLevelManager()->getLevels() as $level){
|
foreach($this->server->getWorldManager()->getWorlds() as $world){
|
||||||
$level->clearCache(true);
|
$world->clearCache(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->lowMemChunkGC){
|
if($this->lowMemChunkGC){
|
||||||
foreach($this->server->getLevelManager()->getLevels() as $level){
|
foreach($this->server->getWorldManager()->getWorlds() as $world){
|
||||||
$level->doChunkGarbageCollection();
|
$world->doChunkGarbageCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +84,6 @@ use pocketmine\item\WritableBook;
|
|||||||
use pocketmine\item\WrittenBook;
|
use pocketmine\item\WrittenBook;
|
||||||
use pocketmine\lang\TextContainer;
|
use pocketmine\lang\TextContainer;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\ChunkListener;
|
|
||||||
use pocketmine\level\ChunkLoader;
|
|
||||||
use pocketmine\level\format\Chunk;
|
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\metadata\MetadataValue;
|
use pocketmine\metadata\MetadataValue;
|
||||||
use pocketmine\nbt\tag\ByteTag;
|
use pocketmine\nbt\tag\ByteTag;
|
||||||
@ -116,6 +111,11 @@ use pocketmine\tile\Tile;
|
|||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
use pocketmine\utils\UUID;
|
use pocketmine\utils\UUID;
|
||||||
|
use pocketmine\world\ChunkListener;
|
||||||
|
use pocketmine\world\ChunkLoader;
|
||||||
|
use pocketmine\world\format\Chunk;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function abs;
|
use function abs;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function assert;
|
use function assert;
|
||||||
@ -305,22 +305,22 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$spawnReset = false;
|
$spawnReset = false;
|
||||||
|
|
||||||
if($namedtag !== null and ($level = $this->server->getLevelManager()->getLevelByName($namedtag->getString("Level", "", true))) !== null){
|
if($namedtag !== null and ($world = $this->server->getWorldManager()->getWorldByName($namedtag->getString("Level", "", true))) !== null){
|
||||||
/** @var float[] $pos */
|
/** @var float[] $pos */
|
||||||
$pos = $namedtag->getListTag("Pos")->getAllValues();
|
$pos = $namedtag->getListTag("Pos")->getAllValues();
|
||||||
$spawn = new Vector3($pos[0], $pos[1], $pos[2]);
|
$spawn = new Vector3($pos[0], $pos[1], $pos[2]);
|
||||||
}else{
|
}else{
|
||||||
$level = $this->server->getLevelManager()->getDefaultLevel(); //TODO: default level might be null
|
$world = $this->server->getWorldManager()->getDefaultWorld(); //TODO: default world might be null
|
||||||
$spawn = $level->getSpawnLocation();
|
$spawn = $world->getSpawnLocation();
|
||||||
$spawnReset = true;
|
$spawnReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load the spawn chunk so we can see the terrain
|
//load the spawn chunk so we can see the terrain
|
||||||
$level->registerChunkLoader($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4, true);
|
$world->registerChunkLoader($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4, true);
|
||||||
$level->registerChunkListener($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4);
|
$world->registerChunkListener($this, $spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4);
|
||||||
$this->usedChunks[Level::chunkHash($spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4)] = false;
|
$this->usedChunks[World::chunkHash($spawn->getFloorX() >> 4, $spawn->getFloorZ() >> 4)] = false;
|
||||||
if($spawnReset){
|
if($spawnReset){
|
||||||
$spawn = $level->getSafeSpawn($spawn);
|
$spawn = $world->getSafeSpawn($spawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($namedtag === null){
|
if($namedtag === null){
|
||||||
@ -337,7 +337,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($level, $namedtag);
|
parent::__construct($world, $namedtag);
|
||||||
|
|
||||||
$ev = new PlayerLoginEvent($this, "Plugin reason");
|
$ev = new PlayerLoginEvent($this, "Plugin reason");
|
||||||
$ev->call();
|
$ev->call();
|
||||||
@ -352,7 +352,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->networkSession->getIp(),
|
$this->networkSession->getIp(),
|
||||||
$this->networkSession->getPort(),
|
$this->networkSession->getPort(),
|
||||||
$this->id,
|
$this->id,
|
||||||
$this->level->getDisplayName(),
|
$this->world->getDisplayName(),
|
||||||
round($this->x, 4),
|
round($this->x, 4),
|
||||||
round($this->y, 4),
|
round($this->y, 4),
|
||||||
round($this->z, 4)
|
round($this->z, 4)
|
||||||
@ -398,10 +398,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->hasValidSpawnPosition()){
|
if(!$this->hasValidSpawnPosition()){
|
||||||
if(($level = $this->server->getLevelManager()->getLevelByName($nbt->getString("SpawnLevel", ""))) instanceof Level){
|
if(($world = $this->server->getWorldManager()->getWorldByName($nbt->getString("SpawnLevel", ""))) instanceof World){
|
||||||
$this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $level);
|
$this->spawnPosition = new Position($nbt->getInt("SpawnX"), $nbt->getInt("SpawnY"), $nbt->getInt("SpawnZ"), $world);
|
||||||
}else{
|
}else{
|
||||||
$this->spawnPosition = $this->level->getSafeSpawn();
|
$this->spawnPosition = $this->world->getSafeSpawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -555,7 +555,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
*/
|
*/
|
||||||
public function spawnTo(Player $player) : void{
|
public function spawnTo(Player $player) : void{
|
||||||
if($this->isAlive() and $player->isAlive() and $player->getLevel() === $this->level and $player->canSee($this) and !$this->isSpectator()){
|
if($this->isAlive() and $player->isAlive() and $player->getWorld() === $this->world and $player->canSee($this) and !$this->isSpectator()){
|
||||||
parent::spawnTo($player);
|
parent::spawnTo($player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -931,20 +931,20 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function switchLevel(Level $targetLevel) : bool{
|
protected function switchWorld(World $targetWorld) : bool{
|
||||||
$oldLevel = $this->level;
|
$oldWorld = $this->world;
|
||||||
if(parent::switchLevel($targetLevel)){
|
if(parent::switchWorld($targetWorld)){
|
||||||
if($oldLevel !== null){
|
if($oldWorld !== null){
|
||||||
foreach($this->usedChunks as $index => $d){
|
foreach($this->usedChunks as $index => $d){
|
||||||
Level::getXZ($index, $X, $Z);
|
World::getXZ($index, $X, $Z);
|
||||||
$this->unloadChunk($X, $Z, $oldLevel);
|
$this->unloadChunk($X, $Z, $oldWorld);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->usedChunks = [];
|
$this->usedChunks = [];
|
||||||
$this->loadQueue = [];
|
$this->loadQueue = [];
|
||||||
$this->level->sendTime($this);
|
$this->world->sendTime($this);
|
||||||
$this->level->sendDifficulty($this);
|
$this->world->sendDifficulty($this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -952,15 +952,15 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function unloadChunk(int $x, int $z, ?Level $level = null){
|
protected function unloadChunk(int $x, int $z, ?World $world = null){
|
||||||
$level = $level ?? $this->level;
|
$world = $world ?? $this->world;
|
||||||
$index = Level::chunkHash($x, $z);
|
$index = World::chunkHash($x, $z);
|
||||||
if(isset($this->usedChunks[$index])){
|
if(isset($this->usedChunks[$index])){
|
||||||
$this->networkSession->stopUsingChunk($x, $z);
|
$this->networkSession->stopUsingChunk($x, $z);
|
||||||
unset($this->usedChunks[$index]);
|
unset($this->usedChunks[$index]);
|
||||||
}
|
}
|
||||||
$level->unregisterChunkLoader($this, $x, $z);
|
$world->unregisterChunkLoader($this, $x, $z);
|
||||||
$level->unregisterChunkListener($this, $x, $z);
|
$world->unregisterChunkListener($this, $x, $z);
|
||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -969,8 +969,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(isset($this->usedChunks[Level::chunkHash($x, $z)]));
|
assert(isset($this->usedChunks[World::chunkHash($x, $z)]));
|
||||||
$this->usedChunks[Level::chunkHash($x, $z)] = true;
|
$this->usedChunks[World::chunkHash($x, $z)] = true;
|
||||||
|
|
||||||
$spawn = $this->spawnChunkLoadCount++ === $this->spawnThreshold;
|
$spawn = $this->spawnChunkLoadCount++ === $this->spawnThreshold;
|
||||||
$this->networkSession->startUsingChunk($x, $z, $spawn);
|
$this->networkSession->startUsingChunk($x, $z, $spawn);
|
||||||
@ -996,21 +996,21 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$X = null;
|
$X = null;
|
||||||
$Z = null;
|
$Z = null;
|
||||||
Level::getXZ($index, $X, $Z);
|
World::getXZ($index, $X, $Z);
|
||||||
assert(is_int($X) and is_int($Z));
|
assert(is_int($X) and is_int($Z));
|
||||||
|
|
||||||
++$count;
|
++$count;
|
||||||
|
|
||||||
$this->usedChunks[$index] = false;
|
$this->usedChunks[$index] = false;
|
||||||
$this->level->registerChunkLoader($this, $X, $Z, true);
|
$this->world->registerChunkLoader($this, $X, $Z, true);
|
||||||
$this->level->registerChunkListener($this, $X, $Z);
|
$this->world->registerChunkListener($this, $X, $Z);
|
||||||
|
|
||||||
if(!$this->level->populateChunk($X, $Z)){
|
if(!$this->world->populateChunk($X, $Z)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
$this->level->requestChunk($X, $Z, $this);
|
$this->world->requestChunk($X, $Z, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Timings::$playerChunkSendTimer->stopTiming();
|
Timings::$playerChunkSendTimer->stopTiming();
|
||||||
@ -1065,23 +1065,23 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
//If the chunk is in the radius, others at the same offsets in different quadrants are also guaranteed to be.
|
//If the chunk is in the radius, others at the same offsets in different quadrants are also guaranteed to be.
|
||||||
|
|
||||||
/* Top right quadrant */
|
/* Top right quadrant */
|
||||||
yield Level::chunkHash($centerX + $x, $centerZ + $z);
|
yield World::chunkHash($centerX + $x, $centerZ + $z);
|
||||||
/* Top left quadrant */
|
/* Top left quadrant */
|
||||||
yield Level::chunkHash($centerX - $x - 1, $centerZ + $z);
|
yield World::chunkHash($centerX - $x - 1, $centerZ + $z);
|
||||||
/* Bottom right quadrant */
|
/* Bottom right quadrant */
|
||||||
yield Level::chunkHash($centerX + $x, $centerZ - $z - 1);
|
yield World::chunkHash($centerX + $x, $centerZ - $z - 1);
|
||||||
/* Bottom left quadrant */
|
/* Bottom left quadrant */
|
||||||
yield Level::chunkHash($centerX - $x - 1, $centerZ - $z - 1);
|
yield World::chunkHash($centerX - $x - 1, $centerZ - $z - 1);
|
||||||
|
|
||||||
if($x !== $z){
|
if($x !== $z){
|
||||||
/* Top right quadrant mirror */
|
/* Top right quadrant mirror */
|
||||||
yield Level::chunkHash($centerX + $z, $centerZ + $x);
|
yield World::chunkHash($centerX + $z, $centerZ + $x);
|
||||||
/* Top left quadrant mirror */
|
/* Top left quadrant mirror */
|
||||||
yield Level::chunkHash($centerX - $z - 1, $centerZ + $x);
|
yield World::chunkHash($centerX - $z - 1, $centerZ + $x);
|
||||||
/* Bottom right quadrant mirror */
|
/* Bottom right quadrant mirror */
|
||||||
yield Level::chunkHash($centerX + $z, $centerZ - $x - 1);
|
yield World::chunkHash($centerX + $z, $centerZ - $x - 1);
|
||||||
/* Bottom left quadrant mirror */
|
/* Bottom left quadrant mirror */
|
||||||
yield Level::chunkHash($centerX - $z - 1, $centerZ - $x - 1);
|
yield World::chunkHash($centerX - $z - 1, $centerZ - $x - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1105,7 +1105,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach($unloadChunks as $index => $bool){
|
foreach($unloadChunks as $index => $bool){
|
||||||
Level::getXZ($index, $X, $Z);
|
World::getXZ($index, $X, $Z);
|
||||||
$this->unloadChunk($X, $Z);
|
$this->unloadChunk($X, $Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1139,9 +1139,9 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
if($this->hasValidSpawnPosition()){
|
if($this->hasValidSpawnPosition()){
|
||||||
return $this->spawnPosition;
|
return $this->spawnPosition;
|
||||||
}else{
|
}else{
|
||||||
$level = $this->server->getLevelManager()->getDefaultLevel();
|
$world = $this->server->getWorldManager()->getDefaultWorld();
|
||||||
|
|
||||||
return $level->getSafeSpawn();
|
return $world->getSafeSpawn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1160,11 +1160,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
*/
|
*/
|
||||||
public function setSpawn(Vector3 $pos){
|
public function setSpawn(Vector3 $pos){
|
||||||
if(!($pos instanceof Position)){
|
if(!($pos instanceof Position)){
|
||||||
$level = $this->level;
|
$world = $this->world;
|
||||||
}else{
|
}else{
|
||||||
$level = $pos->getLevel();
|
$world = $pos->getWorld();
|
||||||
}
|
}
|
||||||
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
|
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $world);
|
||||||
$this->networkSession->syncPlayerSpawnPoint($this->spawnPosition);
|
$this->networkSession->syncPlayerSpawnPoint($this->spawnPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1186,7 +1186,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
$pos = $pos->floor();
|
$pos = $pos->floor();
|
||||||
$b = $this->level->getBlock($pos);
|
$b = $this->world->getBlock($pos);
|
||||||
|
|
||||||
$ev = new PlayerBedEnterEvent($this, $b);
|
$ev = new PlayerBedEnterEvent($this, $b);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
@ -1205,14 +1205,14 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$this->setSpawn($pos);
|
$this->setSpawn($pos);
|
||||||
|
|
||||||
$this->level->setSleepTicks(60);
|
$this->world->setSleepTicks(60);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stopSleep(){
|
public function stopSleep(){
|
||||||
if($this->sleeping instanceof Vector3){
|
if($this->sleeping instanceof Vector3){
|
||||||
$b = $this->level->getBlock($this->sleeping);
|
$b = $this->world->getBlock($this->sleeping);
|
||||||
if($b instanceof Bed){
|
if($b instanceof Bed){
|
||||||
$b->setOccupied(false);
|
$b->setOccupied(false);
|
||||||
}
|
}
|
||||||
@ -1222,7 +1222,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, null);
|
$this->propertyManager->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, null);
|
||||||
$this->setPlayerFlag(PlayerMetadataFlags::SLEEP, false);
|
$this->setPlayerFlag(PlayerMetadataFlags::SLEEP, false);
|
||||||
|
|
||||||
$this->level->setSleepTicks(0);
|
$this->world->setSleepTicks(0);
|
||||||
|
|
||||||
$this->broadcastAnimation([$this], AnimatePacket::ACTION_STOP_SLEEP);
|
$this->broadcastAnimation([$this], AnimatePacket::ACTION_STOP_SLEEP);
|
||||||
}
|
}
|
||||||
@ -1410,7 +1410,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$bb->minY = $this->y - 0.2;
|
$bb->minY = $this->y - 0.2;
|
||||||
$bb->maxY = $this->y + 0.2;
|
$bb->maxY = $this->y + 0.2;
|
||||||
|
|
||||||
$this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0;
|
$this->onGround = $this->isCollided = count($this->world->getCollisionBlocks($bb, true)) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canBeMovedByCurrents() : bool{
|
public function canBeMovedByCurrents() : bool{
|
||||||
@ -1418,7 +1418,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function checkNearEntities(){
|
protected function checkNearEntities(){
|
||||||
foreach($this->level->getNearbyEntities($this->boundingBox->expandedCopy(1, 0.5, 1), $this) as $entity){
|
foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(1, 0.5, 1), $this) as $entity){
|
||||||
$entity->scheduleUpdate();
|
$entity->scheduleUpdate();
|
||||||
|
|
||||||
if(!$entity->isAlive() or $entity->isFlaggedForDespawn()){
|
if(!$entity->isAlive() or $entity->isFlaggedForDespawn()){
|
||||||
@ -1500,7 +1500,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement");
|
$this->server->getLogger()->warning($this->getName() . " moved too fast, reverting movement");
|
||||||
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition);
|
$this->server->getLogger()->debug("Old position: " . $this->asVector3() . ", new position: " . $this->newPosition);
|
||||||
$revert = true;
|
$revert = true;
|
||||||
}elseif(!$this->level->isInLoadedTerrain($newPos) or !$this->level->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){
|
}elseif(!$this->world->isInLoadedTerrain($newPos) or !$this->world->isChunkGenerated($newPos->getFloorX() >> 4, $newPos->getFloorZ() >> 4)){
|
||||||
$revert = true;
|
$revert = true;
|
||||||
$this->nextChunkOrderRun = 0;
|
$this->nextChunkOrderRun = 0;
|
||||||
}
|
}
|
||||||
@ -1864,14 +1864,14 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function pickBlock(Vector3 $pos, bool $addTileNBT) : bool{
|
public function pickBlock(Vector3 $pos, bool $addTileNBT) : bool{
|
||||||
$block = $this->level->getBlock($pos);
|
$block = $this->world->getBlock($pos);
|
||||||
if($block instanceof UnknownBlock){
|
if($block instanceof UnknownBlock){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = $block->getPickedItem();
|
$item = $block->getPickedItem();
|
||||||
if($addTileNBT){
|
if($addTileNBT){
|
||||||
$tile = $this->getLevel()->getTile($block);
|
$tile = $this->getWorld()->getTile($block);
|
||||||
if($tile instanceof Tile){
|
if($tile instanceof Tile){
|
||||||
$nbt = $tile->getCleanedNBT();
|
$nbt = $tile->getCleanedNBT();
|
||||||
if($nbt instanceof CompoundTag){
|
if($nbt instanceof CompoundTag){
|
||||||
@ -1922,12 +1922,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
return false; //TODO: maybe this should throw an exception instead?
|
return false; //TODO: maybe this should throw an exception instead?
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = $this->level->getBlock($pos);
|
$target = $this->world->getBlock($pos);
|
||||||
|
|
||||||
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
$ev = new PlayerInteractEvent($this, $this->inventory->getItemInHand(), $target, null, $face, PlayerInteractEvent::LEFT_CLICK_BLOCK);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
$this->level->sendBlocks([$this], [$target]);
|
$this->world->sendBlocks([$this], [$target]);
|
||||||
$this->inventory->sendHeldItem($this);
|
$this->inventory->sendHeldItem($this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1937,7 +1937,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$block = $target->getSide($face);
|
$block = $target->getSide($face);
|
||||||
if($block->getId() === BlockLegacyIds::FIRE){
|
if($block->getId() === BlockLegacyIds::FIRE){
|
||||||
$this->level->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1945,7 +1945,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
//TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211)
|
//TODO: improve this to take stuff like swimming, ladders, enchanted tools into account, fix wrong tool break time calculations for bad tools (pmmp/PocketMine-MP#211)
|
||||||
$breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20);
|
$breakTime = ceil($target->getBreakTime($this->inventory->getItemInHand()) * 20);
|
||||||
if($breakTime > 0){
|
if($breakTime > 0){
|
||||||
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime));
|
$this->world->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_START_BREAK, (int) (65535 / $breakTime));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1953,8 +1953,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function continueBreakBlock(Vector3 $pos, int $face) : void{
|
public function continueBreakBlock(Vector3 $pos, int $face) : void{
|
||||||
$block = $this->level->getBlock($pos);
|
$block = $this->world->getBlock($pos);
|
||||||
$this->level->broadcastLevelEvent(
|
$this->world->broadcastLevelEvent(
|
||||||
$pos,
|
$pos,
|
||||||
LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK,
|
LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK,
|
||||||
$block->getRuntimeId() | ($face << 24)
|
$block->getRuntimeId() | ($face << 24)
|
||||||
@ -1964,7 +1964,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function stopBreakBlock(Vector3 $pos) : void{
|
public function stopBreakBlock(Vector3 $pos) : void{
|
||||||
$this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK);
|
$this->world->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1980,7 +1980,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7) and !$this->isSpectator()){
|
if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? 13 : 7) and !$this->isSpectator()){
|
||||||
$item = $this->inventory->getItemInHand();
|
$item = $this->inventory->getItemInHand();
|
||||||
$oldItem = clone $item;
|
$oldItem = clone $item;
|
||||||
if($this->level->useBreakOn($pos, $item, $this, true)){
|
if($this->world->useBreakOn($pos, $item, $this, true)){
|
||||||
if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){
|
if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
@ -1992,12 +1992,12 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$this->inventory->sendContents($this);
|
$this->inventory->sendContents($this);
|
||||||
$this->inventory->sendHeldItem($this);
|
$this->inventory->sendHeldItem($this);
|
||||||
|
|
||||||
$target = $this->level->getBlock($pos);
|
$target = $this->world->getBlock($pos);
|
||||||
/** @var Block[] $blocks */
|
/** @var Block[] $blocks */
|
||||||
$blocks = $target->getAllSides();
|
$blocks = $target->getAllSides();
|
||||||
$blocks[] = $target;
|
$blocks[] = $target;
|
||||||
|
|
||||||
$this->level->sendBlocks([$this], $blocks);
|
$this->world->sendBlocks([$this], $blocks);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2017,7 +2017,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
if($this->canInteract($pos->add(0.5, 0.5, 0.5), 13) and !$this->isSpectator()){
|
if($this->canInteract($pos->add(0.5, 0.5, 0.5), 13) and !$this->isSpectator()){
|
||||||
$item = $this->inventory->getItemInHand(); //this is a copy of the real item
|
$item = $this->inventory->getItemInHand(); //this is a copy of the real item
|
||||||
$oldItem = clone $item;
|
$oldItem = clone $item;
|
||||||
if($this->level->useItemOn($pos, $item, $face, $clickOffset, $this, true)){
|
if($this->world->useItemOn($pos, $item, $face, $clickOffset, $this, true)){
|
||||||
if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){
|
if($this->hasFiniteResources() and !$item->equalsExact($oldItem)){
|
||||||
$this->inventory->setItemInHand($item);
|
$this->inventory->setItemInHand($item);
|
||||||
}
|
}
|
||||||
@ -2031,13 +2031,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$target = $this->level->getBlock($pos);
|
$target = $this->world->getBlock($pos);
|
||||||
$block = $target->getSide($face);
|
$block = $target->getSide($face);
|
||||||
|
|
||||||
/** @var Block[] $blocks */
|
/** @var Block[] $blocks */
|
||||||
$blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other
|
$blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other
|
||||||
|
|
||||||
$this->level->sendBlocks([$this], $blocks);
|
$this->world->sendBlocks([$this], $blocks);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2178,7 +2178,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
* @param Item $item
|
* @param Item $item
|
||||||
*/
|
*/
|
||||||
public function dropItem(Item $item) : void{
|
public function dropItem(Item $item) : void{
|
||||||
$this->level->dropItem($this->add(0, 1.3, 0), $item, $this->getDirectionVector()->multiply(0.4), 40);
|
$this->world->dropItem($this->add(0, 1.3, 0), $item, $this->getDirectionVector()->multiply(0.4), 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleBookEdit(BookEditPacket $packet) : bool{
|
public function handleBookEdit(BookEditPacket $packet) : bool{
|
||||||
@ -2564,10 +2564,10 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
foreach($this->usedChunks as $index => $d){
|
foreach($this->usedChunks as $index => $d){
|
||||||
Level::getXZ($index, $chunkX, $chunkZ);
|
World::getXZ($index, $chunkX, $chunkZ);
|
||||||
$this->level->unregisterChunkLoader($this, $chunkX, $chunkZ);
|
$this->world->unregisterChunkLoader($this, $chunkX, $chunkZ);
|
||||||
$this->level->unregisterChunkListener($this, $chunkX, $chunkZ);
|
$this->world->unregisterChunkListener($this, $chunkX, $chunkZ);
|
||||||
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
|
foreach($this->world->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||||
$entity->despawnFrom($this);
|
$entity->despawnFrom($this);
|
||||||
}
|
}
|
||||||
unset($this->usedChunks[$index]);
|
unset($this->usedChunks[$index]);
|
||||||
@ -2626,11 +2626,11 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$nbt = $this->saveNBT();
|
$nbt = $this->saveNBT();
|
||||||
|
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
$nbt->setString("Level", $this->level->getFolderName());
|
$nbt->setString("Level", $this->world->getFolderName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->hasValidSpawnPosition()){
|
if($this->hasValidSpawnPosition()){
|
||||||
$nbt->setString("SpawnLevel", $this->spawnPosition->getLevel()->getFolderName());
|
$nbt->setString("SpawnLevel", $this->spawnPosition->getWorld()->getFolderName());
|
||||||
$nbt->setInt("SpawnX", $this->spawnPosition->getFloorX());
|
$nbt->setInt("SpawnX", $this->spawnPosition->getFloorX());
|
||||||
$nbt->setInt("SpawnY", $this->spawnPosition->getFloorY());
|
$nbt->setInt("SpawnY", $this->spawnPosition->getFloorY());
|
||||||
$nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ());
|
$nbt->setInt("SpawnZ", $this->spawnPosition->getFloorZ());
|
||||||
@ -2671,7 +2671,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
if(!$ev->getKeepInventory()){
|
if(!$ev->getKeepInventory()){
|
||||||
foreach($ev->getDrops() as $item){
|
foreach($ev->getDrops() as $item){
|
||||||
$this->level->dropItem($this, $item);
|
$this->world->dropItem($this, $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->inventory !== null){
|
if($this->inventory !== null){
|
||||||
@ -2683,7 +2683,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->dropExperience($this, $ev->getXpDropAmount());
|
$this->world->dropExperience($this, $ev->getXpDropAmount());
|
||||||
$this->setXpAndProgress(0, 0);
|
$this->setXpAndProgress(0, 0);
|
||||||
|
|
||||||
if($ev->getDeathMessage() != ""){
|
if($ev->getDeathMessage() != ""){
|
||||||
@ -2709,7 +2709,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
$ev = new PlayerRespawnEvent($this, $this->getSpawn());
|
$ev = new PlayerRespawnEvent($this, $this->getSpawn());
|
||||||
$ev->call();
|
$ev->call();
|
||||||
|
|
||||||
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getLevel());
|
$realSpawn = Position::fromObject($ev->getRespawnPosition()->add(0.5, 0, 0.5), $ev->getRespawnPosition()->getWorld());
|
||||||
$this->teleport($realSpawn);
|
$this->teleport($realSpawn);
|
||||||
|
|
||||||
$this->setSprinting(false);
|
$this->setSprinting(false);
|
||||||
@ -3038,7 +3038,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onChunkChanged(Chunk $chunk) : void{
|
public function onChunkChanged(Chunk $chunk) : void{
|
||||||
if(isset($this->usedChunks[$hash = Level::chunkHash($chunk->getX(), $chunk->getZ())])){
|
if(isset($this->usedChunks[$hash = World::chunkHash($chunk->getX(), $chunk->getZ())])){
|
||||||
$this->usedChunks[$hash] = false;
|
$this->usedChunks[$hash] = false;
|
||||||
$this->nextChunkOrderRun = 0;
|
$this->nextChunkOrderRun = 0;
|
||||||
}
|
}
|
||||||
|
@ -47,17 +47,9 @@ use pocketmine\item\ItemFactory;
|
|||||||
use pocketmine\lang\Language;
|
use pocketmine\lang\Language;
|
||||||
use pocketmine\lang\LanguageNotFoundException;
|
use pocketmine\lang\LanguageNotFoundException;
|
||||||
use pocketmine\lang\TextContainer;
|
use pocketmine\lang\TextContainer;
|
||||||
use pocketmine\level\biome\Biome;
|
|
||||||
use pocketmine\level\format\io\LevelProviderManager;
|
|
||||||
use pocketmine\level\format\io\WritableLevelProvider;
|
|
||||||
use pocketmine\level\generator\Generator;
|
|
||||||
use pocketmine\level\generator\GeneratorManager;
|
|
||||||
use pocketmine\level\generator\normal\Normal;
|
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\LevelManager;
|
|
||||||
use pocketmine\metadata\EntityMetadataStore;
|
use pocketmine\metadata\EntityMetadataStore;
|
||||||
use pocketmine\metadata\LevelMetadataStore;
|
|
||||||
use pocketmine\metadata\PlayerMetadataStore;
|
use pocketmine\metadata\PlayerMetadataStore;
|
||||||
|
use pocketmine\metadata\WorldMetadataStore;
|
||||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||||
use pocketmine\nbt\NbtDataException;
|
use pocketmine\nbt\NbtDataException;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
@ -102,6 +94,14 @@ use pocketmine\utils\Terminal;
|
|||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\utils\UUID;
|
use pocketmine\utils\UUID;
|
||||||
|
use pocketmine\world\biome\Biome;
|
||||||
|
use pocketmine\world\format\io\WorldProviderManager;
|
||||||
|
use pocketmine\world\format\io\WritableWorldProvider;
|
||||||
|
use pocketmine\world\generator\Generator;
|
||||||
|
use pocketmine\world\generator\GeneratorManager;
|
||||||
|
use pocketmine\world\generator\normal\Normal;
|
||||||
|
use pocketmine\world\World;
|
||||||
|
use pocketmine\world\WorldManager;
|
||||||
use function array_key_exists;
|
use function array_key_exists;
|
||||||
use function array_shift;
|
use function array_shift;
|
||||||
use function array_sum;
|
use function array_sum;
|
||||||
@ -238,8 +238,8 @@ class Server{
|
|||||||
/** @var ResourcePackManager */
|
/** @var ResourcePackManager */
|
||||||
private $resourceManager;
|
private $resourceManager;
|
||||||
|
|
||||||
/** @var LevelManager */
|
/** @var WorldManager */
|
||||||
private $levelManager;
|
private $worldManager;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
private $maxPlayers;
|
private $maxPlayers;
|
||||||
@ -253,8 +253,8 @@ class Server{
|
|||||||
/** @var PlayerMetadataStore */
|
/** @var PlayerMetadataStore */
|
||||||
private $playerMetadata;
|
private $playerMetadata;
|
||||||
|
|
||||||
/** @var LevelMetadataStore */
|
/** @var WorldMetadataStore */
|
||||||
private $levelMetadata;
|
private $worldMetadata;
|
||||||
|
|
||||||
/** @var Network */
|
/** @var Network */
|
||||||
private $network;
|
private $network;
|
||||||
@ -436,7 +436,7 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns Server global difficulty. Note that this may be overridden in individual Levels.
|
* Returns Server global difficulty. Note that this may be overridden in individual worlds.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getDifficulty() : int{
|
public function getDifficulty() : int{
|
||||||
@ -493,10 +493,10 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LevelMetadataStore
|
* @return WorldMetadataStore
|
||||||
*/
|
*/
|
||||||
public function getLevelMetadata(){
|
public function getWorldMetadata(){
|
||||||
return $this->levelMetadata;
|
return $this->worldMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,10 +528,10 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LevelManager
|
* @return WorldManager
|
||||||
*/
|
*/
|
||||||
public function getLevelManager() : LevelManager{
|
public function getWorldManager() : WorldManager{
|
||||||
return $this->levelManager;
|
return $this->worldManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAsyncPool() : AsyncPool{
|
public function getAsyncPool() : AsyncPool{
|
||||||
@ -1130,7 +1130,7 @@ class Server{
|
|||||||
|
|
||||||
$this->entityMetadata = new EntityMetadataStore();
|
$this->entityMetadata = new EntityMetadataStore();
|
||||||
$this->playerMetadata = new PlayerMetadataStore();
|
$this->playerMetadata = new PlayerMetadataStore();
|
||||||
$this->levelMetadata = new LevelMetadataStore();
|
$this->worldMetadata = new WorldMetadataStore();
|
||||||
|
|
||||||
$this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM);
|
$this->operators = new Config($this->dataPath . "ops.txt", Config::ENUM);
|
||||||
$this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM);
|
$this->whitelist = new Config($this->dataPath . "white-list.txt", Config::ENUM);
|
||||||
@ -1156,8 +1156,8 @@ class Server{
|
|||||||
$this->logger->warning($this->getLanguage()->translateString("pocketmine.server.authProperty.disabled"));
|
$this->logger->warning($this->getLanguage()->translateString("pocketmine.server.authProperty.disabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->getConfigBool("hardcore", false) and $this->getDifficulty() < Level::DIFFICULTY_HARD){
|
if($this->getConfigBool("hardcore", false) and $this->getDifficulty() < World::DIFFICULTY_HARD){
|
||||||
$this->setConfigInt("difficulty", Level::DIFFICULTY_HARD);
|
$this->setConfigInt("difficulty", World::DIFFICULTY_HARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(\pocketmine\DEBUG >= 0){
|
if(\pocketmine\DEBUG >= 0){
|
||||||
@ -1213,18 +1213,18 @@ class Server{
|
|||||||
$this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader));
|
$this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader));
|
||||||
$this->pluginManager->registerInterface(new ScriptPluginLoader());
|
$this->pluginManager->registerInterface(new ScriptPluginLoader());
|
||||||
|
|
||||||
LevelProviderManager::init();
|
WorldProviderManager::init();
|
||||||
if(
|
if(
|
||||||
($format = LevelProviderManager::getProviderByName($formatName = (string) $this->getProperty("level-settings.default-format"))) !== null and
|
($format = WorldProviderManager::getProviderByName($formatName = (string) $this->getProperty("level-settings.default-format"))) !== null and
|
||||||
is_a($format, WritableLevelProvider::class, true)
|
is_a($format, WritableWorldProvider::class, true)
|
||||||
){
|
){
|
||||||
LevelProviderManager::setDefault($format);
|
WorldProviderManager::setDefault($format);
|
||||||
}elseif($formatName !== ""){
|
}elseif($formatName !== ""){
|
||||||
$this->logger->warning($this->language->translateString("pocketmine.level.badDefaultFormat", [$formatName]));
|
$this->logger->warning($this->language->translateString("pocketmine.level.badDefaultFormat", [$formatName]));
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratorManager::registerDefaultGenerators();
|
GeneratorManager::registerDefaultGenerators();
|
||||||
$this->levelManager = new LevelManager($this);
|
$this->worldManager = new WorldManager($this);
|
||||||
|
|
||||||
$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "update.pmmp.io"));
|
$this->updater = new AutoUpdater($this, $this->getProperty("auto-updater.host", "update.pmmp.io"));
|
||||||
|
|
||||||
@ -1241,7 +1241,7 @@ class Server{
|
|||||||
}elseif(!is_array($options)){
|
}elseif(!is_array($options)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(!$this->levelManager->loadLevel($name, true)){
|
if(!$this->worldManager->loadWorld($name, true)){
|
||||||
if(isset($options["generator"])){
|
if(isset($options["generator"])){
|
||||||
$generatorOptions = explode(":", $options["generator"]);
|
$generatorOptions = explode(":", $options["generator"]);
|
||||||
$generator = GeneratorManager::getGenerator(array_shift($generatorOptions));
|
$generator = GeneratorManager::getGenerator(array_shift($generatorOptions));
|
||||||
@ -1252,19 +1252,19 @@ class Server{
|
|||||||
$generator = Normal::class;
|
$generator = Normal::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->levelManager->generateLevel($name, Generator::convertSeed((string) ($options["seed"] ?? "")), $generator, $options);
|
$this->worldManager->generateWorld($name, Generator::convertSeed((string) ($options["seed"] ?? "")), $generator, $options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->levelManager->getDefaultLevel() === null){
|
if($this->worldManager->getDefaultWorld() === null){
|
||||||
$default = $this->getConfigString("level-name", "world");
|
$default = $this->getConfigString("level-name", "world");
|
||||||
if(trim($default) == ""){
|
if(trim($default) == ""){
|
||||||
$this->getLogger()->warning("level-name cannot be null, using default");
|
$this->getLogger()->warning("level-name cannot be null, using default");
|
||||||
$default = "world";
|
$default = "world";
|
||||||
$this->setConfigString("level-name", "world");
|
$this->setConfigString("level-name", "world");
|
||||||
}
|
}
|
||||||
if(!$this->levelManager->loadLevel($default, true)){
|
if(!$this->worldManager->loadWorld($default, true)){
|
||||||
$this->levelManager->generateLevel(
|
$this->worldManager->generateWorld(
|
||||||
$default,
|
$default,
|
||||||
Generator::convertSeed($this->getConfigString("level-seed")),
|
Generator::convertSeed($this->getConfigString("level-seed")),
|
||||||
GeneratorManager::getGenerator($this->getConfigString("level-type")),
|
GeneratorManager::getGenerator($this->getConfigString("level-type")),
|
||||||
@ -1272,14 +1272,14 @@ class Server{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$level = $this->levelManager->getLevelByName($default);
|
$world = $this->worldManager->getWorldByName($default);
|
||||||
if($level === null){
|
if($world === null){
|
||||||
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
|
$this->getLogger()->emergency($this->getLanguage()->translateString("pocketmine.level.defaultError"));
|
||||||
$this->forceShutdown();
|
$this->forceShutdown();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->levelManager->setDefaultLevel($level);
|
$this->worldManager->setDefaultWorld($world);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->enablePlugins(PluginLoadOrder::POSTWORLD());
|
$this->enablePlugins(PluginLoadOrder::POSTWORLD());
|
||||||
@ -1628,10 +1628,10 @@ class Server{
|
|||||||
$this->network->getSessionManager()->close($this->getProperty("settings.shutdown-message", "Server closed"));
|
$this->network->getSessionManager()->close($this->getProperty("settings.shutdown-message", "Server closed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->levelManager instanceof LevelManager){
|
if($this->worldManager instanceof WorldManager){
|
||||||
$this->getLogger()->debug("Unloading all worlds");
|
$this->getLogger()->debug("Unloading all worlds");
|
||||||
foreach($this->levelManager->getLevels() as $level){
|
foreach($this->worldManager->getWorlds() as $world){
|
||||||
$this->levelManager->unloadLevel($level, true);
|
$this->worldManager->unloadWorld($world, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1951,7 +1951,7 @@ class Server{
|
|||||||
$this->asyncPool->collectTasks();
|
$this->asyncPool->collectTasks();
|
||||||
Timings::$schedulerAsyncTimer->stopTiming();
|
Timings::$schedulerAsyncTimer->stopTiming();
|
||||||
|
|
||||||
$this->levelManager->tick($this->tickCounter);
|
$this->worldManager->tick($this->tickCounter);
|
||||||
|
|
||||||
Timings::$connectionTimer->startTiming();
|
Timings::$connectionTimer->startTiming();
|
||||||
$this->network->tick();
|
$this->network->tick();
|
||||||
@ -1978,8 +1978,8 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(($this->tickCounter % 100) === 0){
|
if(($this->tickCounter % 100) === 0){
|
||||||
foreach($this->levelManager->getLevels() as $level){
|
foreach($this->worldManager->getWorlds() as $world){
|
||||||
$level->clearCache();
|
$world->clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->getTicksPerSecondAverage() < 12){
|
if($this->getTicksPerSecondAverage() < 12){
|
||||||
|
@ -92,7 +92,7 @@ class Banner extends Transparent{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileBanner){
|
if($tile instanceof TileBanner){
|
||||||
$this->baseColor = $tile->getBaseColor();
|
$this->baseColor = $tile->getBaseColor();
|
||||||
$this->setPatterns($tile->getPatterns());
|
$this->setPatterns($tile->getPatterns());
|
||||||
@ -101,7 +101,7 @@ class Banner extends Transparent{
|
|||||||
|
|
||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
assert($tile instanceof TileBanner);
|
assert($tile instanceof TileBanner);
|
||||||
$tile->setBaseColor($this->baseColor);
|
$tile->setBaseColor($this->baseColor);
|
||||||
$tile->setPatterns($this->patterns);
|
$tile->setPatterns($this->patterns);
|
||||||
@ -164,7 +164,7 @@ class Banner extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
|
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ abstract class BaseRail extends Flowable{
|
|||||||
if(isset($otherPossible[$otherSide])){
|
if(isset($otherPossible[$otherSide])){
|
||||||
$otherConnections[] = $otherSide;
|
$otherConnections[] = $otherSide;
|
||||||
$other->setConnections($otherConnections);
|
$other->setConnections($otherConnections);
|
||||||
$other->level->setBlock($other, $other);
|
$other->world->setBlock($other, $other);
|
||||||
|
|
||||||
$changed = true;
|
$changed = true;
|
||||||
$thisConnections[] = $thisSide;
|
$thisConnections[] = $thisSide;
|
||||||
@ -275,11 +275,11 @@ abstract class BaseRail extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}else{
|
}else{
|
||||||
foreach($this->connections as $connection){
|
foreach($this->connections as $connection){
|
||||||
if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){
|
if(($connection & self::FLAG_ASCEND) !== 0 and $this->getSide($connection & ~self::FLAG_ASCEND)->isTransparent()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ use pocketmine\item\Bed as ItemBed;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Bearing;
|
use pocketmine\math\Bearing;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -37,6 +36,7 @@ use pocketmine\math\Vector3;
|
|||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\tile\Bed as TileBed;
|
use pocketmine\tile\Bed as TileBed;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\world\World;
|
||||||
|
|
||||||
class Bed extends Transparent{
|
class Bed extends Transparent{
|
||||||
private const BITFLAG_OCCUPIED = 0x04;
|
private const BITFLAG_OCCUPIED = 0x04;
|
||||||
@ -75,7 +75,7 @@ class Bed extends Transparent{
|
|||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
//read extra state information from the tile - this is an ugly hack
|
//read extra state information from the tile - this is an ugly hack
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileBed){
|
if($tile instanceof TileBed){
|
||||||
$this->color = $tile->getColor();
|
$this->color = $tile->getColor();
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ class Bed extends Transparent{
|
|||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
//extra block properties storage hack
|
//extra block properties storage hack
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileBed){
|
if($tile instanceof TileBed){
|
||||||
$tile->setColor($this->color);
|
$tile->setColor($this->color);
|
||||||
}
|
}
|
||||||
@ -111,11 +111,11 @@ class Bed extends Transparent{
|
|||||||
|
|
||||||
public function setOccupied(bool $occupied = true) : void{
|
public function setOccupied(bool $occupied = true) : void{
|
||||||
$this->occupied = $occupied;
|
$this->occupied = $occupied;
|
||||||
$this->level->setBlock($this, $this, false);
|
$this->world->setBlock($this, $this, false);
|
||||||
|
|
||||||
if(($other = $this->getOtherHalf()) !== null){
|
if(($other = $this->getOtherHalf()) !== null){
|
||||||
$other->occupied = $occupied;
|
$other->occupied = $occupied;
|
||||||
$this->level->setBlock($other, $other, false);
|
$this->world->setBlock($other, $other, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +150,9 @@ class Bed extends Transparent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$time = $this->getLevel()->getTime() % Level::TIME_FULL;
|
$time = $this->getWorld()->getTime() % World::TIME_FULL;
|
||||||
|
|
||||||
$isNight = ($time >= Level::TIME_NIGHT and $time < Level::TIME_SUNRISE);
|
$isNight = ($time >= World::TIME_NIGHT and $time < World::TIME_SUNRISE);
|
||||||
|
|
||||||
if(!$isNight){
|
if(!$isNight){
|
||||||
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.noSleep"));
|
$player->sendMessage(new TranslationContainer(TextFormat::GRAY . "%tile.bed.noSleep"));
|
||||||
@ -188,7 +188,7 @@ class Bed extends Transparent{
|
|||||||
parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||||
$nextState = clone $this;
|
$nextState = clone $this;
|
||||||
$nextState->head = true;
|
$nextState->head = true;
|
||||||
$this->getLevel()->setBlock($next, $nextState);
|
$this->getWorld()->setBlock($next, $nextState);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,6 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\item\enchantment\Enchantment;
|
use pocketmine\item\enchantment\Enchantment;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
@ -43,6 +41,8 @@ use pocketmine\network\mcpe\protocol\types\RuntimeBlockMapping;
|
|||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\plugin\Plugin;
|
use pocketmine\plugin\Plugin;
|
||||||
use pocketmine\tile\TileFactory;
|
use pocketmine\tile\TileFactory;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function dechex;
|
use function dechex;
|
||||||
@ -174,16 +174,16 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
$this->level->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId());
|
$this->world->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId());
|
||||||
|
|
||||||
$tileType = $this->idInfo->getTileClass();
|
$tileType = $this->idInfo->getTileClass();
|
||||||
$oldTile = $this->level->getTile($this);
|
$oldTile = $this->world->getTile($this);
|
||||||
if($oldTile !== null and ($tileType === null or !($oldTile instanceof $tileType))){
|
if($oldTile !== null and ($tileType === null or !($oldTile instanceof $tileType))){
|
||||||
$oldTile->close();
|
$oldTile->close();
|
||||||
$oldTile = null;
|
$oldTile = null;
|
||||||
}
|
}
|
||||||
if($oldTile === null and $tileType !== null){
|
if($oldTile === null and $tileType !== null){
|
||||||
$this->level->addTile(TileFactory::create($tileType, $this->level, $this->asVector3()));
|
$this->world->addTile(TileFactory::create($tileType, $this->world, $this->asVector3()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
return $this->getLevel()->setBlock($blockReplace, $this);
|
return $this->getWorld()->setBlock($blockReplace, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -312,10 +312,10 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function onBreak(Item $item, ?Player $player = null) : bool{
|
public function onBreak(Item $item, ?Player $player = null) : bool{
|
||||||
if(($t = $this->level->getTile($this)) !== null){
|
if(($t = $this->world->getTile($this)) !== null){
|
||||||
$t->onBlockDestroyed();
|
$t->onBlockDestroyed();
|
||||||
}
|
}
|
||||||
return $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -370,7 +370,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when this block is updated by the delayed blockupdate scheduler in the level.
|
* Called when this block is updated by the delayed blockupdate scheduler in the world.
|
||||||
*/
|
*/
|
||||||
public function onScheduledUpdate() : void{
|
public function onScheduledUpdate() : void{
|
||||||
|
|
||||||
@ -494,18 +494,19 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @param World $world
|
||||||
*
|
|
||||||
* @param Level $level
|
|
||||||
* @param int $x
|
* @param int $x
|
||||||
* @param int $y
|
* @param int $y
|
||||||
* @param int $z
|
* @param int $z
|
||||||
|
*
|
||||||
|
*@internal
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
final public function position(Level $level, int $x, int $y, int $z) : void{
|
final public function position(World $world, int $x, int $y, int $z) : void{
|
||||||
$this->x = $x;
|
$this->x = $x;
|
||||||
$this->y = $y;
|
$this->y = $y;
|
||||||
$this->z = $z;
|
$this->z = $z;
|
||||||
$this->level = $level;
|
$this->world = $world;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -653,7 +654,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
*/
|
*/
|
||||||
public function getSide(int $side, int $step = 1){
|
public function getSide(int $side, int $step = 1){
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
|
return $this->getWorld()->getBlock(Vector3::getSide($side, $step));
|
||||||
}
|
}
|
||||||
|
|
||||||
return BlockFactory::get(BlockLegacyIds::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
|
return BlockFactory::get(BlockLegacyIds::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
|
||||||
@ -812,13 +813,13 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
|
|
||||||
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{
|
public function setMetadata(string $metadataKey, MetadataValue $newMetadataValue) : void{
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
$this->level->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
$this->world->getBlockMetadata()->setMetadata($this, $metadataKey, $newMetadataValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMetadata(string $metadataKey){
|
public function getMetadata(string $metadataKey){
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
return $this->level->getBlockMetadata()->getMetadata($this, $metadataKey);
|
return $this->world->getBlockMetadata()->getMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -826,7 +827,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
|
|
||||||
public function hasMetadata(string $metadataKey) : bool{
|
public function hasMetadata(string $metadataKey) : bool{
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
return $this->level->getBlockMetadata()->hasMetadata($this, $metadataKey);
|
return $this->world->getBlockMetadata()->hasMetadata($this, $metadataKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -834,7 +835,7 @@ class Block extends Position implements BlockLegacyIds, Metadatable{
|
|||||||
|
|
||||||
public function removeMetadata(string $metadataKey, Plugin $owningPlugin) : void{
|
public function removeMetadata(string $metadataKey, Plugin $owningPlugin) : void{
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
$this->level->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
$this->world->getBlockMetadata()->removeMetadata($this, $metadataKey, $owningPlugin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ use pocketmine\block\utils\TreeType;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\item\ItemIds;
|
use pocketmine\item\ItemIds;
|
||||||
use pocketmine\level\Position;
|
use pocketmine\world\Position;
|
||||||
use pocketmine\tile\Comparator;
|
use pocketmine\tile\Comparator;
|
||||||
use function array_fill;
|
use function array_fill;
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
@ -645,7 +645,7 @@ class BlockFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($pos !== null){
|
if($pos !== null){
|
||||||
$block->position($pos->getLevel(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
|
$block->position($pos->getWorld(), $pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $block;
|
return $block;
|
||||||
|
@ -25,11 +25,11 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\sound\RedstonePowerOffSound;
|
|
||||||
use pocketmine\level\sound\RedstonePowerOnSound;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\sound\RedstonePowerOffSound;
|
||||||
|
use pocketmine\world\sound\RedstonePowerOnSound;
|
||||||
|
|
||||||
abstract class Button extends Flowable{
|
abstract class Button extends Flowable{
|
||||||
|
|
||||||
@ -63,9 +63,9 @@ abstract class Button extends Flowable{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->powered){
|
if(!$this->powered){
|
||||||
$this->powered = true;
|
$this->powered = true;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, $this->getActivationTime());
|
$this->world->scheduleDelayedBlockUpdate($this, $this->getActivationTime());
|
||||||
$this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound());
|
$this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOnSound());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -74,8 +74,8 @@ abstract class Button extends Flowable{
|
|||||||
public function onScheduledUpdate() : void{
|
public function onScheduledUpdate() : void{
|
||||||
if($this->powered){
|
if($this->powered){
|
||||||
$this->powered = false;
|
$this->powered = false;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound());
|
$this->world->addSound($this->add(0.5, 0.5, 0.5), new RedstonePowerOffSound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ class Cactus extends Transparent{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
$down = $this->getSide(Facing::DOWN);
|
||||||
if($down->getId() !== BlockLegacyIds::SAND and $down->getId() !== BlockLegacyIds::CACTUS){
|
if($down->getId() !== BlockLegacyIds::SAND and $down->getId() !== BlockLegacyIds::CACTUS){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}else{
|
}else{
|
||||||
foreach(Facing::HORIZONTAL as $side){
|
foreach(Facing::HORIZONTAL as $side){
|
||||||
$b = $this->getSide($side);
|
$b = $this->getSide($side);
|
||||||
if($b->isSolid()){
|
if($b->isSolid()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,23 +92,23 @@ class Cactus extends Transparent{
|
|||||||
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::CACTUS){
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::CACTUS){
|
||||||
if($this->age === 15){
|
if($this->age === 15){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
|
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
|
||||||
if($b->getId() === BlockLegacyIds::AIR){
|
if($b->getId() === BlockLegacyIds::AIR){
|
||||||
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::CACTUS));
|
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::CACTUS));
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->getLevel()->setBlock($b, $ev->getNewState());
|
$this->getWorld()->setBlock($b, $ev->getNewState());
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->age = 0;
|
$this->age = 0;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}else{
|
}else{
|
||||||
++$this->age;
|
++$this->age;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ class Cake extends Transparent implements FoodSource{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
|
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +125,6 @@ class Cake extends Transparent implements FoodSource{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onConsume(Living $consumer) : void{
|
public function onConsume(Living $consumer) : void{
|
||||||
$this->level->setBlock($this, $this->getResidue());
|
$this->world->setBlock($this, $this->getResidue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ class Carpet extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){
|
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class Chest extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
if(parent::place($item, $blockReplace, $blockClicked, $face, $clickVector, $player)){
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileChest){
|
if($tile instanceof TileChest){
|
||||||
foreach([
|
foreach([
|
||||||
Facing::rotateY($this->facing, true),
|
Facing::rotateY($this->facing, true),
|
||||||
@ -75,7 +75,7 @@ class Chest extends Transparent{
|
|||||||
] as $side){
|
] as $side){
|
||||||
$c = $this->getSide($side);
|
$c = $this->getSide($side);
|
||||||
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
|
if($c instanceof Chest and $c->isSameType($this) and $c->facing === $this->facing){
|
||||||
$pair = $this->level->getTile($c);
|
$pair = $this->world->getTile($c);
|
||||||
if($pair instanceof TileChest and !$pair->isPaired()){
|
if($pair instanceof TileChest and !$pair->isPaired()){
|
||||||
$pair->pairWith($tile);
|
$pair->pairWith($tile);
|
||||||
$tile->pairWith($pair);
|
$tile->pairWith($pair);
|
||||||
@ -94,7 +94,7 @@ class Chest extends Transparent{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
|
|
||||||
$chest = $this->getLevel()->getTile($this);
|
$chest = $this->getWorld()->getTile($this);
|
||||||
if($chest instanceof TileChest){
|
if($chest instanceof TileChest){
|
||||||
if(
|
if(
|
||||||
!$this->getSide(Facing::UP)->isTransparent() or
|
!$this->getSide(Facing::UP)->isTransparent() or
|
||||||
|
@ -34,7 +34,7 @@ class CoarseDirt extends Dirt{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($face === Facing::UP and $item instanceof Hoe){
|
if($face === Facing::UP and $item instanceof Hoe){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ class CocoaBlock extends Transparent{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($this->age < 2 and $item instanceof Fertilizer){
|
if($this->age < 2 and $item instanceof Fertilizer){
|
||||||
$this->age++;
|
$this->age++;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ class CocoaBlock extends Transparent{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$side = $this->getSide(Facing::opposite($this->facing));
|
$side = $this->getSide(Facing::opposite($this->facing));
|
||||||
if(!($side instanceof Wood) or $side->getTreeType() !== TreeType::JUNGLE()){
|
if(!($side instanceof Wood) or $side->getTreeType() !== TreeType::JUNGLE()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ class CocoaBlock extends Transparent{
|
|||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if($this->age < 2 and mt_rand(1, 5) === 1){
|
if($this->age < 2 and mt_rand(1, 5) === 1){
|
||||||
$this->age++;
|
$this->age++;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class ConcretePowder extends Solid implements Fallable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(($block = $this->checkAdjacentWater()) !== null){
|
if(($block = $this->checkAdjacentWater()) !== null){
|
||||||
$this->level->setBlock($this, $block);
|
$this->world->setBlock($this, $block);
|
||||||
}else{
|
}else{
|
||||||
$this->startFalling();
|
$this->startFalling();
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ abstract class Crops extends Flowable{
|
|||||||
$ev = new BlockGrowEvent($this, $block);
|
$ev = new BlockGrowEvent($this, $block);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($this, $ev->getNewState());
|
$this->getWorld()->setBlock($this, $ev->getNewState());
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
@ -81,7 +81,7 @@ abstract class Crops extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::FARMLAND){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ abstract class Crops extends Flowable{
|
|||||||
$ev = new BlockGrowEvent($this, $block);
|
$ev = new BlockGrowEvent($this, $block);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($this, $ev->getNewState());
|
$this->getWorld()->setBlock($this, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class Dandelion extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class DaylightSensor extends Transparent{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->inverted = !$this->inverted;
|
$this->inverted = !$this->inverted;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class DeadBush extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class Dirt extends Solid{
|
|||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($face === Facing::UP and $item instanceof Hoe){
|
if($face === Facing::UP and $item instanceof Hoe){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,13 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\BlockTransaction;
|
|
||||||
use pocketmine\level\sound\DoorSound;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Bearing;
|
use pocketmine\math\Bearing;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\BlockTransaction;
|
||||||
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
|
|
||||||
abstract class Door extends Transparent{
|
abstract class Door extends Transparent{
|
||||||
@ -99,7 +99,7 @@ abstract class Door extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
|
if($this->getSide(Facing::DOWN)->getId() === BlockLegacyIds::AIR){ //Replace with common break method
|
||||||
$this->getLevel()->useBreakOn($this); //this will delete both halves if they exist
|
$this->getWorld()->useBreakOn($this); //this will delete both halves if they exist
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ abstract class Door extends Transparent{
|
|||||||
$topHalf = clone $this;
|
$topHalf = clone $this;
|
||||||
$topHalf->top = true;
|
$topHalf->top = true;
|
||||||
|
|
||||||
$transaction = new BlockTransaction($this->level);
|
$transaction = new BlockTransaction($this->world);
|
||||||
$transaction->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
|
$transaction->addBlock($blockReplace, $this)->addBlock($blockUp, $topHalf);
|
||||||
|
|
||||||
return $transaction->apply();
|
return $transaction->apply();
|
||||||
@ -140,11 +140,11 @@ abstract class Door extends Transparent{
|
|||||||
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
$other = $this->getSide($this->top ? Facing::DOWN : Facing::UP);
|
||||||
if($other instanceof Door and $other->isSameType($this)){
|
if($other instanceof Door and $other->isSameType($this)){
|
||||||
$other->open = $this->open;
|
$other->open = $this->open;
|
||||||
$this->level->setBlock($other, $other);
|
$this->world->setBlock($other, $other);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->addSound($this, new DoorSound());
|
$this->world->addSound($this, new DoorSound());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -24,10 +24,10 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\BlockTransaction;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class DoublePlant extends Flowable{
|
class DoublePlant extends Flowable{
|
||||||
private const BITFLAG_TOP = 0x08;
|
private const BITFLAG_TOP = 0x08;
|
||||||
@ -53,7 +53,7 @@ class DoublePlant extends Flowable{
|
|||||||
$top = clone $this;
|
$top = clone $this;
|
||||||
$top->top = true;
|
$top->top = true;
|
||||||
|
|
||||||
$transaction = new BlockTransaction($this->level);
|
$transaction = new BlockTransaction($this->world);
|
||||||
$transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
|
$transaction->addBlock($blockReplace, $this)->addBlock($blockReplace->getSide(Facing::UP), $top);
|
||||||
return $transaction->apply();
|
return $transaction->apply();
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ class DoublePlant extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){
|
if(!$this->isValidHalfPlant() or (!$this->top and $this->getSide(Facing::DOWN)->isTransparent())){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ use pocketmine\block\utils\FallableTrait;
|
|||||||
use pocketmine\event\block\BlockTeleportEvent;
|
use pocketmine\event\block\BlockTeleportEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\TieredTool;
|
use pocketmine\item\TieredTool;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\particle\DragonEggTeleportParticle;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\particle\DragonEggTeleportParticle;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function max;
|
use function max;
|
||||||
use function min;
|
use function min;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
@ -71,9 +71,9 @@ class DragonEgg extends Transparent implements Fallable{
|
|||||||
|
|
||||||
protected function teleport() : void{
|
protected function teleport() : void{
|
||||||
for($tries = 0; $tries < 16; ++$tries){
|
for($tries = 0; $tries < 16; ++$tries){
|
||||||
$block = $this->level->getBlockAt(
|
$block = $this->world->getBlockAt(
|
||||||
$this->x + mt_rand(-16, 16),
|
$this->x + mt_rand(-16, 16),
|
||||||
max(0, min(Level::Y_MAX - 1, $this->y + mt_rand(-8, 8))),
|
max(0, min(World::Y_MAX - 1, $this->y + mt_rand(-8, 8))),
|
||||||
$this->z + mt_rand(-16, 16)
|
$this->z + mt_rand(-16, 16)
|
||||||
);
|
);
|
||||||
if($block instanceof Air){
|
if($block instanceof Air){
|
||||||
@ -84,9 +84,9 @@ class DragonEgg extends Transparent implements Fallable{
|
|||||||
}else{
|
}else{
|
||||||
$block = $ev->getTo();
|
$block = $ev->getTo();
|
||||||
}
|
}
|
||||||
$this->level->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z));
|
$this->world->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z));
|
||||||
$this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
$this->level->setBlock($block, $this);
|
$this->world->setBlock($block, $this);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class EnderChest extends Transparent{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
$enderChest = $this->getLevel()->getTile($this);
|
$enderChest = $this->getWorld()->getTile($this);
|
||||||
if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){
|
if($enderChest instanceof TileEnderChest and $this->getSide(Facing::UP)->isTransparent()){
|
||||||
$player->getEnderChestInventory()->setHolderPosition($enderChest);
|
$player->getEnderChestInventory()->setHolderPosition($enderChest);
|
||||||
$player->addWindow($player->getEnderChestInventory());
|
$player->addWindow($player->getEnderChestInventory());
|
||||||
|
@ -60,7 +60,7 @@ class Farmland extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::UP)->isSolid()){
|
if($this->getSide(Facing::UP)->isSolid()){
|
||||||
$this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +72,13 @@ class Farmland extends Transparent{
|
|||||||
if(!$this->canHydrate()){
|
if(!$this->canHydrate()){
|
||||||
if($this->wetness > 0){
|
if($this->wetness > 0){
|
||||||
$this->wetness--;
|
$this->wetness--;
|
||||||
$this->level->setBlock($this, $this, false);
|
$this->world->setBlock($this, $this, false);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
||||||
}
|
}
|
||||||
}elseif($this->wetness < 7){
|
}elseif($this->wetness < 7){
|
||||||
$this->wetness = 7;
|
$this->wetness = 7;
|
||||||
$this->level->setBlock($this, $this, false);
|
$this->world->setBlock($this, $this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class Farmland extends Transparent{
|
|||||||
for($y = $start->y; $y <= $end->y; ++$y){
|
for($y = $start->y; $y <= $end->y; ++$y){
|
||||||
for($z = $start->z; $z <= $end->z; ++$z){
|
for($z = $start->z; $z <= $end->z; ++$z){
|
||||||
for($x = $start->x; $x <= $end->x; ++$x){
|
for($x = $start->x; $x <= $end->x; ++$x){
|
||||||
if($this->level->getBlockAt($x, $y, $z) instanceof Water){
|
if($this->world->getBlockAt($x, $y, $z) instanceof Water){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,12 +25,12 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\sound\DoorSound;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Bearing;
|
use pocketmine\math\Bearing;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
class FenceGate extends Transparent{
|
class FenceGate extends Transparent{
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
@ -92,7 +92,7 @@ class FenceGate extends Transparent{
|
|||||||
$inWall = $this->checkInWall();
|
$inWall = $this->checkInWall();
|
||||||
if($inWall !== $this->inWall){
|
if($inWall !== $this->inWall){
|
||||||
$this->inWall = $inWall;
|
$this->inWall = $inWall;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,8 +105,8 @@ class FenceGate extends Transparent{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
$this->level->addSound($this, new DoorSound());
|
$this->world->addSound($this, new DoorSound());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +88,9 @@ class Fire extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
|
if(!$this->getSide(Facing::DOWN)->isSolid() and !$this->hasAdjacentFlammableBlocks()){
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}else{
|
}else{
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,10 +124,10 @@ class Fire extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($result !== null){
|
if($result !== null){
|
||||||
$this->level->setBlock($this, $result);
|
$this->world->setBlock($this, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(30, 40));
|
||||||
|
|
||||||
if($canSpread){
|
if($canSpread){
|
||||||
//TODO: raise upper bound for chance in humid biomes
|
//TODO: raise upper bound for chance in humid biomes
|
||||||
@ -168,9 +168,9 @@ class Fire extends Flowable{
|
|||||||
if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain
|
if(mt_rand(0, $this->age + 9) < 5){ //TODO: check rain
|
||||||
$fire = clone $this;
|
$fire = clone $this;
|
||||||
$fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2));
|
$fire->age = min(15, $fire->age + (mt_rand(0, 4) >> 2));
|
||||||
$this->level->setBlock($block, $fire);
|
$this->world->setBlock($block, $fire);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($block, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class Flower extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class FlowerPot extends Flowable{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileFlowerPot){
|
if($tile instanceof TileFlowerPot){
|
||||||
$this->setPlant($tile->getPlant());
|
$this->setPlant($tile->getPlant());
|
||||||
}else{
|
}else{
|
||||||
@ -67,7 +67,7 @@ class FlowerPot extends Flowable{
|
|||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
|
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
assert($tile instanceof TileFlowerPot);
|
assert($tile instanceof TileFlowerPot);
|
||||||
$tile->setPlant($this->plant);
|
$tile->setPlant($this->plant);
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ class FlowerPot extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ class FlowerPot extends Flowable{
|
|||||||
|
|
||||||
$this->setPlant($plant);
|
$this->setPlant($plant);
|
||||||
$item->pop();
|
$item->pop();
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,17 +50,17 @@ class FrostedIce extends Ice{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->checkAdjacentBlocks(2)){
|
if(!$this->checkAdjacentBlocks(2)){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}else{
|
}else{
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and
|
if((!$this->checkAdjacentBlocks(4) or mt_rand(0, 2) === 0) and
|
||||||
max( //TODO: move this to Level
|
max( //TODO: move this to World
|
||||||
$this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z),
|
$this->world->getHighestAdjacentBlockLight($this->x, $this->y, $this->z),
|
||||||
$this->level->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->level->getSkyLightReduction()
|
$this->world->getHighestAdjacentBlockSkyLight($this->x, $this->y, $this->z) - $this->world->getSkyLightReduction()
|
||||||
) >= 12 - $this->age){
|
) >= 12 - $this->age){
|
||||||
if($this->tryMelt()){
|
if($this->tryMelt()){
|
||||||
foreach($this->getAllSides() as $block){
|
foreach($this->getAllSides() as $block){
|
||||||
@ -70,7 +70,7 @@ class FrostedIce extends Ice{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class FrostedIce extends Ice{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(
|
if(
|
||||||
$this->level->getBlockAt($this->x + $x, $this->y, $this->z + $z) instanceof FrostedIce and
|
$this->world->getBlockAt($this->x + $x, $this->y, $this->z + $z) instanceof FrostedIce and
|
||||||
++$found >= $requirement
|
++$found >= $requirement
|
||||||
){
|
){
|
||||||
return true;
|
return true;
|
||||||
@ -103,13 +103,13 @@ class FrostedIce extends Ice{
|
|||||||
*/
|
*/
|
||||||
private function tryMelt() : bool{
|
private function tryMelt() : bool{
|
||||||
if($this->age >= 3){
|
if($this->age >= 3){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->age++;
|
$this->age++;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
$this->world->scheduleDelayedBlockUpdate($this, mt_rand(20, 40));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ class Furnace extends Solid{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($player instanceof Player){
|
if($player instanceof Player){
|
||||||
$furnace = $this->getLevel()->getTile($this);
|
$furnace = $this->getWorld()->getTile($this);
|
||||||
if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){
|
if($furnace instanceof TileFurnace and $furnace->canOpenWith($item->getCustomName())){
|
||||||
$player->addWindow($furnace->getInventory());
|
$player->addWindow($furnace->getInventory());
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,11 @@ use pocketmine\item\Hoe;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\item\Shovel;
|
use pocketmine\item\Shovel;
|
||||||
use pocketmine\level\generator\object\TallGrass as TallGrassObject;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\Random;
|
use pocketmine\utils\Random;
|
||||||
|
use pocketmine\world\generator\object\TallGrass as TallGrassObject;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Grass extends Solid{
|
class Grass extends Solid{
|
||||||
@ -57,13 +57,13 @@ class Grass extends Solid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
$lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z);
|
$lightAbove = $this->world->getFullLightAt($this->x, $this->y + 1, $this->z);
|
||||||
if($lightAbove < 4 and $this->level->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){
|
if($lightAbove < 4 and $this->world->getBlockAt($this->x, $this->y + 1, $this->z)->getLightFilter() >= 2){
|
||||||
//grass dies
|
//grass dies
|
||||||
$ev = new BlockSpreadEvent($this, $this, BlockFactory::get(BlockLegacyIds::DIRT));
|
$ev = new BlockSpreadEvent($this, $this, BlockFactory::get(BlockLegacyIds::DIRT));
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->level->setBlock($this, $ev->getNewState(), false);
|
$this->world->setBlock($this, $ev->getNewState(), false);
|
||||||
}
|
}
|
||||||
}elseif($lightAbove >= 9){
|
}elseif($lightAbove >= 9){
|
||||||
//try grass spread
|
//try grass spread
|
||||||
@ -72,12 +72,12 @@ class Grass extends Solid{
|
|||||||
$y = mt_rand($this->y - 3, $this->y + 1);
|
$y = mt_rand($this->y - 3, $this->y + 1);
|
||||||
$z = mt_rand($this->z - 1, $this->z + 1);
|
$z = mt_rand($this->z - 1, $this->z + 1);
|
||||||
|
|
||||||
$b = $this->level->getBlockAt($x, $y, $z);
|
$b = $this->world->getBlockAt($x, $y, $z);
|
||||||
if(
|
if(
|
||||||
!($b instanceof Dirt) or
|
!($b instanceof Dirt) or
|
||||||
$b instanceof CoarseDirt or
|
$b instanceof CoarseDirt or
|
||||||
$this->level->getFullLightAt($x, $y + 1, $z) < 4 or
|
$this->world->getFullLightAt($x, $y + 1, $z) < 4 or
|
||||||
$this->level->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
|
$this->world->getBlockAt($x, $y + 1, $z)->getLightFilter() >= 2
|
||||||
){
|
){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ class Grass extends Solid{
|
|||||||
$ev = new BlockSpreadEvent($b, $this, BlockFactory::get(BlockLegacyIds::GRASS));
|
$ev = new BlockSpreadEvent($b, $this, BlockFactory::get(BlockLegacyIds::GRASS));
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->level->setBlock($b, $ev->getNewState(), false);
|
$this->world->setBlock($b, $ev->getNewState(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,17 +97,17 @@ class Grass extends Solid{
|
|||||||
}
|
}
|
||||||
if($item instanceof Fertilizer){
|
if($item instanceof Fertilizer){
|
||||||
$item->pop();
|
$item->pop();
|
||||||
TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2);
|
TallGrassObject::growGrass($this->getWorld(), $this, new Random(mt_rand()), 8, 2);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($item instanceof Hoe){
|
}elseif($item instanceof Hoe){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::FARMLAND));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){
|
}elseif($item instanceof Shovel and $this->getSide(Facing::UP)->getId() === BlockLegacyIds::AIR){
|
||||||
$item->applyDamage(1);
|
$item->applyDamage(1);
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::GRASS_PATH));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::GRASS_PATH));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class GrassPath extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::UP)->isSolid()){
|
if($this->getSide(Facing::UP)->isSolid()){
|
||||||
$this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::DIRT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Ice extends Transparent{
|
|||||||
|
|
||||||
public function onBreak(Item $item, ?Player $player = null) : bool{
|
public function onBreak(Item $item, ?Player $player = null) : bool{
|
||||||
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){
|
if(($player === null or $player->isSurvival()) and !$item->hasEnchantment(Enchantment::SILK_TOUCH())){
|
||||||
return $this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::WATER));
|
return $this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::WATER));
|
||||||
}
|
}
|
||||||
return parent::onBreak($item, $player);
|
return parent::onBreak($item, $player);
|
||||||
}
|
}
|
||||||
@ -57,8 +57,8 @@ class Ice extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){
|
if($this->world->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class ItemFrame extends Flowable{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileItemFrame){
|
if($tile instanceof TileItemFrame){
|
||||||
$this->framedItem = $tile->getItem();
|
$this->framedItem = $tile->getItem();
|
||||||
if($this->framedItem->isNull()){
|
if($this->framedItem->isNull()){
|
||||||
@ -69,7 +69,7 @@ class ItemFrame extends Flowable{
|
|||||||
|
|
||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileItemFrame){
|
if($tile instanceof TileItemFrame){
|
||||||
$tile->setItem($this->framedItem);
|
$tile->setItem($this->framedItem);
|
||||||
$tile->setItemRotation($this->itemRotation);
|
$tile->setItemRotation($this->itemRotation);
|
||||||
@ -151,7 +151,7 @@ class ItemFrame extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -161,16 +161,16 @@ class ItemFrame extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(lcg_value() <= $this->itemDropChance){
|
if(lcg_value() <= $this->itemDropChance){
|
||||||
$this->level->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem());
|
$this->world->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem());
|
||||||
}
|
}
|
||||||
$this->setFramedItem(null);
|
$this->setFramedItem(null);
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){
|
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class Ladder extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method
|
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){ //Replace with common break method
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\event\entity\EntityCombustByBlockEvent;
|
use pocketmine\event\entity\EntityCombustByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\level\sound\BucketEmptyLavaSound;
|
use pocketmine\world\sound\BucketEmptyLavaSound;
|
||||||
use pocketmine\level\sound\BucketFillLavaSound;
|
use pocketmine\world\sound\BucketFillLavaSound;
|
||||||
use pocketmine\level\sound\Sound;
|
use pocketmine\world\sound\Sound;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
|
||||||
class Lava extends Liquid{
|
class Lava extends Liquid{
|
||||||
|
@ -27,10 +27,10 @@ use pocketmine\block\utils\TreeType;
|
|||||||
use pocketmine\event\block\LeavesDecayEvent;
|
use pocketmine\event\block\LeavesDecayEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Leaves extends Transparent{
|
class Leaves extends Transparent{
|
||||||
@ -74,7 +74,7 @@ class Leaves extends Transparent{
|
|||||||
|
|
||||||
|
|
||||||
protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{
|
protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{
|
||||||
$index = Level::blockHash($pos->x, $pos->y, $pos->z);
|
$index = World::blockHash($pos->x, $pos->y, $pos->z);
|
||||||
if(isset($visited[$index])){
|
if(isset($visited[$index])){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -98,7 +98,7 @@ class Leaves extends Transparent{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->noDecay and !$this->checkDecay){
|
if(!$this->noDecay and !$this->checkDecay){
|
||||||
$this->checkDecay = true;
|
$this->checkDecay = true;
|
||||||
$this->getLevel()->setBlock($this, $this, false);
|
$this->getWorld()->setBlock($this, $this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,9 +112,9 @@ class Leaves extends Transparent{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled() or $this->findLog($this)){
|
if($ev->isCancelled() or $this->findLog($this)){
|
||||||
$this->checkDecay = false;
|
$this->checkDecay = false;
|
||||||
$this->getLevel()->setBlock($this, $this, false);
|
$this->getWorld()->setBlock($this, $this, false);
|
||||||
}else{
|
}else{
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,11 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\sound\RedstonePowerOffSound;
|
|
||||||
use pocketmine\level\sound\RedstonePowerOnSound;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\sound\RedstonePowerOffSound;
|
||||||
|
use pocketmine\world\sound\RedstonePowerOnSound;
|
||||||
|
|
||||||
class Lever extends Flowable{
|
class Lever extends Flowable{
|
||||||
protected const BOTTOM = 0;
|
protected const BOTTOM = 0;
|
||||||
@ -106,14 +106,14 @@ class Lever extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->getSide($face)->isSolid()){
|
if(!$this->getSide($face)->isSolid()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->powered = !$this->powered;
|
$this->powered = !$this->powered;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->addSound(
|
$this->world->addSound(
|
||||||
$this->add(0.5, 0.5, 0.5),
|
$this->add(0.5, 0.5, 0.5),
|
||||||
$this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound()
|
$this->powered ? new RedstonePowerOnSound() : new RedstonePowerOffSound()
|
||||||
);
|
);
|
||||||
|
@ -28,11 +28,11 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\event\block\BlockFormEvent;
|
use pocketmine\event\block\BlockFormEvent;
|
||||||
use pocketmine\event\block\BlockSpreadEvent;
|
use pocketmine\event\block\BlockSpreadEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\sound\FizzSound;
|
|
||||||
use pocketmine\level\sound\Sound;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\world\sound\FizzSound;
|
||||||
|
use pocketmine\world\sound\Sound;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function array_fill;
|
use function array_fill;
|
||||||
use function lcg_value;
|
use function lcg_value;
|
||||||
use function min;
|
use function min;
|
||||||
@ -189,7 +189,7 @@ abstract class Liquid extends Transparent{
|
|||||||
}elseif($j === 3){
|
}elseif($j === 3){
|
||||||
++$z;
|
++$z;
|
||||||
}
|
}
|
||||||
$sideBlock = $this->level->getBlockAt($x, $y, $z);
|
$sideBlock = $this->world->getBlockAt($x, $y, $z);
|
||||||
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
|
$blockDecay = $this->getEffectiveFlowDecay($sideBlock);
|
||||||
|
|
||||||
if($blockDecay < 0){
|
if($blockDecay < 0){
|
||||||
@ -197,7 +197,7 @@ abstract class Liquid extends Transparent{
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$blockDecay = $this->getEffectiveFlowDecay($this->level->getBlockAt($x, $y - 1, $z));
|
$blockDecay = $this->getEffectiveFlowDecay($this->world->getBlockAt($x, $y - 1, $z));
|
||||||
|
|
||||||
if($blockDecay >= 0){
|
if($blockDecay >= 0){
|
||||||
$realDecay = $blockDecay - ($decay - 8);
|
$realDecay = $blockDecay - ($decay - 8);
|
||||||
@ -217,14 +217,14 @@ abstract class Liquid extends Transparent{
|
|||||||
|
|
||||||
if($this->falling){
|
if($this->falling){
|
||||||
if(
|
if(
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x, $this->y, $this->z - 1)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x, $this->y, $this->z - 1)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x, $this->y, $this->z + 1)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x, $this->y, $this->z + 1)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x - 1, $this->y, $this->z)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x - 1, $this->y, $this->z)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x + 1, $this->y, $this->z)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x + 1, $this->y, $this->z)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x, $this->y + 1, $this->z - 1)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x, $this->y + 1, $this->z - 1)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x, $this->y + 1, $this->z + 1)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x, $this->y + 1, $this->z + 1)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x - 1, $this->y + 1, $this->z)) or
|
!$this->canFlowInto($this->world->getBlockAt($this->x - 1, $this->y + 1, $this->z)) or
|
||||||
!$this->canFlowInto($this->level->getBlockAt($this->x + 1, $this->y + 1, $this->z))
|
!$this->canFlowInto($this->world->getBlockAt($this->x + 1, $this->y + 1, $this->z))
|
||||||
){
|
){
|
||||||
$vector = $vector->normalize()->add(0, -6, 0);
|
$vector = $vector->normalize()->add(0, -6, 0);
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ abstract class Liquid extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$this->checkForHarden();
|
$this->checkForHarden();
|
||||||
$this->level->scheduleDelayedBlockUpdate($this, $this->tickRate());
|
$this->world->scheduleDelayedBlockUpdate($this, $this->tickRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onScheduledUpdate() : void{
|
public function onScheduledUpdate() : void{
|
||||||
@ -264,10 +264,10 @@ abstract class Liquid extends Transparent{
|
|||||||
if(!$this->isSource()){
|
if(!$this->isSource()){
|
||||||
$smallestFlowDecay = -100;
|
$smallestFlowDecay = -100;
|
||||||
$this->adjacentSources = 0;
|
$this->adjacentSources = 0;
|
||||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x, $this->y, $this->z - 1), $smallestFlowDecay);
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x, $this->y, $this->z - 1), $smallestFlowDecay);
|
||||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x, $this->y, $this->z + 1), $smallestFlowDecay);
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x, $this->y, $this->z + 1), $smallestFlowDecay);
|
||||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x - 1, $this->y, $this->z), $smallestFlowDecay);
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x - 1, $this->y, $this->z), $smallestFlowDecay);
|
||||||
$smallestFlowDecay = $this->getSmallestFlowDecay($this->level->getBlockAt($this->x + 1, $this->y, $this->z), $smallestFlowDecay);
|
$smallestFlowDecay = $this->getSmallestFlowDecay($this->world->getBlockAt($this->x + 1, $this->y, $this->z), $smallestFlowDecay);
|
||||||
|
|
||||||
$newDecay = $smallestFlowDecay + $multiplier;
|
$newDecay = $smallestFlowDecay + $multiplier;
|
||||||
$falling = false;
|
$falling = false;
|
||||||
@ -276,12 +276,12 @@ abstract class Liquid extends Transparent{
|
|||||||
$newDecay = -1;
|
$newDecay = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->getEffectiveFlowDecay($this->level->getBlockAt($this->x, $this->y + 1, $this->z)) >= 0){
|
if($this->getEffectiveFlowDecay($this->world->getBlockAt($this->x, $this->y + 1, $this->z)) >= 0){
|
||||||
$falling = true;
|
$falling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->adjacentSources >= 2 and $this instanceof Water){
|
if($this->adjacentSources >= 2 and $this instanceof Water){
|
||||||
$bottomBlock = $this->level->getBlockAt($this->x, $this->y - 1, $this->z);
|
$bottomBlock = $this->world->getBlockAt($this->x, $this->y - 1, $this->z);
|
||||||
if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){
|
if($bottomBlock->isSolid() or ($bottomBlock instanceof Water and $bottomBlock->isSource())){
|
||||||
$newDecay = 0;
|
$newDecay = 0;
|
||||||
$falling = false;
|
$falling = false;
|
||||||
@ -290,17 +290,17 @@ abstract class Liquid extends Transparent{
|
|||||||
|
|
||||||
if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){
|
if($falling !== $this->falling or (!$falling and $newDecay !== $this->decay)){
|
||||||
if(!$falling and $newDecay < 0){
|
if(!$falling and $newDecay < 0){
|
||||||
$this->level->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->falling = $falling;
|
$this->falling = $falling;
|
||||||
$this->decay = $falling ? 0 : $newDecay;
|
$this->decay = $falling ? 0 : $newDecay;
|
||||||
$this->level->setBlock($this, $this); //local block update will cause an update to be scheduled
|
$this->world->setBlock($this, $this); //local block update will cause an update to be scheduled
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$bottomBlock = $this->level->getBlockAt($this->x, $this->y - 1, $this->z);
|
$bottomBlock = $this->world->getBlockAt($this->x, $this->y - 1, $this->z);
|
||||||
|
|
||||||
$this->flowIntoBlock($bottomBlock, 0, true);
|
$this->flowIntoBlock($bottomBlock, 0, true);
|
||||||
|
|
||||||
@ -315,19 +315,19 @@ abstract class Liquid extends Transparent{
|
|||||||
$flags = $this->getOptimalFlowDirections();
|
$flags = $this->getOptimalFlowDirections();
|
||||||
|
|
||||||
if($flags[0]){
|
if($flags[0]){
|
||||||
$this->flowIntoBlock($this->level->getBlockAt($this->x - 1, $this->y, $this->z), $adjacentDecay, false);
|
$this->flowIntoBlock($this->world->getBlockAt($this->x - 1, $this->y, $this->z), $adjacentDecay, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($flags[1]){
|
if($flags[1]){
|
||||||
$this->flowIntoBlock($this->level->getBlockAt($this->x + 1, $this->y, $this->z), $adjacentDecay, false);
|
$this->flowIntoBlock($this->world->getBlockAt($this->x + 1, $this->y, $this->z), $adjacentDecay, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($flags[2]){
|
if($flags[2]){
|
||||||
$this->flowIntoBlock($this->level->getBlockAt($this->x, $this->y, $this->z - 1), $adjacentDecay, false);
|
$this->flowIntoBlock($this->world->getBlockAt($this->x, $this->y, $this->z - 1), $adjacentDecay, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($flags[3]){
|
if($flags[3]){
|
||||||
$this->flowIntoBlock($this->level->getBlockAt($this->x, $this->y, $this->z + 1), $adjacentDecay, false);
|
$this->flowIntoBlock($this->world->getBlockAt($this->x, $this->y, $this->z + 1), $adjacentDecay, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,10 +345,10 @@ abstract class Liquid extends Transparent{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
if($block->getId() > 0){
|
if($block->getId() > 0){
|
||||||
$this->level->useBreakOn($block);
|
$this->world->useBreakOn($block);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->setBlock($block, $ev->getNewState());
|
$this->world->setBlock($block, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -375,11 +375,11 @@ abstract class Liquid extends Transparent{
|
|||||||
++$z;
|
++$z;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($this->flowCostVisited[$hash = Level::blockHash($x, $y, $z)])){
|
if(!isset($this->flowCostVisited[$hash = World::blockHash($x, $y, $z)])){
|
||||||
$blockSide = $this->level->getBlockAt($x, $y, $z);
|
$blockSide = $this->world->getBlockAt($x, $y, $z);
|
||||||
if(!$this->canFlowInto($blockSide)){
|
if(!$this->canFlowInto($blockSide)){
|
||||||
$this->flowCostVisited[$hash] = self::BLOCKED;
|
$this->flowCostVisited[$hash] = self::BLOCKED;
|
||||||
}elseif($this->level->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
|
}elseif($this->world->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
|
||||||
$this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN;
|
$this->flowCostVisited[$hash] = self::CAN_FLOW_DOWN;
|
||||||
}else{
|
}else{
|
||||||
$this->flowCostVisited[$hash] = self::CAN_FLOW;
|
$this->flowCostVisited[$hash] = self::CAN_FLOW;
|
||||||
@ -428,16 +428,16 @@ abstract class Liquid extends Transparent{
|
|||||||
}elseif($j === 3){
|
}elseif($j === 3){
|
||||||
++$z;
|
++$z;
|
||||||
}
|
}
|
||||||
$block = $this->level->getBlockAt($x, $y, $z);
|
$block = $this->world->getBlockAt($x, $y, $z);
|
||||||
|
|
||||||
if(!$this->canFlowInto($block)){
|
if(!$this->canFlowInto($block)){
|
||||||
$this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::BLOCKED;
|
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::BLOCKED;
|
||||||
continue;
|
continue;
|
||||||
}elseif($this->level->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
|
}elseif($this->world->getBlockAt($x, $y - 1, $z)->canBeFlowedInto()){
|
||||||
$this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN;
|
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW_DOWN;
|
||||||
$flowCost[$j] = $maxCost = 0;
|
$flowCost[$j] = $maxCost = 0;
|
||||||
}elseif($maxCost > 0){
|
}elseif($maxCost > 0){
|
||||||
$this->flowCostVisited[Level::blockHash($x, $y, $z)] = self::CAN_FLOW;
|
$this->flowCostVisited[World::blockHash($x, $y, $z)] = self::CAN_FLOW;
|
||||||
$flowCost[$j] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $j ^ 0x01, $j ^ 0x01);
|
$flowCost[$j] = $this->calculateFlowCost($x, $y, $z, 1, $maxCost, $j ^ 0x01, $j ^ 0x01);
|
||||||
$maxCost = min($maxCost, $flowCost[$j]);
|
$maxCost = min($maxCost, $flowCost[$j]);
|
||||||
}
|
}
|
||||||
@ -480,13 +480,13 @@ abstract class Liquid extends Transparent{
|
|||||||
$ev = new BlockFormEvent($this, $result);
|
$ev = new BlockFormEvent($this, $result);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->level->setBlock($this, $ev->getNewState());
|
$this->world->setBlock($this, $ev->getNewState());
|
||||||
$this->level->addSound($this->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8));
|
$this->world->addSound($this->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function canFlowInto(Block $block) : bool{
|
protected function canFlowInto(Block $block) : bool{
|
||||||
return $this->level->isInWorld($block->x, $block->y, $block->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type
|
return $this->world->isInWorld($block->x, $block->y, $block->z) and $block->canBeFlowedInto() and !($block instanceof Liquid and $block->isSource()); //TODO: I think this should only be liquids of the same type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,13 +54,13 @@ class Mycelium extends Solid{
|
|||||||
$x = mt_rand($this->x - 1, $this->x + 1);
|
$x = mt_rand($this->x - 1, $this->x + 1);
|
||||||
$y = mt_rand($this->y - 2, $this->y + 2);
|
$y = mt_rand($this->y - 2, $this->y + 2);
|
||||||
$z = mt_rand($this->z - 1, $this->z + 1);
|
$z = mt_rand($this->z - 1, $this->z + 1);
|
||||||
$block = $this->getLevel()->getBlockAt($x, $y, $z);
|
$block = $this->getWorld()->getBlockAt($x, $y, $z);
|
||||||
if($block->getId() === BlockLegacyIds::DIRT){
|
if($block->getId() === BlockLegacyIds::DIRT){
|
||||||
if($block->getSide(Facing::UP) instanceof Transparent){
|
if($block->getSide(Facing::UP) instanceof Transparent){
|
||||||
$ev = new BlockSpreadEvent($block, $this, BlockFactory::get(BlockLegacyIds::MYCELIUM));
|
$ev = new BlockSpreadEvent($block, $this, BlockFactory::get(BlockLegacyIds::MYCELIUM));
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($block, $ev->getNewState());
|
$this->getWorld()->setBlock($block, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class NetherWartPlant extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SOUL_SAND){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ class NetherWartPlant extends Flowable{
|
|||||||
$ev = new BlockGrowEvent($this, $block);
|
$ev = new BlockGrowEvent($this, $block);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($this, $ev->getNewState());
|
$this->getWorld()->setBlock($this, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class RedMushroom extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ class RedstoneComparator extends Flowable{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof Comparator){
|
if($tile instanceof Comparator){
|
||||||
$this->signalStrength = $tile->getSignalStrength();
|
$this->signalStrength = $tile->getSignalStrength();
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ class RedstoneComparator extends Flowable{
|
|||||||
|
|
||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
assert($tile instanceof Comparator);
|
assert($tile instanceof Comparator);
|
||||||
$tile->setSignalStrength($this->signalStrength);
|
$tile->setSignalStrength($this->signalStrength);
|
||||||
}
|
}
|
||||||
@ -158,13 +158,13 @@ class RedstoneComparator extends Flowable{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->isSubtractMode = !$this->isSubtractMode;
|
$this->isSubtractMode = !$this->isSubtractMode;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +72,13 @@ class RedstoneOre extends Solid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
return $this->getLevel()->setBlock($this, $this, false);
|
return $this->getWorld()->setBlock($this, $this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if(!$this->lit){
|
if(!$this->lit){
|
||||||
$this->lit = true;
|
$this->lit = true;
|
||||||
$this->getLevel()->setBlock($this, $this); //no return here - this shouldn't prevent block placement
|
$this->getWorld()->setBlock($this, $this); //no return here - this shouldn't prevent block placement
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ class RedstoneOre extends Solid{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!$this->lit){
|
if(!$this->lit){
|
||||||
$this->lit = true;
|
$this->lit = true;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ class RedstoneOre extends Solid{
|
|||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if($this->lit){
|
if($this->lit){
|
||||||
$this->lit = false;
|
$this->lit = false;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,13 +98,13 @@ class RedstoneRepeater extends Flowable{
|
|||||||
if(++$this->delay > 4){
|
if(++$this->delay > 4){
|
||||||
$this->delay = 1;
|
$this->delay = 1;
|
||||||
}
|
}
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,11 +26,11 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\block\utils\TreeType;
|
use pocketmine\block\utils\TreeType;
|
||||||
use pocketmine\item\Fertilizer;
|
use pocketmine\item\Fertilizer;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\generator\object\Tree;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\Random;
|
use pocketmine\utils\Random;
|
||||||
|
use pocketmine\world\generator\object\Tree;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Sapling extends Flowable{
|
class Sapling extends Flowable{
|
||||||
@ -68,7 +68,7 @@ class Sapling extends Flowable{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($item instanceof Fertilizer){
|
if($item instanceof Fertilizer){
|
||||||
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);
|
Tree::growTree($this->getWorld(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ class Sapling extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){
|
if($this->getSide(Facing::DOWN)->isTransparent()){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,12 +89,12 @@ class Sapling extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if($this->level->getFullLightAt($this->x, $this->y, $this->z) >= 8 and mt_rand(1, 7) === 1){
|
if($this->world->getFullLightAt($this->x, $this->y, $this->z) >= 8 and mt_rand(1, 7) === 1){
|
||||||
if($this->ready){
|
if($this->ready){
|
||||||
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);
|
Tree::growTree($this->getWorld(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->treeType);
|
||||||
}else{
|
}else{
|
||||||
$this->ready = true;
|
$this->ready = true;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ class Sign extends Transparent{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileSign){
|
if($tile instanceof TileSign){
|
||||||
$this->text = $tile->getText();
|
$this->text = $tile->getText();
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ class Sign extends Transparent{
|
|||||||
|
|
||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
assert($tile instanceof TileSign);
|
assert($tile instanceof TileSign);
|
||||||
$tile->setText($this->text);
|
$tile->setText($this->text);
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class Sign extends Transparent{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
|
if($this->getSide(Facing::opposite($this->facing))->getId() === BlockLegacyIds::AIR){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ class Sign extends Transparent{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->text = clone $ev->getNewText();
|
$this->text = clone $ev->getNewText();
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class Skull extends Flowable{
|
|||||||
|
|
||||||
public function readStateFromWorld() : void{
|
public function readStateFromWorld() : void{
|
||||||
parent::readStateFromWorld();
|
parent::readStateFromWorld();
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
if($tile instanceof TileSkull){
|
if($tile instanceof TileSkull){
|
||||||
$this->skullType = $tile->getSkullType();
|
$this->skullType = $tile->getSkullType();
|
||||||
$this->rotation = $tile->getRotation();
|
$this->rotation = $tile->getRotation();
|
||||||
@ -75,7 +75,7 @@ class Skull extends Flowable{
|
|||||||
public function writeStateToWorld() : void{
|
public function writeStateToWorld() : void{
|
||||||
parent::writeStateToWorld();
|
parent::writeStateToWorld();
|
||||||
//extra block properties storage hack
|
//extra block properties storage hack
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->world->getTile($this);
|
||||||
assert($tile instanceof TileSkull);
|
assert($tile instanceof TileSkull);
|
||||||
$tile->setRotation($this->rotation);
|
$tile->setRotation($this->rotation);
|
||||||
$tile->setSkullType($this->skullType);
|
$tile->setSkullType($this->skullType);
|
||||||
|
@ -95,8 +95,8 @@ class SnowLayer extends Flowable implements Fallable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onRandomTick() : void{
|
public function onRandomTick() : void{
|
||||||
if($this->level->getBlockLightAt($this->x, $this->y, $this->z) >= 12){
|
if($this->world->getBlockLightAt($this->x, $this->y, $this->z) >= 12){
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR), false);
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ abstract class Stem extends Crops{
|
|||||||
$ev = new BlockGrowEvent($this, $block);
|
$ev = new BlockGrowEvent($this, $block);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($this, $ev->getNewState());
|
$this->getWorld()->setBlock($this, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$grow = $this->getPlant();
|
$grow = $this->getPlant();
|
||||||
@ -57,7 +57,7 @@ abstract class Stem extends Crops{
|
|||||||
$ev = new BlockGrowEvent($side, $grow);
|
$ev = new BlockGrowEvent($side, $grow);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($side, $ev->getNewState());
|
$this->getWorld()->setBlock($side, $ev->getNewState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,20 +52,20 @@ class Sugarcane extends Flowable{
|
|||||||
if($item instanceof Fertilizer){
|
if($item instanceof Fertilizer){
|
||||||
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
|
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
|
||||||
if($b->getId() === BlockLegacyIds::AIR){
|
if($b->getId() === BlockLegacyIds::AIR){
|
||||||
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
|
$ev = new BlockGrowEvent($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->getLevel()->setBlock($b, $ev->getNewState());
|
$this->getWorld()->setBlock($b, $ev->getNewState());
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->age = 0;
|
$this->age = 0;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
@ -79,7 +79,7 @@ class Sugarcane extends Flowable{
|
|||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$down = $this->getSide(Facing::DOWN);
|
$down = $this->getSide(Facing::DOWN);
|
||||||
if($down->isTransparent() and $down->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
if($down->isTransparent() and $down->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,17 +91,17 @@ class Sugarcane extends Flowable{
|
|||||||
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
if($this->getSide(Facing::DOWN)->getId() !== BlockLegacyIds::SUGARCANE_BLOCK){
|
||||||
if($this->age === 15){
|
if($this->age === 15){
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
$b = $this->getLevel()->getBlockAt($this->x, $this->y + $y, $this->z);
|
$b = $this->getWorld()->getBlockAt($this->x, $this->y + $y, $this->z);
|
||||||
if($b->getId() === BlockLegacyIds::AIR){
|
if($b->getId() === BlockLegacyIds::AIR){
|
||||||
$this->getLevel()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
|
$this->getWorld()->setBlock($b, BlockFactory::get(BlockLegacyIds::SUGARCANE_BLOCK));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->age = 0;
|
$this->age = 0;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}else{
|
}else{
|
||||||
++$this->age;
|
++$this->age;
|
||||||
$this->getLevel()->setBlock($this, $this);
|
$this->getWorld()->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,14 +90,14 @@ class TNT extends Solid{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function ignite(int $fuse = 80) : void{
|
public function ignite(int $fuse = 80) : void{
|
||||||
$this->getLevel()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->getWorld()->setBlock($this, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
|
|
||||||
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
||||||
$nbt = EntityFactory::createBaseNBT($this->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));
|
$nbt = EntityFactory::createBaseNBT($this->add(0.5, 0, 0.5), new Vector3(-sin($mot) * 0.02, 0.2, -cos($mot) * 0.02));
|
||||||
$nbt->setShort("Fuse", $fuse);
|
$nbt->setShort("Fuse", $fuse);
|
||||||
|
|
||||||
/** @var PrimedTNT $tnt */
|
/** @var PrimedTNT $tnt */
|
||||||
$tnt = EntityFactory::create(PrimedTNT::class, $this->getLevel(), $nbt);
|
$tnt = EntityFactory::create(PrimedTNT::class, $this->getWorld(), $nbt);
|
||||||
$tnt->spawnToAll();
|
$tnt->spawnToAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class TallGrass extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method
|
if($this->getSide(Facing::DOWN)->isTransparent()){ //Replace with common break method
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class Torch extends Flowable{
|
|||||||
$face = Facing::opposite($this->facing);
|
$face = Facing::opposite($this->facing);
|
||||||
|
|
||||||
if($this->getSide($face)->isTransparent() and !($face === Facing::DOWN and ($below->getId() === BlockLegacyIds::FENCE or $below->getId() === BlockLegacyIds::COBBLESTONE_WALL))){
|
if($this->getSide($face)->isTransparent() and !($face === Facing::DOWN and ($below->getId() === BlockLegacyIds::FENCE or $below->getId() === BlockLegacyIds::COBBLESTONE_WALL))){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,11 @@ namespace pocketmine\block;
|
|||||||
|
|
||||||
use pocketmine\block\utils\BlockDataValidator;
|
use pocketmine\block\utils\BlockDataValidator;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\sound\DoorSound;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\sound\DoorSound;
|
||||||
|
|
||||||
class Trapdoor extends Transparent{
|
class Trapdoor extends Transparent{
|
||||||
private const MASK_UPPER = 0x04;
|
private const MASK_UPPER = 0x04;
|
||||||
@ -79,8 +79,8 @@ class Trapdoor extends Transparent{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->open = !$this->open;
|
$this->open = !$this->open;
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
$this->level->addSound($this, new DoorSound());
|
$this->world->addSound($this, new DoorSound());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,9 +170,9 @@ class Vine extends Flowable{
|
|||||||
|
|
||||||
if($changed){
|
if($changed){
|
||||||
if(empty($this->faces)){
|
if(empty($this->faces)){
|
||||||
$this->level->useBreakOn($this);
|
$this->world->useBreakOn($this);
|
||||||
}else{
|
}else{
|
||||||
$this->level->setBlock($this, $this);
|
$this->world->setBlock($this, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\level\sound\BucketEmptyWaterSound;
|
use pocketmine\world\sound\BucketEmptyWaterSound;
|
||||||
use pocketmine\level\sound\BucketFillWaterSound;
|
use pocketmine\world\sound\BucketFillWaterSound;
|
||||||
use pocketmine\level\sound\Sound;
|
use pocketmine\world\sound\Sound;
|
||||||
|
|
||||||
class Water extends Liquid{
|
class Water extends Liquid{
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class WaterLily extends Flowable{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if(!($this->getSide(Facing::DOWN) instanceof Water)){
|
if(!($this->getSide(Facing::DOWN) instanceof Water)){
|
||||||
$this->getLevel()->useBreakOn($this);
|
$this->getWorld()->useBreakOn($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ use pocketmine\block\Fire;
|
|||||||
use pocketmine\block\Liquid;
|
use pocketmine\block\Liquid;
|
||||||
use pocketmine\entity\EntityFactory;
|
use pocketmine\entity\EntityFactory;
|
||||||
use pocketmine\entity\object\FallingBlock;
|
use pocketmine\entity\object\FallingBlock;
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trait handles falling behaviour for blocks that need them.
|
* This trait handles falling behaviour for blocks that need them.
|
||||||
@ -47,16 +47,16 @@ trait FallableTrait{
|
|||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
$pos = $this->asPosition();
|
$pos = $this->asPosition();
|
||||||
$down = $pos->level->getBlock($pos->getSide(Facing::DOWN));
|
$down = $pos->world->getBlock($pos->getSide(Facing::DOWN));
|
||||||
if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){
|
if($down->getId() === BlockLegacyIds::AIR or $down instanceof Liquid or $down instanceof Fire){
|
||||||
$pos->level->setBlock($pos, BlockFactory::get(BlockLegacyIds::AIR));
|
$pos->world->setBlock($pos, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
|
|
||||||
$nbt = EntityFactory::createBaseNBT($pos->add(0.5, 0, 0.5));
|
$nbt = EntityFactory::createBaseNBT($pos->add(0.5, 0, 0.5));
|
||||||
$nbt->setInt("TileID", $this->getId());
|
$nbt->setInt("TileID", $this->getId());
|
||||||
$nbt->setByte("Data", $this->getMeta());
|
$nbt->setByte("Data", $this->getMeta());
|
||||||
|
|
||||||
/** @var FallingBlock $fall */
|
/** @var FallingBlock $fall */
|
||||||
$fall = EntityFactory::create(FallingBlock::class, $pos->getLevel(), $nbt);
|
$fall = EntityFactory::create(FallingBlock::class, $pos->getWorld(), $nbt);
|
||||||
$fall->spawnToAll();
|
$fall->spawnToAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ use pocketmine\command\Command;
|
|||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\world\World;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
class DifficultyCommand extends VanillaCommand{
|
class DifficultyCommand extends VanillaCommand{
|
||||||
@ -50,18 +50,18 @@ class DifficultyCommand extends VanillaCommand{
|
|||||||
throw new InvalidCommandSyntaxException();
|
throw new InvalidCommandSyntaxException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$difficulty = Level::getDifficultyFromString($args[0]);
|
$difficulty = World::getDifficultyFromString($args[0]);
|
||||||
|
|
||||||
if($sender->getServer()->isHardcore()){
|
if($sender->getServer()->isHardcore()){
|
||||||
$difficulty = Level::DIFFICULTY_HARD;
|
$difficulty = World::DIFFICULTY_HARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($difficulty !== -1){
|
if($difficulty !== -1){
|
||||||
$sender->getServer()->setConfigInt("difficulty", $difficulty);
|
$sender->getServer()->setConfigInt("difficulty", $difficulty);
|
||||||
|
|
||||||
//TODO: add per-world support
|
//TODO: add per-world support
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->setDifficulty($difficulty);
|
$world->setDifficulty($difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.difficulty.success", [$difficulty]));
|
||||||
|
@ -51,13 +51,13 @@ class GarbageCollectorCommand extends VanillaCommand{
|
|||||||
|
|
||||||
$memory = memory_get_usage();
|
$memory = memory_get_usage();
|
||||||
|
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$diff = [count($level->getChunks()), count($level->getEntities())];
|
$diff = [count($world->getChunks()), count($world->getEntities())];
|
||||||
$level->doChunkGarbageCollection();
|
$world->doChunkGarbageCollection();
|
||||||
$level->unloadChunks(true);
|
$world->unloadChunks(true);
|
||||||
$chunksCollected += $diff[0] - count($level->getChunks());
|
$chunksCollected += $diff[0] - count($world->getChunks());
|
||||||
$entitiesCollected += $diff[1] - count($level->getEntities());
|
$entitiesCollected += $diff[1] - count($world->getEntities());
|
||||||
$level->clearCache(true);
|
$world->clearCache(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector();
|
$cyclesCollected = $sender->getServer()->getMemoryManager()->triggerGarbageCollector();
|
||||||
|
@ -29,39 +29,39 @@ use pocketmine\command\utils\InvalidCommandSyntaxException;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\particle\AngryVillagerParticle;
|
|
||||||
use pocketmine\level\particle\BlockForceFieldParticle;
|
|
||||||
use pocketmine\level\particle\BubbleParticle;
|
|
||||||
use pocketmine\level\particle\CriticalParticle;
|
|
||||||
use pocketmine\level\particle\DustParticle;
|
|
||||||
use pocketmine\level\particle\EnchantmentTableParticle;
|
|
||||||
use pocketmine\level\particle\EnchantParticle;
|
|
||||||
use pocketmine\level\particle\ExplodeParticle;
|
|
||||||
use pocketmine\level\particle\FlameParticle;
|
|
||||||
use pocketmine\level\particle\HappyVillagerParticle;
|
|
||||||
use pocketmine\level\particle\HeartParticle;
|
|
||||||
use pocketmine\level\particle\HugeExplodeParticle;
|
|
||||||
use pocketmine\level\particle\HugeExplodeSeedParticle;
|
|
||||||
use pocketmine\level\particle\InkParticle;
|
|
||||||
use pocketmine\level\particle\InstantEnchantParticle;
|
|
||||||
use pocketmine\level\particle\ItemBreakParticle;
|
|
||||||
use pocketmine\level\particle\LavaDripParticle;
|
|
||||||
use pocketmine\level\particle\LavaParticle;
|
|
||||||
use pocketmine\level\particle\Particle;
|
|
||||||
use pocketmine\level\particle\PortalParticle;
|
|
||||||
use pocketmine\level\particle\RainSplashParticle;
|
|
||||||
use pocketmine\level\particle\RedstoneParticle;
|
|
||||||
use pocketmine\level\particle\SmokeParticle;
|
|
||||||
use pocketmine\level\particle\SplashParticle;
|
|
||||||
use pocketmine\level\particle\SporeParticle;
|
|
||||||
use pocketmine\level\particle\TerrainParticle;
|
|
||||||
use pocketmine\level\particle\WaterDripParticle;
|
|
||||||
use pocketmine\level\particle\WaterParticle;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\Random;
|
use pocketmine\utils\Random;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\world\particle\AngryVillagerParticle;
|
||||||
|
use pocketmine\world\particle\BlockForceFieldParticle;
|
||||||
|
use pocketmine\world\particle\BubbleParticle;
|
||||||
|
use pocketmine\world\particle\CriticalParticle;
|
||||||
|
use pocketmine\world\particle\DustParticle;
|
||||||
|
use pocketmine\world\particle\EnchantmentTableParticle;
|
||||||
|
use pocketmine\world\particle\EnchantParticle;
|
||||||
|
use pocketmine\world\particle\ExplodeParticle;
|
||||||
|
use pocketmine\world\particle\FlameParticle;
|
||||||
|
use pocketmine\world\particle\HappyVillagerParticle;
|
||||||
|
use pocketmine\world\particle\HeartParticle;
|
||||||
|
use pocketmine\world\particle\HugeExplodeParticle;
|
||||||
|
use pocketmine\world\particle\HugeExplodeSeedParticle;
|
||||||
|
use pocketmine\world\particle\InkParticle;
|
||||||
|
use pocketmine\world\particle\InstantEnchantParticle;
|
||||||
|
use pocketmine\world\particle\ItemBreakParticle;
|
||||||
|
use pocketmine\world\particle\LavaDripParticle;
|
||||||
|
use pocketmine\world\particle\LavaParticle;
|
||||||
|
use pocketmine\world\particle\Particle;
|
||||||
|
use pocketmine\world\particle\PortalParticle;
|
||||||
|
use pocketmine\world\particle\RainSplashParticle;
|
||||||
|
use pocketmine\world\particle\RedstoneParticle;
|
||||||
|
use pocketmine\world\particle\SmokeParticle;
|
||||||
|
use pocketmine\world\particle\SplashParticle;
|
||||||
|
use pocketmine\world\particle\SporeParticle;
|
||||||
|
use pocketmine\world\particle\TerrainParticle;
|
||||||
|
use pocketmine\world\particle\WaterDripParticle;
|
||||||
|
use pocketmine\world\particle\WaterParticle;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function count;
|
use function count;
|
||||||
use function explode;
|
use function explode;
|
||||||
use function max;
|
use function max;
|
||||||
@ -91,14 +91,14 @@ class ParticleCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($sender instanceof Player){
|
if($sender instanceof Player){
|
||||||
$level = $sender->getLevel();
|
$world = $sender->getWorld();
|
||||||
$pos = new Vector3(
|
$pos = new Vector3(
|
||||||
$this->getRelativeDouble($sender->getX(), $sender, $args[1]),
|
$this->getRelativeDouble($sender->getX(), $sender, $args[1]),
|
||||||
$this->getRelativeDouble($sender->getY(), $sender, $args[2], 0, Level::Y_MAX),
|
$this->getRelativeDouble($sender->getY(), $sender, $args[2], 0, World::Y_MAX),
|
||||||
$this->getRelativeDouble($sender->getZ(), $sender, $args[3])
|
$this->getRelativeDouble($sender->getZ(), $sender, $args[3])
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
$level = $sender->getServer()->getLevelManager()->getDefaultLevel();
|
$world = $sender->getServer()->getWorldManager()->getDefaultWorld();
|
||||||
$pos = new Vector3((float) $args[1], (float) $args[2], (float) $args[3]);
|
$pos = new Vector3((float) $args[1], (float) $args[2], (float) $args[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class ParticleCommand extends VanillaCommand{
|
|||||||
$random = new Random((int) (microtime(true) * 1000) + mt_rand());
|
$random = new Random((int) (microtime(true) * 1000) + mt_rand());
|
||||||
|
|
||||||
for($i = 0; $i < $count; ++$i){
|
for($i = 0; $i < $count; ++$i){
|
||||||
$level->addParticle($pos->add(
|
$world->addParticle($pos->add(
|
||||||
$random->nextSignedFloat() * $xd,
|
$random->nextSignedFloat() * $xd,
|
||||||
$random->nextSignedFloat() * $yd,
|
$random->nextSignedFloat() * $yd,
|
||||||
$random->nextSignedFloat() * $zd
|
$random->nextSignedFloat() * $zd
|
||||||
|
@ -52,8 +52,8 @@ class SaveCommand extends VanillaCommand{
|
|||||||
$player->save();
|
$player->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->save(true);
|
$world->save(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("pocketmine.save.success", [round(microtime(true) - $start, 3)]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("pocketmine.save.success", [round(microtime(true) - $start, 3)]));
|
||||||
|
@ -43,7 +43,7 @@ class SaveOffCommand extends VanillaCommand{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sender->getServer()->getLevelManager()->setAutoSave(false);
|
$sender->getServer()->getWorldManager()->setAutoSave(false);
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.disabled"));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.disabled"));
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class SaveOnCommand extends VanillaCommand{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sender->getServer()->getLevelManager()->setAutoSave(true);
|
$sender->getServer()->getWorldManager()->setAutoSave(true);
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.enabled"));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.save.enabled"));
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ class SeedCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($sender instanceof Player){
|
if($sender instanceof Player){
|
||||||
$seed = $sender->getLevel()->getSeed();
|
$seed = $sender->getWorld()->getSeed();
|
||||||
}else{
|
}else{
|
||||||
$seed = $sender->getServer()->getLevelManager()->getDefaultLevel()->getSeed();
|
$seed = $sender->getServer()->getWorldManager()->getDefaultWorld()->getSeed();
|
||||||
}
|
}
|
||||||
$sender->sendMessage(new TranslationContainer("commands.seed.success", [$seed]));
|
$sender->sendMessage(new TranslationContainer("commands.seed.success", [$seed]));
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class SetWorldSpawnCommand extends VanillaCommand{
|
|||||||
|
|
||||||
if(count($args) === 0){
|
if(count($args) === 0){
|
||||||
if($sender instanceof Player){
|
if($sender instanceof Player){
|
||||||
$level = $sender->getLevel();
|
$world = $sender->getWorld();
|
||||||
$pos = (new Vector3($sender->x, $sender->y, $sender->z))->round();
|
$pos = (new Vector3($sender->x, $sender->y, $sender->z))->round();
|
||||||
}else{
|
}else{
|
||||||
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");
|
$sender->sendMessage(TextFormat::RED . "You can only perform this command as a player");
|
||||||
@ -59,13 +59,13 @@ class SetWorldSpawnCommand extends VanillaCommand{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}elseif(count($args) === 3){
|
}elseif(count($args) === 3){
|
||||||
$level = $sender->getServer()->getLevelManager()->getDefaultLevel();
|
$world = $sender->getServer()->getWorldManager()->getDefaultWorld();
|
||||||
$pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2]));
|
$pos = new Vector3($this->getInteger($sender, $args[0]), $this->getInteger($sender, $args[1]), $this->getInteger($sender, $args[2]));
|
||||||
}else{
|
}else{
|
||||||
throw new InvalidCommandSyntaxException();
|
throw new InvalidCommandSyntaxException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$level->setSpawnLocation($pos);
|
$world->setSpawnLocation($pos);
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.setworldspawn.success", [round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.setworldspawn.success", [round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@ use pocketmine\command\Command;
|
|||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function count;
|
use function count;
|
||||||
use function round;
|
use function round;
|
||||||
|
|
||||||
@ -71,12 +71,12 @@ class SpawnpointCommand extends VanillaCommand{
|
|||||||
|
|
||||||
if(count($args) === 4){
|
if(count($args) === 4){
|
||||||
if($target->isValid()){
|
if($target->isValid()){
|
||||||
$level = $target->getLevel();
|
$world = $target->getWorld();
|
||||||
$pos = $sender instanceof Player ? $sender->getPosition() : $level->getSpawnLocation();
|
$pos = $sender instanceof Player ? $sender->getPosition() : $world->getSpawnLocation();
|
||||||
$x = $this->getRelativeDouble($pos->x, $sender, $args[1]);
|
$x = $this->getRelativeDouble($pos->x, $sender, $args[1]);
|
||||||
$y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, Level::Y_MAX);
|
$y = $this->getRelativeDouble($pos->y, $sender, $args[2], 0, World::Y_MAX);
|
||||||
$z = $this->getRelativeDouble($pos->z, $sender, $args[3]);
|
$z = $this->getRelativeDouble($pos->z, $sender, $args[3]);
|
||||||
$target->setSpawn(new Position($x, $y, $z, $level));
|
$target->setSpawn(new Position($x, $y, $z, $world));
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($x, 2), round($y, 2), round($z, 2)]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($x, 2), round($y, 2), round($z, 2)]));
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ class SpawnpointCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
}elseif(count($args) <= 1){
|
}elseif(count($args) <= 1){
|
||||||
if($sender instanceof Player){
|
if($sender instanceof Player){
|
||||||
$pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getLevel());
|
$pos = new Position($sender->getFloorX(), $sender->getFloorY(), $sender->getFloorZ(), $sender->getWorld());
|
||||||
$target->setSpawn($pos);
|
$target->setSpawn($pos);
|
||||||
|
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.spawnpoint.success", [$target->getName(), round($pos->x, 2), round($pos->y, 2), round($pos->z, 2)]));
|
||||||
|
@ -107,13 +107,13 @@ class StatusCommand extends VanillaCommand{
|
|||||||
$sender->sendMessage(TextFormat::GOLD . "Maximum memory (manager): " . TextFormat::RED . number_format(round($globalLimit, 2), 2) . " MB.");
|
$sender->sendMessage(TextFormat::GOLD . "Maximum memory (manager): " . TextFormat::RED . number_format(round($globalLimit, 2), 2) . " MB.");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($server->getLevelManager()->getLevels() as $level){
|
foreach($server->getWorldManager()->getWorlds() as $world){
|
||||||
$levelName = $level->getFolderName() !== $level->getDisplayName() ? " (" . $level->getDisplayName() . ")" : "";
|
$worldName = $world->getFolderName() !== $world->getDisplayName() ? " (" . $world->getDisplayName() . ")" : "";
|
||||||
$timeColor = $level->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW;
|
$timeColor = $world->getTickRateTime() > 40 ? TextFormat::RED : TextFormat::YELLOW;
|
||||||
$sender->sendMessage(TextFormat::GOLD . "World \"{$level->getFolderName()}\"$levelName: " .
|
$sender->sendMessage(TextFormat::GOLD . "World \"{$world->getFolderName()}\"$worldName: " .
|
||||||
TextFormat::RED . number_format(count($level->getChunks())) . TextFormat::GREEN . " chunks, " .
|
TextFormat::RED . number_format(count($world->getChunks())) . TextFormat::GREEN . " chunks, " .
|
||||||
TextFormat::RED . number_format(count($level->getEntities())) . TextFormat::GREEN . " entities. " .
|
TextFormat::RED . number_format(count($world->getEntities())) . TextFormat::GREEN . " entities. " .
|
||||||
"Time $timeColor" . round($level->getTickRateTime(), 2) . "ms"
|
"Time $timeColor" . round($world->getTickRateTime(), 2) . "ms"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ use pocketmine\command\Command;
|
|||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||||
use pocketmine\lang\TranslationContainer;
|
use pocketmine\lang\TranslationContainer;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\TextFormat;
|
use pocketmine\utils\TextFormat;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
class TimeCommand extends VanillaCommand{
|
class TimeCommand extends VanillaCommand{
|
||||||
@ -54,8 +54,8 @@ class TimeCommand extends VanillaCommand{
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->startTime();
|
$world->startTime();
|
||||||
}
|
}
|
||||||
Command::broadcastCommandMessage($sender, "Restarted the time");
|
Command::broadcastCommandMessage($sender, "Restarted the time");
|
||||||
return true;
|
return true;
|
||||||
@ -65,8 +65,8 @@ class TimeCommand extends VanillaCommand{
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->stopTime();
|
$world->stopTime();
|
||||||
}
|
}
|
||||||
Command::broadcastCommandMessage($sender, "Stopped the time");
|
Command::broadcastCommandMessage($sender, "Stopped the time");
|
||||||
return true;
|
return true;
|
||||||
@ -77,11 +77,11 @@ class TimeCommand extends VanillaCommand{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if($sender instanceof Player){
|
if($sender instanceof Player){
|
||||||
$level = $sender->getLevel();
|
$world = $sender->getWorld();
|
||||||
}else{
|
}else{
|
||||||
$level = $sender->getServer()->getLevelManager()->getDefaultLevel();
|
$world = $sender->getServer()->getWorldManager()->getDefaultWorld();
|
||||||
}
|
}
|
||||||
$sender->sendMessage(new TranslationContainer("commands.time.query", [$level->getTime()]));
|
$sender->sendMessage(new TranslationContainer("commands.time.query", [$world->getTime()]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,15 +98,15 @@ class TimeCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($args[1] === "day"){
|
if($args[1] === "day"){
|
||||||
$value = Level::TIME_DAY;
|
$value = World::TIME_DAY;
|
||||||
}elseif($args[1] === "night"){
|
}elseif($args[1] === "night"){
|
||||||
$value = Level::TIME_NIGHT;
|
$value = World::TIME_NIGHT;
|
||||||
}else{
|
}else{
|
||||||
$value = $this->getInteger($sender, $args[1], 0);
|
$value = $this->getInteger($sender, $args[1], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->setTime($value);
|
$world->setTime($value);
|
||||||
}
|
}
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.set", [$value]));
|
||||||
}elseif($args[0] === "add"){
|
}elseif($args[0] === "add"){
|
||||||
@ -117,8 +117,8 @@ class TimeCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->getInteger($sender, $args[1], 0);
|
$value = $this->getInteger($sender, $args[1], 0);
|
||||||
foreach($sender->getServer()->getLevelManager()->getLevels() as $level){
|
foreach($sender->getServer()->getWorldManager()->getWorlds() as $world){
|
||||||
$level->setTime($level->getTime() + $value);
|
$world->setTime($world->getTime() + $value);
|
||||||
}
|
}
|
||||||
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value]));
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.time.added", [$value]));
|
||||||
}else{
|
}else{
|
||||||
|
@ -30,15 +30,11 @@ use pocketmine\block\Block;
|
|||||||
use pocketmine\block\Water;
|
use pocketmine\block\Water;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\EntityDespawnEvent;
|
use pocketmine\event\entity\EntityDespawnEvent;
|
||||||
use pocketmine\event\entity\EntityLevelChangeEvent;
|
|
||||||
use pocketmine\event\entity\EntityMotionEvent;
|
use pocketmine\event\entity\EntityMotionEvent;
|
||||||
use pocketmine\event\entity\EntityRegainHealthEvent;
|
use pocketmine\event\entity\EntityRegainHealthEvent;
|
||||||
use pocketmine\event\entity\EntitySpawnEvent;
|
use pocketmine\event\entity\EntitySpawnEvent;
|
||||||
use pocketmine\event\entity\EntityTeleportEvent;
|
use pocketmine\event\entity\EntityTeleportEvent;
|
||||||
use pocketmine\level\format\Chunk;
|
use pocketmine\event\entity\EntityWorldChangeEvent;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\Location;
|
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Bearing;
|
use pocketmine\math\Bearing;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -67,6 +63,10 @@ use pocketmine\plugin\Plugin;
|
|||||||
use pocketmine\Server;
|
use pocketmine\Server;
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\timings\TimingsHandler;
|
use pocketmine\timings\TimingsHandler;
|
||||||
|
use pocketmine\world\format\Chunk;
|
||||||
|
use pocketmine\world\Location;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function abs;
|
use function abs;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function cos;
|
use function cos;
|
||||||
@ -199,7 +199,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
/** @var TimingsHandler */
|
/** @var TimingsHandler */
|
||||||
protected $timings;
|
protected $timings;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
public function __construct(World $world, CompoundTag $nbt){
|
||||||
$this->timings = Timings::getEntityTimings($this);
|
$this->timings = Timings::getEntityTimings($this);
|
||||||
|
|
||||||
$this->temporalVector = new Vector3();
|
$this->temporalVector = new Vector3();
|
||||||
@ -209,20 +209,20 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->id = EntityFactory::nextRuntimeId();
|
$this->id = EntityFactory::nextRuntimeId();
|
||||||
$this->server = $level->getServer();
|
$this->server = $world->getServer();
|
||||||
|
|
||||||
/** @var float[] $pos */
|
/** @var float[] $pos */
|
||||||
$pos = $nbt->getListTag("Pos")->getAllValues();
|
$pos = $nbt->getListTag("Pos")->getAllValues();
|
||||||
/** @var float[] $rotation */
|
/** @var float[] $rotation */
|
||||||
$rotation = $nbt->getListTag("Rotation")->getAllValues();
|
$rotation = $nbt->getListTag("Rotation")->getAllValues();
|
||||||
|
|
||||||
parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $level);
|
parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $world);
|
||||||
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
|
assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z));
|
||||||
|
|
||||||
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||||
$this->recalculateBoundingBox();
|
$this->recalculateBoundingBox();
|
||||||
|
|
||||||
$this->chunk = $this->level->getChunkAtPosition($this, false);
|
$this->chunk = $this->world->getChunkAtPosition($this, false);
|
||||||
if($this->chunk === null){
|
if($this->chunk === null){
|
||||||
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
|
throw new \InvalidStateException("Cannot create entities in unloaded chunks");
|
||||||
}
|
}
|
||||||
@ -256,7 +256,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$this->propertyManager->clearDirtyProperties(); //Prevents resending properties that were set during construction
|
$this->propertyManager->clearDirtyProperties(); //Prevents resending properties that were set during construction
|
||||||
|
|
||||||
$this->chunk->addEntity($this);
|
$this->chunk->addEntity($this);
|
||||||
$this->level->addEntity($this);
|
$this->world->addEntity($this);
|
||||||
|
|
||||||
$this->lastUpdate = $this->server->getTick();
|
$this->lastUpdate = $this->server->getTick();
|
||||||
(new EntitySpawnEvent($this))->call();
|
(new EntitySpawnEvent($this))->call();
|
||||||
@ -450,7 +450,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
public function getOwningEntity() : ?Entity{
|
public function getOwningEntity() : ?Entity{
|
||||||
$eid = $this->getOwningEntityId();
|
$eid = $this->getOwningEntityId();
|
||||||
if($eid !== null){
|
if($eid !== null){
|
||||||
return $this->server->getLevelManager()->findEntity($eid);
|
return $this->server->getWorldManager()->findEntity($eid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -490,7 +490,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
public function getTargetEntity() : ?Entity{
|
public function getTargetEntity() : ?Entity{
|
||||||
$eid = $this->getTargetEntityId();
|
$eid = $this->getTargetEntityId();
|
||||||
if($eid !== null){
|
if($eid !== null){
|
||||||
return $this->server->getLevelManager()->findEntity($eid);
|
return $this->server->getWorldManager()->findEntity($eid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -871,7 +871,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT;
|
$pk->flags |= MoveEntityAbsolutePacket::FLAG_TELEPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->broadcastPacketToViewers($this, $pk);
|
$this->world->broadcastPacketToViewers($this, $pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function broadcastMotion() : void{
|
protected function broadcastMotion() : void{
|
||||||
@ -879,7 +879,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$pk->entityRuntimeId = $this->id;
|
$pk->entityRuntimeId = $this->id;
|
||||||
$pk->motion = $this->getMotion();
|
$pk->motion = $this->getMotion();
|
||||||
|
|
||||||
$this->level->broadcastPacketToViewers($this, $pk);
|
$this->world->broadcastPacketToViewers($this, $pk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasGravity() : bool{
|
public function hasGravity() : bool{
|
||||||
@ -914,7 +914,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->onGround){
|
if($this->onGround){
|
||||||
$friction *= $this->level->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor();
|
$friction *= $this->world->getBlockAt((int) floor($this->x), (int) floor($this->y - 1), (int) floor($this->z))->getFrictionFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->motion->x *= $friction;
|
$this->motion->x *= $friction;
|
||||||
@ -922,7 +922,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function checkObstruction(float $x, float $y, float $z) : bool{
|
protected function checkObstruction(float $x, float $y, float $z) : bool{
|
||||||
if(count($this->level->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){
|
if(count($this->world->getCollisionBoxes($this, $this->getBoundingBox(), false)) === 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -934,13 +934,13 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$diffY = $y - $floorY;
|
$diffY = $y - $floorY;
|
||||||
$diffZ = $z - $floorZ;
|
$diffZ = $z - $floorZ;
|
||||||
|
|
||||||
if($this->level->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){
|
if($this->world->getBlockAt($floorX, $floorY, $floorZ)->isSolid()){
|
||||||
$westNonSolid = !$this->level->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid();
|
$westNonSolid = !$this->world->getBlockAt($floorX - 1, $floorY, $floorZ)->isSolid();
|
||||||
$eastNonSolid = !$this->level->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid();
|
$eastNonSolid = !$this->world->getBlockAt($floorX + 1, $floorY, $floorZ)->isSolid();
|
||||||
$downNonSolid = !$this->level->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid();
|
$downNonSolid = !$this->world->getBlockAt($floorX, $floorY - 1, $floorZ)->isSolid();
|
||||||
$upNonSolid = !$this->level->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid();
|
$upNonSolid = !$this->world->getBlockAt($floorX, $floorY + 1, $floorZ)->isSolid();
|
||||||
$northNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid();
|
$northNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ - 1)->isSolid();
|
||||||
$southNonSolid = !$this->level->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid();
|
$southNonSolid = !$this->world->getBlockAt($floorX, $floorY, $floorZ + 1)->isSolid();
|
||||||
|
|
||||||
$direction = -1;
|
$direction = -1;
|
||||||
$limit = 9999;
|
$limit = 9999;
|
||||||
@ -1105,7 +1105,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
if($this->closed){
|
if($this->closed){
|
||||||
throw new \InvalidStateException("Cannot schedule update on garbage entity " . get_class($this));
|
throw new \InvalidStateException("Cannot schedule update on garbage entity " . get_class($this));
|
||||||
}
|
}
|
||||||
$this->level->updateEntities[$this->id] = $this;
|
$this->world->updateEntities[$this->id] = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
@ -1176,7 +1176,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isUnderwater() : bool{
|
public function isUnderwater() : bool{
|
||||||
$block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
|
$block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
|
||||||
|
|
||||||
if($block instanceof Water){
|
if($block instanceof Water){
|
||||||
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
|
||||||
@ -1187,7 +1187,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isInsideOfSolid() : bool{
|
public function isInsideOfSolid() : bool{
|
||||||
$block = $this->level->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
|
$block = $this->world->getBlockAt((int) floor($this->x), (int) floor($y = ($this->y + $this->getEyeHeight())), (int) floor($this->z));
|
||||||
|
|
||||||
return $block->isSolid() and !$block->isTransparent() and $block->collidesWithBB($this->getBoundingBox());
|
return $block->isSolid() and !$block->isTransparent() and $block->collidesWithBB($this->getBoundingBox());
|
||||||
}
|
}
|
||||||
@ -1223,7 +1223,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
/*$sneakFlag = $this->onGround and $this instanceof Player;
|
/*$sneakFlag = $this->onGround and $this instanceof Player;
|
||||||
|
|
||||||
if($sneakFlag){
|
if($sneakFlag){
|
||||||
for($mov = 0.05; $dx != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
|
for($mov = 0.05; $dx != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox($dx, -1, 0))) === 0; $movX = $dx){
|
||||||
if($dx < $mov and $dx >= -$mov){
|
if($dx < $mov and $dx >= -$mov){
|
||||||
$dx = 0;
|
$dx = 0;
|
||||||
}elseif($dx > 0){
|
}elseif($dx > 0){
|
||||||
@ -1233,7 +1233,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; $dz != 0.0 and count($this->level->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
|
for(; $dz != 0.0 and count($this->world->getCollisionCubes($this, $this->boundingBox->getOffsetBoundingBox(0, -1, $dz))) === 0; $movZ = $dz){
|
||||||
if($dz < $mov and $dz >= -$mov){
|
if($dz < $mov and $dz >= -$mov){
|
||||||
$dz = 0;
|
$dz = 0;
|
||||||
}elseif($dz > 0){
|
}elseif($dz > 0){
|
||||||
@ -1249,7 +1249,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
|
assert(abs($dx) <= 20 and abs($dy) <= 20 and abs($dz) <= 20, "Movement distance is excessive: dx=$dx, dy=$dy, dz=$dz");
|
||||||
|
|
||||||
//TODO: bad hack here will cause unexpected behaviour under heavy lag
|
//TODO: bad hack here will cause unexpected behaviour under heavy lag
|
||||||
$list = $this->level->getCollisionBoxes($this, $this->level->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
$list = $this->world->getCollisionBoxes($this, $this->world->getTickRateTime() > 50 ? $this->boundingBox->offsetCopy($dx, $dy, $dz) : $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||||
|
|
||||||
foreach($list as $bb){
|
foreach($list as $bb){
|
||||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||||
@ -1284,7 +1284,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
|
|
||||||
$this->boundingBox->setBB($axisalignedbb);
|
$this->boundingBox->setBB($axisalignedbb);
|
||||||
|
|
||||||
$list = $this->level->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
$list = $this->world->getCollisionBoxes($this, $this->boundingBox->addCoord($dx, $dy, $dz), false);
|
||||||
|
|
||||||
foreach($list as $bb){
|
foreach($list as $bb){
|
||||||
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
$dy = $bb->calculateYOffset($this->boundingBox, $dy);
|
||||||
@ -1367,7 +1367,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
for($z = $minZ; $z <= $maxZ; ++$z){
|
for($z = $minZ; $z <= $maxZ; ++$z){
|
||||||
for($x = $minX; $x <= $maxX; ++$x){
|
for($x = $minX; $x <= $maxX; ++$x){
|
||||||
for($y = $minY; $y <= $maxY; ++$y){
|
for($y = $minY; $y <= $maxY; ++$y){
|
||||||
$block = $this->level->getBlockAt($x, $y, $z);
|
$block = $this->world->getBlockAt($x, $y, $z);
|
||||||
if($block->hasEntityCollision()){
|
if($block->hasEntityCollision()){
|
||||||
$this->blocksAround[] = $block;
|
$this->blocksAround[] = $block;
|
||||||
}
|
}
|
||||||
@ -1418,8 +1418,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
|
if($pos instanceof Position and $pos->world !== null and $pos->world !== $this->world){
|
||||||
if(!$this->switchLevel($pos->getLevel())){
|
if(!$this->switchWorld($pos->getWorld())){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1460,10 +1460,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
if($this->chunk !== null){
|
if($this->chunk !== null){
|
||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
}
|
}
|
||||||
$this->chunk = $this->level->getChunk($chunkX, $chunkZ, true);
|
$this->chunk = $this->world->getChunk($chunkX, $chunkZ, true);
|
||||||
|
|
||||||
if(!$this->justCreated){
|
if(!$this->justCreated){
|
||||||
$newChunk = $this->level->getViewersForPosition($this);
|
$newChunk = $this->world->getViewersForPosition($this);
|
||||||
foreach($this->hasSpawned as $player){
|
foreach($this->hasSpawned as $player){
|
||||||
if(!isset($newChunk[spl_object_id($player)])){
|
if(!isset($newChunk[spl_object_id($player)])){
|
||||||
$this->despawnFrom($player);
|
$this->despawnFrom($player);
|
||||||
@ -1540,8 +1540,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$yaw = $yaw ?? $pos->yaw;
|
$yaw = $yaw ?? $pos->yaw;
|
||||||
$pitch = $pitch ?? $pos->pitch;
|
$pitch = $pitch ?? $pos->pitch;
|
||||||
}
|
}
|
||||||
$from = Position::fromObject($this, $this->level);
|
$from = Position::fromObject($this, $this->world);
|
||||||
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
|
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getWorld() : $this->world);
|
||||||
$ev = new EntityTeleportEvent($this, $from, $to);
|
$ev = new EntityTeleportEvent($this, $from, $to);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
@ -1563,27 +1563,27 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function switchLevel(Level $targetLevel) : bool{
|
protected function switchWorld(World $targetWorld) : bool{
|
||||||
if($this->closed){
|
if($this->closed){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
$ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel);
|
$ev = new EntityWorldChangeEvent($this, $this->world, $targetWorld);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->removeEntity($this);
|
$this->world->removeEntity($this);
|
||||||
if($this->chunk !== null){
|
if($this->chunk !== null){
|
||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
}
|
}
|
||||||
$this->despawnFromAll();
|
$this->despawnFromAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setLevel($targetLevel);
|
$this->setWorld($targetWorld);
|
||||||
$this->level->addEntity($this);
|
$this->world->addEntity($this);
|
||||||
$this->chunk = null;
|
$this->chunk = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1636,7 +1636,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
if($this->chunk === null or $this->closed){
|
if($this->chunk === null or $this->closed){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach($this->level->getViewersForPosition($this) as $player){
|
foreach($this->world->getViewersForPosition($this) as $player){
|
||||||
if($player->isOnline()){
|
if($player->isOnline()){
|
||||||
$this->spawnTo($player);
|
$this->spawnTo($player);
|
||||||
}
|
}
|
||||||
@ -1717,7 +1717,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
}
|
}
|
||||||
if($this->isValid()){
|
if($this->isValid()){
|
||||||
$this->level->removeEntity($this);
|
$this->world->removeEntity($this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1729,7 +1729,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
*/
|
*/
|
||||||
protected function destroyCycles() : void{
|
protected function destroyCycles() : void{
|
||||||
$this->chunk = null;
|
$this->chunk = null;
|
||||||
$this->setLevel(null);
|
$this->setWorld(null);
|
||||||
$this->lastDamageCause = null;
|
$this->lastDamageCause = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ use pocketmine\entity\projectile\EnderPearl;
|
|||||||
use pocketmine\entity\projectile\ExperienceBottle;
|
use pocketmine\entity\projectile\ExperienceBottle;
|
||||||
use pocketmine\entity\projectile\Snowball;
|
use pocketmine\entity\projectile\Snowball;
|
||||||
use pocketmine\entity\projectile\SplashPotion;
|
use pocketmine\entity\projectile\SplashPotion;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\DoubleTag;
|
use pocketmine\nbt\tag\DoubleTag;
|
||||||
@ -45,6 +44,7 @@ use pocketmine\nbt\tag\IntTag;
|
|||||||
use pocketmine\nbt\tag\ListTag;
|
use pocketmine\nbt\tag\ListTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\utils\Utils;
|
use pocketmine\utils\Utils;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function array_keys;
|
use function array_keys;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function in_array;
|
use function in_array;
|
||||||
@ -174,20 +174,20 @@ final class EntityFactory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an entity with the specified type, level and NBT, with optional additional arguments to pass to the
|
* Creates an entity with the specified type, world and NBT, with optional additional arguments to pass to the
|
||||||
* entity's constructor.
|
* entity's constructor.
|
||||||
*
|
*
|
||||||
* TODO: make this NBT-independent
|
* TODO: make this NBT-independent
|
||||||
*
|
*
|
||||||
* @param string $baseClass
|
* @param string $baseClass
|
||||||
* @param Level $level
|
* @param World $world
|
||||||
* @param CompoundTag $nbt
|
* @param CompoundTag $nbt
|
||||||
* @param mixed ...$args
|
* @param mixed ...$args
|
||||||
*
|
*
|
||||||
* @return Entity instanceof $baseClass
|
* @return Entity instanceof $baseClass
|
||||||
* @throws \InvalidArgumentException if the class doesn't exist or is not registered
|
* @throws \InvalidArgumentException if the class doesn't exist or is not registered
|
||||||
*/
|
*/
|
||||||
public static function create(string $baseClass, Level $level, CompoundTag $nbt, ...$args) : Entity{
|
public static function create(string $baseClass, World $world, CompoundTag $nbt, ...$args) : Entity{
|
||||||
if(isset(self::$classMapping[$baseClass])){
|
if(isset(self::$classMapping[$baseClass])){
|
||||||
$class = self::$classMapping[$baseClass];
|
$class = self::$classMapping[$baseClass];
|
||||||
assert(is_a($class, $baseClass, true));
|
assert(is_a($class, $baseClass, true));
|
||||||
@ -195,7 +195,7 @@ final class EntityFactory{
|
|||||||
* @var Entity $entity
|
* @var Entity $entity
|
||||||
* @see Entity::__construct()
|
* @see Entity::__construct()
|
||||||
*/
|
*/
|
||||||
$entity = new $class($level, $nbt, ...$args);
|
$entity = new $class($world, $nbt, ...$args);
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
@ -205,15 +205,16 @@ final class EntityFactory{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an entity from data stored on a chunk.
|
* Creates an entity from data stored on a chunk.
|
||||||
* @internal
|
|
||||||
*
|
*
|
||||||
* @param Level $level
|
* @param World $world
|
||||||
* @param CompoundTag $nbt
|
* @param CompoundTag $nbt
|
||||||
*
|
*
|
||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
|
*@internal
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public static function createFromData(Level $level, CompoundTag $nbt) : ?Entity{
|
public static function createFromData(World $world, CompoundTag $nbt) : ?Entity{
|
||||||
$saveId = $nbt->getTag("id") ?? $nbt->getTag("identifier");
|
$saveId = $nbt->getTag("id") ?? $nbt->getTag("identifier");
|
||||||
$baseClass = null;
|
$baseClass = null;
|
||||||
if($saveId instanceof StringTag){
|
if($saveId instanceof StringTag){
|
||||||
@ -230,7 +231,7 @@ final class EntityFactory{
|
|||||||
* @var Entity $entity
|
* @var Entity $entity
|
||||||
* @see Entity::__construct()
|
* @see Entity::__construct()
|
||||||
*/
|
*/
|
||||||
$entity = new $class($level, $nbt);
|
$entity = new $class($world, $nbt);
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,6 @@ use pocketmine\item\enchantment\Enchantment;
|
|||||||
use pocketmine\item\FoodSource;
|
use pocketmine\item\FoodSource;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\Totem;
|
use pocketmine\item\Totem;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\sound\TotemUseSound;
|
|
||||||
use pocketmine\level\sound\XpCollectSound;
|
|
||||||
use pocketmine\level\sound\XpLevelUpSound;
|
|
||||||
use pocketmine\nbt\NBT;
|
use pocketmine\nbt\NBT;
|
||||||
use pocketmine\nbt\tag\ByteArrayTag;
|
use pocketmine\nbt\tag\ByteArrayTag;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
@ -62,6 +58,10 @@ use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
|||||||
use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags;
|
use pocketmine\network\mcpe\protocol\types\PlayerMetadataFlags;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
use pocketmine\utils\UUID;
|
use pocketmine\utils\UUID;
|
||||||
|
use pocketmine\world\sound\TotemUseSound;
|
||||||
|
use pocketmine\world\sound\XpCollectSound;
|
||||||
|
use pocketmine\world\sound\XpLevelUpSound;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_rand;
|
use function array_rand;
|
||||||
@ -101,7 +101,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
|
|
||||||
protected $baseOffset = 1.62;
|
protected $baseOffset = 1.62;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
public function __construct(World $world, CompoundTag $nbt){
|
||||||
if($this->skin === null){
|
if($this->skin === null){
|
||||||
$skinTag = $nbt->getCompoundTag("Skin");
|
$skinTag = $nbt->getCompoundTag("Skin");
|
||||||
if($skinTag === null or !self::isValidSkin($skinTag->hasTag("Data", ByteArrayTag::class) ?
|
if($skinTag === null or !self::isValidSkin($skinTag->hasTag("Data", ByteArrayTag::class) ?
|
||||||
@ -112,7 +112,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($level, $nbt);
|
parent::__construct($world, $nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -350,7 +350,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
if($playSound){
|
if($playSound){
|
||||||
$newLevel = $this->getXpLevel();
|
$newLevel = $this->getXpLevel();
|
||||||
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
|
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
|
||||||
$this->level->addSound($this, new XpLevelUpSound($newLevel));
|
$this->world->addSound($this, new XpLevelUpSound($newLevel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,9 +442,9 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
if($playSound){
|
if($playSound){
|
||||||
$newLevel = $this->getXpLevel();
|
$newLevel = $this->getXpLevel();
|
||||||
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
|
if((int) ($newLevel / 5) > (int) ($oldLevel / 5)){
|
||||||
$this->level->addSound($this, new XpLevelUpSound($newLevel));
|
$this->world->addSound($this, new XpLevelUpSound($newLevel));
|
||||||
}elseif($this->getCurrentTotalXp() > $oldTotal){
|
}elseif($this->getCurrentTotalXp() > $oldTotal){
|
||||||
$this->level->addSound($this, new XpCollectSound());
|
$this->world->addSound($this, new XpCollectSound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,14 +696,14 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
if($this->isAlive()){
|
if($this->isAlive()){
|
||||||
$food = $this->getFood();
|
$food = $this->getFood();
|
||||||
$health = $this->getHealth();
|
$health = $this->getHealth();
|
||||||
$difficulty = $this->level->getDifficulty();
|
$difficulty = $this->world->getDifficulty();
|
||||||
|
|
||||||
$this->foodTickTimer += $tickDiff;
|
$this->foodTickTimer += $tickDiff;
|
||||||
if($this->foodTickTimer >= 80){
|
if($this->foodTickTimer >= 80){
|
||||||
$this->foodTickTimer = 0;
|
$this->foodTickTimer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($difficulty === Level::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){
|
if($difficulty === World::DIFFICULTY_PEACEFUL and $this->foodTickTimer % 10 === 0){
|
||||||
if($food < $this->getMaxFood()){
|
if($food < $this->getMaxFood()){
|
||||||
$this->addFood(1.0);
|
$this->addFood(1.0);
|
||||||
$food = $this->getFood();
|
$food = $this->getFood();
|
||||||
@ -720,7 +720,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
$this->exhaust(3.0, PlayerExhaustEvent::CAUSE_HEALTH_REGEN);
|
||||||
}
|
}
|
||||||
}elseif($food <= 0){
|
}elseif($food <= 0){
|
||||||
if(($difficulty === Level::DIFFICULTY_EASY and $health > 10) or ($difficulty === Level::DIFFICULTY_NORMAL and $health > 1) or $difficulty === Level::DIFFICULTY_HARD){
|
if(($difficulty === World::DIFFICULTY_EASY and $health > 10) or ($difficulty === World::DIFFICULTY_NORMAL and $health > 1) or $difficulty === World::DIFFICULTY_HARD){
|
||||||
$this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
|
$this->attack(new EntityDamageEvent($this, EntityDamageEvent::CAUSE_STARVATION, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -761,7 +761,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
$this->addEffect(new EffectInstance(Effect::ABSORPTION(), 5 * 20, 1));
|
$this->addEffect(new EffectInstance(Effect::ABSORPTION(), 5 * 20, 1));
|
||||||
|
|
||||||
$this->broadcastEntityEvent(EntityEventPacket::CONSUME_TOTEM);
|
$this->broadcastEntityEvent(EntityEventPacket::CONSUME_TOTEM);
|
||||||
$this->level->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound());
|
$this->world->addSound($this->add(0, $this->eyeHeight, 0), new TotemUseSound());
|
||||||
|
|
||||||
$hand = $this->inventory->getItemInHand();
|
$hand = $this->inventory->getItemInHand();
|
||||||
if($hand instanceof Totem){
|
if($hand instanceof Totem){
|
||||||
|
@ -40,7 +40,6 @@ use pocketmine\item\Consumable;
|
|||||||
use pocketmine\item\Durable;
|
use pocketmine\item\Durable;
|
||||||
use pocketmine\item\enchantment\Enchantment;
|
use pocketmine\item\enchantment\Enchantment;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\level\sound\ItemBreakSound;
|
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\math\VoxelRayTrace;
|
use pocketmine\math\VoxelRayTrace;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
@ -54,6 +53,7 @@ use pocketmine\Player;
|
|||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
use pocketmine\utils\Color;
|
use pocketmine\utils\Color;
|
||||||
|
use pocketmine\world\sound\ItemBreakSound;
|
||||||
use function abs;
|
use function abs;
|
||||||
use function array_shift;
|
use function array_shift;
|
||||||
use function atan2;
|
use function atan2;
|
||||||
@ -546,7 +546,7 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
private function damageItem(Durable $item, int $durabilityRemoved) : void{
|
private function damageItem(Durable $item, int $durabilityRemoved) : void{
|
||||||
$item->applyDamage($durabilityRemoved);
|
$item->applyDamage($durabilityRemoved);
|
||||||
if($item->isBroken()){
|
if($item->isBroken()){
|
||||||
$this->level->addSound($this, new ItemBreakSound());
|
$this->world->addSound($this, new ItemBreakSound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -598,7 +598,7 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
$source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE or
|
$source->getCause() === EntityDamageEvent::CAUSE_PROJECTILE or
|
||||||
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK
|
$source->getCause() === EntityDamageEvent::CAUSE_ENTITY_ATTACK
|
||||||
) and $e->isOnFire()){
|
) and $e->isOnFire()){
|
||||||
$this->setOnFire(2 * $this->level->getDifficulty());
|
$this->setOnFire(2 * $this->world->getDifficulty());
|
||||||
}
|
}
|
||||||
|
|
||||||
$deltaX = $this->x - $e->x;
|
$deltaX = $this->x - $e->x;
|
||||||
@ -646,11 +646,11 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
$ev = new EntityDeathEvent($this, $this->getDrops(), $this->getXpDropAmount());
|
$ev = new EntityDeathEvent($this, $this->getDrops(), $this->getXpDropAmount());
|
||||||
$ev->call();
|
$ev->call();
|
||||||
foreach($ev->getDrops() as $item){
|
foreach($ev->getDrops() as $item){
|
||||||
$this->getLevel()->dropItem($this, $item);
|
$this->getWorld()->dropItem($this, $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: check death conditions (must have been damaged by player < 5 seconds from death)
|
//TODO: check death conditions (must have been damaged by player < 5 seconds from death)
|
||||||
$this->level->dropExperience($this, $ev->getXpDropAmount());
|
$this->world->dropExperience($this, $ev->getXpDropAmount());
|
||||||
|
|
||||||
$this->startDeathAnimation();
|
$this->startDeathAnimation();
|
||||||
}
|
}
|
||||||
@ -864,7 +864,7 @@ abstract class Living extends Entity implements Damageable{
|
|||||||
$nextIndex = 0;
|
$nextIndex = 0;
|
||||||
|
|
||||||
foreach(VoxelRayTrace::inDirection($this->add(0, $this->eyeHeight, 0), $this->getDirectionVector(), $maxDistance) as $vector3){
|
foreach(VoxelRayTrace::inDirection($this->add(0, $this->eyeHeight, 0), $this->getDirectionVector(), $maxDistance) as $vector3){
|
||||||
$block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z);
|
$block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z);
|
||||||
$blocks[$nextIndex++] = $block;
|
$blocks[$nextIndex++] = $block;
|
||||||
|
|
||||||
if($maxLength !== 0 and count($blocks) > $maxLength){
|
if($maxLength !== 0 and count($blocks) > $maxLength){
|
||||||
|
@ -152,7 +152,7 @@ class ExperienceOrb extends Entity{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = $this->level->getEntity($this->targetPlayerRuntimeId);
|
$entity = $this->world->getEntity($this->targetPlayerRuntimeId);
|
||||||
if($entity instanceof Human){
|
if($entity instanceof Human){
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ class ExperienceOrb extends Entity{
|
|||||||
|
|
||||||
if($this->lookForTargetTime >= 20){
|
if($this->lookForTargetTime >= 20){
|
||||||
if($currentTarget === null){
|
if($currentTarget === null){
|
||||||
$newTarget = $this->level->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class);
|
$newTarget = $this->world->getNearestEntity($this, self::MAX_TARGET_DISTANCE, Human::class);
|
||||||
|
|
||||||
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator())){
|
if($newTarget instanceof Human and !($newTarget instanceof Player and $newTarget->isSpectator())){
|
||||||
$currentTarget = $newTarget;
|
$currentTarget = $newTarget;
|
||||||
|
@ -98,7 +98,7 @@ class FallingBlock extends Entity{
|
|||||||
if(!$this->isFlaggedForDespawn()){
|
if(!$this->isFlaggedForDespawn()){
|
||||||
$pos = $this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor();
|
$pos = $this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor();
|
||||||
|
|
||||||
$this->block->position($this->level, $pos->x, $pos->y, $pos->z);
|
$this->block->position($this->world, $pos->x, $pos->y, $pos->z);
|
||||||
|
|
||||||
$blockTarget = null;
|
$blockTarget = null;
|
||||||
if($this->block instanceof Fallable){
|
if($this->block instanceof Fallable){
|
||||||
@ -108,15 +108,15 @@ class FallingBlock extends Entity{
|
|||||||
if($this->onGround or $blockTarget !== null){
|
if($this->onGround or $blockTarget !== null){
|
||||||
$this->flagForDespawn();
|
$this->flagForDespawn();
|
||||||
|
|
||||||
$block = $this->level->getBlock($pos);
|
$block = $this->world->getBlock($pos);
|
||||||
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
|
if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){
|
||||||
//FIXME: anvils are supposed to destroy torches
|
//FIXME: anvils are supposed to destroy torches
|
||||||
$this->getLevel()->dropItem($this, $this->block->asItem());
|
$this->getWorld()->dropItem($this, $this->block->asItem());
|
||||||
}else{
|
}else{
|
||||||
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
|
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->getLevel()->setBlock($pos, $ev->getTo());
|
$this->getWorld()->setBlock($pos, $ev->getTo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
|
@ -29,8 +29,6 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\particle\DestroyBlockParticle;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Bearing;
|
use pocketmine\math\Bearing;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
@ -39,6 +37,8 @@ use pocketmine\nbt\tag\ByteTag;
|
|||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
|
use pocketmine\network\mcpe\protocol\AddPaintingPacket;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\particle\DestroyBlockParticle;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function ceil;
|
use function ceil;
|
||||||
|
|
||||||
class Painting extends Entity{
|
class Painting extends Entity{
|
||||||
@ -62,7 +62,7 @@ class Painting extends Entity{
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
protected $motive;
|
protected $motive;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt){
|
public function __construct(World $world, CompoundTag $nbt){
|
||||||
$this->motive = $nbt->getString("Motive");
|
$this->motive = $nbt->getString("Motive");
|
||||||
$this->blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
|
$this->blockIn = new Vector3($nbt->getInt("TileX"), $nbt->getInt("TileY"), $nbt->getInt("TileZ"));
|
||||||
if($nbt->hasTag("Direction", ByteTag::class)){
|
if($nbt->hasTag("Direction", ByteTag::class)){
|
||||||
@ -70,7 +70,7 @@ class Painting extends Entity{
|
|||||||
}elseif($nbt->hasTag("Facing", ByteTag::class)){
|
}elseif($nbt->hasTag("Facing", ByteTag::class)){
|
||||||
$this->direction = $nbt->getByte("Facing");
|
$this->direction = $nbt->getByte("Facing");
|
||||||
}
|
}
|
||||||
parent::__construct($level, $nbt);
|
parent::__construct($world, $nbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function initEntity(CompoundTag $nbt) : void{
|
protected function initEntity(CompoundTag $nbt) : void{
|
||||||
@ -107,9 +107,9 @@ class Painting extends Entity{
|
|||||||
|
|
||||||
if($drops){
|
if($drops){
|
||||||
//non-living entities don't have a way to create drops generically yet
|
//non-living entities don't have a way to create drops generically yet
|
||||||
$this->level->dropItem($this, ItemFactory::get(Item::PAINTING));
|
$this->world->dropItem($this, ItemFactory::get(Item::PAINTING));
|
||||||
}
|
}
|
||||||
$this->level->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS)));
|
$this->world->addParticle($this->add(0.5, 0.5, 0.5), new DestroyBlockParticle(BlockFactory::get(BlockLegacyIds::PLANKS)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateBoundingBox() : void{
|
protected function recalculateBoundingBox() : void{
|
||||||
@ -121,7 +121,7 @@ class Painting extends Entity{
|
|||||||
parent::onNearbyBlockChange();
|
parent::onNearbyBlockChange();
|
||||||
|
|
||||||
$face = Bearing::toFacing($this->direction);
|
$face = Bearing::toFacing($this->direction);
|
||||||
if(!self::canFit($this->level, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
|
if(!self::canFit($this->world, $this->blockIn->getSide($face), $face, false, $this->getMotive())){
|
||||||
$this->kill();
|
$this->kill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,7 +226,7 @@ class Painting extends Entity{
|
|||||||
/**
|
/**
|
||||||
* Returns whether a painting with the specified motive can be placed at the given position.
|
* Returns whether a painting with the specified motive can be placed at the given position.
|
||||||
*
|
*
|
||||||
* @param Level $level
|
* @param World $world
|
||||||
* @param Vector3 $blockIn
|
* @param Vector3 $blockIn
|
||||||
* @param int $facing
|
* @param int $facing
|
||||||
* @param bool $checkOverlap
|
* @param bool $checkOverlap
|
||||||
@ -234,7 +234,7 @@ class Painting extends Entity{
|
|||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function canFit(Level $level, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{
|
public static function canFit(World $world, Vector3 $blockIn, int $facing, bool $checkOverlap, PaintingMotive $motive) : bool{
|
||||||
$width = $motive->getWidth();
|
$width = $motive->getWidth();
|
||||||
$height = $motive->getHeight();
|
$height = $motive->getHeight();
|
||||||
|
|
||||||
@ -251,7 +251,7 @@ class Painting extends Entity{
|
|||||||
for($h = 0; $h < $height; ++$h){
|
for($h = 0; $h < $height; ++$h){
|
||||||
$pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h);
|
$pos = $startPos->getSide($rotatedFace, $w)->getSide(Facing::UP, $h);
|
||||||
|
|
||||||
$block = $level->getBlockAt($pos->x, $pos->y, $pos->z);
|
$block = $world->getBlockAt($pos->x, $pos->y, $pos->z);
|
||||||
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){
|
if($block->isSolid() or !$block->getSide($oppositeSide)->isSolid()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ class Painting extends Entity{
|
|||||||
if($checkOverlap){
|
if($checkOverlap){
|
||||||
$bb = self::getPaintingBB($blockIn, $facing, $motive);
|
$bb = self::getPaintingBB($blockIn, $facing, $motive);
|
||||||
|
|
||||||
foreach($level->getNearbyEntities($bb) as $entity){
|
foreach($world->getNearbyEntities($bb) as $entity){
|
||||||
if($entity instanceof self){
|
if($entity instanceof self){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -27,12 +27,12 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\entity\Explosive;
|
use pocketmine\entity\Explosive;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\ExplosionPrimeEvent;
|
use pocketmine\event\entity\ExplosionPrimeEvent;
|
||||||
use pocketmine\level\Explosion;
|
|
||||||
use pocketmine\level\sound\IgniteSound;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\ShortTag;
|
use pocketmine\nbt\tag\ShortTag;
|
||||||
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
||||||
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
|
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
|
||||||
|
use pocketmine\world\Explosion;
|
||||||
|
use pocketmine\world\sound\IgniteSound;
|
||||||
|
|
||||||
class PrimedTNT extends Entity implements Explosive{
|
class PrimedTNT extends Entity implements Explosive{
|
||||||
public const NETWORK_ID = self::TNT;
|
public const NETWORK_ID = self::TNT;
|
||||||
@ -68,7 +68,7 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
$this->setGenericFlag(EntityMetadataFlags::IGNITED, true);
|
$this->setGenericFlag(EntityMetadataFlags::IGNITED, true);
|
||||||
$this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
|
$this->propertyManager->setInt(EntityMetadataProperties::FUSE_LENGTH, $this->fuse);
|
||||||
|
|
||||||
$this->level->addSound($this, new IgniteSound());
|
$this->world->addSound($this, new IgniteSound());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,14 +29,14 @@ use pocketmine\event\entity\ProjectileHitEvent;
|
|||||||
use pocketmine\event\inventory\InventoryPickupArrowEvent;
|
use pocketmine\event\inventory\InventoryPickupArrowEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\sound\ArrowHitSound;
|
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
use pocketmine\network\mcpe\protocol\EntityEventPacket;
|
||||||
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
|
use pocketmine\network\mcpe\protocol\TakeItemEntityPacket;
|
||||||
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
use pocketmine\world\sound\ArrowHitSound;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
use function sqrt;
|
use function sqrt;
|
||||||
|
|
||||||
@ -67,8 +67,8 @@ class Arrow extends Projectile{
|
|||||||
/** @var int */
|
/** @var int */
|
||||||
protected $collideTicks = 0;
|
protected $collideTicks = 0;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
|
public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null, bool $critical = false){
|
||||||
parent::__construct($level, $nbt, $shootingEntity);
|
parent::__construct($world, $nbt, $shootingEntity);
|
||||||
$this->setCritical($critical);
|
$this->setCritical($critical);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ class Arrow extends Projectile{
|
|||||||
|
|
||||||
protected function onHit(ProjectileHitEvent $event) : void{
|
protected function onHit(ProjectileHitEvent $event) : void{
|
||||||
$this->setCritical(false);
|
$this->setCritical(false);
|
||||||
$this->level->addSound($this, new ArrowHitSound());
|
$this->world->addSound($this, new ArrowHitSound());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
|
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
|
||||||
|
@ -26,7 +26,7 @@ namespace pocketmine\entity\projectile;
|
|||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
use pocketmine\level\particle\ItemBreakParticle;
|
use pocketmine\world\particle\ItemBreakParticle;
|
||||||
|
|
||||||
class Egg extends Throwable{
|
class Egg extends Throwable{
|
||||||
public const NETWORK_ID = self::EGG;
|
public const NETWORK_ID = self::EGG;
|
||||||
@ -35,7 +35,7 @@ class Egg extends Throwable{
|
|||||||
|
|
||||||
protected function onHit(ProjectileHitEvent $event) : void{
|
protected function onHit(ProjectileHitEvent $event) : void{
|
||||||
for($i = 0; $i < 6; ++$i){
|
for($i = 0; $i < 6; ++$i){
|
||||||
$this->level->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG)));
|
$this->world->addParticle($this, new ItemBreakParticle(ItemFactory::get(Item::EGG)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ use pocketmine\block\Block;
|
|||||||
use pocketmine\block\BlockLegacyIds;
|
use pocketmine\block\BlockLegacyIds;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\level\particle\EndermanTeleportParticle;
|
|
||||||
use pocketmine\level\sound\EndermanTeleportSound;
|
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\world\particle\EndermanTeleportParticle;
|
||||||
|
use pocketmine\world\sound\EndermanTeleportSound;
|
||||||
|
|
||||||
class EnderPearl extends Throwable{
|
class EnderPearl extends Throwable{
|
||||||
public const NETWORK_ID = self::ENDER_PEARL;
|
public const NETWORK_ID = self::ENDER_PEARL;
|
||||||
@ -51,10 +51,10 @@ class EnderPearl extends Throwable{
|
|||||||
//TODO: check end gateways (when they are added)
|
//TODO: check end gateways (when they are added)
|
||||||
//TODO: spawn endermites at origin
|
//TODO: spawn endermites at origin
|
||||||
|
|
||||||
$this->level->addParticle($owner, new EndermanTeleportParticle());
|
$this->world->addParticle($owner, new EndermanTeleportParticle());
|
||||||
$this->level->addSound($owner, new EndermanTeleportSound());
|
$this->world->addSound($owner, new EndermanTeleportSound());
|
||||||
$owner->teleport($target = $event->getRayTraceResult()->getHitVector());
|
$owner->teleport($target = $event->getRayTraceResult()->getHitVector());
|
||||||
$this->level->addSound($target, new EndermanTeleportSound());
|
$this->world->addSound($target, new EndermanTeleportSound());
|
||||||
|
|
||||||
$owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5));
|
$owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5));
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\entity\projectile;
|
namespace pocketmine\entity\projectile;
|
||||||
|
|
||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\level\particle\PotionSplashParticle;
|
use pocketmine\world\particle\PotionSplashParticle;
|
||||||
use pocketmine\level\sound\PotionSplashSound;
|
use pocketmine\world\sound\PotionSplashSound;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class ExperienceBottle extends Throwable{
|
class ExperienceBottle extends Throwable{
|
||||||
@ -38,9 +38,9 @@ class ExperienceBottle extends Throwable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onHit(ProjectileHitEvent $event) : void{
|
public function onHit(ProjectileHitEvent $event) : void{
|
||||||
$this->level->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()));
|
$this->world->addParticle($this, new PotionSplashParticle(PotionSplashParticle::DEFAULT_COLOR()));
|
||||||
$this->level->addSound($this, new PotionSplashSound());
|
$this->world->addSound($this, new PotionSplashSound());
|
||||||
|
|
||||||
$this->level->dropExperience($this, mt_rand(3, 11));
|
$this->world->dropExperience($this, mt_rand(3, 11));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,6 @@ use pocketmine\event\entity\EntityDamageEvent;
|
|||||||
use pocketmine\event\entity\ProjectileHitBlockEvent;
|
use pocketmine\event\entity\ProjectileHitBlockEvent;
|
||||||
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\level\Level;
|
|
||||||
use pocketmine\level\Position;
|
|
||||||
use pocketmine\math\RayTraceResult;
|
use pocketmine\math\RayTraceResult;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\math\VoxelRayTrace;
|
use pocketmine\math\VoxelRayTrace;
|
||||||
@ -43,6 +41,8 @@ use pocketmine\nbt\tag\ByteTag;
|
|||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\World;
|
||||||
use function assert;
|
use function assert;
|
||||||
use function atan2;
|
use function atan2;
|
||||||
use function ceil;
|
use function ceil;
|
||||||
@ -58,8 +58,8 @@ abstract class Projectile extends Entity{
|
|||||||
/** @var Block|null */
|
/** @var Block|null */
|
||||||
protected $blockHit;
|
protected $blockHit;
|
||||||
|
|
||||||
public function __construct(Level $level, CompoundTag $nbt, ?Entity $shootingEntity = null){
|
public function __construct(World $world, CompoundTag $nbt, ?Entity $shootingEntity = null){
|
||||||
parent::__construct($level, $nbt);
|
parent::__construct($world, $nbt);
|
||||||
if($shootingEntity !== null){
|
if($shootingEntity !== null){
|
||||||
$this->setOwningEntity($shootingEntity);
|
$this->setOwningEntity($shootingEntity);
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ abstract class Projectile extends Entity{
|
|||||||
$blockData = null;
|
$blockData = null;
|
||||||
|
|
||||||
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
|
if($nbt->hasTag("tileX", IntTag::class) and $nbt->hasTag("tileY", IntTag::class) and $nbt->hasTag("tileZ", IntTag::class)){
|
||||||
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->level);
|
$blockPos = new Position($nbt->getInt("tileX"), $nbt->getInt("tileY"), $nbt->getInt("tileZ"), $this->world);
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ abstract class Projectile extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onNearbyBlockChange() : void{
|
public function onNearbyBlockChange() : void{
|
||||||
if($this->blockHit !== null and $this->level->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->level->getBlock($this->blockHit))){
|
if($this->blockHit !== null and $this->world->isInLoadedTerrain($this->blockHit) and !$this->blockHit->isSameState($this->world->getBlock($this->blockHit))){
|
||||||
$this->blockHit = null;
|
$this->blockHit = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ abstract class Projectile extends Entity{
|
|||||||
$hitResult = null;
|
$hitResult = null;
|
||||||
|
|
||||||
foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){
|
foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){
|
||||||
$block = $this->level->getBlockAt($vector3->x, $vector3->y, $vector3->z);
|
$block = $this->world->getBlockAt($vector3->x, $vector3->y, $vector3->z);
|
||||||
|
|
||||||
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
|
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
|
||||||
if($blockHitResult !== null){
|
if($blockHitResult !== null){
|
||||||
@ -201,7 +201,7 @@ abstract class Projectile extends Entity{
|
|||||||
$entityDistance = PHP_INT_MAX;
|
$entityDistance = PHP_INT_MAX;
|
||||||
|
|
||||||
$newDiff = $end->subtract($start);
|
$newDiff = $end->subtract($start);
|
||||||
foreach($this->level->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
|
foreach($this->world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
|
||||||
if($entity->getId() === $this->getOwningEntityId() and $this->ticksLived < 5){
|
if($entity->getId() === $this->getOwningEntityId() and $this->ticksLived < 5){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\entity\projectile;
|
namespace pocketmine\entity\projectile;
|
||||||
|
|
||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\level\particle\SnowballPoofParticle;
|
use pocketmine\world\particle\SnowballPoofParticle;
|
||||||
|
|
||||||
class Snowball extends Throwable{
|
class Snowball extends Throwable{
|
||||||
public const NETWORK_ID = self::SNOWBALL;
|
public const NETWORK_ID = self::SNOWBALL;
|
||||||
|
|
||||||
protected function onHit(ProjectileHitEvent $event) : void{
|
protected function onHit(ProjectileHitEvent $event) : void{
|
||||||
for($i = 0; $i < 6; ++$i){
|
for($i = 0; $i < 6; ++$i){
|
||||||
$this->level->addParticle($this, new SnowballPoofParticle());
|
$this->world->addParticle($this, new SnowballPoofParticle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,12 @@ use pocketmine\event\entity\ProjectileHitBlockEvent;
|
|||||||
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
use pocketmine\event\entity\ProjectileHitEntityEvent;
|
||||||
use pocketmine\event\entity\ProjectileHitEvent;
|
use pocketmine\event\entity\ProjectileHitEvent;
|
||||||
use pocketmine\item\Potion;
|
use pocketmine\item\Potion;
|
||||||
use pocketmine\level\particle\PotionSplashParticle;
|
|
||||||
use pocketmine\level\sound\PotionSplashSound;
|
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
use pocketmine\network\mcpe\protocol\types\EntityMetadataFlags;
|
||||||
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
|
use pocketmine\network\mcpe\protocol\types\EntityMetadataProperties;
|
||||||
use pocketmine\utils\Color;
|
use pocketmine\utils\Color;
|
||||||
|
use pocketmine\world\particle\PotionSplashParticle;
|
||||||
|
use pocketmine\world\sound\PotionSplashSound;
|
||||||
use function round;
|
use function round;
|
||||||
use function sqrt;
|
use function sqrt;
|
||||||
|
|
||||||
@ -83,12 +83,12 @@ class SplashPotion extends Throwable{
|
|||||||
$particle = new PotionSplashParticle(Color::mix(...$colors));
|
$particle = new PotionSplashParticle(Color::mix(...$colors));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->level->addParticle($this, $particle);
|
$this->world->addParticle($this, $particle);
|
||||||
$this->level->addSound($this, new PotionSplashSound());
|
$this->world->addSound($this, new PotionSplashSound());
|
||||||
|
|
||||||
if($hasEffects){
|
if($hasEffects){
|
||||||
if(!$this->willLinger()){
|
if(!$this->willLinger()){
|
||||||
foreach($this->level->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){
|
foreach($this->world->getNearbyEntities($this->boundingBox->expandedCopy(4.125, 2.125, 4.125), $this) as $entity){
|
||||||
if($entity instanceof Living and $entity->isAlive()){
|
if($entity instanceof Living and $entity->isAlive()){
|
||||||
$distanceSquared = $entity->add(0, $entity->getEyeHeight(), 0)->distanceSquared($this);
|
$distanceSquared = $entity->add(0, $entity->getEyeHeight(), 0)->distanceSquared($this);
|
||||||
if($distanceSquared > 16){ //4 blocks
|
if($distanceSquared > 16){ //4 blocks
|
||||||
@ -123,11 +123,11 @@ class SplashPotion extends Throwable{
|
|||||||
$blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace());
|
$blockIn = $event->getBlockHit()->getSide($event->getRayTraceResult()->getHitFace());
|
||||||
|
|
||||||
if($blockIn->getId() === BlockLegacyIds::FIRE){
|
if($blockIn->getId() === BlockLegacyIds::FIRE){
|
||||||
$this->level->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($blockIn, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}
|
}
|
||||||
foreach($blockIn->getHorizontalSides() as $horizontalSide){
|
foreach($blockIn->getHorizontalSides() as $horizontalSide){
|
||||||
if($horizontalSide->getId() === BlockLegacyIds::FIRE){
|
if($horizontalSide->getId() === BlockLegacyIds::FIRE){
|
||||||
$this->level->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR));
|
$this->world->setBlock($horizontalSide, BlockFactory::get(BlockLegacyIds::AIR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,6 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
|
|||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
*/
|
*/
|
||||||
public function getChild() : ?Entity{
|
public function getChild() : ?Entity{
|
||||||
return $this->getEntity()->getLevel()->getServer()->getLevelManager()->findEntity($this->childEntityEid);
|
return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->childEntityEid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
|||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
*/
|
*/
|
||||||
public function getDamager() : ?Entity{
|
public function getDamager() : ?Entity{
|
||||||
return $this->getEntity()->getLevel()->getServer()->getLevelManager()->findEntity($this->damagerEntityId);
|
return $this->getEntity()->getWorld()->getServer()->getWorldManager()->findEntity($this->damagerEntityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,7 @@ use pocketmine\block\Block;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
||||||
use pocketmine\level\Position;
|
use pocketmine\world\Position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a entity explodes
|
* Called when a entity explodes
|
||||||
|
@ -26,7 +26,7 @@ namespace pocketmine\event\entity;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
||||||
use pocketmine\level\Position;
|
use pocketmine\world\Position;
|
||||||
|
|
||||||
class EntityTeleportEvent extends EntityEvent implements Cancellable{
|
class EntityTeleportEvent extends EntityEvent implements Cancellable{
|
||||||
use CancellableTrait;
|
use CancellableTrait;
|
||||||
|
@ -26,27 +26,27 @@ namespace pocketmine\event\entity;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\world\World;
|
||||||
|
|
||||||
class EntityLevelChangeEvent extends EntityEvent implements Cancellable{
|
class EntityWorldChangeEvent extends EntityEvent implements Cancellable{
|
||||||
use CancellableTrait;
|
use CancellableTrait;
|
||||||
|
|
||||||
/** @var Level */
|
/** @var World */
|
||||||
private $originLevel;
|
private $originWorld;
|
||||||
/** @var Level */
|
/** @var World */
|
||||||
private $targetLevel;
|
private $targetWorld;
|
||||||
|
|
||||||
public function __construct(Entity $entity, Level $originLevel, Level $targetLevel){
|
public function __construct(Entity $entity, World $originWorld, World $targetWorld){
|
||||||
$this->entity = $entity;
|
$this->entity = $entity;
|
||||||
$this->originLevel = $originLevel;
|
$this->originWorld = $originWorld;
|
||||||
$this->targetLevel = $targetLevel;
|
$this->targetWorld = $targetWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrigin() : Level{
|
public function getOrigin() : World{
|
||||||
return $this->originLevel;
|
return $this->originWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTarget() : Level{
|
public function getTarget() : World{
|
||||||
return $this->targetLevel;
|
return $this->targetWorld;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,7 +25,7 @@ namespace pocketmine\event\player;
|
|||||||
|
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
||||||
use pocketmine\level\Location;
|
use pocketmine\world\Location;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
class PlayerMoveEvent extends PlayerEvent implements Cancellable{
|
class PlayerMoveEvent extends PlayerEvent implements Cancellable{
|
||||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\event\player;
|
namespace pocketmine\event\player;
|
||||||
|
|
||||||
use pocketmine\level\Position;
|
use pocketmine\world\Position;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,8 +89,8 @@ class QueryRegenerateEvent extends ServerEvent{
|
|||||||
$this->gametype = ($server->getGamemode()->getMagicNumber() & 0x01) === 0 ? "SMP" : "CMP";
|
$this->gametype = ($server->getGamemode()->getMagicNumber() & 0x01) === 0 ? "SMP" : "CMP";
|
||||||
$this->version = $server->getVersion();
|
$this->version = $server->getVersion();
|
||||||
$this->server_engine = $server->getName() . " " . $server->getPocketMineVersion();
|
$this->server_engine = $server->getName() . " " . $server->getPocketMineVersion();
|
||||||
$level = $server->getLevelManager()->getDefaultLevel();
|
$world = $server->getWorldManager()->getDefaultWorld();
|
||||||
$this->map = $level === null ? "unknown" : $level->getDisplayName();
|
$this->map = $world === null ? "unknown" : $world->getDisplayName();
|
||||||
$this->numPlayers = count($this->players);
|
$this->numPlayers = count($this->players);
|
||||||
$this->maxPlayers = $server->getMaxPlayers();
|
$this->maxPlayers = $server->getMaxPlayers();
|
||||||
$this->whitelist = $server->hasWhitelist() ? "on" : "off";
|
$this->whitelist = $server->hasWhitelist() ? "on" : "off";
|
||||||
|
@ -22,24 +22,24 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
namespace pocketmine\event\level;
|
namespace pocketmine\event\world;
|
||||||
|
|
||||||
use pocketmine\level\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\world\World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Chunk-related events
|
* Chunk-related events
|
||||||
*/
|
*/
|
||||||
abstract class ChunkEvent extends LevelEvent{
|
abstract class ChunkEvent extends WorldEvent{
|
||||||
/** @var Chunk */
|
/** @var Chunk */
|
||||||
private $chunk;
|
private $chunk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Level $level
|
* @param World $world
|
||||||
* @param Chunk $chunk
|
* @param Chunk $chunk
|
||||||
*/
|
*/
|
||||||
public function __construct(Level $level, Chunk $chunk){
|
public function __construct(World $world, Chunk $chunk){
|
||||||
parent::__construct($level);
|
parent::__construct($world);
|
||||||
$this->chunk = $chunk;
|
$this->chunk = $chunk;
|
||||||
}
|
}
|
||||||
|
|
@ -22,10 +22,10 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
namespace pocketmine\event\level;
|
namespace pocketmine\event\world;
|
||||||
|
|
||||||
use pocketmine\level\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\world\World;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a Chunk is loaded
|
* Called when a Chunk is loaded
|
||||||
@ -34,8 +34,8 @@ class ChunkLoadEvent extends ChunkEvent{
|
|||||||
/** @var bool */
|
/** @var bool */
|
||||||
private $newChunk;
|
private $newChunk;
|
||||||
|
|
||||||
public function __construct(Level $level, Chunk $chunk, bool $newChunk){
|
public function __construct(World $world, Chunk $chunk, bool $newChunk){
|
||||||
parent::__construct($level, $chunk);
|
parent::__construct($world, $chunk);
|
||||||
$this->newChunk = $newChunk;
|
$this->newChunk = $newChunk;
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace pocketmine\event\level;
|
namespace pocketmine\event\world;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a Chunk is populated (after receiving it on the main thread)
|
* Called when a Chunk is populated (after receiving it on the main thread)
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace pocketmine\event\level;
|
namespace pocketmine\event\world;
|
||||||
|
|
||||||
use pocketmine\event\Cancellable;
|
use pocketmine\event\Cancellable;
|
||||||
use pocketmine\event\CancellableTrait;
|
use pocketmine\event\CancellableTrait;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user