Skip to content

Commit

Permalink
Merge branch 'minor-next' into feat/async-events
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps authored Nov 29, 2024
2 parents d9080f1 + a396233 commit 866d473
Show file tree
Hide file tree
Showing 99 changed files with 696 additions and 195 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
id: get-pm-version
run: |
echo PM_VERSION=$(php build/dump-version-info.php base_version) >> $GITHUB_OUTPUT
echo PM_MAJOR=$(php build/dump-version-info.php major_version) >> $GITHUB_OUTPUT
echo MCPE_VERSION=$(php build/dump-version-info.php mcpe_version) >> $GITHUB_OUTPUT
echo CHANGELOG_FILE_NAME=$(php build/dump-version-info.php changelog_file_name) >> $GITHUB_OUTPUT
echo CHANGELOG_MD_HEADER=$(php build/dump-version-info.php changelog_md_header) >> $GITHUB_OUTPUT
Expand All @@ -72,7 +73,7 @@ jobs:
- name: Generate PHP binary download URL
id: php-binary-url
run: |
echo PHP_BINARY_URL="${{ github.server_url }}/${{ github.repository_owner }}/PHP-Binaries/releases/tag/php-${{ matrix.php-version }}-latest" >> $GITHUB_OUTPUT
echo PHP_BINARY_URL="${{ github.server_url }}/${{ github.repository_owner }}/PHP-Binaries/releases/tag/pm${{ steps.get-pm-version.outputs.PM_MAJOR }}-php-${{ matrix.php-version }}-latest" >> $GITHUB_OUTPUT
- name: Generate build info
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/main-php-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP
uses: pmmp/setup-php-action@3.1.0
uses: pmmp/setup-php-action@3.2.0
with:
php-version: ${{ inputs.php }}
install-path: "./bin"
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP
uses: pmmp/setup-php-action@3.1.0
uses: pmmp/setup-php-action@3.2.0
with:
php-version: ${{ inputs.php }}
install-path: "./bin"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
submodules: true

- name: Setup PHP
uses: pmmp/setup-php-action@3.1.0
uses: pmmp/setup-php-action@3.2.0
with:
php-version: ${{ inputs.php }}
install-path: "./bin"
Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP
uses: pmmp/setup-php-action@3.1.0
uses: pmmp/setup-php-action@3.2.0
with:
php-version: ${{ inputs.php }}
install-path: "./bin"
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/pr-remove-waiting-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Remove waiting label from PRs

on:
pull_request_target:
types: synchronize

jobs:
delabel:
name: Remove label
runs-on: ubuntu-latest

steps:
- name: Remove label
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
const [owner, repo] = context.payload.repository.full_name.split('/');
try {
await github.rest.issues.removeLabel({
owner: owner,
repo: repo,
issue_number: context.payload.number,
name: "Status: Waiting on Author",
});
} catch (error) {
if (error.status === 404) {
//probably label wasn't set on the issue
console.log('Failed to remove label (probably label isn\'t on the PR): ' + error.message);
} else {
throw error;
}
}
4 changes: 2 additions & 2 deletions .github/workflows/team-pr-auto-approve.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- ready_for_review
- synchronize

