From ca2bf73e06c0cae202f56f04bb4ee85ea229ff0b Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Wed, 1 Jun 2022 19:32:11 +0300 Subject: [PATCH] Sheep color chance --- src/utils/Utils.php | 8 ++++++++ src/world/Entity.php | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/utils/Utils.php b/src/utils/Utils.php index fff7aa29..e4fdddb3 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -379,6 +379,14 @@ class Utils{ $lastRandom = hash("sha512", $lastRandom, true); return $raw === false ? bin2hex($output):$output; } + + public static function randomFloat(){//GameHerobrine's code + return rand()/getrandmax(); + } + + public static function chance($i){//GameHerobrine's code + return randomFloat() < $i / 100; + } public static function round($number){ return round($number, 0, PHP_ROUND_HALF_DOWN); diff --git a/src/world/Entity.php b/src/world/Entity.php index 60077ae3..20c7c9b7 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -633,6 +633,7 @@ class Entity extends Position{ return null; } } + /*METADATA VALUES(EXPEREMENTAL) ****************** Types: Get input type of @@ -650,6 +651,29 @@ class Entity extends Position{ 16 => array("type" => 0, "value" => 0) --> Unknown 17 => array("type" => 6, "value" => array(0, 0, 0)) --> Unknown */ + + public function sheepColor(){ + $chance = Utils::randomFloat() * 100; + switch($chance){ + case $chance <= 0.1558: + $color = 6; + break; + case $chance <= 2.85: + $color = 12; + break; + case $chance <= 4.75: + $rand = mt_rand(1,3); + if($rand == 1) $color = 15; + elseif($rand == 2) $color = 7; + else $color = 8; + break; + case $chance <= 100: + $color = 0; + break; + } + return $color; + } + public function getMetadata(){ $flags = 0; $flags |= $this->fire > 0 ? 1:0; @@ -669,7 +693,7 @@ class Entity extends Position{ if($this->class === ENTITY_MOB and $this->type === MOB_SHEEP){ if(!isset($this->data["Sheared"])){ $this->data["Sheared"] = 0; - $this->data["Color"] = mt_rand(0,15); + $this->data["Color"] = $this->sheepColor(); } $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); }elseif($this->class === ENTITY_OBJECT && $this->type === OBJECT_PRIMEDTNT){ //ladder fix 2.0