commit f170caebf7451463a77d20cd687bd7b031dc3ac7 Author: Ad5001 Date: Sun Apr 23 16:42:51 2017 +0200 Uploading plugin diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..11cff2b --- /dev/null +++ b/LICENSE @@ -0,0 +1,126 @@ +BoxOfDevs General Software License 1.1.3 +========================================= +This license is designed to be used with any software which would like to have no selling for profits, nor any public redistribution without giving the original author credits. +-------------------------------------------------------------------------------------------------------------------------------------- +The License: refers to the BoxOfDevs International Software License 1.1.2 +The Software: refers to any works licensed under The License. +The Modification: refers to any modified version of The Software. +The Redistribution: refers to any redistributions of The Software/The Modification. +The User: refers to any user of The Software licensed under The License. +The Author: refers to any developer, organisation, legal owner, or creator of The Software that has been licensed under the The License. +-------------------------------------------------------------------------------------------------------------------------------------- +Section 1 - Allowances: + + 1. Both The User & The Author Can: + a. Modify private copies of The Software and use in any way they wish. + b. Change which license The Software/The Modification is licensed under. + + 2. The User Can: + a. Request new features, support, or more rights from The Author. + b. Redistribute The Software/The Modification, ensuring The User gives all appropriate credit to The Author and alerting The Author to The Redistribution. + + 3. The Author Can: + a. Change or update The Software in any way they wish, ensuring they follow the other terms of The License. + b. Grant extra rights to The User who has requested them. + c. Reserve the right to request The User to take down their instance of The Software/The Modification/The Redistribution. + +Section 2 - Restrictions: + 1. Both The User & The Author Cannot: + a. Introduce any malicious code into The Software/The Modification. + b. Sell any part of The Software/The Modification for profit. + + 2. The User Cannot: + a. Hold The Author responsible for any unknown errors. + b. Claim The Software/The Modification/The Redistribution as entirely The User's product. + c. Use the software without crediting the Author. + + 3. The Author Cannot: + a. Restrict The User in any way not specified by The License. + b. Distribute any form of The Software without proper documentation. + + Term. The term of this License is specified in Section 6(a). + Media and formats; technical modifications allowed. The Author authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Author waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this License, simply making modifications authorized by this Section 2(a)(4) never produces Modification. + + Downstream recipients. + Offer from the Author – Software. Every recipient of the Software automatically receives an offer from the Author to exercise the Licensed Rights under the terms and conditions of this License. + Additional offer from the Author – the Modification. Every recipient of the Modification from You automatically receives an offer from the Author to exercise the Licensed Rights in the Modification under the conditions of the Adapter’s License You apply. + No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Software if doing so restricts exercise of the Licensed Rights by any recipient of the Software. + No endorsement. Nothing in this License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Software is, connected with, or sponsored, endorsed, or granted official status by, the Author or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). + + Other rights. + Moral rights, such as the right of integrity, are not licensed under this License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Author waives and/or agrees not to assert any such rights held by the Author to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. + Patent and trademark rights are not licensed under this License. + To the extent possible, the Author waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Author expressly reserves any right to collect such royalties. + +Section 3 – License Conditions. + Your exercise of the Licensed Rights is expressly made subject to the following conditions. + + a) Attribution. + If You Share the Software (including in modified form), You must: + retain the following if it is supplied by the Author with the Software: + identification of the creator(s) of the Software and any others designated to receive attribution, in any reasonable manner requested by the Author (including by pseudonym if designated); + a copyright notice; + a notice that refers to this License; + a notice that refers to the disclaimer of warranties; + a URI or hyperlink to the Software to the extent reasonably practicable; + indicate if You modified the Software and retain an indication of any previous modifications; and + indicate the Software is licensed under this License, and include the text of, or the URI or hyperlink to, this License. + You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Software. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. + If requested by the Author, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. + + b) ShareAlike. + In addition to the conditions in Section 3(a), if You Share the Modification You produce, the following conditions also apply. + The Adapter’s License You apply must be a BoxOfDevs General License with the same License Elements, this version or later, or a BY-SA Compatible License. + You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share the Modification. + You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Modification that restrict exercise of the rights granted under the Adapter's License You apply. + + c) Forever Open Source. + In addition to the conditions in Section 3(a) and Section 3(b), if You Share the Modification You produce, the following conditions also apply. + The Adapted work must have an open source existing repertory, accessible by anyone anytime linked in the Redistribution Description/Documentation. + You may not restrict anyone from accessing the source code, use it, and redistribute it under anything not explicily specified by the License. + + d) Free. + In addition to the conditions in Section 3(a), Section 3(b) and Section 3(c), if You Share by any way Modification and/or the Software You produce, the following conditions also apply. + The Work must be redistributed entirely free, under this license. + You may not impose fees to anyone that gets the Modification/The Software. + + +Section 4 – Sui Generis Database Rights. + Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Software: + + for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; + if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Modification, including for purposes of Section 3(b); and + You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. + + For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this License where the Licensed Rights include other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + + Unless otherwise separately undertaken by the Author, to the extent possible, the Author offers the Software as-is and as-available, and makes no representations or warranties of any kind concerning the Software, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. + To the extent possible, in no event will the Author be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this License or use of the Software, even if the Author has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. + + The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + This License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this License, then Your rights under this License terminate automatically. + + Where Your right to use the Software has terminated under Section 6(a), it reinstates: + automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or + upon express reinstatement by the Author. + For the avoidance of doubt, this Section 6(b) does not affect any right the Author may have to seek remedies for Your violations of this License. + For the avoidance of doubt, the Author may also offer the Software under separate terms or conditions or stop distributing the Software at any time; however, doing so will not terminate this License. + Sections 1, 5, 6, 7, and 8 survive termination of this License. + +Section 7 – Other Terms and Conditions. + + The Author shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. + Any arrangements, understandings, or agreements regarding the Software not stated herein are separate from and independent of the terms and conditions of this License. + In the event that The License is updated/changed on the official github repository/on the official website, you automatically agree. + The Author is not required to notify The User that The License has been updated/changed. + +Section 8 – Interpretation. + For the avoidance of doubt, this License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Software that could lawfully be made without permission under this License. + + To the extent possible, if any provision of this License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this License without affecting the enforceability of the remaining terms and conditions. + No term or condition of this License will be waived and no failure to comply consented to unless expressly agreed to by the Author. +Nothing in this License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Author or You, including from the legal processes of any jurisdiction or authority. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..1beea2d --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ + +

PocketMine's Tomorrow's Generator.

+Welcome user to the home of a new PocketMine World Generator which features 9 new/modified biomes: +------ +# Commun: +### Commun structures to all biomes features: +1.

Mineshafts:

+ +2.

Ravines:

+ +3.

Lakes:

+ +4.

Caves:

+ +5.

Floating islands:

+ + + +----- + +# [NEW BIOME] Sakura forests: +### This biome features new trees: Sakura Trees, japanese pink and white trees and it's own bush. + + +----- + +# [NEW BIOMES] Mesa Mountains & Plains +### These biomes are inspired (but not completly taken) from Minecraft PC. + + + +----- + +# Better Desert: +### The desert has been reworked and now includes the Minecraft PC's temples and wells ! +### Additionaly, deadbush, sugar cane and cactus are here too ! + + +----- + +# Better Ice Plains +### Ice plains got redisigned ! There is now snow instead of grass at it's bottom ! On the plus side, Igloos were imported from Minecraft PC ! + + + +----- + +# Oak and Birch Forests: +### These two biomes now are a bit better by the additions of bushes. + + +All content here is copyrighted (C) Ad5001 2017. Infos about this copyright can be found in the license file. \ No newline at end of file diff --git a/imgs/Island.jpg b/imgs/Island.jpg new file mode 100644 index 0000000..57dfd96 Binary files /dev/null and b/imgs/Island.jpg differ diff --git a/imgs/MesaRavine.jpg b/imgs/MesaRavine.jpg new file mode 100644 index 0000000..f612d11 Binary files /dev/null and b/imgs/MesaRavine.jpg differ diff --git a/imgs/Mineshaft.jpg b/imgs/Mineshaft.jpg new file mode 100644 index 0000000..c2053da Binary files /dev/null and b/imgs/Mineshaft.jpg differ diff --git a/imgs/banner.png b/imgs/banner.png new file mode 100644 index 0000000..1b86a3f Binary files /dev/null and b/imgs/banner.png differ diff --git a/imgs/bushes.png b/imgs/bushes.png new file mode 100644 index 0000000..05f5ded Binary files /dev/null and b/imgs/bushes.png differ diff --git a/imgs/cave.jpg b/imgs/cave.jpg new file mode 100644 index 0000000..5adf896 Binary files /dev/null and b/imgs/cave.jpg differ diff --git a/imgs/igloo.jpg b/imgs/igloo.jpg new file mode 100644 index 0000000..1e22630 Binary files /dev/null and b/imgs/igloo.jpg differ diff --git a/imgs/lake.png b/imgs/lake.png new file mode 100644 index 0000000..3ec08e8 Binary files /dev/null and b/imgs/lake.png differ diff --git a/imgs/mesa.png b/imgs/mesa.png new file mode 100644 index 0000000..4488a37 Binary files /dev/null and b/imgs/mesa.png differ diff --git a/imgs/sakura.jpg b/imgs/sakura.jpg new file mode 100644 index 0000000..543e7bb Binary files /dev/null and b/imgs/sakura.jpg differ diff --git a/imgs/temple.png b/imgs/temple.png new file mode 100644 index 0000000..55af128 Binary files /dev/null and b/imgs/temple.png differ diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..a91e916 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,17 @@ +--- +# Base generated with ImagicalPlugCreator by Ad5001 (C) 2017 for Ad5001 +# link: https://ad5001.eu +name: BetterGen +author: Ad5001 +main: Ad5001\BetterGen\Main +version: 1.0 +api: [3.0.1, 3.0.0-ALPHA3] +commands: + createworld: + description: Generates a new world. + usage: "/createworld [generator = betternormal] [seed = rand()] [options (json)]" + permission: bettergen.cmd.createworld +permissions: + bettergen.cmd.createworld: + default: op +... \ No newline at end of file diff --git a/resources/loots/mineshaft.json b/resources/loots/mineshaft.json new file mode 100644 index 0000000..4d65d11 --- /dev/null +++ b/resources/loots/mineshaft.json @@ -0,0 +1,183 @@ +{ + "max": 27, + "rail": { + "percentage": 79, + "minCount": 4, + "maxCount": 8, + "minStacks": 3, + "maxStacks": 3, + "id": 66, + "data": 0 + }, + "torch": { + "percentage": 66, + "minCount": 1, + "maxCount": 16, + "minStacks": 3, + "maxStacks": 3, + "id": 50, + "data": 0 + }, + "bread": { + "percentage": 45, + "minCount": 1, + "maxCount": 3, + "minStacks": 2, + "maxStacks": 4, + "id": 297, + "data": 0 + }, + "name tag": { + "percentage": 42, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 297, + "data": 0 + }, + "coal": { + "percentage": 32, + "minCount": 3, + "maxCount": 8, + "minStacks": 2, + "maxStacks": 4, + "id": 263, + "data": 0 + }, + "beethroot seeds": { + "percentage": 32, + "minCount": 2, + "maxCount": 4, + "minStacks": 2, + "maxStacks": 4, + "id": 458, + "data": 0 + }, + "melon seeds": { + "percentage": 32, + "minCount": 2, + "maxCount": 4, + "minStacks": 2, + "maxStacks": 4, + "id": 362, + "data": 0 + }, + "pumpkin seeds": { + "percentage": 32, + "minCount": 2, + "maxCount": 4, + "minStacks": 2, + "maxStacks": 4, + "id": 361, + "data": 0 + }, + "iron ingot": { + "percentage": 32, + "minCount": 1, + "maxCount": 5, + "minStacks": 2, + "maxStacks": 4, + "id": 365, + "data": 0 + }, + "golden apple": { + "percentage": 28, + "minCount": 1, + "maxCount": 1, + "minStacks": 1, + "maxStacks": 1, + "id": 322, + "data": 0 + }, + "activator rail": { + "percentage": 27, + "minCount": 1, + "maxCount": 4, + "minStacks": 3, + "maxStacks": 3, + "id": 126, + "data": 0 + }, + "detector rail": { + "percentage": 27, + "minCount": 1, + "maxCount": 4, + "minStacks": 3, + "maxStacks": 3, + "id": 28, + "data": 0 + }, + "powered rail": { + "percentage": 27, + "minCount": 1, + "maxCount": 4, + "minStacks": 3, + "maxStacks": 3, + "id": 27, + "data": 0 + }, + "lapis lazuli": { + "percentage": 17, + "minCount": 4, + "maxCount": 9, + "minStacks": 2, + "maxStacks": 4, + "id": 351, + "data": 4 + }, + "redstone": { + "percentage": 17, + "minCount": 4, + "maxCount": 9, + "minStacks": 2, + "maxStacks": 4, + "id": 331, + "data": 0 + }, + "gold ingot": { + "percentage": 17, + "minCount": 1, + "maxCount": 3, + "minStacks": 2, + "maxStacks": 4, + "id": 366, + "data": 0 + }, + "enchanted book": { + "percentage": 14, + "minCount": 1, + "maxCount": 1, + "minStacks": 1, + "maxStacks": 1, + "id": 403, + "data": 0 + }, + "diamond": { + "percentage": 11, + "minCount": 1, + "maxCount": 2, + "minStacks": 2, + "maxStacks": 4, + "id": 264, + "data": 0 + }, + "iron pickaxe": { + "percentage": 7, + "minCount": 1, + "maxCount": 1, + "minStacks": 1, + "maxStacks": 1, + "id": 257, + "data": 0 + }, + "enchanted golden apple": { + "percentage": 1, + "minCount": 1, + "maxCount": 1, + "minStacks": 1, + "maxStacks": 1, + "id": 466, + "data": 0 + } +} \ No newline at end of file diff --git a/resources/loots/temple.json b/resources/loots/temple.json new file mode 100644 index 0000000..30c5e07 --- /dev/null +++ b/resources/loots/temple.json @@ -0,0 +1,154 @@ +{ + "max": 27, + "bone": { + "percentage": 71, + "minCount": 4, + "maxCount": 6, + "minStacks": 2, + "maxStacks": 4, + "id": 352, + "data": 0 + }, + "rotten_flesh": { + "percentage": 71, + "minCount": 3, + "maxCount": 7, + "minStacks": 2, + "maxStacks": 4, + "id": 367, + "data": 0 + }, + "gunpowder": { + "percentage": 59, + "minCount": 1, + "maxCount": 8, + "minStacks": 4, + "maxStacks": 4, + "id": 289, + "data": 0 + }, + "sand": { + "percentage": 59, + "minCount": 1, + "maxCount": 8, + "minStacks": 4, + "maxStacks": 4, + "id": 12, + "data": 0 + }, + "string": { + "percentage": 59, + "minCount": 1, + "maxCount": 8, + "minStacks": 4, + "maxStacks": 4, + "id": 287, + "data": 0 + }, + "spider_eye": { + "percentage": 29, + "minCount": 1, + "maxCount": 3, + "minStacks": 2, + "maxStacks": 4, + "id": 375, + "data": 0 + }, + "enchanted_book": { + "percentage": 24, + "minCount": 1, + "maxCount": 1, + "id": 403, + "data": 0 + }, + "saddle": { + "percentage": 24, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 329, + "data": 0 + }, + "golden_apple": { + "percentage": 24, + "minCount": 1, + "maxCount": 1, + "minStacks": 1, + "maxStacks": 1, + "id": 322, + "data": 0 + }, + "gold_ingot": { + "percentage": 18, + "minCount": 2, + "maxCount": 7, + "minStacks": 2, + "maxStacks": 4, + "id": 266, + "data": 0 + }, + "iron_ingot": { + "percentage": 18, + "minCount": 1, + "maxCount": 5, + "minStacks": 2, + "maxStacks": 4, + "id": 265, + "data": 0 + }, + "emerald": { + "percentage": 18, + "minCount": 1, + "maxCount": 3, + "minStacks": 2, + "maxStacks": 4, + "id": 388, + "data": 0 + }, + "iron_horse_armor": { + "percentage": 18, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 417, + "data": 0 + }, + "gold_horse_armor": { + "percentage": 12, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 418, + "data": 0 + }, + "diamond": { + "percentage": 6, + "minCount": 1, + "maxCount": 3, + "minStacks": 2, + "maxStacks": 4, + "id": 264, + "data": 0 + }, + "diamond_horse_armor": { + "percentage": 6, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 419, + "data": 0 + }, + "enchanted_golden_apple": { + "percentage": 3, + "minCount": 1, + "maxCount": 1, + "minStacks": 2, + "maxStacks": 4, + "id": 466, + "data": 0 + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/Main.php b/src/Ad5001/BetterGen/Main.php new file mode 100644 index 0000000..0f35978 --- /dev/null +++ b/src/Ad5001/BetterGen/Main.php @@ -0,0 +1,248 @@ +getServer()->getPluginManager()->registerEvents($this, $this); + Generator::addGenerator(BetterNormal::class, "betternormal"); + @mkdir($this->getDataFolder()); + if(! file_exists(LootTable::getPluginFolder(). "processingLoots.json")) + file_put_contents(LootTable::getPluginFolder(). "processingLoots.json", "{}"); + } + + /* + * Called when the plugin disables + */ + public function onDisable() { + } + + /* + * Called when one of the defined commands of the plugin has been called + * @param $sender \pocketmine\command\CommandSender + * @param $cmd \pocketmine\command\Command + * @param $label mixed + * @param $args array + * return bool + */ + public function onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $cmd, $label, array $args): bool { + switch($cmd->getName()) { + case "createworld" : // /createworld [generator = betternormal] [seed = rand()] [options(json)] + switch(count($args)) { + case 0 : + return false; + break; + case 1 : // /createworld + $name = $args [0]; + $generator = Generator::getGenerator("betternormal"); + $generatorName = "betternormal"; + $seed = $this->generateRandomSeed(); + $options = [ ]; + break; + case 2 : // /createworld [generator = betternormal] + $name = $args [0]; + $generator = Generator::getGenerator($args [1]); + if(Generator::getGeneratorName($generator) !== strtolower($args [1])) { + $sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?"); + return true; + } + $generatorName = strtolower($args [1]); + $seed = $this->generateRandomSeed(); + $options = [ ]; + break; + case 3 : // /createworld [generator = betternormal] [seed = rand()] + $name = $args [0]; + $generator = Generator::getGenerator($args [1]); + if(Generator::getGeneratorName($generator) !== strtolower($args [1])) { + $sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?"); + return true; + } + $generatorName = strtolower($args [1]); + if(preg_match("[^\d]", $args [2]) !== false) { + $parts = str_split($args [2]); + foreach($parts as $key => $str) { + $parts [$key] = ord($str); + } + $seed = implode("", $parts); + } else { + $seed = $args [2]; + } + $options = [ ]; + break; + default : // /createworld [generator = betternormal] [seed = rand()] [options(json)] + $name = $args [0]; + $generator = Generator::getGenerator($args [1]); + if(Generator::getGeneratorName($generator) !== strtolower($args [1])) { + $sender->sendMessage(self::PREFIX . "§4Could not find generator {$args[1]}. Are you sure it is registered?"); + return true; + } + $generatorName = strtolower($args [1]); + if(preg_match("[^\d]", $args [2]) !== false) { + $parts = str_split($args [2]); + foreach($parts as $key => $str) { + $parts [$key] = ord($str); + } + $seed = implode("", $parts); + } else { + $seed = $args [2]; + } + unset($args [0], $args [1], $args [2]); + $options = json_decode($args [3], true); + if(! is_array($json)) { + $sender->sendMessage(Main::PREFIX . "§4Invalid JSON for options."); + return true; + } + break; + } + $this->getServer()->broadcastMessage(Main::PREFIX . "§aGenerating level $name with generator $generatorName and seed $seed.."); + $this->getServer()->generateLevel($name, $seed, $generator, $options); + $this->getServer()->loadLevel($name); + return true; + break; + } + } + + /* + * Registers a forest type. + * @param $name string + * @param $treeClass string + * @params $infos Array(temperature, rainfall) + * @return bool + */ + public function registerForest(string $name, string $treeClass, array $infos): bool { + if(! @class_exists($treeClass)) + return false; + if(! @is_subclass_of($treeClass, "pocketmine\\level\\generator\\normal\\object\\Tree")) + return false; + if(count($infos) < 2 or ! is_float($infos [0]) or ! is_float($infos [1])) + return false; + return BetterForest::registerForest($name, $treeClass, $infos); + } + + /* + * Registers a biome for the normal generator. Normal means(Biome::register) doesn't allow biome to be generated + * @param $id int + * @param $biome Biome + * @return void + */ + public static function registerBiome(int $id, Biome $biome) { + $reflection = new \ReflectionClass('pocketmine\\level\\generator\\biome\\Biome'); + $register = $reflection->getMethod('register'); + $register->setAccessible(true); + $register->invoke(null, $id, $biome); + BetterNormal::registerBiome($biome); + } + + /* + * Generates a(semi) random seed. + * @return int + */ + public function generateRandomSeed(): int { + return(int) round(time() * rand(0, time()) / memory_get_usage()); + } + + // Listener + + /* + * Checks after a chunk populates so we an add tiles and loot tables + * @param $event pocketmine\event\level\ChunkPopulateEvent + * @return int + */ + public function onChunkPopulate(ChunkPopulateEvent $event) { + $cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); + foreach($cfg->getAll() as $key => $value) { + list($x, $y, $z) = explode(";", $key); + if($value["saveAs"] == "chest" && $event->getLevel()->getBlockIdAt($x, $y, $z) == Block::AIR ){ + $event->getLevel()->setBlockIdAt($x, $y, $z, Block::CHEST); + } else { + $cfg->remove($key); + $cfg->save(); + } + } + } + + + /* + * Checks when a player interacts with a loot chest to create it. + */ + public function onInteract(PlayerInteractEvent $event) { + $cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); + if($event->getBlock()->getId() !== Block::CHEST) return; + if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return; + echo "Doing {$event->getBlock()}"; + $chest = new \pocketmine\block\Chest(0); + $nbt = new CompoundTag("", [ + new ListTag("Items", []), + new StringTag("id", Tile::CHEST), + new IntTag("x", $event->getBlock()->x), + new IntTag("y", $event->getBlock()->y), + new IntTag("z", $event->getBlock()->z) + ]); + $chest->setLevel($event->getBlock()->getLevel()); + $cItem = Item::get(Item::CHEST, 0); + $cItem->setCustomName("§k(Fake)§r Minecart chest"); + $chest->place($cItem, $event->getBlock()->getLevel()->getBlock($event->getBlock()), $chest, 0, 0, 0, 0); + $inv = $event->getBlock()->getLevel()->getTile($event->getBlock()); + LootTable::fillChest($inv->getInventory(), $event->getBlock()); + } + + + /* + * Checks when a player breaks a loot chest which is not created to create it + */ + public function onBlockBreak(BlockBreakEvent $event) { + $cfg = new Config(LootTable::getPluginFolder() . "processingLoots.json", Config::JSON); + if($event->getBlock()->getId() !== Block::CHEST) return; + if(!$cfg->exists($event->getBlock()->getX() . ";" . $event->getBlock()->getY() . ";" . $event->getBlock()->getZ())) return; + echo "Doing {$event->getBlock()}"; + $chest = new \pocketmine\block\Chest(0); + $nbt = new CompoundTag("", [ + new ListTag("Items", []), + new StringTag("id", Tile::CHEST), + new IntTag("x", $event->getBlock()->x), + new IntTag("y", $event->getBlock()->y), + new IntTag("z", $event->getBlock()->z) + ]); + $chest->setLevel($event->getBlock()->getLevel()); + $cItem = Item::get(Item::CHEST, 0); + $cItem->setCustomName("§k(Fake)§r Minecart chest"); + $chest->place($cItem, $event->getBlock()->getLevel()->getBlock($event->getBlock()), $chest, 0, 0, 0, 0); + $inv = $event->getBlock()->getLevel()->getTile($event->getBlock()); + LootTable::fillChest($inv->getInventory(), $event->getBlock()); + $event->setCancelled(); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterDesert.php b/src/Ad5001/BetterGen/biome/BetterDesert.php new file mode 100644 index 0000000..9561952 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterDesert.php @@ -0,0 +1,79 @@ +setBaseAmount ( 1 ); + $deadBush->setRandomAmount ( 2 ); + + $cactus = new CactusPopulator (); + $cactus->setBaseAmount ( 1 ); + $cactus->setRandomAmount ( 2 ); + + $sugarCane = new SugarCanePopulator (); + $sugarCane->setRandomAmount ( 20 ); + $sugarCane->setBaseAmount ( 3 ); + + $temple = new TemplePopulator (); + + $well = new WellPopulator (); + + $this->addPopulator ( $cactus ); + $this->addPopulator ( $deadBush ); + $this->addPopulator ( $sugarCane ); + $this->addPopulator ( $temple ); + $this->addPopulator ( $well ); + + $this->setElevation ( 63, 70 ); + // $this->setElevation(66, 70); + + $this->temperature = 0.5; + $this->rainfall = 0; + $this->setGroundCover ( [ + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ) + ] ); + } + public function getName(): string { + return "Better Desert"; + } + + /* + * Returns biome id + */ + public function getId() { + return Biome::DESERT; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterForest.php b/src/Ad5001/BetterGen/biome/BetterForest.php new file mode 100644 index 0000000..51cf979 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterForest.php @@ -0,0 +1,76 @@ +clearPopulators (); + + $this->type = $type; + + $bush = new BushPopulator ( $type ); + $bush->setBaseAmount ( 10 ); + $this->addPopulator ( $bush ); + $trees = new TreePopulator ( $type ); + $trees->setBaseAmount ( (null !== @constant ( TreePopulator::$types [$type] . "::maxPerChunk" )) ? constant ( TreePopulator::$types [$type] . "::maxPerChunk" ) : 5 ); + $this->addPopulator ( $trees ); + + $tallGrass = new TallGrass (); + $tallGrass->setBaseAmount ( 3 ); + + $this->addPopulator ( $tallGrass ); + + $this->setElevation ( 63, 81 ); + + $this->temperature = $infos [0]; + $this->rainfall = $infos [1]; + } + public function getName() { + return self::$types [$this->type]; + } + + /* + * Returns the ID relativly. + */ + public function getId() { + return self::$ids [$this->type]; + } + + /* + * Registers a forest type. Don't use this method directly use the one from the main class. + * @param $name string + * @param $treeClass string + * @param + * @return bool + */ + public static function registerForest(string $name, string $treeClass, array $infos): bool { + self::$types [] = str_ireplace ( "tree", "", explode ( "\\", $treeClass ) [count ( explode ( "\\", $treeClass ) )] ) . " Forest"; + TreePopulator::$types [] = $treeClass; + self::$ids [] = Main::SAKURA_FOREST + (count ( self::$types ) - 2); + Main::register ( Main::SAKURA_FOREST + (count ( self::$types ) - 2), new BetterForest ( count ( self::$types ) - 1, $infos ) ); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterIcePlains.php b/src/Ad5001/BetterGen/biome/BetterIcePlains.php new file mode 100644 index 0000000..84407d1 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterIcePlains.php @@ -0,0 +1,50 @@ +setGroundCover ( [ + Block::get ( Block::SNOW, 0 ), + Block::get ( Block::GRASS, 0 ), + Block::get ( Block::DIRT, 0 ), + Block::get ( Block::DIRT, 0 ), + Block::get ( Block::DIRT, 0 ) + ] ); + $this->addPopulator ( new IglooPopulator () ); + + $tallGrass = new TallGrass (); + $tallGrass->setBaseAmount ( 3 ); + + $this->addPopulator ( $tallGrass ); + + $this->setElevation ( 63, 74 ); + + $this->temperature = 0.05; + $this->rainfall = 0.8; + } + public function getName() { + return "Better Ice Plains"; + } + + /* + * Returns biome's id. + */ + public function getId() { + return Biome::ICE_PLAINS; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterMesa.php b/src/Ad5001/BetterGen/biome/BetterMesa.php new file mode 100644 index 0000000..1e09e23 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterMesa.php @@ -0,0 +1,113 @@ +setBaseAmount ( 1 ); + $deadBush->setRandomAmount ( 2 ); + + $cactus = new CactusPopulator (); + $cactus->setBaseAmount ( 1 ); + $cactus->setRandomAmount ( 2 ); + + $sugarCane = new SugarCanePopulator (); + $sugarCane->setRandomAmount ( 20 ); + $sugarCane->setBaseAmount ( 3 ); + + $sugarCane = new TreePopulator (); + $sugarCane->setRandomAmount ( 2 ); + $sugarCane->setBaseAmount ( 0 ); + + $ores = new Ore (); + $ores->setOreTypes ( [ + new OreType ( new GoldOre (), 2, 8, 0, 32 ) + ] ); + + $this->addPopulator ( $cactus ); + $this->addPopulator ( $deadBush ); + $this->addPopulator ( $sugarCane ); + $this->addPopulator ( $ores ); + + $this->setElevation ( 80, 83 ); + // $this->setElevation(66, 70); + + $this->temperature = 0.8; + $this->rainfall = 0; + $this->setGroundCover ( [ + Block::get ( Block::DIRT, 0 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 4 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ) + ] ); + } + public function getName(): string { + return "Better Mesa"; + } + + /* + * Returns biome id + */ + public function getId() { + return 39; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterMesaPlains.php b/src/Ad5001/BetterGen/biome/BetterMesaPlains.php new file mode 100644 index 0000000..8ca80de --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterMesaPlains.php @@ -0,0 +1,108 @@ +setBaseAmount ( 1 ); + $deadBush->setRandomAmount ( 2 ); + + $cactus = new CactusPopulator (); + $cactus->setBaseAmount ( 1 ); + $cactus->setRandomAmount ( 2 ); + + $sugarCane = new SugarCanePopulator (); + $sugarCane->setRandomAmount ( 20 ); + $sugarCane->setBaseAmount ( 3 ); + + $ores = new Ore (); + $ores->setOreTypes ( [ + new OreType ( new GoldOre (), 20, 8, 0, 32 ) + ] ); + + $this->addPopulator ( $cactus ); + $this->addPopulator ( $deadBush ); + $this->addPopulator ( $sugarCane ); + $this->addPopulator ( $ores ); + + $this->setElevation ( 62, 67 ); + // $this->setElevation(66, 70); + + $this->temperature = 0.6; + $this->rainfall = 0; + $this->setGroundCover ( [ + Block::get ( Block::SAND, 1 ), + Block::get ( Block::SAND, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 12 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 14 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 4 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 7 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::HARDENED_CLAY, 0 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::STAINED_HARDENED_CLAY, 1 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ), + Block::get ( Block::RED_SANDSTONE, 0 ) + ] ); + } + public function getName(): string { + return "Better Mesa Plains"; + } + + /* + * Returns biome id + */ + public function getId() { + return 40; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/BetterRiver.php b/src/Ad5001/BetterGen/biome/BetterRiver.php new file mode 100644 index 0000000..18a9e30 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/BetterRiver.php @@ -0,0 +1,48 @@ +clearPopulators (); + + $this->setGroundCover ( [ + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SAND, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ), + Block::get ( Block::SANDSTONE, 0 ) + ] ); + + $this->setElevation ( 60, 60 ); + + $this->temperature = 0.5; + $this->rainfall = 0.7; + } + public function getName() { + return "Better River"; + } + + /* + * Returns the ID relativly. + */ + public function getId() { + return Biome::RIVER; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/biome/Mountainable.php b/src/Ad5001/BetterGen/biome/Mountainable.php new file mode 100644 index 0000000..f250ab6 --- /dev/null +++ b/src/Ad5001/BetterGen/biome/Mountainable.php @@ -0,0 +1,14 @@ +fallback = $fallback; + $this->lookup = $lookup; + $this->temperature = new Simplex ( $random, 2, 1 / 16, 1 / 512 ); + $this->rainfall = new Simplex ( $random, 2, 1 / 16, 1 / 512 ); + } + public function recalculate() { + } // Using our own system, No need for that + public function addBiome(Biome $biome) { + $this->biomes [$biome->getId ()] = $biome; + } + public function getTemperature($x, $z) { + return ($this->temperature->noise2D ( $x, $z, true ) + 1) / 2; + } + public function getRainfall($x, $z) { + return ($this->rainfall->noise2D ( $x, $z, true ) + 1) / 2; + } + + /** + * + * @param + * $x + * @param + * $z + * + * @return Biome + */ + public function pickBiome($x, $z) { + $temperature = ($this->getTemperature ( $x, $z )); + $rainfall = ($this->getRainfall ( $x, $z )); + + $biomeId = BetterNormal::getBiome ( $temperature, $rainfall ); + // $biomeId = new \Ad5001\BetterGen\biome\BetterDesert(); + $b = (($biomeId instanceof Biome) ? $biomeId : ($this->biomes [$biomeId] ?? $this->fallback)); + return $b; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/generator/BetterNormal.php b/src/Ad5001/BetterGen/generator/BetterNormal.php new file mode 100644 index 0000000..f9543fb --- /dev/null +++ b/src/Ad5001/BetterGen/generator/BetterNormal.php @@ -0,0 +1,421 @@ +level->getSeed (); + $hash *= $hash + 223; + $xNoise = $hash >> 20 & 3; + $zNoise = $hash >> 22 & 3; + if ($xNoise == 3) { + $xNoise = 1; + } + if ($zNoise == 3) { + $zNoise = 1; + } + + $b = $this->selector->pickBiome ( $x + $xNoise - 1, $z + $zNoise - 1 ); + if ($b instanceof Mountainable && $this->random->nextBoundedInt ( 1000 ) < 3) { + $b = clone $b; + $b->setElevation ( $b->getMinElevation () + (50 * $b->getMinElevation () / 100), $b->getMaxElevation () + (50 * $b->getMinElevation () / 100) ); + } + return $b; + } + public function init(ChunkManager $level, Random $random) { + $this->level = $level; + $this->random = $random; + + self::$levels [] = $level; + + $this->random->setSeed ( $this->level->getSeed () ); + $this->noiseBase = new Simplex ( $this->random, 4, 1 / 4, 1 / 32 ); + $this->random->setSeed ( $this->level->getSeed () ); + + $this->registerBiome ( Biome::getBiome ( Biome::OCEAN ) ); + $this->registerBiome ( Biome::getBiome ( Biome::PLAINS ) ); + $this->registerBiome ( new BetterDesert () ); + $this->registerBiome ( new BetterMesa () ); + $this->registerBiome ( new BetterMesaPlains () ); + $this->registerBiome ( Biome::getBiome ( Biome::TAIGA ) ); + $this->registerBiome ( Biome::getBiome ( Biome::SWAMP ) ); + $this->registerBiome ( new BetterRiver () ); + $this->registerBiome ( new BetterIcePlains () ); + $this->registerBiome ( new BetterForest ( 0, [ + 0.6, + 0.5 + ] ) ); + $this->registerBiome ( new BetterForest ( 1, [ + 0.7, + 0.8 + ] ) ); + $this->registerBiome ( new BetterForest ( 2, [ + 0.6, + 0.4 + ] ) ); + + $this->selector = new BetterBiomeSelector ( $random, [ + self::class, + "getBiome" + ], self::getBiome ( 0, 0 ) ); + + foreach ( self::$biomes as $rain ) { + foreach ( $rain as $biome ) { + $this->selector->addBiome ( $biome ); + } + } + + $this->selector->recalculate (); + + $cover = new GroundCover (); + $this->generationPopulators [] = $cover; + + $cave = new CavePopulator (); + $cave->setBaseAmount ( 0 ); + $cave->setRandomAmount ( 2 ); + $this->populators [] = $cave; + + $ravine = new RavinePopulator (); + $ravine->setBaseAmount ( 0 ); + $ravine->setRandomAmount ( 51 ); + $this->populators [] = $ravine; + + $mineshaft = new MineshaftPopulator (); + $mineshaft->setBaseAmount ( 0 ); + $mineshaft->setRandomAmount ( 102 ); + $this->populators [] = $mineshaft; + + $lake = new LakePopulator (); + $lake->setBaseAmount ( 0 ); + $lake->setRandomAmount ( 1 ); + $this->generationPopulators [] = $lake; + + $fisl = new FloatingIslandPopulator(); + $fisl->setBaseAmount ( 0 ); + $fisl->setRandomAmount ( 132 ); + $this->populators [] = $fisl; + + $ores = new Ore (); + $ores->setOreTypes ( [ + new OreType ( new CoalOre (), 20, 16, 0, 128 ), + new OreType ( new IronOre (), 20, 8, 0, 64 ), + new OreType ( new RedstoneOre (), 8, 7, 0, 16 ), + new OreType ( new LapisOre (), 1, 6, 0, 32 ), + new OreType ( new GoldOre (), 2, 8, 0, 32 ), + new OreType ( new DiamondOre (), 1, 7, 0, 16 ), + new OreType ( new Dirt (), 20, 32, 0, 128 ), + new OreType ( new Gravel (), 10, 16, 0, 128 ) + ] ); + $this->populators [] = $ores; + } + + /* + * Adds a biome to the selector. Do not use this method directly use Main::registerBiome which registers it properly + * @param $biome Biome + * @return bool + */ + public static function registerBiome(Biome $biome): bool { + foreach ( self::$levels as $lvl ) + if (isset ( $lvl->selector )) + $lvl->selector->addBiome ( $biome ); // If no selector created, it would cause errors. These will be added when selectoes + if (! isset ( self::$biomes [( string ) $biome->getRainfall ()] )) + self::$biomes [( string ) $biome->getRainfall ()] = [ ]; + self::$biomes [( string ) $biome->getRainfall ()] [( string ) $biome->getTemperature ()] = $biome; + ksort ( self::$biomes [( string ) $biome->getRainfall ()] ); + ksort ( self::$biomes ); + self::$biomeById[$biome->getId()] = $biome; + return true; + } + + /* + * Returns a biome by temperature + * @param $temperature float + * @param $rainfall float + */ + public static function getBiome($temperature, $rainfall) { + if (! isset ( self::$biomes [( string ) round ( $rainfall, 1 )] )) { + while ( ! isset ( self::$biomes [( string ) round ( $rainfall, 1 )] ) ) { + if (abs ( $rainfall - round ( $rainfall, 1 ) ) >= 0.05) + $rainfall += 0.1; + if (abs ( $rainfall - round ( $rainfall, 1 ) ) < 0.05) + $rainfall -= 0.1; + if (round ( $rainfall, 1 ) < 0) + $rainfall = 0; + if (round ( $rainfall, 1 ) >= 0.9) + $rainfall = 0.9; + } + } + $b = self::$biomes [( string ) round ( $rainfall, 1 )]; + foreach ( $b as $t => $biome ) { + if ($temperature <= ( float ) $t) { + $ret = $biome; + break; + } + } + if (is_string ( $ret )) { + $ret = new $ret (); + } else { + return $ret; + } + } + + /* + * Returns a biome by its id + * @param $id int + * @return Biome + */ + public function getBiomeById(int $id): Biome { + return self::$biomeById[$id] ?? self::$biomeById(Biome::OCEAN); + } + + /* + * Generates a chunk. + * Cloning method to make it work with new methods. + * @param $chunkX int + * @param $chunkZ int + */ + public function generateChunk($chunkX, $chunkZ) { + $this->reRegisterBiomes (); + + $this->random->setSeed ( 0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed () ); + + $noise = Generator::getFastNoise3D ( $this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16 ); + + $chunk = $this->level->getChunk ( $chunkX, $chunkZ ); + + $biomeCache = [ ]; + + for($x = 0; $x < 16; ++ $x) { + for($z = 0; $z < 16; ++ $z) { + $minSum = 0; + $maxSum = 0; + $weightSum = 0; + + $biome = $this->pickBiome ( $chunkX * 16 + $x, $chunkZ * 16 + $z ); + $chunk->setBiomeId ( $x, $z, $biome->getId () ); + + for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++ $sx) { + for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++ $sz) { + + $weight = self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE]; + + if ($sx === 0 and $sz === 0) { + $adjacent = $biome; + } else { + $index = Level::chunkHash ( $chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz ); + if (isset ( $biomeCache [$index] )) { + $adjacent = $biomeCache [$index]; + } else { + $biomeCache [$index] = $adjacent = $this->pickBiome ( $chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz ); + } + } + $minSum += ($adjacent->getMinElevation () - 1) * $weight; + $maxSum += $adjacent->getMaxElevation () * $weight; + + $weightSum += $weight; + } + } + + $minSum /= $weightSum; + $maxSum /= $weightSum; + + $smoothHeight = ($maxSum - $minSum) / 2; + + for($y = 0; $y < 128; ++ $y) { + if ($y < 3 || ($y < 5 && $this->random->nextBoolean ())) { + $chunk->setBlockId ( $x, $y, $z, Block::BEDROCK ); + continue; + } + $noiseValue = $noise [$x] [$z] [$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum); + + if ($noiseValue > 0) { + $chunk->setBlockId ( $x, $y, $z, Block::STONE ); + } elseif ($y <= $this->waterHeight) { + $chunk->setBlockId ( $x, $y, $z, Block::STILL_WATER ); + } + } + } + } + + foreach ( $this->generationPopulators as $populator ) { + $populator->populate ( $this->level, $chunkX, $chunkZ, $this->random ); + } + } + + /* + * Populates a chunk. + * @param $chunkX int + * @param $chunk2 int + */ + public function populateChunk($chunkX, $chunkZ) { + $this->random->setSeed ( 0xdeadbeef ^ ($chunkX << 8) ^ $chunkZ ^ $this->level->getSeed () ); + foreach ( $this->populators as $populator ) { + $populator->populate ( $this->level, $chunkX, $chunkZ, $this->random ); + } + + // Filling lava (lakes & rivers underground)... + for($x = $chunkX; $x < $chunkX + 16; $x ++) + for($z = $chunkZ; $z < $chunkZ + 16; $z ++) + for($y = 1; $y < 11; $y ++) { + if (! in_array ( $this->level->getBlockIdAt ( $x, $y, $z ), self::NOT_OVERWRITABLE )) + $this->level->setBlockIdAt ( $x, $y, $z, Block::LAVA ); + } + + $chunk = $this->level->getChunk ( $chunkX, $chunkZ ); + $biome = Biome::getBiome ( $chunk->getBiomeId ( 7, 7 ) ); + $biome->populateChunk ( $this->level, $chunkX, $chunkZ, $this->random ); + } + + /* + * Constructs the class + * @param $options array + */ + public function __construct(array $options = []) { + if (self::$GAUSSIAN_KERNEL === null) { + self::generateKernel (); + } + } + + /* + * Generates the genration kernel based on smooth size (here 2) + */ + private static function generateKernel() { + self::$GAUSSIAN_KERNEL = [ ]; + + $bellSize = 1 / self::$SMOOTH_SIZE; + $bellHeight = 2 * self::$SMOOTH_SIZE; + + for($sx = - self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++ $sx) { + self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] = [ ]; + + for($sz = - self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++ $sz) { + $bx = $bellSize * $sx; + $bz = $bellSize * $sz; + self::$GAUSSIAN_KERNEL [$sx + self::$SMOOTH_SIZE] [$sz + self::$SMOOTH_SIZE] = $bellHeight * exp ( - ($bx * $bx + $bz * $bz) / 2 ); + } + } + } + + //  Returns the name of the generator + public function getName() { + return "betternormal"; + } + + /* + * Gives the generators settings. + * @return array + */ + public function getSettings(): array { + return [ ]; + } + public function getSpawn() { + return new Vector3 ( 127.5, 128, 127.5 ); + } + + /* + * Returns a safe spawn location + */ + public function getSafeSpawn() { + return new Vector3 ( 127.5, $this->getHighestWorkableBlock ( 127, 127 ), 127.5 ); + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return - 1; + } + } + + return ++ $y; + } + + /* + * Re registers all biomes for async + */ + public function reRegisterBiomes() { + $reflection = new \ReflectionClass ( 'pocketmine\\level\\generator\\biome\\Biome' ); + $register = $reflection->getMethod ( 'register' ); + $register->setAccessible ( true ); + foreach ( self::$biomes as $rainfall => $arr ) { + foreach ( $arr as $tmp => $biome ) { + $register->invoke ( null, $biome->getId (), $biome ); + } + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/loot/LootTable.php b/src/Ad5001/BetterGen/loot/LootTable.php new file mode 100644 index 0000000..94446d7 --- /dev/null +++ b/src/Ad5001/BetterGen/loot/LootTable.php @@ -0,0 +1,124 @@ +y < 1) return; // Making sure sometimes that it doesn't write for nothing + $cfg = new Config(self::getPluginFolder() . "processingLoots.json", Config::JSON); + $lootsFromJson = json_decode(file_get_contents(self::getResourcesFolder() . "loots/" . self::LOOT_NAMES[$type] . ".json"), true); + $loots =[]; + foreach($lootsFromJson as $loot) { + if(is_array($loot) && $random->nextBoundedInt(101) < $loot["percentage"]) + $loots[] = $loot; + } + if($lootsFromJson["max"] < count($loots)) { + while($lootsFromJson["max"] < count($loots)) + unset($loots[array_rand($loots)]); + } + $loots["saveAs"] = self::LOOT_SAVE[$type]; + $cfg->set($place->x . ";" . $place->y . ";" . $place->z, $loots); + $cfg->save(); + } + + /* + * Syncronous inventory filling with loot table. + * @param $inv pocketmine\inventory\BaseInventory + * @param $pos pocketmine\math\Vector3 + * @return void + */ + public static function fillChest(BaseInventory $inv, Vector3 $pos) { + $cfg = new Config(self::getPluginFolder() . "processingLoots.json", Config::JSON); + if($cfg->exists($pos->x . ";" . $pos->y . ";" . $pos->z)) { + $loots = $cfg->get($pos->x . ";" . $pos->y . ";" . $pos->z); + $items = []; + foreach($loots as $loot) { + if(!is_array($loot)) continue; + $randCount = rand($loot["minStacks"], $loot["maxStacks"]); + for($i = 0; $i <= $randCount; $i++) { + $rand = rand(0, count($loots)); + $items[$rand] = Item::get($loot["id"], $loot["data"], rand($loot["minCount"], $loot["maxCount"])); + if(isset($loot["tags"])) $items[$rand]->setCompoundTag(NBT::fromJSON($loot["tags"])); + } + } + $inv->setContents($items); + $cfg->remove($pos->x . ";" . $pos->y . ";" . $pos->z); + $cfg->save(); + } + } + + /* + * Returns the plugins folder. + * @return string + */ + public static function getPluginFolder(): string { + $dir = explode(DIRECTORY_SEPARATOR, __DIR__); + $c = count($dir); + unset($dir[$c - 1], $dir[$c - 2], $dir[$c - 3], $dir[$c - 4], $dir[$c - 5]); + return str_ireplace("phar://", "", implode(DIRECTORY_SEPARATOR, $dir)) . DIRECTORY_SEPARATOR . "BetterGen" . DIRECTORY_SEPARATOR; + } + + /* + * Returns the resources folder. + * @return string + */ + public static function getResourcesFolder(): string { + $dir = explode(DIRECTORY_SEPARATOR, __DIR__); + $c = count($dir); + unset($dir[$c - 1], $dir[$c - 2], $dir[$c - 3], $dir[$c - 4]); + return str_ireplace("phar://", "", implode(DIRECTORY_SEPARATOR, $dir)) . DIRECTORY_SEPARATOR . "resources" . DIRECTORY_SEPARATOR; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/AmountPopulator.php b/src/Ad5001/BetterGen/populator/AmountPopulator.php new file mode 100644 index 0000000..705aba3 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/AmountPopulator.php @@ -0,0 +1,62 @@ +randomAmount = $amount; + } + + /* + * Sets the base addition amount + * @param $amount int + */ + public function setBaseAmount(int $amount) { + $this->baseAmount = $amount; + } + + /* + * Returns the amount based on random + * @param $random Random + */ + public function getAmount(Random $random) { + return $this->baseAmount + $random->nextRange ( 0, $this->randomAmount + 1 ); + } + + /* + * Returns the base amount + * @return int + */ + public function getBaseAmount(): int { + return $this->baseAmount; + } + + /* + * Returns the random additional amount + * @return int + */ + public function getRandomAmount(): int { + return $this->randomAmount; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/BushPopulator.php b/src/Ad5001/BetterGen/populator/BushPopulator.php new file mode 100644 index 0000000..5fc6777 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/BushPopulator.php @@ -0,0 +1,70 @@ +type = $type; + } + + /* + * Populate the chunk + * @param $level pocketmine\level\ChunkManager + * @param $chunkX int + * @param $chunkZ int + * @param $random pocketmine\utils\Random + */ + public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { + $this->level = $level; + $amount = $this->getAmount ( $random ); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($y === - 1) { + continue; + } + $tree = new TreePopulator::$types [$this->type] (); + $bush = new Bush ( $tree->leafBlock, $tree->leafType ?? $tree->type); + $bush->placeObject ( $level, $x, $y, $z, $random ); + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return - 1; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/CactusPopulator.php b/src/Ad5001/BetterGen/populator/CactusPopulator.php new file mode 100644 index 0000000..74177f4 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/CactusPopulator.php @@ -0,0 +1,63 @@ +setBaseAmount ( 1 ); + $this->setRandomAmount ( 2 ); + } + + /* + * Populate the chunk + * @param $level pocketmine\level\ChunkManager + * @param $chunkX int + * @param $chunkZ int + * @param $random pocketmine\utils\Random + */ + public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { + $this->level = $level; + $amount = $this->getAmount ( $random ); + $cactus = new Cactus (); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX * 16, $chunkX * 16 + 15 ); + $z = $random->nextRange ( $chunkZ * 16, $chunkZ * 16 + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($y !== - 1 and $cactus->canPlaceObject ( $level, $x, $y, $z, $random )) { + $cactus->placeObject ( $level, $x, $y, $z ); + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y >= 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { + break; + } + } + return $y === 0 ? - 1 : ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/CavePopulator.php b/src/Ad5001/BetterGen/populator/CavePopulator.php new file mode 100644 index 0000000..32f64e8 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/CavePopulator.php @@ -0,0 +1,158 @@ +level = $level; + $amount = $this->getAmount ( $random ); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $random->nextRange ( 10, $this->getHighestWorkableBlock ( $x, $z ) ); + // echo "Generating cave at $x, $y, $z." . PHP_EOL; + $this->generateCave ( $x, $y, $z, $random ); + } + // echo "Finished Populating chunk $chunkX, $chunkZ !" . PHP_EOL; + // Filling water & lava sources randomly + for($i = 0; $i < $random->nextBoundedInt ( 10 ) + 15; $i ++) { + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $random->nextRange ( 10, $this->getHighestWorkableBlock ( $x, $z ) ); + if ($level->getBlockIdAt ( $x, $y, $z ) == Block::STONE && ($level->getBlockIdAt ( $x + 1, $y, $z ) == Block::AIR || $level->getBlockIdAt ( $x - 1, $y, $z ) == Block::AIR || $level->getBlockIdAt ( $x, $y, $z + 1 ) == Block::AIR || $level->getBlockIdAt ( $x, $y, $z - 1 ) == Block::AIR) && $level->getBlockIdAt ( $x, $y - 1, $z ) !== Block::AIR && $level->getBlockIdAt ( $x, $y + 1, $z ) !== Block::AIR) { + if ($y < 40 && $random->nextBoolean ()) { + $level->setBlockIdAt ( $x, $y, $z, Block::LAVA ); + } else { + $level->setBlockIdAt ( $x, $y, $z, Block::WATER ); + } + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND or $b === Block::SNOW_BLOCK or $b === Block::SANDSTONE) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER and $b !== Block::WATER) { + return - 1; + } + } + + return ++ $y; + } + + /* + * Generates a cave + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + * @return void + */ + public function generateCave($x, $y, $z, Random $random) { + $generatedBranches = $random->nextBoundedInt ( 10 ) + 1; + // echo "Num of branch left => " . $generatedBranches . PHP_EOL; + foreach ( $gen = $this->generateBranch ( $x, $y, $z, 5, 3, 5, $random ) as $v3 ) { + $generatedBranches --; + if ($generatedBranches <= 0) { + $gen->send ( self::STOP ); + } else { + $gen->send ( self::CONTINUE ); + } + } + } + + /* + * Generates a cave branch. + * @param $x int + * @param $y int + * @param $z int + * @param $length int + * @param $height int + * @param $depth int + * @param $random pocketmine\utils\Random + * @yield int + * @return void + */ + public function generateBranch($x, $y, $z, $length, $height, $depth, Random $random) { + if (! (yield new Vector3 ( $x, $y, $z ))) { + for($i = 0; $i <= 4; $i ++) { + BuildingUtils::buildRandom ( $this->level, new Vector3 ( $x, $y, $z ), new Vector3 ( $length - $i, $height - $i, $depth - $i ), $random, Block::get ( Block::AIR ) ); + $x += round ( ($random->nextBoundedInt ( round ( 30 * ($length / 10) ) + 1 ) / 10 - 2) ); + $yP = $random->nextRange ( - 14, 14 ); + if ($yP > 12) { + $y ++; + } elseif ($yP < - 12) { + $y --; + } + $z += round ( ($random->nextBoundedInt ( round ( 30 * ($depth / 10) ) + 1 ) / 10 - 1) ); + return [ ]; + } + } + $repeat = $random->nextBoundedInt ( 25 ) + 15; + while ( $repeat -- > 0 ) { + // echo "Y => $y; H => $height; L => $length; D => $depth; R => $repeat" . PHP_EOL; + BuildingUtils::buildRandom ( $this->level, new Vector3 ( $x, $y, $z ), new Vector3 ( $length, $height, $depth ), $random, Block::get ( Block::AIR ) ); + $x += round ( ($random->nextBoundedInt ( round ( 30 * ($length / 10) ) + 1 ) / 10 - 2) ); + $yP = $random->nextRange ( - 14, 14 ); + if ($yP > 12) { + $y ++; + } elseif ($yP < - 12) { + $y --; + } + $z += round ( ($random->nextBoundedInt ( round ( 30 * ($depth / 10) ) + 1 ) / 10 - 1) ); + $height += $random->nextBoundedInt ( 3 ) - 1; + $length += $random->nextBoundedInt ( 3 ) - 1; + $depth += $random->nextBoundedInt ( 3 ) - 1; + if ($height < 3) + $height = 3; + if ($length < 3) + $length = 3; + if ($height < 3) + $height = 3; + if ($height < 7) + $height = 7; + if ($length < 7) + $length = 7; + if ($height < 7) + $height = 7; + if ($random->nextBoundedInt ( 10 ) == 0) { + foreach ( $generator = $this->generateBranch ( $x, $y, $z, $length, $height, $depth, $random ) as $gen ) { + if (! (yield $gen)) + $generator->send ( self::STOP ); + } + } + } + return; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/DeadbushPopulator.php b/src/Ad5001/BetterGen/populator/DeadbushPopulator.php new file mode 100644 index 0000000..65800c7 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/DeadbushPopulator.php @@ -0,0 +1,55 @@ +level = $level; + $amount = $this->getAmount ( $random ); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX * 16, $chunkX * 16 + 15 ); + $z = $random->nextRange ( $chunkZ * 16, $chunkZ * 16 + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($y !== - 1 && $level->getBlockIdAt ( $x, $y - 1, $z ) == Block::SAND) { + $level->setBlockIdAt ( $x, $y, $z, Block::DEAD_BUSH ); + $level->setBlockDataAt ( $x, $y, $z, 1 ); + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y >= 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { + break; + } + } + return $y === 0 ? - 1 : ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php new file mode 100644 index 0000000..dc3a453 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php @@ -0,0 +1,151 @@ +level = $level; + if($this->getAmount($random) > 130) { + $x = $random->nextRange(($chunkX << 4), ($chunkX << 4) + 15); + $z = $random->nextRange(($chunkX << 4), ($chunkX << 4) + 15); + $y = $random->nextRange($this->getHighestWorkableBlock($x, $z) < 96 ? $this->getHighestWorkableBlock($x, $z) + 20 : $this->getHighestWorkableBlock($x, $z), 126); + $radius = $random->nextRange(5, 8); + $height = $this->buildIslandBottomShape($level, new Vector3($x, $y, $z), $radius, $random); + $this->populateOres($level, new Vector3($x, $y - 1, $z), $radius * 2, $height, $random); + $chunk = $level->getChunk($chunkX, $chunkZ); + $biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16)); + $populators = $biome->getPopulators(); + foreach($populators as $populator) { + $populator->populate($level, $chunkX, $chunkZ, $random); + } + } + } + + + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return 90; + } + } + + return ++ $y; + } + + + + /* + * Builds a an island shape + * @param $level pocketmine\level\ChunkManager + * @param $pos pocketmine\math\Vector3 + * @param $radius int + * @param $random pocketmine\utils\Random + * @return void + */ + public function buildIslandBottomShape(ChunkManager $level, Vector3 $pos, int $radius, Random $random) { + $pos = $pos->round(); + $xx = $pos->x; + $zz = $z; + $currentLen = 1; + $isEdge = false; + $hBound = 0; + $current = 0; + for($y = $pos->y - 1; $radius > 0; $y--) { + for($x = $pos->x - $radius; $x <= $pos->x + $radius; $x++) { + for($z = $pos->z - $radius; $z <= $pos->z + $radius; $z ++) { + if(abs(abs($x - $pos->x) ** 2) + abs(abs($z - $pos->z) ** 2) == ($radius ** 2) * 0.67) { + $isEdge = true; + } else { + $isEdge = false; + } + if(abs(abs($x - $pos->x) ** 2) + abs(abs($z - $pos->z) ** 2) <= ($radius ** 2) * 0.67 && $y < 128) { + if($chunk = $level->getChunk($x >> 4, $z >> 4)) { + $biome = BetterNormal::getBiomeById($chunk->getBiomeId($x % 16, $z % 16)); + $block = $biome->getGroundCover()[$pos->y - $y - 1] ?? Block::get(Block::STONE); + $block = $block->getId(); + } elseif($random->nextBoundedInt(5) == 0 && $isEdge) { + $block = Block::AIR; + } else { + $block = Block::STONE; + } + $level->setBlockIdAt($x, $y, $z, $block ?? Block::STONE); + } + } + } + $current++; + $oldHB = $hBound; + $hBound = $random->nextFloat(); + if($current >= $currentLen + $hBound) { + if($radius == 0) return; + $current = 0; + $currentLen += 0.3 * ($random->nextFloat() + 0.5); + $radius--; + } + } + return $pos->y - 1 - $y; + } + + + + + /* + * BPopulate the island with ores + * @param $level pocketmine\level\ChunkManager + * @param $pos pocketmine\math\Vector3 + * @param $width int + * @param $height int + * @param $random pocketmine\utils\Random + * @return void + */ + public function populateOres(ChunkManager $level, Vector3 $pos, int $width, int $height, Random $random) { + $ores = new Ore (); + $ores->setOreTypes ( [ + new OreType ( new CoalOre (), 20, 16, $pos->y - $height, $pos->y ), + new OreType ( new IronOre (), 20, 8, $pos->y - $height, $pos->y - round($height * 0.75)), + new OreType ( new RedstoneOre (), 8, 7, $pos->y - $height, $pos->y - round($height / 2)), + new OreType ( new LapisOre (), 1, 6, $pos->y - $height, $pos->y - round($height / 2)), + new OreType ( new GoldOre (), 2, 8, $pos->y - $height, $pos->y - round($height / 2)), + new OreType ( new DiamondOre (), 1, 7, $pos->y - $height, $pos->y - round($height / 4)) + ] ); + $ores->populate($level, $x >> 4, $z >> 4, $random); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/IglooPopulator.php b/src/Ad5001/BetterGen/populator/IglooPopulator.php new file mode 100644 index 0000000..1e70ba0 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/IglooPopulator.php @@ -0,0 +1,56 @@ +level = $level; + if ($random->nextBoundedInt ( 100 ) > 30) + return; + $igloo = new Igloo (); + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ) - 1; + if ($igloo->canPlaceObject ( $level, $x, $y, $z, $random )) + $igloo->placeObject ( $level, $x, $y, $z, $random ); + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return - 1; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/LakePopulator.php b/src/Ad5001/BetterGen/populator/LakePopulator.php new file mode 100644 index 0000000..844482d --- /dev/null +++ b/src/Ad5001/BetterGen/populator/LakePopulator.php @@ -0,0 +1,65 @@ +level = $level; + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $ory = $random->nextRange ( 20, 63 ); // Water level + $y = $ory; + for($i = 0; $i < 4; $i ++) { + $x += $random->nextRange ( - 1, 1 ); + $y += $random->nextRange ( - 1, 1 ); + $z += $random->nextRange ( - 1, 1 ); + if ($level->getBlockIdAt ( $x, $y, $z ) !== Block::AIR) + BuildingUtils::buildRandom ( $this->level, new Vector3 ( $x, $y, $z ), new Vector3 ( 5, 5, 5 ), $random, Block::get ( Block::WATER ) ); + } + for($xx = $x - 8; $xx <= $x + 8; $xx ++) + for($zz = $z - 8; $zz <= $z + 8; $zz ++) + for($yy = $ory + 1; $yy <= $y + 3; $yy ++) + if ($level->getBlockIdAt ( $xx, $yy, $zz ) == Block::WATER) + $level->setBlockIdAt ( $xx, $yy, $zz, Block::AIR ); + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return - 1; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/MineshaftPopulator.php b/src/Ad5001/BetterGen/populator/MineshaftPopulator.php new file mode 100644 index 0000000..f875c64 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/MineshaftPopulator.php @@ -0,0 +1,427 @@ +getAmount ( $random ) < 100) + return; + $this->level = $level; + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $random->nextRange ( 5, 50 ); + // First filling the large dirt place (center of the mineshaft) + BuildingUtils::fill ( $level, new Vector3 ( $x - 6, $y, $x - 6 ), new Vector3 ( $x + 6, $y + 8, $z + 6 ), Block::get ( Block::AIR ) ); + BuildingUtils::fill ( $level, new Vector3 ( $x - 6, $y, $x - 6 ), new Vector3 ( $x + 6, $y, $z + 6 ), Block::get ( Block::DIRT ) ); + $startingPath = $random->nextBoundedInt ( 4 ); + $this->maxPath = $random->nextBoundedInt ( 100 ) + 50; + foreach ( array_fill ( 0, $startingPath, 1 ) as $hey ) { + $dir = $random->nextBoundedInt ( 4 ); + switch ($dir) { + case self::DIR_XPLUS : + $this->generateMineshaftPart ( $x + 6, $y + $random->nextBoundedInt ( 5 ), $z + $random->nextBoundedInt ( 12 ) - 6, $dir, $random ); + break; + case self::DIR_XMIN : + $this->generateMineshaftPart ( $x - 6, $y + $random->nextBoundedInt ( 5 ), $z + $random->nextBoundedInt ( 12 ) - 6, $dir, $random ); + break; + case self::DIR_ZPLUS : + $this->generateMineshaftPart ( $x + $random->nextBoundedInt ( 12 ) - 6, $y + $random->nextBoundedInt ( 8 ), $z + 6, $dir, $random ); + break; + case self::DIR_ZMIN : + $this->generateMineshaftPart ( $x + $random->nextBoundedInt ( 12 ) - 6, $y + $random->nextBoundedInt ( 8 ), $z - 6, $dir, $random ); + break; + } + } + } + + /* + * Builds a mineshaft part and return applicable directions + * @param $x int + * @param $y int + * @param $z int + * @param $dir int + * @param $random pocketmine\utils\Random + * @param $deepneth int + */ + public function generateMineshaftPart(int $x, int $y, int $z, int $dir, Random $random) { + if ($this->maxPath -- < 1) + return; + $type = $random->nextBoundedInt ( 3 ); + $level = $this->level; + switch ($type) { + case self::TYPE_FORWARD : + switch ($dir) { + case self::DIR_XPLUS : + // First, filling everything blank. + BuildingUtils::fill ( $this->level, new Vector3 ( $x, $y, $z - 1 ), new Vector3 ( $x + 4, $y + 2, $z + 1 ), Block::get ( Block::AIR ) ); + // Then, making sure the floor is solid. + BuildingUtils::fillCallback ( new Vector3 ( $x, $y - 1, $z - 1 ), new Vector3 ( $x + 4, $y - 1, $z + 1 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + // Putting rails + BuildingUtils::fillCallback ( new Vector3 ( $x, $y, $z ), new Vector3 ( $x + 4, $y, $z ), function ($v3, $params) { + $level = $params [0]; + $random = $params [1]; + if ($random->nextBoundedInt ( 3 ) !== 0) { + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::RAIL ); + $level->setBlockDataAt ( $v3->x, $v3->y, $v3->z, 1 ); + } + }, $this->level, $random ); + // After this, building the floor maintener (the wood structure) + $level->setBlockIdAt ( $x, $y, $z - 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y, $z + 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 1, $z + 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 2, $z - 1, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z + 1, Block::PLANK ); + $level->setBlockIdAt ( $x + 1, $y + 2, $z, Block::TORCH ); + $level->setBlockDataAt ( $x + 1, $y + 2, $z, 2 ); + // Generating chest + if ($random->nextBoundedInt ( 30 ) == 0) { + $direction = ( int ) $random->nextBoolean (); + if ($direction == 0) + $direction = - 1; // Choosing the part of the rail. + $direction2 = ( int ) $random->nextBoolean (); + if ($direction2 == 0) + $direction2 = 2; + if ($direction2 == 1) + $direction2 = 4; + LootTable::buildLootTable ( new Vector3 ( $x + $direction2, $y, $z + $direction ), LootTable::LOOT_MINESHAFT, $random ); + } + if ($random->nextBoundedInt ( 30 ) !== 0) + $this->generateMineshaftPart ( $x + 5, $y, $z, $dir, $random ); + break; + case self::DIR_XMIN : + // First, filling everything blank. + BuildingUtils::fill ( $this->level, new Vector3 ( $x, $y, $z - 1 ), new Vector3 ( $x - 4, $y + 2, $z + 1 ) ); + // Then, making sure the floor is solid. + BuildingUtils::fillCallback ( new Vector3 ( $x, $y - 1, $z - 1 ), new Vector3 ( $x - 4, $y - 1, $z + 1 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + // Putting rails + BuildingUtils::fillCallback ( new Vector3 ( $x, $y, $z ), new Vector3 ( $x - 4, $y, $z ), function ($v3, $params) { + $level = $params [0]; + $random = $params [1]; + if ($random->nextBoundedInt ( 3 ) !== 0) { + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::RAIL ); + $level->setBlockDataAt ( $v3->x, $v3->y, $v3->z, 1 ); + } + }, $this->level, $random ); + // After this, building the floor maintener (the wood structure) + $level->setBlockIdAt ( $x, $y, $z - 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y, $z + 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 1, $z + 1, Block::FENCE ); + $level->setBlockIdAt ( $x, $y + 2, $z - 1, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z + 1, Block::PLANK ); + $level->setBlockIdAt ( $x - 1, $y + 2, $z, Block::TORCH ); + $level->setBlockDataAt ( $x - 1, $y + 2, $z, 1 ); + // Generating chest + if ($random->nextBoundedInt ( 30 ) == 0) { + $direction = ( int ) $random->nextBoolean (); + if ($direction == 0) + $direction = - 1; // Choosing the part of the rail. + $direction2 = ( int ) $random->nextBoolean (); + if ($direction2 == 0) + $direction2 = 2; + if ($direction2 == 1) + $direction2 = + LootTable::buildLootTable ( new Vector3 ( $x - $direction2, $y, $z + $direction ), LootTable::LOOT_MINESHAFT, $random ); + } + if ($random->nextBoundedInt ( 30 ) !== 0) + $this->generateMineshaftPart ( $x - 5, $y, $z, $dir, $random ); + break; + case self::DIR_ZPLUS : + // First, filling everything blank. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 1, $y, $z ), new Vector3 ( $x + 1, $y + 2, $z + 4 ) ); + // Then, making sure the floor is solid. + BuildingUtils::fillCallback ( new Vector3 ( $x - 1, $y - 1, $z ), new Vector3 ( $x + 1, $y - 1, $z + 4 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + // Putting rails + BuildingUtils::fillCallback ( new Vector3 ( $x, $y, $z ), new Vector3 ( $x, $y, $z + 4 ), function ($v3, $params) { + $level = $params [0]; + $random = $params [1]; + if ($random->nextBoundedInt ( 3 ) !== 0) { + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::RAIL ); + $level->setBlockDataAt ( $v3->x, $v3->y, $v3->z, 0 ); + } + }, $this->level, $random ); + // After this, building the floor maintener (the wood structure) + $level->setBlockIdAt ( $x - 1, $y, $z, Block::FENCE ); + $level->setBlockIdAt ( $x + 1, $y, $z, Block::FENCE ); + $level->setBlockIdAt ( $x - 1, $y + 1, $z, Block::FENCE ); + $level->setBlockIdAt ( $x + 1, $y + 1, $z, Block::FENCE ); + $level->setBlockIdAt ( $x - 1, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x + 1, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z - 1, Block::TORCH ); + $level->setBlockDataAt ( $x, $y + 2, $z - 1, 4 ); + // Generating chest + if ($random->nextBoundedInt ( 30 ) == 0) { + $direction = ( int ) $random->nextBoolean (); + if ($direction == 0) + $direction = - 1; // Choosing the part of the rail. + $direction2 = ( int ) $random->nextBoolean (); + if ($direction2 == 0) + $direction2 = 2; + if ($direction2 == 1) + $direction2 = 4; + LootTable::buildLootTable ( new Vector3 ( $x + $direction, $y, $z + $direction2 ), LootTable::LOOT_MINESHAFT, $random ); + } + if ($random->nextBoundedInt ( 30 ) !== 0) + $this->generateMineshaftPart ( $x, $y, $z + 5, $dir, $random ); + break; + case self::DIR_ZMIN : + // First, filling everything blank. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 1, $y, $z ), new Vector3 ( $x + 1, $y + 2, $z - 4 ) ); + // Then, making sure the floor is solid. + BuildingUtils::fillCallback ( new Vector3 ( $x - 1, $y - 1, $z ), new Vector3 ( $x + 1, $y - 1, $z - 4 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + // Putting rails + BuildingUtils::fillCallback ( new Vector3 ( $x, $y, $z ), new Vector3 ( $x, $y, $z - 4 ), function ($v3, $params) { + $level = $params [0]; + $random = $params [1]; + if ($random->nextBoundedInt ( 3 ) !== 0) { + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::RAIL ); + $level->setBlockDataAt ( $v3->x, $v3->y, $v3->z, 0 ); + } + }, $this->level, $random ); + // After this, building the floor maintener (the wood structure) + $level->setBlockIdAt ( $x - 1, $y, $z, Block::FENCE ); + $level->setBlockIdAt ( $x + 1, $y, $z, Block::FENCE ); + $level->setBlockIdAt ( $x - 1, $y + 1, $z, Block::FENCE ); + $level->setBlockIdAt ( $x + 1, $y + 1, $z, Block::FENCE ); + $level->setBlockIdAt ( $x - 1, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x + 1, $y + 2, $z, Block::PLANK ); + $level->setBlockIdAt ( $x, $y + 2, $z - 1, Block::TORCH ); + $level->setBlockDataAt ( $x, $y + 2, $z - 1, 3 ); + // Generating chest + if ($random->nextBoundedInt ( 30 ) == 0) { + $direction = ( int ) $random->nextBoolean (); + if ($direction == 0) + $direction = - 1; // Choosing the part of the rail. + $direction2 = ( int ) $random->nextBoolean (); + if ($direction2 == 0) + $direction2 = 2; + if ($direction2 == 1) + $direction2 = 4; + LootTable::buildLootTable ( new Vector3 ( $x + $direction, $y, $z - $direction2 ), LootTable::LOOT_MINESHAFT, $random ); + } + if ($random->nextBoundedInt ( 30 ) !== 0) + $this->generateMineshaftPart ( $x, $y, $z - 5, $dir, $random ); + break; + } + // Doing cobwebs + $webNum = $random->nextBoundedInt ( 5 ) + 2; + for($i = 0; $i < $webNum; $i ++) { + $xx = $x + $random->nextBoundedInt ( 5 ) - 2; + $yy = $y + $random->nextBoundedInt ( 3 ); + $zz = $z + $random->nextBoundedInt ( 5 ) - 2; + if ($level->getBlockIdAt ( $xx, $yy, $zz ) == Block::AIR) + $level->setBlockIdAt ( $xx, $yy, $zz, Block::COBWEB ); + } + break; + case self::TYPE_CROSSPATH : + $possiblePathes = [ + self::DIR_XPLUS, + self::DIR_XMIN, + self::DIR_ZPLUS, + self::DIR_ZMIN + ]; + switch ($dir) { + case self::DIR_XPLUS : + $x ++; + unset ( $possiblePathes [0] ); + break; + case self::DIR_XMIN : + $x --; + unset ( $possiblePathes [1] ); + break; + case self::DIR_ZPLUS : + $z ++; + unset ( $possiblePathes [2] ); + break; + case self::DIR_ZMIN : + $z --; + unset ( $possiblePathes [3] ); + break; + } + + // Then, making sure the floor is solid. + BuildingUtils::fillCallback ( new Vector3 ( $x + 1, $y - 1, $z - 1 ), new Vector3 ( $x - 1, $y - 1, $z + 1 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + // Putting rails + + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 1, $y, $z - 1 ), new Vector3 ( $x + 1, $y + 6, $z + 1 ), Block::get ( Block::AIR ) ); + + BuildingUtils::corners ( $this->level, new Vector3 ( $x - 1, $y, $z - 1 ), new Vector3 ( $x + 1, $y + 6, $z + 1 ), Block::get ( Block::PLANK ) ); + + $newFloor = $random->nextBoolean (); + $numberFloor = $random->nextBoundedInt ( 4 + ($newFloor ? 5 : 0) ); + $possiblePathes = [ + $possiblePathes, + ($newFloor ? [ + self::DIR_XPLUS, + self::DIR_XMIN, + self::DIR_ZPLUS, + self::DIR_ZMIN + ] : [ ]) + ]; + for($i = 7; $i > $newfloor; $i --) { + $chooseNew = ( int ) $newFloor && $random->nextBoolean (); + $choose = $random->nextBoundedInt ( 4 ); + unset ( $possiblePathes [$chooseNew] [$choose] ); + } + // Buidling pathes + foreach ( $possiblePathes [0] as $path ) { + switch ($path) { + case self::DIR_XPLUS : + $this->generateMineshaftPart ( $x + 2, $y, $z, self::DIR_XPLUS, $random ); + break; + case self::DIR_XMIN : + $this->generateMineshaftPart ( $x - 2, $y, $z, self::DIR_XMIN, $random ); + break; + case self::DIR_ZPLUS : + $this->generateMineshaftPart ( $x, $y, $z + 2, self::DIR_ZPLUS, $random ); + break; + case self::DIR_ZMIN : + $this->generateMineshaftPart ( $x, $y, $z - 2, self::DIR_ZMIN, $random ); + break; + } + } + foreach ( $possiblePathes [1] as $path ) { + switch ($path) { + case self::DIR_XPLUS : + $this->generateMineshaftPart ( $x + 2, $y + 4, $z, self::DIR_XPLUS, $random ); + break; + case self::DIR_XMIN : + $this->generateMineshaftPart ( $x - 2, $y + 4, $z, self::DIR_XMIN, $random ); + break; + case self::DIR_ZPLUS : + $this->generateMineshaftPart ( $x, $y + 4, $z + 2, self::DIR_ZPLUS, $random ); + break; + case self::DIR_ZMIN : + $this->generateMineshaftPart ( $x, $y + 4, $z - 2, self::DIR_ZMIN, $random ); + break; + } + } + + // Doing cobwebs + $webNum = $random->nextBoundedInt ( 5 ) + 2; + for($i = 0; $i < $webNum; $i ++) { + $xx = $x + $random->nextBoundedInt ( 3 ) - 1; + $yy = $y + $random->nextBoundedInt ( 6 ); + $zz = $z + $random->nextBoundedInt ( 3 ) - 1; + if ($level->getBlockIdAt ( $xx, $yy, $zz ) == Block::AIR) + $level->setBlockIdAt ( $xx, $yy, $zz, Block::COBWEB ); + } + break; + case self::TYPE_STAIRS : + if($y <= 5) { + $this->generateMineshaftPart ( $x, $y, $z, $dir, $random ); + return; + } + // Building stairs + for($i = 0; $i < 4; $i ++) { + switch ($path) { + case self::DIR_XPLUS : + BuildingUtils::fill ( $this->level, new Vector3 ( $x + $i, $y - $i - 1, $z - 2 ), new Vector3 ( $x + $i, $y - $i + 3, $z + 2 ), Block::get ( Block::AIR ) ); + BuildingUtils::fillCallback ( new Vector3 ( $x + $i, $y - $i - 2, $z - 2 ), new Vector3 ( $x + $i, $y - $i - 2, $z + 2 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + break; + case self::DIR_XMIN : + BuildingUtils::fill ( $this->level, new Vector3 ( $x - $i, $y - $i - 1, $z - 2 ), new Vector3 ( $x - $i, $y - $i + 3, $z + 2 ), Block::get ( Block::AIR ) ); + BuildingUtils::fillCallback ( new Vector3 ( $x - $i, $y - $i - 2, $z - 2 ), new Vector3 ( $x - $i, $y - $i - 2, $z + 2 ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + break; + case self::DIR_ZPLUS : + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 2, $y - $i - 1, $z + $i ), new Vector3 ( $x + 2, $y - $i + 3, $z + $i ), Block::get ( Block::AIR ) ); + BuildingUtils::fillCallback ( new Vector3 ( $x - 2, $y - $i - 2, $z + $i ), new Vector3 ( $x + 2, $y - $i - 2, $z + $i ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + break; + case self::DIR_ZMIN : + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 2, $y - $i - 1, $z - $i ), new Vector3 ( $x + 2, $y - $i + 3, $z - $i ), Block::get ( Block::AIR ) ); + BuildingUtils::fillCallback ( new Vector3 ( $x - 2, $y - $i - 2, $z - $i ), new Vector3 ( $x + 2, $y - $i - 2, $z - $i ), function ($v3, $params) { + $level = $params [0]; + if ($level->getBlockIdAt ( $v3->x, $v3->y, $v3->z ) == Block::AIR) + $level->setBlockIdAt ( $v3->x, $v3->y, $v3->z, Block::PLANK ); + }, $this->level ); + break; + } + } + + // Next one + switch ($path) { + case self::DIR_XPLUS : + $this->generateMineshaftPart ( $x + 4, $y - 4, $z, self::DIR_XPLUS, $random ); + break; + case self::DIR_XMIN : + $this->generateMineshaftPart ( $x - 4, $y - 4, $z, self::DIR_XMIN, $random ); + break; + case self::DIR_ZPLUS : + $this->generateMineshaftPart ( $x, $y - 4, $z + 4, self::DIR_ZPLUS, $random ); + break; + case self::DIR_ZMIN : + $this->generateMineshaftPart ( $x, $y - 4, $z - 4, self::DIR_ZMIN, $random ); + break; + } + break; + } + } +} +?> \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/RavinePopulator.php b/src/Ad5001/BetterGen/populator/RavinePopulator.php new file mode 100644 index 0000000..19bc741 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/RavinePopulator.php @@ -0,0 +1,121 @@ +level = $level; + $amount = $this->getAmount ( $random ); + if ($amount > 50) { // Only build one per chunk + $depth = $random->nextBoundedInt ( 60 ) + 30; // 2Much4U? + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $random->nextRange ( 5, $this->getHighestWorkableBlock ( $x, $z ) ); + $deffX = $x; + $deffZ = $z; + $height = $random->nextRange ( 15, 30 ); + $length = $random->nextRange ( 5, 12 ); + for($i = 0; $i < $depth; $i ++) { + $this->buildRavinePart ( $x, $y, $z, $height, $length, $random ); + $diffX = $x - $deffX; + $diffZ = $z - $deffZ; + if ($diffX > $length / 2) + $diffX = $length / 2; + if ($diffX < - $length / 2) + $diffX = - $length / 2; + if ($diffZ > $length / 2) + $diffZ = $length / 2; + if ($diffZ < - $length / 2) + $diffZ = - $length / 2; + if ($length > 10) + $length = 10; + if ($length < 5) + $length = 5; + $x += $random->nextRange ( 0 + $diffX, 2 + $diffX ) - 1; + $y += $random->nextRange ( 0, 2 ) - 1; + $z += $random->nextRange ( 0 + $diffZ, 2 + $diffZ ) - 1; + $heigth += $random->nextRange ( 0, 2 ) - 1; + $length += $random->nextRange ( 0, 2 ) - 1; + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL or $b === Block::SAND or $b === Block::SNOW_BLOCK or $b === Block::SANDSTONE) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER and $b !== Block::WATER) { + return - 1; + } + } + + return ++ $y; + } + + /* + * Builds a ravine part + * @param $x int + * @param $y int + * @param $z int + * @param $height int + * @param $length int + * @param $random pocketmine\utils\Random + */ + protected function buildRavinePart($x, $y, $z, $height, $length, Random $random) { + for($xx = $x - $length; $xx <= $x + $length; $xx ++) { + for($yy = $y; $yy <= $y + $height; $yy ++) { + for($zz = $z - $length; $zz <= $z + $length; $zz ++) { + $oldXB = $xBounded; + $xBounded = $random->nextBoundedInt ( self::NOISE * 2 ) - self::NOISE; + $oldZB = $zBounded; + $zBounded = $random->nextBoundedInt ( self::NOISE * 2 ) - self::NOISE; + if ($xBounded > self::NOISE - 2) { + $xBounded = 1; + } elseif ($xBounded < - self::NOISE + 2) { + $xBounded = - 1; + } else { + $xBounded = $oldXB; + } + if ($zBounded > self::NOISE - 2) { + $zBounded = 1; + } elseif ($zBounded < - self::NOISE + 2) { + $zBounded = - 1; + } else { + $zBounded = $oldZB; + } + if (abs ( (abs ( $xx ) - abs ( $x )) ** 2 + (abs ( $zz ) - abs ( $z )) ** 2 ) < ((($length / 2 - $xBounded) + ($length / 2 - $zBounded)) / 2) ** 2 && $y > 0 && ! in_array ( $this->level->getBlockIdAt ( ( int ) round ( $xx ), ( int ) round ( $yy ), ( int ) round ( $zz ) ), BuildingUtils::TO_NOT_OVERWRITE ) && ! in_array ( $this->level->getBlockIdAt ( ( int ) round ( $xx ), ( int ) round ( $yy + 1 ), ( int ) round ( $zz ) ), BuildingUtils::TO_NOT_OVERWRITE )) { + $this->level->setBlockIdAt ( ( int ) round ( $xx ), ( int ) round ( $yy ), ( int ) round ( $zz ), Block::AIR ); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/SugarCanePopulator.php b/src/Ad5001/BetterGen/populator/SugarCanePopulator.php new file mode 100644 index 0000000..163640e --- /dev/null +++ b/src/Ad5001/BetterGen/populator/SugarCanePopulator.php @@ -0,0 +1,63 @@ +setBaseAmount ( 1 ); + $this->setRandomAmount ( 2 ); + } + + /* + * Populate the chunk + * @param $level pocketmine\level\ChunkManager + * @param $chunkX int + * @param $chunkZ int + * @param $random pocketmine\utils\Random + */ + public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { + $this->level = $level; + $amount = $this->getAmount ( $random ); + $sugarcane = new SugarCane (); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX * 16, $chunkX * 16 + 15 ); + $z = $random->nextRange ( $chunkZ * 16, $chunkZ * 16 + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($y !== - 1 and $sugarcane->canPlaceObject ( $level, $x, $y, $z, $random )) { + $sugarcane->placeObject ( $level, $x, $y, $z ); + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y >= 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b !== Block::AIR and $b !== Block::LEAVES and $b !== Block::LEAVES2) { + break; + } + } + return $y === 0 ? - 1 : ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/TemplePopulator.php b/src/Ad5001/BetterGen/populator/TemplePopulator.php new file mode 100644 index 0000000..1176178 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/TemplePopulator.php @@ -0,0 +1,54 @@ +level = $level; + if ($random->nextBoundedInt ( 1000 ) > 70) + return; + $temple = new Temple (); + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($temple->canPlaceObject ( $level, $x, $y, $z, $random )) + $temple->placeObject ( $level, $x, $y - 1, $z, $random ); + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::SAND) { + break; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/TreePopulator.php b/src/Ad5001/BetterGen/populator/TreePopulator.php new file mode 100644 index 0000000..49f99ce --- /dev/null +++ b/src/Ad5001/BetterGen/populator/TreePopulator.php @@ -0,0 +1,75 @@ +type = $type; + } + + /* + * Populate the chunk + * @param $level pocketmine\level\ChunkManager + * @param $chunkX int + * @param $chunkZ int + * @param $random pocketmine\utils\Random + */ + public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random) { + $this->level = $level; + $amount = $this->getAmount ( $random ); + for($i = 0; $i < $amount; ++ $i) { + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ); + if ($y === - 1) { + continue; + } + $tree = new self::$types [$this->type] (); + if ($tree->canPlaceObject ( $level, $x, $y, $z, $random )) { + $tree->placeObject ( $level, $x, $y, $z, $random ); + } + } + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::DIRT or $b === Block::GRASS or $b === Block::PODZOL) { + break; + } elseif ($b !== 0 and $b !== Block::SNOW_LAYER) { + return - 1; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/populator/WellPopulator.php b/src/Ad5001/BetterGen/populator/WellPopulator.php new file mode 100644 index 0000000..cf300f1 --- /dev/null +++ b/src/Ad5001/BetterGen/populator/WellPopulator.php @@ -0,0 +1,54 @@ +level = $level; + if ($random->nextBoundedInt ( 1000 ) > 25) + return; // ~1 chance / 1000 due to building limitations. + $well = new Well (); + $x = $random->nextRange ( $chunkX << 4, ($chunkX << 4) + 15 ); + $z = $random->nextRange ( $chunkZ << 4, ($chunkZ << 4) + 15 ); + $y = $this->getHighestWorkableBlock ( $x, $z ) - 1; + if ($well->canPlaceObject ( $level, $x, $y, $z, $random )) + $well->placeObject ( $level, $x, $y, $z, $random ); + } + + /* + * Gets the top block (y) on an x and z axes + * @param $x int + * @param $z int + */ + protected function getHighestWorkableBlock($x, $z) { + for($y = 127; $y > 0; -- $y) { + $b = $this->level->getBlockIdAt ( $x, $y, $z ); + if ($b === Block::SAND) { + break; + } + } + + return ++ $y; + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/Bush.php b/src/Ad5001/BetterGen/structure/Bush.php new file mode 100644 index 0000000..b9d9bc5 --- /dev/null +++ b/src/Ad5001/BetterGen/structure/Bush.php @@ -0,0 +1,76 @@ + true, + 17 => true, + Block::SNOW_LAYER => true, + Block::LOG2 => true + ]; + protected $leaf; + protected $height; + + /* + * Constructs the class + * @param $leafId int + * @param $leafData int + */ + public function __construct($leafId = Block::LEAVES, $leafData = 0) { + $this->leaf = [ + $leafId, + $leafData + ]; + } + + /* + * Places a bush + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + */ + public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + $number = $random->nextBoundedInt ( 6 ); + $pos = new Vector3 ( $x, $y, $z ); + $this->placeLeaf ( $pos->x, $pos->y, $pos->z, $level ); + for($i = 0; $i < $number; $i ++) { + $transfer = $random->nextBoolean (); + $direction = $random->nextBoundedInt ( 6 ); + $newPos = $pos->getSide ( $direction ); + if ($transfer) + $pos = $newPos; + $this->placeLeaf ( $newPos->x, $newPos->y, $newPos->z, $level ); + } + } + + /* + * Places a leaf + * @param $x int + * @param $y int + * @param $z int + * @param $level pocketmine\level\ChunkManager + */ + public function placeLeaf($x, $y, $z, ChunkManager $level) { + if (isset ( $this->overridable [$level->getBlockIdAt ( $x, $y, $z )] ) && ! isset ( $this->overridable [$level->getBlockIdAt ( $x, $y - 1, $z )] )) { + $level->setBlockIdAt ( $x, $y, $z, $this->leaf [0] ); + $level->setBlockDataAt ( $x, $y, $z, $this->leaf [1] ); + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/Cactus.php b/src/Ad5001/BetterGen/structure/Cactus.php new file mode 100644 index 0000000..73bfa39 --- /dev/null +++ b/src/Ad5001/BetterGen/structure/Cactus.php @@ -0,0 +1,54 @@ +totalHeight = 1 + $random->nextBoundedInt ( 3 ); + $below = $level->getBlockIdAt ( $x, $y - 1, $z ); + for($yy = $y; $yy <= $y + $totalHeight; $yy ++) { + if ($level->getBlockIdAt ( $x, $yy, $z ) !== Block::AIR || ($below !== Block::SAND && $below !== Block::CACTUS) || ($level->getBlockIdAt ( $x - 1, $yy, $z ) !== Block::AIR || $level->getBlockIdAt ( $x + 1, $yy, $z ) !== Block::AIR || $level->getBlockIdAt ( $x, $yy, $z - 1 ) !== Block::AIR || $level->getBlockIdAt ( $x, $yy, $z + 1 ) !== Block::AIR)) { + return false; + } + } + return true; + } + + /* + * Places a cactus + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + */ + public function placeObject(ChunkManager $level, int $x, int $y, int $z) { + for($yy = 0; $yy < $this->totalHeight; $yy ++) { + if ($level->getBlockIdAt ( $x, $y + $yy, $z ) != Block::AIR) { + return; + } + $level->setBlockIdAt ( $x, $y + $yy, $z, Block::CACTUS ); + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/Igloo.php b/src/Ad5001/BetterGen/structure/Igloo.php new file mode 100644 index 0000000..bd02ecc --- /dev/null +++ b/src/Ad5001/BetterGen/structure/Igloo.php @@ -0,0 +1,384 @@ + true, + 6 => true, + 17 => true, + 18 => true, + Block::DANDELION => true, + Block::POPPY => true, + Block::SNOW_LAYER => true, + Block::LOG2 => true, + Block::LEAVES2 => true + ]; + protected $direction; + + /* + * Checks if an igloo is placeable + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + * @return bool + */ + public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) { + $this->direction = $random->nextBoundedInt ( 4 ); + switch ($this->direction) { + case 0 : // Entrance is x+ + for($xx = $x - 3; $xx <= $x + 4; $xx ++) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 3; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + break; + case 1 : // Entrance is x- + for($xx = $x - 4; $xx <= $x + 3; $xx ++) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 3; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + break; + case 2 : // Entrence is z+ + for($xx = $x - 3; $xx <= $x + 3; $xx ++) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 3; $zz <= $z + 4; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + break; + case 3 : // Entrance is z- + for($xx = $x - 3; $xx <= $x + 3; $xx ++) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 4; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + break; + } + return true; + } + + /* + * Places an igloo + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + */ + public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + if (! isset ( $this->direction ) && ! $this->canPlaceObject ( $level, $x, $y, $z, $random )) + return false; + switch ($this->direction) { + case 0 : // Entrance is x+ + // Ground + for($xx = $x - 3; $xx <= $x + 4; $xx ++) + for($zz = $z - 3; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $y, $zz )] )) + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + // Entrance + for($i = 0; $i < 2; $i ++) { + $level->setBlockIdAt ( $x + 3 + $i, $y, $z, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3 + $i, $y + 3, $z, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3 + $i, $y + 1, $z + 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3 + $i, $y + 1, $z - 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3 + $i, $y + 2, $z + 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3 + $i, $y + 2, $z - 1, Block::SNOW_BLOCK ); + } + + // Back + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $x - 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3, $y + 2, $zz, Block::SNOW_BLOCK ); + } + + // Sides + for($xx = $x - 1; $xx <= $x + 1; $xx ++) { + $level->setBlockIdAt ( $xx, $y + 1, $z - 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z - 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 1, $z + 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z + 3, Block::SNOW_BLOCK ); + } + $level->setBlockIdAt ( $x, $y + 1, $z + 3, Block::ICE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 3, Block::ICE ); + + // Diags + for($i = 1; $i <= 2; $i ++) { + $level->setBlockIdAt ( $x + 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + } + + // 2nd layer + for($i = 0; $i < 3; $i ++) { + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + } + + // Top + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 4, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + } + + // Carpets + for($xx = $x - 2; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 1, $zz, Block::CARPET ); + } + + // Other furnitures + // Bed + $level->setBlockIdAt ( $x - 1, $y + 1, $z + 2, Block::BED_BLOCK ); + $level->setBlockIdAt ( $x, $y + 1, $z + 2, Block::BED_BLOCK ); + $level->setBlockDataAt ( $x - 1, $y + 1, $z + 2, 9 ); + $level->setBlockDataAt ( $x, $y + 1, $z + 2, 1 ); + // Other + $level->setBlockIdAt ( $x - 1, $y + 1, $z - 2, Block::CRAFTING_TABLE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 2, Block::REDSTONE_TORCH ); + $level->setBlockIdAt ( $x + 1, $y + 1, $z - 2, Block::FURNACE ); + + break; + + // Second direction + case 1 : // Entrance is x- + // Ground + for($xx = $x - 4; $xx <= $x + 3; $xx ++) + for($zz = $z - 3; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $y, $zz )] )) + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + // Entrance + for($i = 0; $i < 2; $i ++) { + $level->setBlockIdAt ( $x - 3 - $i, $y, $z, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3 - $i, $y + 3, $z, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3 - $i, $y + 1, $z + 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3 - $i, $y + 1, $z - 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3 - $i, $y + 2, $z + 1, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3 - $i, $y + 2, $z - 1, Block::SNOW_BLOCK ); + } + + // Back + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $x + 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3, $y + 2, $zz, Block::SNOW_BLOCK ); + } + + // Sides + for($xx = $x - 1; $xx <= $x + 1; $xx ++) { + $level->setBlockIdAt ( $xx, $y + 1, $z - 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z - 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 1, $z + 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z + 3, Block::SNOW_BLOCK ); + } + $level->setBlockIdAt ( $x, $y + 1, $z + 3, Block::ICE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 3, Block::ICE ); + + // Diags + for($i = 1; $i <= 2; $i ++) { + $level->setBlockIdAt ( $x + 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + } + + // 2nd layer + for($i = 0; $i < 3; $i ++) { + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + } + + // Top + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 4, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + } + + // Carpets + for($xx = $x - 1; $xx <= $x + 2; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 1, $zz, Block::CARPET ); + } + + // Other furnitures + // Bed + $level->setBlockIdAt ( $x + 1, $y + 1, $z + 2, Block::BED_BLOCK ); + $level->setBlockIdAt ( $x, $y + 1, $z + 2, Block::BED_BLOCK ); + $level->setBlockDataAt ( $x + 1, $y + 1, $z + 2, 11 ); + $level->setBlockDataAt ( $x, $y + 1, $z + 2, 3 ); + // Other + $level->setBlockIdAt ( $x + 1, $y + 1, $z - 2, Block::CRAFTING_TABLE ); + $level->setBlockIdAt ( $x, $y + 1, $z - 2, Block::REDSTONE_TORCH ); + $level->setBlockIdAt ( $x - 1, $y + 1, $z - 2, Block::FURNACE ); + break; + + // Third direction + case 2 : // Entrence is z+ + // Ground + for($xx = $x - 3; $xx <= $x + 3; $xx ++) + for($zz = $z - 3; $zz <= $z + 4; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $y, $zz )] )) + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + // Entrance + for($i = 0; $i < 2; $i ++) { + $level->setBlockIdAt ( $x, $y, $z + 3 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x, $y + 3, $z + 3 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 1, $y + 1, $z + 3 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1, $y + 1, $z + 3 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 1, $y + 2, $z + 3 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1, $y + 2, $z + 3 + $i, Block::SNOW_BLOCK ); + } + + // Back + for($xx = $x - 1; $xx <= $x + 1; $xx ++) { + $level->setBlockIdAt ( $xx, $y + 1, $z - 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z - 3, Block::SNOW_BLOCK ); + } + + // Sides + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $x - 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3, $y + 2, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3, $y + 2, $zz, Block::SNOW_BLOCK ); + } + $level->setBlockIdAt ( $x + 3, $y + 1, $z, Block::ICE ); + $level->setBlockIdAt ( $x - 3, $y + 1, $z, Block::ICE ); + + // Diags + for($i = 1; $i <= 2; $i ++) { + $level->setBlockIdAt ( $x + 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + } + + // 2nd layer + for($i = 0; $i < 3; $i ++) { + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + } + + // Top + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 4, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + } + + // Carpets + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 2; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 1, $zz, Block::CARPET ); + } + + // Other furnitures + // Bed + $level->setBlockIdAt ( $x + 2, $y + 1, $z - 1, Block::BED_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 1, $z, Block::BED_BLOCK ); + $level->setBlockDataAt ( $x + 2, $y + 1, $z - 1, 10 ); + $level->setBlockDataAt ( $x + 2, $y + 1, $z, 2 ); + // Other + $level->setBlockIdAt ( $x - 2, $y + 1, $z + 1, Block::CRAFTING_TABLE ); + $level->setBlockIdAt ( $x - 2, $y + 1, $z, Block::REDSTONE_TORCH ); + $level->setBlockIdAt ( $x - 2, $y + 1, $z - 1, Block::FURNACE ); + break; + + // Fourth direction + case 3 : // Entrance is z- + // Ground + for($xx = $x - 3; $xx <= $x + 3; $xx ++) + for($zz = $z - 4; $zz <= $z + 3; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $y, $zz )] )) + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + // Entrance + for($i = 0; $i < 2; $i ++) { + $level->setBlockIdAt ( $x, $y, $z - 3 - $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x, $y + 3, $z - 3 - $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 1, $y + 1, $z - 3 - $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1, $y + 1, $z - 3 - $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 1, $y + 2, $z - 3 - $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1, $y + 2, $z - 3 - $i, Block::SNOW_BLOCK ); + } + + // Back + for($xx = $x - 1; $xx <= $x + 1; $xx ++) { + $level->setBlockIdAt ( $xx, $y + 1, $z + 3, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y + 2, $z + 3, Block::SNOW_BLOCK ); + } + + // Sides + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $x - 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 3, $y + 2, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3, $y + 1, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 3, $y + 2, $zz, Block::SNOW_BLOCK ); + } + $level->setBlockIdAt ( $x + 3, $y + 1, $z, Block::ICE ); + $level->setBlockIdAt ( $x - 3, $y + 1, $z, Block::ICE ); + + // Diags + for($i = 1; $i <= 2; $i ++) { + $level->setBlockIdAt ( $x + 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + $i, $z - 2, Block::SNOW_BLOCK ); + } + + // 2nd layer + for($i = 0; $i < 3; $i ++) { + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z + 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 1 + $i, $y + 3, $z - 2, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $x - 2, $y + 3, $z - 1 + $i, Block::SNOW_BLOCK ); + } + + // Top + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 4, $zz, Block::SNOW_BLOCK ); + $level->setBlockIdAt ( $xx, $y, $zz, Block::SNOW_BLOCK ); + } + + // Carpets + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 2; $zz ++) { + $level->setBlockIdAt ( $xx, $y + 1, $zz, Block::CARPET ); + } + + // Other furnitures + // Bed + $level->setBlockIdAt ( $x + 2, $y + 1, $z + 1, Block::BED_BLOCK ); + $level->setBlockIdAt ( $x + 2, $y + 1, $z, Block::BED_BLOCK ); + $level->setBlockDataAt ( $x + 2, $y + 1, $z + 1, 8 ); + $level->setBlockDataAt ( $x + 2, $y + 1, $z, 0 ); + // Other + $level->setBlockIdAt ( $x - 2, $y + 1, $z - 1, Block::CRAFTING_TABLE ); + $level->setBlockIdAt ( $x - 2, $y + 1, $z, Block::REDSTONE_TORCH ); + $level->setBlockIdAt ( $x - 2, $y + 1, $z + 1, Block::FURNACE ); + break; + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/SakuraTree.php b/src/Ad5001/BetterGen/structure/SakuraTree.php new file mode 100644 index 0000000..7861bda --- /dev/null +++ b/src/Ad5001/BetterGen/structure/SakuraTree.php @@ -0,0 +1,661 @@ + [ + 0, + 1 + ], // 0 vertical, 1 horizontal and same goes for others... + 8 => [ + 1, + 0 + ], + 9 => [ + 1, + 1 + ], + 10 => [ + 2, + 0 + ], + 11 => [ + 2, + 1 + ], + 12 => [ + 2, + 2 + ], + 13 => [ + 3, + 1 + ] + ]; + const DIAG_LEAVES = [ // Diag poses of the leaves based on the height of the tree.X relative to $lastX and Z from $lastZ + 7 => [ + [ + 4, + 4 + ], + [ + - 4, + 4 + ], + [ + 4, + - 4 + ], + [ + - 4, + - 4 + ] + ], + 8 => [ + [ + 6, + 6 + ], + [ + - 6, + 6 + ], + [ + 6, + - 6 + ], + [ + - 6, + - 6 + ] + ], + 9 => [ + [ + 6, + 6 + ], + [ + - 6, + 6 + ], + [ + 6, + - 6 + ], + [ + - 6, + - 6 + ] + ], + 10 => [ + [ + 6, + 6 + ], + [ + - 6, + 6 + ], + [ + 6, + - 6 + ], + [ + - 6, + - 6 + ] + ], + 11 => [ + [ + 7, + 7 + ], + [ + 6, + 8 + ], + [ + 8, + 6 + ], + [ + - 7, + 7 + ], + [ + - 6, + 8 + ], + [ + - 8, + 6 + ], + [ + 7, + - 7 + ], + [ + 6, + - 8 + ], + [ + 8, + - 6 + ], + [ + - 7, + - 7 + ], + [ + - 6, + - 8 + ], + [ + - 8, + - 6 + ] + ], + 12 => [ + [ + 7, + 7 + ], + [ + 6, + 8 + ], + [ + 8, + 6 + ], + [ + - 7, + 7 + ], + [ + - 6, + 8 + ], + [ + - 8, + 6 + ], + [ + 7, + - 7 + ], + [ + 6, + - 8 + ], + [ + 8, + - 6 + ], + [ + - 7, + - 7 + ], + [ + - 6, + - 8 + ], + [ + - 8, + - 6 + ] + ], + 13 => [ + [ + 7, + 7 + ], + [ + 6, + 8 + ], + [ + 8, + 6 + ], + [ + - 7, + 7 + ], + [ + - 6, + 8 + ], + [ + - 8, + 6 + ], + [ + 7, + - 7 + ], + [ + 6, + - 8 + ], + [ + 8, + - 6 + ], + [ + - 7, + - 7 + ], + [ + - 6, + - 8 + ], + [ + - 8, + - 6 + ] + ] + ]; + const ADDITIONAL_BLOCKS = [ // Blocks who aren't set to fully fill the tree. X relative to $lastX and Z from $lastZ + 7 => [ ], + 8 => [ ], + 9 => [ ], + 10 => [ ], + 11 => [ + [ + 6, + 6 + ], + [ + 7, + 6 + ], + [ + 6, + 7 + ], + [ + - 6, + 6 + ], + [ + - 7, + 6 + ], + [ + - 6, + 7 + ], + [ + 6, + - 6 + ], + [ + 7, + - 6 + ], + [ + 6, + - 7 + ], + [ + - 6, + - 6 + ], + [ + - 7, + - 6 + ], + [ + - 6, + - 7 + ] + ], + 12 => [ + [ + 6, + 6 + ], + [ + 7, + 6 + ], + [ + 6, + 7 + ], + [ + - 6, + 6 + ], + [ + - 7, + 6 + ], + [ + - 6, + 7 + ], + [ + 6, + - 6 + ], + [ + 7, + - 6 + ], + [ + 6, + - 7 + ], + [ + - 6, + - 6 + ], + [ + - 7, + - 6 + ], + [ + - 6, + - 7 + ] + ], + 13 => [ + [ + 6, + 6 + ], + [ + 7, + 6 + ], + [ + 6, + 7 + ], + [ + - 6, + 6 + ], + [ + - 7, + 6 + ], + [ + - 6, + 7 + ], + [ + 6, + - 6 + ], + [ + 7, + - 6 + ], + [ + 6, + - 7 + ], + [ + - 6, + - 6 + ], + [ + - 7, + - 6 + ], + [ + - 6, + - 7 + ] + ] + ]; + const maxPerChunk = 2; + + /* + * Constructs the class + */ + public function __construct() { + $this->trunkBlock = Block::LOG; + $this->leafBlock = Block::WOOL; + $this->leafType = 6; + $this->leaf2Type = 0; + $this->type = Wood::OAK; + } + + /* + * Builds the tree. + * @param $level \pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random $random + */ + public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + $percentage = $random->nextBoundedInt ( 100 ); + if ($percentage > 10) { + return; + } + $trunkHeight = 7 + $random->nextBoundedInt ( 7 ); + + $direction = $random->nextBoundedInt ( 3 ); // Choosing building north east west south + switch ($direction) { + case 0 : + $xDiff = 0; + $zDiff = - 1; + break; + case 1 : + $xDiff = 0; + $zDiff = 1; + break; + case 2 : + $xDiff = - 1; + $zDiff = 0; + break; + case 3 : + $xDiff = 1; + $zDiff = 0; + break; + } + list ( $vParts, $hParts ) = self::TRUNK_POS [$trunkHeight]; + + $this->setLog ( $level, $x, $y, $z ); + list ( $lastX, $lastY, $lastZ ) = [ + $x, + $y, + $z + ]; + + // Filling horisontally + if ($hParts > 0) { + for($i = 0; $i < $hParts; $i ++) { + $lastX += $xDiff * 2; + $lastY ++; + $lastZ += $zDiff * 2; + $this->setLog ( $level, $lastX - $xDiff, $lastY, $lastZ - $zDiff ); + $this->setLog ( $level, $lastX, $lastY, $lastZ ); + } + } + + // The middle block + $lastX += $xDiff; + $lastY ++; + $lastZ += $zDiff; + $this->setLog ( $level, $lastX, $lastY, $lastZ ); + + // Filling verticaly + if ($vParts > 0) { + for($i = 0; $i < $vParts; $i ++) { + $lastX += $xDiff; + $lastY += 2; + $lastZ += $zDiff; + $this->setLog ( $level, $lastX, $lastY - 1, $lastZ ); + $this->setLog ( $level, $lastX, $lastY, $lastZ ); + } + } + // Filling the top trunk. + $lastX += $xDiff; + $lastY ++; + $lastZ += $zDiff; + for($i = 0; $i < 4; $i ++) { + $this->setLog ( $level, $lastX, $lastY + $i, $lastZ ); + } + $lastY ++; + // FIlling the branches. + $branchLen2 = function ($base) { + return ceil ( $base / 2 ); + }; + + for($dir = 0; $dir < 4; $dir ++) { + switch ($dir) { + case 0 : + $xd = 0; + $zd = - 1; + break; + case 1 : + $xd = 0; + $zd = 1; + break; + case 2 : + $xd = - 1; + $zd = 0; + break; + case 3 : + $xd = 1; + $zd = 0; + break; + } + + $stickLen = round ( $trunkHeight / 3 ); + $stickLen2 = call_user_func ( $branchLen2, $stickLen ); + $totalLength = $stickLen + $stickLen2; // Length of the stick + $sideLen = $totalLength ** 2; // Side length + + // First branch part + first leave part + for($i = 1; $i < $stickLen + 1; $i ++) { + $lX1 = $lastX + ($xd * $i); + $lZ1 = $lastZ + ($zd * $i); + if ($zd !== 0) + for($x = $lX1 - $numForward; $x !== $lX1 + $numForward + 1; $x ++) { + $this->setLeave ( $level, $x, $lastY + 3, $lZ1, $random ); + } + if ($xd !== 0) + for($z = $lZ1 - $numForward; $z !== $lZ1 + $numForward + 1; $z ++) { + $this->setLeave ( $level, $lX1, $lastY + 3, $z, $random ); + } + $this->setLog ( $level, $lX1, $lastY, $lZ1 ); + } + + // Second branch part. + second leave part + $numForward = ($totalLength % 2 == 0) ? $totalLength - 1 : $totalLength; + for($i = 1; $i < $stickLen + 1; $i ++) { + $lX = $lX1 + ($xd * $i); + $lZ = $lZ1 + ($zd * $i); + if ($zd !== 0) + for($x = $lX - $numForward; $x !== $lX + $numForward + 1; $x ++) { + $this->setLeave ( $level, $x, $lastY + 2, $lZ, $random ); + } + if ($xd !== 0) + for($z = $lZ - $numForward; $z !== $lZ + $numForward + 1; $z ++) { + $this->setLeave ( $level, $lX, $lastY + 2, $z, $random ); + } + $this->setLog ( $level, $lX, $lastY + 1, $lZ ); + } + + $lX += $xd; + $lZ += $zd; + // Leaves falling from the tree forward + if ($lastZ !== $lZ) { // Z has changed, using X for setting + for($x = $lX - $numForward; $x <= $lX + $numForward; $x ++) { + $numDown = $random->nextBoundedInt ( 3 ) + 1; + for($y = $lastY + 1; $y > $lastY - $numDown; $y --) + $this->setLeave ( $level, $x, $y, $lZ, $random ); + } + } else { // Z have stayed, X has changed + for($z = $lZ - $numForward; $z <= $lZ + $numForward; $z ++) { + $numDown = $random->nextBoundedInt ( 3 ) + 1; + for($y = $lastY + 1; $y > $lastY + 1 - $numDown; $y --) + $this->setLeave ( $level, $lX, $y, $z, $random ); + } + } + + // continue; + + switch ($dir + 1) { + case 4 : + $xd2 = 0; + $zd2 = - 1; + break; + case 1 : + $xd2 = 0; + $zd2 = 1; + break; + case 2 : + $xd2 = - 1; + $zd2 = 0; + break; + case 3 : + $xd2 = 1; + $zd2 = 0; + break; + } + + // Leaves falling from the tree diagonaly + foreach ( self::DIAG_LEAVES [$trunkHeight] as $pos ) { + $numDown = $random->nextBoundedInt ( 3 ) + 1; + for($y = $lastY + 1; $y > $lastY - $numDown; $y --) + $this->setLeave ( $level, $lastX + $pos [0], $y, $lastZ + $pos [1], $random ); + } + + // Additional leaves + foreach ( self::ADDITIONAL_BLOCKS [$trunkHeight] as $pos ) { + $this->setLeave ( $level, $lastX + $pos [0], $lastY + 2, $lastZ + $pos [1], $random ); + } + } + } + + /* + * Fills a log at. + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + */ + public function setLog(ChunkManager $level, $x, $y, $z) { + $level->setBlockIdAt ( $x, $y, $z, $this->trunkBlock ); + $level->setBlockDataAt ( $x, $y, $z, $this->type ); + } + + /* + * Fills a leave at. + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + */ + public function setLeave(ChunkManager $level, $x, $y, $z, Random $random) { + $data = [ + $this->leafType, + $this->leaf2Type + ] [( int ) $random->nextBoolean ()]; + $level->setBlockIdAt ( $x, $y, $z, $this->leafBlock ); + $level->setBlockDataAt ( $x, $y, $z, $data ); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/SugarCane.php b/src/Ad5001/BetterGen/structure/SugarCane.php new file mode 100644 index 0000000..68e0855 --- /dev/null +++ b/src/Ad5001/BetterGen/structure/SugarCane.php @@ -0,0 +1,52 @@ +totalHeight = 1 + $random->nextBoundedInt ( 3 ); + $below = $level->getBlockIdAt ( $x, $y - 1, $z ); + if (($below == Block::SAND || $below == Block::GRASS) && ($level->getBlockIdAt ( $x + 1, $y - 1, $z ) == Block::WATER || $level->getBlockIdAt ( $x - 1, $y - 1, $z ) == Block::WATER || $level->getBlockIdAt ( $x, $y - 1, $z + 1 ) == Block::WATER || $level->getBlockIdAt ( $x, $y - 1, $z - 1 ) == Block::WATER)) { + return true; + } + return false; + } + + /* + * Places a cactus + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + */ + public function placeObject(ChunkManager $level, int $x, int $y, int $z) { + for($yy = 0; $yy < $this->totalHeight; $yy ++) { + if ($level->getBlockIdAt ( $x, $y + $yy, $z ) != Block::AIR) { + return; + } + $level->setBlockIdAt ( $x, $y + $yy, $z, Block::SUGARCANE_BLOCK ); + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/Temple.php b/src/Ad5001/BetterGen/structure/Temple.php new file mode 100644 index 0000000..cbed7da --- /dev/null +++ b/src/Ad5001/BetterGen/structure/Temple.php @@ -0,0 +1,907 @@ + true, + 6 => true, + 17 => true, + 18 => true, + Block::DANDELION => true, + Block::POPPY => true, + Block::SNOW_LAYER => true, + Block::LOG2 => true, + Block::LEAVES2 => true, + Block::CACTUS => true + ]; + protected $directions = [ + [ + 1, + 1 + ], + [ + 1, + - 1 + ], + [ + - 1, + - 1 + ], + [ + - 1, + 1 + ] + ]; + + /* + * Checks if a temple is placeable + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + * @return bool + */ + public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) { + $this->direction = $random->nextBoundedInt ( 4 ); + for($xx = $x - 10; $xx <= $x + 10; $xx ++) + for($yy = $y + 1; $yy <= $y + 11; $yy ++) + for($zz = $z - 10; $zz <= $z + 10; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + return true; + } + + /* + * Places a temple + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + */ + public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + // Clearing space... + BuildingUtils::fill ( $level, new Vector3 ( $x + 10, $y + 1, $z + 10 ), new Vector3 ( $x - 10, $y + 2, $z - 10 ), Block::get ( Block::AIR ) ); + // First, build a pyramid. + $this->level = $level; + $firstPos = new Vector3 ( $x + 10, $y, $z + 10 ); + $sndPos = new Vector3 ( $x - 10, $y, $z - 10 ); + for($i = 0; $i <= 9; $i ++) { + // Building sides + BuildingUtils::walls ( $level, $firstPos, $sndPos, Block::get ( Block::SANDSTONE ) ); + + // Next floor + $firstPos->x --; + $firstPos->z --; + $firstPos->y = $y + $i; + $sndPos->x ++; + $sndPos->z ++; + $sndPos->y = $y + $i; + } + // Floors + for($xx = $x + 9; $xx >= $x - 9; $xx --) + for($zz = $z + 9; $zz >= $z - 9; $zz --) + $this->placeBlock ( $xx, $y, $zz ); + for($xx = $x + 5; $xx >= $x - 5; $xx --) + for($zz = $z + 5; $zz >= $z - 5; $zz --) + $this->placeBlock ( $xx, $y + 4, $zz ); + + // Creating hole + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($yy = $y - 11; $yy <= $y + 4; $yy ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeBlock ( $xx, $yy, $zz, 0 ); + + // Floor patern + foreach ( $this->directions as $dir ) { + // Building pillar + for($yy = $y + 1; $yy <= $y + 3; $yy ++) + $this->placeBlock ( $x + ($dir [0] * 2), $yy, $z + ($dir [1] * 2), Block::SANDSTONE, 2 ); + // Orange hardened clay + $this->placeBlock ( $x + $dir [0], $y, $z + $dir [1], Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + ($dir [0] * 2), $y, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + ($dir [0] * 3), $y, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y, $z + ($dir [1] * 2), Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y, $z + ($dir [1] * 3), Block::STAINED_HARDENED_CLAY, 1 ); + + // Sandstone + $this->placeBlock ( $x + $dir [0], $y, $z ); + $this->placeBlock ( $x, $y, $z + $dir [1] ); + } + // Blue hardened clay (center) + $this->placeBlock ( $x, $y, $z, Block::STAINED_HARDENED_CLAY, 11 ); + // Hole walls + BuildingUtils::walls ( $level, new Vector3 ( $x - 2, $y, $z - 2 ), new Vector3 ( $x + 2, $y - 8, $z + 2 ), Block::get ( Block::SANDSTONE ) ); + + // Last step like this + for($xx = $x - 2; $xx <= $x + 2; $xx ++) { + $this->placeBlock ( $xx, $y - 9, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $xx, $y - 9, $z + 2, Block::SANDSTONE, 2 ); + } + for($zz = $z - 2; $zz <= $z + 2; $zz ++) { + $this->placeBlock ( $x - 2, $y - 9, $zz, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y - 9, $zz, Block::SANDSTONE, 2 ); + } + + foreach ( self::THREE_DIAGS as $diagPos ) { + $this->placeBlock ( $x + $diagPos [0], $y - 10, $z + $diagPos [1], Block::SANDSTONE, 1 ); + $this->placeBlock ( $x + $diagPos [0], $y - 11, $z + $diagPos [1], Block::SANDSTONE, 2 ); + } + + // Floor + TNT + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + $this->placeBlock ( $xx, $y - 12, $zz, Block::SANDSTONE, 2 ); + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeBlock ( $xx, $y - 13, $zz, Block::TNT ); + $this->placeBlock ( $x, $y - 11, $z, Block::STONE_PRESSURE_PLATE ); + + // Chests + LootTable::buildLootTable ( new Vector3 ( $x, $y - 11, $z + 2 ), LootTable::LOOT_DESERT_TEMPLE, $random ); + LootTable::buildLootTable ( new Vector3 ( $x, $y - 11, $z - 2 ), LootTable::LOOT_DESERT_TEMPLE, $random ); + LootTable::buildLootTable ( new Vector3 ( $x + 2, $y - 11, $z ), LootTable::LOOT_DESERT_TEMPLE, $random ); + LootTable::buildLootTable ( new Vector3 ( $x - 2, $y - 11, $z ), LootTable::LOOT_DESERT_TEMPLE, $random ); + + // Entrance is a rectangular parallelepiped + switch ($this->direction) { + case self::DIRECTION_PLUSX : // x+ (0) + // Building towers. + $this->placeTower ( $x + 8, $y, $z + 8, self::DIRECTION_PLUSX, self::DIRECTION_PLUSZ ); + $this->placeTower ( $x + 8, $y, $z - 8, self::DIRECTION_PLUSX, self::DIRECTION_MINZ ); + // Creating rectangular parallelepiped of sandstone. + BuildingUtils::fill ( $level, new Vector3 ( $x + 6, $y + 1, $z - 6 ), new Vector3 ( $x + 9, $y + 4, $z + 6 ), Block::get ( Block::SANDSTONE ) ); + // Creating a path to the entrance + BuildingUtils::fill ( $level, new Vector3 ( $x + 6, $y + 1, $z - 1 ), new Vector3 ( $x + 9, $y + 4, $z + 1 ), Block::get ( Block::AIR ) ); + // Creating path to towers. + for($yy = $y + 1; $yy <= $y + 2; $yy ++) + for($zz = $z - 6; $zz <= $z + 6; $zz ++) + $this->placeBlock ( $x + 8, $yy, $zz, 0 ); + // Door additional blocks + for($yy = $y + 1; $yy <= $y + 4; $yy ++) { + $this->placeBlock ( $x + 6, $yy, $z - 2 ); + $this->placeBlock ( $x + 6, $yy, $z + 2 ); + // Polished entrance + $this->placeBlock ( $x + 9, $yy, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 9, $yy, $z - 1, Block::SANDSTONE, 2 ); + // Starting entrance structure + $this->placeBlock ( $x + 10, $yy, $z - 2 ); + $this->placeBlock ( $x + 10, $yy, $z + 2 ); + } + // Finishing entrance structure + $this->placeBlock ( $x + 9, $y + 3, $z, Block::SANDSTONE, 2 ); + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + $this->placeBlock ( $x + 10, $y + 4, $zz, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 10, $y + 5, $z, Block::SANDSTONE, 1 ); + $this->placeBlock ( $x + 10, $y + 5, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 10, $y + 5, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 10, $y + 5, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 10, $y + 5, $z + 2, Block::SANDSTONE, 2 ); + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeBlock ( $x + 10, $y + 6, $zz, Block::SANDSTONE, 2 ); + for($xx = $x + 6; $xx <= $x + 9; $xx ++) + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + $this->placeBlock ( $xx, $y + 4, $zz ); + break; + + case self::DIRECTION_MINX : // x- (1) + // Building towers. + $this->placeTower ( $x - 8, $y, $z + 8, self::DIRECTION_MINX, self::DIRECTION_PLUSZ ); + $this->placeTower ( $x - 8, $y, $z - 8, self::DIRECTION_MINX, self::DIRECTION_MINZ ); + // Creating rectangular parallelepiped of sandstone. + for($xx = $x - 6; $xx >= $x - 9; $xx --) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 6; $zz <= $z + 6; $zz ++) + $this->placeBlock ( $xx, $yy, $zz ); + // Creating a path to the entrance + for($xx = $x - 6; $xx >= $x - 9; $xx --) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeBlock ( $xx, $yy, $zz, 0 ); + // Creating path to towers. + for($yy = $y + 1; $yy <= $y + 2; $yy ++) + for($zz = $z - 6; $zz <= $z + 6; $zz ++) + $this->placeBlock ( $x - 8, $yy, $zz, 0 ); + // Door additional blocks + for($yy = $y + 1; $yy <= $y + 4; $yy ++) { + $this->placeBlock ( $x - 6, $yy, $z - 2 ); + $this->placeBlock ( $x - 6, $yy, $z + 2 ); + // Polished entrance + $this->placeBlock ( $x - 9, $yy, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 9, $yy, $z - 1, Block::SANDSTONE, 2 ); + // Starting entrance structure + $this->placeBlock ( $x - 10, $yy, $z - 2 ); + $this->placeBlock ( $x - 10, $yy, $z + 2 ); + } + // Finishing entrance structure + $this->placeBlock ( $x - 9, $y + 3, $z, Block::SANDSTONE, 2 ); + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + $this->placeBlock ( $x - 10, $y + 4, $zz, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 10, $y + 5, $z, Block::SANDSTONE, 1 ); + $this->placeBlock ( $x - 10, $y + 5, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 10, $y + 5, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 10, $y + 5, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 10, $y + 5, $z + 2, Block::SANDSTONE, 2 ); + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeBlock ( $x - 10, $y + 6, $zz, Block::SANDSTONE, 2 ); + for($xx = $x - 6; $xx >= $x - 9; $xx --) + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + $this->placeBlock ( $xx, $y + 4, $zz ); + break; + + case self::DIRECTION_PLUSZ : // z+ (2) + // Building towers. + $this->placeTower ( $x + 8, $y, $z + 8, self::DIRECTION_PLUSZ, self::DIRECTION_PLUSX ); + $this->placeTower ( $x - 8, $y, $z + 8, self::DIRECTION_PLUSZ, self::DIRECTION_MINX ); + // Creating rectangular parallelepiped of sandstone. + BuildingUtils::fill ( $level, new Vector3 ( $x - 6, $y + 1, $z + 6 ), new Vector3 ( $x + 6, $y + 4, $z + 9 ), Block::get ( Block::SANDSTONE ) ); + // Creating a path to the entrance + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($yy = $y + 1; $yy <= $y + 4; $yy ++) + for($zz = $z + 6; $zz <= $z + 9; $zz ++) + $this->placeBlock ( $xx, $yy, $zz, 0 ); + // Creating path to towers. + BuildingUtils::fill ( $level, new Vector3 ( $x - 1, $y + 1, $z + 6 ), new Vector3 ( $x + 1, $y + 4, $z + 9 ), Block::get ( Block::AIR ) ); + // Door additional blocks + for($yy = $y + 1; $yy <= $y + 4; $yy ++) { + $this->placeBlock ( $x - 2, $yy, $z + 6 ); + $this->placeBlock ( $x + 2, $yy, $z + 6 ); + // Polished entrance + $this->placeBlock ( $x + 1, $yy, $z + 9, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $yy, $z + 9, Block::SANDSTONE, 2 ); + // Starting entrance structure + $this->placeBlock ( $x + 2, $yy, $z + 10 ); + $this->placeBlock ( $x - 2, $yy, $z + 10 ); + } + // Finishing entrance structure + $this->placeBlock ( $x, $y + 3, $z + 9, Block::SANDSTONE, 2 ); + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + $this->placeBlock ( $xx, $y + 4, $z + 10, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 5, $z + 10, Block::SANDSTONE, 1 ); + $this->placeBlock ( $x - 1, $y + 5, $z + 10, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 5, $z + 10, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 5, $z + 10, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 5, $z + 10, Block::SANDSTONE, 2 ); + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + $this->placeBlock ( $xx, $y + 6, $z + 10, Block::SANDSTONE, 2 ); + for($zz = $z + 6; $zz <= $z + 9; $zz ++) + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + $this->placeBlock ( $xx, $y + 4, $zz ); + break; + + case self::DIRECTION_MINZ : // z- (3) + // Building towers. + $this->placeTower ( $x + 8, $y, $z - 8, self::DIRECTION_MINZ, self::DIRECTION_PLUSX ); + $this->placeTower ( $x - 8, $y, $z - 8, self::DIRECTION_MINZ, self::DIRECTION_MINX ); + // Creating rectangular parallelepiped of sandstone. + BuildingUtils::fill ( $level, new Vector3 ( $x - 6, $y + 1, $z - 6 ), new Vector3 ( $x + 6, $y + 4, $z - 9 ), Block::get ( Block::SANDSTONE ) ); + // Creating a path to the entrance + BuildingUtils::fill ( $level, new Vector3 ( $x - 1, $y + 1, $z - 6 ), new Vector3 ( $x + 1, $y + 4, $z - 9 ), Block::get ( Block::AIR ) ); + // Creating path to towers. + for($yy = $y + 1; $yy <= $y + 2; $yy ++) + for($xx = $x - 6; $xx <= $x + 6; $xx ++) + $this->placeBlock ( $xx, $yy, $z - 8, 0 ); + // Door additional blocks + for($yy = $y + 1; $yy <= $y + 4; $yy ++) { + $this->placeBlock ( $x - 2, $yy, $z - 6 ); + $this->placeBlock ( $x + 2, $yy, $z - 6 ); + // Polished entrance + $this->placeBlock ( $x + 1, $yy, $z - 9, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $yy, $z - 9, Block::SANDSTONE, 2 ); + // Starting entrance structure + $this->placeBlock ( $x + 2, $yy, $z - 10 ); + $this->placeBlock ( $x - 2, $yy, $z - 10 ); + } + // Finishing entrance structure + $this->placeBlock ( $x, $y + 3, $z - 9, Block::SANDSTONE, 2 ); + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + $this->placeBlock ( $xx, $y + 4, $z - 10, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 5, $z - 10, Block::SANDSTONE, 1 ); + $this->placeBlock ( $x - 1, $y + 5, $z - 10, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 5, $z - 10, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 5, $z - 10, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 5, $z - 10, Block::SANDSTONE, 2 ); + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + $this->placeBlock ( $xx, $y + 6, $z - 10, Block::SANDSTONE, 2 ); + for($zz = $z - 6; $zz >= $z - 9; $zz --) + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + $this->placeBlock ( $xx, $y + 4, $zz ); + break; + } + } + + /* + * Places a slab + * @param $x int + * @param $y int + * @param $z int + * @return void + */ + protected function placeSlab($x, $y, $z) { + $this->level->setBlockIdAt ( $x, $y, $z, 44 ); + $this->level->setBlockDataAt ( $x, $y, $z, 1 ); + } + + /* + * Places a slab + * @param $x int + * @param $y int + * @param $z int + * @param $id int + * @param $meta int + * @return void + */ + protected function placeBlock($x, $y, $z, $id = Block::SANDSTONE, $meta = 0) { + $this->level->setBlockIdAt ( $x, $y, $z, $id ); + $this->level->setBlockDataAt ( $x, $y, $z, $meta ); + } + + /* + * Places one of the towers. Out is inversed $direction1, stairs come from inversed $direction2 to $direction2, patterns are on $direction1 and $direction2 + * @param $x int + * @param $y int + * @param $z int + * @param $direction1 int + * @param $direction2 int + * @return void + */ + public function placeTower($x, $y, $z, $direction1 = self::DIRECTION_PLUSX, $direction2 = self::DIRECTION_PLUSZ) { + BuildingUtils::walls ( $this->level, new Vector3 ( $x + 2, $y, $z + 2 ), new Vector3 ( $x - 2, $y + 8, $z - 2 ), Block::get ( Block::SANDSTONE ) ); + switch ($direction1) { + case self::DIRECTION_PLUSX : // x+ (0) + // Stairs + switch ($direction2) { + case self::DIRECTION_PLUSZ : + for($zz = $z + 1; $zz >= $z; $zz --) { + $this->placeBlock ( $x - 1, $y + 1, $zz ); + $this->placeBlock ( $x - 1, $y + 2, $zz ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 2 ); + $this->placeBlock ( $x, $y + 1, $z + 1 ); + $this->placeSlab ( $x, $y + 2, $z + 1 ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 9, $y + 5, $z - 4 ), new Vector3 ( $x - 7, $y + 7, $z - 5 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 8, $y + 5, $z - 4 ), new Vector3 ( $x - 8, $y + 6, $z - 5 ), Block::get ( Block::AIR ) ); + break; + case self::DIRECTION_MINZ : + for($zz = $z - 1; $zz <= $z; $zz ++) { + $this->placeBlock ( $x - 1, $y + 1, $zz ); + $this->placeBlock ( $x - 1, $y + 2, $zz ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 3 ); + $this->placeBlock ( $x, $y + 1, $z - 1 ); + $this->placeSlab ( $x, $y + 2, $z - 1 ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + break; + + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 9, $y + 5, $z + 4 ), new Vector3 ( $x - 7, $y + 7, $z + 5 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 8, $y + 5, $z + 4 ), new Vector3 ( $x - 8, $y + 6, $z + 5 ), Block::get ( Block::AIR ) ); + } + + // Finishing stairs system + $this->placeBlock ( $x - 2, $y + 3, $z, Block::SANDSTONE_STAIRS, 1 ); + $this->placeBlock ( $x - 3, $y + 4, $z, Block::SANDSTONE_STAIRS, 1 ); + $this->placeBlock ( $x - 2, $y + 4, $z, Block::AIR ); + $this->placeBlock ( $x - 2, $y + 5, $z, Block::AIR ); + $this->placeBlock ( $x - 2, $y + 6, $z, Block::AIR ); + // Making path from stairs to first floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 4, $y, $z + 2 ), new Vector3 ( $x - 9, $y + 4, $z - 2 ), Block::get ( Block::SANDSTONE ) ); + + // Other side pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x + 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + break; + + case self::DIRECTION_MINX : // x- (1) + // Stairs + switch ($direction2) { + case self::DIRECTION_PLUSZ : + for($zz = $z + 1; $zz >= $z; $zz --) { + $this->placeBlock ( $x + 1, $y + 1, $zz ); + $this->placeBlock ( $x + 1, $y + 2, $zz ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 2 ); + $this->placeBlock ( $x, $y + 1, $z + 1 ); + $this->placeSlab ( $x, $y + 2, $z + 1 ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 9, $y + 5, $z - 4 ), new Vector3 ( $x + 7, $y + 7, $z - 5 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 8, $y + 5, $z - 4 ), new Vector3 ( $x + 8, $y + 6, $z - 5 ), Block::get ( Block::AIR ) ); + break; + case self::DIRECTION_MINZ : + for($zz = $z - 1; $zz <= $z; $zz ++) { + $this->placeBlock ( $x + 1, $y + 1, $zz ); + $this->placeBlock ( $x + 1, $y + 2, $zz ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 3 ); + $this->placeBlock ( $x, $y + 1, $z - 1 ); + $this->placeSlab ( $x, $y + 2, $z - 1 ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 6, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 6, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 6, $z - 2, Block::SANDSTONE, 2 ); + + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 9, $y + 5, $z + 4 ), new Vector3 ( $x + 7, $y + 7, $z + 5 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 8, $y + 5, $z + 4 ), new Vector3 ( $x + 8, $y + 6, $z + 5 ), Block::get ( Block::AIR ) ); + break; + } + + // Finishing stairs system + $this->placeBlock ( $x + 2, $y + 3, $z, Block::SANDSTONE_STAIRS, 0 ); + $this->placeBlock ( $x + 3, $y + 4, $z, Block::SANDSTONE_STAIRS, 0 ); + $this->placeBlock ( $x + 2, $y + 4, $z, Block::AIR ); + $this->placeBlock ( $x + 2, $y + 5, $z, Block::AIR ); + $this->placeBlock ( $x + 2, $y + 6, $z, Block::AIR ); + // Making path from stairs to first floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 4, $y, $z + 2 ), new Vector3 ( $x + 9, $y + 4, $z - 2 ), Block::get ( Block::SANDSTONE ) ); + + // Other side pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + break; + + case self::DIRECTION_PLUSZ : // z+ (2) + // Stairs + switch ($direction2) { + case self::DIRECTION_PLUSX : + for($xx = $x + 1; $xx >= $x; $xx --) { + $this->placeBlock ( $xx, $y + 1, $z - 1 ); + $this->placeBlock ( $xx, $y + 2, $z - 1 ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 0 ); + $this->placeBlock ( $x + 1, $y + 1, $z ); + $this->placeSlab ( $x + 1, $y + 2, $z ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x + 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 4, $y + 5, $z - 9 ), new Vector3 ( $x - 5, $y + 7, $z - 7 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 4, $y + 5, $z - 8 ), new Vector3 ( $x - 5, $y + 6, $z - 8 ), Block::get ( Block::AIR ) ); + break; + case self::DIRECTION_MINX : + for($xx = $x - 1; $xx <= $x; $xx ++) { + $this->placeBlock ( $xx, $y + 1, $z - 1 ); + $this->placeBlock ( $xx, $y + 2, $z - 1 ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 1 ); + $this->placeBlock ( $x - 1, $y + 1, $z ); + $this->placeSlab ( $x - 1, $y + 2, $z ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 4, $y + 5, $z - 9 ), new Vector3 ( $x + 5, $y + 7, $z - 7 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 4, $y + 5, $z - 8 ), new Vector3 ( $x + 5, $y + 6, $z - 8 ), Block::get ( Block::AIR ) ); + break; + } + + // Finishing stairs system + $this->placeBlock ( $x, $y + 3, $z - 2, Block::SANDSTONE_STAIRS, 3 ); + $this->placeBlock ( $x, $y + 4, $z - 3, Block::SANDSTONE_STAIRS, 3 ); + $this->placeBlock ( $x, $y + 4, $z - 2, Block::AIR ); + $this->placeBlock ( $x, $y + 5, $z - 2, Block::AIR ); + $this->placeBlock ( $x, $y + 6, $z - 2, Block::AIR ); + // Making path from stairs to first floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 2, $y, $z - 4 ), new Vector3 ( $x - 2, $y + 4, $z - 9 ), Block::get ( Block::SANDSTONE ) ); + + // Other side pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + $h, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z + 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z + 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 7, $z + 2, Block::SANDSTONE, 2 ); + break; + + case self::DIRECTION_MINZ : // z- (3) + // Stairs + switch ($direction2) { + case self::DIRECTION_PLUSX : + for($xx = $x + 1; $xx >= $x; $xx --) { + $this->placeBlock ( $xx, $y + 1, $z + 1 ); + $this->placeBlock ( $xx, $y + 2, $z + 1 ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 0 ); + $this->placeBlock ( $x + 1, $y + 1, $z ); + $this->placeSlab ( $x + 1, $y + 2, $z ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x + 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 4, $y + 5, $z + 9 ), new Vector3 ( $x - 5, $y + 7, $z + 7 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x - 4, $y + 5, $z + 8 ), new Vector3 ( $x - 5, $y + 6, $z + 8 ), Block::get ( Block::AIR ) ); + break; + case self::DIRECTION_MINX : + for($xx = $x - 1; $xx <= $x; $xx ++) { + $this->placeBlock ( $xx, $y + 1, $z + 1 ); + $this->placeBlock ( $xx, $y + 2, $z + 1 ); + } + $this->placeBlock ( $x, $y + 1, $z, Block::SANDSTONE_STAIRS, 1 ); + $this->placeBlock ( $x - 1, $y + 1, $z ); + $this->placeSlab ( $x - 1, $y + 2, $z ); + // Pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x - 2, $y + $h, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + $h, $z, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 2, $y + 6, $z - 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 6, $z + 1, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 2, $y + 7, $z - 1, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 2, $y + 7, $z + 1, Block::SANDSTONE, 2 ); + // Building entrance to second floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 4, $y + 5, $z + 9 ), new Vector3 ( $x + 5, $y + 7, $z + 7 ), Block::get ( Block::SANDSTONE, 2 ) ); + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 4, $y + 5, $z + 8 ), new Vector3 ( $x + 5, $y + 6, $z + 8 ), Block::get ( Block::AIR ) ); + break; + } + + // Finishing stairs system + $this->placeBlock ( $x, $y + 3, $z + 2, Block::SANDSTONE_STAIRS, 2 ); + $this->placeBlock ( $x, $y + 4, $z + 3, Block::SANDSTONE_STAIRS, 2 ); + $this->placeBlock ( $x, $y + 4, $z + 2, Block::AIR ); + $this->placeBlock ( $x, $y + 5, $z + 2, Block::AIR ); + $this->placeBlock ( $x, $y + 6, $z + 2, Block::AIR ); + // Making path from stairs to first floor. + BuildingUtils::fill ( $this->level, new Vector3 ( $x + 2, $y, $z + 4 ), new Vector3 ( $x - 2, $y + 4, $z + 9 ), Block::get ( Block::SANDSTONE ) ); + + // Other side pattern + foreach ( [ + 1, + 2, + 4 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + } + foreach ( [ + 3, + 5 + ] as $h ) { + $this->placeBlock ( $x + 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + $h, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + $h, $z - 2, Block::SANDSTONE, 1 ); + } + $this->placeBlock ( $x - 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x + 1, $y + 6, $z - 2, Block::STAINED_HARDENED_CLAY, 1 ); + $this->placeBlock ( $x - 1, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + $this->placeBlock ( $x + 1, $y + 7, $z - 2, Block::SANDSTONE, 2 ); + break; + } + + // Making top + BuildingUtils::top ( $this->level, new Vector3 ( $x - 1, $y + 9, $z - 1 ), new Vector3 ( $x + 1, $y, $z + 1 ), Block::get ( Block::SANDSTONE ) ); + $this->placeBlock ( $x - 2, $y + 9, $z, Block::SANDSTONE_STAIRS, 0 ); + $this->placeBlock ( $x + 2, $y + 9, $z, Block::SANDSTONE_STAIRS, 1 ); + $this->placeBlock ( $x, $y + 9, $z - 2, Block::SANDSTONE_STAIRS, 2 ); + $this->placeBlock ( $x, $y + 9, $z + 2, Block::SANDSTONE_STAIRS, 3 ); + } + + /* + * Inverses a direction + * @param $direction int + * @return int + */ + protected function getInversedDirection(int $direction): int { + switch ($direction) { + case self::DIRECTION_PLUSX : // x+ (0) + return self::DIRECTION_MINX; + break; + case self::DIRECTION_MINX : // x- (1) + return self::DIRECTION_PLUSX; + break; + case self::DIRECTION_PLUSZ : // z+ (2) + return self::DIRECTION_MINZ; + break; + case self::DIRECTION_MINZ : // z- (3) + return self::DIRECTION_PLUSZ; + break; + default : + return - 1; + break; + } + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/structure/Well.php b/src/Ad5001/BetterGen/structure/Well.php new file mode 100644 index 0000000..af12995 --- /dev/null +++ b/src/Ad5001/BetterGen/structure/Well.php @@ -0,0 +1,130 @@ + true, + 6 => true, + 17 => true, + 18 => true, + Block::DANDELION => true, + Block::POPPY => true, + Block::SNOW_LAYER => true, + Block::LOG2 => true, + Block::LEAVES2 => true, + Block::CACTUS => true + ]; + protected $directions = [ + [ + 1, + 1 + ], + [ + 1, + - 1 + ], + [ + - 1, + - 1 + ], + [ + - 1, + 1 + ] + ]; + + /* + * Checks if a well is placeable + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + * @return bool + */ + public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random) { + for($xx = $x - 2; $xx <= $x + 2; $xx ++) + for($yy = $y; $yy <= $y + 3; $yy ++) + for($zz = $z - 2; $zz <= $z + 2; $zz ++) + if (! isset ( $this->overridable [$level->getBlockIdAt ( $xx, $yy, $zz )] )) + return false; + return true; + } + + /* + * Places a well + * @param $level pocketmine\level\ChunkManager + * @param $x int + * @param $y int + * @param $z int + * @param $random pocketmine\utils\Random + */ + public function placeObject(ChunkManager $level, $x, $y, $z, Random $random) { + $this->level = $level; + foreach ( $this->directions as $direction ) { + // Building pillard + for($yy = $y; $yy < $y + 3; $yy ++) + $this->placeBlock ( $x + $direction [0], $yy, $z + $direction [1], Block::SANDSTONE ); + + // Building corners + $this->placeBlock ( $x + ($direction [0] * 2), $y, $z + $direction [1], Block::SANDSTONE ); + $this->placeBlock ( $x + $direction [0], $y, $z + ($direction [1] * 2), Block::SANDSTONE ); + $this->placeBlock ( $x + ($direction [0] * 2), $y, $z + ($direction [1] * 2), Block::SANDSTONE ); + + // Building slabs on the sides. Places two times due to all directions. + $this->placeSlab ( $x + ($direction [0] * 2), $y, $z ); + $this->placeSlab ( $x, $y, $z + ($direction [1] * 2) ); + + // Placing water.Places two times due to all directions. + $this->placeBlock ( $x + $direction [0], $y, $z, Block::WATER ); + $this->placeBlock ( $x, $y, $z + $direction [1], Block::WATER ); + } + + // Finitions + for($xx = $x - 1; $xx <= $x + 1; $xx ++) + for($zz = $z - 1; $zz <= $z + 1; $zz ++) + $this->placeSlab ( $xx, $y + 3, $zz ); + $this->placeSlab ( $x, $y + 3, $z, Block::SANDSTONE ); + $this->placeSlab ( $x, $y, $z, Block::WATER ); + } + + /* + * Places a slab + * @param $x int + * @param $y int + * @param $z int + * @return void + */ + public function placeSlab($x, $y, $z) { + $this->level->setBlockIdAt ( $x, $y, $z, 44 ); + $this->level->setBlockDataAt ( $x, $y, $z, 1 ); + } + + /* + * Places a slab + * @param $x int + * @param $y int + * @param $z int + * @param $id int + * @return void + */ + public function placeBlock($x, $y, $z, $id) { + $this->level->setBlockIdAt ( $x, $y, $z, $id ); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php b/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php new file mode 100644 index 0000000..2881fbc --- /dev/null +++ b/src/Ad5001/BetterGen/tasks/ChestGenerateTask.php @@ -0,0 +1,44 @@ +block = $block; + $this->pos = $pos; + $this->item = $item; + } + + /* + * Runs when the delay comes + */ + public function onRun($currentTick) { + $this->block->place($this->item, $this->pos->getLevel()->getBlock($this->pos), $this->block, 0, 0, 0, 0); + $inv = $this->pos->getLevel()->getTile($this->pos); + LootTable::fillChest($inv->getInventory(), $this->pos); + } +} \ No newline at end of file diff --git a/src/Ad5001/BetterGen/utils/BuildingUtils.php b/src/Ad5001/BetterGen/utils/BuildingUtils.php new file mode 100644 index 0000000..1677ec6 --- /dev/null +++ b/src/Ad5001/BetterGen/utils/BuildingUtils.php @@ -0,0 +1,188 @@ +x; $x >= $pos2->x; $x --) + for($y = $pos1->y; $y >= $pos2->y; $y --) + for($z = $pos1->z; $z >= $pos2->z; $z --) { + $level->setBlockIdAt ( $x, $y, $z, $block->getId () ); + $level->setBlockDataAt ( $x, $y, $z, $block->getDamage () ); + } + } + + /* + * Fills an area by custom filling + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $call callback + * @param $params array + * @return void + */ + public static function fillCallback(Vector3 $pos1, Vector3 $pos2, callable $call, ...$params) { + list ( $pos1, $pos2 ) = self::minmax ( $pos1, $pos2 ); + for($x = $pos1->x; $x >= $pos2->x; $x --) + for($y = $pos1->y; $y >= $pos2->y; $y --) + for($z = $pos1->z; $z >= $pos2->z; $z --) { + call_user_func ( $call, new Vector3 ( $x, $y, $z ), $params ); + } + } + + /* + * Creates walls + * @param $level pocketmine\level\ChunkManager + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $block pocketmine\block\Block + * @return void + */ + public static function walls(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { + list ( $pos1, $pos2 ) = self::minmax ( $pos1, $pos2 ); + for($y = $pos1->y; $y >= $pos2->y; $y --) { + for($x = $pos1->x; $x >= $pos2->x; $x --) { + $level->setBlockIdAt ( $x, $y, $pos1->z, $block->getId () ); + $level->setBlockDataAt ( $x, $y, $pos1->z, $block->getDamage () ); + $level->setBlockIdAt ( $x, $y, $pos2->z, $block->getId () ); + $level->setBlockDataAt ( $x, $y, $pos2->z, $block->getDamage () ); + } + for($z = $pos1->z; $z >= $pos2->z; $z --) { + $level->setBlockIdAt ( $pos1->x, $y, $z, $block->getId () ); + $level->setBlockDataAt ( $pos1->x, $y, $z, $block->getDamage () ); + $level->setBlockIdAt ( $pos2->x, $y, $z, $block->getId () ); + $level->setBlockDataAt ( $pos2->x, $y, $z, $block->getDamage () ); + } + } + } + + /* + * Creates the top of a structure + * @param $level pocketmine\level\ChunkManager + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $block pocketmine\block\Block + * @return void + */ + public static function top(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { + list ( $pos1, $pos2 ) = self::minmax ( $pos1, $pos2 ); + for($x = $pos1->x; $x >= $pos2->x; $x --) + for($z = $pos1->z; $z >= $pos2->z; $z --) { + $level->setBlockIdAt ( $x, $pos1->y, $z, $block->getId () ); + $level->setBlockDataAt ( $x, $pos1->y, $z, $block->getDamage () ); + } + } + + /* + * Creates all corners from positions. Used for Mineshaft. + * @param $level pocketmine\level\ChunkManager + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $block pocketmine\block\Block + * @return void + */ + public static function corners(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { + list ( $pos1, $pos2 ) = self::minmax ( $pos1, $pos2 ); + for($y = $pos1->y; $y >= $pos2->y; $y --) { + $level->setBlockIdAt ( $pos1->x, $y, $pos1->z, $block->getId () ); + $level->setBlockDataAt ( $pos1->x, $y, $pos1->z, $block->getDamage () ); + $level->setBlockIdAt ( $pos2->x, $y, $pos1->z, $block->getId () ); + $level->setBlockDataAt ( $pos2->x, $y, $pos1->z, $block->getDamage () ); + $level->setBlockIdAt ( $pos1->x, $y, $pos2->z, $block->getId () ); + $level->setBlockDataAt ( $pos1->x, $y, $pos2->z, $block->getDamage () ); + $level->setBlockIdAt ( $pos2->x, $y, $pos2->z, $block->getId () ); + $level->setBlockDataAt ( $pos2->x, $y, $pos2->z, $block->getDamage () ); + } + } + + /* + * Creates the bottom of a structure + * @param $level pocketmine\level\ChunkManager + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @param $block pocketmine\block\Block + * @return void + */ + public static function bottom(ChunkManager $level, Vector3 $pos1, Vector3 $pos2, Block $block) { + list ( $pos1, $pos2 ) = self::minmax ( $pos1, $pos2 ); + for($x = $pos1->x; $x >= $pos2->x; $x --) + for($z = $pos1->z; $z >= $pos2->z; $z --) { + $level->setBlockIdAt ( $x, $pos2->y, $z, $block->getId () ); + $level->setBlockDataAt ( $x, $pos2->y, $z, $block->getDamage () ); + } + } + + /* + * Builds a random structure depending of length, height, depth and random + * @param $level pocketmine\level\ChunkManager + * @param $pos pocketmine\math\Vector3 + * @param $infos pocketmine\math\Vector3 + * @param $random pocketmine\utils\Random + * @param $block pocketmine\block\Block + * @return void + */ + public function buildRandom(ChunkManager $level, Vector3 $pos, Vector3 $infos, Random $random, Block $block) { + $xBounded = $random->nextBoundedInt ( 3 ) - 1; + $yBounded = $random->nextBoundedInt ( 3 ) - 1; + $zBounded = $random->nextBoundedInt ( 3 ) - 1; + $pos = $pos->round (); + for($x = $pos->x - ($infos->x / 2); $x <= $pos->x + ($infos->x / 2); $x ++) { + for($y = $pos->y - ($infos->y / 2); $y <= $pos->y + ($infos->y / 2); $y ++) { + for($z = $pos->z - ($infos->z / 2); $z <= $pos->z + ($infos->z / 2); $z ++) { + // if(abs((abs($x) - abs($pos->x)) ** 2 + ($y - $pos->y) ** 2 + (abs($z) - abs($pos->z)) ** 2) < (abs($infos->x / 2 + $xBounded) + abs($infos->y / 2 + $yBounded) + abs($infos->z / 2 + $zBounded)) ** 2 + if (abs ( (abs ( $x ) - abs ( $pos->x )) ** 2 + ($y - $pos->y) ** 2 + (abs ( $z ) - abs ( $pos->z )) ** 2 ) < ((($infos->x / 2 - $xBounded) + ($infos->y / 2 - $yBounded) + ($infos->z / 2 - $zBounded)) / 3) ** 2 && $y > 0 && ! in_array ( $level->getBlockIdAt ( $x, $y, $z ), self::TO_NOT_OVERWRITE ) && ! in_array ( $level->getBlockIdAt ( $x, $y + 1, $z ), self::TO_NOT_OVERWRITE )) { + $level->setBlockIdAt ( $x, $y, $z, $block->getId () ); + $level->setBlockDataAt ( $x, $y, $z, $block->getDamage () ); + } + } + } + } + } + + /* + * Returns 2 vector3, one with minimal values, one with max values of the provided ones. + * @param $pos1 pocketmine\math\Vector3 + * @param $pos2 pocketmine\math\Vector3 + * @return array + */ + protected static function minmax(Vector3 $pos1, Vector3 $pos2): array { + $v1 = new Vector3 ( max ( $pos1->x, $pos2->x ), max ( $pos1->y, $pos2->y ), max ( $pos1->z, $pos2->z ) ); + $v2 = new Vector3 ( min ( $pos1->x, $pos2->x ), min ( $pos1->y, $pos2->y ), min ( $pos1->z, $pos2->z ) ); + return [ + $v1, + $v2 + ]; + } +} \ No newline at end of file