jobs:
dispatch:
Expand All @@ -35,4 +35,4 @@ jobs:
token: ${{ steps.generate-token.outputs.token }}
repository: ${{ github.repository_owner }}/RestrictedActions
event-type: auto_approve_collaborator_pr
client-payload: '{"repo": "${{ github.repository }}", "pull_request_id": "${{ github.event.pull_request.number }}" }'
client-payload: '{"repo": "${{ github.repository }}", "pull_request_id": "${{ github.event.pull_request.number }}", "reviewer_id": "0" }'
1 change: 1 addition & 0 deletions build/dump-version-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
$options = [
"base_version" => VersionInfo::BASE_VERSION,
"major_version" => fn() => explode(".", VersionInfo::BASE_VERSION)[0],
"mcpe_version" => ProtocolInfo::MINECRAFT_VERSION_NETWORK,
"is_dev" => VersionInfo::IS_DEVELOPMENT_BUILD,
"changelog_file_name" => function() : string{
Expand Down
2 changes: 1 addition & 1 deletion build/generate-biome-ids.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function __construct(){
throw new \RuntimeException("Invalid biome ID map, expected array for root JSON object");
}
$cleanedIds = [];
foreach($ids as $name => $id){
foreach(Utils::promoteKeys($ids) as $name => $id){
if(!is_string($name) || !is_int($id)){
throw new \RuntimeException("Invalid biome ID map, expected string => int map");
}
Expand Down
2 changes: 1 addition & 1 deletion build/generate-pocketmine-yml-property-consts.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @phpstan-param-out array<string, string> $constants
*/
function collectProperties(string $prefix, array $properties, array &$constants) : void{
foreach($properties as $propertyName => $property){
foreach(Utils::promoteKeys($properties) as $propertyName => $property){
$fullPropertyName = ($prefix !== "" ? $prefix . "." : "") . $propertyName;

$constName = str_replace([".", "-"], "_", strtoupper($fullPropertyName));
Expand Down
4 changes: 3 additions & 1 deletion build/generate-registry-annotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\build\update_registry_annotations;

use pocketmine\utils\Utils;
use function basename;
use function class_exists;
use function count;
Expand All @@ -48,6 +49,7 @@

/**
* @param object[] $members
* @phpstan-param array<string, object> $members
*/
function generateMethodAnnotations(string $namespaceName, array $members) : string{
$selfName = basename(__FILE__);
Expand All @@ -60,7 +62,7 @@ function generateMethodAnnotations(string $namespaceName, array $members) : stri

static $lineTmpl = " * @method static %2\$s %s()";
$memberLines = [];
foreach($members as $name => $member){
foreach(Utils::stringifyKeys($members) as $name => $member){
$reflect = new \ReflectionClass($member);
while($reflect !== false && $reflect->isAnonymous()){
$reflect = $reflect->getParentClass();
Expand Down
2 changes: 1 addition & 1 deletion build/php
Submodule php updated from a51259 to 8a396c
10 changes: 5 additions & 5 deletions src/MemoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public static function dumpMemory(mixed $startingObject, string $outputFolder, i
continue;
}
$methodStatics = [];
foreach($method->getStaticVariables() as $name => $variable){
foreach(Utils::promoteKeys($method->getStaticVariables()) as $name => $variable){
$methodStatics[$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
if(count($methodStatics) > 0){
Expand Down Expand Up @@ -360,7 +360,7 @@ public static function dumpMemory(mixed $startingObject, string $outputFolder, i
'_SESSION' => true
];

foreach($GLOBALS as $varName => $value){
foreach(Utils::promoteKeys($GLOBALS) as $varName => $value){
if(isset($ignoredGlobals[$varName])){
continue;
}
Expand All @@ -376,7 +376,7 @@ public static function dumpMemory(mixed $startingObject, string $outputFolder, i
$reflect = new \ReflectionFunction($function);

$vars = [];
foreach($reflect->getStaticVariables() as $varName => $variable){
foreach(Utils::promoteKeys($reflect->getStaticVariables()) as $varName => $variable){
$vars[$varName] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
if(count($vars) > 0){
Expand Down Expand Up @@ -416,7 +416,7 @@ public static function dumpMemory(mixed $startingObject, string $outputFolder, i
$info["this"] = self::continueDump($closureThis, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}

foreach($reflect->getStaticVariables() as $name => $variable){
foreach(Utils::promoteKeys($reflect->getStaticVariables()) as $name => $variable){
$info["referencedVars"][$name] = self::continueDump($variable, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
}
}else{
Expand Down Expand Up @@ -499,7 +499,7 @@ private static function continueDump(mixed $from, array &$objects, array &$refCo
}
$data = [];
$numeric = 0;
foreach($from as $key => $value){
foreach(Utils::promoteKeys($from) as $key => $value){
$data[$numeric] = [
"k" => self::continueDump($key, $objects, $refCounts, $recursion + 1, $maxNesting, $maxStringSize),
"v" => self::continueDump($value, $objects, $refCounts, $recursion + 1, $maxNesting, $maxStringSize),
Expand Down
13 changes: 10 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,20 +737,23 @@ public function getOps() : Config{

/**
* @return string[][]
* @phpstan-return array<string, list<string>>
*/
public function getCommandAliases() : array{
$section = $this->configGroup->getProperty(Yml::ALIASES);
$result = [];
if(is_array($section)){
foreach($section as $key => $value){
foreach(Utils::promoteKeys($section) as $key => $value){
//TODO: more validation needed here
//key might not be a string, value might not be list<string>
$commands = [];
if(is_array($value)){
$commands = $value;
}else{
$commands[] = (string) $value;
}

$result[$key] = $commands;
$result[(string) $key] = $commands;
}
}

Expand Down Expand Up @@ -1095,7 +1098,11 @@ private function startupPrepareWorlds() : bool{

$anyWorldFailedToLoad = false;

foreach((array) $this->configGroup->getProperty(Yml::WORLDS, []) as $name => $options){
foreach(Utils::promoteKeys((array) $this->configGroup->getProperty(Yml::WORLDS, [])) as $name => $options){
if(!is_string($name)){
//TODO: this probably should be an error
continue;
}
if($options === null){
$options = [];
}elseif(!is_array($options)){
Expand Down
4 changes: 2 additions & 2 deletions src/block/Anvil.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\Utils;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\AnvilFallSound;
use pocketmine\world\sound\Sound;
use function lcg_value;
use function round;

class Anvil extends Transparent implements Fallable{
Expand Down Expand Up @@ -97,7 +97,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo
}

public function onHitGround(FallingBlock $blockEntity) : bool{
if(lcg_value() < 0.05 + (round($blockEntity->getFallDistance()) - 1) * 0.05){
if(Utils::getRandomFloat() < 0.05 + (round($blockEntity->getFallDistance()) - 1) * 0.05){
if($this->damage !== self::VERY_DAMAGED){
$this->damage = $this->damage + 1;
}else{
Expand Down
3 changes: 3 additions & 0 deletions src/block/CakeWithCandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public function getCandle() : Candle{
}

public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($this->lit && $face !== Facing::UP){
return true;
}
if($this->onInteractCandle($item, $face, $clickVector, $player, $returnedItems)){
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/block/Farmland.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\utils\Utils;
use function intdiv;
use function lcg_value;

class Farmland extends Transparent{
public const MAX_WETNESS = 7;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function onRandomTick() : void{
}

public function onEntityLand(Entity $entity) : ?float{
if($entity instanceof Living && lcg_value() < $entity->getFallDistance() - 0.5){
if($entity instanceof Living && Utils::getRandomFloat() < $entity->getFallDistance() - 0.5){
$ev = new EntityTrampleFarmlandEvent($entity, $this);
$ev->call();
if(!$ev->isCancelled()){
Expand Down
6 changes: 3 additions & 3 deletions src/block/ItemFrame.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\Utils;
use pocketmine\world\BlockTransaction;
use pocketmine\world\sound\ItemFrameAddItemSound;
use pocketmine\world\sound\ItemFrameRemoveItemSound;
use pocketmine\world\sound\ItemFrameRotateItemSound;
use function is_infinite;
use function is_nan;
use function lcg_value;

class ItemFrame extends Flowable{
use AnyFacingTrait;
Expand Down Expand Up @@ -154,7 +154,7 @@ public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
return false;
}
$world = $this->position->getWorld();
if(lcg_value() <= $this->itemDropChance){
if(Utils::getRandomFloat() <= $this->itemDropChance){
$world->dropItem($this->position->add(0.5, 0.5, 0.5), clone $this->framedItem);
$world->addSound($this->position, new ItemFrameRemoveItemSound());
}
Expand Down Expand Up @@ -185,7 +185,7 @@ public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Blo

public function getDropsForCompatibleTool(Item $item) : array{
$drops = parent::getDropsForCompatibleTool($item);
if($this->framedItem !== null && lcg_value() <= $this->itemDropChance){
if($this->framedItem !== null && Utils::getRandomFloat() <= $this->itemDropChance){
$drops[] = clone $this->framedItem;
}

Expand Down
4 changes: 2 additions & 2 deletions src/block/Liquid.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use pocketmine\math\Vector3;
use pocketmine\utils\Utils;
use pocketmine\world\sound\FizzSound;
use pocketmine\world\sound\Sound;
use function lcg_value;

abstract class Liquid extends Transparent{
public const MAX_DECAY = 7;
Expand Down Expand Up @@ -368,7 +368,7 @@ protected function checkForHarden() : bool{

protected function liquidCollide(Block $cause, Block $result) : bool{
if(BlockEventHelper::form($this, $result, $cause)){
$this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8));
$this->position->getWorld()->addSound($this->position->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (Utils::getRandomFloat() - Utils::getRandomFloat()) * 0.8));
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions src/block/RuntimeBlockStateRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function fromStateId(int $stateId) : Block{

/**
* @return Block[]
* @phpstan-return array<int, Block>
*/
public function getAllKnownStates() : array{
return $this->fullList;
Expand Down
5 changes: 4 additions & 1 deletion src/block/inventory/EnchantInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class EnchantInventory extends SimpleInventory implements BlockInventory, Tempor
public const SLOT_INPUT = 0;
public const SLOT_LAPIS = 1;

/** @var EnchantingOption[] $options */
/**
* @var EnchantingOption[] $options
* @phpstan-var list<EnchantingOption>
*/
private array $options = [];

public function __construct(Position $holder){
Expand Down
7 changes: 6 additions & 1 deletion src/block/utils/SignText.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@
class SignText{
public const LINE_COUNT = 4;

/** @var string[] */
/**
* @var string[]
* @phpstan-var array{0: string, 1: string, 2: string, 3: string}
*/
private array $lines;
private Color $baseColor;
private bool $glowing;

/**
* @param string[]|null $lines index-sensitive; keys 0-3 will be used, regardless of array order
* @phpstan-param array{0?: string, 1?: string, 2?: string, 3?: string}|null $lines
*
* @throws \InvalidArgumentException if the array size is greater than 4
* @throws \InvalidArgumentException if invalid keys (out of bounds or string) are found in the array
Expand Down Expand Up @@ -82,6 +86,7 @@ public static function fromBlob(string $blob, ?Color $baseColor = null, bool $gl
* Returns an array of lines currently on the sign.
*
* @return string[]
* @phpstan-return array{0: string, 1: string, 2: string, 3: string}
*/
public function getLines() : array{
return $this->lines;
Expand Down
Loading

0 comments on commit 866d473

Please sign in to comment.