Browse Source

Uploading plugin

tags/1.0
Ad5001 2 years ago
commit
f170caebf7
50 changed files with 5849 additions and 0 deletions
  1. 126
    0
      LICENSE
  2. 52
    0
      README.md
  3. BIN
      imgs/Island.jpg
  4. BIN
      imgs/MesaRavine.jpg
  5. BIN
      imgs/Mineshaft.jpg
  6. BIN
      imgs/banner.png
  7. BIN
      imgs/bushes.png
  8. BIN
      imgs/cave.jpg
  9. BIN
      imgs/igloo.jpg
  10. BIN
      imgs/lake.png
  11. BIN
      imgs/mesa.png
  12. BIN
      imgs/sakura.jpg
  13. BIN
      imgs/temple.png
  14. 17
    0
      plugin.yml
  15. 183
    0
      resources/loots/mineshaft.json
  16. 154
    0
      resources/loots/temple.json
  17. 248
    0
      src/Ad5001/BetterGen/Main.php
  18. 79
    0
      src/Ad5001/BetterGen/biome/BetterDesert.php
  19. 76
    0
      src/Ad5001/BetterGen/biome/BetterForest.php
  20. 50
    0
      src/Ad5001/BetterGen/biome/BetterIcePlains.php
  21. 113
    0
      src/Ad5001/BetterGen/biome/BetterMesa.php
  22. 108
    0
      src/Ad5001/BetterGen/biome/BetterMesaPlains.php
  23. 48
    0
      src/Ad5001/BetterGen/biome/BetterRiver.php
  24. 14
    0
      src/Ad5001/BetterGen/biome/Mountainable.php
  25. 66
    0
      src/Ad5001/BetterGen/generator/BetterBiomeSelector.php
  26. 421
    0
      src/Ad5001/BetterGen/generator/BetterNormal.php
  27. 124
    0
      src/Ad5001/BetterGen/loot/LootTable.php
  28. 62
    0
      src/Ad5001/BetterGen/populator/AmountPopulator.php
  29. 70
    0
      src/Ad5001/BetterGen/populator/BushPopulator.php
  30. 63
    0
      src/Ad5001/BetterGen/populator/CactusPopulator.php
  31. 158
    0
      src/Ad5001/BetterGen/populator/CavePopulator.php
  32. 55
    0
      src/Ad5001/BetterGen/populator/DeadbushPopulator.php
  33. 151
    0
      src/Ad5001/BetterGen/populator/FloatingIslandPopulator.php
  34. 56
    0
      src/Ad5001/BetterGen/populator/IglooPopulator.php
  35. 65
    0
      src/Ad5001/BetterGen/populator/LakePopulator.php
  36. 427
    0
      src/Ad5001/BetterGen/populator/MineshaftPopulator.php
  37. 121
    0
      src/Ad5001/BetterGen/populator/RavinePopulator.php
  38. 63
    0
      src/Ad5001/BetterGen/populator/SugarCanePopulator.php
  39. 54
    0
      src/Ad5001/BetterGen/populator/TemplePopulator.php
  40. 75
    0
      src/Ad5001/BetterGen/populator/TreePopulator.php
  41. 54
    0
      src/Ad5001/BetterGen/populator/WellPopulator.php
  42. 76
    0
      src/Ad5001/BetterGen/structure/Bush.php
  43. 54
    0
      src/Ad5001/BetterGen/structure/Cactus.php
  44. 384
    0
      src/Ad5001/BetterGen/structure/Igloo.php
  45. 661
    0
      src/Ad5001/BetterGen/structure/SakuraTree.php
  46. 52
    0
      src/Ad5001/BetterGen/structure/SugarCane.php
  47. 907
    0
      src/Ad5001/BetterGen/structure/Temple.php
  48. 130
    0
      src/Ad5001/BetterGen/structure/Well.php
  49. 44
    0
      src/Ad5001/BetterGen/tasks/ChestGenerateTask.php
  50. 188
    0
      src/Ad5001/BetterGen/utils/BuildingUtils.php

+ 126
- 0
LICENSE View File

@@ -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.

+ 52
- 0
README.md View File

@@ -0,0 +1,52 @@
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/banner.png"></img>
<center><h1>PocketMine's Tomorrow's Generator.</h1></center>
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. <h3>Mineshafts:</h3>
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/Mineshaft.jpg" style="width: 500px"></img>
2. <h3>Ravines:</h3>
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/MesaRavine.jpg" style="width: 500px"></img>
3. <h3>Lakes:</h3>
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/lake.png" style="width: 500px"></img>
4. <h3>Caves:</h3>
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/cave.jpg" style="width: 500px"></img>
5. <h3>Floating islands:</h3>
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/Island.jpg" style="width: 500px"></img>


