├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── dependabot.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── Jenkinsfile ├── LICENSE.MD ├── README.md ├── build.gradle ├── docs └── images │ ├── logo.png │ ├── logo_small.png │ ├── pictures │ ├── grand_canyon │ │ ├── 1.png │ │ ├── 2.png │ │ └── 3.png │ ├── half_dome │ │ ├── 1.png │ │ └── 2.png │ ├── makapuu_point │ │ ├── 1.png │ │ └── 2.png │ └── mount_everest │ │ ├── 1.png │ │ └── 2.png │ ├── projections │ └── bte_airocean.jpg │ └── troubleshooting │ ├── args │ ├── edit.png │ └── installations.png │ └── launcher │ ├── options.png │ └── settings.png ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml ├── lombok.config └── src ├── main ├── java │ └── net │ │ └── buildtheearth │ │ └── terraplusplus │ │ ├── EarthWorldType.java │ │ ├── TerraConfig.java │ │ ├── TerraConstants.java │ │ ├── TerraMod.java │ │ ├── config │ │ ├── GlobalParseRegistries.java │ │ ├── SingleProperty.java │ │ ├── TypedDeserializer.java │ │ ├── TypedSerializer.java │ │ ├── condition │ │ │ ├── AndDC.java │ │ │ ├── DoubleCondition.java │ │ │ ├── EqualDC.java │ │ │ ├── GreaterThanDC.java │ │ │ ├── LessThanDC.java │ │ │ ├── NotDC.java │ │ │ └── OrDC.java │ │ └── scalarparse │ │ │ ├── d │ │ │ ├── AddDSP.java │ │ │ ├── DivideDSP.java │ │ │ ├── DoubleScalarParser.java │ │ │ ├── FlipXDSP.java │ │ │ ├── FlipZDSP.java │ │ │ ├── FromIntDSP.java │ │ │ ├── MultiplyDSP.java │ │ │ ├── ParseTerrariumPngDSP.java │ │ │ ├── ParseTiffAutoDSP.java │ │ │ ├── ParseTiffFloatingPointDSP.java │ │ │ ├── ParseTiffIntDSP.java │ │ │ └── SwapAxesDSP.java │ │ │ └── i │ │ │ ├── AddISP.java │ │ │ ├── AndISP.java │ │ │ ├── FlipXISP.java │ │ │ ├── FlipZISP.java │ │ │ ├── GrayscaleExtractISP.java │ │ │ ├── IntScalarParser.java │ │ │ ├── ParseJpgISP.java │ │ │ ├── ParsePngISP.java │ │ │ ├── ParseTiffISP.java │ │ │ ├── RGBExtractISP.java │ │ │ ├── RequireOpaqueISP.java │ │ │ └── SwapAxesISP.java │ │ ├── control │ │ ├── AdvancedEarthGui.java │ │ ├── Command.java │ │ ├── PresetEarthGui.java │ │ ├── TerraCommand.java │ │ ├── TerraTeleport.java │ │ └── fragments │ │ │ ├── CommandFragment.java │ │ │ ├── FragmentManager.java │ │ │ └── terra │ │ │ ├── TerraConvertFragment.java │ │ │ ├── TerraDistortionFragment.java │ │ │ ├── TerraInfoFragment.java │ │ │ ├── TerraWhereFragment.java │ │ │ └── TerraWorldFragment.java │ │ ├── dataset │ │ ├── BlendMode.java │ │ ├── Dataset.java │ │ ├── IDataset.java │ │ ├── IElementDataset.java │ │ ├── IScalarDataset.java │ │ ├── KeyedHttpDataset.java │ │ ├── TiledDataset.java │ │ ├── TiledHttpDataset.java │ │ ├── builtin │ │ │ ├── AbstractBuiltinDataset.java │ │ │ ├── Climate.java │ │ │ └── Soil.java │ │ ├── geojson │ │ │ ├── AbstractGeoJsonDeserializer.java │ │ │ ├── GeoJson.java │ │ │ ├── GeoJsonObject.java │ │ │ ├── Geometry.java │ │ │ ├── GeometryDeserializer.java │ │ │ ├── ObjectDeserializer.java │ │ │ ├── dataset │ │ │ │ ├── AbstractReferenceResolvingGeoJsonDataset.java │ │ │ │ ├── ParsingGeoJsonDataset.java │ │ │ │ ├── ReferenceResolvingGeoJsonDataset.java │ │ │ │ └── TiledGeoJsonDataset.java │ │ │ ├── geometry │ │ │ │ ├── GeometryCollection.java │ │ │ │ ├── LineString.java │ │ │ │ ├── MultiLineString.java │ │ │ │ ├── MultiPoint.java │ │ │ │ ├── MultiPolygon.java │ │ │ │ ├── Point.java │ │ │ │ └── Polygon.java │ │ │ └── object │ │ │ │ ├── Feature.java │ │ │ │ ├── FeatureCollection.java │ │ │ │ └── Reference.java │ │ ├── osm │ │ │ ├── BlockStateParser.java │ │ │ ├── JsonParser.java │ │ │ ├── OSMMapper.java │ │ │ ├── Root.java │ │ │ ├── dvalue │ │ │ │ ├── BiOp.java │ │ │ │ ├── Constant.java │ │ │ │ ├── DValue.java │ │ │ │ ├── DValueParser.java │ │ │ │ └── Tag.java │ │ │ ├── mapper │ │ │ │ ├── All.java │ │ │ │ ├── Any.java │ │ │ │ ├── Condition.java │ │ │ │ ├── First.java │ │ │ │ ├── LineMapper.java │ │ │ │ ├── LineNarrow.java │ │ │ │ ├── LineParser.java │ │ │ │ ├── LineSharp.java │ │ │ │ ├── LineWide.java │ │ │ │ ├── Nothing.java │ │ │ │ ├── PolygonConvert.java │ │ │ │ ├── PolygonDistance.java │ │ │ │ ├── PolygonFill.java │ │ │ │ ├── PolygonMapper.java │ │ │ │ └── PolygonParser.java │ │ │ ├── match │ │ │ │ ├── And.java │ │ │ │ ├── Id.java │ │ │ │ ├── Intersects.java │ │ │ │ ├── MatchCondition.java │ │ │ │ ├── MatchParser.java │ │ │ │ ├── Not.java │ │ │ │ ├── Or.java │ │ │ │ └── Tag.java │ │ │ └── package-info.java │ │ ├── scalar │ │ │ ├── ConfigurableDoubleTiledDataset.java │ │ │ ├── DoubleTiledDataset.java │ │ │ └── MultiScalarDataset.java │ │ └── vector │ │ │ ├── GeoJsonToVectorDataset.java │ │ │ ├── VectorTiledDataset.java │ │ │ ├── draw │ │ │ ├── All.java │ │ │ ├── Block.java │ │ │ ├── DrawFunction.java │ │ │ ├── DrawFunctionParser.java │ │ │ ├── NoTrees.java │ │ │ ├── Ocean.java │ │ │ ├── Water.java │ │ │ ├── WeightAdd.java │ │ │ ├── WeightClamp.java │ │ │ ├── WeightGreaterThan.java │ │ │ └── WeightLessThan.java │ │ │ └── geometry │ │ │ ├── AbstractVectorGeometry.java │ │ │ ├── Segment.java │ │ │ ├── VectorGeometry.java │ │ │ ├── line │ │ │ ├── AbstractLine.java │ │ │ ├── NarrowLine.java │ │ │ ├── SharpLine.java │ │ │ └── WideLine.java │ │ │ └── polygon │ │ │ ├── AbstractPolygon.java │ │ │ ├── DistancePolygon.java │ │ │ └── FillPolygon.java │ │ ├── event │ │ ├── AbstractCustomRegistrationEvent.java │ │ ├── InitDatasetsEvent.java │ │ └── InitEarthRegistryEvent.java │ │ ├── generator │ │ ├── CachedChunkData.java │ │ ├── ChunkBiomesBuilder.java │ │ ├── CliffReplacer.java │ │ ├── EarthBiomeProvider.java │ │ ├── EarthGenerator.java │ │ ├── EarthGeneratorPipelines.java │ │ ├── EarthGeneratorSettings.java │ │ ├── GeneratorDatasets.java │ │ ├── IEarthAsyncDataBuilder.java │ │ ├── IEarthAsyncPipelineStep.java │ │ ├── TerrainPreview.java │ │ ├── biome │ │ │ ├── IEarthBiomeFilter.java │ │ │ ├── Terra121BiomeFilter.java │ │ │ └── UserOverrideBiomeFilter.java │ │ ├── data │ │ │ ├── HeightsBaker.java │ │ │ ├── IEarthDataBaker.java │ │ │ ├── InitialBiomesBaker.java │ │ │ ├── NullIslandBaker.java │ │ │ ├── OSMBaker.java │ │ │ └── TreeCoverBaker.java │ │ └── populate │ │ │ ├── BiomeDecorationPopulator.java │ │ │ ├── CompatibilityEarthPopulators.java │ │ │ ├── IEarthPopulator.java │ │ │ ├── SnowPopulator.java │ │ │ └── TreePopulator.java │ │ ├── projection │ │ ├── AzimuthalEquidistantProjection.java │ │ ├── EqualEarthProjection.java │ │ ├── EquirectangularProjection.java │ │ ├── GeographicProjection.java │ │ ├── LambertAzimuthalProjection.java │ │ ├── OutOfProjectionBoundsException.java │ │ ├── ProjectionFunction.java │ │ ├── SinusoidalProjection.java │ │ ├── StereographicProjection.java │ │ ├── dymaxion │ │ │ ├── BTEDymaxionProjection.java │ │ │ ├── ConformalDynmaxionProjection.java │ │ │ └── DymaxionProjection.java │ │ ├── mercator │ │ │ ├── CenteredMercatorProjection.java │ │ │ ├── TransverseMercatorProjection.java │ │ │ └── WebMercatorProjection.java │ │ └── transform │ │ │ ├── ClampProjectionTransform.java │ │ │ ├── FlipHorizontalProjectionTransform.java │ │ │ ├── FlipVerticalProjectionTransform.java │ │ │ ├── OffsetProjectionTransform.java │ │ │ ├── ProjectionTransform.java │ │ │ ├── RotateProjectionTransform.java │ │ │ ├── ScaleProjectionTransform.java │ │ │ └── SwapAxesProjectionTransform.java │ │ ├── provider │ │ ├── EarthWorldProvider.java │ │ ├── GenerationEventDenier.java │ │ └── WaterDenier.java │ │ └── util │ │ ├── BiomeDeserializeMixin.java │ │ ├── BlockStateDeserializeMixin.java │ │ ├── CardinalDirection.java │ │ ├── ChatUtil.java │ │ ├── CornerBoundingBox2d.java │ │ ├── CustomAttributeContainer.java │ │ ├── EmptyWorld.java │ │ ├── EqualsTieBreakComparator.java │ │ ├── ImmutableCompactArray.java │ │ ├── IntRange.java │ │ ├── IntToDoubleBiFunction.java │ │ ├── MathUtils.java │ │ ├── OrderedRegistry.java │ │ ├── RLEByteArray.java │ │ ├── TilePos.java │ │ ├── TranslateUtil.java │ │ ├── bvh │ │ ├── BVH.java │ │ ├── Bounds2d.java │ │ ├── Bounds2dImpl.java │ │ ├── EmptyBVH.java │ │ ├── QuadtreeBVH.java │ │ └── SingletonBVH.java │ │ ├── geo │ │ ├── CoordinateParseUtils.java │ │ └── LatLng.java │ │ ├── http │ │ ├── CacheEntry.java │ │ ├── Disk.java │ │ ├── Host.java │ │ ├── HostManager.java │ │ ├── Http.java │ │ └── package-info.java │ │ └── interval │ │ ├── Interval.java │ │ ├── IntervalImpl.java │ │ └── IntervalTree.java └── resources │ ├── assets │ └── terraplusplus │ │ ├── lang │ │ ├── de_de.lang │ │ ├── en_us.lang │ │ ├── es_es.lang │ │ ├── fr_fr.lang │ │ ├── ko_kr.lang │ │ ├── pl_pl.lang │ │ ├── ru_ru.lang │ │ ├── uk_ua.lang │ │ ├── uk_uk.lang │ │ └── zh_cn.lang │ │ └── textures │ │ ├── directions.png │ │ ├── icon.png │ │ └── presets │ │ ├── advanced.png │ │ ├── bte.png │ │ └── default.png │ ├── mcmod.info │ ├── net │ └── buildtheearth │ │ └── terraplusplus │ │ ├── control │ │ └── map.png │ │ ├── dataset │ │ ├── builtin │ │ │ ├── climate.lzma │ │ │ └── soil.lzma │ │ ├── osm │ │ │ ├── osm.json5 │ │ │ ├── osm_no_buildings.json5 │ │ │ ├── osm_no_roads.json5 │ │ │ └── osm_no_roads_or_buildings.json5 │ │ └── scalar │ │ │ ├── heights.json5 │ │ │ └── tree_cover.json5 │ │ ├── generator │ │ ├── biome │ │ │ └── biome_overrides.json5 │ │ ├── bte_generator_settings.json5 │ │ └── default_generator_settings.json5 │ │ └── projection │ │ └── dymaxion │ │ └── conformal.lzma │ └── pack.mcmeta └── test └── java └── net └── buildtheearth └── terraplusplus └── util ├── OrderedRegistryTest.java └── geo └── CoordinateParseUtilsTest.java /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | *.java text=auto eol=lf 3 | *.gradle text=auto eol=lf 4 | *.xml text=auto eol=lf 5 | *.json text=auto eol=lf 6 | *.md text=auto eol=lf 7 | *.yml text=auto eol=lf 8 | *.template text=auto eol=lf 9 | *.txt text=auto eol=lf 10 | *.bat text=auto eol=crlf 11 | *.gradle text=auto eol=lf 12 | *.sh text=auto eol=lf 13 | *.html text=auto eol=lf 14 | *.settings text=auto eol=lf 15 | *.properties text=auto eol=lf 16 | *.config text=auto eol=lf 17 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['http://buildtheearth.net/patreon'] 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Describe the steps it takes to reproduce the bug 15 | Example: 16 | 1. Join the game 17 | 3. Execute command `/tpll...` 18 | 4. See Error Log 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Error Logs** 27 | If applicable, paste your server logs into `https://mclo.gs/` and include the link here. 28 | 29 | **Version (please complete the following information):** 30 | - What version of TerraPlusPlus are you using? 31 | - What version of the BTE Modpack or Server pack are you running? (If applicable) 32 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. If it is related to an issue in the current release of T++, please include the issue if it exists, or create one if it doesn't exist. 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gradle" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | gradle/.DS_Store 3 | .DS_Store 4 | 5 | # eclipse 6 | bin 7 | *.launch 8 | .settings 9 | .metadata 10 | .classpath 11 | .project 12 | 13 | # idea 14 | out 15 | *.ipr 16 | *.iws 17 | *.iml 18 | .idea 19 | 20 | # gradle 21 | build 22 | .gradle 23 | 24 | #our build stuff 25 | build.sh 26 | build.bat 27 | 28 | # other 29 | eclipse 30 | run 31 | *.log 32 | ======= 33 | gradlew 34 | 35 | /logs/ 36 | -------------------------------------------------------------------------------- /LICENSE.MD: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 BuildTheEarth.net 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/logo.png -------------------------------------------------------------------------------- /docs/images/logo_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/logo_small.png -------------------------------------------------------------------------------- /docs/images/pictures/grand_canyon/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/grand_canyon/1.png -------------------------------------------------------------------------------- /docs/images/pictures/grand_canyon/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/grand_canyon/2.png -------------------------------------------------------------------------------- /docs/images/pictures/grand_canyon/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/grand_canyon/3.png -------------------------------------------------------------------------------- /docs/images/pictures/half_dome/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/half_dome/1.png -------------------------------------------------------------------------------- /docs/images/pictures/half_dome/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/half_dome/2.png -------------------------------------------------------------------------------- /docs/images/pictures/makapuu_point/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/makapuu_point/1.png -------------------------------------------------------------------------------- /docs/images/pictures/makapuu_point/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/makapuu_point/2.png -------------------------------------------------------------------------------- /docs/images/pictures/mount_everest/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/mount_everest/1.png -------------------------------------------------------------------------------- /docs/images/pictures/mount_everest/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/pictures/mount_everest/2.png -------------------------------------------------------------------------------- /docs/images/projections/bte_airocean.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/projections/bte_airocean.jpg -------------------------------------------------------------------------------- /docs/images/troubleshooting/args/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/troubleshooting/args/edit.png -------------------------------------------------------------------------------- /docs/images/troubleshooting/args/installations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/troubleshooting/args/installations.png -------------------------------------------------------------------------------- /docs/images/troubleshooting/launcher/options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/troubleshooting/launcher/options.png -------------------------------------------------------------------------------- /docs/images/troubleshooting/launcher/settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/docs/images/troubleshooting/launcher/settings.png -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Sets default memory used for gradle commands. Can be overridden by user or command line properties. 2 | # This is required to provide enough memory for the Minecraft decompilation process. 3 | org.gradle.jvmargs=-Xmx3G 4 | 5 | # workaround: https://www.abrarsyed.com/ForgeGradleVersion.json doesn't have a valid SSL certificate any more 6 | net.minecraftforge.gradle.disableUpdateChecker=true 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 14 12:28:28 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip 7 | -------------------------------------------------------------------------------- /jitpack.yml: -------------------------------------------------------------------------------- 1 | jdk: 2 | - openjdk8 3 | install: 4 | - ./gradlew setupCiWorkspace publishToMavenLocal 5 | -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.accessors.fluent=true 2 | lombok.accessors.chain=true 3 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/SingleProperty.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Indicates that a type deserialized by {@link TypedDeserializer} is represented as a single value rather than an object. 10 | * 11 | * @author DaPorkchop_ 12 | */ 13 | @Target(ElementType.TYPE) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface SingleProperty { 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/TypedDeserializer.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config; 2 | 3 | import com.fasterxml.jackson.core.JsonParser; 4 | import com.fasterxml.jackson.core.JsonProcessingException; 5 | import com.fasterxml.jackson.core.JsonToken; 6 | import com.fasterxml.jackson.databind.DeserializationContext; 7 | import com.fasterxml.jackson.databind.JsonDeserializer; 8 | import com.fasterxml.jackson.databind.JsonMappingException; 9 | import net.daporkchop.lib.common.util.PorkUtil; 10 | 11 | import java.io.IOException; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | public abstract class TypedDeserializer extends JsonDeserializer { 18 | @Override 19 | public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { 20 | String name = p.nextFieldName(); 21 | if (name == null) { 22 | throw JsonMappingException.from(p, "expected type name, found: " + p.currentToken()); 23 | } 24 | 25 | Class clazz = this.registry().get(name); 26 | if (clazz == null) { 27 | throw JsonMappingException.from(p, "invalid type type name: " + name); 28 | } 29 | 30 | if (!clazz.isAnnotationPresent(SingleProperty.class) & p.nextToken() != JsonToken.START_OBJECT) { 31 | throw JsonMappingException.from(p, "expected json object, but found: " + p.currentToken()); 32 | } 33 | 34 | T value = ctxt.readValue(p, PorkUtil.>uncheckedCast(clazz)); 35 | 36 | if (p.nextToken() != JsonToken.END_OBJECT) { 37 | throw JsonMappingException.from(p, "expected json object end, but found: " + p.currentToken()); 38 | } 39 | 40 | return value; 41 | } 42 | 43 | protected abstract Map> registry(); 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/TypedSerializer.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonMappingException; 5 | import com.fasterxml.jackson.databind.JsonSerializer; 6 | import com.fasterxml.jackson.databind.SerializerProvider; 7 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 8 | import net.buildtheearth.terraplusplus.TerraConstants; 9 | 10 | import java.io.IOException; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | public abstract class TypedSerializer extends JsonSerializer { 17 | @Override 18 | public void serialize(T value, JsonGenerator gen, SerializerProvider serializers) throws IOException { 19 | if (value == null) { 20 | gen.writeNull(); 21 | return; 22 | } 23 | 24 | String name = this.registry().get(value.getClass()); 25 | if (name == null) { 26 | throw JsonMappingException.from(gen, "invalid value type: " + value.getClass()); 27 | } 28 | 29 | gen.writeStartObject(value); 30 | gen.writeFieldName(name); 31 | 32 | TerraConstants.JSON_MAPPER.rebuild().addMixIn(value.getClass(), MixIn.class).build().writeValue(gen, value); 33 | 34 | gen.writeEndObject(); 35 | } 36 | 37 | protected abstract Map, String> registry(); 38 | 39 | @JsonSerialize 40 | private class MixIn {} // Have this here to avoid a bug in forge gradle (https://forums.minecraftforge.net/topic/40670-build-terminates-at-extractrangemapreplacedmain/) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/AndDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import lombok.Getter; 7 | import lombok.NonNull; 8 | import lombok.RequiredArgsConstructor; 9 | import net.buildtheearth.terraplusplus.config.SingleProperty; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | @RequiredArgsConstructor(onConstructor_ = { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) }) 15 | @JsonDeserialize 16 | @Getter(onMethod_ = { @JsonValue }) 17 | @SingleProperty 18 | public class AndDC implements DoubleCondition { 19 | @NonNull 20 | protected final DoubleCondition[] delegates; 21 | 22 | @Override 23 | public boolean test(double value) { 24 | for (DoubleCondition delegate : this.delegates) { 25 | if (!delegate.test(value)) { 26 | return false; 27 | } 28 | } 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/DoubleCondition.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import net.buildtheearth.terraplusplus.config.GlobalParseRegistries; 6 | import net.buildtheearth.terraplusplus.config.TypedDeserializer; 7 | import net.buildtheearth.terraplusplus.config.TypedSerializer; 8 | 9 | import java.util.Map; 10 | import java.util.function.DoublePredicate; 11 | 12 | /** 13 | * A condition that accepts a {@code double} value and checks if it is applicable to a given argument. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonDeserialize(using = DoubleCondition.Deserializer.class) 18 | @JsonSerialize(using = DoubleCondition.Serializer.class) 19 | @FunctionalInterface 20 | public interface DoubleCondition extends DoublePredicate { 21 | class Deserializer extends TypedDeserializer { 22 | @Override 23 | protected Map> registry() { 24 | return GlobalParseRegistries.DOUBLE_CONDITIONS; 25 | } 26 | } 27 | 28 | class Serializer extends TypedSerializer { 29 | @Override 30 | protected Map, String> registry() { 31 | return GlobalParseRegistries.DOUBLE_CONDITIONS.inverse(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/EqualDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import lombok.Getter; 7 | import lombok.RequiredArgsConstructor; 8 | import net.buildtheearth.terraplusplus.config.SingleProperty; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @RequiredArgsConstructor(onConstructor_ = { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) }) 14 | @JsonDeserialize 15 | @Getter(onMethod_ = { @JsonValue }) 16 | @SingleProperty 17 | public class EqualDC implements DoubleCondition { 18 | protected final double value; 19 | 20 | @Override 21 | public boolean test(double value) { 22 | return this.value == value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/GreaterThanDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import lombok.Getter; 7 | import lombok.RequiredArgsConstructor; 8 | import net.buildtheearth.terraplusplus.config.SingleProperty; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @RequiredArgsConstructor(onConstructor_ = { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) }) 14 | @JsonDeserialize 15 | @Getter(onMethod_ = { @JsonValue }) 16 | @SingleProperty 17 | public class GreaterThanDC implements DoubleCondition { 18 | protected final double value; 19 | 20 | @Override 21 | public boolean test(double value) { 22 | return value > this.value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/LessThanDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import lombok.Getter; 7 | import lombok.RequiredArgsConstructor; 8 | import net.buildtheearth.terraplusplus.config.SingleProperty; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @RequiredArgsConstructor(onConstructor_ = { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) }) 14 | @JsonDeserialize 15 | @Getter(onMethod_ = { @JsonValue }) 16 | @SingleProperty 17 | public class LessThanDC implements DoubleCondition { 18 | protected final double value; 19 | 20 | @Override 21 | public boolean test(double value) { 22 | return value < this.value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/NotDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import lombok.Getter; 8 | import lombok.NonNull; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @JsonDeserialize 14 | @Getter(onMethod_ = { @JsonGetter }) 15 | public class NotDC implements DoubleCondition { 16 | protected final DoubleCondition delegate; 17 | 18 | @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) 19 | public NotDC(@JsonProperty(value = "delegate", required = true) @NonNull DoubleCondition delegate) { 20 | this.delegate = delegate; 21 | } 22 | 23 | @Override 24 | public boolean test(double value) { 25 | return !this.delegate.test(value); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/condition/OrDC.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.condition; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonValue; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import lombok.Getter; 7 | import lombok.NonNull; 8 | import lombok.RequiredArgsConstructor; 9 | import net.buildtheearth.terraplusplus.config.SingleProperty; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | @RequiredArgsConstructor(onConstructor_ = { @JsonCreator(mode = JsonCreator.Mode.DELEGATING) }) 15 | @JsonDeserialize 16 | @Getter(onMethod_ = { @JsonValue }) 17 | @SingleProperty 18 | public class OrDC implements DoubleCondition { 19 | @NonNull 20 | protected final DoubleCondition[] delegates; 21 | 22 | @Override 23 | public boolean test(double value) { 24 | for (DoubleCondition delegate : this.delegates) { 25 | if (delegate.test(value)) { 26 | return true; 27 | } 28 | } 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/AddDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class AddDSP implements DoubleScalarParser { 19 | protected final DoubleScalarParser delegate; 20 | protected final double value; 21 | 22 | @JsonCreator 23 | public AddDSP( 24 | @JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate, 25 | @JsonProperty(value = "value", required = true) double value) { 26 | this.delegate = delegate; 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 32 | double[] arr = this.delegate.parse(resolution, buffer); 33 | double value = this.value; 34 | for (int i = 0, len = resolution * resolution; i < len; i++) { 35 | arr[i] += value; 36 | } 37 | return arr; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/DivideDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.AccessLevel; 9 | import lombok.Getter; 10 | import lombok.NonNull; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonDeserialize 18 | @Getter(onMethod_ = { @JsonGetter }) 19 | public class DivideDSP implements DoubleScalarParser { 20 | protected final DoubleScalarParser delegate; 21 | protected final double value; 22 | 23 | @Getter(AccessLevel.NONE) 24 | protected final double factor; 25 | 26 | @JsonCreator 27 | public DivideDSP( 28 | @JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate, 29 | @JsonProperty(value = "value", required = true) double value) { 30 | this.delegate = delegate; 31 | this.value = value; 32 | this.factor = 1.0d / value; 33 | } 34 | 35 | @Override 36 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 37 | double[] arr = this.delegate.parse(resolution, buffer); 38 | double factor = this.factor; 39 | for (int i = 0, len = resolution * resolution; i < len; i++) { 40 | arr[i] *= factor; 41 | } 42 | return arr; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/DoubleScalarParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import io.netty.buffer.ByteBuf; 6 | import lombok.NonNull; 7 | import net.buildtheearth.terraplusplus.config.GlobalParseRegistries; 8 | import net.buildtheearth.terraplusplus.config.TypedDeserializer; 9 | import net.buildtheearth.terraplusplus.config.TypedSerializer; 10 | 11 | import java.io.IOException; 12 | import java.util.Map; 13 | 14 | /** 15 | * Parses a square grid of {@code double} values from a binary representation. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | @JsonDeserialize(using = DoubleScalarParser.Deserializer.class) 20 | @JsonSerialize(using = DoubleScalarParser.Serializer.class) 21 | @FunctionalInterface 22 | public interface DoubleScalarParser { 23 | double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException; 24 | 25 | class Deserializer extends TypedDeserializer { 26 | @Override 27 | protected Map> registry() { 28 | return GlobalParseRegistries.SCALAR_PARSERS_DOUBLE; 29 | } 30 | } 31 | 32 | class Serializer extends TypedSerializer { 33 | @Override 34 | protected Map, String> registry() { 35 | return GlobalParseRegistries.SCALAR_PARSERS_DOUBLE.inverse(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/FlipXDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class FlipXDSP implements DoubleScalarParser { 19 | protected final DoubleScalarParser delegate; 20 | 21 | @JsonCreator 22 | public FlipXDSP(@JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | double[] arr = this.delegate.parse(resolution, buffer); 29 | for (int z = 0; z < resolution; z++) { 30 | for (int x = 0, lim = resolution >> 1; x < lim; x++) { 31 | int a = z * resolution + x; 32 | int b = z * resolution + (resolution - x - 1); 33 | double t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/FlipZDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class FlipZDSP implements DoubleScalarParser { 19 | protected final DoubleScalarParser delegate; 20 | 21 | @JsonCreator 22 | public FlipZDSP(@JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | double[] arr = this.delegate.parse(resolution, buffer); 29 | for (int z = 0, lim = resolution >> 1; z < lim; z++) { 30 | for (int x = 0; x < resolution; x++) { 31 | int a = z * resolution + x; 32 | int b = (resolution - z - 1) * resolution + x; 33 | double t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/FromIntDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | import net.buildtheearth.terraplusplus.config.scalarparse.i.IntScalarParser; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonDeserialize 18 | @Getter(onMethod_ = { @JsonGetter }) 19 | public class FromIntDSP implements DoubleScalarParser { 20 | protected final IntScalarParser delegate; 21 | 22 | @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) 23 | public FromIntDSP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 24 | this.delegate = delegate; 25 | } 26 | 27 | @Override 28 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 29 | int[] src = this.delegate.parse(resolution, buffer); 30 | int len = resolution * resolution; 31 | double[] dst = new double[len]; 32 | for (int i = 0; i < len; i++) { 33 | dst[i] = src[i] != Integer.MIN_VALUE ? src[i] : Double.NaN; 34 | } 35 | return dst; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/MultiplyDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class MultiplyDSP implements DoubleScalarParser { 19 | protected final DoubleScalarParser delegate; 20 | protected final double value; 21 | 22 | @JsonCreator 23 | public MultiplyDSP( 24 | @JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate, 25 | @JsonProperty(value = "value", required = true) double value) { 26 | this.delegate = delegate; 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 32 | double[] arr = this.delegate.parse(resolution, buffer); 33 | double value = this.value; 34 | for (int i = 0, len = resolution * resolution; i < len; i++) { 35 | arr[i] *= value; 36 | } 37 | return arr; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/ParseTerrariumPngDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.ByteBufInputStream; 6 | import lombok.NonNull; 7 | import net.buildtheearth.terraplusplus.config.scalarparse.i.IntScalarParser; 8 | 9 | import javax.imageio.ImageIO; 10 | import java.awt.image.BufferedImage; 11 | import java.io.IOException; 12 | 13 | import static net.daporkchop.lib.common.util.PValidation.*; 14 | 15 | /** 16 | * @author DaPorkchop_ 17 | */ 18 | @JsonDeserialize 19 | public class ParseTerrariumPngDSP implements DoubleScalarParser { 20 | @Override 21 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 22 | BufferedImage image = ImageIO.read(new ByteBufInputStream(buffer)); 23 | 24 | int w = image.getWidth(); 25 | int h = image.getHeight(); 26 | checkArg(w == resolution && h == resolution, "invalid image resolution: %dx%d (expected: %dx%3$d)", w, h, resolution); 27 | 28 | int[] rgb = image.getRGB(0, 0, resolution, resolution, null, 0, resolution); 29 | double[] out = new double[resolution * resolution]; 30 | 31 | for (int i = 0; i < resolution * resolution; i++) { 32 | int c = rgb[i]; 33 | if ((c >>> 24) != 0xFF) { //nodata 34 | out[i] = Double.NaN; 35 | } else { 36 | out[i] = ((c & ~0xFF000000) - 0x00800000) * (1.0d / 256.0d); 37 | } 38 | } 39 | 40 | return out; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/ParseTiffFloatingPointDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import lombok.NonNull; 5 | import org.apache.commons.imaging.ImageReadException; 6 | import org.apache.commons.imaging.formats.tiff.TiffDirectory; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @JsonDeserialize 14 | public class ParseTiffFloatingPointDSP extends ParseTiffAutoDSP { 15 | @Override 16 | protected boolean parseInteger(int resolution, @NonNull TiffDirectory directory, @NonNull double[] dst) throws ImageReadException, IOException { 17 | return false; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/ParseTiffIntDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import lombok.NonNull; 5 | import org.apache.commons.imaging.ImageReadException; 6 | import org.apache.commons.imaging.formats.tiff.TiffDirectory; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @JsonDeserialize 14 | public class ParseTiffIntDSP extends ParseTiffAutoDSP { 15 | @Override 16 | protected boolean parseFloatingPoint(int resolution, @NonNull TiffDirectory directory, @NonNull double[] dst) throws ImageReadException, IOException { 17 | return false; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/d/SwapAxesDSP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.d; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class SwapAxesDSP implements DoubleScalarParser { 19 | protected final DoubleScalarParser delegate; 20 | 21 | @JsonCreator 22 | public SwapAxesDSP(@JsonProperty(value = "delegate", required = true) @NonNull DoubleScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public double[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | double[] arr = this.delegate.parse(resolution, buffer); 29 | for (int i = 1; i < resolution; i++) { 30 | for (int j = 0; j < i; j++) { 31 | int a = i * resolution + j; 32 | int b = j * resolution + i; 33 | double t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/AddISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class AddISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | protected final int value; 21 | 22 | @JsonCreator 23 | public AddISP( 24 | @JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate, 25 | @JsonProperty(value = "value", required = true) int value) { 26 | this.delegate = delegate; 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 32 | int[] arr = this.delegate.parse(resolution, buffer); 33 | int value = this.value; 34 | for (int i = 0, len = resolution * resolution; i < len; i++) { 35 | arr[i] += value; 36 | } 37 | return arr; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/AndISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class AndISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | protected final int mask; 21 | 22 | @JsonCreator 23 | public AndISP( 24 | @JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate, 25 | @JsonProperty(value = "mask", required = true) int mask) { 26 | this.delegate = delegate; 27 | this.mask = mask; 28 | } 29 | 30 | @Override 31 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 32 | int[] arr = this.delegate.parse(resolution, buffer); 33 | int mask = this.mask; 34 | for (int i = 0, len = resolution * resolution; i < len; i++) { 35 | int v = arr[i]; 36 | if (v != Integer.MIN_VALUE) { 37 | arr[i] = v & mask; 38 | } 39 | } 40 | return arr; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/FlipXISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class FlipXISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator 22 | public FlipXISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int z = 0; z < resolution; z++) { 30 | for (int x = 0, lim = resolution >> 1; x < lim; x++) { 31 | int a = z * resolution + x; 32 | int b = z * resolution + (resolution - x - 1); 33 | int t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/FlipZISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class FlipZISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator 22 | public FlipZISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int z = 0, lim = resolution >> 1; z < lim; z++) { 30 | for (int x = 0; x < resolution; x++) { 31 | int a = z * resolution + x; 32 | int b = (resolution - z - 1) * resolution + x; 33 | int t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/GrayscaleExtractISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class GrayscaleExtractISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator 22 | public GrayscaleExtractISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int i = 0, len = resolution * resolution; i < len; i++) { 30 | int val = arr[i]; 31 | arr[i] = (val >>> 24) == 0xFF ? arr[i] & 0x000000FF : Integer.MIN_VALUE; 32 | } 33 | return arr; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/IntScalarParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import io.netty.buffer.ByteBuf; 6 | import lombok.NonNull; 7 | import net.buildtheearth.terraplusplus.config.GlobalParseRegistries; 8 | import net.buildtheearth.terraplusplus.config.TypedDeserializer; 9 | import net.buildtheearth.terraplusplus.config.TypedSerializer; 10 | 11 | import java.io.IOException; 12 | import java.util.Map; 13 | 14 | /** 15 | * Parses a square grid of {@code int} values from a binary representation. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | @JsonDeserialize(using = IntScalarParser.Deserializer.class) 20 | @JsonSerialize(using = IntScalarParser.Serializer.class) 21 | @FunctionalInterface 22 | public interface IntScalarParser { 23 | int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException; 24 | 25 | class Deserializer extends TypedDeserializer { 26 | @Override 27 | protected Map> registry() { 28 | return GlobalParseRegistries.SCALAR_PARSERS_INT; 29 | } 30 | } 31 | 32 | class Serializer extends TypedSerializer { 33 | @Override 34 | protected Map, String> registry() { 35 | return GlobalParseRegistries.SCALAR_PARSERS_INT.inverse(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/ParseJpgISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | 5 | /** 6 | * @author DaPorkchop_ 7 | */ 8 | @JsonDeserialize 9 | public class ParseJpgISP extends ParsePngISP { 10 | //we don't actually need to do anything different, since ImageIO does automatic type detection... 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/ParsePngISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.ByteBufInputStream; 6 | import lombok.NonNull; 7 | 8 | import javax.imageio.ImageIO; 9 | import java.awt.image.BufferedImage; 10 | import java.io.IOException; 11 | 12 | import static net.daporkchop.lib.common.util.PValidation.*; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonDeserialize 18 | public class ParsePngISP implements IntScalarParser { 19 | @Override 20 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 21 | BufferedImage image = ImageIO.read(new ByteBufInputStream(buffer)); 22 | 23 | int w = image.getWidth(); 24 | int h = image.getHeight(); 25 | checkArg(w == resolution && h == resolution, "invalid image resolution: %dx%d (expected: %dx%3$d)", w, h, resolution); 26 | 27 | return image.getRGB(0, 0, resolution, resolution, null, 0, resolution); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/ParseTiffISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.ByteBufInputStream; 6 | import lombok.NonNull; 7 | import lombok.SneakyThrows; 8 | import org.apache.commons.imaging.ImageReadException; 9 | import org.apache.commons.imaging.common.bytesource.ByteSourceInputStream; 10 | import org.apache.commons.imaging.formats.tiff.TiffImageParser; 11 | 12 | import java.awt.image.BufferedImage; 13 | import java.io.IOException; 14 | import java.util.Collections; 15 | 16 | import static net.daporkchop.lib.common.util.PValidation.*; 17 | 18 | /** 19 | * @author DaPorkchop_ 20 | */ 21 | @JsonDeserialize 22 | public class ParseTiffISP implements IntScalarParser { 23 | @Override 24 | @SneakyThrows(ImageReadException.class) 25 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 26 | BufferedImage image = new TiffImageParser().getBufferedImage(new ByteSourceInputStream(new ByteBufInputStream(buffer), ""), Collections.emptyMap()); 27 | 28 | int w = image.getWidth(); 29 | int h = image.getHeight(); 30 | checkArg(w == resolution && h == resolution, "invalid image resolution: %dx%d (expected: %dx%3$d)", w, h, resolution); 31 | 32 | return image.getRGB(0, 0, resolution, resolution, null, 0, resolution); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/RGBExtractISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class RGBExtractISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator 22 | public RGBExtractISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int i = 0, len = resolution * resolution; i < len; i++) { 30 | int val = arr[i]; 31 | arr[i] = (val >>> 24) == 0xFF ? arr[i] & 0x00FFFFFF : Integer.MIN_VALUE; 32 | } 33 | return arr; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/RequireOpaqueISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class RequireOpaqueISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) 22 | public RequireOpaqueISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int i = 0, len = resolution * resolution; i < len; i++) { 30 | if ((arr[i] >>> 24) != 0xFF) { //pixel is not fully transparent 31 | arr[i] = Integer.MIN_VALUE; 32 | } 33 | } 34 | return arr; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/config/scalarparse/i/SwapAxesISP.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.config.scalarparse.i; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import io.netty.buffer.ByteBuf; 8 | import lombok.Getter; 9 | import lombok.NonNull; 10 | 11 | import java.io.IOException; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize 17 | @Getter(onMethod_ = { @JsonGetter }) 18 | public class SwapAxesISP implements IntScalarParser { 19 | protected final IntScalarParser delegate; 20 | 21 | @JsonCreator 22 | public SwapAxesISP(@JsonProperty(value = "delegate", required = true) @NonNull IntScalarParser delegate) { 23 | this.delegate = delegate; 24 | } 25 | 26 | @Override 27 | public int[] parse(int resolution, @NonNull ByteBuf buffer) throws IOException { 28 | int[] arr = this.delegate.parse(resolution, buffer); 29 | for (int i = 1; i < resolution; i++) { 30 | for (int j = 0; j < i; j++) { 31 | int a = i * resolution + j; 32 | int b = j * resolution + i; 33 | int t = arr[a]; 34 | arr[a] = arr[b]; 35 | arr[b] = t; 36 | } 37 | } 38 | return arr; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/control/Command.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.control; 2 | 3 | import net.buildtheearth.terraplusplus.TerraConstants; 4 | import net.minecraft.command.CommandBase; 5 | import net.minecraft.command.ICommandSender; 6 | import net.minecraft.entity.player.EntityPlayer; 7 | import net.minecraftforge.server.permission.DefaultPermissionLevel; 8 | import net.minecraftforge.server.permission.PermissionAPI; 9 | 10 | public abstract class Command extends CommandBase { 11 | 12 | public Command() { 13 | PermissionAPI.registerNode(TerraConstants.defaultCommandNode + this.getName(), DefaultPermissionLevel.OP, ""); 14 | } 15 | 16 | protected boolean hasPermission(ICommandSender sender, String perm) { 17 | if (sender instanceof EntityPlayer) { 18 | return PermissionAPI.hasPermission((EntityPlayer) sender, perm); 19 | } 20 | return sender.canUseCommand(2, ""); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/control/TerraCommand.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.control; 2 | 3 | import com.google.common.collect.Lists; 4 | import net.buildtheearth.terraplusplus.TerraConstants; 5 | import net.buildtheearth.terraplusplus.control.fragments.FragmentManager; 6 | import net.buildtheearth.terraplusplus.control.fragments.terra.TerraConvertFragment; 7 | import net.buildtheearth.terraplusplus.control.fragments.terra.TerraDistortionFragment; 8 | import net.buildtheearth.terraplusplus.control.fragments.terra.TerraInfoFragment; 9 | import net.buildtheearth.terraplusplus.control.fragments.terra.TerraWhereFragment; 10 | import net.buildtheearth.terraplusplus.control.fragments.terra.TerraWorldFragment; 11 | import net.minecraft.command.ICommandSender; 12 | import net.minecraft.server.MinecraftServer; 13 | 14 | import java.util.List; 15 | 16 | public class TerraCommand extends FragmentManager { 17 | 18 | public TerraCommand() { 19 | super("terra"); 20 | this.register(new TerraInfoFragment()); 21 | this.register(new TerraWhereFragment()); 22 | this.register(new TerraWorldFragment()); 23 | this.register(new TerraConvertFragment()); 24 | this.register(new TerraDistortionFragment()); 25 | } 26 | 27 | @Override 28 | public List getAliases() { 29 | return Lists.newArrayList("t"); 30 | } 31 | 32 | @Override 33 | public String getName() { 34 | return "terra"; 35 | } 36 | 37 | @Override 38 | public String getUsage(ICommandSender sender) { 39 | return TerraConstants.defaultCommandNode + "terra.usage"; 40 | } 41 | 42 | @Override 43 | public boolean checkPermission(MinecraftServer server, ICommandSender sender) { 44 | return true; 45 | } 46 | 47 | @Override 48 | public int getRequiredPermissionLevel() { 49 | return 0; 50 | } 51 | 52 | @Override 53 | public void execute(MinecraftServer server, ICommandSender sender, String[] args) { 54 | this.executeFragment(server, sender, args); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/control/fragments/CommandFragment.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.control.fragments; 2 | 3 | import net.minecraft.command.ICommandSender; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.server.MinecraftServer; 6 | import net.minecraftforge.fml.common.FMLCommonHandler; 7 | import net.minecraftforge.server.permission.PermissionAPI; 8 | 9 | public abstract class CommandFragment { 10 | protected boolean hasPermission(ICommandSender sender) { 11 | return this.hasPermission(sender, this.getPermission()); 12 | } 13 | 14 | protected boolean hasPermission(ICommandSender sender, String permission) { 15 | if (FMLCommonHandler.instance().getMinecraftServerInstance().isSinglePlayer() && sender.getEntityWorld().getWorldInfo().areCommandsAllowed()) { 16 | return true; 17 | } 18 | if (sender instanceof EntityPlayer) { 19 | return PermissionAPI.hasPermission((EntityPlayer) sender, permission); 20 | } 21 | return sender.canUseCommand(2, ""); 22 | } 23 | 24 | public abstract void execute(MinecraftServer server, ICommandSender sender, String[] args); 25 | 26 | public abstract String[] getName(); 27 | 28 | public abstract String getPurpose(); 29 | 30 | public abstract String[] getArguments(); 31 | 32 | public abstract String getPermission(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/control/fragments/terra/TerraInfoFragment.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.control.fragments.terra; 2 | 3 | import net.buildtheearth.terraplusplus.TerraConstants; 4 | import net.buildtheearth.terraplusplus.control.fragments.CommandFragment; 5 | import net.buildtheearth.terraplusplus.util.ChatUtil; 6 | import net.buildtheearth.terraplusplus.util.TranslateUtil; 7 | import net.minecraft.command.ICommandSender; 8 | import net.minecraft.server.MinecraftServer; 9 | import net.minecraft.util.text.TextComponentString; 10 | import net.minecraft.util.text.TextFormatting; 11 | 12 | public class TerraInfoFragment extends CommandFragment { 13 | @Override 14 | public void execute(MinecraftServer server, ICommandSender sender, String[] args) { 15 | sender.sendMessage(ChatUtil.titleAndCombine(TextFormatting.GREEN, "Terra++ v", TerraConstants.VERSION, 16 | TextFormatting.GRAY, " by the ", TextFormatting.BLUE, "BTE Development Community")); 17 | sender.sendMessage(new TextComponentString(TextFormatting.GOLD + "Original mod by orangeadam3 and shejan0")); 18 | } 19 | 20 | @Override 21 | public String[] getName() { 22 | return new String[]{ "info" }; 23 | } 24 | 25 | @Override 26 | public String getPurpose() { 27 | return TranslateUtil.translate(TerraConstants.MODID + ".fragment.terra.info.purpose").getUnformattedComponentText(); 28 | } 29 | 30 | @Override 31 | public String[] getArguments() { 32 | return null; 33 | } 34 | 35 | @Override 36 | public String getPermission() { 37 | return TerraConstants.MODID + ".commands.terra"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/Dataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import com.google.common.cache.CacheBuilder; 4 | import com.google.common.cache.CacheLoader; 5 | import com.google.common.cache.LoadingCache; 6 | import lombok.NonNull; 7 | 8 | import java.util.concurrent.CompletableFuture; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | public abstract class Dataset extends CacheLoader> implements IDataset { 15 | protected final LoadingCache> cache = CacheBuilder.newBuilder() 16 | .softValues() 17 | .expireAfterAccess(5L, TimeUnit.MINUTES) 18 | .build(this); 19 | 20 | @Override 21 | public CompletableFuture getAsync(@NonNull K key) { 22 | return this.cache.getUnchecked(key); 23 | } 24 | 25 | /** 26 | * @deprecated internal API, don't call this method directly! 27 | */ 28 | @Override 29 | @Deprecated 30 | public abstract CompletableFuture load(@NonNull K key) throws Exception; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/IDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import lombok.NonNull; 4 | 5 | import java.util.concurrent.CompletableFuture; 6 | 7 | /** 8 | * @author DaPorkchop_ 9 | */ 10 | public interface IDataset { 11 | CompletableFuture getAsync(@NonNull K key); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/IElementDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import lombok.NonNull; 4 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 5 | import net.buildtheearth.terraplusplus.util.CornerBoundingBox2d; 6 | 7 | import java.util.concurrent.CompletableFuture; 8 | 9 | /** 10 | * A dataset consisting of arbitrary elements. 11 | * 12 | * @author DaPorkchop_ 13 | */ 14 | public interface IElementDataset { 15 | /** 16 | * Gets all of the elements that intersect the given bounding box. 17 | * 18 | * @param bounds the bounding box 19 | * @return a {@link CompletableFuture} which will be completed with the elements 20 | */ 21 | CompletableFuture getAsync(@NonNull CornerBoundingBox2d bounds) throws OutOfProjectionBoundsException; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/IScalarDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.scalar.ConfigurableDoubleTiledDataset; 6 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 7 | import net.buildtheearth.terraplusplus.util.CornerBoundingBox2d; 8 | 9 | import java.util.concurrent.CompletableFuture; 10 | 11 | /** 12 | * A dataset consisting of floating-point scalar values. 13 | * 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonDeserialize(as = ConfigurableDoubleTiledDataset.class) 17 | public interface IScalarDataset { 18 | /** 19 | * @param point the point 20 | * @see #getAsync(double, double) 21 | */ 22 | default CompletableFuture getAsync(@NonNull double[] point) throws OutOfProjectionBoundsException { 23 | return this.getAsync(point[0], point[1]); 24 | } 25 | 26 | /** 27 | * Asynchronously gets a single value at the given point. 28 | * 29 | * @param lon the longitude 30 | * @param lat the latitude 31 | * @return a {@link CompletableFuture} which will be completed with the value 32 | */ 33 | CompletableFuture getAsync(double lon, double lat) throws OutOfProjectionBoundsException; 34 | 35 | /** 36 | * Asynchronously gets a bunch of values at the given coordinates. 37 | * 38 | * @param sizeX the number of samples to take along the X axis 39 | * @param sizeZ the number of samples to take along the Z axis 40 | * @return a {@link CompletableFuture} which will be completed with the values 41 | */ 42 | CompletableFuture getAsync(@NonNull CornerBoundingBox2d bounds, int sizeX, int sizeZ) throws OutOfProjectionBoundsException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/KeyedHttpDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import lombok.Getter; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.util.http.Http; 8 | 9 | import java.util.Arrays; 10 | import java.util.concurrent.CompletableFuture; 11 | 12 | /** 13 | * @author DaPorkchop_ 14 | */ 15 | @RequiredArgsConstructor 16 | @Getter 17 | public abstract class KeyedHttpDataset extends Dataset { 18 | @NonNull 19 | protected final String[] urls; 20 | 21 | protected abstract V decode(@NonNull String path, @NonNull ByteBuf data) throws Exception; 22 | 23 | @Override 24 | public CompletableFuture load(@NonNull String key) throws Exception { 25 | return Http.getFirst(Arrays.stream(this.urls()).map(s -> s + key).toArray(String[]::new), data -> this.decode(key, data)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/TiledDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.RequiredArgsConstructor; 6 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 7 | import net.minecraft.util.math.ChunkPos; 8 | 9 | @RequiredArgsConstructor 10 | @Getter 11 | public abstract class TiledDataset extends Dataset { 12 | @NonNull 13 | protected final GeographicProjection projection; 14 | protected final double tileSize; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/builtin/Soil.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.builtin; 2 | 3 | import LZMA.LzmaInputStream; 4 | import io.netty.buffer.ByteBuf; 5 | import io.netty.buffer.Unpooled; 6 | import net.buildtheearth.terraplusplus.util.RLEByteArray; 7 | import net.daporkchop.lib.binary.oio.StreamUtil; 8 | import net.daporkchop.lib.common.function.io.IOSupplier; 9 | import net.daporkchop.lib.common.reference.ReferenceStrength; 10 | import net.daporkchop.lib.common.reference.cache.Cached; 11 | 12 | import java.io.InputStream; 13 | 14 | import static net.daporkchop.lib.common.math.PMath.*; 15 | 16 | public class Soil extends AbstractBuiltinDataset { 17 | protected static final int COLS = 10800; 18 | protected static final int ROWS = 5400; 19 | 20 | private static final Cached DATA_CACHE = Cached.global((IOSupplier) () -> { 21 | ByteBuf buf; 22 | try (InputStream in = new LzmaInputStream(Climate.class.getResourceAsStream("soil.lzma"))) { 23 | buf = Unpooled.wrappedBuffer(StreamUtil.toByteArray(in)); 24 | } 25 | 26 | RLEByteArray.Builder builder = RLEByteArray.builder(); 27 | for (int i = 0, lim = buf.readableBytes(); i < lim; i++) { 28 | builder.append(buf.getByte(i)); 29 | } 30 | return builder.build(); 31 | }, ReferenceStrength.SOFT); 32 | 33 | private final RLEByteArray data = DATA_CACHE.get(); 34 | 35 | public Soil() { 36 | super(COLS, ROWS); 37 | } 38 | 39 | @Override 40 | protected double get(double fx, double fy) { 41 | int x = floorI(fx); 42 | int y = floorI(fy); 43 | if (x >= COLS || x < 0 || y >= ROWS || y < 0) { 44 | return 0; 45 | } 46 | return this.data.get(y * COLS + x); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/GeoJson.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson; 2 | 3 | import lombok.NonNull; 4 | import lombok.experimental.UtilityClass; 5 | import net.buildtheearth.terraplusplus.TerraConstants; 6 | 7 | import java.io.Reader; 8 | 9 | /** 10 | * @author DaPorkchop_ 11 | */ 12 | @UtilityClass 13 | public class GeoJson { 14 | /** 15 | * Parses a single GeoJSON object from the given {@link Reader}. 16 | * 17 | * @param in the {@link Reader} to read from 18 | * @return the parsed GeoJSON object 19 | */ 20 | public static GeoJsonObject parse(@NonNull Reader in) { 21 | return TerraConstants.GSON.fromJson(in, GeoJsonObject.class); 22 | } 23 | 24 | /** 25 | * Parses a single GeoJSON object from the given {@link String}. 26 | * 27 | * @param json the {@link String} containing the JSON text 28 | * @return the parsed GeoJSON object 29 | */ 30 | public static GeoJsonObject parse(@NonNull String json) { 31 | return TerraConstants.GSON.fromJson(json, GeoJsonObject.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/GeoJsonObject.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | 5 | /** 6 | * @author DaPorkchop_ 7 | */ 8 | @JsonAdapter(ObjectDeserializer.class) 9 | public interface GeoJsonObject { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/Geometry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Adapted from The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2021 DaPorkchop_ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 9 | * is furnished to do so, subject to the following conditions: 10 | * 11 | * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, 12 | * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 16 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | * 19 | */ 20 | 21 | package net.buildtheearth.terraplusplus.dataset.geojson; 22 | 23 | import com.google.gson.annotations.JsonAdapter; 24 | import lombok.NonNull; 25 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 26 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 27 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 28 | 29 | /** 30 | * @author DaPorkchop_ 31 | */ 32 | @JsonAdapter(GeometryDeserializer.class) 33 | public interface Geometry extends GeoJsonObject { 34 | Geometry project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException; 35 | 36 | Bounds2d bounds(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/GeometryDeserializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Adapted from The MIT License (MIT) 3 | * 4 | * Copyright (c) 2020-2021 DaPorkchop_ 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation 7 | * files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software 9 | * is furnished to do so, subject to the following conditions: 10 | * 11 | * Any persons and/or organizations using this software must include the above copyright notice and this permission notice, 12 | * provide sufficient credit to the original authors of the project (IE: DaPorkchop_), as well as provide a link to the original project. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 15 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 16 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 18 | * 19 | */ 20 | 21 | package net.buildtheearth.terraplusplus.dataset.geojson; 22 | 23 | import com.google.gson.stream.JsonReader; 24 | 25 | import java.io.IOException; 26 | 27 | /** 28 | * @author DaPorkchop_ 29 | */ 30 | final class GeometryDeserializer extends AbstractGeoJsonDeserializer { 31 | public GeometryDeserializer() { 32 | super("geometry"); 33 | } 34 | 35 | @Override 36 | protected Geometry read0(String type, JsonReader in) throws IOException { 37 | return super.readGeometry(type, in); 38 | } 39 | 40 | @Override 41 | protected GeometryDeserializer geometryDeserializer() { 42 | return this; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/dataset/ParsingGeoJsonDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.dataset; 2 | 3 | import io.netty.buffer.ByteBuf; 4 | import io.netty.buffer.ByteBufInputStream; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.KeyedHttpDataset; 7 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJson; 8 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJsonObject; 9 | 10 | import java.io.BufferedReader; 11 | import java.io.InputStreamReader; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | public class ParsingGeoJsonDataset extends KeyedHttpDataset { 17 | public ParsingGeoJsonDataset(@NonNull String[] urls) { 18 | super(urls); 19 | } 20 | 21 | @Override 22 | protected GeoJsonObject[] decode(@NonNull String path, @NonNull ByteBuf data) throws Exception { 23 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteBufInputStream(data)))) { //parse each line as a GeoJSON object 24 | return reader.lines().map(GeoJson::parse).toArray(GeoJsonObject[]::new); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/dataset/ReferenceResolvingGeoJsonDataset.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.dataset; 2 | 3 | import lombok.NonNull; 4 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJsonObject; 5 | 6 | import java.util.Arrays; 7 | import java.util.stream.Stream; 8 | 9 | /** 10 | * @author DaPorkchop_ 11 | */ 12 | public class ReferenceResolvingGeoJsonDataset extends AbstractReferenceResolvingGeoJsonDataset { 13 | public ReferenceResolvingGeoJsonDataset(@NonNull ParsingGeoJsonDataset delegate) { 14 | super(delegate); 15 | } 16 | 17 | @Override 18 | protected GeoJsonObject[] translate(@NonNull Stream inputs) { 19 | return inputs.toArray(GeoJsonObject[]::new); 20 | } 21 | 22 | @Override 23 | protected GeoJsonObject[] merge(@NonNull Stream inputs) { 24 | return inputs.flatMap(Arrays::stream).toArray(GeoJsonObject[]::new); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/GeometryCollection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import com.google.common.collect.Iterators; 4 | import lombok.Data; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | 11 | import java.util.Arrays; 12 | import java.util.Iterator; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @Data 18 | public final class GeometryCollection implements Geometry, Iterable { 19 | @NonNull 20 | protected final Geometry[] geometries; 21 | 22 | @Override 23 | public Iterator iterator() { 24 | return Iterators.forArray(this.geometries); 25 | } 26 | 27 | @Override 28 | public Geometry project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 29 | Geometry[] out = this.geometries.clone(); 30 | for (int i = 0; i < out.length; i++) { 31 | out[i] = out[i].project(projection); 32 | } 33 | return new GeometryCollection(out); 34 | } 35 | 36 | @Override 37 | public Bounds2d bounds() { 38 | return Arrays.stream(this.geometries).map(Geometry::bounds).reduce(Bounds2d::union).orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/LineString.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import lombok.Data; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 6 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 7 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 8 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 9 | 10 | import java.util.Objects; 11 | 12 | import static java.lang.Math.*; 13 | import static net.daporkchop.lib.common.util.PValidation.*; 14 | 15 | /** 16 | * @author DaPorkchop_ 17 | */ 18 | @Data 19 | public final class LineString implements Geometry { 20 | protected final Point[] points; 21 | 22 | public LineString(@NonNull Point[] points) { 23 | checkArg(points.length >= 2, "LineString must contain at least 2 points!"); 24 | this.points = points; 25 | } 26 | 27 | public boolean isLinearRing() { 28 | return this.points.length >= 4 && Objects.equals(this.points[0], this.points[this.points.length - 1]); 29 | } 30 | 31 | @Override 32 | public LineString project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 33 | Point[] out = this.points.clone(); 34 | for (int i = 0; i < out.length; i++) { 35 | out[i] = out[i].project(projection); 36 | } 37 | return new LineString(out); 38 | } 39 | 40 | @Override 41 | public Bounds2d bounds() { 42 | if (this.points.length == 0) { 43 | return null; 44 | } 45 | 46 | double minLon = Double.POSITIVE_INFINITY; 47 | double maxLon = Double.NEGATIVE_INFINITY; 48 | double minLat = Double.POSITIVE_INFINITY; 49 | double maxLat = Double.NEGATIVE_INFINITY; 50 | for (Point point : this.points) { 51 | minLon = min(minLon, point.lon); 52 | maxLon = max(maxLon, point.lon); 53 | minLat = min(minLat, point.lat); 54 | maxLat = max(maxLat, point.lat); 55 | } 56 | return Bounds2d.of(minLon, maxLon, minLat, maxLat); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/MultiLineString.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import com.google.common.collect.Iterators; 4 | import lombok.Data; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | 11 | import java.util.Arrays; 12 | import java.util.Iterator; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @Data 18 | public final class MultiLineString implements Geometry, Iterable { 19 | @NonNull 20 | protected final LineString[] lines; 21 | 22 | @Override 23 | public Iterator iterator() { 24 | return Iterators.forArray(this.lines); 25 | } 26 | 27 | @Override 28 | public MultiLineString project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 29 | LineString[] out = this.lines.clone(); 30 | for (int i = 0; i < out.length; i++) { 31 | out[i] = out[i].project(projection); 32 | } 33 | return new MultiLineString(out); 34 | } 35 | 36 | @Override 37 | public Bounds2d bounds() { 38 | return Arrays.stream(this.lines).map(LineString::bounds).reduce(Bounds2d::union).orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/MultiPoint.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import com.google.common.collect.Iterators; 4 | import lombok.Data; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | 11 | import java.util.Iterator; 12 | 13 | import static java.lang.Math.*; 14 | 15 | /** 16 | * @author DaPorkchop_ 17 | */ 18 | @Data 19 | public final class MultiPoint implements Geometry, Iterable { 20 | @NonNull 21 | protected final Point[] points; 22 | 23 | @Override 24 | public Iterator iterator() { 25 | return Iterators.forArray(this.points); 26 | } 27 | 28 | @Override 29 | public MultiPoint project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 30 | Point[] out = this.points.clone(); 31 | for (int i = 0; i < out.length; i++) { 32 | out[i] = out[i].project(projection); 33 | } 34 | return new MultiPoint(out); 35 | } 36 | 37 | @Override 38 | public Bounds2d bounds() { 39 | if (this.points.length == 0) { 40 | return null; 41 | } 42 | 43 | double minLon = Double.POSITIVE_INFINITY; 44 | double maxLon = Double.NEGATIVE_INFINITY; 45 | double minLat = Double.POSITIVE_INFINITY; 46 | double maxLat = Double.NEGATIVE_INFINITY; 47 | for (Point point : this.points) { 48 | minLon = min(minLon, point.lon); 49 | maxLon = max(maxLon, point.lon); 50 | minLat = min(minLat, point.lat); 51 | maxLat = max(maxLat, point.lat); 52 | } 53 | return Bounds2d.of(minLon, maxLon, minLat, maxLat); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/MultiPolygon.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import com.google.common.collect.Iterators; 4 | import lombok.Data; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | 11 | import java.util.Arrays; 12 | import java.util.Iterator; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @Data 18 | public final class MultiPolygon implements Geometry, Iterable { 19 | @NonNull 20 | protected final Polygon[] polygons; 21 | 22 | @Override 23 | public Iterator iterator() { 24 | return Iterators.forArray(this.polygons); 25 | } 26 | 27 | @Override 28 | public MultiPolygon project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 29 | Polygon[] out = this.polygons.clone(); 30 | for (int i = 0; i < out.length; i++) { 31 | out[i] = out[i].project(projection); 32 | } 33 | return new MultiPolygon(out); 34 | } 35 | 36 | @Override 37 | public Bounds2d bounds() { 38 | return Arrays.stream(this.polygons).map(Polygon::bounds).reduce(Bounds2d::union).orElse(null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/Point.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import lombok.Data; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 6 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 7 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 8 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @Data 14 | public final class Point implements Geometry { 15 | protected final double lon; 16 | protected final double lat; 17 | 18 | @Override 19 | public Point project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 20 | double[] proj = projection.project(this.lon, this.lat); 21 | return new Point(proj[0], proj[1]); 22 | } 23 | 24 | @Override 25 | public Bounds2d bounds() { 26 | return Bounds2d.of(this.lon, this.lon, this.lat, this.lat); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/geometry/Polygon.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.geometry; 2 | 3 | import lombok.Data; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 6 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 7 | import net.buildtheearth.terraplusplus.projection.ProjectionFunction; 8 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 9 | 10 | import static net.daporkchop.lib.common.util.PValidation.*; 11 | 12 | /** 13 | * @author DaPorkchop_ 14 | */ 15 | @Data 16 | public final class Polygon implements Geometry { 17 | protected final LineString outerRing; 18 | protected final LineString[] innerRings; 19 | 20 | public Polygon(@NonNull LineString outerRing, @NonNull LineString[] innerRings) { 21 | checkArg(outerRing.isLinearRing(), "outerRing is not a linear ring!"); 22 | for (int i = 0; i < innerRings.length; i++) { 23 | checkArg(innerRings[i].isLinearRing(), "innerRings[%d] is not a linear ring!", i); 24 | } 25 | this.outerRing = outerRing; 26 | this.innerRings = innerRings; 27 | } 28 | 29 | @Override 30 | public Polygon project(@NonNull ProjectionFunction projection) throws OutOfProjectionBoundsException { 31 | LineString outerRing = this.outerRing.project(projection); 32 | LineString[] innerRings = this.innerRings.clone(); 33 | for (int i = 0; i < innerRings.length; i++) { 34 | innerRings[i] = innerRings[i].project(projection); 35 | } 36 | return new Polygon(outerRing, innerRings); 37 | } 38 | 39 | @Override 40 | public Bounds2d bounds() { 41 | return this.outerRing.bounds(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/object/Feature.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.object; 2 | 3 | import lombok.Data; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJsonObject; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @Data 14 | public final class Feature implements GeoJsonObject { 15 | @NonNull 16 | protected final Geometry geometry; 17 | protected final Map properties; 18 | protected final String id; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/object/FeatureCollection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.object; 2 | 3 | import com.google.common.collect.Iterators; 4 | import lombok.Data; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJsonObject; 7 | 8 | import java.util.Iterator; 9 | 10 | /** 11 | * @author DaPorkchop_ 12 | */ 13 | @Data 14 | public final class FeatureCollection implements GeoJsonObject, Iterable { 15 | @NonNull 16 | protected final Feature[] features; 17 | 18 | @Override 19 | public Iterator iterator() { 20 | return Iterators.forArray(this.features); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/geojson/object/Reference.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.geojson.object; 2 | 3 | import lombok.Data; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.GeoJsonObject; 6 | 7 | /** 8 | * Non-standard GeoJSON object: represents a reference to another URL containing a GeoJSON object that this object should be substituted with. 9 | * 10 | * @author DaPorkchop_ 11 | */ 12 | @Data 13 | public final class Reference implements GeoJsonObject { 14 | @NonNull 15 | protected final String location; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/OSMMapper.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm; 2 | 3 | import com.google.gson.JsonParseException; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.SneakyThrows; 7 | import net.buildtheearth.terraplusplus.TerraConstants; 8 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 9 | import net.buildtheearth.terraplusplus.dataset.vector.geometry.VectorGeometry; 10 | import net.buildtheearth.terraplusplus.util.http.Disk; 11 | import net.daporkchop.lib.binary.oio.reader.UTF8FileReader; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStreamReader; 15 | import java.nio.file.Files; 16 | import java.nio.file.Path; 17 | import java.util.Collection; 18 | import java.util.Map; 19 | 20 | /** 21 | * Consumes a GeoJSON geometry object and emits some number of generateable elements. 22 | * 23 | * @author DaPorkchop_ 24 | */ 25 | @FunctionalInterface 26 | public interface OSMMapper { 27 | @SneakyThrows(IOException.class) 28 | static OSMMapper load() { 29 | Path path = Disk.configFile("osm.json5"); 30 | try (JsonReader reader = new JsonReader(Files.exists(path) 31 | ? new UTF8FileReader(path.toString()) 32 | : new InputStreamReader(OSMMapper.class.getResourceAsStream("osm.json5")))) { 33 | try { 34 | return TerraConstants.GSON.fromJson(reader, Root.class); 35 | } catch (Exception e) { 36 | throw new JsonParseException(reader.toString(), e); 37 | } 38 | } 39 | } 40 | 41 | Collection apply(String id, @NonNull Map tags, @NonNull Geometry originalGeometry, @NonNull G projectedGeometry); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/dvalue/Constant.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.dvalue; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | /** 13 | * Returns a single, constant value. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(Constant.Parser.class) 18 | @RequiredArgsConstructor 19 | final class Constant implements DValue { 20 | protected final double value; 21 | 22 | @Override 23 | public double apply(@NonNull Map tags) { 24 | return this.value; 25 | } 26 | 27 | static class Parser extends JsonParser { 28 | @Override 29 | public DValue read(JsonReader in) throws IOException { 30 | return new Constant(in.nextDouble()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/dvalue/DValue.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.dvalue; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import lombok.NonNull; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | @JsonAdapter(DValueParser.class) 12 | @FunctionalInterface 13 | public interface DValue { 14 | double apply(@NonNull Map tags); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/dvalue/DValueParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.dvalue; 2 | 3 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 4 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public class DValueParser extends JsonParser.Typed { 12 | public static final Map> TYPES = new Object2ObjectOpenHashMap<>(); 13 | 14 | static { 15 | TYPES.put("+", BiOp.Add.class); 16 | TYPES.put("-", BiOp.Subtract.class); 17 | TYPES.put("*", BiOp.Multiply.class); 18 | TYPES.put("/", BiOp.Divide.class); 19 | 20 | TYPES.put("constant", Constant.class); 21 | TYPES.put("floor_div", BiOp.FloorDiv.class); 22 | TYPES.put("min", BiOp.Min.class); 23 | TYPES.put("max", BiOp.Max.class); 24 | TYPES.put("tag", Tag.class); 25 | } 26 | 27 | public DValueParser() { 28 | super("dvalue", TYPES); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/dvalue/Tag.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.dvalue; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import com.google.gson.stream.JsonToken; 6 | import lombok.Builder; 7 | import lombok.NonNull; 8 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 9 | 10 | import java.io.IOException; 11 | import java.util.Map; 12 | 13 | /** 14 | * Returns a single, constant value. 15 | * 16 | * @author DaPorkchop_ 17 | */ 18 | @JsonAdapter(Tag.Parser.class) 19 | @Builder 20 | final class Tag implements DValue { 21 | @NonNull 22 | protected final String key; 23 | protected final double fallback; 24 | 25 | @Override 26 | public double apply(@NonNull Map tags) { 27 | String value = tags.get(this.key); 28 | if (value != null) { 29 | try { 30 | return Double.parseDouble(value); 31 | } catch (NumberFormatException ignored) { 32 | } 33 | } 34 | return this.fallback; 35 | } 36 | 37 | static class Parser extends JsonParser { 38 | @Override 39 | public DValue read(JsonReader in) throws IOException { 40 | TagBuilder builder = builder(); 41 | 42 | in.beginObject(); 43 | while (in.peek() != JsonToken.END_OBJECT) { 44 | String name = in.nextName(); 45 | switch (name) { 46 | case "key": 47 | builder.key(in.nextString().intern()); 48 | break; 49 | case "fallback": 50 | builder.fallback(in.nextDouble()); 51 | break; 52 | default: 53 | throw new IllegalStateException("invalid property: " + name); 54 | } 55 | } 56 | in.endObject(); 57 | 58 | return builder.build(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/mapper/LineMapper.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.mapper; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.MultiLineString; 5 | import net.buildtheearth.terraplusplus.dataset.osm.OSMMapper; 6 | 7 | /** 8 | * @author DaPorkchop_ 9 | */ 10 | @JsonAdapter(LineParser.class) 11 | @FunctionalInterface 12 | public interface LineMapper extends OSMMapper { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/mapper/LineParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.mapper; 2 | 3 | import java.util.Map; 4 | 5 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 6 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public class LineParser extends JsonParser.Typed { 12 | public static final Map> TYPES = new Object2ObjectOpenHashMap<>(); 13 | 14 | static { 15 | TYPES.put("all", All.Line.class); 16 | TYPES.put("any", Any.Line.class); 17 | TYPES.put("condition", Condition.Line.class); 18 | TYPES.put("first", First.Line.class); 19 | TYPES.put("nothing", Nothing.Line.class); 20 | 21 | TYPES.put("narrow", LineNarrow.class); 22 | TYPES.put("sharp", LineSharp.class); 23 | TYPES.put("wide", LineWide.class); 24 | } 25 | 26 | public LineParser() { 27 | super("line", TYPES); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/mapper/PolygonMapper.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.mapper; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.MultiPolygon; 5 | import net.buildtheearth.terraplusplus.dataset.osm.OSMMapper; 6 | 7 | /** 8 | * @author DaPorkchop_ 9 | */ 10 | @JsonAdapter(PolygonParser.class) 11 | @FunctionalInterface 12 | public interface PolygonMapper extends OSMMapper { 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/mapper/PolygonParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.mapper; 2 | 3 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 4 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public class PolygonParser extends JsonParser.Typed { 12 | public static final Map> TYPES = new Object2ObjectOpenHashMap<>(); 13 | 14 | static { 15 | TYPES.put("all", All.Polygon.class); 16 | TYPES.put("any", Any.Polygon.class); 17 | TYPES.put("condition", Condition.Polygon.class); 18 | TYPES.put("convert", PolygonConvert.class); 19 | TYPES.put("first", First.Polygon.class); 20 | TYPES.put("nothing", Nothing.Polygon.class); 21 | 22 | TYPES.put("distance", PolygonDistance.class); 23 | TYPES.put("fill", PolygonFill.class); 24 | } 25 | 26 | public PolygonParser() { 27 | super("polygon", TYPES); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/match/And.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.match; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | /** 13 | * Combines the results of multiple match conditions using a logical AND operation. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(And.Parser.class) 18 | @RequiredArgsConstructor 19 | final class And implements MatchCondition { 20 | @NonNull 21 | protected final MatchCondition[] delegates; 22 | 23 | @Override 24 | public boolean test(String id, @NonNull Map tags, @NonNull Geometry originalGeometry, @NonNull Geometry projectedGeometry) { 25 | for (MatchCondition delegate : this.delegates) { 26 | if (!delegate.test(id, tags, originalGeometry, projectedGeometry)) { 27 | return false; 28 | } 29 | } 30 | return true; 31 | } 32 | 33 | static class Parser extends MatchParser { 34 | @Override 35 | public MatchCondition read(JsonReader in) throws IOException { 36 | return new And(readTypedList(in, this).toArray(new MatchCondition[0])); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/match/MatchCondition.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.match; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 6 | 7 | import java.util.Map; 8 | 9 | /** 10 | * @author DaPorkchop_ 11 | */ 12 | @JsonAdapter(MatchParser.class) 13 | @FunctionalInterface 14 | public interface MatchCondition { 15 | /** 16 | * Always returns {@code false}. 17 | */ 18 | MatchCondition FALSE = (id, tags, originalGeometry, projectedGeometry) -> false; 19 | 20 | boolean test(String id, @NonNull Map tags, @NonNull Geometry originalGeometry, @NonNull Geometry projectedGeometry); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/match/MatchParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.match; 2 | 3 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 4 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public class MatchParser extends JsonParser.Typed { 12 | public static final Map> TYPES = new Object2ObjectOpenHashMap<>(); 13 | 14 | static { 15 | TYPES.put("and", And.class); 16 | TYPES.put("id", Id.class); 17 | TYPES.put("not", Not.class); 18 | TYPES.put("or", Or.class); 19 | 20 | TYPES.put("intersects", Intersects.class); 21 | TYPES.put("tag", Tag.class); 22 | } 23 | 24 | public MatchParser() { 25 | super("match", TYPES); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/match/Not.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.match; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.TerraConstants; 8 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 9 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 10 | 11 | import java.io.IOException; 12 | import java.util.Map; 13 | 14 | /** 15 | * Inverts the result of a single match condition. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | @JsonAdapter(Not.Parser.class) 20 | @RequiredArgsConstructor 21 | final class Not implements MatchCondition { 22 | @NonNull 23 | protected final MatchCondition delegate; 24 | 25 | @Override 26 | public boolean test(String id, @NonNull Map tags, @NonNull Geometry originalGeometry, @NonNull Geometry projectedGeometry) { 27 | return !this.delegate.test(id, tags, originalGeometry, projectedGeometry); 28 | } 29 | 30 | static class Parser extends JsonParser { 31 | @Override 32 | public Not read(JsonReader in) throws IOException { 33 | in.beginObject(); 34 | MatchCondition delegate = TerraConstants.GSON.fromJson(in, MatchCondition.class); 35 | in.endObject(); 36 | return new Not(delegate); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/match/Or.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.osm.match; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.dataset.geojson.Geometry; 8 | 9 | import java.io.IOException; 10 | import java.util.Map; 11 | 12 | /** 13 | * Combines the results of multiple match conditions using a logical OR operation. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(Or.Parser.class) 18 | @RequiredArgsConstructor 19 | final class Or implements MatchCondition { 20 | @NonNull 21 | protected final MatchCondition[] delegates; 22 | 23 | @Override 24 | public boolean test(String id, @NonNull Map tags, @NonNull Geometry originalGeometry, @NonNull Geometry projectedGeometry) { 25 | for (MatchCondition delegate : this.delegates) { 26 | if (delegate.test(id, tags, originalGeometry, projectedGeometry)) { 27 | return true; 28 | } 29 | } 30 | return false; 31 | } 32 | 33 | static class Parser extends MatchParser { 34 | @Override 35 | public MatchCondition read(JsonReader in) throws IOException { 36 | return new Or(readTypedList(in, this).toArray(new MatchCondition[0])); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/osm/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This package and its subpackages contain all the Gson hackery required to deserialize the OpenStreetMap config properly. 3 | *

4 | * I apologize profusely to anyone who has to debug this. 5 | * 6 | * @author DaPorkchop_ 7 | */ 8 | package net.buildtheearth.terraplusplus.dataset.osm; -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/All.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | @JsonAdapter(All.Parser.class) 15 | @RequiredArgsConstructor 16 | final class All implements DrawFunction { 17 | @NonNull 18 | protected final DrawFunction[] delegates; 19 | 20 | @Override 21 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 22 | for (DrawFunction delegate : this.delegates) { 23 | delegate.drawOnto(data, x, z, weight); 24 | } 25 | } 26 | 27 | static class Parser extends DrawFunctionParser { 28 | @Override 29 | public DrawFunction read(JsonReader in) throws IOException { 30 | return new All(readTypedList(in, this).toArray(new DrawFunction[0])); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/Block.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.TerraConstants; 8 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 9 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 10 | import net.minecraft.block.state.IBlockState; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * {@link DrawFunction} which sets the surface block to a fixed block state. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | @JsonAdapter(Block.Parser.class) 20 | @RequiredArgsConstructor 21 | public final class Block implements DrawFunction { 22 | @NonNull 23 | protected final IBlockState state; 24 | 25 | @Override 26 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 27 | data.surfaceBlocks()[x * 16 + z] = this.state; 28 | } 29 | 30 | static class Parser extends JsonParser { 31 | @Override 32 | public Block read(JsonReader in) throws IOException { 33 | return new Block(TerraConstants.GSON.fromJson(in, IBlockState.class)); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/DrawFunction.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 6 | 7 | /** 8 | * Draws pixels onto a {@link CachedChunkData.Builder} while processing geometry. 9 | * 10 | * @author DaPorkchop_ 11 | */ 12 | @JsonAdapter(DrawFunctionParser.class) 13 | @FunctionalInterface 14 | public interface DrawFunction { 15 | /** 16 | * Draws a single pixel onto the given {@link CachedChunkData.Builder}. 17 | * 18 | * @param data the {@link CachedChunkData.Builder} 19 | * @param x the relative X coordinate of the pixel 20 | * @param z the relative Z coordinate of the pixel 21 | * @param weight the pixel weight 22 | */ 23 | void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/DrawFunctionParser.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 4 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public class DrawFunctionParser extends JsonParser.Typed { 12 | public static final Map> TYPES = new Object2ObjectOpenHashMap<>(); 13 | 14 | static { 15 | TYPES.put("all", All.class); 16 | 17 | TYPES.put("weight_add", WeightAdd.class); 18 | TYPES.put("weight_clamp", WeightClamp.class); 19 | TYPES.put("weight_greater_than", WeightGreaterThan.class); 20 | TYPES.put("weight_less_than", WeightLessThan.class); 21 | 22 | TYPES.put("block", Block.class); 23 | TYPES.put("no_trees", NoTrees.class); 24 | TYPES.put("ocean", Ocean.class); 25 | TYPES.put("water", Water.class); 26 | } 27 | 28 | public DrawFunctionParser() { 29 | super("draw", TYPES); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/NoTrees.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 7 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 8 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorPipelines; 9 | 10 | import java.io.IOException; 11 | 12 | /** 13 | * {@link DrawFunction} which removes trees at a given position. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(NoTrees.Parser.class) 18 | final class NoTrees implements DrawFunction { 19 | @Override 20 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 21 | byte[] treeCover = data.getCustom(EarthGeneratorPipelines.KEY_DATA_TREE_COVER, null); 22 | if (treeCover != null) { 23 | treeCover[x * 16 + z] = (byte) 0; //set chance to 0 24 | } 25 | } 26 | 27 | static class Parser extends JsonParser { 28 | @Override 29 | public NoTrees read(JsonReader in) throws IOException { 30 | in.beginObject(); 31 | in.endObject(); 32 | return new NoTrees(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/Ocean.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 7 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * {@link DrawFunction} which updates the water depth based on the pixel weight. 13 | * 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonAdapter(Ocean.Parser.class) 17 | final class Ocean implements DrawFunction { 18 | @Override 19 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 20 | data.updateOceanDepth(x, z, weight); 21 | } 22 | 23 | static class Parser extends JsonParser { 24 | @Override 25 | public Ocean read(JsonReader in) throws IOException { 26 | in.beginObject(); 27 | in.endObject(); 28 | return new Ocean(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/Water.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import lombok.NonNull; 6 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 7 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * {@link DrawFunction} which updates the water depth based on the pixel weight. 13 | * 14 | * @author DaPorkchop_ 15 | */ 16 | @JsonAdapter(Water.Parser.class) 17 | final class Water implements DrawFunction { 18 | @Override 19 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 20 | data.updateWaterDepth(x, z, weight); 21 | } 22 | 23 | static class Parser extends JsonParser { 24 | @Override 25 | public Water read(JsonReader in) throws IOException { 26 | in.beginObject(); 27 | in.endObject(); 28 | return new Water(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/WeightAdd.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import com.google.gson.stream.JsonToken; 6 | import lombok.Builder; 7 | import lombok.NonNull; 8 | import net.buildtheearth.terraplusplus.TerraConstants; 9 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 10 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(WeightAdd.Parser.class) 18 | @Builder 19 | final class WeightAdd implements DrawFunction { 20 | @NonNull 21 | protected final DrawFunction delegate; 22 | protected final int value; 23 | 24 | @Override 25 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 26 | this.delegate.drawOnto(data, x, z, weight + this.value); 27 | } 28 | 29 | static class Parser extends JsonParser { 30 | @Override 31 | public WeightAdd read(JsonReader in) throws IOException { 32 | WeightAddBuilder builder = builder(); 33 | 34 | in.beginObject(); 35 | while (in.peek() != JsonToken.END_OBJECT) { 36 | String name = in.nextName(); 37 | switch (name) { 38 | case "value": 39 | builder.value(in.nextInt()); 40 | break; 41 | case "delegate": 42 | in.beginObject(); 43 | builder.delegate(TerraConstants.GSON.fromJson(in, DrawFunction.class)); 44 | in.endObject(); 45 | break; 46 | default: 47 | throw new IllegalStateException("invalid property: " + name); 48 | } 49 | } 50 | in.endObject(); 51 | 52 | return builder.build(); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/WeightGreaterThan.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import com.google.gson.stream.JsonToken; 6 | import lombok.Builder; 7 | import lombok.NonNull; 8 | import net.buildtheearth.terraplusplus.TerraConstants; 9 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 10 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(WeightGreaterThan.Parser.class) 18 | @Builder 19 | final class WeightGreaterThan implements DrawFunction { 20 | @NonNull 21 | protected final DrawFunction delegate; 22 | protected final int value; 23 | 24 | @Override 25 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 26 | if (weight > this.value) { 27 | this.delegate.drawOnto(data, x, z, weight); 28 | } 29 | } 30 | 31 | static class Parser extends JsonParser { 32 | @Override 33 | public WeightGreaterThan read(JsonReader in) throws IOException { 34 | WeightGreaterThanBuilder builder = builder(); 35 | 36 | in.beginObject(); 37 | while (in.peek() != JsonToken.END_OBJECT) { 38 | String name = in.nextName(); 39 | switch (name) { 40 | case "value": 41 | builder.value(in.nextInt()); 42 | break; 43 | case "delegate": 44 | in.beginObject(); 45 | builder.delegate(TerraConstants.GSON.fromJson(in, DrawFunction.class)); 46 | in.endObject(); 47 | break; 48 | default: 49 | throw new IllegalStateException("invalid property: " + name); 50 | } 51 | } 52 | in.endObject(); 53 | 54 | return builder.build(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/draw/WeightLessThan.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.draw; 2 | 3 | import com.google.gson.annotations.JsonAdapter; 4 | import com.google.gson.stream.JsonReader; 5 | import com.google.gson.stream.JsonToken; 6 | import lombok.Builder; 7 | import lombok.NonNull; 8 | import net.buildtheearth.terraplusplus.TerraConstants; 9 | import net.buildtheearth.terraplusplus.dataset.osm.JsonParser; 10 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 11 | 12 | import java.io.IOException; 13 | 14 | /** 15 | * @author DaPorkchop_ 16 | */ 17 | @JsonAdapter(WeightLessThan.Parser.class) 18 | @Builder 19 | final class WeightLessThan implements DrawFunction { 20 | @NonNull 21 | protected final DrawFunction delegate; 22 | protected final int value; 23 | 24 | @Override 25 | public void drawOnto(@NonNull CachedChunkData.Builder data, int x, int z, int weight) { 26 | if (weight < this.value) { 27 | this.delegate.drawOnto(data, x, z, weight); 28 | } 29 | } 30 | 31 | static class Parser extends JsonParser { 32 | @Override 33 | public WeightLessThan read(JsonReader in) throws IOException { 34 | WeightLessThanBuilder builder = builder(); 35 | 36 | in.beginObject(); 37 | while (in.peek() != JsonToken.END_OBJECT) { 38 | String name = in.nextName(); 39 | switch (name) { 40 | case "value": 41 | builder.value(in.nextInt()); 42 | break; 43 | case "delegate": 44 | in.beginObject(); 45 | builder.delegate(TerraConstants.GSON.fromJson(in, DrawFunction.class)); 46 | in.endObject(); 47 | break; 48 | default: 49 | throw new IllegalStateException("invalid property: " + name); 50 | } 51 | } 52 | in.endObject(); 53 | 54 | return builder.build(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/geometry/AbstractVectorGeometry.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.geometry; 2 | 3 | import lombok.EqualsAndHashCode; 4 | import lombok.Getter; 5 | import lombok.NonNull; 6 | import lombok.RequiredArgsConstructor; 7 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.LineString; 8 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.Point; 9 | import net.buildtheearth.terraplusplus.dataset.vector.draw.DrawFunction; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | @RequiredArgsConstructor 17 | @Getter 18 | @EqualsAndHashCode 19 | public abstract class AbstractVectorGeometry implements VectorGeometry { 20 | protected static void convertToSegments(@NonNull LineString line, @NonNull List segments) { 21 | Point[] points = line.points(); 22 | Point prev = points[0]; 23 | for (int i = 1; i < points.length; i++) { 24 | Point next = points[i]; 25 | segments.add(new Segment(prev.lon(), prev.lat(), next.lon(), next.lat())); 26 | prev = next; 27 | } 28 | } 29 | 30 | @NonNull 31 | protected final String id; 32 | protected final double layer; 33 | @NonNull 34 | protected final DrawFunction draw; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/geometry/Segment.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.geometry; 2 | 3 | import lombok.EqualsAndHashCode; 4 | import lombok.Getter; 5 | import lombok.RequiredArgsConstructor; 6 | import lombok.ToString; 7 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 8 | import net.buildtheearth.terraplusplus.util.interval.Interval; 9 | 10 | /** 11 | * A simple representation of a line segment as a pair of two sets of coordinates. 12 | * 13 | * @author DaPorkchop_ 14 | */ 15 | @RequiredArgsConstructor 16 | @Getter 17 | @ToString 18 | @EqualsAndHashCode 19 | public final class Segment implements Bounds2d, Interval { 20 | protected final double x0; 21 | protected final double z0; 22 | protected final double x1; 23 | protected final double z1; 24 | 25 | //bounds2d 26 | 27 | @Override 28 | public double minX() { 29 | return Math.min(this.x0, this.x1); 30 | } 31 | 32 | @Override 33 | public double maxX() { 34 | return Math.max(this.x0, this.x1); 35 | } 36 | 37 | @Override 38 | public double minZ() { 39 | return Math.min(this.z0, this.z1); 40 | } 41 | 42 | @Override 43 | public double maxZ() { 44 | return Math.max(this.z0, this.z1); 45 | } 46 | 47 | //interval 48 | 49 | @Override 50 | public double min() { 51 | return this.minX(); 52 | } 53 | 54 | @Override 55 | public double max() { 56 | return this.maxX(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/geometry/VectorGeometry.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.geometry; 2 | 3 | import lombok.NonNull; 4 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 5 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 6 | 7 | /** 8 | * A generate-able OpenStreetMap element. 9 | * 10 | * @author DaPorkchop_ 11 | */ 12 | public interface VectorGeometry extends Comparable, Bounds2d { 13 | /** 14 | * Modifies the given {@link CachedChunkData.Builder} for the given chunk 15 | * 16 | * @param builder the {@link CachedChunkData.Builder} 17 | * @param chunkX the chunk's X coordinate 18 | * @param chunkZ the chunk's Z coordinate 19 | * @param bounds the chunk's bounding box 20 | */ 21 | void apply(@NonNull CachedChunkData.Builder builder, int chunkX, int chunkZ, @NonNull Bounds2d bounds); 22 | 23 | /** 24 | * @return this element's id 25 | */ 26 | String id(); 27 | 28 | /** 29 | * @return the map layer that this element is on 30 | */ 31 | double layer(); 32 | 33 | @Override 34 | default int compareTo(VectorGeometry o) { 35 | int d = Double.compare(this.layer(), o.layer()); 36 | if (d == 0) { //elements are on the same layer, compare IDs 37 | return this.id().compareTo(o.id()); 38 | } else { 39 | return d; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/geometry/line/AbstractLine.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.geometry.line; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.LineString; 6 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.MultiLineString; 7 | import net.buildtheearth.terraplusplus.dataset.vector.draw.DrawFunction; 8 | import net.buildtheearth.terraplusplus.dataset.vector.geometry.AbstractVectorGeometry; 9 | import net.buildtheearth.terraplusplus.dataset.vector.geometry.Segment; 10 | import net.buildtheearth.terraplusplus.util.bvh.BVH; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | /** 16 | * @author DaPorkchop_ 17 | */ 18 | @Getter 19 | public abstract class AbstractLine extends AbstractVectorGeometry { 20 | protected final BVH segments; 21 | 22 | public AbstractLine(@NonNull String id, double layer, @NonNull DrawFunction draw, @NonNull MultiLineString lines) { 23 | super(id, layer, draw); 24 | 25 | List segments = new ArrayList<>(); 26 | for (LineString line : lines.lines()) { //convert MultiLineString to line segments 27 | convertToSegments(line, segments); 28 | } 29 | this.segments = BVH.of(segments.toArray(new Segment[0])); 30 | } 31 | 32 | @Override 33 | public double minX() { 34 | return this.segments.minX(); 35 | } 36 | 37 | @Override 38 | public double maxX() { 39 | return this.segments.maxX(); 40 | } 41 | 42 | @Override 43 | public double minZ() { 44 | return this.segments.minZ(); 45 | } 46 | 47 | @Override 48 | public double maxZ() { 49 | return this.segments.maxZ(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/dataset/vector/geometry/polygon/FillPolygon.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.dataset.vector.geometry.polygon; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.util.Coords; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.dataset.geojson.geometry.MultiPolygon; 6 | import net.buildtheearth.terraplusplus.dataset.vector.draw.DrawFunction; 7 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 8 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 9 | 10 | import static net.daporkchop.lib.common.math.PMath.*; 11 | 12 | /** 13 | * @author DaPorkchop_ 14 | */ 15 | public final class FillPolygon extends AbstractPolygon { 16 | public FillPolygon(@NonNull String id, double layer, @NonNull DrawFunction draw, @NonNull MultiPolygon polygons) { 17 | super(id, layer, draw, polygons); 18 | } 19 | 20 | @Override 21 | public void apply(@NonNull CachedChunkData.Builder builder, int chunkX, int chunkZ, @NonNull Bounds2d bounds) { 22 | int baseX = Coords.cubeToMinBlock(chunkX); 23 | int baseZ = Coords.cubeToMinBlock(chunkZ); 24 | 25 | for (int x = 0; x < 16; x++) { 26 | double[] intersectionPoints = this.getIntersectionPoints(x + baseX); 27 | 28 | for (int i = 0; i < intersectionPoints.length; ) { 29 | int min = clamp(floorI(intersectionPoints[i++]) - baseZ, 0, 16); 30 | int max = clamp(floorI(intersectionPoints[i++]) - baseZ, 0, 16); 31 | for (int z = min; z < max; z++) { 32 | this.draw.drawOnto(builder, x, z, 1); 33 | } 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/event/AbstractCustomRegistrationEvent.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.event; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; 5 | import lombok.NonNull; 6 | import net.minecraftforge.fml.common.eventhandler.Event; 7 | 8 | import java.util.Collections; 9 | import java.util.Map; 10 | 11 | import static net.daporkchop.lib.common.util.PorkUtil.*; 12 | 13 | /** 14 | * @author DaPorkchop_ 15 | */ 16 | public abstract class AbstractCustomRegistrationEvent extends Event { 17 | protected final Map custom = new Object2ObjectOpenHashMap<>(); 18 | 19 | public void register(@NonNull String key, @NonNull Object value) { 20 | this.custom.put(key, value); 21 | } 22 | 23 | public void remove(@NonNull String key) { 24 | this.custom.remove(key); 25 | } 26 | 27 | public T get(@NonNull String key) { 28 | return uncheckedCast(this.custom.get(key)); 29 | } 30 | 31 | public Map getAllCustomProperties() { 32 | return this.custom.isEmpty() ? Collections.emptyMap() : ImmutableMap.copyOf(this.custom); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/event/InitDatasetsEvent.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.event; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import lombok.RequiredArgsConstructor; 6 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings; 7 | import net.buildtheearth.terraplusplus.generator.GeneratorDatasets; 8 | import net.minecraftforge.common.MinecraftForge; 9 | 10 | /** 11 | * Fired on {@link MinecraftForge#TERRAIN_GEN_BUS} when a new instance of {@link GeneratorDatasets} is being constructed. 12 | *

13 | * Allows custom datasets to be registered. 14 | * 15 | * @author DaPorkchop_ 16 | */ 17 | @RequiredArgsConstructor 18 | @Getter 19 | public class InitDatasetsEvent extends AbstractCustomRegistrationEvent { 20 | @NonNull 21 | protected final EarthGeneratorSettings settings; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/event/InitEarthRegistryEvent.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.event; 2 | 3 | import lombok.AccessLevel; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NonNull; 7 | import lombok.Setter; 8 | import lombok.experimental.Accessors; 9 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings; 10 | import net.buildtheearth.terraplusplus.util.OrderedRegistry; 11 | import net.daporkchop.lib.common.util.GenericMatcher; 12 | import net.minecraftforge.common.MinecraftForge; 13 | import net.minecraftforge.fml.common.eventhandler.Event; 14 | import net.minecraftforge.fml.common.eventhandler.IGenericEvent; 15 | 16 | /** 17 | * Fired when an {@link OrderedRegistry} is being initialized. 18 | *

19 | * This event is fired on {@link MinecraftForge#TERRAIN_GEN_BUS}. 20 | * 21 | * @author DaPorkchop_ 22 | */ 23 | @AllArgsConstructor(access = AccessLevel.PROTECTED) 24 | @Getter 25 | @Setter 26 | public class InitEarthRegistryEvent extends Event implements IGenericEvent { 27 | @NonNull 28 | protected final EarthGeneratorSettings settings; 29 | @NonNull 30 | protected OrderedRegistry registry; 31 | 32 | @Accessors(fluent = false) 33 | protected final Class genericType = GenericMatcher.uncheckedFind(this.getClass(), InitEarthRegistryEvent.class, "T"); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/ChunkBiomesBuilder.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator; 2 | 3 | import lombok.Getter; 4 | import net.buildtheearth.terraplusplus.util.ImmutableCompactArray; 5 | import net.daporkchop.lib.common.reference.ReferenceStrength; 6 | import net.daporkchop.lib.common.reference.cache.Cached; 7 | import net.minecraft.world.biome.Biome; 8 | 9 | import java.util.Arrays; 10 | 11 | /** 12 | * Builds a 16x16 area of chunks. 13 | * 14 | * @author DaPorkchop_ 15 | */ 16 | @Getter 17 | public class ChunkBiomesBuilder implements IEarthAsyncDataBuilder> { 18 | private static final Cached BUILDER_CACHE = Cached.threadLocal(ChunkBiomesBuilder::new, ReferenceStrength.SOFT); 19 | 20 | public static ChunkBiomesBuilder get() { 21 | return BUILDER_CACHE.get().reset(); 22 | } 23 | 24 | protected final Biome[] state = new Biome[16 * 16]; 25 | 26 | public Biome get(int x, int z) { 27 | return this.state[x * 16 + z]; 28 | } 29 | 30 | public ChunkBiomesBuilder set(int x, int z, Biome biome) { 31 | this.state[x * 16 + z] = biome; 32 | return this; 33 | } 34 | 35 | /** 36 | * Resets this builder instance so that it may be used again. 37 | */ 38 | public ChunkBiomesBuilder reset() { 39 | Arrays.fill(this.state, null); 40 | return this; 41 | } 42 | 43 | /** 44 | * @return the array of biomes in this chunk 45 | */ 46 | @Override 47 | public ImmutableCompactArray build() { 48 | for (int i = 0; i < 16 * 16; i++) { 49 | if (this.state[i] == null) { 50 | throw new IllegalStateException("all biomes must be set!"); 51 | } 52 | } 53 | return new ImmutableCompactArray<>(this.state); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/CliffReplacer.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator; 2 | 3 | import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.IBiomeBlockReplacer; 4 | import lombok.AccessLevel; 5 | import lombok.NoArgsConstructor; 6 | import net.minecraft.block.Block; 7 | import net.minecraft.block.state.IBlockState; 8 | import net.minecraft.init.Blocks; 9 | 10 | /** 11 | * Prevents sheer cliff faces from being grass or dirt. 12 | */ 13 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 14 | public final class CliffReplacer implements IBiomeBlockReplacer { 15 | public static final CliffReplacer INSTANCE = new CliffReplacer(); 16 | 17 | private static final IBlockState STONE = Blocks.STONE.getDefaultState(); 18 | 19 | @Override 20 | public IBlockState getReplacedBlock(IBlockState prev, int x, int y, int z, double dx, double dy, double dz, double density) { 21 | if (y > 6000 || dx * dx + dz * dz > 4.0d) { 22 | Block block = prev.getBlock(); 23 | if (block == Blocks.GRASS || block == Blocks.DIRT) { 24 | return STONE; 25 | } 26 | } 27 | 28 | return prev; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/GeneratorDatasets.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator; 2 | 3 | import lombok.Getter; 4 | import lombok.NonNull; 5 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 6 | import net.buildtheearth.terraplusplus.util.CustomAttributeContainer; 7 | 8 | /** 9 | * Wrapper class which contains all of the datasets used by {@link EarthGenerator}. 10 | * 11 | * @author DaPorkchop_ 12 | */ 13 | @Getter 14 | public class GeneratorDatasets extends CustomAttributeContainer { 15 | protected final GeographicProjection projection; 16 | 17 | public GeneratorDatasets(@NonNull EarthGeneratorSettings settings) { 18 | super(EarthGeneratorPipelines.datasets(settings)); 19 | 20 | this.projection = settings.projection(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/IEarthAsyncDataBuilder.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator; 2 | 3 | /** 4 | * @author DaPorkchop_ 5 | */ 6 | public interface IEarthAsyncDataBuilder { 7 | /** 8 | * @return the built value 9 | */ 10 | V build(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/biome/IEarthBiomeFilter.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.biome; 2 | 3 | import net.buildtheearth.terraplusplus.generator.ChunkBiomesBuilder; 4 | import net.buildtheearth.terraplusplus.generator.IEarthAsyncPipelineStep; 5 | import net.buildtheearth.terraplusplus.util.ImmutableCompactArray; 6 | import net.minecraft.world.biome.Biome; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | public interface IEarthBiomeFilter extends IEarthAsyncPipelineStep, ChunkBiomesBuilder> { 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/data/HeightsBaker.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.data; 2 | 3 | import net.buildtheearth.terraplusplus.dataset.IScalarDataset; 4 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 5 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorPipelines; 6 | import net.buildtheearth.terraplusplus.generator.GeneratorDatasets; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.util.CornerBoundingBox2d; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | import net.minecraft.util.math.ChunkPos; 11 | 12 | import java.util.Arrays; 13 | import java.util.concurrent.CompletableFuture; 14 | 15 | import static net.daporkchop.lib.common.math.PMath.*; 16 | 17 | /** 18 | * @author DaPorkchop_ 19 | */ 20 | public class HeightsBaker implements IEarthDataBaker { 21 | @Override 22 | public CompletableFuture requestData(ChunkPos pos, GeneratorDatasets datasets, Bounds2d bounds, CornerBoundingBox2d boundsGeo) throws OutOfProjectionBoundsException { 23 | return datasets.getCustom(EarthGeneratorPipelines.KEY_DATASET_HEIGHTS).getAsync(boundsGeo, 16, 16); 24 | } 25 | 26 | @Override 27 | public void bake(ChunkPos pos, CachedChunkData.Builder builder, double[] heights) { 28 | if (heights == null) { //consider heights array to be filled with NaNs 29 | Arrays.fill(builder.waterDepth(), (byte) (CachedChunkData.WATERDEPTH_TYPE_OCEAN | ~CachedChunkData.WATERDEPTH_TYPE_MASK)); 30 | return; //we assume the builder's heights are already all set to the blank height value 31 | } 32 | 33 | for (int x = 0; x < 16; x++) { 34 | for (int z = 0; z < 16; z++) { 35 | double height = heights[x * 16 + z]; 36 | if (!Double.isNaN(height)) { 37 | builder.surfaceHeight(x, z, floorI(height)); 38 | } else { 39 | builder.updateOceanDepth(x, z, 0); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/data/IEarthDataBaker.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.data; 2 | 3 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 4 | import net.buildtheearth.terraplusplus.generator.IEarthAsyncPipelineStep; 5 | 6 | /** 7 | * @author DaPorkchop_ 8 | */ 9 | public interface IEarthDataBaker extends IEarthAsyncPipelineStep { 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/data/InitialBiomesBaker.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.data; 2 | 3 | import lombok.NonNull; 4 | import lombok.RequiredArgsConstructor; 5 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 6 | import net.buildtheearth.terraplusplus.generator.EarthBiomeProvider; 7 | import net.buildtheearth.terraplusplus.generator.GeneratorDatasets; 8 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 9 | import net.buildtheearth.terraplusplus.util.CornerBoundingBox2d; 10 | import net.buildtheearth.terraplusplus.util.ImmutableCompactArray; 11 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 12 | import net.minecraft.util.math.ChunkPos; 13 | import net.minecraft.world.biome.Biome; 14 | import net.minecraft.world.biome.BiomeProvider; 15 | 16 | import java.util.concurrent.CompletableFuture; 17 | 18 | /** 19 | * @author DaPorkchop_ 20 | */ 21 | @RequiredArgsConstructor 22 | public class InitialBiomesBaker implements IEarthDataBaker> { 23 | @NonNull 24 | protected final EarthBiomeProvider biomeProvider; 25 | 26 | @Override 27 | public CompletableFuture> requestData(ChunkPos pos, GeneratorDatasets datasets, Bounds2d bounds, CornerBoundingBox2d boundsGeo) throws OutOfProjectionBoundsException { 28 | return this.biomeProvider.getBiomesForChunkAsync(pos); 29 | } 30 | 31 | @Override 32 | public void bake(ChunkPos pos, CachedChunkData.Builder builder, ImmutableCompactArray biomes) { 33 | if (biomes == null) { //can occur if chunk coordinates are outside projection bounds 34 | return; 35 | } 36 | 37 | for (int zz = 0; zz < 16; zz++) { 38 | for (int xx = 0; xx < 16; xx++) { //reverse coordinate order 39 | builder.biomes()[zz * 16 + xx] = biomes.get(xx * 16 + zz); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/data/NullIslandBaker.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.data; 2 | 3 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 4 | import net.buildtheearth.terraplusplus.generator.EarthGenerator; 5 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorPipelines; 6 | import net.buildtheearth.terraplusplus.generator.GeneratorDatasets; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | import net.buildtheearth.terraplusplus.util.CornerBoundingBox2d; 9 | import net.buildtheearth.terraplusplus.util.bvh.Bounds2d; 10 | import net.minecraft.init.Biomes; 11 | import net.minecraft.util.math.ChunkPos; 12 | 13 | import java.util.Arrays; 14 | import java.util.concurrent.CompletableFuture; 15 | 16 | /** 17 | * Sets the surface height at null island to 1. 18 | * 19 | * @author DaPorkchop_ 20 | */ 21 | public class NullIslandBaker implements IEarthDataBaker { 22 | @Override 23 | public CompletableFuture requestData(ChunkPos pos, GeneratorDatasets datasets, Bounds2d bounds, CornerBoundingBox2d boundsGeo) throws OutOfProjectionBoundsException { 24 | return null; 25 | } 26 | 27 | @Override 28 | public void bake(ChunkPos pos, CachedChunkData.Builder builder, Void data) { 29 | if (EarthGenerator.isNullIsland(pos.x, pos.z)) { 30 | Arrays.fill(builder.surfaceHeight(), -1); 31 | 32 | byte[] trees = builder.getCustom(EarthGeneratorPipelines.KEY_DATA_TREE_COVER, null); 33 | if (trees != null) { 34 | Arrays.fill(trees, (byte) 0); 35 | } 36 | 37 | if (((pos.x ^ (pos.x >> 31)) | (pos.z ^ (pos.z >> 31))) == 0) { 38 | Arrays.fill(builder.biomes(), Biomes.FOREST); 39 | } else { 40 | Arrays.fill(builder.biomes(), Biomes.PLAINS); 41 | } 42 | 43 | Arrays.fill(builder.waterDepth(), (byte) CachedChunkData.WATERDEPTH_DEFAULT); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/populate/BiomeDecorationPopulator.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.populate; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.util.CubePos; 4 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.ICubicPopulator; 5 | import io.github.opencubicchunks.cubicchunks.cubicgen.common.biome.CubicBiome; 6 | import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap; 7 | import lombok.NonNull; 8 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 9 | import net.buildtheearth.terraplusplus.generator.EarthGeneratorSettings; 10 | import net.minecraft.world.World; 11 | import net.minecraft.world.biome.Biome; 12 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 13 | 14 | import java.util.Map; 15 | import java.util.Random; 16 | 17 | /** 18 | * Implementation of {@link IEarthPopulator} which delegates tasks to ordinary cubic populators for the biome in the given cube. 19 | * 20 | * @author DaPorkchop_ 21 | */ 22 | public class BiomeDecorationPopulator implements IEarthPopulator { 23 | protected final Map populators = new Reference2ObjectOpenHashMap<>(ForgeRegistries.BIOMES.getKeys().size()); 24 | 25 | public BiomeDecorationPopulator(@NonNull EarthGeneratorSettings settings) { 26 | for (Biome biome : ForgeRegistries.BIOMES) { 27 | this.populators.put(biome, CubicBiome.getCubic(biome).getDecorator(settings.customCubic())); 28 | } 29 | } 30 | 31 | @Override 32 | public void populate(World world, Random random, CubePos pos, Biome biome, CachedChunkData[] datas) { 33 | this.populators.get(biome).generate(world, random, pos, biome); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/populate/CompatibilityEarthPopulators.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.populate; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.util.CubePos; 4 | import io.github.opencubicchunks.cubicchunks.api.worldgen.CubeGeneratorsRegistry; 5 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.event.PopulateCubeEvent; 6 | import lombok.experimental.UtilityClass; 7 | import net.minecraft.world.World; 8 | import net.minecraft.world.biome.Biome; 9 | import net.minecraftforge.common.MinecraftForge; 10 | 11 | import java.util.Random; 12 | 13 | /** 14 | * {@link IEarthPopulator}s for inter-mod compatibility. 15 | * 16 | * @author DaPorkchop_ 17 | */ 18 | @UtilityClass 19 | public class CompatibilityEarthPopulators { 20 | /** 21 | * Fires {@link PopulateCubeEvent.Pre}. 22 | */ 23 | public IEarthPopulator cubePopulatePre() { 24 | return (world, random, pos, biome, datas) -> 25 | MinecraftForge.EVENT_BUS.post(new PopulateCubeEvent.Pre(world, random, pos.getX(), pos.getY(), pos.getZ(), false)); 26 | } 27 | 28 | /** 29 | * Fires {@link PopulateCubeEvent.Post}. 30 | */ 31 | public IEarthPopulator cubePopulatePost() { 32 | return (world, random, pos, biome, datas) -> 33 | MinecraftForge.EVENT_BUS.post(new PopulateCubeEvent.Post(world, random, pos.getX(), pos.getY(), pos.getZ(), false)); 34 | } 35 | 36 | /** 37 | * Calls {@link CubeGeneratorsRegistry#generateWorld(World, Random, CubePos, Biome)}. 38 | */ 39 | public IEarthPopulator cubeGeneratorsRegistry() { 40 | return (world, random, pos, biome, datas) -> CubeGeneratorsRegistry.generateWorld(world, random, pos, biome); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/generator/populate/IEarthPopulator.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.generator.populate; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.util.CubePos; 4 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.ICubicPopulator; 5 | import net.buildtheearth.terraplusplus.generator.CachedChunkData; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.biome.Biome; 8 | 9 | import java.util.Random; 10 | 11 | /** 12 | * A cube populator for earth terrain data. 13 | * 14 | * @author DaPorkchop_ 15 | * @see ICubicPopulator 16 | */ 17 | @FunctionalInterface 18 | public interface IEarthPopulator { 19 | /** 20 | * @param datas the {@link CachedChunkData} for the 2x2 column area being populated 21 | * @see ICubicPopulator#generate(World, Random, CubePos, Biome) 22 | */ 23 | void populate(World world, Random random, CubePos pos, Biome biome, CachedChunkData[] datas); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/EquirectangularProjection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | 5 | /** 6 | * Implements the equirectangular map projection, which applies no transformation at all. 7 | * x and y are therefore the same as longitude and latitude (in degrees). 8 | */ 9 | @JsonDeserialize 10 | public class EquirectangularProjection implements GeographicProjection { 11 | /** 12 | * Converts map coordinates to geographic coordinates 13 | * 14 | * @param x - x map coordinate 15 | * @param y - y map coordinate 16 | * @return {longitude, latitude} in degrees 17 | */ 18 | @Override 19 | public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException { 20 | OutOfProjectionBoundsException.checkLongitudeLatitudeInRange(x, y); 21 | return new double[]{ x, y }; 22 | } 23 | 24 | /** 25 | * Converts geographic coordinates to map coordinates 26 | * 27 | * @param longitude - longitude, in degrees 28 | * @param latitude - latitude, in degrees 29 | * @return {x, y} map coordinates 30 | */ 31 | @Override 32 | public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException { 33 | OutOfProjectionBoundsException.checkLongitudeLatitudeInRange(longitude, latitude); 34 | return new double[]{ longitude, latitude }; 35 | } 36 | 37 | /** 38 | * Gives an estimation of the scale of this projection. 39 | * This is just an estimation, as distortion is inevitable when projecting a sphere onto a flat surface, 40 | * so this value varies from places to places in reality. 41 | * 42 | * @return an estimation of the scale of this projection 43 | */ 44 | @Override 45 | public double metersPerUnit() { 46 | return 100000; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return "Equirectangular"; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/OutOfProjectionBoundsException.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection; 2 | 3 | public final class OutOfProjectionBoundsException extends Exception { 4 | private static final OutOfProjectionBoundsException INSTANCE = new OutOfProjectionBoundsException(false); 5 | 6 | private static final boolean FAST = Boolean.parseBoolean(System.getProperty("terraplusplus.fastExcept", "true")); 7 | 8 | public static OutOfProjectionBoundsException get() { 9 | if (FAST) { 10 | return INSTANCE; 11 | } else { 12 | return new OutOfProjectionBoundsException(true); 13 | } 14 | } 15 | 16 | /** 17 | * @param x 18 | * @param y 19 | * @param maxX 20 | * @param maxY 21 | * @throws OutOfProjectionBoundsException if Math.abs(x) > maxX || Math.abs(y) > maxY 22 | */ 23 | public static void checkInRange(double x, double y, double maxX, double maxY) throws OutOfProjectionBoundsException { 24 | if (Math.abs(x) > maxX || Math.abs(y) > maxY) { 25 | throw OutOfProjectionBoundsException.get(); 26 | } 27 | } 28 | 29 | /** 30 | * @param longitude 31 | * @param latitude 32 | * @throws OutOfProjectionBoundsException if Math.abs(longitude) > 180 || Math.abs(latitude) > 90 33 | */ 34 | public static void checkLongitudeLatitudeInRange(double longitude, double latitude) throws OutOfProjectionBoundsException { 35 | checkInRange(longitude, latitude, 180, 90); 36 | } 37 | 38 | private OutOfProjectionBoundsException(boolean flag) { 39 | super(null, null, flag, flag); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/ProjectionFunction.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection; 2 | 3 | /** 4 | * A function that can apply a projection to a pair of lon/lat or x/y coordinates. 5 | * 6 | * @author DaPorkchop_ 7 | */ 8 | @FunctionalInterface 9 | public interface ProjectionFunction { 10 | double[] project(double lon_x, double lat_y) throws OutOfProjectionBoundsException; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/SinusoidalProjection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import net.buildtheearth.terraplusplus.TerraConstants; 5 | 6 | /** 7 | * Implementation of the Sinusoidal projection. 8 | * 9 | * @see Wikipedia's article on the sinusoidal projection 10 | */ 11 | @JsonDeserialize 12 | public class SinusoidalProjection implements GeographicProjection { 13 | @Override 14 | public double[] toGeo(double x, double y) { 15 | return new double[]{ x / Math.cos(Math.toRadians(y)), y }; 16 | } 17 | 18 | @Override 19 | public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException { 20 | OutOfProjectionBoundsException.checkLongitudeLatitudeInRange(longitude, latitude); 21 | return new double[]{ longitude * Math.cos(Math.toRadians(latitude)), latitude }; 22 | } 23 | 24 | @Override 25 | public double metersPerUnit() { 26 | return TerraConstants.EARTH_CIRCUMFERENCE / 360.0; //gotta make good on that exact area 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return "Sinusoidal"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/mercator/CenteredMercatorProjection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection.mercator; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import net.buildtheearth.terraplusplus.TerraConstants; 5 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 6 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 7 | 8 | /** 9 | * Implementation of the Mercator projection, normalized between -1 and 1. 10 | * 11 | * @see WebMercatorProjection 12 | * @see Wikipedia's article on the Mercator projection 13 | */ 14 | @JsonDeserialize 15 | public class CenteredMercatorProjection implements GeographicProjection { 16 | 17 | @Override 18 | public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException { 19 | OutOfProjectionBoundsException.checkInRange(x, y, 1, 1); 20 | return new double[]{ 21 | x * 180.0, 22 | Math.toDegrees(Math.atan(Math.exp(-y * Math.PI)) * 2 - Math.PI / 2) 23 | }; 24 | } 25 | 26 | @Override 27 | public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException { 28 | OutOfProjectionBoundsException.checkInRange(longitude, latitude, 180, WebMercatorProjection.LIMIT_LATITUDE); 29 | return new double[]{ 30 | longitude / 180.0, 31 | -(Math.log(Math.tan((Math.PI / 2 + Math.toRadians(latitude)) / 2))) / Math.PI 32 | }; 33 | } 34 | 35 | @Override 36 | public double[] bounds() { 37 | return new double[]{ -1, -1, 1, 1 }; 38 | } 39 | 40 | @Override 41 | public double metersPerUnit() { 42 | return Math.cos(Math.toRadians(30)) * TerraConstants.EARTH_CIRCUMFERENCE / 2; //Accurate at about 30 degrees 43 | } 44 | 45 | @Override 46 | public boolean upright() { 47 | return true; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "Mercator"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/transform/FlipHorizontalProjectionTransform.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection.transform; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | 9 | /** 10 | * Mirrors the warped projection horizontally. 11 | * I.E. x' = -x and y' = y 12 | */ 13 | @JsonDeserialize 14 | public class FlipHorizontalProjectionTransform extends ProjectionTransform { 15 | /** 16 | * @param delegate - projection to transform 17 | */ 18 | @JsonCreator 19 | public FlipHorizontalProjectionTransform( 20 | @JsonProperty(value = "delegate", required = true) GeographicProjection delegate) { 21 | super(delegate); 22 | } 23 | 24 | @Override 25 | public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException { 26 | return this.delegate.toGeo(-x, y); 27 | } 28 | 29 | @Override 30 | public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException { 31 | double[] p = this.delegate.fromGeo(longitude, latitude); 32 | p[0] = -p[0]; 33 | return p; 34 | } 35 | 36 | @Override 37 | public boolean upright() { 38 | return !this.delegate.upright(); 39 | } 40 | 41 | @Override 42 | public double[] bounds() { 43 | double[] b = this.delegate.bounds(); 44 | return new double[]{ -b[0], b[3], -b[2], b[1] }; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Horizontal Flip (" + super.delegate + ')'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/transform/FlipVerticalProjectionTransform.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection.transform; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | 9 | /** 10 | * Mirrors the warped projection vertically. 11 | * I.E. x' = x and y' = -y 12 | */ 13 | @JsonDeserialize 14 | public class FlipVerticalProjectionTransform extends ProjectionTransform { 15 | /** 16 | * @param delegate - projection to transform 17 | */ 18 | @JsonCreator 19 | public FlipVerticalProjectionTransform( 20 | @JsonProperty(value = "delegate", required = true) GeographicProjection delegate) { 21 | super(delegate); 22 | } 23 | 24 | @Override 25 | public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException { 26 | return this.delegate.toGeo(x, -y); 27 | } 28 | 29 | @Override 30 | public double[] fromGeo(double longitude, double latitude) throws OutOfProjectionBoundsException { 31 | double[] p = this.delegate.fromGeo(longitude, latitude); 32 | p[1] = -p[1]; 33 | return p; 34 | } 35 | 36 | @Override 37 | public boolean upright() { 38 | return !this.delegate.upright(); 39 | } 40 | 41 | @Override 42 | public double[] bounds() { 43 | double[] b = this.delegate.bounds(); 44 | return new double[]{ b[0], -b[3], b[2], -b[1] }; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return "Vertical Flip (" + super.delegate + ')'; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/transform/ProjectionTransform.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection.transform; 2 | 3 | import com.fasterxml.jackson.annotation.JsonGetter; 4 | import lombok.Getter; 5 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 6 | 7 | /** 8 | * Warps a Geographic projection and applies a transformation to it. 9 | */ 10 | @Getter(onMethod_ = { @JsonGetter }) 11 | public abstract class ProjectionTransform implements GeographicProjection { 12 | protected final GeographicProjection delegate; 13 | 14 | /** 15 | * @param delegate - projection to transform 16 | */ 17 | public ProjectionTransform(GeographicProjection delegate) { 18 | this.delegate = delegate; 19 | } 20 | 21 | @Override 22 | public boolean upright() { 23 | return this.delegate.upright(); 24 | } 25 | 26 | @Override 27 | public double[] bounds() { 28 | return this.delegate.bounds(); 29 | } 30 | 31 | @Override 32 | public double metersPerUnit() { 33 | return this.delegate.metersPerUnit(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/projection/transform/SwapAxesProjectionTransform.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.projection.transform; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 6 | import net.buildtheearth.terraplusplus.projection.GeographicProjection; 7 | import net.buildtheearth.terraplusplus.projection.OutOfProjectionBoundsException; 8 | 9 | /** 10 | * Inverses the warped projection such that x becomes y and y becomes x. 11 | */ 12 | @JsonDeserialize 13 | public class SwapAxesProjectionTransform extends ProjectionTransform { 14 | 15 | /** 16 | * @param delegate - projection to transform 17 | */ 18 | @JsonCreator 19 | public SwapAxesProjectionTransform( 20 | @JsonProperty(value = "delegate", required = true) GeographicProjection delegate) { 21 | super(delegate); 22 | } 23 | 24 | @Override 25 | public double[] toGeo(double x, double y) throws OutOfProjectionBoundsException { 26 | return this.delegate.toGeo(y, x); 27 | } 28 | 29 | @Override 30 | public double[] fromGeo(double lon, double lat) throws OutOfProjectionBoundsException { 31 | double[] p = this.delegate.fromGeo(lon, lat); 32 | double t = p[0]; 33 | p[0] = p[1]; 34 | p[1] = t; 35 | return p; 36 | } 37 | 38 | @Override 39 | public double[] bounds() { 40 | double[] b = this.delegate.bounds(); 41 | return new double[]{ b[1], b[0], b[3], b[2] }; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "Swap Axes(" + super.delegate + ')'; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/provider/EarthWorldProvider.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.provider; 2 | 3 | import net.buildtheearth.terraplusplus.EarthWorldType; 4 | import net.buildtheearth.terraplusplus.generator.populate.SnowPopulator; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.WorldProviderSurface; 7 | 8 | public class EarthWorldProvider extends WorldProviderSurface { 9 | protected boolean isEarth; 10 | 11 | @Override 12 | public void init() { 13 | super.init(); 14 | this.isEarth = this.world.getWorldInfo().getTerrainType() instanceof EarthWorldType; 15 | } 16 | 17 | @Override 18 | public boolean canSnowAt(BlockPos pos, boolean checkLight) { 19 | if (!this.isEarth) { 20 | return super.canSnowAt(pos, checkLight); 21 | } 22 | 23 | return SnowPopulator.canSnow(pos, this.world, false); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/provider/GenerationEventDenier.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.provider; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.world.ICubicWorldServer; 4 | import io.github.opencubicchunks.cubicchunks.api.worldgen.ICubeGenerator; 5 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.event.DecorateCubeBiomeEvent; 6 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.event.PopulateCubeEvent; 7 | import lombok.experimental.UtilityClass; 8 | import net.buildtheearth.terraplusplus.TerraConstants; 9 | import net.buildtheearth.terraplusplus.generator.EarthBiomeProvider; 10 | import net.buildtheearth.terraplusplus.generator.EarthGenerator; 11 | import net.minecraft.world.World; 12 | import net.minecraftforge.event.terraingen.DecorateBiomeEvent; 13 | import net.minecraftforge.event.terraingen.PopulateChunkEvent; 14 | import net.minecraftforge.fml.common.Mod; 15 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 16 | 17 | @Mod.EventBusSubscriber(modid = TerraConstants.MODID) 18 | @UtilityClass 19 | public class GenerationEventDenier { 20 | @SubscribeEvent 21 | public void populateCatcher(PopulateCubeEvent.Populate event) { 22 | ICubeGenerator generator = event.getGenerator(); 23 | if (generator instanceof EarthGenerator && ((EarthGenerator) generator).settings.skipChunkPopulation().contains(event.getType())) { 24 | event.setResult(PopulateCubeEvent.Populate.Result.DENY); 25 | } 26 | } 27 | 28 | @SubscribeEvent 29 | public void decorateCatcher(DecorateCubeBiomeEvent.Decorate event) { 30 | World world = event.getWorld(); 31 | if (world instanceof ICubicWorldServer) { 32 | ICubeGenerator generator = ((ICubicWorldServer) world).getCubeGenerator(); 33 | if (generator instanceof EarthGenerator && ((EarthGenerator) generator).settings.skipBiomeDecoration().contains(event.getType())) { 34 | event.setResult(PopulateCubeEvent.Populate.Result.DENY); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/provider/WaterDenier.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.provider; 2 | 3 | import io.github.opencubicchunks.cubicchunks.api.worldgen.populator.event.PopulateCubeEvent; 4 | import lombok.experimental.UtilityClass; 5 | import net.buildtheearth.terraplusplus.generator.EarthBiomeProvider; 6 | import net.minecraft.block.BlockLiquid; 7 | import net.minecraft.block.material.Material; 8 | import net.minecraft.block.state.IBlockState; 9 | import net.minecraft.util.math.BlockPos; 10 | import net.minecraft.world.World; 11 | import net.minecraftforge.event.world.BlockEvent.CreateFluidSourceEvent; 12 | import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; 13 | 14 | @UtilityClass 15 | public class WaterDenier { 16 | @SubscribeEvent 17 | public void sourceCatch(CreateFluidSourceEvent event) { 18 | World world = event.getWorld(); 19 | 20 | if (world.getBiomeProvider() instanceof EarthBiomeProvider) { 21 | if (event.getState().getMaterial() != Material.WATER) { 22 | return; 23 | } 24 | 25 | BlockPos pos = event.getPos(); 26 | 27 | int c = 0; 28 | c += isSource(world, pos.north()); 29 | c += isSource(world, pos.south()); 30 | c += isSource(world, pos.east()); 31 | c += isSource(world, pos.west()); 32 | 33 | if (c < 3) { 34 | event.setResult(PopulateCubeEvent.Populate.Result.DENY); 35 | } 36 | } 37 | } 38 | 39 | private int isSource(World world, BlockPos pos) { 40 | IBlockState state = world.getBlockState(pos); 41 | return (state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) == 0) ? 1 : 0; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/BiomeDeserializeMixin.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 4 | import com.fasterxml.jackson.databind.util.StdConverter; 5 | import lombok.NonNull; 6 | import net.minecraft.util.ResourceLocation; 7 | import net.minecraft.world.biome.Biome; 8 | 9 | import static net.daporkchop.lib.common.util.PValidation.*; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | @JsonDeserialize(converter = BiomeDeserializeMixin.Converter.class) 15 | public abstract class BiomeDeserializeMixin { 16 | protected static class Converter extends StdConverter { 17 | @Override 18 | public Biome convert(@NonNull String value) { 19 | ResourceLocation id = new ResourceLocation(value); 20 | checkArg(Biome.REGISTRY.containsKey(id), "unknown biome id: %s", id); 21 | return Biome.REGISTRY.getObject(id); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/CardinalDirection.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import lombok.Getter; 4 | import net.buildtheearth.terraplusplus.TerraConstants; 5 | 6 | @Getter 7 | public enum CardinalDirection { 8 | N(337.5, 22.5, "North"), S(157.5, 202.5, "South"), E(67.5, 112.5, "East"), W(247.5, 292.5, "West"), 9 | NW(292.5, 337.5, "Northwest"), SW(202.5, 247.5, "Southwest"), SE(112.5, 157.5, "Southeast"), 10 | NE(22.5, 67.5, "Northeast"), UNKNOWN(360.5, 10000000.0, "Unknown"); 11 | 12 | /** 13 | * @param azimuth - an azimuth 14 | * @return the CardinalDirection the given azimuth faces 15 | */ 16 | public static CardinalDirection azimuthToFacing(float azimuth) { 17 | for (CardinalDirection facingToBeTestedFor : CardinalDirection.values()) { 18 | if (facingToBeTestedFor == CardinalDirection.N) { 19 | 20 | if (azimuth >= facingToBeTestedFor.min() && azimuth <= 360) { 21 | return facingToBeTestedFor; 22 | 23 | } else if (azimuth >= 0 && azimuth <= facingToBeTestedFor.max()) { 24 | return facingToBeTestedFor; 25 | } 26 | 27 | } else if (azimuth >= facingToBeTestedFor.min() && azimuth <= facingToBeTestedFor.max()) { 28 | return facingToBeTestedFor; 29 | } 30 | } 31 | return CardinalDirection.UNKNOWN; 32 | } 33 | private final double min; 34 | private final double max; 35 | private final String realName; 36 | private final String translationKey; 37 | 38 | CardinalDirection(double min, double max, String realName) { 39 | this.min = min; 40 | this.max = max; 41 | this.realName = realName; 42 | this.translationKey = TerraConstants.MODID + ".cardinal_directions." + this.name().toLowerCase(); 43 | } 44 | 45 | /** 46 | * @param azimuth - an azimuth 47 | * @return true if the given azimuth faces this cardinal direction 48 | */ 49 | public boolean matches(float azimuth) { 50 | return azimuthToFacing(azimuth) == this; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/CustomAttributeContainer.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.NonNull; 5 | 6 | import java.util.Map; 7 | 8 | import static net.daporkchop.lib.common.util.PValidation.*; 9 | import static net.daporkchop.lib.common.util.PorkUtil.*; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | @AllArgsConstructor 15 | public abstract class CustomAttributeContainer { 16 | @NonNull 17 | protected final Map custom; 18 | 19 | /** 20 | * Gets the custom attribute with the given key. 21 | * 22 | * @param key the key of the attribute to get 23 | * @return the attribute 24 | * @throws IllegalArgumentException if a property with the given name couldn't be found 25 | */ 26 | public T getCustom(@NonNull String key) { 27 | T value = uncheckedCast(this.custom.get(key)); 28 | checkArg(value != null || this.custom.containsKey(key), "unknown property: \"%s\"", key); 29 | return value; 30 | } 31 | 32 | /** 33 | * Gets the custom attribute with the given key. 34 | * 35 | * @param key the key of the attribute to get 36 | * @param fallback the value to return if the key couldn't be found 37 | * @return the attribute 38 | */ 39 | public T getCustom(@NonNull String key, T fallback) { 40 | return uncheckedCast(this.custom.getOrDefault(key, fallback)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/EmptyWorld.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import lombok.AccessLevel; 4 | import lombok.NoArgsConstructor; 5 | import net.minecraft.block.state.IBlockState; 6 | import net.minecraft.init.Biomes; 7 | import net.minecraft.init.Blocks; 8 | import net.minecraft.tileentity.TileEntity; 9 | import net.minecraft.util.EnumFacing; 10 | import net.minecraft.util.math.BlockPos; 11 | import net.minecraft.world.IBlockAccess; 12 | import net.minecraft.world.WorldType; 13 | import net.minecraft.world.biome.Biome; 14 | 15 | import javax.annotation.Nullable; 16 | 17 | /** 18 | * Implementation of {@link IBlockAccess} which contains nothing. 19 | * 20 | * @author DaPorkchop_ 21 | */ 22 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 23 | public final class EmptyWorld implements IBlockAccess { 24 | public static final EmptyWorld INSTANCE = new EmptyWorld(); 25 | 26 | @Nullable 27 | @Override 28 | public TileEntity getTileEntity(BlockPos pos) { 29 | return null; 30 | } 31 | 32 | @Override 33 | public int getCombinedLight(BlockPos pos, int lightValue) { 34 | return 15 << 20; //sky light: 15, block light: 0 35 | } 36 | 37 | @Override 38 | public IBlockState getBlockState(BlockPos pos) { 39 | return Blocks.AIR.getDefaultState(); 40 | } 41 | 42 | @Override 43 | public boolean isAirBlock(BlockPos pos) { 44 | return true; 45 | } 46 | 47 | @Override 48 | public Biome getBiome(BlockPos pos) { 49 | return Biomes.OCEAN; 50 | } 51 | 52 | @Override 53 | public int getStrongPower(BlockPos pos, EnumFacing direction) { 54 | return 0; 55 | } 56 | 57 | @Override 58 | public WorldType getWorldType() { 59 | return WorldType.DEFAULT; 60 | } 61 | 62 | @Override 63 | public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) { 64 | return false; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/EqualsTieBreakComparator.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import lombok.RequiredArgsConstructor; 4 | import net.daporkchop.lib.common.util.PorkUtil; 5 | 6 | import java.util.Comparator; 7 | import java.util.Objects; 8 | 9 | /** 10 | * Copied from FarPlaneTwo. 11 | * 12 | * @author DaPorkchop_ 13 | */ 14 | @RequiredArgsConstructor 15 | public class EqualsTieBreakComparator implements Comparator { 16 | protected final Comparator comparator; 17 | protected final boolean useHashCode; 18 | protected final boolean up; 19 | 20 | @Override 21 | public int compare(T o1, T o2) { 22 | int d; 23 | if (this.comparator != null) { 24 | d = this.comparator.compare(o1, o2); 25 | } else { 26 | d = PorkUtil.>uncheckedCast(o1).compareTo(o2); 27 | } 28 | 29 | if (d == 0 && !Objects.equals(o1, o2)) { //comparison resulted in a tie, but the objects are different 30 | if (this.useHashCode) { 31 | d = Integer.compare(Objects.hashCode(o1), Objects.hash(o2)); 32 | } 33 | if (d == 0) { 34 | d = this.up ? 1 : -1; 35 | } 36 | } 37 | return d; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/ImmutableCompactArray.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import it.unimi.dsi.fastutil.objects.Reference2IntMap; 4 | import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; 5 | import lombok.NonNull; 6 | import net.daporkchop.lib.binary.bit.BitArray; 7 | import net.daporkchop.lib.binary.bit.padded.PaddedBitArray; 8 | import net.minecraft.block.state.IBlockState; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | import static java.lang.Math.*; 15 | 16 | /** 17 | * A compact, immutable array of {@link IBlockState}s. 18 | * 19 | * @author DaPorkchop_ 20 | */ 21 | public final class ImmutableCompactArray { 22 | protected final BitArray data; 23 | protected final T[] palette; 24 | 25 | public ImmutableCompactArray(@NonNull T[] data) { 26 | Reference2IntMap valueIds = new Reference2IntOpenHashMap<>(); 27 | List paletteBuilder = new ArrayList<>(); 28 | int idCounter = 0; 29 | 30 | for (T value : data) { 31 | if (!valueIds.containsKey(value)) { //add value to palette 32 | valueIds.put(value, idCounter++); 33 | paletteBuilder.add(value); 34 | } 35 | } 36 | 37 | this.palette = paletteBuilder.toArray(Arrays.copyOf(data, paletteBuilder.size())); 38 | this.data = new PaddedBitArray(max(32 - Integer.numberOfLeadingZeros(idCounter - 1), 1), data.length); 39 | 40 | for (int i = 0; i < data.length; i++) { //set values 41 | this.data.set(i, valueIds.get(data[i])); 42 | } 43 | } 44 | 45 | /** 46 | * Gets the value at the given index. 47 | * 48 | * @param i the index 49 | * @return the value 50 | */ 51 | public T get(int i) { 52 | return this.palette[this.data.get(i)]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/IntRange.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | import lombok.EqualsAndHashCode; 6 | import lombok.Getter; 7 | import lombok.ToString; 8 | 9 | import static net.daporkchop.lib.common.util.PValidation.*; 10 | 11 | /** 12 | * A simple closed range between two integers. 13 | * 14 | * @author DaPorkchop_ 15 | */ 16 | @Getter 17 | @ToString 18 | @EqualsAndHashCode 19 | public class IntRange { 20 | protected final int min; 21 | protected final int max; 22 | 23 | @JsonCreator 24 | public IntRange(int val) { 25 | this(val, val); 26 | } 27 | 28 | @JsonCreator 29 | public IntRange( 30 | @JsonProperty(value = "min", required = true) int min, 31 | @JsonProperty(value = "max", required = true) int max) { 32 | checkArg(min <= max, "min (%d) may not be greater than max (%d)", min, max); 33 | this.min = min; 34 | this.max = max; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/IntToDoubleBiFunction.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | /** 4 | * A function that accepts two {@code int} parameters and returns a {@code double}. 5 | * 6 | * @author DaPorkchop_ 7 | */ 8 | @FunctionalInterface 9 | public interface IntToDoubleBiFunction { 10 | double apply(int x, int z); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/RLEByteArray.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import it.unimi.dsi.fastutil.bytes.ByteArrayList; 4 | import it.unimi.dsi.fastutil.bytes.ByteList; 5 | import it.unimi.dsi.fastutil.ints.IntArrayList; 6 | import it.unimi.dsi.fastutil.ints.IntList; 7 | import lombok.Getter; 8 | import lombok.NonNull; 9 | 10 | import java.util.Arrays; 11 | 12 | import static net.daporkchop.lib.common.util.PValidation.*; 13 | 14 | /** 15 | * A run-length-encoded byte array with random access. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | public class RLEByteArray { 20 | public static Builder builder() { 21 | return new Builder(); 22 | } 23 | 24 | protected final int[] index; 25 | protected final byte[] data; 26 | @Getter 27 | protected final int size; 28 | 29 | protected RLEByteArray(@NonNull IntList index, @NonNull ByteList data, int size) { 30 | this.index = index.toIntArray(); 31 | this.data = data.toByteArray(); 32 | this.size = size; 33 | } 34 | 35 | public byte get(int i) { 36 | checkIndex(this.size, i); 37 | 38 | i = Arrays.binarySearch(this.index, i); 39 | int mask = i >> 31; 40 | i = (i ^ mask) + mask; 41 | 42 | return this.data[i]; 43 | } 44 | 45 | public static class Builder { 46 | protected final IntList index = new IntArrayList(); 47 | protected final ByteList data = new ByteArrayList(); 48 | protected int size; 49 | protected byte last; 50 | 51 | /** 52 | * Appends a value to this builder. 53 | * 54 | * @param val the value to append 55 | */ 56 | public void append(byte val) { 57 | int size = this.size++; 58 | if (size == 0 || this.last != val) { 59 | this.index.add(size); 60 | this.data.add(this.last = val); 61 | } 62 | } 63 | 64 | public RLEByteArray build() { 65 | return new RLEByteArray(this.index, this.data, this.size); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/TilePos.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.ToString; 6 | 7 | /** 8 | * Representation of a tile position (a 2D position and a zoom level). 9 | * 10 | * @author DaPorkchop_ 11 | */ 12 | @AllArgsConstructor 13 | @Getter 14 | @ToString 15 | public class TilePos { 16 | protected final int x; 17 | protected final int z; 18 | protected final int zoom; 19 | 20 | @Override 21 | public int hashCode() { 22 | return (int) (((3241L * 3457689L + this.x) * 8734625L + this.z) * 2873465L + this.zoom); 23 | } 24 | 25 | @Override 26 | public boolean equals(Object obj) { 27 | if (obj == this) { 28 | return true; 29 | } else if (obj instanceof TilePos) { 30 | TilePos pos = (TilePos) obj; 31 | return this.x == pos.x && this.z == pos.z && this.zoom == pos.zoom; 32 | } else { 33 | return false; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/TranslateUtil.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import net.minecraft.util.text.ITextComponent; 4 | import net.minecraft.util.text.TextComponentString; 5 | import net.minecraft.util.text.TextComponentTranslation; 6 | import net.minecraft.util.text.translation.I18n; 7 | import net.minecraftforge.fml.common.FMLCommonHandler; 8 | 9 | public class TranslateUtil { 10 | public static ITextComponent translate(String key) { 11 | if (FMLCommonHandler.instance().getMinecraftServerInstance().isSinglePlayer()) { 12 | return new TextComponentTranslation(key); 13 | } 14 | return new TextComponentString(net.minecraft.util.text.translation.I18n.translateToLocal(key)); 15 | } 16 | 17 | public static ITextComponent format(String key, Object... args) { 18 | if (FMLCommonHandler.instance().getMinecraftServerInstance().isSinglePlayer()) { 19 | return new TextComponentTranslation(key, args); 20 | } 21 | return new TextComponentString(I18n.translateToLocalFormatted(key, args)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/bvh/BVH.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.bvh; 2 | 3 | import lombok.NonNull; 4 | 5 | import java.util.Collection; 6 | import java.util.List; 7 | import java.util.function.Consumer; 8 | import java.util.stream.Stream; 9 | 10 | /** 11 | * A simple, immutable, quadtree-based implementation of a BVH (Bounding Volume Hierarchy) on arbitrary values implementing {@link Bounds2d}. 12 | * 13 | * @author DaPorkchop_ 14 | */ 15 | public interface BVH extends Bounds2d, Iterable { 16 | static BVH of(@NonNull V[] values) { 17 | if (values.length == 0) { 18 | return EmptyBVH.get(); 19 | } else if (values.length == 1) { 20 | return new SingletonBVH<>(values[0]); 21 | } else { 22 | return new QuadtreeBVH<>(values); 23 | } 24 | } 25 | 26 | /** 27 | * @return the number of values 28 | */ 29 | int size(); 30 | 31 | /** 32 | * Gets a {@link List} containing every value that intersects with the given bounding box. 33 | * 34 | * @param bb the bounding box that values must intersect with 35 | * @return the values 36 | */ 37 | List getAllIntersecting(@NonNull Bounds2d bb); 38 | 39 | /** 40 | * Runs the given function on every value that intersects with the given bounding box. 41 | * 42 | * @param bb the bounding box that values must intersect with 43 | * @param callback the callback function to run 44 | */ 45 | void forEachIntersecting(@NonNull Bounds2d bb, @NonNull Consumer callback); 46 | 47 | /** 48 | * @see Collection#stream() 49 | */ 50 | Stream stream(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/bvh/Bounds2dImpl.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.bvh; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonGetter; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 7 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 8 | import lombok.EqualsAndHashCode; 9 | import lombok.Getter; 10 | import lombok.ToString; 11 | 12 | import static net.daporkchop.lib.common.util.PValidation.*; 13 | 14 | /** 15 | * Trivial implementation of {@link Bounds2d}. 16 | * 17 | * @author DaPorkchop_ 18 | */ 19 | @JsonDeserialize 20 | @JsonSerialize 21 | @Getter(onMethod_ = { @JsonGetter }) 22 | @ToString 23 | @EqualsAndHashCode 24 | class Bounds2dImpl implements Bounds2d { 25 | protected final double minX; 26 | protected final double maxX; 27 | protected final double minZ; 28 | protected final double maxZ; 29 | 30 | @JsonCreator 31 | public Bounds2dImpl( 32 | @JsonProperty(value = "minX", required = true) double minX, 33 | @JsonProperty(value = "maxX", required = true) double maxX, 34 | @JsonProperty(value = "minZ", required = true) double minZ, 35 | @JsonProperty(value = "maxZ", required = true) double maxZ) { 36 | checkArg(minX <= maxX, "minX (%s) may not be greater than maxX (%s)!", minX, maxX); 37 | checkArg(minZ <= maxZ, "minZ (%s) may not be greater than maxZ (%s)!", minZ, maxZ); 38 | 39 | this.minX = minX; 40 | this.maxX = maxX; 41 | this.minZ = minZ; 42 | this.maxZ = maxZ; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/bvh/EmptyBVH.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.bvh; 2 | 3 | import lombok.AccessLevel; 4 | import lombok.NoArgsConstructor; 5 | import lombok.NonNull; 6 | 7 | import java.util.Collections; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | import java.util.Spliterator; 11 | import java.util.Spliterators; 12 | import java.util.function.Consumer; 13 | import java.util.stream.Stream; 14 | 15 | import static net.daporkchop.lib.common.util.PorkUtil.*; 16 | 17 | /** 18 | * Implementation of {@link BVH} which contains no values. 19 | * 20 | * @author DaPorkchop_ 21 | */ 22 | @NoArgsConstructor(access = AccessLevel.PRIVATE) 23 | final class EmptyBVH implements BVH { 24 | private static final EmptyBVH INSTANCE = new EmptyBVH(); 25 | 26 | public static EmptyBVH get() { 27 | return uncheckedCast(INSTANCE); 28 | } 29 | 30 | @Override 31 | public int size() { 32 | return 0; 33 | } 34 | 35 | @Override 36 | public List getAllIntersecting(@NonNull Bounds2d bb) { 37 | return Collections.emptyList(); 38 | } 39 | 40 | @Override 41 | public void forEachIntersecting(@NonNull Bounds2d bb, @NonNull Consumer callback) { 42 | //no-op 43 | } 44 | 45 | @Override 46 | public Stream stream() { 47 | return Stream.empty(); 48 | } 49 | 50 | @Override 51 | public double minX() { 52 | return 0.0d; 53 | } 54 | 55 | @Override 56 | public double maxX() { 57 | return 0.0d; 58 | } 59 | 60 | @Override 61 | public double minZ() { 62 | return 0.0d; 63 | } 64 | 65 | @Override 66 | public double maxZ() { 67 | return 0.0d; 68 | } 69 | 70 | @Override 71 | public Iterator iterator() { 72 | return Collections.emptyIterator(); 73 | } 74 | 75 | @Override 76 | public void forEach(@NonNull Consumer action) { 77 | //no-op 78 | } 79 | 80 | @Override 81 | public Spliterator spliterator() { 82 | return Spliterators.emptySpliterator(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/geo/LatLng.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.geo; 2 | 3 | public class LatLng { 4 | private final Double lat; 5 | private final Double lng; 6 | 7 | public LatLng(double lat, double lng) { 8 | this.lat = lat; 9 | this.lng = lng; 10 | } 11 | 12 | public LatLng() { 13 | this.lat = null; 14 | this.lng = null; 15 | } 16 | 17 | public Double getLat() { 18 | return this.lat; 19 | } 20 | 21 | public Double getLng() { 22 | return this.lng; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/http/Host.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.http; 2 | 3 | import lombok.EqualsAndHashCode; 4 | import lombok.NonNull; 5 | 6 | import java.net.URL; 7 | 8 | /** 9 | * @author DaPorkchop_ 10 | */ 11 | @EqualsAndHashCode 12 | class Host { 13 | @NonNull 14 | protected final String host; 15 | protected final int port; 16 | 17 | protected final boolean ssl; 18 | 19 | @EqualsAndHashCode.Exclude 20 | protected final String authority; 21 | 22 | public Host(@NonNull URL url) { 23 | this.host = url.getHost(); 24 | this.port = Math.max(url.getPort(), url.getDefaultPort()); 25 | this.authority = url.getAuthority(); 26 | 27 | switch (url.getProtocol()) { 28 | case "http": 29 | this.ssl = false; 30 | break; 31 | case "https": 32 | this.ssl = true; 33 | break; 34 | default: 35 | throw new IllegalArgumentException("unsupported protocol: " + url.getProtocol()); 36 | } 37 | } 38 | 39 | protected Host(@NonNull Host host) { 40 | this.host = host.host; 41 | this.port = host.port; 42 | this.ssl = host.ssl; 43 | this.authority = host.authority; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/http/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Performant, asynchronous HTTP requests multiplexed over a single-threaded Netty event loop. 3 | * 4 | * @author DaPorkchop_ 5 | */ 6 | package net.buildtheearth.terraplusplus.util.http; 7 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/interval/Interval.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.interval; 2 | 3 | /** 4 | * A 1-dimensional interval represented using double-precision floating-point coordinates. 5 | * 6 | * @author DaPorkchop_ 7 | */ 8 | public interface Interval { 9 | static Interval of(double v0, double v1) { 10 | return new IntervalImpl(Math.min(v0, v1), Math.max(v0, v1)); 11 | } 12 | 13 | /** 14 | * @return the minimum coordinate 15 | */ 16 | double min(); 17 | 18 | /** 19 | * @return the maximum coordinate 20 | */ 21 | double max(); 22 | 23 | /** 24 | * @return the length of this interval 25 | */ 26 | default double length() { 27 | return this.max() - this.min(); 28 | } 29 | 30 | /** 31 | * Checks whether or not this interval contains the given point. 32 | * 33 | * @param point the point 34 | * @return whether or not this interval contains the given point 35 | */ 36 | default boolean contains(double point) { 37 | return this.min() < point && this.max() > point; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/buildtheearth/terraplusplus/util/interval/IntervalImpl.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util.interval; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.EqualsAndHashCode; 5 | import lombok.Getter; 6 | import lombok.ToString; 7 | 8 | /** 9 | * Trivial implementation of {@link Interval}. 10 | * 11 | * @author DaPorkchop_ 12 | */ 13 | @AllArgsConstructor 14 | @Getter 15 | @ToString 16 | @EqualsAndHashCode 17 | class IntervalImpl implements Interval { 18 | protected final double min; 19 | protected final double max; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/de_de.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | generator.EarthCubic=Die Erde 5 | 6 | ## GUI options 7 | terraplusplus.gui.projection=Projektion 8 | terraplusplus.gui.orientation=Ausrichtung 9 | terraplusplus.gui.roads=Strassen Generieren 10 | terraplusplus.gui.smoothblend=glattes Mischen 11 | terraplusplus.gui.dynamicbaseheight=Erzgenerierung auf Höhe basieren 12 | terraplusplus.gui.osmwater=fortgeschrittenes Wassergenerierung (experimentell) 13 | terraplusplus.gui.buildings=Gebäudegliederungen von OSM 14 | 15 | ## Projection types 16 | terraplusplus.projection.web_mercator=Mercator 17 | terraplusplus.projection.equirectangular=Plattkarte 18 | terraplusplus.projection.sinusoidal=Sinusoidal 19 | terraplusplus.projection.equal_earth=Gleichgrosse Erde 20 | 21 | ## Projection orientations 22 | terraplusplus.orientation.upright=Aufrecht 23 | terraplusplus.orientation.none=Keine Orientation 24 | terraplusplus.orientation.swapped=Umgekehrt 25 | 26 | ## command messages 27 | terraplusplus.command.tpll.usage=/tpll breitengrad längengrad [altitude] [player] 28 | 29 | terraplusplus.command.terra.usage=/terra [where:ou] [player]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[breitengrad längengrad] 30 | 31 | terraplusplus.command.terra.gensettings=Generator Settings: 32 | terraplusplus.command.terra.latlon=breitengrad längengrad: %.7f %.7f 33 | terraplusplus.command.terra.xy=x y: %.7f %.7f 34 | 35 | ## command errors 36 | terraplusplus.error.notcc=Muss in einer Cubic Chunks Welt verwendet werden! 37 | terraplusplus.error.notterra=Muss in einer Terra 1:1 Welt verwendet werden! 38 | terraplusplus.error.numbers=Alle Argumente müssen Zahlen sein! 39 | terraplusplus.error.getcoords=Konnte die Koordinaten nicht heraussuchen! 40 | terraplusplus.error.notplayer=Du bist kein Spieler, bitte einen nennen! 41 | terraplusplus.error.unknownplayer=Unbekannter Spieler! 42 | terraplusplus.error.notopothers=Braucht OP für Info von anderen Spielern! 43 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/es_es.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | generator.EarthCubic=Planeta Tierra 5 | 6 | ## GUI options 7 | terraplusplus.gui.projection=Proyección 8 | terraplusplus.gui.orientation=Orientación 9 | terraplusplus.gui.roads=Crear Calles 10 | terraplusplus.gui.smoothblend=Suavizado 11 | terraplusplus.gui.dynamicbaseheight=Altura de Minerales Dinámica 12 | terraplusplus.gui.osmwater=Agua Avanzada (experimental) 13 | terraplusplus.gui.buildings=Guías de Construcciones 14 | 15 | ## Projection types 16 | terraplusplus.projection.web_mercator=Mercator 17 | terraplusplus.projection.equirectangular=Equirectangular 18 | terraplusplus.projection.sinusoidal=Sinusoidal 19 | terraplusplus.projection.equal_earth=Equal Earth 20 | terraplusplus.projection.transverse_mercator=Mercator Transversal 21 | 22 | ## Projection orientations 23 | terraplusplus.orientation.upright=Derecha 24 | terraplusplus.orientation.none=Ninguna 25 | terraplusplus.orientation.swapped=Eje Invertido 26 | 27 | ## command messages 28 | terraplusplus.command.tpll.usage=/tpll latitud longitud [altitud] [jugador] 29 | 30 | terraplusplus.command.terra.usage=/terra [where:ou] [jugador]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[latitud longitud] 31 | 32 | terraplusplus.command.terra.gensettings=Configuración del Generador: 33 | terraplusplus.command.terra.latlon=latitud longitud: %.7f %.7f 34 | terraplusplus.command.terra.xy=x y: %.7f %.7f 35 | 36 | ## command errors 37 | terraplusplus.error.notcc=¡Tienes que estar en un mundo Cubic Chunks! 38 | terraplusplus.error.notterra=¡Tienes que estar en un mundo Terra! 39 | terraplusplus.error.numbers=¡Todos los argumentos tienen que ser números! 40 | terraplusplus.error.getcoords=¡No se pudieron obtener las coordenadas! 41 | terraplusplus.error.notplayer=¡No eres un jugador, por favor especifica uno! 42 | terraplusplus.error.unknownplayer=¡Jugador desconocido! 43 | terraplusplus.error.notopothers=¡Necesitas OP para obtener información de otros jugadores! 44 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/pl_pl.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | generator.EarthCubic=Ziemia 5 | 6 | ## GUI options 7 | terraplusplus.gui.projection=Odwzorowanie 8 | terraplusplus.gui.orientation=Orientacja 9 | terraplusplus.gui.roads=Drogi 10 | terraplusplus.gui.smoothblend=Wygładzanie terenu 11 | terraplusplus.gui.dynamicbaseheight=Wypiętrzone rudy 12 | terraplusplus.gui.osmwater=Wody śródlądowe (eksperymentalne) 13 | terraplusplus.gui.buildings=Krawędzie budynków z OSM 14 | 15 | ## Projection types 16 | terraplusplus.projection.web_mercator=Merkatora 17 | terraplusplus.projection.equirectangular=Równoodległościowe 18 | terraplusplus.projection.sinusoidal=Sinusoidalne 19 | terraplusplus.projection.equal_earth=Equal Earth 20 | terraplusplus.projection.transverse_mercator=Poprzeczne Merkatora (UTM) 21 | terraplusplus.projection.airocean=Fullera (nie BTE) 22 | terraplusplus.projection.conformal=Równokątne Fullera (nie BTE) 23 | terraplusplus.projection.bteairocean=Build The Earth 24 | 25 | ## Projection orientations 26 | terraplusplus.orientation.upright=Pionowa 27 | terraplusplus.orientation.none=Brak 28 | terraplusplus.orientation.swapped=Odwrócona oś 29 | 30 | ## command messages 31 | terraplusplus.command.tpll.usage=/tpll szerokość długość [wysokość] [gracz] 32 | 33 | terraplusplus.command.terra.usage=/terra [where:ou] [gracz]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[szerokość długość] 34 | 35 | terraplusplus.command.terra.gensettings=Ustawienia generatora: 36 | terraplusplus.command.terra.latlon=szerokość długość: %.7f %.7f 37 | terraplusplus.command.terra.xy=x y: %.7f %.7f 38 | 39 | ## command errors 40 | terraplusplus.error.notcc=Wymagany świat Cubic Chunks! 41 | terraplusplus.error.notterra=Wymagany świat Terra 1 to 1! 42 | terraplusplus.error.numbers=Wszystkie argumenty muszą być liczbami! 43 | terraplusplus.error.getcoords=Nie udało się uzyskać współrzędnych geograficznych! 44 | terraplusplus.error.notplayer=Nie jesteś graczem, wymień jakiegoś! 45 | terraplusplus.error.unknownplayer=Podany gracz nie istnieje! 46 | terraplusplus.error.notopothers=Tylko OP może uzyskiwać informacje o innych graczach! 47 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/ru_ru.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | generator.EarthCubic=Планета Земля 5 | 6 | ## GUI options 7 | terraplusplus.gui.projection=Проекция 8 | terraplusplus.gui.orientation=Ориентация 9 | terraplusplus.gui.roads=Создать дороги 10 | terraplusplus.gui.smoothblend=Гладкое смешивание 11 | terraplusplus.gui.dynamicbaseheight=Высота руды 12 | terraplusplus.gui.osmwater=Продвинутая вода (экспериментально) 13 | terraplusplus.gui.buildings=Контуры здания OSM 14 | 15 | ## Projection types 16 | terraplusplus.projection.web_mercator=Меркатор 17 | terraplusplus.projection.equirectangular=Равнопромежуточно 18 | terraplusplus.projection.sinusoidal=Синусоидальный 19 | terraplusplus.projection.equal_earth=Равный Земле 20 | 21 | ## Projection orientations 22 | terraplusplus.orientation.upright=Прямо 23 | terraplusplus.orientation.none=Нет ориентации 24 | terraplusplus.orientation.swapped=Перевернутая ось 25 | 26 | ## command messages 27 | terraplusplus.command.tpll.usage=/tpll шир дол [высота] [игрок] 28 | 29 | terraplusplus.command.terra.usage=/terra [where:ou] [игрок]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[шир дол] 30 | 31 | terraplusplus.command.terra.gensettings=Настройки генератора: 32 | terraplusplus.command.terra.latlon=шир дол: %.7f %.7f 33 | terraplusplus.command.terra.xy=x y: %.7f %.7f 34 | 35 | ## command errors 36 | terraplusplus.error.notcc=Должен быть в мире Cubic Chunks! 37 | terraplusplus.error.notterra=Должен быть в мире Terra 1 to 1! 38 | terraplusplus.error.numbers=Все аргументы должны быть числами! 39 | terraplusplus.error.getcoords=Не удалось получить координаты! 40 | terraplusplus.error.notplayer=Вы не игрок, пожалуйста, укажите одного! 41 | terraplusplus.error.unknownplayer=Неизвестный игрок! 42 | terraplusplus.error.notopothers=Требуется OP для информации о других игроках! -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/uk_uk.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | generator.EarthCubic=Планета Земля 5 | 6 | ## GUI options 7 | terraplusplus.gui.projection=Проєкція 8 | terraplusplus.gui.orientation=Орієнтація 9 | terraplusplus.gui.roads=Створити дороги 10 | terraplusplus.gui.smoothblend=Гладке змішування 11 | terraplusplus.gui.dynamicbaseheight=Висота руди 12 | terraplusplus.gui.osmwater=Просунута вода (експериментально) 13 | terraplusplus.gui.buildings=Контури будівлі OSM 14 | 15 | ## Projection types 16 | terraplusplus.projection.web_mercator=Меркатора 17 | terraplusplus.projection.equirectangular=Рівнокутна 18 | terraplusplus.projection.sinusoidal=Синусоїдальна 19 | terraplusplus.projection.equal_earth=Рівна Землі 20 | 21 | ## Projection orientations 22 | terraplusplus.orientation.upright=Пряма 23 | terraplusplus.orientation.none=Без орієнтації 24 | terraplusplus.orientation.swapped=Перевернута вісь 25 | 26 | ## command messages 27 | terraplusplus.command.tpll.usage=/tpll шир дов [висота] [гравець] 28 | 29 | terraplusplus.command.terra.usage=/terra [where:ou] [гравець]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[шир дов] 30 | 31 | terraplusplus.command.terra.gensettings=Налаштування генератора: 32 | terraplusplus.command.terra.latlon=шир дов: %.7f %.7f 33 | terraplusplus.command.terra.xy=x y: %.7f %.7f 34 | 35 | ## command errors 36 | terraplusplus.error.notcc=Повинен бути у світі Cubic Chunks! 37 | terraplusplus.error.notterra=Повинен бути у світі Terra 1 to 1! 38 | terraplusplus.error.numbers=Всі аргументи мають бути числами! 39 | terraplusplus.error.getcoords=Не вдалось отримати координати! 40 | terraplusplus.error.notplayer=Ви не гравець, будь ласка вкажіть такого! 41 | terraplusplus.error.unknownplayer=Невідомий гравець! 42 | terraplusplus.error.notopothers=Необхідне OP для інформації про інших гравців! 43 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/lang/zh_cn.lang: -------------------------------------------------------------------------------- 1 | #PARSE_ESCAPES 2 | 3 | ## World Type name 4 | 5 | generator.EarthCubic=地球 6 | 7 | 8 | 9 | ## GUI options 10 | 11 | terraplusplus.gui.projection=投影方式 12 | 13 | terraplusplus.gui.orientation=投影方向 14 | 15 | terraplusplus.gui.roads=生成道路 16 | 17 | terraplusplus.gui.smoothblend=平滑过渡 18 | 19 | terraplusplus.gui.dynamicbaseheight=高海拔生成矿物 20 | 21 | terraplusplus.gui.osmwater=高级水面(实验性) 22 | 23 | terraplusplus.gui.buildings=OSM建筑轮廓 24 | 25 | 26 | 27 | ## Projection types 28 | 29 | terraplusplus.projection.web_mercator=墨卡托投影 30 | 31 | terraplusplus.projection.equirectangular=等矩投影 32 | 33 | terraplusplus.projection.sinusoidal=正弦投影 34 | 35 | terraplusplus.projection.equal_earth=Equal Earth 36 | 37 | 38 | 39 | ## Projection orientations 40 | 41 | terraplusplus.orientation.upright=定向 42 | 43 | terraplusplus.orientation.none=无方向 44 | 45 | terraplusplus.orientation.swapped=翻转坐标轴 46 | 47 | ## command messages 48 | 49 | terraplusplus.command.tpll.usage=/tpll <纬度> <经度> [海拔高度] [玩家] 50 | 51 | terraplusplus.command.terra.usage=/terra [where:ou] [玩家]\n/terra world\n/terra osm\n/terra conv[ert] [x z]:[纬度 经度] 52 | 53 | terraplusplus.command.terra.gensettings=Generator Settings: 54 | 55 | terraplusplus.command.terra.latlon=纬度 经度: %.7f %.7f 56 | 57 | terraplusplus.command.terra.xy=x y: %.7f %.7f 58 | 59 | ## command errors 60 | terraplusplus.error.notcc=必须在Cubic Chunks世界中执行! 61 | 62 | terraplusplus.error.notterra=必须在Terra 1 to 1世界中执行! 63 | 64 | terraplusplus.error.numbers=所有参数必须是数字! 65 | 66 | terraplusplus.error.getcoords=无法获取坐标! 67 | 68 | terraplusplus.error.notplayer=你不是玩家,必须指定一个! 69 | 70 | terraplusplus.error.unknownplayer=未知玩家! 71 | 72 | terraplusplus.error.notopothers=需要OP权限以获得其他玩家信息! 73 | -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/textures/directions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/assets/terraplusplus/textures/directions.png -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/textures/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/assets/terraplusplus/textures/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/textures/presets/advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/assets/terraplusplus/textures/presets/advanced.png -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/textures/presets/bte.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/assets/terraplusplus/textures/presets/bte.png -------------------------------------------------------------------------------- /src/main/resources/assets/terraplusplus/textures/presets/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/assets/terraplusplus/textures/presets/default.png -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "terraplusplus", 4 | "name": "TerraPlusPlus", 5 | "description": "A feature-rich fork of Terra121 focusing on performance.", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "https://buildtheearth.net", 9 | "updateUrl": "", 10 | "authorList": [ 11 | "DaPorkchop_", 12 | "SmylerMC", 13 | "noahhusby", 14 | "BTE Development Community" 15 | ], 16 | "credits": "Cubic Chunks discord and all source providers specified below, especially OpenStreetMap (© OpenStreetMap contributors). Terra121 by orangeadam3 and shejan0", 17 | "logoFile": "assets/terraplusplus/textures/icon.png", 18 | "screenshots": [], 19 | "dependencies": [] 20 | } 21 | ] 22 | -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/control/map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/net/buildtheearth/terraplusplus/control/map.png -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/dataset/builtin/climate.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/net/buildtheearth/terraplusplus/dataset/builtin/climate.lzma -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/dataset/builtin/soil.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/net/buildtheearth/terraplusplus/dataset/builtin/soil.lzma -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/dataset/scalar/tree_cover.json5: -------------------------------------------------------------------------------- 1 | /* 2 | * DEFAULT TERRA++ TREE COVER DATASETS 3 | */ 4 | 5 | [ 6 | //whole world at max resolution 7 | { 8 | "dataset": { 9 | "urls": [ 10 | "https://cloud.daporkchop.net/gis/treecover2000/13/${x}/${z}.tiff" 11 | ], 12 | "projection": { 13 | "scale": { 14 | "delegate": { 15 | "web_mercator": { 16 | "zoom": 13 17 | } 18 | }, 19 | "x": 1.0, 20 | "y": 1.0 21 | } 22 | }, 23 | "resolution": 256, 24 | "blend": "CUBIC", 25 | "parse": { 26 | "divide": { 27 | "delegate": { 28 | "parse_tiff_auto": {} 29 | }, 30 | "value": 100.0 31 | } 32 | } 33 | }, 34 | "zooms": 0, 35 | "bounds": { 36 | "minX": -180.0, 37 | "maxX": 180.0, 38 | "minZ": -60, 39 | "maxZ": 80 40 | }, 41 | "priority": -100.0 42 | } 43 | ] 44 | -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/generator/biome/biome_overrides.json5: -------------------------------------------------------------------------------- 1 | [ 2 | /*{ 3 | "biome": "minecraft:hell", 4 | "bounds": { 5 | "minX": 5, 6 | "maxX": 50, 7 | "minZ": 5, 8 | "maxZ": 50 9 | }, 10 | "priority": 100.0 11 | }, 12 | { 13 | "biome": "minecraft:void", 14 | "replace": [ //this part is optional 15 | "minecraft:ocean", 16 | "minecraft:deep_ocean" 17 | ], 18 | "bounds": { 19 | "minX": -50, 20 | "maxX": -5, 21 | "minZ": -50, 22 | "maxZ": -5 23 | }, 24 | "priority": 3.0 25 | }*/ 26 | ] 27 | -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/generator/bte_generator_settings.json5: -------------------------------------------------------------------------------- 1 | { 2 | "projection": { 3 | "scale": { 4 | "delegate": { 5 | "flip_vertical": { 6 | "delegate": { 7 | "bte_conformal_dymaxion": {} 8 | } 9 | } 10 | }, 11 | "x": 7318261.522857145, 12 | "y": 7318261.522857145 13 | } 14 | }, 15 | "useDefaultHeights": true, 16 | "useDefaultTrees": true, 17 | "version": 2 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/generator/default_generator_settings.json5: -------------------------------------------------------------------------------- 1 | { 2 | "projection": { 3 | "scale": { 4 | "delegate": { 5 | "equirectangular": {} 6 | }, 7 | "x": 100000.0, 8 | "y": 100000.0 9 | } 10 | }, 11 | "useDefaultHeights": true, 12 | "useDefaultTrees": true, 13 | "version": 2 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/net/buildtheearth/terraplusplus/projection/dymaxion/conformal.lzma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BuildTheEarth/terraplusplus/5ae750171a0c6b8ef3cdf586b9dafe9851c84e53/src/main/resources/net/buildtheearth/terraplusplus/projection/dymaxion/conformal.lzma -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack": { 3 | "description": "terraplusplus resources", 4 | "pack_format": 4, 5 | "_comment": "" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/net/buildtheearth/terraplusplus/util/OrderedRegistryTest.java: -------------------------------------------------------------------------------- 1 | package net.buildtheearth.terraplusplus.util; 2 | 3 | import static net.daporkchop.lib.common.util.PValidation.checkState; 4 | 5 | import java.util.Arrays; 6 | import java.util.Map; 7 | import java.util.stream.Collectors; 8 | 9 | import org.junit.Test; 10 | 11 | /** 12 | * @author DaPorkchop_ 13 | */ 14 | public class OrderedRegistryTest { 15 | @Test 16 | public void test() { 17 | Object dummy = new Object(); 18 | OrderedRegistry registry = new OrderedRegistry<>(); 19 | 20 | checkState(registry.entryStream().count() == 0L); 21 | 22 | registry.addFirst("c", dummy) 23 | .addFirst("a", dummy) 24 | .addLast("m", dummy); 25 | checkState(Arrays.asList("a", "c", "m").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 26 | 27 | registry.addBefore("a", "", dummy); 28 | registry.addBefore("m", "h", dummy); 29 | checkState(Arrays.asList("", "a", "c", "h", "m").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 30 | 31 | registry.addAfter("a", "b", dummy); 32 | registry.addAfter("m", "n", dummy); 33 | checkState(Arrays.asList("", "a", "b", "c", "h", "m", "n").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 34 | 35 | registry.set("h", dummy); 36 | checkState(Arrays.asList("", "a", "b", "c", "h", "m", "n").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 37 | 38 | registry.set("h", "i", dummy); 39 | checkState(Arrays.asList("", "a", "b", "c", "i", "m", "n").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 40 | 41 | registry.remove("c"); 42 | checkState(Arrays.asList("", "a", "b", "i", "m", "n").equals(registry.entryStream().map(Map.Entry::getKey).collect(Collectors.toList())), registry); 43 | } 44 | } 45 | --------------------------------------------------------------------------------