Skip to content

Commit

Permalink
fix: blocksCount = 0
Browse files Browse the repository at this point in the history
  • Loading branch information
AzaleeX committed Nov 9, 2024
1 parent 1f73547 commit 215db35
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/world/generator/object/NetherGrass.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ public static function growGrass(ChunkManager $world, Vector3 $pos, Random $rand
}

$blocksCount = count($blocksToGrow) - 1;
for ($c = 0; $c < $count; ++$c) {
$x = $random->nextRange((int) ($pos->x - $radius), (int) ($pos->x + $radius));
$z = $random->nextRange((int) ($pos->z - $radius), (int) ($pos->z + $radius));
$blockBelow = $world->getBlockAt($x, (int) $pos->y, $z);
if ($world->getBlockAt($x, (int) ($pos->y + 1), $z)->getTypeId() === BlockTypeIds::AIR && $blockBelow->getTypeId() !== BlockTypeIds::AIR) {
$blockToGrow = $blocksToGrow[$random->nextRange(0, $blocksCount)];
if ($blockToGrow === VanillaBlocks::CRIMSON_ROOTS()) {
if ($random->nextFloat() < 0.1) { // 10% chance for rare blocks
$world->setBlockAt($x, (int) ($pos->y + 1), $z, $blockToGrow);
if ($blocksCount >= 0) {
for ($c = 0; $c < $count; ++$c) {
$x = $random->nextRange((int)($pos->x - $radius), (int)($pos->x + $radius));
$z = $random->nextRange((int)($pos->z - $radius), (int)($pos->z + $radius));
$blockBelow = $world->getBlockAt((int)$x, (int)$pos->y, (int)$z);

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 61 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.
if ($world->getBlockAt((int)$x, (int)($pos->y + 1), (int)$z)->getTypeId() === BlockTypeIds::AIR && $blockBelow->getTypeId() !== BlockTypeIds::AIR) {

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 62 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.
$blockToGrow = $blocksToGrow[$random->nextRange(0, $blocksCount)];

Check failure on line 63 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Offset int does not exist on array{}|array{0: pocketmine\block\NetherRoots, 1?: pocketmine\block\NetherRoots}.

Check failure on line 63 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Offset int does not exist on array{}|array{0: pocketmine\block\NetherRoots, 1?: pocketmine\block\NetherRoots}.

Check failure on line 63 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Offset int does not exist on array{}|array{0: pocketmine\block\NetherRoots, 1?: pocketmine\block\NetherRoots}.
if ($blockToGrow === VanillaBlocks::CRIMSON_ROOTS()) {
if ($random->nextFloat() < 0.1) { // 10% chance for rare blocks
$world->setBlockAt((int)$x, (int)($pos->y + 1), (int)$z, $blockToGrow);

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 66 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.
}
} else {
$world->setBlockAt((int)$x, (int)($pos->y + 1), (int)$z, $blockToGrow);

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.

Check failure on line 69 in src/world/generator/object/NetherGrass.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 / PHPStan analysis

Casting to int something that's already int.
}
} else {
$world->setBlockAt($x, (int) ($pos->y + 1), $z, $blockToGrow);
}
}
}
Expand Down

0 comments on commit 215db35

Please sign in to comment.