Merge branch 'major-next' into inventory-rework

This commit is contained in:
Dylan T.
2024-12-06 12:58:03 +00:00
committed by GitHub
66 changed files with 1858 additions and 959 deletions

View File

@ -33,7 +33,7 @@ use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\player\Player;
use pocketmine\utils\Binary;
use function lcg_value;
use pocketmine\utils\Utils;
use function mt_rand;
class Armor extends Durable{
@ -129,7 +129,7 @@ class Armor extends Durable{
$chance = 1 / ($unbreakingLevel + 1);
for($i = 0; $i < $amount; ++$i){
if(mt_rand(1, 100) > 60 && lcg_value() > $chance){ //unbreaking only applies to armor 40% of the time at best
if(mt_rand(1, 100) > 60 && Utils::getRandomFloat() > $chance){ //unbreaking only applies to armor 40% of the time at best
$negated++;
}
}

View File

@ -25,7 +25,7 @@ namespace pocketmine\item;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\nbt\tag\CompoundTag;
use function lcg_value;
use pocketmine\utils\Utils;
use function min;
abstract class Durable extends Item{
@ -87,7 +87,7 @@ abstract class Durable extends Item{
$chance = 1 / ($unbreakingLevel + 1);
for($i = 0; $i < $amount; ++$i){
if(lcg_value() > $chance){
if(Utils::getRandomFloat() > $chance){
$negated++;
}
}

View File

@ -44,6 +44,6 @@ abstract class Food extends Item implements FoodSourceItem{
}
public function canStartUsingItem(Player $player) : bool{
return !$this->requiresHunger() || $player->getHungerManager()->isHungry();
return !$this->requiresHunger() || $player->canEat();
}
}

View File

@ -327,8 +327,9 @@ final class ItemTypeIds{
public const GOAT_HORN = 20288;
public const END_CRYSTAL = 20289;
public const ICE_BOMB = 20290;
public const RECOVERY_COMPASS = 20291;
public const FIRST_UNUSED_ITEM_ID = 20291;
public const FIRST_UNUSED_ITEM_ID = 20292;
private static int $nextDynamicId = self::FIRST_UNUSED_ITEM_ID;

View File

@ -25,7 +25,7 @@ namespace pocketmine\item;
use pocketmine\entity\effect\EffectInstance;
use pocketmine\entity\effect\VanillaEffects;
use function lcg_value;
use pocketmine\utils\Utils;
class RottenFlesh extends Food{
@ -38,7 +38,7 @@ class RottenFlesh extends Food{
}
public function getAdditionalEffects() : array{
if(lcg_value() <= 0.8){
if(Utils::getRandomFloat() <= 0.8){
return [
new EffectInstance(VanillaEffects::HUNGER(), 600)
];

View File

@ -27,15 +27,15 @@ use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\utils\Utils;
use pocketmine\world\World;
use function lcg_value;
abstract class SpawnEgg extends Item{
abstract protected function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity;
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
$entity = $this->createEntity($player->getWorld(), $blockReplace->getPosition()->add(0.5, 0, 0.5), lcg_value() * 360, 0);
$entity = $this->createEntity($player->getWorld(), $blockReplace->getPosition()->add(0.5, 0, 0.5), Utils::getRandomFloat() * 360, 0);
if($this->hasCustomName()){
$entity->setNameTag($this->getCustomName());

View File

@ -1481,6 +1481,7 @@ final class StringToItemParser extends StringToTParser{
$result->register("record_strad", fn() => Items::RECORD_STRAD());
$result->register("record_wait", fn() => Items::RECORD_WAIT());
$result->register("record_ward", fn() => Items::RECORD_WARD());
$result->register("recovery_compass", fn() => Items::RECOVERY_COMPASS());
$result->register("redstone", fn() => Items::REDSTONE_DUST());
$result->register("redstone_dust", fn() => Items::REDSTONE_DUST());
$result->register("rib_armor_trim_smithing_template", fn() => Items::RIB_ARMOR_TRIM_SMITHING_TEMPLATE());

View File

@ -284,6 +284,7 @@ use function strtolower;
* @method static Record RECORD_STRAD()
* @method static Record RECORD_WAIT()
* @method static Record RECORD_WARD()
* @method static Item RECOVERY_COMPASS()
* @method static Redstone REDSTONE_DUST()
* @method static Item RIB_ARMOR_TRIM_SMITHING_TEMPLATE()
* @method static RottenFlesh ROTTEN_FLESH()
@ -574,6 +575,7 @@ final class VanillaItems{
self::register("record_strad", fn(IID $id) => new Record($id, RecordType::DISK_STRAD, "Record Strad"));
self::register("record_wait", fn(IID $id) => new Record($id, RecordType::DISK_WAIT, "Record Wait"));
self::register("record_ward", fn(IID $id) => new Record($id, RecordType::DISK_WARD, "Record Ward"));
self::register("recovery_compass", fn(IID $id) => new Item($id, "Recovery Compass"));
self::register("redstone_dust", fn(IID $id) => new Redstone($id, "Redstone"));
self::register("rotten_flesh", fn(IID $id) => new RottenFlesh($id, "Rotten Flesh"));
self::register("scute", fn(IID $id) => new Item($id, "Scute"));

View File

@ -57,6 +57,7 @@ final class AvailableEnchantmentRegistry{
$this->register(Enchantments::THORNS(), [Tags::CHESTPLATE], [Tags::HELMET, Tags::LEGGINGS, Tags::BOOTS]);
$this->register(Enchantments::RESPIRATION(), [Tags::HELMET], []);
$this->register(Enchantments::AQUA_AFFINITY(), [Tags::HELMET], []);
$this->register(Enchantments::FROST_WALKER(), [/* no primary items */], [Tags::BOOTS]);
$this->register(Enchantments::SHARPNESS(), [Tags::SWORD, Tags::AXE], []);
$this->register(Enchantments::KNOCKBACK(), [Tags::SWORD], []);
$this->register(Enchantments::FIRE_ASPECT(), [Tags::SWORD], []);

View File

@ -44,6 +44,7 @@ final class StringToEnchantmentParser extends StringToTParser{
$result->register("fire_protection", fn() => VanillaEnchantments::FIRE_PROTECTION());
$result->register("flame", fn() => VanillaEnchantments::FLAME());
$result->register("fortune", fn() => VanillaEnchantments::FORTUNE());
$result->register("frost_walker", fn() => VanillaEnchantments::FROST_WALKER());
$result->register("infinity", fn() => VanillaEnchantments::INFINITY());
$result->register("knockback", fn() => VanillaEnchantments::KNOCKBACK());
$result->register("mending", fn() => VanillaEnchantments::MENDING());

View File

@ -41,6 +41,7 @@ use pocketmine\utils\RegistryTrait;
* @method static ProtectionEnchantment FIRE_PROTECTION()
* @method static Enchantment FLAME()
* @method static Enchantment FORTUNE()
* @method static Enchantment FROST_WALKER()
* @method static Enchantment INFINITY()
* @method static KnockbackEnchantment KNOCKBACK()
* @method static Enchantment MENDING()
@ -131,6 +132,14 @@ final class VanillaEnchantments{
fn(int $level) : int => 10 * $level,
30
));
self::register("FROST_WALKER", new Enchantment(
KnownTranslationFactory::enchantment_frostwalker(),
Rarity::RARE,
2,
fn(int $level) : int => 10 * $level,
15
));
self::register("AQUA_AFFINITY", new Enchantment(
KnownTranslationFactory::enchantment_waterWorker(),
Rarity::RARE,