diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 9023000d..197ccf18 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -21,7 +21,7 @@ class EntityAPI{ private $server; - private $entities; + public $entities; private $eCnt = 1; function __construct(){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index a32a7f66..ab1530a4 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -74,6 +74,7 @@ class PocketMinecraftServer{ console("[INFO] Loading extra.properties..."); $this->extraprops = new Config(DATA_PATH . "extra.properties", CONFIG_PROPERTIES, array( "version" => "4", + "enable-nether-reactor" => true, "enable-explosions" => true, "enable-rail-connection" => false, "save-player-data" => true, @@ -85,7 +86,7 @@ class PocketMinecraftServer{ )); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); RailBlock::$shouldconnectrails = $this->extraprops->get("enable-rail-connection"); //Rail connection in config - + NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); if($this->extraprops->get("discord-msg") == true){ if($this->extraprops->get("discord-webhook-url") !== "none"){ console("[INFO] Discord Logger is enabled."); diff --git a/src/material/block/misc/NetherReactor.php b/src/material/block/misc/NetherReactor.php index 6b142e5c..f7c3e093 100644 --- a/src/material/block/misc/NetherReactor.php +++ b/src/material/block/misc/NetherReactor.php @@ -20,9 +20,224 @@ */ class NetherReactorBlock extends SolidBlock{ + public static $enableReactor = true; public function __construct($meta = 0){ parent::__construct(NETHER_REACTOR, $meta, "Nether Reactor"); $this->isActivable = true; } + public function onActivate(Item $item, Player $player){ + //if(($item->getID() === IRON_SWORD || $item->getID() === WOODEN_SWORD || $item->getID() === STONE_SWORD || $item->getID() === DIAMOND_SWORD || $item->getID() === GOLD_SWORD) /*&& $player->gamemode === 0*/){ + if($this->isCorrect($this->getX(),$this->getY(),$this->getZ()) && $this->getY() < 101){ + NetherReactorStructure::buildReactor($this->level, $this->getX(),$this->getY(),$this->getZ()); + $this->meta = 1; + $this->level->setBlock($this,$this); + $server = ServerAPI::request(); + $server->schedule(40, array($this, "glow"), 1); + $server->schedule(60, array($this, "glow"), 2); + $server->schedule(80, array($this, "glow"), 3); + $server->schedule(140, array($this, "glow"), 4); + $server->schedule(200, array($this, "spawnItems"), [0,15,2,true]); //200 + $server->schedule(260, array($this, "spawnItems"), [0,15,"checkPigmen",true]); + $server->schedule(300, array($this, "spawnItems"), [0,15,"checkPigmen",true]); + $server->schedule(340, array($this, "spawnItems"), [11,20,"checkPigmen",false]); + $server->schedule(400, array($this, "spawnItems"), [0,10,"checkPigmen",false]); + $server->schedule(500, array($this, "spawnItems"), [17,32, "checkPigmen",false]); //500 + $server->schedule(580, array($this, "spawnItems"), [17,32, "checkPigmen",false]); + $server->schedule(620, array($this, "spawnItems"), [1,32, "checkPigmen",false]); + $server->schedule(660, array($this, "spawnItems"), [1,32,"checkPigmen",false]); + $server->schedule(700, array($this, "spawnItems"), [1,32,"checkPigmen",false]); + $server->schedule(860, array($this, "glow"), 5); + $server->schedule(880, array($this, "glow"), 6); + $server->schedule(900, array($this, "glow"), 7); + $server->schedule(920, array($this, "destroy")); + return true; + } + //} + + } + 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); + $this->decay($this->x-8, $this->y-3, $this->z-8, 1, 16, 1, 2, 34, 1, 0, 17, 16); + $this->decay($this->x-8, $this->y-3, $this->z-8, 3, 14, 10, 8, 34, 1, 3, 14, 1); + $this->decay($this->x-8, $this->y-3, $this->z-8, 4, 13, 1, 8, 34, 1, 3, 14, 10); + $this->decay($this->x-8, $this->y-3, $this->z-8, 5, 12, 6, 14, 34, 1, 5, 12, 1); + $this->decay($this->x-8, $this->y-3, $this->z-8, 6, 11, 1, 14, 34, 1, 5, 12, 16); + } + + private function decay($x,$y,$z,$aOne,$aTwo,$aThree,$bOne,$bTwo,$bThree,$cOne,$cTwo,$cThree) { + 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){ + $this->level->setBlock(new Vector3($x+$a, $y+$b, $z+$c), new AirBlock()); + } + } + } + } + } + + private function pigmenCheck($x,$y,$z) { + $pigCount = 0; + $server = ServerAPI::request(); + $allEntities = $server->api->entity->entities; + foreach($allEntities as $entity) { + if($entity->type === MOB_PIGMAN && $entity->x < $x + 8 && $entity->x > $x - 8 && $entity->z < $z + 8 && $entity->z > $z - 8 && $entity->y > $y - 2 && $entity->y < $y + 3){ + $pigCount += 1; + } + } + return $pigCount < 3 ? $pigCount < 2 ? 2 : 1 : 0; + } + public function spawnItems($data) { + $x = $this->x; + $y = $this->y; + $z = $this->z; + $minAmount = $data[0]; + $maxAmount = $data[1]; + $pigmen = $data[2] === "checkPigmen" ? $this->pigmenCheck($x, $y, $z) : $data[2]; + $forceAmount = $data[3]; + $server = ServerAPI::request(); + if(!$forceAmount){ + $spawnNumber = $minAmount + floor($this->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)); + } + 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)); + $data = array( + "x" => $x+($shiftX*$randomRange)+0.5, + "y" => $y-1, + "z" => $z+($shiftZ*$randomRange)+0.5, + ); + $e = $server->api->entity->add($this->level, ENTITY_MOB, MOB_PIGMAN, $data); + $server->api->entity->spawnToAll($e); + } + } + public function glow($part){ + $x = $this->x; + $y = $this->y; + $z = $this->z; + switch($part){ + case 1: + $this->level->setBlock(new Vector3($x, $y-1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y-1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y-1, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y-1, $z-1),new GlowingObsidianBlock); + break; + case 2: + $this->level->setBlock(new Vector3($x+1, $y, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y, $z-1),new GlowingObsidianBlock); + break; + case 3: + $this->level->setBlock(new Vector3($x, $y+1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y+1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y+1, $z),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y+1, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x, $y+1, $z-1),new GlowingObsidianBlock); + break; + case 4: + $this->level->setBlock(new Vector3($x+1, $y-1, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y-1, $z-1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z+1),new GlowingObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z-1),new GlowingObsidianBlock); + break; + case 5: + $this->level->setBlock(new Vector3($x, $y+1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y+1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y+1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y+1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y+1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y+1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y+1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y+1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y+1, $z-1),new ObsidianBlock); + break; + case 6: + $this->level->setBlock(new Vector3($x, $y, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y, $z-1),new ObsidianBlock); + break; + case 7: + $this->level->setBlock(new Vector3($x, $y-1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y-1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y-1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x, $y-1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y-1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x+1, $y-1, $z-1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z+1),new ObsidianBlock); + $this->level->setBlock(new Vector3($x-1, $y-1, $z-1),new ObsidianBlock); + break; + } + } + private function isCorrect($x, $y, $z){ + $offsetX = -1; + $offsetZ = -1; + foreach($this->core as $yOffset => $layer){ + foreach($layer as $line){ + foreach(str_split($line) as $char){ + switch($char){ + case "G": + if($this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getID() === GOLD_BLOCK){ + continue; + } + return false; + case "C": + if($this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getID() === COBBLESTONE){ + continue; + } + return false; + case "R": + if($this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getID() === NETHER_REACTOR){ + continue; + } + return false; + case " ": + if($this->level->getBlock(new Vector3($x + $offsetX, $y + $yOffset, $z + $offsetZ))->getID() === 0){ + continue; + } + return false; + default: + continue; + } + ++$offsetX; + } + ++$offsetZ; + $offsetX = -1; + } + $offsetZ = -1; + } + return true; + } + private $possibleLoot = [ + GLOWSTONE_DUST, QUARTZ, CACTUS, SUGARCANE, BROWN_MUSHROOM, RED_MUSHROOM, BOW, BOWL, PUMPKIN_SEEDS, MELON_SEEDS + ]; + private $core = [ + -1 => ["GCG", "CCC", "GCG"], + 0 => ["C C", " R ", "C C",], + 1 =>[" C ", "CCC", " C "] + ]; } \ No newline at end of file