Added rare drop from reactor
Tall grass now drop only wheat seeds
Fix utils::chance()
Zombie now can drop carrot or potato
This commit is contained in:
ArkQuark 2022-06-02 23:56:38 +03:00
parent ccc51c8fe7
commit ac60efb7ca
4 changed files with 27 additions and 39 deletions

View file

@ -56,9 +56,7 @@ class NetherReactorBlock extends SolidBlock{
//}
}
private function randomFloat(){
return (rand()/getrandmax());
}
public function destroy(){
$this->level->setBlock(new Vector3($this->x, $this->y, $this->z),new NetherReactorBlock(2));
$this->decay($this->x-8, $this->y-3, $this->z-8, 0, 17, 16, 2, 34, 1, 0, 17, 1);
@ -73,7 +71,7 @@ class NetherReactorBlock extends SolidBlock{
for($a = $aOne; $a < $aTwo; $a += $aThree) { //wth those cycles are?
for($b = $bOne; $b < $bTwo; $b += $bThree) {
for($c = $cOne; $c < $cTwo; $c += $cThree) {
if ($this->level->getBlock(new Vector3($x+$a, $y+$b, $z+$c))->getID() === 87 && $this->randomFloat() >0.75){
if ($this->level->getBlock(new Vector3($x+$a, $y+$b, $z+$c))->getID() === 87 && Utils::randomFloat() > 0.75){
$this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock());
}
}
@ -102,22 +100,23 @@ class NetherReactorBlock extends SolidBlock{
$forceAmount = $data[3];
$server = ServerAPI::request();
if(!$forceAmount){
$spawnNumber = $minAmount + floor($this->randomFloat()*($maxAmount-$minAmount+1));
$spawnNumber = $minAmount + floor(Utils::randomFloat()*($maxAmount-$minAmount+1));
}
else{
$spawnNumber = $maxAmount;
}
for($i = 0; $i < $spawnNumber; $i++) {
$randomRange = floor($this->randomFloat()*5+3);
$shiftX = cos(floor($this->randomFloat()*360)*(pi()/180));
$shiftZ = sin(floor($this->randomFloat()*360)*(pi()/180));
$randomId = $this->possibleLoot[array_rand($this->possibleLoot)];
$server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y-1, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomId, 0, 1));
$randomRange = floor(Utils::randomFloat()*5+3);
$shiftX = cos(floor(Utils::randomFloat()*360)*(pi()/180));
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
if(Utils::chance(5)) $randomID = $this->rarePossibleLoot[array_rand($this->rarePossibleLoot)];
else $randomID = $this->possibleLoot[array_rand($this->possibleLoot)];
$server->api->entity->drop(new Position($x+($shiftX*$randomRange)+0.5, $y-1, $z+($shiftZ*$randomRange)+0.5, $this->level), BlockAPI::getItem($randomID, 0, 1));
}
for($i = 0; $i < $pigmen; $i++) {
$randomRange = floor($this->randomFloat()*5+3);
$shiftX = cos(floor($this->randomFloat()*360)*(pi()/180));
$shiftZ = sin(floor($this->randomFloat()*360)*(pi()/180));
$randomRange = floor(Utils::randomFloat()*5+3);
$shiftX = cos(floor(Utils::randomFloat()*360)*(pi()/180));
$shiftZ = sin(floor(Utils::randomFloat()*360)*(pi()/180));
$data = array(
"x" => $x+($shiftX*$randomRange)+0.5,
"y" => $y-1,
@ -232,9 +231,15 @@ class NetherReactorBlock extends SolidBlock{
}
return true;
}
private $possibleLoot = [
GLOWSTONE_DUST, QUARTZ, CACTUS, SUGARCANE, BROWN_MUSHROOM, RED_MUSHROOM, BOW, BOWL, PUMPKIN_SEEDS, MELON_SEEDS
GLOWSTONE_DUST, QUARTZ, CACTUS, SUGARCANE, BROWN_MUSHROOM, RED_MUSHROOM, PUMPKIN_SEEDS, MELON_SEEDS
];
private $rarePossibleLoot = [
BOW, BED, BOWL, ARROW, WOODEN_DOOR, FEATHER, PAINTING, BONE, DANDELION
];
private $core = [
-1 => ["GCG", "CCC", "GCG"],
0 => ["C C", " R ", "C C",],

View file

@ -34,10 +34,9 @@ class TallGrassBlock extends FlowableBlock{
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->isTransparent === true){ //Replace with common break method
if($this->getSide(0)->isTransparent === true){//Replace with common break method
$this->level->setBlock($this, new AirBlock(), false, false, true);
$random = mt_rand(0,3);
if($random == 3) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS));
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(WHEAT_SEEDS));
return BLOCK_UPDATE_NORMAL;
}
}
@ -46,34 +45,16 @@ class TallGrassBlock extends FlowableBlock{
public function getDrops(Item $item, Player $player){
$drops = array();
$possibleDrops = array(
array(WHEAT_SEEDS, 0, 1),
array(CARROT, 0, 1),
array(POTATO, 0, 1),
array(BEETROOT_SEEDS, 0, 1),
array(MELON_SEEDS, 0, 1),
array(PUMPKIN_SEEDS, 0, 1),
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
);
if ($item->isShears()){
$drops[] = array($this->id, $this->meta & 0x03, 1);
}
elseif(($item = $possibleDrops[mt_rand(0, count($possibleDrops) - 1)]) !== 0){
$drops[] = $item;
elseif(Utils::chance(15)){
$drops[] = array(WHEAT_SEEDS, 0, 1)
}
return $drops;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() == 2 or $down->getID() == 3){
$this->level->setBlock($block, $this, true, false, true);

View file

@ -385,7 +385,7 @@ class Utils{
}
public static function chance($i){//GameHerobrine's code
return self::randomFloat() < $i / 100;
return self::randomFloat() <= $i / 100;
}
public static function round($number){

View file

@ -276,6 +276,8 @@ class Entity extends Position{
//Monsters
case MOB_ZOMBIE:
return array(
array(CARROT, 0, Utils::chance(0.83) ? 1 : 0),
array(POTATO, 0, Utils::chance(0.83) ? 1 : 0),
array(FEATHER, 0, mt_rand(0,2)),
);
case MOB_SPIDER: