From 34346dbd684243e3cd7c1af6e6732b8838df4476 Mon Sep 17 00:00:00 2001 From: Petteri <26197131+PetteriM1@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:38:08 +0200 Subject: [PATCH] Include better vanilla gen + fix placeDecoration --- README.md | 3 +- pom.xml | 2 +- .../java/worldgeneratorextension/Loader.java | 19 +- .../pm1e/populator/PopulatorCoralCrust.java | 3 +- .../vanillagenerator/LICENSE | 387 +++++++++++++ .../vanillagenerator/NormalGenerator.java | 505 +++++++++++++++++ .../vanillagenerator/biome/BiomeClimate.java | 132 +++++ .../vanillagenerator/biomegrid/MapLayer.java | 103 ++++ .../biomegrid/MapLayerBiome.java | 64 +++ .../biomegrid/MapLayerBiomeConstant.java | 22 + .../biomegrid/MapLayerBiomeEdge.java | 87 +++ .../biomegrid/MapLayerBiomeEdgeThin.java | 92 +++ .../biomegrid/MapLayerBiomeVariation.java | 158 ++++++ .../biomegrid/MapLayerDeepOcean.java | 51 ++ .../biomegrid/MapLayerErosion.java | 53 ++ .../biomegrid/MapLayerNoise.java | 33 ++ .../biomegrid/MapLayerRarePlains.java | 44 ++ .../biomegrid/MapLayerRiver.java | 106 ++++ .../biomegrid/MapLayerShore.java | 83 +++ .../biomegrid/MapLayerSmooth.java | 47 ++ .../biomegrid/MapLayerWhittaker.java | 107 ++++ .../biomegrid/MapLayerZoom.java | 95 ++++ .../ground/GroundGenerator.java | 101 ++++ .../ground/GroundGeneratorMesa.java | 173 ++++++ .../ground/GroundGeneratorMycel.java | 8 + .../ground/GroundGeneratorPatchDirt.java | 22 + .../GroundGeneratorPatchDirtAndStone.java | 24 + .../ground/GroundGeneratorPatchGravel.java | 20 + .../ground/GroundGeneratorPatchPodzol.java | 20 + .../ground/GroundGeneratorPatchStone.java | 20 + .../ground/GroundGeneratorRocky.java | 9 + .../ground/GroundGeneratorSandOcean.java | 63 +++ .../ground/GroundGeneratorSandy.java | 9 + .../ground/GroundGeneratorSnowy.java | 8 + .../vanillagenerator/noise/PerlinNoise.java | 142 +++++ .../noise/PerlinOctaveGenerator.java | 132 +++++ .../vanillagenerator/noise/SimplexNoise.java | 318 +++++++++++ .../noise/SimplexOctaveGenerator.java | 48 ++ .../noise/bukkit/NoiseGenerator.java | 177 ++++++ .../noise/bukkit/OctaveGenerator.java | 200 +++++++ .../noise/bukkit/PerlinNoiseGenerator.java | 223 ++++++++ .../noise/bukkit/PerlinOctaveGenerator.java | 59 ++ .../noise/bukkit/SimplexNoiseGenerator.java | 534 ++++++++++++++++++ .../noise/bukkit/SimplexOctaveGenerator.java | 141 +++++ .../vanillagenerator/object/OreType.java | 77 +++ .../populator/PopulatorOre.java | 38 ++ .../populator/overworld/PopulatorCaves.java | 272 +++++++++ .../overworld/PopulatorSnowLayers.java | 166 ++++++ src/main/resources/plugin.yml | 1 + 49 files changed, 5195 insertions(+), 6 deletions(-) create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/LICENSE create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/NormalGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biome/BiomeClimate.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayer.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiome.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeConstant.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdge.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdgeThin.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeVariation.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerDeepOcean.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerErosion.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerNoise.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRarePlains.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRiver.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerShore.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerSmooth.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerWhittaker.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerZoom.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMesa.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMycel.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirt.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirtAndStone.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchGravel.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchPodzol.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchStone.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorRocky.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandOcean.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandy.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSnowy.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinNoise.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinOctaveGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/SimplexNoise.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/SimplexOctaveGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/NoiseGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/OctaveGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinNoiseGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinOctaveGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexNoiseGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexOctaveGenerator.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/object/OreType.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/populator/PopulatorOre.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorCaves.java create mode 100644 src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorSnowLayers.java diff --git a/README.md b/README.md index e37133a..5d05e34 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,5 @@ Based on plugins made by [wode490390](https://github.com/wode490390) - https://github.com/wode490390/MultiTemplateStructurePopulator - https://github.com/wode490390/SingleTemplateStructurePopulator - https://github.com/wode490390/ScatteredBuildingPopulator -- https://github.com/wode490390/TheEnd \ No newline at end of file +- https://github.com/wode490390/BetterVanillaGenerator +- https://github.com/wode490390/TheEnd diff --git a/pom.xml b/pom.xml index d801344..821c343 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 worldgeneratorextension WorldGeneratorExtension - 1.6.0 + 1.7.0 ${basedir}/src/main/java diff --git a/src/main/java/worldgeneratorextension/Loader.java b/src/main/java/worldgeneratorextension/Loader.java index 40f5bba..468fd04 100644 --- a/src/main/java/worldgeneratorextension/Loader.java +++ b/src/main/java/worldgeneratorextension/Loader.java @@ -7,6 +7,7 @@ import cn.nukkit.item.RuntimeItemMapping; import cn.nukkit.item.RuntimeItems; import cn.nukkit.level.Level; +import cn.nukkit.level.generator.Generator; import cn.nukkit.level.generator.Normal; import cn.nukkit.level.generator.Void; import cn.nukkit.level.generator.populator.type.Populator; @@ -36,6 +37,7 @@ import worldgeneratorextension.theend.noise.SimplexNoise; import worldgeneratorextension.theend.object.theend.ObsidianPillar; import worldgeneratorextension.theend.populator.theend.*; +import worldgeneratorextension.vanillagenerator.NormalGenerator; import worldgeneratorextension.vipop.populator.PopulatorVillage; import worldgeneratorextension.vipop.structure.VillagePieces; @@ -58,10 +60,21 @@ public void onLoad() { @Override public void onEnable() { + Plugin betterVanillaGenerator = getServer().getPluginManager().getPlugin("BetterVanillaGenerator"); + if (betterVanillaGenerator != null && "cn.wode490390.nukkit.vanillagenerator.BetterGenerator".equals(betterVanillaGenerator.getDescription().getMain())) { + getLogger().warning("Already loaded plugin cn.wode490390.nukkit.vanillagenerator.BetterGenerator found. Using WorldGeneratorExtension instead is recommended."); + } + Plugin theEnd = getServer().getPluginManager().getPlugin("TheEnd"); if (theEnd != null && "cn.wode490390.nukkit.theend.TheEnd".equals(theEnd.getDescription().getMain())) { - getLogger().info("Disabling already loaded cn.wode490390.nukkit.theend.TheEnd"); - getServer().getPluginManager().disablePlugin(theEnd); + getLogger().warning("Already loaded plugin cn.wode490390.nukkit.theend.TheEnd found. Using WorldGeneratorExtension instead is recommended."); + } + + boolean vanillaOverworld = getServer().getPropertyBoolean("wgenext.vanilla-overworld"); + if (vanillaOverworld) { + getLogger().info("Using better vanilla overworld generator"); + Generator.addGenerator(NormalGenerator.class, "default", NormalGenerator.TYPE_INFINITE); + Generator.addGenerator(NormalGenerator.class, "normal", NormalGenerator.TYPE_INFINITE); } PopulatorFossil.init(); @@ -87,7 +100,7 @@ public void onEnable() { populatorsOverworld.add(new PopulatorPillagerOutpost()); populatorsOverworld.add(new PopulatorOceanRuin()); populatorsOverworld.add(new PopulatorRuinedPortal()); - populatorsOverworld.add(new PopulatorVillage(Normal.seaHeight > 62)); + populatorsOverworld.add(new PopulatorVillage(!vanillaOverworld && Normal.seaHeight > 62)); populatorsOverworld.add(new PopulatorStronghold()); populatorsOverworld.add(new PopulatorOceanMonument()); populatorsOverworld.add(new PopulatorMineshaft()); diff --git a/src/main/java/worldgeneratorextension/pm1e/populator/PopulatorCoralCrust.java b/src/main/java/worldgeneratorextension/pm1e/populator/PopulatorCoralCrust.java index dc00345..cc1e14b 100644 --- a/src/main/java/worldgeneratorextension/pm1e/populator/PopulatorCoralCrust.java +++ b/src/main/java/worldgeneratorextension/pm1e/populator/PopulatorCoralCrust.java @@ -1,6 +1,7 @@ package worldgeneratorextension.pm1e.populator; import cn.nukkit.Server; +import cn.nukkit.block.Block; import cn.nukkit.block.BlockID; import cn.nukkit.block.BlockLayer; import cn.nukkit.level.ChunkManager; @@ -98,7 +99,7 @@ private static void placeDecoration(NukkitRandom random, FullChunk chunk, int am int z = random.nextBoundedInt(16); int y = getHighestWorkableBlock(chunk, x, z); - if (y >= 40 && y < Normal.seaHeight) { + if (y >= 40 && y < Normal.seaHeight && Block.isWater(chunk.getBlockId(x, y, z))) { chunk.setBlock(x, y, z, id, random.nextBoundedInt(type)); chunk.setBlockAtLayer(x, y, z, BlockLayer.WATERLOGGED, BlockID.WATER); } diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/LICENSE b/src/main/java/worldgeneratorextension/vanillagenerator/LICENSE new file mode 100644 index 0000000..206f31c --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/LICENSE @@ -0,0 +1,387 @@ +wodeTeam is pleased to support the open source community by making BetterVanillaGenerator available. + +Copyright (C) 2019 Woder. + +If you have downloaded a copy of the BetterVanillaGenerator binary from wodeTeam, please note that the BetterVanillaGenerator binary is licensed under the GNU General Public License, Version 3.0. + +If you have downloaded a copy of the BetterVanillaGenerator source code from wodeTeam, please note that BetterVanillaGenerator source code is licensed under the GNU General Public License, Version 3.0, except for the third-party components listed below which are subject to different license terms. Your integration of BetterVanillaGenerator into your own projects may require compliance with the GNU General Public License, Version 3.0, as well as the other licenses applicable to the third-party components included within BetterVanillaGenerator. + +BetterVanillaGenerator is licensed under the GNU General Public License, Version 3.0. + +A copy of the GNU General Public License, Version 3.0 is included in this file. + +Other dependencies and licenses: + +Open Source Software Licensed Under the MIT License: +------------------------------------------------------ +1. Glowstone 2018.10 +Glowstone Copyright (C) 2015-2019 The Glowstone Project. +Glowstone Copyright (C) 2011-2014 Tad Hardesty. +Lightstone Copyright (C) 2010-2011 Graham Edgecombe. + + +Terms of the MIT License: +--------------------------------------------------- +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + + +Open Source Software Licensed Under the BSD 2-Clause License: +-------------------------------------------------------------------- +1. JOCL 2.3.6 +Copyright 2009 - 2010 JogAmp Community. All rights reserved. + +2. GlueGen 2.3.6 +Copyright 2010 - 2019 JogAmp Community. All rights reserved. + + +Terms of the BSD 2-Clause License: +-------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +Open Source Software Licensed Under the GNU Lesser General Public License, Version 3.0: +------------------------------------------------------ +1. bStats-Metrics 1.7 +Copyright (c) bStats https://bstats.org + + +Terms of the GNU Lesser General Public License, Version 3.0: +--------------------------------------------------- +GNU LESSER GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. + +0. Additional Definitions. + +As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. + +"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". + +The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. + +1. Exception to Section 3 of the GNU GPL. + +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. + +2. Conveying Modified Versions. + +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + + a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or + b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. + +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. + b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. + +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + + a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. + b) Accompany the Combined Work with a copy of the GNU GPL and this license document. + c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. + d) Do one of the following: + 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. + 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. + e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. + +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. + b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. + + + +Open Source Software Licensed Under the GNU General Public License, Version 3.0: +------------------------------------------------------ +1. Bukkit 1.12.2 +Copyright (c) SpigotMC +Copyright (c) The Bukkit Project + + +Terms of the GNU General Public License, Version 3.0: +--------------------------------------------------- +GNU GENERAL PUBLIC LICENSE + +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. https://fsf.org/ + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +Preamble + +The GNU General Public License is a free, copyleft license for software and other kinds of works. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. + +Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS + +0. Definitions. + +"This License" refers to version 3 of the GNU General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based on the Program. + +To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. + +The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. + +A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. + +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. + +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. + +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. + +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. + +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. + +"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Use with the GNU Affero General Public License. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + +How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + +Copyright (C) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: + + Copyright (C) +This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". + +You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see https://www.gnu.org/licenses/. + +The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read https://www.gnu.org/licenses/why-not-lgpl.html. diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/NormalGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/NormalGenerator.java new file mode 100644 index 0000000..6516983 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/NormalGenerator.java @@ -0,0 +1,505 @@ +package worldgeneratorextension.vanillagenerator; + +import cn.nukkit.block.Block; +import cn.nukkit.block.BlockID; +import cn.nukkit.block.BlockStone; +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.biome.Biome; +import cn.nukkit.level.biome.EnumBiome; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.level.generator.Generator; +import cn.nukkit.level.generator.populator.impl.PopulatorSpring; +import cn.nukkit.level.generator.populator.impl.WaterIcePopulator; +import cn.nukkit.level.generator.populator.type.Populator; +import cn.nukkit.math.NukkitRandom; +import cn.nukkit.math.Vector3; +import worldgeneratorextension.vanillagenerator.biomegrid.MapLayer; +import worldgeneratorextension.vanillagenerator.ground.*; +import worldgeneratorextension.vanillagenerator.noise.PerlinOctaveGenerator; +import worldgeneratorextension.vanillagenerator.noise.SimplexOctaveGenerator; +import worldgeneratorextension.vanillagenerator.noise.bukkit.OctaveGenerator; +import worldgeneratorextension.vanillagenerator.object.OreType; +import worldgeneratorextension.vanillagenerator.populator.PopulatorOre; +import worldgeneratorextension.vanillagenerator.populator.overworld.PopulatorCaves; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ThreadLocalRandom; + +public class NormalGenerator extends Generator { + + public static final int TYPE_LARGE_BIOMES = 5; + public static final int TYPE_AMPLIFIED = 6; + + public static int SEA_LEVEL = 64; // 64 generates water normally at y 62 + + /** + * The biome maps used to fill chunks biome grid and terrain generation. + */ + private MapLayer[] biomeGrid; + + private static final double[][] ELEVATION_WEIGHT = new double[5][5]; + private static final Int2ObjectMap GROUND_MAP = new Int2ObjectOpenHashMap<>(); + private static final Int2ObjectMap HEIGHT_MAP = new Int2ObjectOpenHashMap<>(); + + private static final double coordinateScale = 684.412d; + private static final double heightScale = 684.412d; + private static final double heightNoiseScaleX = 200d; // depthNoiseScaleX + private static final double heightNoiseScaleZ = 200d; // depthNoiseScaleZ + private static final double detailNoiseScaleX = 80d; // mainNoiseScaleX + private static final double detailNoiseScaleY = 160d; // mainNoiseScaleY + private static final double detailNoiseScaleZ = 80d; // mainNoiseScaleZ + private static final double surfaceScale = 0.0625d; + private static final double baseSize = 8.5d; + private static final double stretchY = 12d; + private static final double biomeHeightOffset = 0d; // biomeDepthOffset + private static final double biomeHeightWeight = 1d; // biomeDepthWeight + private static final double biomeScaleOffset = 0d; + private static final double biomeScaleWeight = 1d; + + static { + setBiomeSpecificGround(new GroundGeneratorSandy(), EnumBiome.BEACH.id, EnumBiome.COLD_BEACH.id, EnumBiome.DESERT.id, EnumBiome.DESERT_HILLS.id, EnumBiome.DESERT_M.id); + setBiomeSpecificGround(new GroundGeneratorRocky(), EnumBiome.STONE_BEACH.id); + setBiomeSpecificGround(new GroundGeneratorSnowy(), EnumBiome.ICE_PLAINS_SPIKES.id); + setBiomeSpecificGround(new GroundGeneratorMycel(), EnumBiome.MUSHROOM_ISLAND.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + setBiomeSpecificGround(new GroundGeneratorPatchStone(), EnumBiome.EXTREME_HILLS.id); + setBiomeSpecificGround(new GroundGeneratorPatchGravel(), EnumBiome.EXTREME_HILLS_M.id, EnumBiome.EXTREME_HILLS_PLUS_M.id); + setBiomeSpecificGround(new GroundGeneratorPatchDirtAndStone(), EnumBiome.SAVANNA_M.id, EnumBiome.SAVANNA_PLATEAU_M.id); + setBiomeSpecificGround(new GroundGeneratorPatchDirt(), EnumBiome.MEGA_TAIGA.id, EnumBiome.MEGA_TAIGA_HILLS.id, EnumBiome.MEGA_SPRUCE_TAIGA.id, EnumBiome.MEGA_SPRUCE_TAIGA_HILLS.id); + setBiomeSpecificGround(new GroundGeneratorPatchPodzol(), EnumBiome.BAMBOO_JUNGLE.id, EnumBiome.BAMBOO_JUNGLE_HILLS.id); + setBiomeSpecificGround(new GroundGeneratorMesa(), EnumBiome.MESA.id, EnumBiome.MESA_PLATEAU.id, EnumBiome.MESA_PLATEAU_F.id); + setBiomeSpecificGround(new GroundGeneratorMesa(GroundGeneratorMesa.MesaType.BRYCE), EnumBiome.MESA_BRYCE.id); + setBiomeSpecificGround(new GroundGeneratorMesa(GroundGeneratorMesa.MesaType.FOREST), EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_F_M.id); + setBiomeSpecificGround(new GroundGeneratorSandOcean(), EnumBiome.WARM_OCEAN.id, EnumBiome.LUKEWARM_OCEAN.id, EnumBiome.DEEP_WARM_OCEAN.id, EnumBiome.DEEP_LUKEWARM_OCEAN.id); + + setBiomeHeight(BiomeHeight.OCEAN, EnumBiome.OCEAN.id, EnumBiome.FROZEN_OCEAN.id, EnumBiome.WARM_OCEAN.id, EnumBiome.LUKEWARM_OCEAN.id); + setBiomeHeight(BiomeHeight.DEEP_OCEAN, EnumBiome.DEEP_OCEAN.id, EnumBiome.DEEP_FROZEN_OCEAN.id, EnumBiome.DEEP_WARM_OCEAN.id, EnumBiome.DEEP_LUKEWARM_OCEAN.id); + setBiomeHeight(BiomeHeight.RIVER, EnumBiome.RIVER.id, EnumBiome.FROZEN_RIVER.id); + setBiomeHeight(BiomeHeight.FLAT_SHORE, EnumBiome.BEACH.id, EnumBiome.COLD_BEACH.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + setBiomeHeight(BiomeHeight.ROCKY_SHORE, EnumBiome.STONE_BEACH.id); + setBiomeHeight(BiomeHeight.FLATLANDS, EnumBiome.DESERT.id, EnumBiome.ICE_PLAINS.id, EnumBiome.SAVANNA.id); + setBiomeHeight(BiomeHeight.EXTREME_HILLS, EnumBiome.EXTREME_HILLS.id, EnumBiome.EXTREME_HILLS_PLUS.id, EnumBiome.EXTREME_HILLS_M.id, EnumBiome.EXTREME_HILLS_PLUS_M.id); + setBiomeHeight(BiomeHeight.MID_PLAINS, EnumBiome.TAIGA.id, EnumBiome.COLD_TAIGA.id, EnumBiome.MEGA_TAIGA.id); + setBiomeHeight(BiomeHeight.SWAMPLAND, EnumBiome.SWAMP.id); + setBiomeHeight(BiomeHeight.LOW_HILLS, EnumBiome.MUSHROOM_ISLAND.id); + setBiomeHeight(BiomeHeight.HILLS, EnumBiome.DESERT_HILLS.id, EnumBiome.FOREST_HILLS.id, EnumBiome.TAIGA_HILLS.id, EnumBiome.EXTREME_HILLS_EDGE.id, EnumBiome.JUNGLE_HILLS.id, EnumBiome.BIRCH_FOREST_HILLS.id, EnumBiome.COLD_TAIGA_HILLS.id, EnumBiome.MEGA_TAIGA_HILLS.id, EnumBiome.MESA_PLATEAU_F_M.id, EnumBiome.MESA_PLATEAU_M.id, EnumBiome.ICE_MOUNTAINS.id); + setBiomeHeight(BiomeHeight.HIGH_PLATEAU, EnumBiome.SAVANNA_PLATEAU.id, EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU.id); + setBiomeHeight(BiomeHeight.FLATLANDS_HILLS, EnumBiome.DESERT_M.id); + setBiomeHeight(BiomeHeight.BIG_HILLS, EnumBiome.ICE_PLAINS_SPIKES.id); + setBiomeHeight(BiomeHeight.BIG_HILLS2, EnumBiome.BIRCH_FOREST_HILLS_M.id); + setBiomeHeight(BiomeHeight.SWAMPLAND_HILLS, EnumBiome.SWAMPLAND_M.id); + setBiomeHeight(BiomeHeight.DEFAULT_HILLS, EnumBiome.JUNGLE_M.id, EnumBiome.JUNGLE_EDGE_M.id, EnumBiome.BIRCH_FOREST_M.id, EnumBiome.ROOFED_FOREST_M.id); + setBiomeHeight(BiomeHeight.MID_HILLS, EnumBiome.TAIGA_M.id, EnumBiome.COLD_TAIGA_M.id, EnumBiome.MEGA_SPRUCE_TAIGA.id, EnumBiome.MEGA_SPRUCE_TAIGA_HILLS.id); + setBiomeHeight(BiomeHeight.MID_HILLS2, EnumBiome.FLOWER_FOREST.id); + setBiomeHeight(BiomeHeight.LOW_SPIKES, EnumBiome.SAVANNA_M.id); + setBiomeHeight(BiomeHeight.HIGH_SPIKES, EnumBiome.SAVANNA_PLATEAU_M.id); + + // fill a 5x5 array with values that acts as elevation weight on chunk neighboring, this can be viewed as a parabolic field: the center gets the more weight, and the weight decreases as distance increases from the center. This is applied on the lower scale biome grid. + for (int x = 0; x < 5; x++) { + for (int z = 0; z < 5; z++) { + int sqX = x - 2; + sqX *= sqX; + int sqZ = z - 2; + sqZ *= sqZ; + ELEVATION_WEIGHT[x][z] = 10d / Math.sqrt(sqX + sqZ + 0.2d); + } + } + } + + private final Map> octaveCache = Maps.newHashMap(); + private final double[][][] density = new double[5][5][33]; + private final GroundGenerator groundGen = new GroundGenerator(); + private final BiomeHeight defaultHeight = BiomeHeight.DEFAULT; + + private static void setBiomeSpecificGround(GroundGenerator gen, int... biomes) { + for (int biome : biomes) { + GROUND_MAP.put(biome, gen); + } + } + + private static void setBiomeHeight(BiomeHeight height, int... biomes) { + for (int biome : biomes) { + HEIGHT_MAP.put(biome, height); + } + } + + private List generationPopulators = Lists.newArrayList(); + private List populators = Lists.newArrayList(); + private ChunkManager level; + private NukkitRandom nukkitRandom; + private long localSeed1; + private long localSeed2; + + public NormalGenerator() { + // reflect + } + + public NormalGenerator(Map options) { + // reflect + } + + @Override + public int getId() { + return TYPE_INFINITE; + } + + @Override + public ChunkManager getChunkManager() { + return level; + } + + @Override + public String getName() { + return "normal"; + } + + @Override + public Map getSettings() { + return Collections.emptyMap(); + } + + @Override + public void init(ChunkManager level, NukkitRandom random) { + this.level = level; + this.nukkitRandom = random; + this.nukkitRandom.setSeed(this.level.getSeed()); + this.localSeed1 = ThreadLocalRandom.current().nextLong(); + this.localSeed2 = ThreadLocalRandom.current().nextLong(); + this.nukkitRandom.setSeed(this.level.getSeed()); + + this.generationPopulators = ImmutableList.of(new PopulatorCaves()); + + this.populators = ImmutableList.of( + new PopulatorOre(STONE, new OreType[]{ + new OreType(Block.get(COAL_ORE), 20, 17, 0, 128), + new OreType(Block.get(IRON_ORE), 20, 9, 0, 64), + new OreType(Block.get(REDSTONE_ORE), 8, 8, 0, 16), + new OreType(Block.get(LAPIS_ORE), 1, 7, 0, 30), + new OreType(Block.get(GOLD_ORE), 2, 9, 0, 32), + new OreType(Block.get(DIAMOND_ORE), 1, 8, 0, 16), + new OreType(Block.get(DIRT), 10, 33, 0, 128), + new OreType(Block.get(GRAVEL), 8, 33, 0, 128), + new OreType(Block.get(STONE, BlockStone.GRANITE), 10, 33, 0, 80), + new OreType(Block.get(STONE, BlockStone.DIORITE), 10, 33, 0, 80), + new OreType(Block.get(STONE, BlockStone.ANDESITE), 10, 33, 0, 80) + }), + new cn.wode490390.nukkit.vanillagenerator.populator.overworld.PopulatorSnowLayers(), + new WaterIcePopulator(), + new PopulatorSpring(BlockID.WATER, BlockID.STONE, 15, 8, 255), + new PopulatorSpring(BlockID.LAVA, BlockID.STONE, 10, 16, 255) + ); + this.biomeGrid = MapLayer.initialize(level.getSeed(), this.getDimension(), this.getId()); + } + + @Override + public void generateChunk(int chunkX, int chunkZ) { + this.nukkitRandom.setSeed(chunkX * localSeed1 ^ chunkZ * localSeed2 ^ this.level.getSeed()); + + BaseFullChunk chunkData = level.getChunk(chunkX, chunkZ); + + // Scaling chunk x and z coordinates (4x, see below) + int x = chunkX << 2; + int z = chunkZ << 2; + + // Get biome grid data at lower res (scaled 4x, at this scale a chunk is 4x4 columns of the biome grid), we are loosing biome detail but saving huge amount of computation. + // We need 1 chunk (4 columns) + 1 column for later needed outer edges (1 column) and at least 2 columns on each side to be able to cover every value. + // 4 + 1 + 2 + 2 = 9 columns but the biomegrid generator needs a multiple of 2 so we ask 10 columns wide to the biomegrid generator. + // This gives a total of 81 biome grid columns to work with, and this includes the chunk neighborhood. + int[] biomeGrid = this.biomeGrid[1].generateValues(x - 2, z - 2, 10, 10); + + Map octaves = getWorldOctaves(); + double[] heightNoise = ((PerlinOctaveGenerator) octaves.get("height")).getFractalBrownianMotion(x, z, 0.5d, 2d); + double[] roughnessNoise = ((PerlinOctaveGenerator) octaves.get("roughness")).getFractalBrownianMotion(x, 0, z, 0.5d, 2d); + double[] roughnessNoise2 = ((PerlinOctaveGenerator) octaves.get("roughness2")).getFractalBrownianMotion(x, 0, z, 0.5d, 2d); + double[] detailNoise = ((PerlinOctaveGenerator) octaves.get("detail")).getFractalBrownianMotion(x, 0, z, 0.5d, 2d); + + int index = 0; + int indexHeight = 0; + + // Sampling densities. + // Ideally we would sample 512 (4x4x32) values but in reality we need 825 values (5x5x33). + // This is because linear interpolation is done later to re-scale so we need right and bottom edge values if we want it to be "seamless". + // You can check this picture to have a visualization of how the biomegrid is traversed (2D plan): http://i.imgur.com/s4whlZE.png + // The big square grid represents our lower res biomegrid columns, and the very small square grid represents the normal biome grid columns (at block level) and the reason why it's required to re-scale it and do linear interpolation before densities can be used to generate raw terrain. + for (int i = 0; i < 5; i++) { + for (int j = 0; j < 5; j++) { + double avgHeightScale = 0; + double avgHeightBase = 0; + double totalWeight = 0; + int biome = Biome.getBiome(biomeGrid[i + 2 + (j + 2) * 10]).getId(); + BiomeHeight biomeHeight = HEIGHT_MAP.getOrDefault(biome, defaultHeight); + // Sampling an average height base and scale by visiting the neighborhood of the current biomegrid column. + for (int m = 0; m < 5; m++) { + for (int n = 0; n < 5; n++) { + int nearBiome = Biome.getBiome(biomeGrid[i + m + (j + n) * 10]).getId(); + BiomeHeight nearBiomeHeight = HEIGHT_MAP.getOrDefault(nearBiome, defaultHeight); + double heightBase = biomeHeightOffset + nearBiomeHeight.getHeight() * biomeHeightWeight; + double heightScale = biomeScaleOffset + nearBiomeHeight.getScale() * biomeScaleWeight; + if (this.getId() == TYPE_AMPLIFIED && heightBase > 0) { + heightBase = 1d + heightBase * 2d; + heightScale = 1d + heightScale * 4d; + } + double weight = ELEVATION_WEIGHT[m][n] / (heightBase + 2d); + if (nearBiomeHeight.getHeight() > biomeHeight.getHeight()) { + weight *= 0.5d; + } + avgHeightScale += heightScale * weight; + avgHeightBase += heightBase * weight; + totalWeight += weight; + } + } + avgHeightScale /= totalWeight; + avgHeightBase /= totalWeight; + avgHeightScale = avgHeightScale * 0.9d + 0.1d; + avgHeightBase = (avgHeightBase * 4d - 1d) / 8d; + + double noiseH = heightNoise[indexHeight++] / 8000d; + if (noiseH < 0) { + noiseH = Math.abs(noiseH) * 0.3d; + } + noiseH = noiseH * 3d - 2d; + if (noiseH < 0) { + noiseH = Math.max(noiseH * 0.5d, -1) / 1.4d * 0.5d; + } else { + noiseH = Math.min(noiseH, 1) / 8d; + } + + noiseH = (noiseH * 0.2d + avgHeightBase) * baseSize / 8d * 4d + baseSize; + for (int k = 0; k < 33; k++) { + // density should be lower and lower as we climb up, this gets a height value to subtract from the noise. + double nh = (k - noiseH) * stretchY * 128d / 256d / avgHeightScale; + if (nh < 0) { + nh *= 4d; + } + double noiseR = roughnessNoise[index] / 512d; + double noiseR2 = roughnessNoise2[index] / 512d; + double noiseD = (detailNoise[index] / 10d + 1d) / 2d; + // linear interpolation + double dens = noiseD < 0 ? noiseR + : noiseD > 1 ? noiseR2 : noiseR + (noiseR2 - noiseR) * noiseD; + dens -= nh; + index++; + if (k > 29) { + double lowering = (k - 29) / 3d; + // linear interpolation + dens = dens * (1d - lowering) + -10d * lowering; + } + this.density[i][j][k] = dens; + } + } + } + + // Terrain densities are sampled at different resolutions (1/4x on x,z and 1/8x on y by default) so it's needed to re-scale it. Linear interpolation is used to fill in the gaps. + + int fill = 0; + int afill = 0; //Math.abs(fill); + int seaFill = 0; + double densityOffset = 0.0; + + for (int i = 0; i < 5 - 1; i++) { + for (int j = 0; j < 5 - 1; j++) { + for (int k = 0; k < 33 - 1; k++) { + // 2x2 grid + double d1 = this.density[i][j][k]; + double d2 = this.density[i + 1][j][k]; + double d3 = this.density[i][j + 1][k]; + double d4 = this.density[i + 1][j + 1][k]; + // 2x2 grid (row above) + double d5 = (this.density[i][j][k + 1] - d1) / 8; + double d6 = (this.density[i + 1][j][k + 1] - d2) / 8; + double d7 = (this.density[i][j + 1][k + 1] - d3) / 8; + double d8 = (this.density[i + 1][j + 1][k + 1] - d4) / 8; + + for (int l = 0; l < 8; l++) { + double d9 = d1; + double d10 = d3; + for (int m = 0; m < 4; m++) { + double dens = d9; + for (int n = 0; n < 4; n++) { + // any density higher than density offset is ground, any density lower or equal to the density offset is air (or water if under the sea level). + // this can be flipped if the mode is negative, so lower or equal to is ground, and higher is air/water and, then data can be shifted by afill the order is air by default, ground, then water. + // they can shift places within each if statement the target is densityOffset + 0, since the default target is 0, so don't get too confused by the naming. + if (afill == 1 || afill == 10 || afill == 13 || afill == 16) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STILL_WATER); + } else if (afill == 2 || afill == 9 || afill == 12 || afill == 15) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STONE); + } + if (dens > densityOffset && fill > -1 || dens <= densityOffset && fill < 0) { + if (afill == 0 || afill == 3 || afill == 6 || afill == 9 || afill == 12) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STONE); + } else if (afill == 2 || afill == 7 || afill == 10 || afill == 16) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STILL_WATER); + } + } else if (l + (k << 3) < SEA_LEVEL - 1 && seaFill == 0 || l + (k << 3) >= SEA_LEVEL - 1 && seaFill == 1) { + if (afill == 0 || afill == 3 || afill == 7 || afill == 10 || afill == 13) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STILL_WATER); + } else if (afill == 1 || afill == 6 || afill == 9 || afill == 15) { + chunkData.setBlock(m + (i << 2), l + (k << 3), n + (j << 2), STONE); + } + } + // interpolation along z + dens += (d10 - d9) / 4; + } + // interpolation along x + d9 += (d2 - d1) / 4; + // interpolate along z + d10 += (d4 - d3) / 4; + } + // interpolation along y + d1 += d5; + d3 += d7; + d2 += d6; + d4 += d8; + } + } + } + } + + int cx = chunkX << 4; + int cz = chunkZ << 4; + + BiomeGrid biomes = new BiomeGrid(); + int[] biomeValues = this.biomeGrid[0].generateValues(cx, cz, 16, 16); + for (int i = 0; i < biomeValues.length; i++) { + biomes.biomes[i] = (byte) biomeValues[i]; + } + + SimplexOctaveGenerator octaveGenerator = ((SimplexOctaveGenerator) getWorldOctaves().get("surface")); + int sizeX = octaveGenerator.getSizeX(); + int sizeZ = octaveGenerator.getSizeZ(); + + double[] surfaceNoise = octaveGenerator.getFractalBrownianMotion(cx, cz, 0.5d, 0.5d); + for (int sx = 0; sx < sizeX; sx++) { + for (int sz = 0; sz < sizeZ; sz++) { + GROUND_MAP.getOrDefault(biomes.getBiome(sx, sz), groundGen).generateTerrainColumn(level, chunkData, this.nukkitRandom, cx + sx, cz + sz, biomes.getBiome(sx, sz), surfaceNoise[sx | sz << 4]); + chunkData.setBiomeId(sx, sz, biomes.getBiome(sx, sz)); + } + } + + //populate chunk + this.generationPopulators.forEach(populator -> populator.populate(this.level, chunkX, chunkZ, this.nukkitRandom, chunkData)); + } + + @Override + public void populateChunk(int chunkX, int chunkZ) { + BaseFullChunk chunk = this.level.getChunk(chunkX, chunkZ); + this.nukkitRandom.setSeed(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ this.level.getSeed()); + + Biome.getBiome(chunk.getBiomeId(7, 7)).populateChunk(this.level, chunkX, chunkZ, this.nukkitRandom); + this.populators.forEach(populator -> populator.populate(this.level, chunkX, chunkZ, this.nukkitRandom, chunk)); + } + + @Override + public Vector3 getSpawn() { + return new Vector3(0.5, 256, 0.5); + } + + /** + * Returns the {@link OctaveGenerator} instances for the world, which are + * either newly created or retrieved from the cache. + * + * @return A map of {@link OctaveGenerator}s + */ + private Map getWorldOctaves() { + Map octaves = this.octaveCache.get(this.getName()); + if (octaves == null) { + octaves = Maps.newHashMap(); + NukkitRandom seed = new NukkitRandom(this.level.getSeed()); + + OctaveGenerator gen = new PerlinOctaveGenerator(seed, 16, 5, 5); + gen.setXScale(heightNoiseScaleX); + gen.setZScale(heightNoiseScaleZ); + octaves.put("height", gen); + + gen = new PerlinOctaveGenerator(seed, 16, 5, 33, 5); + gen.setXScale(coordinateScale); + gen.setYScale(heightScale); + gen.setZScale(coordinateScale); + octaves.put("roughness", gen); + + gen = new PerlinOctaveGenerator(seed, 16, 5, 33, 5); + gen.setXScale(coordinateScale); + gen.setYScale(heightScale); + gen.setZScale(coordinateScale); + octaves.put("roughness2", gen); + + gen = new PerlinOctaveGenerator(seed, 8, 5, 33, 5); + gen.setXScale(coordinateScale / detailNoiseScaleX); + gen.setYScale(heightScale / detailNoiseScaleY); + gen.setZScale(coordinateScale / detailNoiseScaleZ); + octaves.put("detail", gen); + + gen = new SimplexOctaveGenerator(seed, 4, 16, 16); + gen.setScale(surfaceScale); + octaves.put("surface", gen); + + this.octaveCache.put(this.getName(), octaves); + } + return octaves; + } + + /** + * A BiomeGrid implementation for chunk generation. + */ + private static class BiomeGrid { + + public final byte[] biomes = new byte[256]; + + public int getBiome(int x, int z) { + // upcasting is very important to get extended biomes + return Biome.biomes[biomes[x | z << 4] & 0xff].getId(); + } + + public void setBiome(int x, int z, int bio) { + biomes[x | z << 4] = (byte) Biome.biomes[bio].getId(); + } + } + + private static class BiomeHeight { + + public static final BiomeHeight DEFAULT = new BiomeHeight(0.1d,0.2d); + public static final BiomeHeight FLAT_SHORE = new BiomeHeight(0d,0.025d); + public static final BiomeHeight HIGH_PLATEAU = new BiomeHeight(1.5d,0.025d); + public static final BiomeHeight FLATLANDS = new BiomeHeight(0.125d,0.05d); + public static final BiomeHeight SWAMPLAND = new BiomeHeight(-0.2d,0.1d); + public static final BiomeHeight MID_PLAINS = new BiomeHeight(0.2d,0.2d); + public static final BiomeHeight FLATLANDS_HILLS = new BiomeHeight(0.275d,0.25d); + public static final BiomeHeight SWAMPLAND_HILLS = new BiomeHeight(-0.1d,0.3d); + public static final BiomeHeight LOW_HILLS = new BiomeHeight(0.2d,0.3d); + public static final BiomeHeight HILLS = new BiomeHeight(0.45d,0.3d); + public static final BiomeHeight MID_HILLS2 = new BiomeHeight(0.1d,0.4d); + public static final BiomeHeight DEFAULT_HILLS = new BiomeHeight(0.2d,0.4d); + public static final BiomeHeight MID_HILLS = new BiomeHeight(0.3d,0.4d); + public static final BiomeHeight BIG_HILLS = new BiomeHeight(0.525d,0.55d); + public static final BiomeHeight BIG_HILLS2 = new BiomeHeight(0.55d,0.5d); + public static final BiomeHeight EXTREME_HILLS = new BiomeHeight(1d,0.5d); + public static final BiomeHeight ROCKY_SHORE = new BiomeHeight(0.1d,0.8d); + public static final BiomeHeight LOW_SPIKES = new BiomeHeight(0.4125d,1.325d); + public static final BiomeHeight HIGH_SPIKES = new BiomeHeight(1.1d,1.3125d); + public static final BiomeHeight RIVER = new BiomeHeight(-0.5d,0d); + public static final BiomeHeight OCEAN = new BiomeHeight(-1d,0.1d); + public static final BiomeHeight DEEP_OCEAN = new BiomeHeight(-1.8d,0.1d); + + private final double height; + private final double scale; + + BiomeHeight(double height, double scale){ + this.height = height; + this.scale = scale; + } + + public double getHeight(){ + return this.height; + } + + public double getScale(){ + return this.scale; + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biome/BiomeClimate.java b/src/main/java/worldgeneratorextension/vanillagenerator/biome/BiomeClimate.java new file mode 100644 index 0000000..09fc8d8 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biome/BiomeClimate.java @@ -0,0 +1,132 @@ +package worldgeneratorextension.vanillagenerator.biome; + +import cn.nukkit.level.biome.Biome; +import cn.nukkit.level.biome.EnumBiome; +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.noise.bukkit.SimplexOctaveGenerator; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +public class BiomeClimate { + + private static final Int2ObjectMap CLIMATE_MAP = new Int2ObjectOpenHashMap<>(); + private static final SimplexOctaveGenerator noiseGen; + + static { + int[] biomes = new int[Biome.unorderedBiomes.size()]; + for (int i = 0; i < biomes.length; i++) { + biomes[i] = Biome.unorderedBiomes.get(i).getId(); + } + setBiomeClimate(Climate.DEFAULT, biomes); + setBiomeClimate(Climate.PLAINS, EnumBiome.PLAINS.id, EnumBiome.SUNFLOWER_PLAINS.id, EnumBiome.BEACH.id); + setBiomeClimate(Climate.DESERT, EnumBiome.DESERT.id, EnumBiome.DESERT_HILLS.id, EnumBiome.DESERT_M.id, EnumBiome.MESA.id, EnumBiome.MESA_BRYCE.id, EnumBiome.MESA_PLATEAU.id, EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_M.id, EnumBiome.MESA_PLATEAU_F_M.id, EnumBiome.HELL.id); + setBiomeClimate(Climate.EXTREME_HILLS, EnumBiome.EXTREME_HILLS.id, EnumBiome.EXTREME_HILLS_PLUS.id, EnumBiome.EXTREME_HILLS_M.id, EnumBiome.EXTREME_HILLS_PLUS_M.id, EnumBiome.STONE_BEACH.id, EnumBiome.EXTREME_HILLS_EDGE.id); + setBiomeClimate(Climate.FOREST, EnumBiome.FOREST.id, EnumBiome.FOREST_HILLS.id, EnumBiome.FLOWER_FOREST.id, EnumBiome.ROOFED_FOREST.id, EnumBiome.ROOFED_FOREST_M.id); + setBiomeClimate(Climate.BIRCH_FOREST, EnumBiome.BIRCH_FOREST.id, EnumBiome.BIRCH_FOREST_HILLS.id, EnumBiome.BIRCH_FOREST_M.id, EnumBiome.BIRCH_FOREST_HILLS_M.id); + setBiomeClimate(Climate.TAIGA, EnumBiome.TAIGA.id, EnumBiome.TAIGA_HILLS.id, EnumBiome.TAIGA_M.id, EnumBiome.MEGA_SPRUCE_TAIGA.id, EnumBiome.MEGA_SPRUCE_TAIGA_HILLS.id); + setBiomeClimate(Climate.SWAMPLAND, EnumBiome.SWAMP.id, EnumBiome.SWAMPLAND_M.id); + setBiomeClimate(Climate.ICE_PLAINS, EnumBiome.ICE_PLAINS.id, EnumBiome.ICE_PLAINS_SPIKES.id, EnumBiome.FROZEN_RIVER.id, EnumBiome.FROZEN_OCEAN.id, EnumBiome.ICE_MOUNTAINS.id); + setBiomeClimate(Climate.MUSHROOM, EnumBiome.MUSHROOM_ISLAND.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + setBiomeClimate(Climate.COLD_BEACH, EnumBiome.COLD_BEACH.id); + setBiomeClimate(Climate.JUNGLE, EnumBiome.JUNGLE.id, EnumBiome.JUNGLE_HILLS.id, EnumBiome.JUNGLE_M.id, EnumBiome.BAMBOO_JUNGLE.id, EnumBiome.BAMBOO_JUNGLE_HILLS.id); + setBiomeClimate(Climate.JUNGLE_EDGE, EnumBiome.JUNGLE_EDGE.id, EnumBiome.JUNGLE_EDGE_M.id); + setBiomeClimate(Climate.COLD_TAIGA, EnumBiome.COLD_TAIGA.id, EnumBiome.COLD_TAIGA_HILLS.id, EnumBiome.COLD_TAIGA_M.id); + setBiomeClimate(Climate.MEGA_TAIGA, EnumBiome.MEGA_TAIGA.id, EnumBiome.MEGA_TAIGA_HILLS.id); + setBiomeClimate(Climate.SAVANNA, EnumBiome.SAVANNA.id); + setBiomeClimate(Climate.SAVANNA_MOUNTAINS, EnumBiome.SAVANNA_M.id); + setBiomeClimate(Climate.SAVANNA_PLATEAU, EnumBiome.SAVANNA_PLATEAU.id); + setBiomeClimate(Climate.SAVANNA_PLATEAU_MOUNTAINS, EnumBiome.SAVANNA_PLATEAU_M.id); + setBiomeClimate(Climate.SKY);//, EnumBiome.THE_END.id, EnumBiome.SMALL_END_ISLANDS.id, EnumBiome.END_MIDLANDS.id, EnumBiome.END_HIGHLANDS.id, EnumBiome.END_BARRENS.id + + noiseGen = new SimplexOctaveGenerator(new NukkitRandom(1234), 1); + noiseGen.setScale(1 / 8.0D); + } + + public static double getTemperature(int biome) { + return CLIMATE_MAP.get(biome).getTemperature(); + } + + public static double getHumidity(int biome) { + return CLIMATE_MAP.get(biome).getHumidity(); + } + + public static boolean isWet(int biome) { + return getHumidity(biome) > 0.85D; + } + + public static boolean isCold(int biome, int x, int y, int z) { + return getVariatedTemperature(biome, x, y, z) < 0.15D; + } + + public static boolean isRainy(int biome, int x, int y, int z) { + boolean rainy = CLIMATE_MAP.get(biome).isRainy(); + return rainy && !isCold(biome, x, y, z); + } + + public static boolean isSnowy(int biome, int x, int y, int z) { + boolean rainy = CLIMATE_MAP.get(biome).isRainy(); + return rainy && isCold(biome, x, y, z); + } + + private static double getVariatedTemperature(int biome, int x, int y, int z) { + double temp = CLIMATE_MAP.get(biome).getTemperature(); + if (y > 64) { + double variation = noiseGen.noise(x, z, 0.5D, 2.0D) * 4.0D; + return temp - (variation + (y - 64)) * 0.05D / 30.0D; + } else { + return temp; + } + } + + private static void setBiomeClimate(Climate temp, int... biomes) { + for (int biome : biomes) { + CLIMATE_MAP.put(biome, temp); + } + } + + private static class Climate { + + public static final Climate DEFAULT = new Climate(0.5D, 0.5D, true); + public static final Climate PLAINS = new Climate(0.8D, 0.4D, true); + public static final Climate DESERT = new Climate(2.0D, 0.0D, false); + public static final Climate EXTREME_HILLS = new Climate(0.2D, 0.3D, true); + public static final Climate FOREST = new Climate(0.7D, 0.8D, true); + public static final Climate BIRCH_FOREST = new Climate(0.6D, 0.6D, true); + public static final Climate TAIGA = new Climate(0.25D, 0.8D, true); + public static final Climate SWAMPLAND = new Climate(0.8D, 0.9D, true); + public static final Climate ICE_PLAINS = new Climate(0.0D, 0.5D, true); + public static final Climate MUSHROOM = new Climate(0.9D, 1.0D, true); + public static final Climate COLD_BEACH = new Climate(0.05D, 0.3D, true); + public static final Climate JUNGLE = new Climate(0.95D, 0.9D, true); + public static final Climate JUNGLE_EDGE = new Climate(0.95D, 0.8D, true); + public static final Climate COLD_TAIGA = new Climate(-0.5D, 0.4D, true); + public static final Climate MEGA_TAIGA = new Climate(0.3D, 0.8D, true); + public static final Climate SAVANNA = new Climate(1.2D, 0.0D, false); + public static final Climate SAVANNA_MOUNTAINS = new Climate(1.1D, 0.0D, false); + public static final Climate SAVANNA_PLATEAU = new Climate(1.0D, 0.0D, false); + public static final Climate SAVANNA_PLATEAU_MOUNTAINS = new Climate(0.5D, 0.0D, false); + public static final Climate SKY = new Climate(0.5D, 0.5D, false); + + private final double temperature; + private final double humidity; + private final boolean rainy; + + Climate(double temperature, double humidity, boolean rainy) { + this.temperature = temperature; + this.humidity = humidity; + this.rainy = rainy; + } + + public double getTemperature() { + return this.temperature; + } + + public double getHumidity() { + return this.humidity; + } + + public boolean isRainy() { + return this.rainy; + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayer.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayer.java new file mode 100644 index 0000000..856b93e --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayer.java @@ -0,0 +1,103 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.Level; +import cn.nukkit.level.biome.EnumBiome; +import cn.nukkit.level.generator.Generator; +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.NormalGenerator; +import worldgeneratorextension.vanillagenerator.biomegrid.MapLayerWhittaker.ClimateType; +import worldgeneratorextension.vanillagenerator.biomegrid.MapLayerZoom.ZoomType; + +public abstract class MapLayer { + + private final NukkitRandom random = new NukkitRandom(); + private final long seed; + + public MapLayer(long seed) { + this.seed = seed; + } + + /** + * Creates the instances for the given map. + * @param seed the world seed + * @param environment the type of dimension + * @param worldType the world generator + * @return an array of all map layers this dimension needs + */ + public static MapLayer[] initialize(long seed, int environment, int worldType) { + if (environment == Level.DIMENSION_OVERWORLD && worldType == Generator.TYPE_FLAT) { + return new MapLayer[]{new MapLayerBiomeConstant(seed, EnumBiome.PLAINS.id), null}; + } else if (environment == Level.DIMENSION_NETHER) { + return new MapLayer[]{new MapLayerBiomeConstant(seed, EnumBiome.HELL.id), null}; + } else if (environment == Level.DIMENSION_THE_END) { + return new MapLayer[]{new MapLayerBiomeConstant(seed, 9), null};//EnumBiome.THE_END.id + } + + int zoom = 2; + if (worldType == NormalGenerator.TYPE_LARGE_BIOMES) { + zoom = 4; + } + + MapLayer layer = new MapLayerNoise(seed); // this is initial land spread layer + layer = new MapLayerWhittaker(seed + 1, layer, ClimateType.WARM_WET); + layer = new MapLayerWhittaker(seed + 1, layer, ClimateType.COLD_DRY); + layer = new MapLayerWhittaker(seed + 2, layer, ClimateType.LARGER_BIOMES); + for (int i = 0; i < 2; i++) { + layer = new MapLayerZoom(seed + 100 + i, layer, ZoomType.BLURRY); + } + for (int i = 0; i < 2; i++) { + layer = new MapLayerErosion(seed + 3 + i, layer); + } + layer = new MapLayerDeepOcean(seed + 4, layer); + + MapLayer layerMountains = new MapLayerBiomeVariation(seed + 200, layer); + for (int i = 0; i < 2; i++) { + layerMountains = new MapLayerZoom(seed + 200 + i, layerMountains); + } + + layer = new MapLayerBiome(seed + 5, layer); + for (int i = 0; i < 2; i++) { + layer = new MapLayerZoom(seed + 200 + i, layer); + } + layer = new MapLayerBiomeEdge(seed + 200, layer); + layer = new MapLayerBiomeVariation(seed + 200, layer, layerMountains); + layer = new MapLayerRarePlains(seed + 201, layer); + layer = new MapLayerZoom(seed + 300, layer); + layer = new MapLayerErosion(seed + 6, layer); + layer = new MapLayerZoom(seed + 400, layer); + layer = new MapLayerBiomeEdgeThin(seed + 400, layer); + layer = new MapLayerShore(seed + 7, layer); + for (int i = 0; i < zoom; i++) { + layer = new MapLayerZoom(seed + 500 + i, layer); + } + + MapLayer layerRiver = layerMountains; + layerRiver = new MapLayerZoom(seed + 300, layerRiver); + layerRiver = new MapLayerZoom(seed + 400, layerRiver); + for (int i = 0; i < zoom; i++) { + layerRiver = new MapLayerZoom(seed + 500 + i, layerRiver); + } + layerRiver = new MapLayerRiver(seed + 10, layerRiver); + layer = new MapLayerRiver(seed + 1000, layerRiver, layer); + + MapLayer layerLowerRes = layer; + for (int i = 0; i < 2; i++) { + layer = new MapLayerZoom(seed + 2000 + i, layer); + } + + layer = new MapLayerSmooth(seed + 1001, layer); + + return new MapLayer[]{layer, layerLowerRes}; + } + + public void setCoordsSeed(int x, int z) { + this.random.setSeed(this.seed); + this.random.setSeed(x * this.random.nextInt() + z * this.random.nextInt() ^ this.seed); + } + + public int nextInt(int max) { + return this.random.nextBoundedInt(max); + } + + public abstract int[] generateValues(int x, int z, int sizeX, int sizeZ); +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiome.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiome.java new file mode 100644 index 0000000..9aa2b3a --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiome.java @@ -0,0 +1,64 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; + +public class MapLayerBiome extends MapLayer { + + private static final int[] WARM = new int[]{EnumBiome.DESERT.id, EnumBiome.DESERT.id, EnumBiome.DESERT.id, EnumBiome.SAVANNA.id, EnumBiome.SAVANNA.id, EnumBiome.PLAINS.id}; + private static final int[] WET = new int[]{EnumBiome.PLAINS.id, EnumBiome.PLAINS.id, EnumBiome.FOREST.id, EnumBiome.BIRCH_FOREST.id, EnumBiome.ROOFED_FOREST.id, EnumBiome.EXTREME_HILLS.id, EnumBiome.SWAMP.id}; + private static final int[] DRY = new int[]{EnumBiome.PLAINS.id, EnumBiome.FOREST.id, EnumBiome.TAIGA.id, EnumBiome.EXTREME_HILLS.id}; + private static final int[] COLD = new int[]{EnumBiome.ICE_PLAINS.id, EnumBiome.ICE_PLAINS.id, EnumBiome.COLD_TAIGA.id}; + private static final int[] WARM_LARGE = new int[]{EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU.id}; + private static final int[] DRY_LARGE = new int[]{EnumBiome.MEGA_TAIGA.id}; + private static final int[] WET_LARGE = new int[]{EnumBiome.JUNGLE.id, EnumBiome.JUNGLE.id, EnumBiome.BAMBOO_JUNGLE.id}; + + private final MapLayer belowLayer; + + public MapLayerBiome(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int[] values = this.belowLayer.generateValues(x, z, sizeX, sizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + int val = values[j + i * sizeX]; + if (val != 0) { + setCoordsSeed(x + j, z + i); + switch (val) { + case 1: + val = DRY[nextInt(DRY.length)]; + break; + case 2: + val = WARM[nextInt(WARM.length)]; + break; + case 3: + case 1003: + val = COLD[nextInt(COLD.length)]; + break; + case 4: + val = WET[nextInt(WET.length)]; + break; + case 1001: + val = DRY_LARGE[nextInt(DRY_LARGE.length)]; + break; + case 1002: + val = WARM_LARGE[nextInt(WARM_LARGE.length)]; + break; + case 1004: + val = WET_LARGE[nextInt(WET_LARGE.length)]; + break; + default: + break; + } + } + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeConstant.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeConstant.java new file mode 100644 index 0000000..a802346 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeConstant.java @@ -0,0 +1,22 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +public class MapLayerBiomeConstant extends MapLayer { + + private final int biome; + + public MapLayerBiomeConstant(long seed, int biome) { + super(seed); + this.biome = biome; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int[] values = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + values[j + i * sizeX] = biome; + } + } + return values; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdge.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdge.java new file mode 100644 index 0000000..c285deb --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdge.java @@ -0,0 +1,87 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; +import com.google.common.collect.Maps; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; + +import java.util.Map; +import java.util.Map.Entry; + +public class MapLayerBiomeEdge extends MapLayer { + + private static final Int2IntMap MESA_EDGES = new Int2IntOpenHashMap(); + private static final Int2IntMap MEGA_TAIGA_EDGES = new Int2IntOpenHashMap(); + private static final Int2IntMap DESERT_EDGES = new Int2IntOpenHashMap(); + private static final Int2IntMap SWAMP1_EDGES = new Int2IntOpenHashMap(); + private static final Int2IntMap SWAMP2_EDGES = new Int2IntOpenHashMap(); + private static final Map EDGES = Maps.newHashMap(); + + static { + MESA_EDGES.put(EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA.id); + MESA_EDGES.put(EnumBiome.MESA_PLATEAU.id, EnumBiome.MESA.id); + + MEGA_TAIGA_EDGES.put(EnumBiome.MEGA_TAIGA.id, EnumBiome.TAIGA.id); + + DESERT_EDGES.put(EnumBiome.DESERT.id, EnumBiome.EXTREME_HILLS_PLUS.id); + + SWAMP1_EDGES.put(EnumBiome.SWAMP.id, EnumBiome.PLAINS.id); + SWAMP2_EDGES.put(EnumBiome.SWAMP.id, EnumBiome.JUNGLE_EDGE.id); + + EDGES.put(MESA_EDGES, null); + EDGES.put(MEGA_TAIGA_EDGES, null); + EDGES.put(DESERT_EDGES, IntArrayList.wrap(new int[]{EnumBiome.ICE_PLAINS.id})); + EDGES.put(SWAMP1_EDGES, IntArrayList.wrap(new int[]{EnumBiome.DESERT.id, EnumBiome.COLD_TAIGA.id, EnumBiome.ICE_PLAINS.id})); + EDGES.put(SWAMP2_EDGES, IntArrayList.wrap(new int[]{EnumBiome.JUNGLE.id})); + } + + private final MapLayer belowLayer; + + public MapLayerBiomeEdge(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies biome large edges using Von Neumann neighborhood + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + int val = centerVal; + for (Entry entry : EDGES.entrySet()) { + Int2IntMap map = entry.getKey(); + if (map.containsKey(centerVal)) { + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + IntList entryValue = entry.getValue(); + if (entryValue == null && (!map.containsKey(upperVal) || !map.containsKey(lowerVal) || !map.containsKey(leftVal) || !map.containsKey(rightVal))) { + val = map.get(centerVal); + break; + } else if (entryValue != null && (entryValue.contains(upperVal) || entryValue.contains(lowerVal) || entryValue.contains(leftVal) || entryValue.contains(rightVal))) { + val = map.get(centerVal); + break; + } else if (centerVal == EnumBiome.DESERT.id && + (upperVal == EnumBiome.OCEAN.id || lowerVal == EnumBiome.OCEAN.id || leftVal == EnumBiome.OCEAN.id || rightVal == EnumBiome.OCEAN.id)) { + val = EnumBiome.WARM_OCEAN.id; + } + } + } + + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdgeThin.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdgeThin.java new file mode 100644 index 0000000..6f3ab95 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeEdgeThin.java @@ -0,0 +1,92 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; +import com.google.common.collect.Maps; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + +import java.util.Map; +import java.util.Map.Entry; + +public class MapLayerBiomeEdgeThin extends MapLayer { + + private static final IntSet OCEANS = new IntOpenHashSet(); + private static final Int2IntMap MESA_EDGES = new Int2IntOpenHashMap(); + private static final Int2IntMap JUNGLE_EDGES = new Int2IntOpenHashMap(); + private static final Map EDGES = Maps.newHashMap(); + + static { + OCEANS.add(EnumBiome.OCEAN.id); + OCEANS.add(EnumBiome.DEEP_OCEAN.id); + OCEANS.add(EnumBiome.WARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_WARM_OCEAN.id); + OCEANS.add(EnumBiome.LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.COLD_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_COLD_OCEAN.id); + + MESA_EDGES.put(EnumBiome.MESA.id, EnumBiome.DESERT.id); + MESA_EDGES.put(EnumBiome.MESA_BRYCE.id, EnumBiome.DESERT.id); + MESA_EDGES.put(EnumBiome.MESA_PLATEAU_F.id, EnumBiome.DESERT.id); + MESA_EDGES.put(EnumBiome.MESA_PLATEAU_F_M.id, EnumBiome.DESERT.id); + MESA_EDGES.put(EnumBiome.MESA_PLATEAU.id, EnumBiome.DESERT.id); + MESA_EDGES.put(EnumBiome.MESA_PLATEAU_M.id, EnumBiome.DESERT.id); + + JUNGLE_EDGES.put(EnumBiome.JUNGLE.id, EnumBiome.JUNGLE_EDGE.id); + JUNGLE_EDGES.put(EnumBiome.JUNGLE_HILLS.id, EnumBiome.JUNGLE_EDGE.id); + JUNGLE_EDGES.put(EnumBiome.JUNGLE_M.id, EnumBiome.JUNGLE_EDGE.id); + JUNGLE_EDGES.put(EnumBiome.JUNGLE_EDGE_M.id, EnumBiome.JUNGLE_EDGE.id); + + EDGES.put(MESA_EDGES, null); + EDGES.put(JUNGLE_EDGES, IntArrayList.wrap(new int[]{EnumBiome.JUNGLE.id, EnumBiome.JUNGLE_HILLS.id, EnumBiome.JUNGLE_M.id, EnumBiome.JUNGLE_EDGE_M.id, EnumBiome.FOREST.id, EnumBiome.TAIGA.id})); + } + + private final MapLayer belowLayer; + + public MapLayerBiomeEdgeThin(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies biome thin edges using Von Neumann neighborhood + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + int val = centerVal; + for (Entry entry : EDGES.entrySet()) { + Int2IntMap map = entry.getKey(); + if (map.containsKey(centerVal)) { + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + IntList entryValue = entry.getValue(); + if (entryValue == null && (!OCEANS.contains(upperVal) && !map.containsKey(upperVal) || !OCEANS.contains(lowerVal) && !map.containsKey(lowerVal) || !OCEANS.contains(leftVal) && !map.containsKey(leftVal) || !OCEANS.contains(rightVal) && !map.containsKey(rightVal))) { + val = map.get(centerVal); + break; + } else if (entryValue != null && (!OCEANS.contains(upperVal) && !entryValue.contains(upperVal) || !OCEANS.contains(lowerVal) && !entryValue.contains(lowerVal) || !OCEANS.contains(leftVal) && !entryValue.contains(leftVal) || !OCEANS.contains(rightVal) && !entryValue.contains(rightVal))) { + val = map.get(centerVal); + break; + } + } + } + + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeVariation.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeVariation.java new file mode 100644 index 0000000..8fceb47 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerBiomeVariation.java @@ -0,0 +1,158 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.Biome; +import cn.nukkit.level.biome.EnumBiome; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; + +public class MapLayerBiomeVariation extends MapLayer { + + private static final int[] ISLANDS = new int[]{EnumBiome.PLAINS.id, EnumBiome.FOREST.id}; + private static final Int2ObjectMap VARIATIONS = new Int2ObjectOpenHashMap<>(); + + static { + VARIATIONS.put(EnumBiome.DESERT.id, new int[]{EnumBiome.DESERT_HILLS.id}); + VARIATIONS.put(EnumBiome.FOREST.id, new int[]{EnumBiome.FOREST_HILLS.id}); + VARIATIONS.put(EnumBiome.BIRCH_FOREST.id, new int[]{EnumBiome.BIRCH_FOREST_HILLS.id}); + VARIATIONS.put(EnumBiome.ROOFED_FOREST.id, new int[]{EnumBiome.PLAINS.id}); + VARIATIONS.put(EnumBiome.TAIGA.id, new int[]{EnumBiome.TAIGA_HILLS.id}); + VARIATIONS.put(EnumBiome.MEGA_TAIGA.id, new int[]{EnumBiome.MEGA_TAIGA_HILLS.id}); + VARIATIONS.put(EnumBiome.COLD_TAIGA.id, new int[]{EnumBiome.COLD_TAIGA_HILLS.id}); + VARIATIONS.put(EnumBiome.PLAINS.id, new int[]{EnumBiome.FOREST.id, EnumBiome.FOREST.id, EnumBiome.FOREST_HILLS.id}); + VARIATIONS.put(EnumBiome.ICE_PLAINS.id, new int[]{EnumBiome.ICE_MOUNTAINS.id}); + VARIATIONS.put(EnumBiome.JUNGLE.id, new int[]{EnumBiome.JUNGLE_HILLS.id}); + VARIATIONS.put(EnumBiome.BAMBOO_JUNGLE.id, new int[]{EnumBiome.BAMBOO_JUNGLE_HILLS.id}); + VARIATIONS.put(EnumBiome.OCEAN.id, new int[]{EnumBiome.DEEP_OCEAN.id}); + VARIATIONS.put(EnumBiome.WARM_OCEAN.id, new int[]{EnumBiome.DEEP_WARM_OCEAN.id}); + VARIATIONS.put(EnumBiome.LUKEWARM_OCEAN.id, new int[]{EnumBiome.DEEP_LUKEWARM_OCEAN.id}); + VARIATIONS.put(EnumBiome.COLD_OCEAN.id, new int[]{EnumBiome.DEEP_COLD_OCEAN.id}); + VARIATIONS.put(EnumBiome.EXTREME_HILLS.id, new int[]{EnumBiome.EXTREME_HILLS_PLUS.id}); + VARIATIONS.put(EnumBiome.SAVANNA.id, new int[]{EnumBiome.SAVANNA_PLATEAU.id}); + VARIATIONS.put(EnumBiome.MESA_PLATEAU_F.id, new int[]{EnumBiome.MESA.id}); + VARIATIONS.put(EnumBiome.MESA_PLATEAU.id, new int[]{EnumBiome.MESA.id}); + VARIATIONS.put(EnumBiome.MESA.id, new int[]{EnumBiome.MESA.id}); + } + + private final MapLayer belowLayer; + private final MapLayer variationLayer; + + /** + * Creates an instance with no variation layer. + * @param seed the PRNG seed + * @param belowLayer the layer below this one + */ + public MapLayerBiomeVariation(long seed, MapLayer belowLayer) { + this(seed, belowLayer, null); + } + + /** + * Creates an instance with the given variation layer. + * @param seed the PRNG seed + * @param belowLayer the layer below this one + * @param variationLayer the variation layer, or null to use no variation layer + */ + public MapLayerBiomeVariation(long seed, MapLayer belowLayer, MapLayer variationLayer) { + super(seed); + this.belowLayer = belowLayer; + this.variationLayer = variationLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + if (this.variationLayer == null) { + return generateRandomValues(x, z, sizeX, sizeZ); + } + return mergeValues(x, z, sizeX, sizeZ); + } + + /** + * Generates a rectangle, replacing all the positive values in the previous layer with random + * values from 2 to 31 while leaving zero and negative values unchanged. + * + * @param x the lowest x coordinate + * @param z the lowest z coordinate + * @param sizeX the x coordinate range + * @param sizeZ the z coordinate range + * @return a flattened array of generated values + */ + public int[] generateRandomValues(int x, int z, int sizeX, int sizeZ) { + int[] values = this.belowLayer.generateValues(x, z, sizeX, sizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + int val = values[j + i * sizeX]; + if (val > 0) { + setCoordsSeed(x + j, z + i); + val = nextInt(30) + 2; + } + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } + + /** + * Generates a rectangle using the previous layer and the variation layer. + * + * @param x the lowest x coordinate + * @param z the lowest z coordinate + * @param sizeX the x coordinate range + * @param sizeZ the z coordinate range + * @return a flattened array of generated values + */ + public int[] mergeValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + int[] variationValues = this.variationLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + setCoordsSeed(x + j, z + i); + int centerValue = values[j + 1 + (i + 1) * gridSizeX]; + int variationValue = variationValues[j + 1 + (i + 1) * gridSizeX]; + if (centerValue != 0 && variationValue == 3 && centerValue < 128) { + finalValues[j + i * sizeX] = Biome.biomes[centerValue + 128] != null ? centerValue + 128 : centerValue; + } else if (variationValue == 2 || nextInt(3) == 0) { + int val = centerValue; + if (VARIATIONS.containsKey(centerValue)) { + val = VARIATIONS.get(centerValue)[nextInt(VARIATIONS.get(centerValue).length)]; + } else if ((centerValue == EnumBiome.DEEP_OCEAN.id || centerValue == EnumBiome.DEEP_COLD_OCEAN.id || centerValue == EnumBiome.DEEP_WARM_OCEAN.id || centerValue == EnumBiome.DEEP_LUKEWARM_OCEAN.id || centerValue == EnumBiome.DEEP_FROZEN_OCEAN.id) + && nextInt(3) == 0) { + val = ISLANDS[nextInt(ISLANDS.length)]; + } + if (variationValue == 2 && val != centerValue) { + val = Biome.biomes[val + 128] != null ? val + 128 : centerValue; + } + if (val != centerValue) { + int count = 0; + if (values[j + 1 + i * gridSizeX] == centerValue) { // upper value + count++; + } + if (values[j + 1 + (i + 2) * gridSizeX] == centerValue) { // lower value + count++; + } + if (values[j + (i + 1) * gridSizeX] == centerValue) { // left value + count++; + } + if (values[j + 2 + (i + 1) * gridSizeX] == centerValue) { // right value + count++; + } + // spread mountains if not too close from an edge + finalValues[j + i * sizeX] = count < 3 ? centerValue : val; + } else { + finalValues[j + i * sizeX] = val; + } + } else { + finalValues[j + i * sizeX] = centerValue; + } + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerDeepOcean.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerDeepOcean.java new file mode 100644 index 0000000..8456e37 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerDeepOcean.java @@ -0,0 +1,51 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; + +public class MapLayerDeepOcean extends MapLayer { + + private final MapLayer belowLayer; + + public MapLayerDeepOcean(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies deep oceans using Von Neumann neighborhood + // it takes a 3x3 grid with a cross shape and analyzes values as follow + // OXO + // XxX + // OXO + // the grid center value decides how we are proceeding: + // - if it's ocean and it's surrounded by 4 ocean cells we spread deep ocean. + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + if (centerVal == 0) { + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + if (upperVal == 0 && lowerVal == 0 && leftVal == 0 && rightVal == 0) { + setCoordsSeed(x + j, z + i); + finalValues[j + i * sizeX] = nextInt(100) == 0 ? EnumBiome.MUSHROOM_ISLAND.id : EnumBiome.DEEP_OCEAN.id; + } else { + finalValues[j + i * sizeX] = centerVal; + } + } else { + finalValues[j + i * sizeX] = centerVal; + } + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerErosion.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerErosion.java new file mode 100644 index 0000000..1c023ff --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerErosion.java @@ -0,0 +1,53 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +public class MapLayerErosion extends MapLayer { + + private final MapLayer belowLayer; + + public MapLayerErosion(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies erosion using Rotated Von Neumann neighborhood + // it takes a 3x3 grid with a cross shape and analyzes values as follow + // XOX + // OXO + // XOX + // the grid center value decides how we are proceeding: + // - if it's land and it's surrounded by at least 1 ocean cell there are 4/5 chances to proceed to land weathering, and 1/5 chance to spread some land. + // - if it's ocean and it's surrounded by at least 1 land cell, there are 2/3 chances to proceed to land weathering, and 1/3 chance to spread some land. + int upperLeftVal = values[j + i * gridSizeX]; + int lowerLeftVal = values[j + (i + 2) * gridSizeX]; + int upperRightVal = values[j + 2 + i * gridSizeX]; + int lowerRightVal = values[j + 2 + (i + 2) * gridSizeX]; + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + + setCoordsSeed(x + j, z + i); + if (centerVal != 0 && (upperLeftVal == 0 || upperRightVal == 0 || lowerLeftVal == 0 || lowerRightVal == 0)) { + finalValues[j + i * sizeX] = nextInt(5) == 0 ? 0 : centerVal; + } else if (centerVal == 0 && (upperLeftVal != 0 || upperRightVal != 0 || lowerLeftVal != 0 || lowerRightVal != 0)) { + if (nextInt(3) == 0) { + finalValues[j + i * sizeX] = upperLeftVal; + } else { + finalValues[j + i * sizeX] = 0; + } + } else { + finalValues[j + i * sizeX] = centerVal; + } + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerNoise.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerNoise.java new file mode 100644 index 0000000..24151fa --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerNoise.java @@ -0,0 +1,33 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import worldgeneratorextension.vanillagenerator.noise.bukkit.SimplexOctaveGenerator; + +public class MapLayerNoise extends MapLayer { + + private final SimplexOctaveGenerator noiseGen; + + public MapLayerNoise(long seed) { + super(seed); + this.noiseGen = new SimplexOctaveGenerator(seed, 2); + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int[] values = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + double noise = this.noiseGen.noise(x + j, z + i, 0.175D, 0.8D, true) * 4.0D; + int val; + if (noise >= 0.05D) { + val = noise <= 0.2D ? 3 : 2; + } else { + setCoordsSeed(x + j, z + i); + val = nextInt(2) == 0 ? 3 : 0; + } + values[j + i * sizeX] = val; + //values[j + i * sizeX] = noise >= -0.5D ? (double) noise >= 0.57D ? 2 : noise <= 0.2D ? 3 : 2 : nextInt(2) == 0 ? 3 : 0; + } + } + return values; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRarePlains.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRarePlains.java new file mode 100644 index 0000000..e025ae4 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRarePlains.java @@ -0,0 +1,44 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; + +public class MapLayerRarePlains extends MapLayer { + + private static final Int2IntMap RARE_PLAINS = new Int2IntOpenHashMap(); + + static { + RARE_PLAINS.put(EnumBiome.PLAINS.id, EnumBiome.SUNFLOWER_PLAINS.id); + } + + private final MapLayer belowLayer; + + public MapLayerRarePlains(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + setCoordsSeed(x + j, z + i); + int centerValue = values[j + 1 + (i + 1) * gridSizeX]; + if (nextInt(57) == 0 && RARE_PLAINS.containsKey(centerValue)) { + centerValue = RARE_PLAINS.get(centerValue); + } + finalValues[j + i * sizeX] = centerValue; + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRiver.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRiver.java new file mode 100644 index 0000000..5791298 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerRiver.java @@ -0,0 +1,106 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + +public class MapLayerRiver extends MapLayer { + + private static final IntSet OCEANS = new IntOpenHashSet(); + private static final Int2IntMap SPECIAL_RIVERS = new Int2IntOpenHashMap(); + private static final int CLEAR_VALUE = 0; + private static final int RIVER_VALUE = 1; + + static { + OCEANS.add(EnumBiome.OCEAN.id); + OCEANS.add(EnumBiome.DEEP_OCEAN.id); + OCEANS.add(EnumBiome.WARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_WARM_OCEAN.id); + OCEANS.add(EnumBiome.LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.COLD_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_COLD_OCEAN.id); + + SPECIAL_RIVERS.put(EnumBiome.ICE_PLAINS.id, EnumBiome.FROZEN_RIVER.id); + SPECIAL_RIVERS.put(EnumBiome.MUSHROOM_ISLAND.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + SPECIAL_RIVERS.put(EnumBiome.MUSHROOM_ISLAND_SHORE.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + } + + private final MapLayer belowLayer; + private final MapLayer mergeLayer; + + public MapLayerRiver(long seed, MapLayer belowLayer) { + this(seed, belowLayer, null); + } + + /** + * Creates a map layer that generates rivers. + * + * @param seed the layer's PRNG seed + * @param belowLayer the layer to apply before this one + * @param mergeLayer + */ + public MapLayerRiver(long seed, MapLayer belowLayer, MapLayer mergeLayer) { + super(seed); + this.belowLayer = belowLayer; + this.mergeLayer = mergeLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + if (this.mergeLayer == null) { + return generateRivers(x, z, sizeX, sizeZ); + } + return mergeRivers(x, z, sizeX, sizeZ); + } + + private int[] generateRivers(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies rivers using Von Neumann neighborhood + int centerVal = values[j + 1 + (i + 1) * gridSizeX] & 1; + int upperVal = values[j + 1 + i * gridSizeX] & 1; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX] & 1; + int leftVal = values[j + (i + 1) * gridSizeX] & 1; + int rightVal = values[j + 2 + (i + 1) * gridSizeX] & 1; + int val = CLEAR_VALUE; + if (centerVal != upperVal || centerVal != lowerVal || centerVal != leftVal || centerVal != rightVal) { + val = RIVER_VALUE; + } + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } + + private int[] mergeRivers(int x, int z, int sizeX, int sizeZ) { + int[] values = this.belowLayer.generateValues(x, z, sizeX, sizeZ); + int[] mergeValues = this.mergeLayer.generateValues(x, z, sizeX, sizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeX * sizeZ; i++) { + int val = mergeValues[i]; + if (OCEANS.contains(mergeValues[i])) { + val = mergeValues[i]; + } else if (values[i] == RIVER_VALUE) { + if (SPECIAL_RIVERS.containsKey(mergeValues[i])) { + val = SPECIAL_RIVERS.get(mergeValues[i]); + } else { + val = EnumBiome.RIVER.id; + } + } + finalValues[i] = val; + } + + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerShore.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerShore.java new file mode 100644 index 0000000..81401c0 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerShore.java @@ -0,0 +1,83 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import cn.nukkit.level.biome.EnumBiome; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; + +public class MapLayerShore extends MapLayer { + + private static final IntSet OCEANS = new IntOpenHashSet(); + private static final Int2IntMap SPECIAL_SHORES = new Int2IntOpenHashMap(); + + static { + OCEANS.add(EnumBiome.OCEAN.id); + OCEANS.add(EnumBiome.DEEP_OCEAN.id); + OCEANS.add(EnumBiome.WARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_WARM_OCEAN.id); + OCEANS.add(EnumBiome.LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_LUKEWARM_OCEAN.id); + OCEANS.add(EnumBiome.COLD_OCEAN.id); + OCEANS.add(EnumBiome.DEEP_COLD_OCEAN.id); + + SPECIAL_SHORES.put(EnumBiome.EXTREME_HILLS.id, EnumBiome.STONE_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.EXTREME_HILLS_PLUS.id, EnumBiome.STONE_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.EXTREME_HILLS_M.id, EnumBiome.STONE_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.EXTREME_HILLS_PLUS_M.id, EnumBiome.STONE_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.ICE_PLAINS.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.ICE_MOUNTAINS.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.ICE_PLAINS_SPIKES.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.COLD_TAIGA.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.COLD_TAIGA_HILLS.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.COLD_TAIGA_M.id, EnumBiome.COLD_BEACH.id); + SPECIAL_SHORES.put(EnumBiome.MUSHROOM_ISLAND.id, EnumBiome.MUSHROOM_ISLAND_SHORE.id); + SPECIAL_SHORES.put(EnumBiome.SWAMP.id, EnumBiome.SWAMP.id); + SPECIAL_SHORES.put(EnumBiome.MESA.id, EnumBiome.MESA.id); + SPECIAL_SHORES.put(EnumBiome.MESA_PLATEAU_F.id, EnumBiome.MESA_PLATEAU_F.id); + SPECIAL_SHORES.put(EnumBiome.MESA_PLATEAU_F_M.id, EnumBiome.MESA_PLATEAU_F_M.id); + SPECIAL_SHORES.put(EnumBiome.MESA_PLATEAU.id, EnumBiome.MESA_PLATEAU.id); + SPECIAL_SHORES.put(EnumBiome.MESA_PLATEAU_M.id, EnumBiome.MESA_PLATEAU_M.id); + SPECIAL_SHORES.put(EnumBiome.MESA_BRYCE.id, EnumBiome.MESA_BRYCE.id); + } + + private final MapLayer belowLayer; + + public MapLayerShore(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies shores using Von Neumann neighborhood + // it takes a 3x3 grid with a cross shape and analyzes values as follow + // OXO + // XxX + // OXO + // the grid center value decides how we are proceeding: + // - if it's not ocean and it's surrounded by at least 1 ocean cell it turns the center value into beach. + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + if (!OCEANS.contains(centerVal) && (OCEANS.contains(upperVal) || OCEANS.contains(lowerVal) || OCEANS.contains(leftVal) || OCEANS.contains(rightVal))) { + finalValues[j + i * sizeX] = SPECIAL_SHORES.containsKey(centerVal) ? SPECIAL_SHORES.get(centerVal) : EnumBiome.BEACH.id; + } else { + finalValues[j + i * sizeX] = centerVal; + } + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerSmooth.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerSmooth.java new file mode 100644 index 0000000..90df932 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerSmooth.java @@ -0,0 +1,47 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +public class MapLayerSmooth extends MapLayer { + + private final MapLayer belowLayer; + + public MapLayerSmooth(long seed, MapLayer belowLayer) { + super(seed); + this.belowLayer = belowLayer; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = this.belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + // This applies smoothing using Von Neumann neighborhood + // it takes a 3x3 grid with a cross shape and analyzes values as follow + // OXO + // XxX + // OXO + // it is required that we use the same shape that was used for what we want to smooth + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + if (upperVal == lowerVal && leftVal == rightVal) { + setCoordsSeed(x + j, z + i); + centerVal = nextInt(2) == 0 ? upperVal : leftVal; + } else if (upperVal == lowerVal) { + centerVal = upperVal; + } else if (leftVal == rightVal) { + centerVal = leftVal; + } + finalValues[j + i * sizeX] = centerVal; + } + } + return finalValues; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerWhittaker.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerWhittaker.java new file mode 100644 index 0000000..e8adbb6 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerWhittaker.java @@ -0,0 +1,107 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +import com.google.common.collect.Maps; + +import java.util.Map; + +public class MapLayerWhittaker extends MapLayer { + + private static final Map MAP = Maps.newEnumMap(ClimateType.class); + + static { + MAP.put(ClimateType.WARM_WET, new Climate(2, new int[]{3, 1}, 4)); + MAP.put(ClimateType.COLD_DRY, new Climate(3, new int[]{2, 4}, 1)); + } + + private final MapLayer belowLayer; + private final ClimateType type; + + /** + * Creates a map layer. + * + * @param seed the layer random seed + * @param belowLayer the layer generated before this one + * @param type the climate-type parameter + */ + public MapLayerWhittaker(long seed, MapLayer belowLayer, ClimateType type) { + super(seed); + this.belowLayer = belowLayer; + this.type = type; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + if (type == ClimateType.WARM_WET || type == ClimateType.COLD_DRY) { + return swapValues(x, z, sizeX, sizeZ); + } else { + return modifyValues(x, z, sizeX, sizeZ); + } + } + + private int[] swapValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x - 1; + int gridZ = z - 1; + int gridSizeX = sizeX + 2; + int gridSizeZ = sizeZ + 2; + int[] values = belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + Climate climate = MAP.get(type); + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + int centerVal = values[j + 1 + (i + 1) * gridSizeX]; + if (centerVal == climate.value) { + int upperVal = values[j + 1 + i * gridSizeX]; + int lowerVal = values[j + 1 + (i + 2) * gridSizeX]; + int leftVal = values[j + (i + 1) * gridSizeX]; + int rightVal = values[j + 2 + (i + 1) * gridSizeX]; + for (int type : climate.crossTypes) { + if (upperVal == type || lowerVal == type || leftVal == type || rightVal == type) { + centerVal = climate.finalValue; + break; + } + } + } + finalValues[j + i * sizeX] = centerVal; + } + } + return finalValues; + } + + private int[] modifyValues(int x, int z, int sizeX, int sizeZ) { + int[] values = belowLayer.generateValues(x, z, sizeX, sizeZ); + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + int val = values[j + i * sizeX]; + if (val != 0) { + setCoordsSeed(x + j, z + i); + if (nextInt(13) == 0) { + val += 1000; + } + } + finalValues[j + i * sizeX] = val; + } + } + return finalValues; + } + + public enum ClimateType { + WARM_WET, + COLD_DRY, + LARGER_BIOMES + } + + private static class Climate { + + public final int value; + public final int[] crossTypes; + public final int finalValue; + + public Climate(int value, int[] crossTypes, int finalValue) { + this.value = value; + this.crossTypes = crossTypes; + this.finalValue = finalValue; + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerZoom.java b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerZoom.java new file mode 100644 index 0000000..aa0e110 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/biomegrid/MapLayerZoom.java @@ -0,0 +1,95 @@ +package worldgeneratorextension.vanillagenerator.biomegrid; + +public class MapLayerZoom extends MapLayer { + + private final MapLayer belowLayer; + private final ZoomType zoomType; + + public MapLayerZoom(long seed, MapLayer belowLayer) { + this(seed, belowLayer, ZoomType.NORMAL); + } + + /** + * Creates a map layer. + * + * @param seed the layer random seed + * @param belowLayer the layer generated before this one + * @param zoomType the zoom-type parameter + */ + public MapLayerZoom(long seed, MapLayer belowLayer, ZoomType zoomType) { + super(seed); + this.belowLayer = belowLayer; + this.zoomType = zoomType; + } + + @Override + public int[] generateValues(int x, int z, int sizeX, int sizeZ) { + int gridX = x >> 1; + int gridZ = z >> 1; + int gridSizeX = (sizeX >> 1) + 2; + int gridSizeZ = (sizeZ >> 1) + 2; + int[] values = belowLayer.generateValues(gridX, gridZ, gridSizeX, gridSizeZ); + + int zoomSizeX = gridSizeX - 1 << 1; + int zoomSizeZ = gridSizeZ - 1 << 1; + int[] tmpValues = new int[zoomSizeX * zoomSizeZ]; + for (int i = 0; i < gridSizeZ - 1; i++) { + int n = i * 2 * zoomSizeX; + int upperLeftVal = values[i * gridSizeX]; + int lowerLeftVal = values[(i + 1) * gridSizeX]; + for (int j = 0; j < gridSizeX - 1; j++) { + setCoordsSeed(gridX + j << 1, gridZ + i << 1); + tmpValues[n] = upperLeftVal; + tmpValues[n + zoomSizeX] = nextInt(2) > 0 ? upperLeftVal : lowerLeftVal; + int upperRightVal = values[j + 1 + i * gridSizeX]; + int lowerRightVal = values[j + 1 + (i + 1) * gridSizeX]; + tmpValues[n + 1] = nextInt(2) > 0 ? upperLeftVal : upperRightVal; + tmpValues[n + 1 + zoomSizeX] = getNearest(upperLeftVal, upperRightVal, lowerLeftVal, lowerRightVal); + upperLeftVal = upperRightVal; + lowerLeftVal = lowerRightVal; + n += 2; + } + } + int[] finalValues = new int[sizeX * sizeZ]; + for (int i = 0; i < sizeZ; i++) { + for (int j = 0; j < sizeX; j++) { + finalValues[j + i * sizeX] = tmpValues[j + (i + (z & 1)) * zoomSizeX + (x & 1)]; + } + } + + return finalValues; + } + + private int getNearest(int upperLeftVal, int upperRightVal, int lowerLeftVal, int lowerRightVal) { + if (zoomType == ZoomType.NORMAL) { + if (upperRightVal == lowerLeftVal && lowerLeftVal == lowerRightVal) { + return upperRightVal; + } else if (upperLeftVal == upperRightVal && upperLeftVal == lowerLeftVal) { + return upperLeftVal; + } else if (upperLeftVal == upperRightVal && upperLeftVal == lowerRightVal) { + return upperLeftVal; + } else if (upperLeftVal == lowerLeftVal && upperLeftVal == lowerRightVal) { + return upperLeftVal; + } else if (upperLeftVal == upperRightVal && lowerLeftVal != lowerRightVal) { + return upperLeftVal; + } else if (upperLeftVal == lowerLeftVal && upperRightVal != lowerRightVal) { + return upperLeftVal; + } else if (upperLeftVal == lowerRightVal && upperRightVal != lowerLeftVal) { + return upperLeftVal; + } else if (upperRightVal == lowerLeftVal && upperLeftVal != lowerRightVal) { + return upperRightVal; + } else if (upperRightVal == lowerRightVal && upperLeftVal != lowerLeftVal) { + return upperRightVal; + } else if (lowerLeftVal == lowerRightVal && upperLeftVal != upperRightVal) { + return lowerLeftVal; + } + } + int[] values = new int[]{upperLeftVal, upperRightVal, lowerLeftVal, lowerRightVal}; + return values[nextInt(values.length)]; + } + + public enum ZoomType { + NORMAL, + BLURRY + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGenerator.java new file mode 100644 index 0000000..326477f --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGenerator.java @@ -0,0 +1,101 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.block.Block; +import cn.nukkit.block.BlockID; +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.biome.BiomeClimate; + +public class GroundGenerator implements BlockID { + + protected int topMaterial; + protected int topData; + protected int groundMaterial; + protected int groundData; + + public GroundGenerator() { + setTopMaterial(GRASS); + setGroundMaterial(DIRT); + } + + /** + * Generates a terrain column. + * + * @param chunkData the affected chunk + * @param world the affected world + * @param random the PRNG to use + * @param chunkX the chunk X coordinate + * @param chunkZ the chunk Z coordinate + * @param biome the biome this column is in + * @param surfaceNoise the amplitude of random variation in surface height + */ + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + int seaLevel = 64; + + int topMat = this.topMaterial; + int groundMat = this.groundMaterial; + + int x = chunkX & 0xF; + int z = chunkZ & 0xF; + + int surfaceHeight = Math.max((int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D), 1); + int deep = -1; + for (int y = 255; y >= 0; y--) { + if (y <= random.nextBoundedInt(5)) { + chunkData.setBlock(x, y, z, BEDROCK); + } else { + int mat = chunkData.getBlockId(x, y, z); + if (mat == AIR) { + deep = -1; + } else if (mat == STONE) { + if (deep == -1) { + if (y >= seaLevel - 5 && y <= seaLevel) { + topMat = this.topMaterial; + groundMat = this.groundMaterial; + } + + deep = surfaceHeight; + if (y >= seaLevel - 2) { + chunkData.setBlock(x, y, z, topMat, this.topData); + } else if (y < seaLevel - 8 - surfaceHeight) { + topMat = AIR; + groundMat = STONE; + chunkData.setBlock(x, y, z, GRAVEL); + } else { + chunkData.setBlock(x, y, z, groundMat, this.groundData); + } + } else if (deep > 0) { + deep--; + chunkData.setBlock(x, y, z, groundMat, this.groundData); + + if (deep == 0 && groundMat == SAND) { + deep = random.nextBoundedInt(4) + Math.max(0, y - seaLevel - 1); + groundMat = SANDSTONE; + } + } + } else if (mat == Block.STILL_WATER && y == seaLevel - 2 && BiomeClimate.isCold(biome, chunkX, y, chunkZ)) { + chunkData.setBlock(x, y, z, ICE); + } + } + } + } + + protected final void setTopMaterial(int topMaterial) { + this.setTopMaterial(topMaterial, 0); + } + + protected final void setTopMaterial(int topMaterial, int topData) { + this.topMaterial = topMaterial; + this.topData = topData; + } + + protected final void setGroundMaterial(int groundMaterial) { + this.setGroundMaterial(groundMaterial, 0); + } + + protected final void setGroundMaterial(int groundMaterial, int groundData) { + this.groundMaterial = groundMaterial; + this.groundData = groundData; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMesa.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMesa.java new file mode 100644 index 0000000..68075c3 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMesa.java @@ -0,0 +1,173 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.noise.SimplexOctaveGenerator; + +import java.util.Arrays; + +import static worldgeneratorextension.vanillagenerator.NormalGenerator.SEA_LEVEL; + +public class GroundGeneratorMesa extends GroundGenerator { + + private final MesaType type; + private final int[] colorLayer = new int[64]; + private SimplexOctaveGenerator colorNoise; + private SimplexOctaveGenerator canyonHeightNoise; + private SimplexOctaveGenerator canyonScaleNoise; + private long seed; + + public GroundGeneratorMesa() { + this(MesaType.NORMAL); + } + + /** + * Creates a ground generator for mesa biomes. + * + * @param type the type of mesa biome to generate + */ + public GroundGeneratorMesa(MesaType type) { + this.type = type; + } + + private void initialize(long seed) { + if (seed != this.seed || this.colorNoise == null || this.canyonScaleNoise == null || this.canyonHeightNoise == null) { + NukkitRandom random = new NukkitRandom(seed); + this.colorNoise = new SimplexOctaveGenerator(random, 1); + this.colorNoise.setScale(1 / 512.0D); + this.initializeColorLayers(random); + + this.canyonHeightNoise = new SimplexOctaveGenerator(random, 4); + this.canyonHeightNoise.setScale(1 / 4.0D); + this.canyonScaleNoise = new SimplexOctaveGenerator(random, 1); + this.canyonScaleNoise.setScale(1 / 512.0D); + this.seed = seed; + } + } + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + this.initialize(world.getSeed()); + + int surfaceHeight = Math.max((int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D), 1); + boolean colored = Math.cos(surfaceNoise / 3.0D * Math.PI) <= 0; + double bryceCanyonHeight = 0; + if (type == MesaType.BRYCE) { + int noiseX = (chunkX & 0xFFFFFFF0) + (chunkZ & 0xF); + int noiseZ = (chunkZ & 0xFFFFFFF0) + (chunkX & 0xF); + double noiseCanyonHeight = Math.min(Math.abs(surfaceNoise), this.canyonHeightNoise.noise(noiseX, noiseZ, 0.5D, 2.0D)); + if (noiseCanyonHeight > 0) { + double heightScale = Math.abs(this.canyonScaleNoise.noise(noiseX, noiseZ, 0.5D, 2.0D)); + bryceCanyonHeight = Math.pow(noiseCanyonHeight, 2) * 2.5D; + double maxHeight = Math.ceil(50 * heightScale) + 14; + if (bryceCanyonHeight > maxHeight) { + bryceCanyonHeight = maxHeight; + } + bryceCanyonHeight += SEA_LEVEL; + } + } + + int x = chunkX & 0xF; + int z = chunkZ & 0xF; + + int deep = -1; + boolean groundSet = false; + for (int y = 255; y >= 0; y--) { + if (y < (int) bryceCanyonHeight && chunkData.getBlockId(x, y, z) == AIR) { + chunkData.setBlock(x, y, z, STONE); + } + if (y <= random.nextBoundedInt(5)) { + chunkData.setBlock(x, y, z, BEDROCK); + } else { + int mat = chunkData.getBlockId(x, y, z); + if (mat == AIR) { + deep = -1; + } else if (mat == STONE) { // revert 9747d77 -- hennick + if (deep == -1) { + groundSet = false; + //if (y >= SEA_LEVEL - 5 && y <= SEA_LEVEL) { + // groundMat = this.groundMaterial; + //} + + deep = surfaceHeight + Math.max(0, y - SEA_LEVEL - 1); + if (y >= SEA_LEVEL - 2) { + if (type == MesaType.FOREST && y > SEA_LEVEL + 22 + (surfaceHeight << 1)) { + int topMat = colored ? GRASS : DIRT; + int topData = colored ? 0 : 1; + chunkData.setBlock(x, y, z, topMat, topData); + } else if (y > SEA_LEVEL + 2 + surfaceHeight) { + int color = this.colorLayer[(y + (int) Math.round(this.colorNoise.noise(chunkX, chunkZ, 0.5D, 2.0D) * 2.0D)) % this.colorLayer.length]; + this.setColoredGroundLayer(chunkData, x, y, z, y < SEA_LEVEL || y > 128 ? 1 : colored ? color : -1); + } else { + chunkData.setBlock(x, y, z, SAND, 1); + groundSet = true; + } + } else { + chunkData.setBlock(x, y, z, STAINED_HARDENED_CLAY, 1); + } + } else if (deep > 0) { + deep--; + if (groundSet) { + chunkData.setBlock(x, y, z, STAINED_HARDENED_CLAY, 1); + } else { + int color = this.colorLayer[(y + (int) Math.round(this.colorNoise.noise(chunkX, chunkZ, 0.5D, 2.0D) * 2.0D)) % this.colorLayer.length]; + this.setColoredGroundLayer(chunkData, x, y, z, color); + } + } + } + } + } + } + + private void setColoredGroundLayer(BaseFullChunk chunkData, int x, int y, int z, int color) { + if (color >= 0) { + chunkData.setBlock(x, y, z, STAINED_HARDENED_CLAY, color & 0xf); + } else { + chunkData.setBlock(x, y, z, TERRACOTTA); + } + } + + private void setRandomLayerColor(NukkitRandom random, int minLayerCount, int minLayerHeight, int color) { + for (int i = 0; i < random.nextBoundedInt(4) + minLayerCount; i++) { + int j = random.nextBoundedInt(this.colorLayer.length); + int k = 0; + while (k < random.nextBoundedInt(3) + minLayerHeight && j < this.colorLayer.length) { + this.colorLayer[j++] = color; + k++; + } + } + } + + private void initializeColorLayers(NukkitRandom random) { + Arrays.fill(this.colorLayer, -1); // hard clay, other values are stained clay + int i = 0; + while (i < this.colorLayer.length) { + i += random.nextBoundedInt(5) + 1; + if (i < this.colorLayer.length) { + this.colorLayer[i++] = 1; // orange + } + } + this.setRandomLayerColor(random, 2, 1, 4); // yellow + this.setRandomLayerColor(random, 2, 2, 12); // brown + this.setRandomLayerColor(random, 2, 1, 14); // red + int j = 0; + for (i = 0; i < random.nextBoundedInt(3) + 3; i++) { + j += random.nextBoundedInt(16) + 4; + if (j >= this.colorLayer.length) { + break; + } + if (random.nextBoundedInt(2) == 0 || j < this.colorLayer.length - 1 && random.nextBoundedInt(2) == 0) { + this.colorLayer[j - 1] = 8; // light gray + } else { + this.colorLayer[j] = 0; // white + } + } + } + + public enum MesaType { + NORMAL, + BRYCE, + FOREST + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMycel.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMycel.java new file mode 100644 index 0000000..32292f3 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorMycel.java @@ -0,0 +1,8 @@ +package worldgeneratorextension.vanillagenerator.ground; + +public class GroundGeneratorMycel extends GroundGenerator { + + public GroundGeneratorMycel() { + setTopMaterial(MYCELIUM); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirt.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirt.java new file mode 100644 index 0000000..d70b258 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirt.java @@ -0,0 +1,22 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorPatchDirt extends GroundGenerator { + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + if (surfaceNoise > 1.75D) { + setTopMaterial(DIRT, 1); + } else if (surfaceNoise > -0.95D) { + setTopMaterial(PODZOL); + } else { + setTopMaterial(GRASS); + } + setGroundMaterial(DIRT); + + super.generateTerrainColumn(world, chunkData, random, chunkX, chunkZ, biome, surfaceNoise); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirtAndStone.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirtAndStone.java new file mode 100644 index 0000000..97c08b8 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchDirtAndStone.java @@ -0,0 +1,24 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorPatchDirtAndStone extends GroundGenerator { + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + if (surfaceNoise > 1.75D) { + setTopMaterial(STONE); + setGroundMaterial(STONE); + } else if (surfaceNoise > -0.5D) { + setTopMaterial(DIRT, 1); + setGroundMaterial(DIRT); + } else { + setTopMaterial(GRASS); + setGroundMaterial(DIRT); + } + + super.generateTerrainColumn(world, chunkData, random, chunkX, chunkZ, biome, surfaceNoise); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchGravel.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchGravel.java new file mode 100644 index 0000000..027e74b --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchGravel.java @@ -0,0 +1,20 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorPatchGravel extends GroundGenerator { + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + if (surfaceNoise < -1.0D || surfaceNoise > 2.0D) { + setTopMaterial(GRAVEL); + setGroundMaterial(GRAVEL); + } else { + setTopMaterial(GRASS); + setGroundMaterial(DIRT); + } + super.generateTerrainColumn(world, chunkData, random, chunkX, chunkZ, biome, surfaceNoise); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchPodzol.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchPodzol.java new file mode 100644 index 0000000..128d4b0 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchPodzol.java @@ -0,0 +1,20 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorPatchPodzol extends GroundGenerator { + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + if (surfaceNoise > -0.95D) { + setTopMaterial(PODZOL); + } else { + setTopMaterial(GRASS); + } + setGroundMaterial(DIRT); + + super.generateTerrainColumn(world, chunkData, random, chunkX, chunkZ, biome, surfaceNoise); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchStone.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchStone.java new file mode 100644 index 0000000..e0326c7 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorPatchStone.java @@ -0,0 +1,20 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorPatchStone extends GroundGenerator { + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + if (surfaceNoise > 1.0D) { + setTopMaterial(STONE); + setGroundMaterial(STONE); + } else { + setTopMaterial(GRASS); + setGroundMaterial(DIRT); + } + super.generateTerrainColumn(world, chunkData, random, chunkX, chunkZ, biome, surfaceNoise); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorRocky.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorRocky.java new file mode 100644 index 0000000..86e1f68 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorRocky.java @@ -0,0 +1,9 @@ +package worldgeneratorextension.vanillagenerator.ground; + +public class GroundGeneratorRocky extends GroundGenerator { + + public GroundGeneratorRocky() { + setTopMaterial(STONE); + setGroundMaterial(STONE); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandOcean.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandOcean.java new file mode 100644 index 0000000..1f9d021 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandOcean.java @@ -0,0 +1,63 @@ +package worldgeneratorextension.vanillagenerator.ground; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.generic.BaseFullChunk; +import cn.nukkit.math.NukkitRandom; + +public class GroundGeneratorSandOcean extends GroundGenerator { + + public GroundGeneratorSandOcean() { + setTopMaterial(SAND); + setGroundMaterial(SANDSTONE); + } + + @Override + public void generateTerrainColumn(ChunkManager world, BaseFullChunk chunkData, NukkitRandom random, int chunkX, int chunkZ, int biome, double surfaceNoise) { + int seaLevel = 64; + + int topMat = this.topMaterial; + int groundMat = this.groundMaterial; + + int x = chunkX & 0xF; + int z = chunkZ & 0xF; + + int surfaceHeight = Math.max((int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D), 1); + int deep = -1; + for (int y = 255; y >= 0; y--) { + if (y <= random.nextBoundedInt(5)) { + chunkData.setBlock(x, y, z, BEDROCK); + } else { + int mat = chunkData.getBlockId(x, y, z); + if (mat == AIR) { + deep = -1; + } else if (mat == STONE) { + if (deep == -1) { + if (y >= seaLevel - 5 && y <= seaLevel) { + topMat = this.topMaterial; + groundMat = this.groundMaterial; + } + + deep = surfaceHeight; + if (y >= seaLevel - 2) { + chunkData.setBlock(x, y, z, topMat, this.topData); + } else if (y < seaLevel - 8 - surfaceHeight) { + topMat = AIR; + groundMat = STONE; + chunkData.setBlock(x, y, z, SAND); + } else { + chunkData.setBlock(x, y, z, groundMat, this.groundData); + } + } else if (deep > 0) { + deep--; + chunkData.setBlock(x, y, z, groundMat, this.groundData); + + if (deep == 0 && groundMat == SAND) { + deep = random.nextBoundedInt(4) + Math.max(0, y - seaLevel - 1); + groundMat = SANDSTONE; + } + } + } + } + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandy.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandy.java new file mode 100644 index 0000000..b0a0172 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSandy.java @@ -0,0 +1,9 @@ +package worldgeneratorextension.vanillagenerator.ground; + +public class GroundGeneratorSandy extends GroundGenerator { + + public GroundGeneratorSandy() { + setTopMaterial(SAND); + setGroundMaterial(SAND); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSnowy.java b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSnowy.java new file mode 100644 index 0000000..585116d --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/ground/GroundGeneratorSnowy.java @@ -0,0 +1,8 @@ +package worldgeneratorextension.vanillagenerator.ground; + +public class GroundGeneratorSnowy extends GroundGenerator { + + public GroundGeneratorSnowy() { + setTopMaterial(SNOW); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinNoise.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinNoise.java new file mode 100644 index 0000000..048d5c6 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinNoise.java @@ -0,0 +1,142 @@ +package worldgeneratorextension.vanillagenerator.noise; + +import worldgeneratorextension.vanillagenerator.noise.bukkit.PerlinNoiseGenerator; +import cn.nukkit.math.NukkitRandom; + +public class PerlinNoise extends PerlinNoiseGenerator { + + /** + * Creates an instance using the given PRNG. + * + * @param rand the PRNG used to generate the seed permutation + */ + public PerlinNoise(NukkitRandom rand) { + offsetX = rand.nextDouble() * 256; + offsetY = rand.nextDouble() * 256; + offsetZ = rand.nextDouble() * 256; + // The only reason why I'm re-implementing the constructor code is that I've read + // on at least 3 different sources that the permutation table should initially be + // populated with indices. + // "The permutation table is his answer to the issue of random numbers. + // First take an array of decent length, usually 256 values. Fill it sequentially with each + // number in that range: so index 1 gets 1, index 8 gets 8, index 251 gets 251, etc... + // Then randomly shuffle the values so you have a table of 256 random values, but only + // contains the values between 0 and 255." + // source: https://code.google.com/p/fractalterraingeneration/wiki/Perlin_Noise + for (int i = 0; i < 256; i++) { + perm[i] = i; + } + for (int i = 0; i < 256; i++) { + int pos = rand.nextBoundedInt(256 - i) + i; + int old = perm[i]; + perm[i] = perm[pos]; + perm[pos] = old; + perm[i + 256] = perm[i]; + } + } + + public static int floor(double x) { + int floored = (int) x; + return x < floored ? floored - 1 : floored; + } + + /** + * Generates a rectangular section of this generator's noise. + * + * @param noise the output of the previous noise layer + * @param x the X offset + * @param y the Y offset + * @param z the Z offset + * @param sizeX the size on the X axis + * @param sizeY the size on the Y axis + * @param sizeZ the size on the Z axis + * @param scaleX the X scale parameter + * @param scaleY the Y scale parameter + * @param scaleZ the Z scale parameter + * @param amplitude the amplitude parameter + * @return {@code noise} with this layer of noise added + */ + public double[] getNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) { + if (sizeY == 1) { + return get2dNoise(noise, x, z, sizeX, sizeZ, scaleX, scaleZ, amplitude); + } else { + return get3dNoise(noise, x, y, z, sizeX, sizeY, sizeZ, scaleX, scaleY, scaleZ, amplitude); + } + } + + protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeZ, double scaleX, double scaleZ, double amplitude) { + int index = 0; + for (int i = 0; i < sizeX; i++) { + double dx = x + offsetX + i * scaleX; + int floorX = floor(dx); + int ix = floorX & 255; + dx -= floorX; + double fx = fade(dx); + for (int j = 0; j < sizeZ; j++) { + double dz = z + offsetZ + j * scaleZ; + int floorZ = floor(dz); + int iz = floorZ & 255; + dz -= floorZ; + double fz = fade(dz); + // Hash coordinates of the square corners + int a = perm[ix]; + int aa = perm[a] + iz; + int b = perm[ix + 1]; + int ba = perm[b] + iz; + double x1 = lerp(fx, grad(perm[aa], dx, 0, dz), grad(perm[ba], dx - 1, 0, dz)); + double x2 = lerp(fx, grad(perm[aa + 1], dx, 0, dz - 1), grad(perm[ba + 1], dx - 1, 0, dz - 1)); + noise[index++] += lerp(fz, x1, x2) * amplitude; + } + } + return noise; + } + + protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) { + int n = -1; + double x1 = 0; + double x2 = 0; + double x3 = 0; + double x4 = 0; + int index = 0; + for (int i = 0; i < sizeX; i++) { + double dx = x + offsetX + i * scaleX; + int floorX = floor(dx); + int ix = floorX & 255; + dx -= floorX; + double fx = fade(dx); + for (int j = 0; j < sizeZ; j++) { + double dz = z + offsetZ + j * scaleZ; + int floorZ = floor(dz); + int iz = floorZ & 255; + dz -= floorZ; + double fz = fade(dz); + for (int k = 0; k < sizeY; k++) { + double dy = y + offsetY + k * scaleY; + int floorY = floor(dy); + int iy = floorY & 255; + dy -= floorY; + double fy = fade(dy); + if (k == 0 || iy != n) { + n = iy; + // Hash coordinates of the cube corners + int a = perm[ix] + iy; + int aa = perm[a] + iz; + int ab = perm[a + 1] + iz; + int b = perm[ix + 1] + iy; + int ba = perm[b] + iz; + int bb = perm[b + 1] + iz; + x1 = lerp(fx, grad(perm[aa], dx, dy, dz), grad(perm[ba], dx - 1, dy, dz)); + x2 = lerp(fx, grad(perm[ab], dx, dy - 1, dz), grad(perm[bb], dx - 1, dy - 1, dz)); + x3 = lerp(fx, grad(perm[aa + 1], dx, dy, dz - 1), grad(perm[ba + 1], dx - 1, dy, dz - 1)); + x4 = lerp(fx, grad(perm[ab + 1], dx, dy - 1, dz - 1), grad(perm[bb + 1], dx - 1, dy - 1, dz - 1)); + } + double y1 = lerp(fy, x1, x2); + double y2 = lerp(fy, x3, x4); + + noise[index++] += lerp(fz, y1, y2) * amplitude; + } + } + } + return noise; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinOctaveGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinOctaveGenerator.java new file mode 100644 index 0000000..cbdb935 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/PerlinOctaveGenerator.java @@ -0,0 +1,132 @@ +package worldgeneratorextension.vanillagenerator.noise; + +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.noise.bukkit.NoiseGenerator; +import worldgeneratorextension.vanillagenerator.noise.bukkit.OctaveGenerator; + +import java.util.Arrays; + +public class PerlinOctaveGenerator extends OctaveGenerator { + + protected final int sizeX; + protected final int sizeY; + protected final int sizeZ; + protected double[] noise; + + public PerlinOctaveGenerator(NukkitRandom rand, int octaves, int sizeX, int sizeZ) { + this(rand, octaves, sizeX, 1, sizeZ); + } + + public PerlinOctaveGenerator(NukkitRandom rand, int octaves, int sizeX, int sizeY, int sizeZ) { + this(createOctaves(rand, octaves), rand, sizeX, sizeY, sizeZ); + } + + /** + * Creates a generator for multiple layers of Perlin noise. + * + * @param octaves the noise generators + * @param rand the PRNG + * @param sizeX the size on the X axis + * @param sizeY the size on the Y axis + * @param sizeZ the size on the Z axis + */ + public PerlinOctaveGenerator(NoiseGenerator[] octaves, NukkitRandom rand, int sizeX, int sizeY, int sizeZ) { + super(octaves); + this.sizeX = sizeX; + this.sizeY = sizeY; + this.sizeZ = sizeZ; + noise = new double[sizeX * sizeY * sizeZ]; + } + + protected static NoiseGenerator[] createOctaves(NukkitRandom rand, int octaves) { + NoiseGenerator[] result = new NoiseGenerator[octaves]; + + for (int i = 0; i < octaves; i++) { + result[i] = new PerlinNoise(rand); + } + + return result; + } + + protected static long floor(double x) { + return x >= 0 ? (long) x : (long) x - 1; + } + + /** + * Generates multiple layers of noise. + * + * @param x the starting X coordinate + * @param z the starting Z coordinate + * @param lacunarity layer n's frequency as a fraction of layer + * {@code n - 1}'s frequency + * @param persistence layer n's amplitude as a multiple of layer + * {@code n - 1}'s amplitude + * @return The noise array + */ + public double[] getFractalBrownianMotion(double x, double z, double lacunarity, double persistence) { + return getFractalBrownianMotion(x, 0, z, lacunarity, persistence); + } + + /** + * Generates multiple layers of noise. + * + * @param x the starting X coordinate + * @param y the starting Y coordinate + * @param z the starting Z coordinate + * @param lacunarity layer n's frequency as a fraction of layer + * {@code n - 1}'s frequency + * @param persistence layer n's amplitude as a multiple of layer + * {@code n - 1}'s amplitude + * @return The noise array + */ + public double[] getFractalBrownianMotion(double x, double y, double z, double lacunarity, double persistence) { + Arrays.fill(noise, 0); + + double freq = 1; + double amp = 1; + + x *= xScale; + y *= yScale; + z *= zScale; + + // fBm + // the noise have to be periodic over x and z axis: otherwise it can go crazy with high + // input, leading to strange oddities in terrain generation like the old minecraft farland + // symptoms. + for (NoiseGenerator octave : octaves) { + double dx = x * freq; + double dz = z * freq; + // compute integer part + long lx = floor(dx); + long lz = floor(dz); + // compute fractional part + dx -= lx; + dz -= lz; + // wrap integer part to 0..16777216 + lx %= 16777216; + lz %= 16777216; + // add to fractional part + dx += lx; + dz += lz; + + double dy = y * freq; + noise = ((PerlinNoise) octave).getNoise(noise, dx, dy, dz, sizeX, sizeY, sizeZ, xScale * freq, yScale * freq, zScale * freq, amp); + freq *= lacunarity; + amp *= persistence; + } + + return noise; + } + + public int getSizeX() { + return this.sizeX; + } + + public int getSizeY() { + return this.sizeY; + } + + public int getSizeZ() { + return this.sizeZ; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/SimplexNoise.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/SimplexNoise.java new file mode 100644 index 0000000..72c84e3 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/SimplexNoise.java @@ -0,0 +1,318 @@ +package worldgeneratorextension.vanillagenerator.noise; + +import cn.nukkit.math.NukkitRandom; + +/** + * A speed-improved simplex noise algorithm. + * + *

+ * Based on example code by Stefan Gustavson (stegu@itn.liu.se). Optimisations + * by Peter Eastman (peastman@drizzle.stanford.edu). Better rank ordering method + * by Stefan Gustavson in 2012. + * + *

+ * This could be sped up even further, but it's useful as is. + */ +public class SimplexNoise extends PerlinNoise { + + protected static final double SQRT_3 = 1.7320508075688772; // Math.sqrt(3) + protected static final double F2 = 0.5 * (SQRT_3 - 1); + protected static final double G2 = (3 - SQRT_3) / 6; + protected static final double G22 = G2 * 2.0 - 1; + protected static final double F3 = 1.0 / 3.0; + protected static final double G3 = 1.0 / 6.0; + protected static final double G32 = G3 * 2.0; + protected static final double G33 = G3 * 3.0 - 1.0; + private static final Grad[] grad3 = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0), new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1), new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)}; + protected final int[] permMod12 = new int[512]; + + /** + * Creates a simplex noise generator. + * + * @param rand the PRNG to use + */ + public SimplexNoise(NukkitRandom rand) { + super(rand); + for (int i = 0; i < 512; i++) { + permMod12[i] = perm[i] % 12; + } + } + + public static int floor(double x) { + return x > 0 ? (int) x : (int) x - 1; + } + + protected static double dot(Grad g, double x, double y) { + return g.x * x + g.y * y; + } + + protected static double dot(Grad g, double x, double y, double z) { + return g.x * x + g.y * y + g.z * z; + } + + @Override + protected double[] get2dNoise(double[] noise, double x, double z, int sizeX, int sizeY, double scaleX, double scaleY, double amplitude) { + int index = 0; + for (int i = 0; i < sizeY; i++) { + double zin = offsetY + (z + i) * scaleY; + for (int j = 0; j < sizeX; j++) { + double xin = offsetX + (x + j) * scaleX; + noise[index++] += simplex2D(xin, zin) * amplitude; + } + } + return noise; + } + + @Override + protected double[] get3dNoise(double[] noise, double x, double y, double z, int sizeX, int sizeY, int sizeZ, double scaleX, double scaleY, double scaleZ, double amplitude) { + int index = 0; + for (int i = 0; i < sizeZ; i++) { + double zin = offsetZ + (z + i) * scaleZ; + for (int j = 0; j < sizeX; j++) { + double xin = offsetX + (x + j) * scaleX; + for (int k = 0; k < sizeY; k++) { + double yin = offsetY + (y + k) * scaleY; + noise[index++] += simplex3D(xin, yin, zin) * amplitude; + } + } + } + return noise; + } + + @Override + public double noise(double xin, double yin) { + xin += offsetX; + yin += offsetY; + return simplex2D(xin, yin); + } + + @Override + public double noise(double xin, double yin, double zin) { + xin += offsetX; + yin += offsetY; + zin += offsetZ; + return simplex3D(xin, yin, zin); + } + + private double simplex2D(double xin, double yin) { + // Skew the input space to determine which simplex cell we're in + double s = (xin + yin) * F2; // Hairy factor for 2D + int i = floor(xin + s); + int j = floor(yin + s); + double t = (i + j) * G2; + double dx0 = i - t; // Unskew the cell origin back to (x,y) space + double dy0 = j - t; + double x0 = xin - dx0; // The x,y distances from the cell origin + double y0 = yin - dy0; + + // For the 2D case, the simplex shape is an equilateral triangle. + // Determine which simplex we are in. + int i1; // Offsets for second (middle) corner of simplex in (i,j) coords + int j1; + if (x0 > y0) { + i1 = 1; // lower triangle, XY order: (0,0)->(1,0)->(1,1) + j1 = 0; + } else { + i1 = 0; // upper triangle, YX order: (0,0)->(0,1)->(1,1) + j1 = 1; + } + + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-sqrt(3))/6 + double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords + double y1 = y0 - j1 + G2; + double x2 = x0 + G22; // Offsets for last corner in (x,y) unskewed coords + double y2 = y0 + G22; + + // Work out the hashed gradient indices of the three simplex corners + int ii = i & 255; + int jj = j & 255; + int gi0 = permMod12[ii + perm[jj]]; + int gi1 = permMod12[ii + i1 + perm[jj + j1]]; + int gi2 = permMod12[ii + 1 + perm[jj + 1]]; + + // Calculate the contribution from the three corners + double t0 = 0.5 - x0 * x0 - y0 * y0; + double n0; + if (t0 < 0) { + n0 = 0.0; + } else { + t0 *= t0; + n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient + } + + double t1 = 0.5 - x1 * x1 - y1 * y1; + double n1; + if (t1 < 0) { + n1 = 0.0; + } else { + t1 *= t1; + n1 = t1 * t1 * dot(grad3[gi1], x1, y1); + } + + double t2 = 0.5 - x2 * x2 - y2 * y2; + double n2; + if (t2 < 0) { + n2 = 0.0; + } else { + t2 *= t2; + n2 = t2 * t2 * dot(grad3[gi2], x2, y2); + } + + // Add contributions from each corner to get the final noise value. + // The result is scaled to return values in the interval [-1,1]. + return 70.0 * (n0 + n1 + n2); + } + + private double simplex3D(double xin, double yin, double zin) { + // Skew the input space to determine which simplex cell we're in + double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D + int i = floor(xin + s); + int j = floor(yin + s); + int k = floor(zin + s); + double t = (i + j + k) * G3; + double dx0 = i - t; // Unskew the cell origin back to (x,y,z) space + double dy0 = j - t; + double dz0 = k - t; + + // For the 3D case, the simplex shape is a slightly irregular tetrahedron. + int i1; // Offsets for second corner of simplex in (i,j,k) coords + int j1; + int k1; + int i2; // Offsets for third corner of simplex in (i,j,k) coords + int j2; + int k2; + + double x0 = xin - dx0; // The x,y,z distances from the cell origin + double y0 = yin - dy0; + double z0 = zin - dz0; + // Determine which simplex we are in + if (x0 >= y0) { + if (y0 >= z0) { + i1 = 1; // X Y Z order + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } else if (x0 >= z0) { + i1 = 1; // X Z Y order + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } else { + i1 = 0; // Z X Y order + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } + } else { // x0= 0 ? (int) x : (int) x - 1; + } + + protected static double fade(double x) { + return x * x * x * (x * (x * 6 - 15) + 10); + } + + protected static double lerp(double x, double y, double z) { + return y + x * (z - y); + } + + protected static double grad(int hash, double x, double y, double z) { + hash &= 15; + double u = hash < 8 ? x : y; + double v = hash < 4 ? y : hash == 12 || hash == 14 ? x : z; + return ((hash & 1) == 0 ? u : -u) + ((hash & 2) == 0 ? v : -v); + } + + /** + * Computes and returns the 1D noise for the given coordinate in 1D space + * + * @param x X coordinate + * @return Noise at given location, from range -1 to 1 + */ + public double noise(double x) { + return this.noise(x, 0, 0); + } + + /** + * Computes and returns the 2D noise for the given coordinates in 2D space + * + * @param x X coordinate + * @param y Y coordinate + * @return Noise at given location, from range -1 to 1 + */ + public double noise(double x, double y) { + return this.noise(x, y, 0); + } + + /** + * Computes and returns the 3D noise for the given coordinates in 3D space + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return Noise at given location, from range -1 to 1 + */ + public abstract double noise(double x, double y, double z); + + /** + * Generates noise for the 1D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, int octaves, double frequency, double amplitude) { + return this.noise(x, 0, 0, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 1D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, int octaves, double frequency, double amplitude, boolean normalized) { + return this.noise(x, 0, 0, octaves, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 2D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, int octaves, double frequency, double amplitude) { + return this.noise(x, y, 0, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 2D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, int octaves, double frequency, double amplitude, boolean normalized) { + return this.noise(x, y, 0, octaves, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, double z, int octaves, double frequency, double amplitude) { + return this.noise(x, y, z, octaves, frequency, amplitude, false); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, double z, int octaves, double frequency, double amplitude, boolean normalized) { + double result = 0; + double amp = 1; + double freq = 1; + double max = 0; + + for (int i = 0; i < octaves; i++) { + result += this.noise(x * freq, y * freq, z * freq) * amp; + max += amp; + freq *= frequency; + amp *= amplitude; + } + + if (normalized) { + result /= max; + } + + return result; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/OctaveGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/OctaveGenerator.java new file mode 100644 index 0000000..b2f28eb --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/OctaveGenerator.java @@ -0,0 +1,200 @@ +package worldgeneratorextension.vanillagenerator.noise.bukkit; + +/** + * Creates noise using unbiased octaves + */ +public abstract class OctaveGenerator { + + protected final NoiseGenerator[] octaves; + protected double xScale = 1; + protected double yScale = 1; + protected double zScale = 1; + + protected OctaveGenerator(NoiseGenerator[] octaves) { + this.octaves = octaves; + } + + /** + * Sets the scale used for all coordinates passed to this generator. + *

+ * This is the equivalent to setting each coordinate to the specified + * value. + * + * @param scale New value to scale each coordinate by + */ + public void setScale(double scale) { + this.setXScale(scale); + this.setYScale(scale); + this.setZScale(scale); + } + + /** + * Gets the scale used for each X-coordinates passed + * + * @return X scale + */ + public double getXScale() { + return this.xScale; + } + + /** + * Sets the scale used for each X-coordinates passed + * + * @param scale New X scale + */ + public void setXScale(double scale) { + this.xScale = scale; + } + + /** + * Gets the scale used for each Y-coordinates passed + * + * @return Y scale + */ + public double getYScale() { + return this.yScale; + } + + /** + * Sets the scale used for each Y-coordinates passed + * + * @param scale New Y scale + */ + public void setYScale(double scale) { + this.yScale = scale; + } + + /** + * Gets the scale used for each Z-coordinates passed + * + * @return Z scale + */ + public double getZScale() { + return this.zScale; + } + + /** + * Sets the scale used for each Z-coordinates passed + * + * @param scale New Z scale + */ + public void setZScale(double scale) { + this.zScale = scale; + } + + /** + * Gets a clone of the individual octaves used within this generator + * + * @return Clone of the individual octaves + */ + public NoiseGenerator[] getOctaves() { + return this.octaves.clone(); + } + + /** + * Generates noise for the 1D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double frequency, double amplitude) { + return this.noise(x, 0, 0, frequency, amplitude); + } + + /** + * Generates noise for the 1D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double frequency, double amplitude, boolean normalized) { + return this.noise(x, 0, 0, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 2D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, double frequency, double amplitude) { + return this.noise(x, y, 0, frequency, amplitude); + } + + /** + * Generates noise for the 2D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, double frequency, double amplitude, boolean normalized) { + return this.noise(x, y, 0, frequency, amplitude, normalized); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, double z, double frequency, double amplitude) { + return this.noise(x, y, z, frequency, amplitude, false); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, double z, double frequency, double amplitude, boolean normalized) { + double result = 0; + double amp = 1; + double freq = 1; + double max = 0; + + x *= this.xScale; + y *= this.yScale; + z *= this.zScale; + + for (NoiseGenerator octave : this.octaves) { + result += octave.noise(x * freq, y * freq, z * freq) * amp; + max += amp; + freq *= frequency; + amp *= amplitude; + } + + if (normalized) { + result /= max; + } + + return result; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinNoiseGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinNoiseGenerator.java new file mode 100644 index 0000000..87af2da --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinNoiseGenerator.java @@ -0,0 +1,223 @@ +package worldgeneratorextension.vanillagenerator.noise.bukkit; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.Level; +import cn.nukkit.math.NukkitRandom; + +/** + * Generates noise using the "classic" perlin generator + * + * @see SimplexNoiseGenerator "Improved" and faster version with slightly + * different results + */ +public class PerlinNoiseGenerator extends NoiseGenerator { + + protected static final int[][] grad3 = { + {1, 1, 0}, {-1, 1, 0}, {1, -1, 0}, {-1, -1, 0}, + {1, 0, 1}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, + {0, 1, 1}, {0, -1, 1}, {0, 1, -1}, {0, -1, -1} + }; + private static final PerlinNoiseGenerator instance = new PerlinNoiseGenerator(); + + protected PerlinNoiseGenerator() { + int[] p = {151, 160, 137, 91, 90, 15, 131, 13, 201, + 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, + 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, + 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33, 88, 237, 149, 56, + 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, + 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, + 230, 220, 105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, + 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, + 196, 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, + 64, 52, 217, 226, 250, 124, 123, 5, 202, 38, 147, 118, 126, 255, + 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42, + 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, + 101, 155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, + 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, + 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, + 14, 239, 107, 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, + 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236, 205, 93, 222, + 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180}; + + for (int i = 0; i < 512; ++i) { + this.perm[i] = p[i & 255]; + } + } + + /** + * Creates a seeded perlin noise generator for the given world + * + * @param world World to construct this generator for + */ + public PerlinNoiseGenerator(Level world) { + this(new NukkitRandom(world.getSeed())); + } + + /** + * Creates a seeded perlin noise generator for the given level + * + * @param level Level to construct this generator for + */ + public PerlinNoiseGenerator(ChunkManager level) { + this(new NukkitRandom(level.getSeed())); + } + + /** + * Creates a seeded perlin noise generator for the given seed + * + * @param seed Seed to construct this generator for + */ + public PerlinNoiseGenerator(long seed) { + this(new NukkitRandom(seed)); + } + + /** + * Creates a seeded perlin noise generator with the given {@link NukkitRandom} + * + * @param rand NukkitRandom to construct with + */ + public PerlinNoiseGenerator(NukkitRandom rand) { + this.offsetX = rand.nextDouble() * 256; + this.offsetY = rand.nextDouble() * 256; + this.offsetZ = rand.nextDouble() * 256; + + for (int i = 0; i < 256; ++i) { + this.perm[i] = rand.nextBoundedInt(256); + } + + for (int i = 0; i < 256; ++i) { + int pos = rand.nextBoundedInt(256 - i) + i; + int old = this.perm[i]; + + this.perm[i] = this.perm[pos]; + this.perm[pos] = old; + this.perm[i + 256] = this.perm[i]; + } + } + + /** + * Computes and returns the 1D unseeded perlin noise for the given + * coordinates in 1D space + * + * @param x X coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x) { + return instance.noise(x); + } + + /** + * Computes and returns the 2D unseeded perlin noise for the given + * coordinates in 2D space + * + * @param x X coordinate + * @param y Y coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x, double y) { + return instance.noise(x, y); + } + + /** + * Computes and returns the 3D unseeded perlin noise for the given + * coordinates in 3D space + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x, double y, double z) { + return instance.noise(x, y, z); + } + + /** + * Gets the singleton unseeded instance of this generator + * + * @return Singleton + */ + public static PerlinNoiseGenerator getInstance() { + return instance; + } + + @Override + public double noise(double x, double y, double z) { + x += this.offsetX; + y += this.offsetY; + z += this.offsetZ; + + int floorX = floor(x); + int floorY = floor(y); + int floorZ = floor(z); + + // Find unit cube containing the point + int X = floorX & 255; + int Y = floorY & 255; + int Z = floorZ & 255; + + // Get relative xyz coordinates of the point within the cube + x -= floorX; + y -= floorY; + z -= floorZ; + + // Compute fade curves for xyz + double fX = fade(x); + double fY = fade(y); + double fZ = fade(z); + + // Hash coordinates of the cube corners + int A = this.perm[X] + Y; + int AA = this.perm[A] + Z; + int AB = this.perm[A + 1] + Z; + int B = this.perm[X + 1] + Y; + int BA = this.perm[B] + Z; + int BB = this.perm[B + 1] + Z; + + return lerp(fZ, lerp(fY, lerp(fX, grad(this.perm[AA], x, y, z), grad(this.perm[BA], x - 1, y, z)), lerp(fX, grad(this.perm[AB], x, y - 1, z), grad(this.perm[BB], x - 1, y - 1, z))), lerp(fY, lerp(fX, grad(this.perm[AA + 1], x, y, z - 1), grad(this.perm[BA + 1], x - 1, y, z - 1)), lerp(fX, grad(this.perm[AB + 1], x, y - 1, z - 1), grad(this.perm[BB + 1], x - 1, y - 1, z - 1)))); + } + + /** + * Generates noise for the 1D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, int octaves, double frequency, double amplitude) { + return instance.noise(x, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 2D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, double y, int octaves, double frequency, double amplitude) { + return instance.noise(x, y, octaves, frequency, amplitude); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param octaves Number of octaves to use + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public static double getNoise(double x, double y, double z, int octaves, double frequency, double amplitude) { + return instance.noise(x, y, z, octaves, frequency, amplitude); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinOctaveGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinOctaveGenerator.java new file mode 100644 index 0000000..37fd0a4 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/PerlinOctaveGenerator.java @@ -0,0 +1,59 @@ +package worldgeneratorextension.vanillagenerator.noise.bukkit; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.Level; +import cn.nukkit.math.NukkitRandom; + +/** + * Creates perlin noise through unbiased octaves + */ +public class PerlinOctaveGenerator extends OctaveGenerator { + + /** + * Creates a perlin octave generator for the given world + * + * @param world World to construct this generator for + * @param octaves Amount of octaves to create + */ + public PerlinOctaveGenerator(Level world, int octaves) { + this(new NukkitRandom(world.getSeed()), octaves); + } + + /** + * Creates a perlin octave generator for the given level + * + * @param level Level to construct this generator for + * @param octaves Amount of octaves to create + */ + public PerlinOctaveGenerator(ChunkManager level, int octaves) { + this(new NukkitRandom(level.getSeed()), octaves); + } + + /** + * Creates a perlin octave generator for the given world + * + * @param seed Seed to construct this generator for + * @param octaves Amount of octaves to create + */ + public PerlinOctaveGenerator(long seed, int octaves) { + this(new NukkitRandom(seed), octaves); + } + + /** + * Creates a perlin octave generator for the given {@link NukkitRandom} + * + * @param rand NukkitRandom object to construct this generator for + * @param octaves Amount of octaves to create + */ + public PerlinOctaveGenerator(NukkitRandom rand, int octaves) { + super(createOctaves(rand, octaves)); + } + + private static NoiseGenerator[] createOctaves(NukkitRandom rand, int octaves) { + NoiseGenerator[] result = new NoiseGenerator[octaves]; + for (int i = 0; i < octaves; ++i) { + result[i] = new PerlinNoiseGenerator(rand); + } + return result; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexNoiseGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexNoiseGenerator.java new file mode 100644 index 0000000..a30fb1c --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexNoiseGenerator.java @@ -0,0 +1,534 @@ +package worldgeneratorextension.vanillagenerator.noise.bukkit; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.Level; +import cn.nukkit.math.NukkitRandom; + +/** + * Generates simplex-based noise. + *

+ * This is a modified version of the freely published version in the paper by + * Stefan Gustavson at + * + * http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf + */ +public class SimplexNoiseGenerator extends PerlinNoiseGenerator { + + protected static final double SQRT_3 = Math.sqrt(3); + protected static final double SQRT_5 = Math.sqrt(5); + protected static final double F2 = 0.5 * (SQRT_3 - 1); + protected static final double G2 = (3 - SQRT_3) / 6; + protected static final double G22 = G2 * 2.0 - 1; + protected static final double F3 = 1.0 / 3.0; + protected static final double G3 = 1.0 / 6.0; + protected static final double F4 = (SQRT_5 - 1.0) / 4.0; + protected static final double G4 = (5.0 - SQRT_5) / 20.0; + protected static final double G42 = G4 * 2.0; + protected static final double G43 = G4 * 3.0; + protected static final double G44 = G4 * 4.0 - 1.0; + protected static final int[][] grad4 = { + {0, 1, 1, 1}, {0, 1, 1, -1}, {0, 1, -1, 1}, {0, 1, -1, -1}, + {0, -1, 1, 1}, {0, -1, 1, -1}, {0, -1, -1, 1}, {0, -1, -1, -1}, + {1, 0, 1, 1}, {1, 0, 1, -1}, {1, 0, -1, 1}, {1, 0, -1, -1}, + {-1, 0, 1, 1}, {-1, 0, 1, -1}, {-1, 0, -1, 1}, {-1, 0, -1, -1}, + {1, 1, 0, 1}, {1, 1, 0, -1}, {1, -1, 0, 1}, {1, -1, 0, -1}, + {-1, 1, 0, 1}, {-1, 1, 0, -1}, {-1, -1, 0, 1}, {-1, -1, 0, -1}, + {1, 1, 1, 0}, {1, 1, -1, 0}, {1, -1, 1, 0}, {1, -1, -1, 0}, + {-1, 1, 1, 0}, {-1, 1, -1, 0}, {-1, -1, 1, 0}, {-1, -1, -1, 0} + }; + protected static final int[][] simplex = { + {0, 1, 2, 3}, {0, 1, 3, 2}, {0, 0, 0, 0}, {0, 2, 3, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 2, 3, 0}, + {0, 2, 1, 3}, {0, 0, 0, 0}, {0, 3, 1, 2}, {0, 3, 2, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 3, 2, 0}, + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, + {1, 2, 0, 3}, {0, 0, 0, 0}, {1, 3, 0, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 3, 0, 1}, {2, 3, 1, 0}, + {1, 0, 2, 3}, {1, 0, 3, 2}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {2, 0, 3, 1}, {0, 0, 0, 0}, {2, 1, 3, 0}, + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, + {2, 0, 1, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 0, 1, 2}, {3, 0, 2, 1}, {0, 0, 0, 0}, {3, 1, 2, 0}, + {2, 1, 0, 3}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {3, 1, 0, 2}, {0, 0, 0, 0}, {3, 2, 0, 1}, {3, 2, 1, 0} + }; + protected double offsetW; + private static final SimplexNoiseGenerator instance = new SimplexNoiseGenerator(); + + protected SimplexNoiseGenerator() { + + } + + /** + * Creates a seeded simplex noise generator for the given world + * + * @param world World to construct this generator for + */ + public SimplexNoiseGenerator(Level world) { + this(new NukkitRandom(world.getSeed())); + } + + /** + * Creates a seeded simplex noise generator for the given level + * + * @param level Level to construct this generator for + */ + public SimplexNoiseGenerator(ChunkManager level) { + this(new NukkitRandom(level.getSeed())); + } + + /** + * Creates a seeded simplex noise generator for the given seed + * + * @param seed Seed to construct this generator for + */ + public SimplexNoiseGenerator(long seed) { + this(new NukkitRandom(seed)); + } + + /** + * Creates a seeded simplex noise generator with the given {@link NukkitRandom} + * + * @param rand NukkitRandom to construct with + */ + public SimplexNoiseGenerator(NukkitRandom rand) { + super(rand); + this.offsetW = rand.nextDouble() * 256; + } + + protected static double dot(int[] g, double x, double y) { + return g[0] * x + g[1] * y; + } + + protected static double dot(int[] g, double x, double y, double z) { + return g[0] * x + g[1] * y + g[2] * z; + } + + protected static double dot(int[] g, double x, double y, double z, double w) { + return g[0] * x + g[1] * y + g[2] * z + g[3] * w; + } + + /** + * Computes and returns the 1D unseeded simplex noise for the given + * coordinates in 1D space + * + * @param xin X coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double xin) { + return instance.noise(xin); + } + + /** + * Computes and returns the 2D unseeded simplex noise for the given + * coordinates in 2D space + * + * @param xin X coordinate + * @param yin Y coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double xin, double yin) { + return instance.noise(xin, yin); + } + + /** + * Computes and returns the 3D unseeded simplex noise for the given + * coordinates in 3D space + * + * @param xin X coordinate + * @param yin Y coordinate + * @param zin Z coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double xin, double yin, double zin) { + return instance.noise(xin, yin, zin); + } + + /** + * Computes and returns the 4D simplex noise for the given coordinates in + * 4D space + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @param w W coordinate + * @return Noise at given location, from range -1 to 1 + */ + public static double getNoise(double x, double y, double z, double w) { + return instance.noise(x, y, z, w); + } + + @Override + public double noise(double xin, double yin, double zin) { + xin += this.offsetX; + yin += this.offsetY; + zin += this.offsetZ; + + double n0, n1, n2, n3; // Noise contributions from the four corners + + // Skew the input space to determine which simplex cell we're in + double s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D + int i = floor(xin + s); + int j = floor(yin + s); + int k = floor(zin + s); + double t = (i + j + k) * G3; + double X0 = i - t; // Unskew the cell origin back to (x,y,z) space + double Y0 = j - t; + double Z0 = k - t; + double x0 = xin - X0; // The x,y,z distances from the cell origin + double y0 = yin - Y0; + double z0 = zin - Z0; + + // For the 3D case, the simplex shape is a slightly irregular tetrahedron. + + // Determine which simplex we are in. + int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords + int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords + if (x0 >= y0) { + if (y0 >= z0) { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 1; + k2 = 0; + } // X Y Z order + else if (x0 >= z0) { + i1 = 1; + j1 = 0; + k1 = 0; + i2 = 1; + j2 = 0; + k2 = 1; + } // X Z Y order + else { + i1 = 0; + j1 = 0; + k1 = 1; + i2 = 1; + j2 = 0; + k2 = 1; + } // Z X Y order + } else { // x0 y0) { + i1 = 1; + j1 = 0; + } // lower triangle, XY order: (0,0)->(1,0)->(1,1) + else { + i1 = 0; + j1 = 1; + } // upper triangle, YX order: (0,0)->(0,1)->(1,1) + + // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and + // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where + // c = (3-sqrt(3))/6 + + double x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords + double y1 = y0 - j1 + G2; + double x2 = x0 + G22; // Offsets for last corner in (x,y) unskewed coords + double y2 = y0 + G22; + + // Work out the hashed gradient indices of the three simplex corners + int ii = i & 255; + int jj = j & 255; + int gi0 = this.perm[ii + this.perm[jj]] % 12; + int gi1 = this.perm[ii + i1 + this.perm[jj + j1]] % 12; + int gi2 = this.perm[ii + 1 + this.perm[jj + 1]] % 12; + + // Calculate the contribution from the three corners + double t0 = 0.5 - x0 * x0 - y0 * y0; + if (t0 < 0) { + n0 = 0; + } else { + t0 *= t0; + n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient + } + + double t1 = 0.5 - x1 * x1 - y1 * y1; + if (t1 < 0) { + n1 = 0; + } else { + t1 *= t1; + n1 = t1 * t1 * dot(grad3[gi1], x1, y1); + } + + double t2 = 0.5 - x2 * x2 - y2 * y2; + if (t2 < 0) { + n2 = 0; + } else { + t2 *= t2; + n2 = t2 * t2 * dot(grad3[gi2], x2, y2); + } + + // Add contributions from each corner to get the final noise value. + // The result is scaled to return values in the interval [-1,1]. + return 70.0 * (n0 + n1 + n2); + } + + /** + * Computes and returns the 4D simplex noise for the given coordinates in + * 4D space + * + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @param w W coordinate + * @return Noise at given location, from range -1 to 1 + */ + public double noise(double x, double y, double z, double w) { + x += this.offsetX; + y += this.offsetY; + z += this.offsetZ; + w += this.offsetW; + + double n0, n1, n2, n3, n4; // Noise contributions from the five corners + + // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in + double s = (x + y + z + w) * F4; // Factor for 4D skewing + int i = floor(x + s); + int j = floor(y + s); + int k = floor(z + s); + int l = floor(w + s); + + double t = (i + j + k + l) * G4; // Factor for 4D unskewing + double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space + double Y0 = j - t; + double Z0 = k - t; + double W0 = l - t; + double x0 = x - X0; // The x,y,z,w distances from the cell origin + double y0 = y - Y0; + double z0 = z - Z0; + double w0 = w - W0; + + // For the 4D case, the simplex is a 4D shape I won't even try to describe. + // To find out which of the 24 possible simplices we're in, we need to + // determine the magnitude ordering of x0, y0, z0 and w0. + // The method below is a good way of finding the ordering of x,y,z,w and + // then find the correct traversal order for the simplex we’re in. + // First, six pair-wise comparisons are performed between each possible pair + // of the four coordinates, and the results are used to add up binary bits + // for an integer index. + int c1 = (x0 > y0) ? 32 : 0; + int c2 = (x0 > z0) ? 16 : 0; + int c3 = (y0 > z0) ? 8 : 0; + int c4 = (x0 > w0) ? 4 : 0; + int c5 = (y0 > w0) ? 2 : 0; + int c6 = (z0 > w0) ? 1 : 0; + int c = c1 + c2 + c3 + c4 + c5 + c6; + int i1, j1, k1, l1; // The integer offsets for the second simplex corner + int i2, j2, k2, l2; // The integer offsets for the third simplex corner + int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner + + // simplex[c] is a 4-vector with the numbers 0, 1, 2 and 3 in some order. + // Many values of c will never occur, since e.g. x>y>z>w makes x= 3 ? 1 : 0; + j1 = simplex[c][1] >= 3 ? 1 : 0; + k1 = simplex[c][2] >= 3 ? 1 : 0; + l1 = simplex[c][3] >= 3 ? 1 : 0; + + // The number 2 in the "simplex" array is at the second largest coordinate. + i2 = simplex[c][0] >= 2 ? 1 : 0; + j2 = simplex[c][1] >= 2 ? 1 : 0; + k2 = simplex[c][2] >= 2 ? 1 : 0; + l2 = simplex[c][3] >= 2 ? 1 : 0; + + // The number 1 in the "simplex" array is at the second smallest coordinate. + i3 = simplex[c][0] >= 1 ? 1 : 0; + j3 = simplex[c][1] >= 1 ? 1 : 0; + k3 = simplex[c][2] >= 1 ? 1 : 0; + l3 = simplex[c][3] >= 1 ? 1 : 0; + + // The fifth corner has all coordinate offsets = 1, so no need to look that up. + + double x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords + double y1 = y0 - j1 + G4; + double z1 = z0 - k1 + G4; + double w1 = w0 - l1 + G4; + + double x2 = x0 - i2 + G42; // Offsets for third corner in (x,y,z,w) coords + double y2 = y0 - j2 + G42; + double z2 = z0 - k2 + G42; + double w2 = w0 - l2 + G42; + + double x3 = x0 - i3 + G43; // Offsets for fourth corner in (x,y,z,w) coords + double y3 = y0 - j3 + G43; + double z3 = z0 - k3 + G43; + double w3 = w0 - l3 + G43; + + double x4 = x0 + G44; // Offsets for last corner in (x,y,z,w) coords + double y4 = y0 + G44; + double z4 = z0 + G44; + double w4 = w0 + G44; + + // Work out the hashed gradient indices of the five simplex corners + int ii = i & 255; + int jj = j & 255; + int kk = k & 255; + int ll = l & 255; + + int gi0 = this.perm[ii + this.perm[jj + this.perm[kk + this.perm[ll]]]] % 32; + int gi1 = this.perm[ii + i1 + this.perm[jj + j1 + this.perm[kk + k1 + this.perm[ll + l1]]]] % 32; + int gi2 = this.perm[ii + i2 + this.perm[jj + j2 + this.perm[kk + k2 + this.perm[ll + l2]]]] % 32; + int gi3 = this.perm[ii + i3 + this.perm[jj + j3 + this.perm[kk + k3 + this.perm[ll + l3]]]] % 32; + int gi4 = this.perm[ii + 1 + this.perm[jj + 1 + this.perm[kk + 1 + this.perm[ll + 1]]]] % 32; + + // Calculate the contribution from the five corners + double t0 = 0.6 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0; + if (t0 < 0) { + n0 = 0; + } else { + t0 *= t0; + n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0); + } + + double t1 = 0.6 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1; + if (t1 < 0) { + n1 = 0; + } else { + t1 *= t1; + n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1); + } + + double t2 = 0.6 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2; + if (t2 < 0) { + n2 = 0; + } else { + t2 *= t2; + n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2); + } + + double t3 = 0.6 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3; + if (t3 < 0) { + n3 = 0; + } else { + t3 *= t3; + n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3); + } + + double t4 = 0.6 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4; + if (t4 < 0) { + n4 = 0; + } else { + t4 *= t4; + n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4); + } + + // Sum up and scale the result to cover the range [-1,1] + return 27.0 * (n0 + n1 + n2 + n3 + n4); + } + + /** + * Gets the singleton unseeded instance of this generator + * + * @return Singleton + */ + public static SimplexNoiseGenerator getInstance() { + return instance; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexOctaveGenerator.java b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexOctaveGenerator.java new file mode 100644 index 0000000..d1c739d --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/noise/bukkit/SimplexOctaveGenerator.java @@ -0,0 +1,141 @@ +package worldgeneratorextension.vanillagenerator.noise.bukkit; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.Level; +import cn.nukkit.math.NukkitRandom; + +/** + * Creates simplex noise through unbiased octaves + */ +public class SimplexOctaveGenerator extends OctaveGenerator { + + private double wScale = 1; + + /** + * Creates a simplex octave generator for the given world + * + * @param world World to construct this generator for + * @param octaves Amount of octaves to create + */ + public SimplexOctaveGenerator(Level world, int octaves) { + this(new NukkitRandom(world.getSeed()), octaves); + } + + /** + * Creates a simplex octave generator for the given level + * + * @param level Level to construct this generator for + * @param octaves Amount of octaves to create + */ + public SimplexOctaveGenerator(ChunkManager level, int octaves) { + this(new NukkitRandom(level.getSeed()), octaves); + } + + /** + * Creates a simplex octave generator for the given world + * + * @param seed Seed to construct this generator for + * @param octaves Amount of octaves to create + */ + public SimplexOctaveGenerator(long seed, int octaves) { + this(new NukkitRandom(seed), octaves); + } + + /** + * Creates a simplex octave generator for the given {@link NukkitRandom} + * + * @param rand NukkitRandom object to construct this generator for + * @param octaves Amount of octaves to create + */ + public SimplexOctaveGenerator(NukkitRandom rand, int octaves) { + super(createOctaves(rand, octaves)); + } + + @Override + public void setScale(double scale) { + super.setScale(scale); + this.setWScale(scale); + } + + /** + * Gets the scale used for each W-coordinates passed + * + * @return W scale + */ + public double getWScale() { + return this.wScale; + } + + /** + * Sets the scale used for each W-coordinates passed + * + * @param scale New W scale + */ + public void setWScale(double scale) { + this.wScale = scale; + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param w W-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @return Resulting noise + */ + public double noise(double x, double y, double z, double w, double frequency, double amplitude) { + return this.noise(x, y, z, w, frequency, amplitude, false); + } + + /** + * Generates noise for the 3D coordinates using the specified number of + * octaves and parameters + * + * @param x X-coordinate + * @param y Y-coordinate + * @param z Z-coordinate + * @param w W-coordinate + * @param frequency How much to alter the frequency by each octave + * @param amplitude How much to alter the amplitude by each octave + * @param normalized If true, normalize the value to [-1, 1] + * @return Resulting noise + */ + public double noise(double x, double y, double z, double w, double frequency, double amplitude, boolean normalized) { + double result = 0; + double amp = 1; + double freq = 1; + double max = 0; + + x *= this.xScale; + y *= this.yScale; + z *= this.zScale; + w *= this.wScale; + + for (NoiseGenerator octave : this.octaves) { + result += ((SimplexNoiseGenerator) octave).noise(x * freq, y * freq, z * freq, w * freq) * amp; + max += amp; + freq *= frequency; + amp *= amplitude; + } + + if (normalized) { + result /= max; + } + + return result; + } + + private static NoiseGenerator[] createOctaves(NukkitRandom rand, int octaves) { + NoiseGenerator[] result = new NoiseGenerator[octaves]; + + for (int i = 0; i < octaves; ++i) { + result[i] = new SimplexNoiseGenerator(rand); + } + + return result; + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/object/OreType.java b/src/main/java/worldgeneratorextension/vanillagenerator/object/OreType.java new file mode 100644 index 0000000..7c33372 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/object/OreType.java @@ -0,0 +1,77 @@ +package worldgeneratorextension.vanillagenerator.object; + +import cn.nukkit.block.Block; +import cn.nukkit.level.ChunkManager; +import cn.nukkit.math.MathHelper; +import cn.nukkit.math.NukkitRandom; + +public class OreType { + + public final int fullId; + public final int clusterCount; + public final int clusterSize; + public final int maxHeight; + public final int minHeight; + public final int replaceBlockId; + + public OreType(Block material, int clusterCount, int clusterSize, int minHeight, int maxHeight) { + this(material, clusterCount, clusterSize, minHeight, maxHeight, Block.STONE); + } + + public OreType(Block material, int clusterCount, int clusterSize, int minHeight, int maxHeight, int replaceBlockId) { + this.fullId = material.getFullId(); + this.clusterCount = clusterCount; + this.clusterSize = clusterSize; + this.maxHeight = maxHeight; + this.minHeight = minHeight; + this.replaceBlockId = replaceBlockId; + } + + public void spawn(ChunkManager level, NukkitRandom rand, int replaceId, int x, int y, int z) { + float piScaled = rand.nextFloat() * (float) Math.PI; + double scaleMaxX = (float) (x + 8) + MathHelper.sin(piScaled) * (float) clusterSize / 8.0F; + double scaleMinX = (float) (x + 8) - MathHelper.sin(piScaled) * (float) clusterSize / 8.0F; + double scaleMaxZ = (float) (z + 8) + MathHelper.cos(piScaled) * (float) clusterSize / 8.0F; + double scaleMinZ = (float) (z + 8) - MathHelper.cos(piScaled) * (float) clusterSize / 8.0F; + double scaleMaxY = y + rand.nextBoundedInt(3) - 2; + double scaleMinY = y + rand.nextBoundedInt(3) - 2; + + for (int i = 0; i < clusterSize; ++i) { + float sizeIncr = (float) i / (float) clusterSize; + double scaleX = scaleMaxX + (scaleMinX - scaleMaxX) * (double) sizeIncr; + double scaleY = scaleMaxY + (scaleMinY - scaleMaxY) * (double) sizeIncr; + double scaleZ = scaleMaxZ + (scaleMinZ - scaleMaxZ) * (double) sizeIncr; + double randSizeOffset = rand.nextDouble() * (double) clusterSize / 16.0D; + double randVec1 = (double) (MathHelper.sin((float) Math.PI * sizeIncr) + 1.0F) * randSizeOffset + 1.0D; + double randVec2 = (double) (MathHelper.sin((float) Math.PI * sizeIncr) + 1.0F) * randSizeOffset + 1.0D; + int minX = MathHelper.floor(scaleX - randVec1 / 2.0D); + int minY = MathHelper.floor(scaleY - randVec2 / 2.0D); + int minZ = MathHelper.floor(scaleZ - randVec1 / 2.0D); + int maxX = MathHelper.floor(scaleX + randVec1 / 2.0D); + int maxY = MathHelper.floor(scaleY + randVec2 / 2.0D); + int maxZ = MathHelper.floor(scaleZ + randVec1 / 2.0D); + + for (int xSeg = minX; xSeg <= maxX; ++xSeg) { + double xVal = ((double) xSeg + 0.5D - scaleX) / (randVec1 / 2.0D); + + if (xVal * xVal < 1.0D) { + for (int ySeg = minY; ySeg <= maxY; ++ySeg) { + double yVal = ((double) ySeg + 0.5D - scaleY) / (randVec2 / 2.0D); + + if (xVal * xVal + yVal * yVal < 1.0D) { + for (int zSeg = minZ; zSeg <= maxZ; ++zSeg) { + double zVal = ((double) zSeg + 0.5D - scaleZ) / (randVec1 / 2.0D); + + if (xVal * xVal + yVal * yVal + zVal * zVal < 1.0D) { + if (level.getBlockIdAt(xSeg, ySeg, zSeg) == replaceBlockId) { + level.setBlockFullIdAt(xSeg, ySeg, zSeg, fullId); + } + } + } + } + } + } + } + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/populator/PopulatorOre.java b/src/main/java/worldgeneratorextension/vanillagenerator/populator/PopulatorOre.java new file mode 100644 index 0000000..ce5a0d5 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/populator/PopulatorOre.java @@ -0,0 +1,38 @@ +package worldgeneratorextension.vanillagenerator.populator; + +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.generator.populator.type.Populator; +import cn.nukkit.math.NukkitMath; +import cn.nukkit.math.NukkitRandom; +import worldgeneratorextension.vanillagenerator.object.OreType; + +public class PopulatorOre extends Populator { + + private final int replaceId; + private final OreType[] oreTypes; + + public PopulatorOre(int replaceId, OreType[] oreTypes) { + this.replaceId = replaceId; + this.oreTypes = oreTypes; + } + + @Override + public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) { + int sx = chunkX << 4; + int ex = sx + 15; + int sz = chunkZ << 4; + int ez = sz + 15; + for (OreType type : this.oreTypes) { + for (int i = 0; i < type.clusterCount; i++) { + int x = NukkitMath.randomRange(random, sx, ex); + int z = NukkitMath.randomRange(random, sz, ez); + int y = NukkitMath.randomRange(random, type.minHeight, type.maxHeight); + if (level.getBlockIdAt(x, y, z) != replaceId) { + continue; + } + type.spawn(level, random, replaceId, x, y, z); + } + } + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorCaves.java b/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorCaves.java new file mode 100644 index 0000000..5bc0903 --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorCaves.java @@ -0,0 +1,272 @@ +package worldgeneratorextension.vanillagenerator.populator.overworld; + +import cn.nukkit.block.Block; +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.biome.Biome; +import cn.nukkit.level.biome.type.CoveredBiome; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.generator.populator.type.Populator; +import cn.nukkit.math.MathHelper; +import cn.nukkit.math.NukkitRandom; + +import java.util.Random; + +public class PopulatorCaves extends Populator { + + protected int checkAreaSize = 8; + + private Random random; + + public static int caveRarity = 7; + public static int caveFrequency = 40; + public static int caveMinAltitude = 8; + public static int caveMaxAltitude = 67; + public static int individualCaveRarity = 25; + public static int caveSystemFrequency = 1; + public static int caveSystemPocketChance = 0; + public static int caveSystemPocketMinSize = 0; + public static int caveSystemPocketMaxSize = 4; + public static boolean evenCaveDistribution = false; + + public int worldHeightCap = 128; + + @Override + public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) { + this.random = new Random(level.getSeed()); + long worldLong1 = this.random.nextLong(); + long worldLong2 = this.random.nextLong(); + + int size = this.checkAreaSize; + + for (int x = chunkX - size; x <= chunkX + size; x++) { + for (int z = chunkZ - size; z <= chunkZ + size; z++) { + long randomX = x * worldLong1; + long randomZ = z * worldLong2; + this.random.setSeed(randomX ^ randomZ ^ level.getSeed()); + generateChunk(x, z, chunk); + } + } + } + + private void generateLargeCaveNode(long seed, FullChunk chunk, double x, double y, double z) { + generateCaveNode(seed, chunk, x, y, z, 1.0F + this.random.nextFloat() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D); + } + + private void generateCaveNode(long seed, FullChunk chunk, double x, double y, double z, float radius, float angelOffset, float angel, int angle, int maxAngle, double scale) { + int chunkX = chunk.getX(); + int chunkZ = chunk.getZ(); + + double realX = chunkX * 16 + 8; + double realZ = chunkZ * 16 + 8; + + float f1 = 0.0F; + float f2 = 0.0F; + + Random localRandom = new Random(seed); + + if (maxAngle <= 0) { + int checkAreaSize = this.checkAreaSize * 16 - 16; + maxAngle = checkAreaSize - localRandom.nextInt(checkAreaSize / 4); + } + boolean isLargeCave = false; + + if (angle == -1) { + angle = maxAngle / 2; + isLargeCave = true; + } + + int randomAngel = localRandom.nextInt(maxAngle / 2) + maxAngle / 4; + boolean bigAngel = localRandom.nextInt(6) == 0; + + for (; angle < maxAngle; angle++) { + double offsetXZ = 1.5D + MathHelper.sin(angle * 3.141593F / maxAngle) * radius * 1.0F; + double offsetY = offsetXZ * scale; + + float cos = MathHelper.cos(angel); + float sin = MathHelper.sin(angel); + x += MathHelper.cos(angelOffset) * cos; + y += sin; + z += MathHelper.sin(angelOffset) * cos; + + if (bigAngel) { + angel *= 0.92F; + } else { + angel *= 0.7F; + } + angel += f2 * 0.1F; + angelOffset += f1 * 0.1F; + + f2 *= 0.9F; + f1 *= 0.75F; + f2 += (localRandom.nextFloat() - localRandom.nextFloat()) * localRandom.nextFloat() * 2.0F; + f1 += (localRandom.nextFloat() - localRandom.nextFloat()) * localRandom.nextFloat() * 4.0F; + + if ((!isLargeCave) && (angle == randomAngel) && (radius > 1.0F) && (maxAngle > 0)) { + generateCaveNode(localRandom.nextLong(), chunk, x, y, z, localRandom.nextFloat() * 0.5F + 0.5F, angelOffset - 1.570796F, angel / 3.0F, angle, maxAngle, 1.0D); + generateCaveNode(localRandom.nextLong(), chunk, x, y, z, localRandom.nextFloat() * 0.5F + 0.5F, angelOffset + 1.570796F, angel / 3.0F, angle, maxAngle, 1.0D); + return; + } + if ((!isLargeCave) && (localRandom.nextInt(4) == 0)) { + continue; + } + + // Check if distance to working point (x and z) too larger than working radius (maybe ??) + double distanceX = x - realX; + double distanceZ = z - realZ; + double angelDiff = maxAngle - angle; + double newRadius = radius + 2.0F + 16.0F; + if (distanceX * distanceX + distanceZ * distanceZ - angelDiff * angelDiff > newRadius * newRadius) { + return; + } + + //Boundaries check. + if ((x < realX - 16.0D - offsetXZ * 2.0D) || (z < realZ - 16.0D - offsetXZ * 2.0D) || (x > realX + 16.0D + offsetXZ * 2.0D) || (z > realZ + 16.0D + offsetXZ * 2.0D)) { + continue; + } + + int xFrom = MathHelper.floor(x - offsetXZ) - chunkX * 16 - 1; + int xTo = MathHelper.floor(x + offsetXZ) - chunkX * 16 + 1; + + int yFrom = MathHelper.floor(y - offsetY) - 1; + int yTo = MathHelper.floor(y + offsetY) + 1; + + int zFrom = MathHelper.floor(z - offsetXZ) - chunkZ * 16 - 1; + int zTo = MathHelper.floor(z + offsetXZ) - chunkZ * 16 + 1; + + if (xFrom < 0) { + xFrom = 0; + } + if (xTo > 16) { + xTo = 16; + } + + if (yFrom < 1) { + yFrom = 1; + } + if (yTo > this.worldHeightCap - 8) { + yTo = this.worldHeightCap - 8; + } + if (zFrom < 0) { + zFrom = 0; + } + if (zTo > 16) { + zTo = 16; + } + + // Search for water + boolean waterFound = false; + for (int xx = xFrom; (!waterFound) && (xx < xTo); xx++) { + for (int zz = zFrom; (!waterFound) && (zz < zTo); zz++) { + for (int yy = yTo + 1; (!waterFound) && (yy >= yFrom - 1); yy--) { + if (yy >= 0 && yy < this.worldHeightCap) { + int block = chunk.getBlockId(xx, yy, zz); + if (block == Block.WATER || block == Block.STILL_WATER) { + waterFound = true; + } + if ((yy != yFrom - 1) && (xx != xFrom) && (xx != xTo - 1) && (zz != zFrom) && (zz != zTo - 1)) { + yy = yFrom; + } + } + } + } + } + + if (waterFound) { + continue; + } + + // Generate cave + for (int xx = xFrom; xx < xTo; xx++) { + double modX = (xx + chunkX * 16 + 0.5D - x) / offsetXZ; + for (int zz = zFrom; zz < zTo; zz++) { + double modZ = (zz + chunkZ * 16 + 0.5D - z) / offsetXZ; + + boolean grassFound = false; + if (modX * modX + modZ * modZ < 1.0D) { + for (int yy = yTo; yy > yFrom; yy--) { + double modY = ((yy - 1) + 0.5D - y) / offsetY; + if ((modY > -0.7D) && (modX * modX + modY * modY + modZ * modZ < 1.0D)) { + Biome biome = Biome.getBiome(chunk.getBiomeId(xx, zz)); + if (!(biome instanceof CoveredBiome)) { + continue; + } + + int material = chunk.getBlockId(xx, yy, zz); + //int materialAbove = chunk.getBlockId(xx, yy + 1, zz); + if (material == Block.GRASS || material == Block.MYCELIUM) { + grassFound = true; + } + //TODO: check this +// if (this.isSuitableBlock(material, materialAbove, biome)) + { + if (yy - 1 < 10) { + chunk.setBlock(xx, yy, zz, Block.LAVA); + } else { + chunk.setBlock(xx, yy, zz, Block.AIR); + + // If grass was just deleted, try to + // move it down + if (grassFound && (chunk.getBlockId(xx, yy - 1, zz) == Block.DIRT)) { + chunk.setFullBlockId(xx, yy - 1, zz, ((CoveredBiome) biome).getSurfaceId(xx, yy - 1, zz)); + } + } + } + } + } + } + } + } + + if (isLargeCave) { + break; + } + } + } + + private void generateChunk(int chunkX, int chunkZ, FullChunk generatingChunkBuffer) { + int i = this.random.nextInt(this.random.nextInt(this.random.nextInt(caveFrequency) + 1) + 1); + if (evenCaveDistribution) { + i = caveFrequency; + } + if (this.random.nextInt(100) >= caveRarity) { + i = 0; + } + + for (int j = 0; j < i; j++) { + double x = chunkX * 16 + this.random.nextInt(16); + + double y; + + if (evenCaveDistribution) { + y = numberInRange(random, caveMinAltitude, caveMaxAltitude); + } else { + y = this.random.nextInt(this.random.nextInt(caveMaxAltitude - caveMinAltitude + 1) + 1) + caveMinAltitude; + } + + double z = chunkZ * 16 + this.random.nextInt(16); + + int count = caveSystemFrequency; + boolean largeCaveSpawned = false; + if (this.random.nextInt(100) <= individualCaveRarity) { + generateLargeCaveNode(this.random.nextLong(), generatingChunkBuffer, x, y, z); + largeCaveSpawned = true; + } + + if ((largeCaveSpawned) || (this.random.nextInt(100) <= caveSystemPocketChance - 1)) { + count += numberInRange(random, caveSystemPocketMinSize, caveSystemPocketMaxSize); + } + while (count > 0) { + count--; + float f1 = this.random.nextFloat() * 3.141593F * 2.0F; + float f2 = (this.random.nextFloat() - 0.5F) * 2.0F / 8.0F; + float f3 = this.random.nextFloat() * 2.0F + this.random.nextFloat(); + + generateCaveNode(this.random.nextLong(), generatingChunkBuffer, x, y, z, f3, f1, f2, 0, 0, 1.0D); + } + } + } + + private static int numberInRange(Random random, int min, int max) { + return min + random.nextInt(max - min + 1); + } +} diff --git a/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorSnowLayers.java b/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorSnowLayers.java new file mode 100644 index 0000000..c5aba9f --- /dev/null +++ b/src/main/java/worldgeneratorextension/vanillagenerator/populator/overworld/PopulatorSnowLayers.java @@ -0,0 +1,166 @@ +package cn.wode490390.nukkit.vanillagenerator.populator.overworld; + +import cn.nukkit.block.Block; +import cn.nukkit.level.ChunkManager; +import cn.nukkit.level.biome.EnumBiome; +import cn.nukkit.level.format.FullChunk; +import cn.nukkit.level.generator.populator.type.Populator; +import cn.nukkit.math.NukkitRandom; + +public class PopulatorSnowLayers extends Populator { + + protected static final boolean[] coverableBiome = new boolean[Block.MAX_BLOCK_ID]; + protected static final boolean[] uncoverableBlock = new boolean[Block.MAX_BLOCK_ID]; + + static { + coverableBiome[EnumBiome.ICE_PLAINS.id] = true; + coverableBiome[EnumBiome.ICE_PLAINS_SPIKES.id] = true; + coverableBiome[EnumBiome.COLD_BEACH.id] = true; + coverableBiome[EnumBiome.COLD_TAIGA.id] = true; + coverableBiome[EnumBiome.COLD_TAIGA_HILLS.id] = true; + coverableBiome[EnumBiome.COLD_TAIGA_M.id] = true; + + uncoverableBlock[SAPLING] = true; + uncoverableBlock[WATER] = true; + uncoverableBlock[STILL_WATER] = true; + uncoverableBlock[LAVA] = true; + uncoverableBlock[STILL_LAVA] = true; + uncoverableBlock[BED_BLOCK] = true; + uncoverableBlock[POWERED_RAIL] = true; + uncoverableBlock[DETECTOR_RAIL] = true; + uncoverableBlock[COBWEB] = true; + uncoverableBlock[TALL_GRASS] = true; + uncoverableBlock[DEAD_BUSH] = true; + uncoverableBlock[PISTON_HEAD] = true; + uncoverableBlock[DANDELION] = true; + uncoverableBlock[RED_FLOWER] = true; + uncoverableBlock[BROWN_MUSHROOM] = true; + uncoverableBlock[RED_MUSHROOM] = true; + uncoverableBlock[STONE_SLAB] = true; + uncoverableBlock[TORCH] = true; + uncoverableBlock[FIRE] = true; + uncoverableBlock[OAK_WOOD_STAIRS] = true; + uncoverableBlock[CHEST] = true; + uncoverableBlock[REDSTONE_WIRE] = true; + uncoverableBlock[WHEAT_BLOCK] = true; + uncoverableBlock[SIGN_POST] = true; + uncoverableBlock[WOODEN_DOOR_BLOCK] = true; + uncoverableBlock[LADDER] = true; + uncoverableBlock[RAIL] = true; + uncoverableBlock[COBBLESTONE_STAIRS] = true; + uncoverableBlock[WALL_SIGN] = true; + uncoverableBlock[LEVER] = true; + uncoverableBlock[STONE_PRESSURE_PLATE] = true; + uncoverableBlock[IRON_DOOR_BLOCK] = true; + uncoverableBlock[WOODEN_PRESSURE_PLATE] = true; + uncoverableBlock[REDSTONE_ORE] = true; + uncoverableBlock[UNLIT_REDSTONE_TORCH] = true; + uncoverableBlock[REDSTONE_TORCH] = true; + uncoverableBlock[STONE_BUTTON] = true; + uncoverableBlock[SNOW_LAYER] = true; //existed + uncoverableBlock[ICE] = true; + uncoverableBlock[CACTUS] = true; + uncoverableBlock[REEDS] = true; + uncoverableBlock[FENCE] = true; + uncoverableBlock[NETHER_PORTAL] = true; + uncoverableBlock[CAKE_BLOCK] = true; + uncoverableBlock[UNPOWERED_REPEATER] = true; + uncoverableBlock[POWERED_REPEATER] = true; + uncoverableBlock[TRAPDOOR] = true; + uncoverableBlock[IRON_BARS] = true; + uncoverableBlock[GLASS_PANE] = true; + uncoverableBlock[PUMPKIN_STEM] = true; + uncoverableBlock[MELON_STEM] = true; + uncoverableBlock[VINE] = true; + uncoverableBlock[FENCE_GATE] = true; + uncoverableBlock[BRICK_STAIRS] = true; + uncoverableBlock[STONE_BRICK_STAIRS] = true; + uncoverableBlock[WATER_LILY] = true; + uncoverableBlock[NETHER_BRICK_FENCE] = true; + uncoverableBlock[NETHER_BRICKS_STAIRS] = true; + uncoverableBlock[NETHER_WART_BLOCK] = true; + uncoverableBlock[ENCHANTING_TABLE] = true; + uncoverableBlock[BREWING_STAND_BLOCK] = true; + uncoverableBlock[END_PORTAL] = true; + uncoverableBlock[END_PORTAL_FRAME] = true; + uncoverableBlock[DRAGON_EGG] = true; + uncoverableBlock[ACTIVATOR_RAIL] = true; + uncoverableBlock[COCOA] = true; + uncoverableBlock[SANDSTONE_STAIRS] = true; + uncoverableBlock[ENDER_CHEST] = true; + uncoverableBlock[TRIPWIRE_HOOK] = true; + uncoverableBlock[TRIPWIRE] = true; + uncoverableBlock[SPRUCE_WOOD_STAIRS] = true; + uncoverableBlock[BIRCH_WOOD_STAIRS] = true; + uncoverableBlock[JUNGLE_WOOD_STAIRS] = true; + uncoverableBlock[COBBLESTONE_WALL] = true; + uncoverableBlock[FLOWER_POT_BLOCK] = true; + uncoverableBlock[CARROT_BLOCK] = true; + uncoverableBlock[POTATO_BLOCK] = true; + uncoverableBlock[WOODEN_BUTTON] = true; + uncoverableBlock[SKULL_BLOCK] = true; + uncoverableBlock[ANVIL] = true; + uncoverableBlock[TRAPPED_CHEST] = true; + uncoverableBlock[LIGHT_WEIGHTED_PRESSURE_PLATE] = true; + uncoverableBlock[HEAVY_WEIGHTED_PRESSURE_PLATE] = true; + uncoverableBlock[UNPOWERED_COMPARATOR] = true; + uncoverableBlock[POWERED_COMPARATOR] = true; + uncoverableBlock[DAYLIGHT_DETECTOR] = true; + uncoverableBlock[QUARTZ_STAIRS] = true; + uncoverableBlock[WOODEN_SLABS] = true; + uncoverableBlock[STAINED_GLASS_PANE] = true; + uncoverableBlock[ACACIA_WOOD_STAIRS] = true; + uncoverableBlock[DARK_OAK_WOOD_STAIRS] = true; + uncoverableBlock[IRON_TRAPDOOR] = true; + uncoverableBlock[CARPET] = true; + uncoverableBlock[DOUBLE_PLANT] = true; + uncoverableBlock[STANDING_BANNER] = true; + uncoverableBlock[WALL_BANNER] = true; + uncoverableBlock[DAYLIGHT_DETECTOR_INVERTED] = true; + uncoverableBlock[RED_SANDSTONE_STAIRS] = true; + uncoverableBlock[RED_SANDSTONE_SLAB] = true; + uncoverableBlock[FENCE_GATE_SPRUCE] = true; + uncoverableBlock[FENCE_GATE_BIRCH] = true; + uncoverableBlock[FENCE_GATE_JUNGLE] = true; + uncoverableBlock[FENCE_GATE_DARK_OAK] = true; + uncoverableBlock[FENCE_GATE_ACACIA] = true; + uncoverableBlock[190] = true; // HARD_GLASS_PANE + uncoverableBlock[191] = true; // HARD_STAINED_GLASS_PANE + uncoverableBlock[SPRUCE_DOOR_BLOCK] = true; + uncoverableBlock[BIRCH_DOOR_BLOCK] = true; + uncoverableBlock[JUNGLE_DOOR_BLOCK] = true; + uncoverableBlock[ACACIA_DOOR_BLOCK] = true; + uncoverableBlock[DARK_OAK_DOOR_BLOCK] = true; + uncoverableBlock[ITEM_FRAME_BLOCK] = true; + uncoverableBlock[CHORUS_FLOWER] = true; + uncoverableBlock[202] = true; // COLORED_TORCH_RG + uncoverableBlock[PURPUR_STAIRS] = true; + uncoverableBlock[204] = true; // COLORED_TORCH_BP + uncoverableBlock[UNDYED_SHULKER_BOX] = true; + uncoverableBlock[ICE_FROSTED] = true; + uncoverableBlock[END_ROD] = true; + uncoverableBlock[END_GATEWAY] = true; + uncoverableBlock[217] = true; // STRUCTURE_VOID + uncoverableBlock[SHULKER_BOX] = true; + uncoverableBlock[239] = true; // UNDERWATER_TORCH + uncoverableBlock[CHORUS_PLANT] = true; + uncoverableBlock[242] = true; // CAMERA + uncoverableBlock[BEETROOT_BLOCK] = true; + uncoverableBlock[PISTON_EXTENSION] = true; + } + + @Override + public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random, FullChunk chunk) { + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + if (coverableBiome[chunk.getBiomeId(x, z)]) { + int y = chunk.getHighestBlockAt(x, z); + if (y > 0 && y < 255 && !uncoverableBlock[chunk.getBlockId(x, y, z)]) { + int chance = random.nextBoundedInt(10); + chunk.setBlock(x, y + 1, z, SNOW_LAYER, chance < 6 ? 0 : chance == 6 ? 2 : 1); + } + } + } + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3494b4c..213a5ea 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,3 +2,4 @@ name: WorldGeneratorExtension main: worldgeneratorextension.Loader version: "${pom.version}" api: ["1.1.0"] +load: STARTUP