-----

# [NEW BIOME] Sakura forests:
### This biome features new trees: Sakura Trees, japanese pink and white trees and it's own bush.
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/sakura.jpg" style="width: 500px"></img>

-----

# [NEW BIOMES] Mesa Mountains & Plains
### These biomes are inspired (but not completly taken) from Minecraft PC.
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/mesa.png" style="width: 500px"></img>


-----

# 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 !
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/temple.png" style="width: 500px"></img>

-----

# 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 !
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/igloo.jpg" style="width: 500px"></img>


-----

# Oak and Birch Forests:
### These two biomes now are a bit better by the additions of bushes.
<img src="https://raw.githubusercontent.com/Ad5001/BetterGen/master/imgs/bushes.png" style="width: 500px"></img>

All content here is copyrighted (C) Ad5001 2017. Infos about this copyright can be found in the license file.

BIN
imgs/Island.jpg View File


BIN
imgs/MesaRavine.jpg View File


BIN
imgs/Mineshaft.jpg View File


BIN
imgs/banner.png View File


BIN
imgs/bushes.png View File


BIN
imgs/cave.jpg View File


BIN
imgs/igloo.jpg View File


BIN
imgs/lake.png View File


BIN
imgs/mesa.png View File


BIN
imgs/sakura.jpg View File


BIN
imgs/temple.png View File


+ 17
- 0
plugin.yml View File

@@ -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 <name> [generator = betternormal] [seed = rand()] [options (json)]"
permission: bettergen.cmd.createworld
permissions:
bettergen.cmd.createworld:
default: op
...

+ 183
- 0
resources/loots/mineshaft.json View File

@@ -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
}
}

+ 154
- 0
resources/loots/temple.json View File

@@ -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
}
}

+ 248
- 0
src/Ad5001/BetterGen/Main.php View File

@@ -0,0 +1,248 @@
<?php

/*
* Main from BetterGen
* Copyright(C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen;

use pocketmine\plugin\PluginBase;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator;
use pocketmine\level\generator\normal\Normal;
use pocketmine\event\level\ChunkPopulateEvent;
use Ad5001\BetterGen\generator\BetterNormal;
use Ad5001\BetterGen\biome\BetterForest;
use Ad5001\BetterGen\loot\LootTable;
use pocketmine\utils\Config;
use pocketmine\block\Block;
use pocketmine\tile\Chest;
use pocketmine\nbt\NBT;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\tile\Tile;
use pocketmine\item\Item;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\block\BlockBreakEvent;

class Main extends PluginBase implements \pocketmine\event\Listener {
const PREFIX = "§l§o§b[§r§l§2Better§aGen§o§b]§r§f ";
const SAKURA_FOREST = 100; // Letting some place for future biomes.
/*
* Called when the plugin enables
*/
public function onEnable() {
$this->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 <name> [generator = betternormal] [seed = rand()] [options(json)]
switch(count($args)) {
case 0 :
return false;
break;
case 1 : // /createworld <name>
$name = $args [0];
$generator = Generator::getGenerator("betternormal");
$generatorName = "betternormal";
$seed = $this->generateRandomSeed();
$options = [ ];
break;
case 2 : // /createworld <name> [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 <name> [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 <name> [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();
}
}

+ 79
- 0
src/Ad5001/BetterGen/biome/BetterDesert.php View File

@@ -0,0 +1,79 @@
<?php

