mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 00:39:45 +00:00
Merge 'minor-next' into 'major-next'
Automatic merge performed by: https://github.com/pmmp/RestrictedActions/actions/runs/12042121495
This commit is contained in:
commit
a078f653f4
@ -35,10 +35,10 @@ use pocketmine\math\AxisAlignedBB;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
use pocketmine\world\sound\AnvilFallSound;
|
use pocketmine\world\sound\AnvilFallSound;
|
||||||
use pocketmine\world\sound\Sound;
|
use pocketmine\world\sound\Sound;
|
||||||
use function lcg_value;
|
|
||||||
use function round;
|
use function round;
|
||||||
|
|
||||||
class Anvil extends Transparent implements Fallable{
|
class Anvil extends Transparent implements Fallable{
|
||||||
@ -97,7 +97,7 @@ class Anvil extends Transparent implements Fallable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onHitGround(FallingBlock $blockEntity) : bool{
|
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){
|
if($this->damage !== self::VERY_DAMAGED){
|
||||||
$this->damage = $this->damage + 1;
|
$this->damage = $this->damage + 1;
|
||||||
}else{
|
}else{
|
||||||
|
@ -31,8 +31,8 @@ use pocketmine\event\entity\EntityTrampleFarmlandEvent;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use function intdiv;
|
use function intdiv;
|
||||||
use function lcg_value;
|
|
||||||
|
|
||||||
class Farmland extends Transparent{
|
class Farmland extends Transparent{
|
||||||
public const MAX_WETNESS = 7;
|
public const MAX_WETNESS = 7;
|
||||||
@ -148,7 +148,7 @@ class Farmland extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onEntityLand(Entity $entity) : ?float{
|
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 = new EntityTrampleFarmlandEvent($entity, $this);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
|
@ -31,13 +31,13 @@ use pocketmine\item\Item;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
use pocketmine\world\sound\ItemFrameAddItemSound;
|
use pocketmine\world\sound\ItemFrameAddItemSound;
|
||||||
use pocketmine\world\sound\ItemFrameRemoveItemSound;
|
use pocketmine\world\sound\ItemFrameRemoveItemSound;
|
||||||
use pocketmine\world\sound\ItemFrameRotateItemSound;
|
use pocketmine\world\sound\ItemFrameRotateItemSound;
|
||||||
use function is_infinite;
|
use function is_infinite;
|
||||||
use function is_nan;
|
use function is_nan;
|
||||||
use function lcg_value;
|
|
||||||
|
|
||||||
class ItemFrame extends Flowable{
|
class ItemFrame extends Flowable{
|
||||||
use AnyFacingTrait;
|
use AnyFacingTrait;
|
||||||
@ -154,7 +154,7 @@ class ItemFrame extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$world = $this->position->getWorld();
|
$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->dropItem($this->position->add(0.5, 0.5, 0.5), clone $this->framedItem);
|
||||||
$world->addSound($this->position, new ItemFrameRemoveItemSound());
|
$world->addSound($this->position, new ItemFrameRemoveItemSound());
|
||||||
}
|
}
|
||||||
@ -185,7 +185,7 @@ class ItemFrame extends Flowable{
|
|||||||
|
|
||||||
public function getDropsForCompatibleTool(Item $item) : array{
|
public function getDropsForCompatibleTool(Item $item) : array{
|
||||||
$drops = parent::getDropsForCompatibleTool($item);
|
$drops = parent::getDropsForCompatibleTool($item);
|
||||||
if($this->framedItem !== null && lcg_value() <= $this->itemDropChance){
|
if($this->framedItem !== null && Utils::getRandomFloat() <= $this->itemDropChance){
|
||||||
$drops[] = clone $this->framedItem;
|
$drops[] = clone $this->framedItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ use pocketmine\item\Item;
|
|||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\sound\FizzSound;
|
use pocketmine\world\sound\FizzSound;
|
||||||
use pocketmine\world\sound\Sound;
|
use pocketmine\world\sound\Sound;
|
||||||
use function lcg_value;
|
|
||||||
|
|
||||||
abstract class Liquid extends Transparent{
|
abstract class Liquid extends Transparent{
|
||||||
public const MAX_DECAY = 7;
|
public const MAX_DECAY = 7;
|
||||||
@ -368,7 +368,7 @@ abstract class Liquid extends Transparent{
|
|||||||
|
|
||||||
protected function liquidCollide(Block $cause, Block $result) : bool{
|
protected function liquidCollide(Block $cause, Block $result) : bool{
|
||||||
if(BlockEventHelper::form($this, $result, $cause)){
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ use function deg2rad;
|
|||||||
use function floor;
|
use function floor;
|
||||||
use function fmod;
|
use function fmod;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
use function lcg_value;
|
|
||||||
use function sin;
|
use function sin;
|
||||||
use function spl_object_id;
|
use function spl_object_id;
|
||||||
use const M_PI_2;
|
use const M_PI_2;
|
||||||
@ -910,7 +909,7 @@ abstract class Entity{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$force = lcg_value() * 0.2 + 0.1;
|
$force = Utils::getRandomFloat() * 0.2 + 0.1;
|
||||||
|
|
||||||
$this->motion = match($direction){
|
$this->motion = match($direction){
|
||||||
Facing::WEST => $this->motion->withComponents(-$force, null, null),
|
Facing::WEST => $this->motion->withComponents(-$force, null, null),
|
||||||
|
@ -58,6 +58,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
|||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\timings\Timings;
|
use pocketmine\timings\Timings;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\sound\BurpSound;
|
use pocketmine\world\sound\BurpSound;
|
||||||
use pocketmine\world\sound\EntityLandSound;
|
use pocketmine\world\sound\EntityLandSound;
|
||||||
use pocketmine\world\sound\EntityLongFallSound;
|
use pocketmine\world\sound\EntityLongFallSound;
|
||||||
@ -69,7 +70,6 @@ use function ceil;
|
|||||||
use function count;
|
use function count;
|
||||||
use function floor;
|
use function floor;
|
||||||
use function ksort;
|
use function ksort;
|
||||||
use function lcg_value;
|
|
||||||
use function max;
|
use function max;
|
||||||
use function min;
|
use function min;
|
||||||
use function mt_getrandmax;
|
use function mt_getrandmax;
|
||||||
@ -490,7 +490,7 @@ abstract class Living extends Entity{
|
|||||||
$helmet = $this->armorInventory->getHelmet();
|
$helmet = $this->armorInventory->getHelmet();
|
||||||
if($helmet instanceof Armor){
|
if($helmet instanceof Armor){
|
||||||
$finalDamage = $source->getFinalDamage();
|
$finalDamage = $source->getFinalDamage();
|
||||||
$this->damageItem($helmet, (int) round($finalDamage * 4 + lcg_value() * $finalDamage * 2));
|
$this->damageItem($helmet, (int) round($finalDamage * 4 + Utils::getRandomFloat() * $finalDamage * 2));
|
||||||
$this->armorInventory->setHelmet($helmet);
|
$this->armorInventory->setHelmet($helmet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -697,7 +697,7 @@ abstract class Living extends Entity{
|
|||||||
$this->setBreathing(false);
|
$this->setBreathing(false);
|
||||||
|
|
||||||
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(VanillaEnchantments::RESPIRATION())) <= 0 ||
|
if(($respirationLevel = $this->armorInventory->getHelmet()->getEnchantmentLevel(VanillaEnchantments::RESPIRATION())) <= 0 ||
|
||||||
lcg_value() <= (1 / ($respirationLevel + 1))
|
Utils::getRandomFloat() <= (1 / ($respirationLevel + 1))
|
||||||
){
|
){
|
||||||
$ticks -= $tickDiff;
|
$ticks -= $tickDiff;
|
||||||
if($ticks <= -20){
|
if($ticks <= -20){
|
||||||
|
@ -33,7 +33,7 @@ use pocketmine\nbt\tag\CompoundTag;
|
|||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
use function lcg_value;
|
use pocketmine\utils\Utils;
|
||||||
use function mt_rand;
|
use function mt_rand;
|
||||||
|
|
||||||
class Armor extends Durable{
|
class Armor extends Durable{
|
||||||
@ -129,7 +129,7 @@ class Armor extends Durable{
|
|||||||
|
|
||||||
$chance = 1 / ($unbreakingLevel + 1);
|
$chance = 1 / ($unbreakingLevel + 1);
|
||||||
for($i = 0; $i < $amount; ++$i){
|
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++;
|
$negated++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
|||||||
|
|
||||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use function lcg_value;
|
use pocketmine\utils\Utils;
|
||||||
use function min;
|
use function min;
|
||||||
|
|
||||||
abstract class Durable extends Item{
|
abstract class Durable extends Item{
|
||||||
@ -87,7 +87,7 @@ abstract class Durable extends Item{
|
|||||||
|
|
||||||
$chance = 1 / ($unbreakingLevel + 1);
|
$chance = 1 / ($unbreakingLevel + 1);
|
||||||
for($i = 0; $i < $amount; ++$i){
|
for($i = 0; $i < $amount; ++$i){
|
||||||
if(lcg_value() > $chance){
|
if(Utils::getRandomFloat() > $chance){
|
||||||
$negated++;
|
$negated++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace pocketmine\item;
|
|||||||
|
|
||||||
use pocketmine\entity\effect\EffectInstance;
|
use pocketmine\entity\effect\EffectInstance;
|
||||||
use pocketmine\entity\effect\VanillaEffects;
|
use pocketmine\entity\effect\VanillaEffects;
|
||||||
use function lcg_value;
|
use pocketmine\utils\Utils;
|
||||||
|
|
||||||
class RottenFlesh extends Food{
|
class RottenFlesh extends Food{
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class RottenFlesh extends Food{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getAdditionalEffects() : array{
|
public function getAdditionalEffects() : array{
|
||||||
if(lcg_value() <= 0.8){
|
if(Utils::getRandomFloat() <= 0.8){
|
||||||
return [
|
return [
|
||||||
new EffectInstance(VanillaEffects::HUNGER(), 600)
|
new EffectInstance(VanillaEffects::HUNGER(), 600)
|
||||||
];
|
];
|
||||||
|
@ -27,15 +27,15 @@ use pocketmine\block\Block;
|
|||||||
use pocketmine\entity\Entity;
|
use pocketmine\entity\Entity;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use function lcg_value;
|
|
||||||
|
|
||||||
abstract class SpawnEgg extends Item{
|
abstract class SpawnEgg extends Item{
|
||||||
|
|
||||||
abstract protected function createEntity(World $world, Vector3 $pos, float $yaw, float $pitch) : Entity;
|
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{
|
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()){
|
if($this->hasCustomName()){
|
||||||
$entity->setNameTag($this->getCustomName());
|
$entity->setNameTag($this->getCustomName());
|
||||||
|
@ -67,6 +67,8 @@ use function is_nan;
|
|||||||
use function is_object;
|
use function is_object;
|
||||||
use function is_string;
|
use function is_string;
|
||||||
use function mb_check_encoding;
|
use function mb_check_encoding;
|
||||||
|
use function mt_getrandmax;
|
||||||
|
use function mt_rand;
|
||||||
use function ob_end_clean;
|
use function ob_end_clean;
|
||||||
use function ob_get_contents;
|
use function ob_get_contents;
|
||||||
use function ob_start;
|
use function ob_start;
|
||||||
@ -688,4 +690,12 @@ final class Utils{
|
|||||||
//jit not available
|
//jit not available
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random float between 0.0 and 1.0
|
||||||
|
* Drop-in replacement for lcg_value()
|
||||||
|
*/
|
||||||
|
public static function getRandomFloat() : float{
|
||||||
|
return mt_rand() / mt_getrandmax();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ use pocketmine\ServerConfigGroup;
|
|||||||
use pocketmine\utils\AssumptionFailedError;
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use pocketmine\utils\Limits;
|
use pocketmine\utils\Limits;
|
||||||
use pocketmine\utils\ReversePriorityQueue;
|
use pocketmine\utils\ReversePriorityQueue;
|
||||||
|
use pocketmine\utils\Utils;
|
||||||
use pocketmine\world\biome\Biome;
|
use pocketmine\world\biome\Biome;
|
||||||
use pocketmine\world\biome\BiomeRegistry;
|
use pocketmine\world\biome\BiomeRegistry;
|
||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
@ -120,7 +121,6 @@ use function get_class;
|
|||||||
use function gettype;
|
use function gettype;
|
||||||
use function is_a;
|
use function is_a;
|
||||||
use function is_object;
|
use function is_object;
|
||||||
use function lcg_value;
|
|
||||||
use function max;
|
use function max;
|
||||||
use function microtime;
|
use function microtime;
|
||||||
use function min;
|
use function min;
|
||||||
@ -1998,10 +1998,10 @@ class World implements ChunkManager{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemEntity = new ItemEntity(Location::fromObject($source, $this, lcg_value() * 360, 0), $item);
|
$itemEntity = new ItemEntity(Location::fromObject($source, $this, Utils::getRandomFloat() * 360, 0), $item);
|
||||||
|
|
||||||
$itemEntity->setPickupDelay($delay);
|
$itemEntity->setPickupDelay($delay);
|
||||||
$itemEntity->setMotion($motion ?? new Vector3(lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1));
|
$itemEntity->setMotion($motion ?? new Vector3(Utils::getRandomFloat() * 0.2 - 0.1, 0.2, Utils::getRandomFloat() * 0.2 - 0.1));
|
||||||
$itemEntity->spawnToAll();
|
$itemEntity->spawnToAll();
|
||||||
|
|
||||||
return $itemEntity;
|
return $itemEntity;
|
||||||
@ -2018,9 +2018,9 @@ class World implements ChunkManager{
|
|||||||
$orbs = [];
|
$orbs = [];
|
||||||
|
|
||||||
foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){
|
foreach(ExperienceOrb::splitIntoOrbSizes($amount) as $split){
|
||||||
$orb = new ExperienceOrb(Location::fromObject($pos, $this, lcg_value() * 360, 0), $split);
|
$orb = new ExperienceOrb(Location::fromObject($pos, $this, Utils::getRandomFloat() * 360, 0), $split);
|
||||||
|
|
||||||
$orb->setMotion(new Vector3((lcg_value() * 0.2 - 0.1) * 2, lcg_value() * 0.4, (lcg_value() * 0.2 - 0.1) * 2));
|
$orb->setMotion(new Vector3((Utils::getRandomFloat() * 0.2 - 0.1) * 2, Utils::getRandomFloat() * 0.4, (Utils::getRandomFloat() * 0.2 - 0.1) * 2));
|
||||||
$orb->spawnToAll();
|
$orb->spawnToAll();
|
||||||
|
|
||||||
$orbs[] = $orb;
|
$orbs[] = $orb;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user