Skip to content

Commit

Permalink
Merge branch 'minor-next' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Feb 28, 2024
2 parents 34a5f91 + 98042f8 commit 54ea404
Show file tree
Hide file tree
Showing 61 changed files with 828 additions and 417 deletions.
133 changes: 133 additions & 0 deletions build/generate-biome-ids.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\build\generate_biome_ids;

use pocketmine\data\bedrock\BedrockDataFiles;
use pocketmine\utils\Filesystem;
use pocketmine\utils\Utils;
use function asort;
use function dirname;
use function fclose;
use function fopen;
use function fwrite;
use function is_array;
use function is_int;
use function is_string;
use function json_decode;
use function str_replace;
use function strtoupper;
use const SORT_NUMERIC;

require dirname(__DIR__) . '/vendor/autoload.php';

const HEADER = <<<'HEADER'
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);


HEADER;

/** @return resource */
function safe_fopen(string $file, string $flags){
$result = fopen($file, $flags);
if($result === false){
throw new \RuntimeException("Failed to open file");
}
return $result;
}

function make_const_name(string $name) : string{
return strtoupper(str_replace(['.', 'minecraft:'], ['_', ''], $name));
}

/**
* @param int[] $map
* @phpstan-param array<string, int> $map
*/
function generate(array $map, string $outputFile) : void{
$file = safe_fopen($outputFile, 'wb');
fwrite($file, HEADER);
fwrite($file, <<<'CLASSHEADER'
namespace pocketmine\data\bedrock;
final class BiomeIds{
private function __construct(){
//NOOP
}


CLASSHEADER
);
$list = $map;
asort($list, SORT_NUMERIC);
$lastId = -1;
foreach(Utils::stringifyKeys($list) as $name => $id){
if($name === ""){
continue;
}
if($id !== $lastId + 1){
fwrite($file, "\n");
}
$lastId = $id;
fwrite($file, "\tpublic const " . make_const_name($name) . ' = ' . $id . ';' . "\n");
}
fwrite($file, "}\n");
fclose($file);
}

$ids = json_decode(Filesystem::fileGetContents(BedrockDataFiles::BIOME_ID_MAP_JSON), true);
if(!is_array($ids)){
throw new \RuntimeException("Invalid biome ID map, expected array for root JSON object");
}
$cleanedIds = [];
foreach($ids as $name => $id){
if(!is_string($name) || !is_int($id)){
throw new \RuntimeException("Invalid biome ID map, expected string => int map");
}
$cleanedIds[$name] = $id;
}
generate($cleanedIds, dirname(__DIR__) . '/src/data/bedrock/BiomeIds.php');

echo "Done. Don't forget to run CS fixup after generating code.\n";
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"pocketmine/bedrock-block-upgrade-schema": "~3.5.0+bedrock-1.20.60",
"pocketmine/bedrock-data": "~2.8.0+bedrock-1.20.60",
"pocketmine/bedrock-item-upgrade-schema": "~1.7.0+bedrock-1.20.60",
"pocketmine/bedrock-protocol": "~27.0.0+bedrock-1.20.60",
"pocketmine/bedrock-protocol": "~28.0.0+bedrock-1.20.60",
"pocketmine/binaryutils": "^0.2.1",
"pocketmine/callback-validator": "^1.0.2",
"pocketmine/color": "^0.3.0",
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/BootstrapOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ private function __construct(){
public const PLUGINS = "plugins";
/** Path to store and load server data */
public const DATA = "data";
/** Shows basic server version information and exits */
public const VERSION = "version";
}
11 changes: 10 additions & 1 deletion src/PocketMine.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use Composer\InstalledVersions;
use pocketmine\errorhandler\ErrorToExceptionHandler;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\thread\ThreadManager;
use pocketmine\thread\ThreadSafeClassLoader;
use pocketmine\utils\Filesystem;
Expand All @@ -40,14 +41,17 @@
use function extension_loaded;
use function function_exists;
use function getcwd;
use function getopt;
use function is_dir;
use function mkdir;
use function phpversion;
use function preg_match;
use function preg_quote;
use function printf;
use function realpath;
use function version_compare;
use const DIRECTORY_SEPARATOR;
use const PHP_EOL;

require_once __DIR__ . '/VersionInfo.php';

Expand Down Expand Up @@ -166,7 +170,7 @@ function check_platform_dependencies(){
* @return void
*/
function emit_performance_warnings(\Logger $logger){
if(PHP_DEBUG !== 0){
if(ZEND_DEBUG_BUILD){
$logger->warning("This PHP binary was compiled in debug mode. This has a major impact on performance.");
}
if(extension_loaded("xdebug") && (!function_exists('xdebug_info') || count(xdebug_info('mode')) !== 0)){
Expand Down Expand Up @@ -273,6 +277,11 @@ function server(){

ErrorToExceptionHandler::set();

if(count(getopt("", [BootstrapOptions::VERSION])) > 0){
printf("%s %s (git hash %s) for Minecraft: Bedrock Edition %s\n", VersionInfo::NAME, VersionInfo::VERSION()->getFullVersion(true), VersionInfo::GIT_HASH(), ProtocolInfo::MINECRAFT_VERSION);
exit(0);
}

$cwd = Utils::assumeNotFalse(realpath(Utils::assumeNotFalse(getcwd())));
$dataPath = getopt_string(BootstrapOptions::DATA) ?? $cwd;
$pluginPath = getopt_string(BootstrapOptions::PLUGINS) ?? $cwd . DIRECTORY_SEPARATOR . "plugins";
Expand Down
11 changes: 4 additions & 7 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\PacketBroadcaster;
use pocketmine\network\mcpe\protocol\ProtocolInfo;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializerContext;
use pocketmine\network\mcpe\protocol\types\CompressionAlgorithm;
use pocketmine\network\mcpe\raklib\RakLibInterface;
use pocketmine\network\mcpe\StandardEntityEventBroadcaster;
Expand Down Expand Up @@ -1187,12 +1186,11 @@ private function startupPrepareConnectableNetworkInterfaces(
bool $useQuery,
PacketBroadcaster $packetBroadcaster,
EntityEventBroadcaster $entityEventBroadcaster,
PacketSerializerContext $packetSerializerContext,
TypeConverter $typeConverter
) : bool{
$prettyIp = $ipV6 ? "[$ip]" : $ip;
try{
$rakLibRegistered = $this->network->registerInterface(new RakLibInterface($this, $ip, $port, $ipV6, $packetBroadcaster, $entityEventBroadcaster, $packetSerializerContext, $typeConverter));
$rakLibRegistered = $this->network->registerInterface(new RakLibInterface($this, $ip, $port, $ipV6, $packetBroadcaster, $entityEventBroadcaster, $typeConverter));
}catch(NetworkInterfaceStartException $e){
$this->logger->emergency($this->language->translate(KnownTranslationFactory::pocketmine_server_networkStartFailed(
$ip,
Expand All @@ -1219,15 +1217,14 @@ private function startupPrepareNetworkInterfaces() : bool{
$useQuery = $this->configGroup->getConfigBool(ServerProperties::ENABLE_QUERY, true);

$typeConverter = TypeConverter::getInstance();
$packetSerializerContext = new PacketSerializerContext($typeConverter->getItemTypeDictionary());
$packetBroadcaster = new StandardPacketBroadcaster($this, $packetSerializerContext);
$packetBroadcaster = new StandardPacketBroadcaster($this);
$entityEventBroadcaster = new StandardEntityEventBroadcaster($packetBroadcaster, $typeConverter);

if(
!$this->startupPrepareConnectableNetworkInterfaces($this->getIp(), $this->getPort(), false, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $packetSerializerContext, $typeConverter) ||
!$this->startupPrepareConnectableNetworkInterfaces($this->getIp(), $this->getPort(), false, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $typeConverter) ||
(
$this->configGroup->getConfigBool(ServerProperties::ENABLE_IPV6, true) &&
!$this->startupPrepareConnectableNetworkInterfaces($this->getIpV6(), $this->getPortV6(), true, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $packetSerializerContext, $typeConverter)
!$this->startupPrepareConnectableNetworkInterfaces($this->getIpV6(), $this->getPortV6(), true, $useQuery, $packetBroadcaster, $entityEventBroadcaster, $typeConverter)
)
){
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/block/BaseBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function array_filter;
use function assert;
use function count;

Expand Down Expand Up @@ -89,11 +88,12 @@ public function getPatterns() : array{
* @return $this
*/
public function setPatterns(array $patterns) : self{
$checked = array_filter($patterns, fn($v) => $v instanceof BannerPatternLayer);
if(count($checked) !== count($patterns)){
throw new \TypeError("Deque must only contain " . BannerPatternLayer::class . " objects");
foreach($patterns as $pattern){
if(!$pattern instanceof BannerPatternLayer){
throw new \TypeError("Array must only contain " . BannerPatternLayer::class . " objects");
}
}
$this->patterns = $checked;
$this->patterns = $patterns;
return $this;
}

Expand Down
16 changes: 14 additions & 2 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public function writeStateToWorld() : void{
}

/**
* AKA: Block->isPlaceable
* Returns whether this block can be placed when obtained as an item.
*/
public function canBePlaced() : bool{
return true;
Expand Down Expand Up @@ -572,16 +572,28 @@ public function blocksDirectSkyLight() : bool{
return $this->getLightFilter() > 0;
}

/**
* Returns whether this block allows any light to pass through it.
*/
public function isTransparent() : bool{
return false;
}

/**
* @deprecated TL;DR: Don't use this function. Its results are confusing and inconsistent.
*
* No one is sure what the meaning of this property actually is. It's borrowed from Minecraft Java Edition, and is
* used by various blocks for support checks.
*
* Things like signs and banners are considered "solid" despite having no collision box, and things like skulls and
* flower pots are considered non-solid despite obviously being "solid" in the conventional, real-world sense.
*/
public function isSolid() : bool{
return true;
}

/**
* AKA: Block->isFlowable
* Returns whether this block can be destroyed by liquid flowing into its cell.
*/
public function canBeFlowedInto() : bool{
return false;
Expand Down
7 changes: 1 addition & 6 deletions src/block/CocoaBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use pocketmine\block\utils\AgeableTrait;
use pocketmine\block\utils\BlockEventHelper;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\block\utils\SupportType;
use pocketmine\block\utils\WoodType;
use pocketmine\data\runtime\RuntimeDataDescriber;
use pocketmine\item\Fertilizer;
Expand All @@ -40,7 +39,7 @@
use pocketmine\world\BlockTransaction;
use function mt_rand;

class CocoaBlock extends Transparent{
class CocoaBlock extends Flowable{
use HorizontalFacingTrait;
use AgeableTrait;

Expand All @@ -65,10 +64,6 @@ protected function recalculateCollisionBoxes() : array{
];
}

public function getSupportType(int $facing) : SupportType{
return SupportType::NONE;
}

private function canAttachTo(Block $block) : bool{
return $block instanceof Wood && $block->getWoodType() === WoodType::JUNGLE;
}
Expand Down
Loading

0 comments on commit 54ea404

Please sign in to comment.