Skip to content

Commit

Permalink
Merge remote-tracking branch 'pmmp/minor-next' into stable
Browse files Browse the repository at this point in the history
# Conflicts:
#	build/php
#	composer.lock
#	src/item/ItemTypeIds.php
  • Loading branch information
DavyCraft648 committed Nov 10, 2023
2 parents a17587a + 7a4cf8e commit c4fa3e2
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 104 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/discord-release-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP and tools
uses: shivammathur/setup-php@2.26.0
uses: shivammathur/setup-php@2.27.1
with:
php-version: 8.1
php-version: 8.2

- name: Restore Composer package cache
uses: actions/cache@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [8.1]
php-version: [8.2]

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Setup PHP
uses: shivammathur/setup-php@2.26.0
uses: shivammathur/setup-php@2.27.1
with:
php-version: ${{ matrix.php-version }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ jobs:
- uses: actions/checkout@v4

- name: Setup PHP and tools
uses: shivammathur/setup-php@2.26.0
uses: shivammathur/setup-php@2.27.1
with:
php-version: 8.1
tools: php-cs-fixer:3.17
php-version: 8.2
tools: php-cs-fixer:3.38
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Pre-requisites
- A bash shell (git bash is sufficient for Windows)
- [`git`](https://git-scm.com) available in your shell
- PHP 8.1 or newer available in your shell
- PHP 8.2 or newer available in your shell
- [`composer`](https://getcomposer.org) available in your shell

## Custom PHP binaries
Expand Down
19 changes: 19 additions & 0 deletions changelogs/5.8.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,22 @@ Consider using the `mcpe-protocol` directive in `plugin.yml` as a constraint if
- Removed code generation step for `RuntimeDataDescriber` enum serialization. All described enums now use PHP 8.1 native enums, which can be described without codegen using `RuntimeDataDescriber->enum()`.
- Added `DeprecatedLegacyEnumAccessRule` custom PHPStan rule to flag legacy `EnumTrait` case accessors.
- Cleaned up remaining hardcoded `Config` keys in `SetupWizard`. These usages now use auto-generated constants like the rest of the codebase.

# 5.8.2
Released 9th November 2023.

## Performance
- Improved performance of small packet zero-compression (unintended use of slow zlib compressor instead of fast libdeflate one).
- This affected the majority of outbound packets, as most packets are below the 256-byte threshold for compression.
- This faster method is over 20x faster than the old method, producing noticeable performance gains for large servers.

## Fixes
- Fixed melons and pumpkins not growing.
- Fixed melon and pumpkin stems not attaching to the grown melon/pumpkin.
- Fixed iron and gold ores not being affected by the Fortune enchantment.
- Fixed ancient debris burning in lava.
- Fixed sign (front) text loading from vanilla world saves (back text is not yet supported).

## Internals
- Removed bogus optimization from `tools/generate-blockstate-upgrade-schema.php` that could cause incorrect `remappedStates` generation when some of the states stayed under the old ID.
- Fixed possible crash in `BlockStateUpgrader` name flattening rule handling with invalid blockstate NBT data.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"symfony/filesystem": "~6.3.0"
},
"require-dev": {
"phpstan/phpstan": "1.10.40",
"phpstan/phpstan": "1.10.41",
"phpstan/phpstan-phpunit": "^1.1.0",
"phpstan/phpstan-strict-rules": "^1.2.0",
"phpunit/phpunit": "~10.3.0 || ~10.2.0 || ~10.1.0"
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

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

7 changes: 7 additions & 0 deletions src/PocketMine.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ function check_platform_dependencies(){
$messages[] = "chunkutils2 ^$wantedVersionMin is required, while you have $chunkutils2_version.";
}

if(($libdeflate_version = phpversion("libdeflate")) !== false){
//make sure level 0 compression is available
if(version_compare($libdeflate_version, "0.2.0") < 0 || version_compare($libdeflate_version, "0.3.0") >= 0){
$messages[] = "php-libdeflate ^0.2.0 is required, while you have $libdeflate_version.";
}
}

if(extension_loaded("pocketmine")){
$messages[] = "The native PocketMine extension is no longer supported.";
}
Expand Down
2 changes: 1 addition & 1 deletion src/VersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

final class VersionInfo{
public const NAME = "PocketMine-MP";
public const BASE_VERSION = "5.8.2";
public const BASE_VERSION = "5.8.3";
public const IS_DEVELOPMENT_BUILD = true;
public const BUILD_CHANNEL = "stable";

Expand Down
19 changes: 15 additions & 4 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,22 @@ private function encodeBlockOnlyState() : int{
}

private function encodeFullState() : int{
$writer = new RuntimeDataWriter($this->requiredBlockItemStateDataBits + $this->requiredBlockOnlyStateDataBits);
$writer->writeInt($this->requiredBlockItemStateDataBits, $this->encodeBlockItemState());
$writer->writeInt($this->requiredBlockOnlyStateDataBits, $this->encodeBlockOnlyState());
$blockItemBits = $this->requiredBlockItemStateDataBits;
$blockOnlyBits = $this->requiredBlockOnlyStateDataBits;

return $writer->getValue();
if($blockOnlyBits === 0 && $blockItemBits === 0){
return 0;
}

$result = 0;
if($blockItemBits > 0){
$result |= $this->encodeBlockItemState();
}
if($blockOnlyBits > 0){
$result |= $this->encodeBlockOnlyState() << $blockItemBits;
}

return $result;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/block/GoldOre.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

namespace pocketmine\block;

use pocketmine\block\utils\FortuneDropHelper;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;

final class GoldOre extends Opaque{

public function getDropsForCompatibleTool(Item $item) : array{
return [VanillaItems::RAW_GOLD()];
return [VanillaItems::RAW_GOLD()->setCount(FortuneDropHelper::weighted($item, min: 1, maxBase: 1))];
}

public function isAffectedBySilkTouch() : bool{ return true; }
Expand Down
3 changes: 2 additions & 1 deletion src/block/IronOre.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@

namespace pocketmine\block;

use pocketmine\block\utils\FortuneDropHelper;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;

final class IronOre extends Opaque{

public function getDropsForCompatibleTool(Item $item) : array{
return [VanillaItems::RAW_IRON()];
return [VanillaItems::RAW_IRON()->setCount(FortuneDropHelper::weighted($item, min: 1, maxBase: 1))];
}

public function isAffectedBySilkTouch() : bool{ return true; }
Expand Down
4 changes: 3 additions & 1 deletion src/block/VanillaBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,9 @@ private static function registerBlocksR16() : void{
//for some reason, slabs have weird hardness like the legacy ones
$slabBreakInfo = new Info(BreakInfo::pickaxe(2.0, ToolTier::WOOD, 30.0));

self::register("ancient_debris", new Opaque(new BID(Ids::ANCIENT_DEBRIS), "Ancient Debris", new Info(BreakInfo::pickaxe(30, ToolTier::DIAMOND, 3600.0))));
self::register("ancient_debris", new class(new BID(Ids::ANCIENT_DEBRIS), "Ancient Debris", new Info(BreakInfo::pickaxe(30, ToolTier::DIAMOND, 3600.0))) extends Opaque{
public function isFireProofAsItem() : bool{ return true; }
});
$netheriteBreakInfo = new Info(BreakInfo::pickaxe(50, ToolTier::DIAMOND, 3600.0));
self::register("netherite", new class(new BID(Ids::NETHERITE), "Netherite Block", $netheriteBreakInfo) extends Opaque{
public function isFireProofAsItem() : bool{ return true; }
Expand Down
56 changes: 34 additions & 22 deletions src/block/tile/Sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,30 @@ public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);
}

private function readTextTag(CompoundTag $nbt, bool $lightingBugResolved) : void{
$baseColor = new Color(0, 0, 0);
$glowingText = false;
if(($baseColorTag = $nbt->getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
$baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
}
if($lightingBugResolved && ($glowingTextTag = $nbt->getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag){
//both of these must be 1 - if only one is set, it's a leftover from 1.16.210 experimental features
//see https://bugs.mojang.com/browse/MCPE-117835
$glowingText = $glowingTextTag->getValue() !== 0;
}
$this->text = SignText::fromBlob(mb_scrub($nbt->getString(self::TAG_TEXT_BLOB), 'UTF-8'), $baseColor, $glowingText);
}

public function readSaveData(CompoundTag $nbt) : void{
if(($textBlobTag = $nbt->getTag(self::TAG_TEXT_BLOB)) instanceof StringTag){ //MCPE 1.2 save format
$baseColor = new Color(0, 0, 0);
$glowingText = false;
if(($baseColorTag = $nbt->getTag(self::TAG_TEXT_COLOR)) instanceof IntTag){
$baseColor = Color::fromARGB(Binary::unsignInt($baseColorTag->getValue()));
}
if(
($glowingTextTag = $nbt->getTag(self::TAG_GLOWING_TEXT)) instanceof ByteTag &&
($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag
){
//both of these must be 1 - if only one is set, it's a leftover from 1.16.210 experimental features
//see https://bugs.mojang.com/browse/MCPE-117835
$glowingText = $glowingTextTag->getValue() !== 0 && $lightingBugResolvedTag->getValue() !== 0;
$frontTextTag = $nbt->getTag(self::TAG_FRONT_TEXT);
if($frontTextTag instanceof CompoundTag){
$this->readTextTag($frontTextTag, true);
}elseif($nbt->getTag(self::TAG_TEXT_BLOB) instanceof StringTag){ //MCPE 1.2 save format
$lightingBugResolved = false;
if(($lightingBugResolvedTag = $nbt->getTag(self::TAG_LEGACY_BUG_RESOLVE)) instanceof ByteTag){
$lightingBugResolved = $lightingBugResolvedTag->getValue() !== 0;
}
$this->text = SignText::fromBlob(mb_scrub($textBlobTag->getValue(), 'UTF-8'), $baseColor, $glowingText);
$this->readTextTag($nbt, $lightingBugResolved);
}else{
$text = [];
for($i = 0; $i < SignText::LINE_COUNT; ++$i){
Expand All @@ -108,15 +116,19 @@ public function readSaveData(CompoundTag $nbt) : void{
}

protected function writeSaveData(CompoundTag $nbt) : void{
$nbt->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines()));
$nbt->setTag(self::TAG_FRONT_TEXT, CompoundTag::create()
->setString(self::TAG_TEXT_BLOB, implode("\n", $this->text->getLines()))
->setInt(self::TAG_TEXT_COLOR, Binary::signInt($this->text->getBaseColor()->toARGB()))
->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0)
->setByte(self::TAG_PERSIST_FORMATTING, 1)
);
$nbt->setTag(self::TAG_BACK_TEXT, CompoundTag::create()
->setString(self::TAG_TEXT_BLOB, "")
->setInt(self::TAG_TEXT_COLOR, Binary::signInt(0xff_00_00_00))
->setByte(self::TAG_GLOWING_TEXT, 0)
->setByte(self::TAG_PERSIST_FORMATTING, 1)
);

for($i = 0; $i < SignText::LINE_COUNT; ++$i){ //Backwards-compatibility
$textKey = sprintf(self::TAG_TEXT_LINE, $i + 1);
$nbt->setString($textKey, $this->text->getLine($i));
}
$nbt->setInt(self::TAG_TEXT_COLOR, Binary::signInt($this->text->getBaseColor()->toARGB()));
$nbt->setByte(self::TAG_GLOWING_TEXT, $this->text->isGlowing() ? 1 : 0);
$nbt->setByte(self::TAG_LEGACY_BUG_RESOLVE, 1);
$nbt->setByte(self::TAG_WAXED, $this->waxed ? 1 : 0);
}

Expand Down
12 changes: 11 additions & 1 deletion src/block/utils/CropGrowthHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ final class CropGrowthHelper{

private const IMPROPER_ARRANGEMENT_DIVISOR = 2;

private const MIN_LIGHT_LEVEL = 9;

private function __construct(){
//NOOP
}
Expand Down Expand Up @@ -102,9 +104,17 @@ public static function calculateMultiplier(Block $block) : float{
return $result;
}

public static function hasEnoughLight(Block $block, int $minLevel = self::MIN_LIGHT_LEVEL) : bool{
$position = $block->getPosition();
$world = $position->getWorld();

//crop growth is not affected by time of day since 1.11 or so
return $world->getPotentialLightAt($position->x, $position->y, $position->z) >= $minLevel;
}

public static function canGrow(Block $block) : bool{
//while it may be tempting to use mt_rand(0, 25) < multiplier, this would make crops grow a bit faster than
//vanilla in most cases due to the remainder of 25 / multiplier not being discarded
return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0;
return mt_rand(0, (int) (25 / self::calculateMultiplier($block))) === 0 && self::hasEnoughLight($block);
}
}
2 changes: 1 addition & 1 deletion src/data/bedrock/block/upgrade/BlockStateUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function upgrade(BlockStateData $blockStateData) : BlockStateData{
if(is_string($remap->newName)){
$newName = $remap->newName;
}else{
$flattenedValue = $oldState[$remap->newName->flattenedProperty];
$flattenedValue = $oldState[$remap->newName->flattenedProperty] ?? null;
if($flattenedValue instanceof StringTag){
$newName = sprintf("%s%s%s", $remap->newName->prefix, $flattenedValue->getValue(), $remap->newName->suffix);
unset($oldState[$remap->newName->flattenedProperty]);
Expand Down
Loading

0 comments on commit c4fa3e2

Please sign in to comment.