/*
* BetterDesert from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\normal\biome\SandyBiome;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use Ad5001\BetterGen\populator\TemplePopulator;
use Ad5001\BetterGen\populator\WellPopulator;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
use Ad5001\BetterGen\populator\SugarCanePopulator;

class BetterDesert extends SandyBiome implements Mountainable {
public function __construct() {
$deadBush = new DeadbushPopulator ();
$deadBush->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;
}
}

+ 76
- 0
src/Ad5001/BetterGen/biome/BetterForest.php View File

@@ -0,0 +1,76 @@
<?php

/*
* BetterForest from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\normal\biome\ForestBiome;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\populator\TallGrass;
use Ad5001\BetterGen\Main;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\BushPopulator;

class BetterForest extends ForestBiome implements Mountainable {
static $types = [
"Oak Forest",
"Birch Forest",
"Sakura Forest"
];
static $ids = [
Biome::FOREST,
Biome::BIRCH_FOREST,
Main::SAKURA_FOREST
];
public function __construct($type = 0, array $infos = [0.6, 0.5]) {
parent::__construct ( $type );
$this->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 ) );
}
}

+ 50
- 0
src/Ad5001/BetterGen/biome/BetterIcePlains.php View File

@@ -0,0 +1,50 @@
<?php

/*
* BetterIcePlains from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\normal\biome\SnowyBiome;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use pocketmine\level\generator\populator\TallGrass;
use Ad5001\BetterGen\populator\IglooPopulator;

class BetterIcePlains extends SnowyBiome implements Mountainable {
public function __construct() {
parent::__construct ();
$this->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;
}
}

+ 113
- 0
src/Ad5001/BetterGen/biome/BetterMesa.php View File

@@ -0,0 +1,113 @@
<?php

/*
* BetterMesa from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\normal\biome\SandyBiome;
use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use pocketmine\block\GoldOre;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
use Ad5001\BetterGen\populator\SugarCanePopulator;

class BetterMesa extends SandyBiome {
public function __construct() {
$deadBush = new DeadbushPopulator ();
$deadBush->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;
}
}

+ 108
- 0
src/Ad5001/BetterGen/biome/BetterMesaPlains.php View File

@@ -0,0 +1,108 @@
<?php

/*
* BetterMesaPlains from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\normal\biome\SandyBiome;
use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;
use pocketmine\block\GoldOre;
use Ad5001\BetterGen\populator\CactusPopulator;
use Ad5001\BetterGen\populator\DeadbushPopulator;
use Ad5001\BetterGen\populator\SugarCanePopulator;

class BetterMesaPlains extends SandyBiome {
public function __construct() {
$deadBush = new DeadbushPopulator ();
$deadBush->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;
}
}

+ 48
- 0
src/Ad5001/BetterGen/biome/BetterRiver.php View File

@@ -0,0 +1,48 @@
<?php

/*
* BetterRiver from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\biome;

use pocketmine\level\generator\biome\Biome;
use pocketmine\block\Block;

class BetterRiver extends Biome {
public function __construct() {
$this->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;
}
}

+ 14
- 0
src/Ad5001/BetterGen/biome/Mountainable.php View File

@@ -0,0 +1,14 @@
<?php

/*
* Mountainable from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\biome;

// Class to iplement when the biome can be set as a mountain
interface Mountainable {
}

+ 66
- 0
src/Ad5001/BetterGen/generator/BetterBiomeSelector.php View File

@@ -0,0 +1,66 @@
<?php

/*
* BetterBiomeSelector from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\generator;

use pocketmine\level\generator\biome\BiomeSelector;
use pocketmine\level\generator\biome\Biome;
use pocketmine\utils\Random;
use pocketmine\level\generator\noise\Simplex;

class BetterBiomeSelector extends BiomeSelector {
/** @var Biome */
private $fallback;
/** @var Simplex */
private $temperature;
/** @var Simplex */
private $rainfall;
/** @var Biome[] */
private $biomes = [ ];
private $map = [ ];
private $lookup;
public function __construct(Random $random, callable $lookup, Biome $fallback) {
$this->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;
}
}

+ 421
- 0
src/Ad5001/BetterGen/generator/BetterNormal.php View File

@@ -0,0 +1,421 @@
<?php

/*
* BetterNormal from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\generator;

use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\Generator;
use pocketmine\level\generator\noise\Simplex;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\populator\GroundCover;
use pocketmine\level\generator\populator\Ore;
use pocketmine\block\Block;
use pocketmine\block\CoalOre;
use pocketmine\block\DiamondOre;
use pocketmine\block\Dirt;
use pocketmine\block\GoldOre;
use pocketmine\block\Gravel;
use pocketmine\block\IronOre;
use pocketmine\block\LapisOre;
use pocketmine\block\RedstoneOre;
use pocketmine\level\Level;
use Ad5001\BetterGen\biome\BetterForest;
use Ad5001\BetterGen\biome\BetterDesert;
use Ad5001\BetterGen\biome\BetterIcePlains;
use Ad5001\BetterGen\biome\BetterMesa;
use Ad5001\BetterGen\biome\BetterMesaPlains;
use Ad5001\BetterGen\biome\BetterRiver;
use Ad5001\BetterGen\biome\Mountainable;
use Ad5001\BetterGen\populator\CavePopulator;
use Ad5001\BetterGen\populator\RavinePopulator;
use Ad5001\BetterGen\populator\LakePopulator;
use Ad5001\BetterGen\populator\MineshaftPopulator;
use Ad5001\BetterGen\populator\FloatingIslandPopulator;

class BetterNormal extends Generator {
const NOT_OVERWRITABLE = [
Block::STONE,
Block::GRAVEL,
Block::BEDROCK,
Block::DIAMOND_ORE,
Block::GOLD_ORE,
Block::LAPIS_ORE,
Block::REDSTONE_ORE,
Block::IRON_ORE,
Block::COAL_ORE,
Block::WATER,
Block::STILL_WATER
];
protected $selector;
protected $level;
protected $random;
protected $populators = [ ];
protected $generationPopulators = [ ];
public static $biomes = [ ];
public static $biomeById = [ ];
public static $levels = [ ];
protected static $GAUSSIAN_KERNEL = null; // From main class
protected static $SMOOTH_SIZE = 2;
protected $waterHeight = 63;
/*
* Picks a biome by X and Z
* @param $x int
* @param $z int
* @return Biome
*/
public function pickBiome($x, $z) {
$hash = $x * 2345803 ^ $z * 9236449 ^ $this->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 );
}
}
}
}

+ 124
- 0
src/Ad5001/BetterGen/loot/LootTable.php View File

@@ -0,0 +1,124 @@
<?php

/*
* LootTable from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\loot;

use pocketmine\utils\Config;
use pocketmine\utils\Random;
use pocketmine\math\Vector3;
use pocketmine\item\Item;
use pocketmine\inventory\BaseInventory;
use pocketmine\nbt\NBT;

/*
* This class is used for loot setting.
* Please note that they AREN'T as powerfull as PC ones due to some implementations limitations.
* Loot table format:
* {
* "max": Max number of loots (storable amount)
* "example": {
* "percentage": Chance of appearing(in percent)
* "minCount": Minimal count
* "maxCount": Maximal count
* "id": Id of the item
* "data": Item damage
* "tags": {"display": {"Name": "Example NBT data"}}. This parameter is optionnal
* "minStacks": If choosen, the minimum amount of stacks that can be found
* "maxStacks": If choosen the maximum number of stacks that can be choosen
* }
* }
*/
class LootTable {
const LOOT_NAMES = [
"temple",
"igloo",
"mineshaft"
];
const LOOT_SAVE = [
"chest",
"chest",
"chest"
];
const LOOT_DESERT_TEMPLE = 0;
const LOOT_IGLOO = 1;
const LOOT_MINESHAFT = 2;
/*
* Asyncronous loot table choosing
* @param $place pocketmine\math\Vector3
* @param $type int
* @param $random pocketmine\utils\Random
* @return void
*/
public static function buildLootTable(Vector3 $place, int $type, Random $random) {
if($place->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;
}
}

+ 62
- 0
src/Ad5001/BetterGen/populator/AmountPopulator.php View File

@@ -0,0 +1,62 @@
<?php

/*
* AmountPopulator from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\populator;

use pocketmine\utils\Random;
use pocketmine\level\generator\populator\Populator;

abstract class AmountPopulator extends Populator {
protected $baseAmount = 0;
protected $randomAmount = 0;
/*
* Crosssoftware class for random amount
*/
/*
* Sets the random addition amount
* @param $amount int
*/
public function setRandomAmount(int $amount) {
$this->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;
}
}

+ 70
- 0
src/Ad5001/BetterGen/populator/BushPopulator.php View File

@@ -0,0 +1,70 @@
<?php

/*
* BushPopulator from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/
namespace Ad5001\BetterGen\populator;

use pocketmine\utils\Random;
use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use Ad5001\BetterGen\populator\TreePopulator;
use Ad5001\BetterGen\populator\AmountPopulator;
use Ad5001\BetterGen\structure\Bush;

class BushPopulator extends AmountPopulator {
protected $level;
protected $type;
/*
* Constructs the class
* @param $type int
*/
public function __construct($type = 0) {
$this->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;
}
}

+ 63
- 0
src/Ad5001/BetterGen/populator/CactusPopulator.php View File

@@ -0,0 +1,63 @@
<?php

/*
* CactusPopulator from BetterGen
* Copyright (C) Ad5001 2017
* Licensed under the BoxOfDevs Public General LICENSE which can be found in the file LICENSE in the root directory
* @author ad5001
*/

namespace Ad5001\BetterGen\populator;

use pocketmine\block\Block;
use pocketmine\level\ChunkManager;
use pocketmine\utils\Random;
use Ad5001\BetterGen\structure\Cactus;
use Ad5001\BetterGen\populator\AmountPopulator;

class CactusPopulator extends AmountPopulator {
protected $level;
/*
* Constructs the class
*/
public function __construct() {
$this->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;
}