├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── ci.yml │ ├── codeql-analysis.yml │ ├── sonarqube.yml │ └── validate-gradle-build.yml ├── .gitignore ├── .travis.yml ├── CHANGELOG.txt ├── Jenkinsfile ├── LICENSE ├── README.md ├── build.gradle ├── changelog.mustache ├── config └── checkstyle │ └── checkstyle.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── com │ └── mcmoddev │ └── orespawn │ ├── EventHandlers.java │ ├── OreSpawn.java │ ├── api │ ├── BiomeLocation.java │ ├── FeatureBase.java │ ├── IBlockList.java │ ├── IDimensionList.java │ ├── IFeature.java │ ├── exceptions │ │ ├── BadStateValueException.java │ │ ├── BadValueException.java │ │ ├── MissingVersionException.java │ │ ├── NotAProperConfigException.java │ │ ├── OldVersionException.java │ │ ├── UnknownFieldException.java │ │ ├── UnknownNameException.java │ │ └── UnknownVersionException.java │ ├── os3 │ │ ├── IBiomeBuilder.java │ │ ├── IBlockBuilder.java │ │ ├── IBlockDefinition.java │ │ ├── IDimensionBuilder.java │ │ ├── IFeatureBuilder.java │ │ ├── IFeatureEntry.java │ │ ├── IReplacementBuilder.java │ │ ├── IReplacementEntry.java │ │ ├── ISpawnBuilder.java │ │ ├── ISpawnEntry.java │ │ ├── OS3API.java │ │ ├── OS3FeatureGenerator.java │ │ ├── OreSpawnBlockMatcher.java │ │ └── package-info.java │ └── plugin │ │ ├── IOreSpawnPlugin.java │ │ ├── OreSpawnPlugin.java │ │ └── PluginLoader.java │ ├── commands │ ├── AddOreCommand.java │ ├── ClearChunkCommand.java │ ├── DumpBiomesCommand.java │ └── WriteConfigsCommand.java │ ├── data │ ├── Config.java │ ├── Constants.java │ ├── FeatureRegistry.java │ ├── PresetsStorage.java │ ├── ReplacementsRegistry.java │ └── VanillaOres.java │ ├── impl │ ├── features │ │ ├── ClusterGenerator.java │ │ ├── DefaultFeatureGenerator.java │ │ ├── NormalCloudGenerator.java │ │ ├── PrecisionGenerator.java │ │ ├── UnderFluid.java │ │ └── VeinGenerator.java │ ├── location │ │ ├── BiomeLocationAcceptAny.java │ │ ├── BiomeLocationComposition.java │ │ ├── BiomeLocationDictionary.java │ │ ├── BiomeLocationEmpty.java │ │ ├── BiomeLocationList.java │ │ └── BiomeLocationSingle.java │ └── os3 │ │ ├── BiomeBuilder.java │ │ ├── BlockBuilder.java │ │ ├── BlockDefinition.java │ │ ├── BlockList.java │ │ ├── DimensionBuilder.java │ │ ├── DimensionList.java │ │ ├── DimensionListAcceptAll.java │ │ ├── DimensionListAcceptAllOverworld.java │ │ ├── DimensionListDenyAll.java │ │ ├── FeatureBuilder.java │ │ ├── FeatureEntry.java │ │ ├── OS3APIImpl.java │ │ ├── ReplacementBuilder.java │ │ ├── ReplacementEntry.java │ │ ├── SpawnBuilder.java │ │ └── SpawnEntry.java │ ├── json │ ├── OreSpawnReader.java │ └── OreSpawnWriter.java │ ├── util │ ├── Collectors2.java │ └── StateUtil.java │ └── worldgen │ ├── FlatBedrock.java │ ├── OreSpawnFeatureGenerator.java │ └── OreSpawnWorldGen.java └── resources ├── assets └── orespawn │ └── configs │ ├── _features.json │ ├── _replacements.json │ └── orespawn.json ├── mcmod.info └── pack.mcmeta /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Java Gradle CircleCI 2.0 Configuration file. 2 | version: 2 3 | jobs: 4 | build: 5 | docker: 6 | - image: circleci/openjdk:8-jdk 7 | 8 | working_directory: ~/repo 9 | 10 | environment: 11 | JVM_OPTS: -Xmx3200m 12 | TERM: dumb 13 | 14 | steps: 15 | - checkout 16 | 17 | # Download and cache dependencies 18 | - restore_cache: 19 | keys: 20 | - v1-dependencies-{{ checksum "build.gradle" }} 21 | # fallback to using the latest cache if no exact match is found 22 | - v1-dependencies- 23 | 24 | - run: 25 | name: Grant access to ./gradlew. 26 | command: | 27 | chmod +x gradlew 28 | 29 | - run: 30 | name: Show the Gradle version in use with other details. 31 | command: | 32 | ./gradlew --version 33 | 34 | - run: 35 | name: Set up the workspace for ci build 36 | command: | 37 | ./gradlew setupCiWorkspace 38 | 39 | - run: 40 | name: Clean the workspace ready for a fresh build. 41 | command: | 42 | ./gradlew clean 43 | 44 | - run: 45 | name: Attempt to build the mod. 46 | command: | 47 | ./gradlew build 48 | 49 | - store_artifacts: 50 | path: ./build/libs 51 | 52 | - save_cache: 53 | paths: 54 | - ~/.gradle 55 | key: v1-dependencies-{{ checksum "build.gradle" }} 56 | 57 | # run tests! 58 | - run: ./gradlew test 59 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | 7 | [*.java] 8 | charset = utf-8 9 | indent_style = tab 10 | indent_size = 4 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.bat text eol=crlf 4 | #*.bat text eol=lf 5 | *.gradle text diff=java 6 | mcmod.info text 7 | *.java text 8 | *.json text 9 | *.lang text 10 | *.mcmeta text 11 | *.md text 12 | *.properties text 13 | gradlew text eol=lf 14 | *.sh text eol=lf 15 | *.txt text 16 | *.xml text 17 | *.yml text 18 | *.yaml text 19 | *.toml text 20 | 21 | # Documents 22 | *.pdf binary 23 | 24 | # Graphics 25 | *.eps binary 26 | *.gif binary 27 | *.ico binary 28 | *.jpg binary 29 | *.jpeg binary 30 | *.png binary 31 | *.psd binary 32 | # SVG treated as an asset (binary) by default. If you want to treat it as text, 33 | # comment-out the following line and uncomment the line after. 34 | *.svg binary 35 | #*.svg text 36 | *.tif binary 37 | *.tiff binary 38 | *.webp binary 39 | *.xcf binary 40 | 41 | # Other 42 | *.exe binary 43 | *.jar binary 44 | 45 | ############################### 46 | # Git Large File System (LFS) # 47 | ############################### 48 | 49 | # Archives 50 | #*.7z filter=lfs diff=lfs merge=lfs -text 51 | #*.br filter=lfs diff=lfs merge=lfs -text 52 | #*.bz2 filter=lfs diff=lfs merge=lfs -text 53 | #*.gz filter=lfs diff=lfs merge=lfs -text 54 | #*.tar filter=lfs diff=lfs merge=lfs -text 55 | #*.zip filter=lfs diff=lfs merge=lfs -text 56 | 57 | # Documents 58 | #*.pdf filter=lfs diff=lfs merge=lfs -text 59 | 60 | # Graphics 61 | #*.eps filter=lfs diff=lfs merge=lfs -text 62 | #*.gif filter=lfs diff=lfs merge=lfs -text 63 | #*.ico filter=lfs diff=lfs merge=lfs -text 64 | #*.jpg filter=lfs diff=lfs merge=lfs -text 65 | #*.jpeg filter=lfs diff=lfs merge=lfs -text 66 | #*.png filter=lfs diff=lfs merge=lfs -text 67 | #*.psd filter=lfs diff=lfs merge=lfs -text 68 | #*.tif filter=lfs diff=lfs merge=lfs -text 69 | #*.tiff filter=lfs diff=lfs merge=lfs -text 70 | #*.webp filter=lfs diff=lfs merge=lfs -text 71 | #*.xcf filter=lfs diff=lfs merge=lfs -text 72 | 73 | # Other 74 | #*.exe filter=lfs diff=lfs merge=lfs -text 75 | #*.jar filter=lfs diff=lfs merge=lfs -text 76 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [push, pull_request] 4 | #on: 5 | # push: 6 | # branches: [ master-1.12 ] 7 | # pull_request: 8 | # # The branches below must be a subset of the branches above 9 | # branches: [ master-1.12 ] 10 | # types: [opened, synchronize, reopened] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | name: Build 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions/setup-java@v1 19 | with: 20 | java-version: 8 21 | - run: chmod a+x gradlew 22 | - run: ./gradlew --version --no-daemon 23 | - run: ./gradlew setupCIWorkspace -S 24 | - run: ./gradlew clean build -S 25 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: [push, pull_request] 15 | #on: 16 | # push: 17 | # branches: [ master-1.12 ] 18 | # pull_request: 19 | # # The branches below must be a subset of the branches above 20 | # branches: [ master-1.12 ] 21 | # types: [opened, synchronize, reopened] 22 | # schedule: 23 | # - cron: '43 7 * * 4' 24 | 25 | jobs: 26 | analyze: 27 | name: Analyze 28 | runs-on: ubuntu-latest 29 | permissions: 30 | actions: read 31 | contents: read 32 | security-events: write 33 | 34 | strategy: 35 | fail-fast: false 36 | matrix: 37 | language: [ 'java' ] 38 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 39 | # Learn more: 40 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 41 | 42 | steps: 43 | - name: Checkout repository 44 | uses: actions/checkout@v2 45 | 46 | # Initializes the CodeQL tools for scanning. 47 | - name: Initialize CodeQL 48 | uses: github/codeql-action/init@v1 49 | with: 50 | languages: ${{ matrix.language }} 51 | # If you wish to specify custom queries, you can do so here or in a config file. 52 | # By default, queries listed here will override any specified in a config file. 53 | # Prefix the list here with "+" to use these queries and those in the config file. 54 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v1 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 https://git.io/JvXDl 63 | 64 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 65 | # and modify them (or add more) to build your code if your project 66 | # uses a compiled language 67 | 68 | #- run: | 69 | # make bootstrap 70 | # make release 71 | 72 | - name: Perform CodeQL Analysis 73 | uses: github/codeql-action/analyze@v1 74 | -------------------------------------------------------------------------------- /.github/workflows/sonarqube.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | #on: 3 | # push: 4 | # branches: 5 | # - master-1.12 6 | # pull_request: 7 | # types: [opened, synchronize, reopened] 8 | # 9 | name: SonarCloud 10 | jobs: 11 | sonarcloud: 12 | name: SonarCloud Scan 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | with: 17 | # Disabling shallow clone is recommended for improving relevancy of reporting 18 | fetch-depth: 0 19 | - name: SonarCloud Scan 20 | uses: SonarSource/sonarcloud-github-action@master 21 | env: 22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 23 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 24 | # SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} 25 | - name: SonarCloud Quality Gate check 26 | uses: SonarSource/sonarqube-quality-gate-action@master 27 | # Force to fail step after specific time 28 | timeout-minutes: 5 29 | env: 30 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 31 | -------------------------------------------------------------------------------- /.github/workflows/validate-gradle-build.yml: -------------------------------------------------------------------------------- 1 | name: Validate Gradle Wrapper 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | validation: 7 | name: "Validation" 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: gradle/wrapper-validation-action@v1 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # eclipse 2 | bin 3 | *.launch 4 | .settings 5 | .metadata 6 | .classpath 7 | .project 8 | 9 | # idea 10 | out 11 | *.ipr 12 | *.iws 13 | *.iml 14 | .idea 15 | 16 | # gradle 17 | build 18 | .gradle 19 | 20 | # other 21 | eclipse 22 | run 23 | classes 24 | *.hprof 25 | 26 | /README.txt 27 | /forge-*-changelog.txt 28 | 29 | secret.json 30 | libs/* 31 | !/libs/README.txt 32 | 33 | .DS_Store 34 | .DS_Store/* 35 | .okhttpcache/* 36 | OS3 API Redesign Notes.txt 37 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | os: linux 3 | dist: trusty 4 | addons: 5 | apt: 6 | update: true 7 | packages: 8 | # - oracle-java8-installer 9 | git: 10 | quiet: true 11 | arch: amd64 12 | before_cache: 13 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 14 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 15 | cache: 16 | directories: 17 | - $HOME/.gradle/caches/ 18 | - $HOME/.gradle/wrapper/ 19 | notifications: 20 | email: false 21 | jdk: 22 | - oraclejdk8 23 | before_install: skip 24 | install: skip 25 | before_script: 26 | - chmod a+x gradlew 27 | script: 28 | - ./gradlew setupCIWorkspace -S 29 | - ./gradlew clean build -S 30 | -------------------------------------------------------------------------------- /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | Version 3.3.1 2 | 3 | * Fix several bugs 4 | * Add ability to completely replace oregeneration (By popular request) 5 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | environment { 4 | GRADLE_OPTS = '-Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dorg.gradle.warning.mode=all' 5 | // JAVA_OPTS = '' 6 | } 7 | options { 8 | ansiColor('xterm') 9 | } 10 | tools { 11 | // git 'Git' 12 | gradle 'Gradle 4.9' 13 | jdk 'oraclejdk8' 14 | } 15 | stages { 16 | stage('prebuild') { 17 | steps { 18 | sh 'rm -rf build/libs' 19 | sh 'chmod +x gradlew' 20 | sh 'java -version' 21 | sh 'gradle -version' 22 | sh './gradlew -version' 23 | sh 'export' 24 | } 25 | } 26 | stage('CIWorkspace') { 27 | steps { 28 | withGradle { 29 | sh './gradlew clean setupCiWorkspace -S' 30 | } 31 | } 32 | } 33 | stage('build') { 34 | steps { 35 | withGradle { 36 | sh './gradlew build -S' 37 | } 38 | } 39 | } 40 | stage('test') { 41 | steps { 42 | withGradle { 43 | sh './gradlew test -S' 44 | } 45 | } 46 | } 47 | stage('publish') { 48 | steps { 49 | withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { 50 | withGradle { 51 | sh './gradlew publish -S' 52 | } 53 | } 54 | } 55 | } 56 | stage('CurseForge') { 57 | steps { 58 | withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { 59 | withGradle { 60 | sh './gradlew -x publish curseforge -S' 61 | } 62 | } 63 | } 64 | } 65 | stage('SonarQube') { 66 | tools { 67 | jdk "oraclejdk11" 68 | } 69 | environment { 70 | scannerHome = tool 'SonarQube' 71 | } 72 | steps { 73 | // withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { 74 | // withGradle { 75 | // sh './gradlew sonarqube -S' 76 | // } 77 | // } 78 | withSonarQubeEnv(installationName: 'SonarCloud', , envOnly: false) { 79 | sh "${scannerHome}/bin/sonar-scanner -Dsonar.java.jdkHome=${JAVA_HOME}" 80 | } 81 | } 82 | } 83 | stage('postbuild') { 84 | steps { 85 | archiveArtifacts artifacts: 'build/libs/*.jar', followSymlinks: false 86 | javadoc javadocDir: 'build/docs/javadoc', keepAll: false 87 | fingerprint 'build/libs/*.zip' 88 | junit allowEmptyResults: true, testResults: '**/build/test-results/junit-platform/*.xml' 89 | jacoco classPattern: '**/build/classes/java', execPattern: '**/build/jacoco/**.exec', sourceInclusionPattern: '**/*.java', sourcePattern: '**/src/main/java' 90 | findBuildScans() 91 | recordIssues(tools: [java()]) 92 | recordIssues(tools: [javaDoc()]) 93 | // if (fileExists('')) { 94 | // recordIssues(tools: [errorProne(pattern: 'ReportFilePattern', reportEncoding: 'UTF-8')]) 95 | // } else { 96 | // echo 'No ErrorProne report available' 97 | // } 98 | if (fileExists('**/build/reports/checkstyle/*.xml')) { 99 | recordIssues(tools: [checkStyle(pattern: '**/build/reports/checkstyle/*.xml')]) 100 | } else { 101 | echo 'No CheckStyle report available' 102 | } 103 | if (fileExists('**/build/reports/pmd/*.xml')) { 104 | recordIssues(tools: [pmdParser(pattern: '**/build/reports/pmd/*.xml')]) 105 | } else { 106 | echo 'No PMD report available' 107 | } 108 | if (fileExists('*/build/reports/findbugs/*.xml')) { 109 | recordIssues(tools: [findBugs(pattern: '*/build/reports/findbugs/*.xml', useRankAsPriority: true)]) 110 | } else { 111 | echo 'No FindBugs report available' 112 | } 113 | } 114 | when { expression { fileExists('**/build/reports/spotbugs/*.xml') } } 115 | steps { 116 | recordIssues(tools: [spotBugs(pattern: '**/build/reports/spotbugs/*.xml', useRankAsPriority: true)]) 117 | } 118 | when { expression { fileExists('**/build/test-results/junit-platform/*.xml') } } 119 | steps { 120 | recordIssues(tools: [junitParser(pattern: '**/build/test-results/junit-platform/*.xml')]) 121 | } 122 | when { expression { fileExists('**/sonar-report.json') } } 123 | steps { 124 | recordIssues(tools: [sonarQube(pattern: '**/sonar-report.json')]) 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) 2 | [![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) 3 | [![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) 4 | [![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) 5 | 6 | # OreSpawn 7 | Minecraft library mod that provides better control over the spawning of ores in Minecraft. 8 | If you're looking for a place to report bugs for the mod that adds extra mobs, the "DangerZone", etc... go [to the site for that mod](http://www.orespawn.com/) as this is not it. 9 | 10 | ## How it works 11 | Ore Spawn parses all of the .json files found in `orespawn` and adds ore generators to the game based on those files. The JSON structure looks like this: 12 | 13 | ```json 14 | [ 15 | { 16 | "dimension": -1, 17 | "ores": [ 18 | { 19 | "block": "minecraft:quartz_ore", 20 | "size": 15, 21 | "variation": 4, 22 | "frequency": 7, 23 | "min_height": 0, 24 | "max_height": 128 25 | } 26 | ] 27 | }, 28 | { 29 | "ores": [ 30 | { 31 | "block": "minecraft:coal_ore", 32 | "size": 25, 33 | "variation": 12, 34 | "frequency": 20, 35 | "min_height": 0, 36 | "max_height": 128 37 | }, 38 | { 39 | "block": "minecraft:iron_ore", 40 | "size": 8, 41 | "variation": 4, 42 | "frequency": 20, 43 | "min_height": 0, 44 | "max_height": 64 45 | }, 46 | { 47 | "block": "minecraft:gold_ore", 48 | "size": 8, 49 | "variation": 2, 50 | "frequency": 2, 51 | "min_height": 0, 52 | "max_height": 32 53 | }, 54 | { 55 | "block": "minecraft:diamond_ore", 56 | "size": 6, 57 | "variation": 3, 58 | "frequency": 8, 59 | "min_height": 0, 60 | "max_height": 16 61 | }, 62 | { 63 | "block": "minecraft:lapis_ore", 64 | "size": 5, 65 | "variation": 2, 66 | "frequency": 1, 67 | "min_height": 0, 68 | "max_height": 32 69 | }, 70 | { 71 | "block": "minecraft:emerald_ore", 72 | "size": 1, 73 | "variation": 0, 74 | "frequency": 8, 75 | "min_height": 4, 76 | "max_height": 32, 77 | "biomes": [ 78 | "minecraft:extreme_hills", 79 | "minecraft:smaller_extreme_hills" 80 | ] 81 | }, 82 | { 83 | "block": "minecraft:dirt", 84 | "size": 112, 85 | "variation": 50, 86 | "frequency": 10, 87 | "min_height": 0, 88 | "max_height": 255 89 | }, 90 | { 91 | "block": "minecraft:gravel", 92 | "size": 112, 93 | "variation": 50, 94 | "frequency": 8, 95 | "min_height": 0, 96 | "max_height": 255 97 | }, 98 | { 99 | "block": "minecraft:stone", 100 | "state": "variant=granite", 101 | "size": 112, 102 | "variation": 50, 103 | "frequency": 10, 104 | "min_height": 0, 105 | "max_height": 255 106 | }, 107 | { 108 | "block": "minecraft:stone", 109 | "state": "variant=diorite", 110 | "size": 112, 111 | "variation": 50, 112 | "frequency": 10, 113 | "min_height": 0, 114 | "max_height": 255 115 | }, 116 | { 117 | "block": "minecraft:stone", 118 | "state": "variant=andesite", 119 | "size": 112, 120 | "variation": 50, 121 | "frequency": 10, 122 | "min_height": 0, 123 | "max_height": 255 124 | } 125 | ] 126 | } 127 | ] 128 | ``` 129 | 130 | ### dimension 131 | The number ID of a dimension. Don't specify any dimension to target all dimensions *that are not already specified*. 132 | ### ores 133 | Array of JSON objects specifying ore generators for this dimension 134 | ### block 135 | Text ID of a block (the same you would use in the /give command) 136 | ### state 137 | The state of a block (typically used for colored blocks) 138 | ### size 139 | The number of blocks to spawn. Unlike the default Minecraft world settings JSON, this is the actually number of blocks that will spawn. 140 | ### variation 141 | How much to randomly vary the number of blocks spawned (I recommend making this value 50% of the *size* value) 142 | ### frequency 143 | How often, per chunk, to attempt to spawn this ore block. This value can be a fraction less than 1. If this value is between 0 and 1, then not every chunk will have a spawn in it. For example, a frequency of 0.1 means that there will be one attempt to spawn the ore per 10 chunks. 144 | ### min_height 145 | The lowest Y-coordinate that the ore is allowed to spawn at 146 | ### max_height 147 | The highest Y-coordinate that the ore is allowed to spawn at 148 | ### biomes 149 | If this array is not empty, then the biomes in which the ore will spawn is restricted to those specified by ID in this array. 150 | 151 | # API 152 | Adding OreSpawn support to your mod is not hard. Look at `VanillaOreSpawn.java` for an example. 153 | -------------------------------------------------------------------------------- /changelog.mustache: -------------------------------------------------------------------------------- 1 | {{#tags}} 2 | {{#issues}} 3 | {{#commits}} 4 | **{{{messageTitle}}}** 5 | {{#messageBodyItems}} 6 | * {{.}} 7 | {{/messageBodyItems}} 8 | {{/commits}} 9 | {{/issues}} 10 | {{/tags}} 11 | -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 16 | 17 | 18 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 60 | 61 | 62 | 63 | 64 | 65 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 131 | 132 | 133 | 134 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | org.gradle.daemon = false 2 | 3 | group = com.mcmoddev 4 | archivesBaseName = OreSpawn 5 | modid = orespawn 6 | vendor = mcmoddev 7 | name = MMD OreSpawn 8 | description = MMD OreSpawn 9 | 10 | #Minumum Minecraft Version Mod will be built with 11 | mc_version=1.12 12 | 13 | #ForgeGradle version to use (Required) 14 | fg_version = 2.3-SNAPSHOT 15 | #version of Minecraft Forge is built against (Required) 16 | forge_mc_version = 1.12.2 17 | #Forge version to use (Required) 18 | forge_version = 14.23.5.2847 19 | #Mappings version to use (Required) 20 | mcp_mappings_version = stable_39 21 | 22 | # The following will currently only be set when using Gradle 4.8 or later 23 | pom_information = false 24 | pom_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' 25 | 26 | pom_license_information = true 27 | pom_license_name = 'GNU Lesser General Public License v2.1' 28 | pom_license_url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' 29 | pom_comments = '' 30 | 31 | pom_scm_information = true 32 | pom_scm_connection = 'scm:git:git://github.com/MinecraftModDevelopmentMods/OreSpawn.git' 33 | pom_scm_developer_connection = 'scm:git:git@github.com:MinecraftModDevelopmentMods/OreSpawn.git' 34 | pom_scm_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' 35 | 36 | pom_issue_information = true 37 | pom_issue_system = 'github' 38 | pom_issue_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn/issues' 39 | 40 | pom_ci_information = true 41 | pom_ci_system = 'jenkins' 42 | pom_ci_url = 'https://ci.mcmoddev.com/' 43 | 44 | pom_organisation_information = true 45 | pom_organization_name = 'Minecraft Mod Development' 46 | pom_organization_url = 'https://mcmoddev.com/' 47 | 48 | curseforge_do_upload=false 49 | #curseforge_debug=false 50 | #Cursforge Project ID (Required) 51 | curseforge_project_id = 245586 52 | #Type of Release, can be one of 'alpha', 'beta' or 'release' (Defaults to 'alpha' if not set) 53 | curseforge_release_type = release 54 | #When using a ChangeLog file specifies filename 55 | curseforge_changelog_filename = CHANGELOG.txt 56 | #Changelog type, can be one of 'text', 'html' or 'markdown' (Defaults to 'text' if not set) 57 | curseforge_changelog_type = text 58 | #Version(s) of Minecraft this mod will work on (comma separated list) 59 | curseforge_versions = 1.12, 1.12.1, 1.12.2 60 | #Whether to use a custom display name on artifacts 61 | curseforge_use_custom_display_name = true 62 | #List of required dependencies (comma separated list) 63 | #curseforge_requirements = 64 | #List of optional dependencies (comma separated list) 65 | #curseforge_optionals = 66 | #List of embedded dependencies (comma separated list) 67 | #curseforge_embeddeds = 68 | #List of compatible tools (comma separated list) 69 | #curseforge_tools = 70 | #List of incompatible dependencies (comma separated list) 71 | #curseforge_incompatibles = 72 | #List of included dependencies (comma separated list) 73 | #curseforge_includes = 74 | 75 | #String reference to Core Plugin this mod contains, if any 76 | #core_plugin = 77 | #Whether or not to use Access Transformers from depended mods 78 | dep_has_ats = false 79 | #File name of this mod's Access Transformers (If any) 80 | #mod_at_file = _at.cfg 81 | 82 | #Whether the artifacts should be signed 83 | do_sign_jar = true 84 | 85 | #Create a source jar? 86 | create_source_jar = true 87 | #Create an API jar? 88 | create_api_jar = true 89 | #Create a deobf jar? 90 | create_deobf_jar = true 91 | #Create a javadoc jar? 92 | create_javadoc_jar = true 93 | 94 | #The following four options are optional and do not affect your build in any way 95 | #They are only for convenience when using the 'runClient' and 'runServer' tasks 96 | #Whether to Disable server gui 97 | #mc_server_nogui = true 98 | #Whether to Skip the screen to confirm that you want to load a world with missing registry entries 99 | #forge_do_not_backup = true 100 | #Whether to skip having to confirm on server 101 | #forge_query_result_confirm = true 102 | #Whether to Skip jansi warnings in the log 103 | #log4j_skip_jansi = true 104 | 105 | # Optional convenience setter for game resolution one of '480p', '576p', '720p', '1080p' or 'custom' 106 | #mc_resolution = 1080p 107 | #the following two will only be used when mc_resolution = custom 108 | #mc_custom_resolution_width = 1920 109 | #mc_custom_resolution_height = 1080 110 | #mc_fullscreen = true 111 | 112 | #Additional arguments to pass to minecraft.clientJvmArgs 113 | #client_jvm_args = 114 | #Additional arguments to pass to minecraft.serverJvmArgs 115 | #client_game_args = 116 | #Additional arguments to pass to minecraft.clientRunArgs 117 | #server_jvm_args = 118 | #Additional arguments to pass to minecraft.serverRunArgs 119 | #server_game_args = 120 | 121 | ##The following three options should *NEVER* be set in this file, it's a security risk, Be safe, keep your account information private. 122 | ##These properties here are for reference only and explanation of what they do 123 | ##Your Minecraft account username (Consistent player name for singleplayer worlds) 124 | ##mc_username = 125 | ##Your Minecraft account password (Allows online play while present with associated username) 126 | ##mc_password = 127 | ##Your Minecraft account uuid (Allows using your skin while testing, This can be with or without hyphens) 128 | ##mc_uuid = 129 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MinecraftModDevelopmentMods/OreSpawn/a794d665caf0d635a755bd4c30aadd5ef9ef7ab7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // Workaround to make the JUnit Platform Gradle Plugin available using the `plugins` DSL 2 | // See https://github.com/junit-team/junit5/issues/768 3 | if (!(GradleVersion.current() <= GradleVersion.version('2.14.1'))) { 4 | pluginManagement { 5 | repositories { 6 | gradlePluginPortal() 7 | maven { url = ArtifactRepositoryContainer.MAVEN_CENTRAL_URL } 8 | } 9 | resolutionStrategy { 10 | eachPlugin { 11 | if (requested.id.id == 'org.junit.platform.gradle.plugin') { 12 | useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") 13 | // } else if (requested.id.id == 'org.junit.platform.gradle.plugin') { 14 | // useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") 15 | } 16 | } 17 | } 18 | } 19 | } 20 | 21 | rootProject.name = archivesBaseName 22 | import org.gradle.util.GradleVersion 23 | if ((GradleVersion.current() >= GradleVersion.version('4.8')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { 24 | enableFeaturePreview('STABLE_PUBLISHING') // 4.10.3 25 | } 26 | 27 | // TODO: Things which likely don't work with FG yet, but I've not checked. 28 | /* 29 | if ((GradleVersion.current() >= GradleVersion.version('4.6')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { 30 | enableFeaturePreview('IMPROVED_POM_SUPPORT') // Previously -Dorg.gradle.advancedpomsupport=true 31 | enableFeaturePreview('GRADLE_METADATA') // Previously -Dorg.gradle.gradlemetadata=true 32 | } 33 | */ 34 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/OreSpawn.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | 6 | import com.mcmoddev.orespawn.api.os3.OS3API; 7 | import com.mcmoddev.orespawn.api.plugin.PluginLoader; 8 | import com.mcmoddev.orespawn.commands.AddOreCommand; 9 | import com.mcmoddev.orespawn.commands.ClearChunkCommand; 10 | import com.mcmoddev.orespawn.commands.DumpBiomesCommand; 11 | import com.mcmoddev.orespawn.commands.WriteConfigsCommand; 12 | import com.mcmoddev.orespawn.data.Config; 13 | import com.mcmoddev.orespawn.data.Constants; 14 | import com.mcmoddev.orespawn.data.FeatureRegistry; 15 | import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; 16 | import com.mcmoddev.orespawn.worldgen.FlatBedrock; 17 | import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; 18 | 19 | import net.minecraftforge.common.MinecraftForge; 20 | import net.minecraftforge.fml.common.Mod; 21 | import net.minecraftforge.fml.common.Mod.EventHandler; 22 | import net.minecraftforge.fml.common.Mod.Instance; 23 | import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; 24 | import net.minecraftforge.fml.common.event.FMLInitializationEvent; 25 | import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; 26 | import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; 27 | import net.minecraftforge.fml.common.event.FMLServerStartingEvent; 28 | import net.minecraftforge.fml.common.registry.GameRegistry; 29 | 30 | /** 31 | * Main entry point for the mod, everything runs through this. 32 | * 33 | * @author DShadowWolf <dshadowwolf@gmail.com> 34 | */ 35 | 36 | @Mod(modid = Constants.MODID, 37 | name = Constants.NAME, 38 | version = Constants.VERSION, 39 | acceptedMinecraftVersions = "[1.12,1.12.2]", 40 | certificateFingerprint = "@FINGERPRINT@") 41 | 42 | public class OreSpawn { 43 | 44 | @Instance 45 | public static OreSpawn instance; 46 | 47 | public static final Logger LOGGER = LogManager.getLogger(Constants.MODID); 48 | public static final OS3API API = new OS3APIImpl(); 49 | static final EventHandlers eventHandlers = new EventHandlers(); 50 | public static final FeatureRegistry FEATURES = new FeatureRegistry(); 51 | 52 | static final FlatBedrock flatBedrock = new FlatBedrock(); 53 | 54 | @EventHandler 55 | public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { 56 | LOGGER.warn("Invalid fingerprint detected!"); 57 | } 58 | 59 | @EventHandler 60 | public void preInit(final FMLPreInitializationEvent ev) { 61 | Config.loadConfig(); 62 | 63 | PluginLoader.INSTANCE.load(ev); 64 | 65 | if (Config.getBoolean(Constants.FLAT_BEDROCK)) { 66 | GameRegistry.registerWorldGenerator(flatBedrock, 100); 67 | } 68 | 69 | if (Config.getBoolean(Constants.RETROGEN_KEY) 70 | || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) 71 | || Config.getBoolean(Constants.RETRO_BEDROCK)) { 72 | MinecraftForge.EVENT_BUS.register(eventHandlers); 73 | MinecraftForge.ORE_GEN_BUS.register(eventHandlers); 74 | } 75 | } 76 | 77 | @EventHandler 78 | public void init(final FMLInitializationEvent ev) { 79 | PluginLoader.INSTANCE.register(); 80 | 81 | API.loadConfigFiles(); 82 | } 83 | 84 | @EventHandler 85 | public void postInit(final FMLPostInitializationEvent ev) { 86 | Config.saveConfig(); 87 | API.getAllSpawns().entrySet().stream() 88 | .forEach(ent -> { 89 | GameRegistry.registerWorldGenerator(new OreSpawnFeatureGenerator(ent.getValue(), ent.getKey()), 100); 90 | }); 91 | } 92 | 93 | @EventHandler 94 | public void onServerStarting(final FMLServerStartingEvent ev) { 95 | ev.registerServerCommand(new ClearChunkCommand()); 96 | ev.registerServerCommand(new DumpBiomesCommand()); 97 | ev.registerServerCommand(new AddOreCommand()); 98 | ev.registerServerCommand(new WriteConfigsCommand()); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.gson.JsonElement; 5 | import com.mcmoddev.orespawn.util.Collectors2; 6 | 7 | import net.minecraft.world.biome.Biome; 8 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 9 | 10 | public interface BiomeLocation { 11 | 12 | boolean matches(Biome biome); 13 | 14 | JsonElement serialize(); 15 | 16 | default ImmutableList getBiomes() { 17 | return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) 18 | .collect(Collectors2.toImmutableList()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/IBlockList.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.api.os3.IBlockDefinition; 6 | 7 | import net.minecraft.block.state.IBlockState; 8 | 9 | public interface IBlockList { 10 | 11 | void addBlock(IBlockDefinition block); 12 | 13 | IBlockState getRandomBlock(Random rand); 14 | 15 | void startNewSpawn(); 16 | 17 | void dump(); 18 | 19 | int count(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api; 2 | 3 | import com.google.gson.JsonObject; 4 | 5 | public interface IDimensionList { 6 | 7 | JsonObject serialize(); 8 | 9 | default boolean matches(int dimensionId) { 10 | return false; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/IFeature.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api; 2 | 3 | import java.util.Random; 4 | 5 | import com.google.gson.JsonObject; 6 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 7 | 8 | import net.minecraft.util.math.ChunkPos; 9 | import net.minecraft.world.World; 10 | import net.minecraft.world.chunk.IChunkProvider; 11 | import net.minecraft.world.gen.IChunkGenerator; 12 | import net.minecraftforge.registries.IForgeRegistryEntry; 13 | 14 | public interface IFeature extends IForgeRegistryEntry { 15 | 16 | void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, 17 | ISpawnEntry spawn, ChunkPos pos); 18 | 19 | void setRandom(Random rand); 20 | 21 | JsonObject getDefaultParameters(); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | public class BadStateValueException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 3826628238012469423L; 9 | 10 | public BadStateValueException(String msg) { 11 | super(msg); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | import java.util.Locale; 4 | 5 | public class BadValueException extends Exception { 6 | 7 | private static final long serialVersionUID = 1143938140559149506L; 8 | private final String keyName; 9 | private final String keyValue; 10 | 11 | public BadValueException(final String keyName, final String keyValue) { 12 | super(); 13 | this.keyName = keyName; 14 | this.keyValue = keyValue; 15 | } 16 | 17 | @Override 18 | public String getMessage() { 19 | final String baseMessage = super.getMessage(); 20 | return String.format(Locale.ENGLISH, "Unknown value %s for key %s%n%s", this.keyValue, this.keyName, 21 | baseMessage); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | public class MissingVersionException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -4306852267351590384L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | public class NotAProperConfigException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -7748241590958198482L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | public class OldVersionException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 3760017140789193369L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | import java.util.Locale; 4 | 5 | public class UnknownFieldException extends Exception { 6 | 7 | private static final long serialVersionUID = 1L; 8 | private final String message; 9 | 10 | public UnknownFieldException(final String theField) { 11 | super(); 12 | this.message = String.format(Locale.ENGLISH, "Unkown field %s in config", theField); 13 | } 14 | 15 | @Override 16 | public String getMessage() { 17 | final String baseMessage = super.getMessage(); 18 | return String.format(Locale.ENGLISH, "%s%n%s", this.message, baseMessage); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | import java.util.Locale; 4 | 5 | public class UnknownNameException extends Exception { 6 | 7 | private static final long serialVersionUID = -3426121906665390773L; 8 | private final String fieldName; 9 | private final String fieldValue; 10 | 11 | public UnknownNameException(final String fieldName, final String fieldValue) { 12 | super(); 13 | this.fieldName = fieldName; 14 | this.fieldValue = fieldValue; 15 | } 16 | 17 | @Override 18 | public String getMessage() { 19 | final String baseMessage = super.getMessage(); 20 | return String.format(Locale.ENGLISH, "Unknown %s name %s%n%s", this.fieldName, this.fieldValue, 21 | baseMessage); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.exceptions; 2 | 3 | public class UnknownVersionException extends Exception { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 3817238409227005355L; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import com.mcmoddev.orespawn.api.BiomeLocation; 4 | 5 | import net.minecraft.util.ResourceLocation; 6 | import net.minecraft.world.biome.Biome; 7 | 8 | public interface IBiomeBuilder { 9 | 10 | IBiomeBuilder addWhitelistEntry(Biome biome); 11 | 12 | IBiomeBuilder addWhitelistEntry(String biomeName); 13 | 14 | IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); 15 | 16 | IBiomeBuilder addBlacklistEntry(Biome biome); 17 | 18 | IBiomeBuilder addBlacklistEntry(String biomeName); 19 | 20 | IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); 21 | 22 | IBiomeBuilder setAcceptAll(); 23 | 24 | BiomeLocation create(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.state.IBlockState; 5 | import net.minecraft.util.ResourceLocation; 6 | 7 | public interface IBlockBuilder { 8 | 9 | /** 10 | * 11 | * @param blockState 12 | * @return 13 | */ 14 | IBlockBuilder setFromBlockState(IBlockState blockState); 15 | 16 | /** 17 | * 18 | * @param block 19 | * @return 20 | */ 21 | IBlockBuilder setFromBlock(Block block); 22 | 23 | /** 24 | * 25 | * @param blockName 26 | * @return 27 | */ 28 | IBlockBuilder setFromName(String blockName); 29 | 30 | /** 31 | * 32 | * @param blockName 33 | * @param state 34 | * @return 35 | */ 36 | IBlockBuilder setFromName(String blockName, String state); 37 | 38 | /** 39 | * 40 | * @param blockName 41 | * @param metadata 42 | * @return 43 | * @deprecated 44 | */ 45 | @Deprecated 46 | IBlockBuilder setFromName(String blockName, int metadata); 47 | 48 | /** 49 | * 50 | * @param blockResourceLocation 51 | * @return 52 | */ 53 | IBlockBuilder setFromName(ResourceLocation blockResourceLocation); 54 | 55 | /** 56 | * 57 | * @param blockResourceLocation 58 | * @param state 59 | * @return 60 | */ 61 | IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); 62 | 63 | /** 64 | * 65 | * @param blockResourceLocation 66 | * @param metadata 67 | * @return 68 | * @deprecated 69 | */ 70 | @Deprecated 71 | IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); 72 | 73 | /** 74 | * 75 | * @param blockState 76 | * @param chance 77 | * @return 78 | */ 79 | IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); 80 | 81 | /** 82 | * 83 | * @param block 84 | * @param chance 85 | * @return 86 | */ 87 | IBlockBuilder setFromBlockWithChance(Block block, int chance); 88 | 89 | /** 90 | * 91 | * @param blockName 92 | * @param chance 93 | * @return 94 | */ 95 | IBlockBuilder setFromNameWithChance(String blockName, int chance); 96 | 97 | /** 98 | * 99 | * @param blockName 100 | * @param state 101 | * @param chance 102 | * @return 103 | */ 104 | IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); 105 | 106 | /** 107 | * 108 | * @param blockName 109 | * @param metadata 110 | * @param chance 111 | * @return 112 | * @deprecated 113 | */ 114 | @Deprecated 115 | IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); 116 | 117 | /** 118 | * 119 | * @param blockResourceLocation 120 | * @param chance 121 | * @return 122 | */ 123 | IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); 124 | 125 | /** 126 | * 127 | * @param blockResourceLocation 128 | * @param state 129 | * @param chance 130 | * @return 131 | */ 132 | IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, 133 | int chance); 134 | 135 | /** 136 | * 137 | * @param blockResourceLocation 138 | * @param metadata 139 | * @param chance 140 | * @return 141 | * @deprecated 142 | */ 143 | @Deprecated 144 | IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, 145 | int chance); 146 | 147 | /** 148 | * 149 | * @param chance 150 | * @return 151 | */ 152 | IBlockBuilder setChance(int chance); 153 | 154 | /** 155 | * 156 | * @return 157 | */ 158 | IBlockDefinition create(); 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import net.minecraft.block.state.IBlockState; 4 | 5 | public interface IBlockDefinition { 6 | 7 | IBlockState getBlock(); 8 | 9 | int getChance(); 10 | 11 | default boolean isValid() { 12 | return true; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import com.mcmoddev.orespawn.api.IDimensionList; 4 | 5 | public interface IDimensionBuilder { 6 | 7 | IDimensionBuilder addWhitelistEntry(int dimensionID); 8 | 9 | IDimensionBuilder addBlacklistEntry(int dimensionID); 10 | 11 | IDimensionBuilder setAcceptAll(); 12 | 13 | IDimensionBuilder setDenyAll(); 14 | 15 | IDimensionBuilder setAcceptAllOverworld(); 16 | 17 | IDimensionList create(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.mcmoddev.orespawn.api.IFeature; 5 | 6 | import net.minecraft.util.ResourceLocation; 7 | 8 | public interface IFeatureBuilder { 9 | 10 | IFeatureBuilder setFeature(String featureName); 11 | 12 | IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); 13 | 14 | IFeatureBuilder setFeature(IFeature feature); 15 | 16 | IFeatureBuilder setParameter(String parameterName, String parameterValue); 17 | 18 | IFeatureBuilder setParameter(String parameterName, int parameterValue); 19 | 20 | IFeatureBuilder setParameter(String parameterName, float parameterValue); 21 | 22 | IFeatureBuilder setParameter(String parameterName, boolean parameterValue); 23 | 24 | IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); 25 | 26 | IFeatureBuilder setUseFeatureDefaults(); 27 | 28 | IFeatureEntry create(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.mcmoddev.orespawn.api.IFeature; 5 | 6 | public interface IFeatureEntry { 7 | 8 | IFeature getFeature(); 9 | 10 | String getFeatureName(); 11 | 12 | JsonObject getFeatureParameters(); 13 | 14 | void setParameter(String parameterName, String parameterValue); 15 | 16 | void setParameter(String parameterName, int parameterValue); 17 | 18 | void setParameter(String parameterName, boolean parameterValue); 19 | 20 | void setParameter(String parameterName, float parameterValue); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import net.minecraft.block.state.IBlockState; 4 | import net.minecraft.util.ResourceLocation; 5 | 6 | public interface IReplacementBuilder { 7 | 8 | /** 9 | * 10 | * @param entryName 11 | * @return 12 | */ 13 | IReplacementBuilder setFromName(String entryName); 14 | 15 | /** 16 | * 17 | * @param name 18 | * @return 19 | */ 20 | IReplacementBuilder setName(String name); 21 | 22 | /** 23 | * 24 | * @param blockState 25 | * @return 26 | */ 27 | IReplacementBuilder addEntry(IBlockState blockState); 28 | 29 | /** 30 | * 31 | * @param blockName 32 | * @return 33 | */ 34 | IReplacementBuilder addEntry(String blockName); 35 | 36 | /** 37 | * 38 | * @param blockName 39 | * @param state 40 | * @return 41 | */ 42 | IReplacementBuilder addEntry(String blockName, String state); 43 | 44 | /** 45 | * 46 | * @param blockName 47 | * @param metadata 48 | * @return 49 | * @deprecated 50 | */ 51 | @Deprecated 52 | IReplacementBuilder addEntry(String blockName, int metadata); 53 | 54 | /** 55 | * 56 | * @param blockResourceLocation 57 | * @return 58 | */ 59 | IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); 60 | 61 | /** 62 | * 63 | * @param blockResourceLocation 64 | * @param state 65 | * @return 66 | */ 67 | IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); 68 | 69 | /** 70 | * 71 | * @param blockResourceLocation 72 | * @param metadata 73 | * @return 74 | * @deprecated 75 | */ 76 | @Deprecated 77 | IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); 78 | 79 | boolean hasEntries(); 80 | 81 | IReplacementEntry create(); 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import java.util.List; 4 | 5 | import net.minecraft.block.state.IBlockState; 6 | import net.minecraftforge.registries.IForgeRegistryEntry; 7 | 8 | public interface IReplacementEntry extends IForgeRegistryEntry { 9 | 10 | OreSpawnBlockMatcher getMatcher(); 11 | 12 | List getEntries(); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import com.mcmoddev.orespawn.api.BiomeLocation; 4 | import com.mcmoddev.orespawn.api.IDimensionList; 5 | 6 | import net.minecraft.block.Block; 7 | import net.minecraft.block.state.IBlockState; 8 | import net.minecraft.util.ResourceLocation; 9 | 10 | public interface ISpawnBuilder { 11 | 12 | ISpawnBuilder setName(String name); 13 | 14 | ISpawnBuilder setDimensions(IDimensionList dimensions); 15 | 16 | ISpawnBuilder setBiomes(BiomeLocation biomes); 17 | 18 | ISpawnBuilder setEnabled(boolean enabled); 19 | 20 | ISpawnBuilder setRetrogen(boolean retrogen); 21 | 22 | ISpawnBuilder setReplacement(IReplacementEntry replacements); 23 | 24 | ISpawnBuilder setFeature(IFeatureEntry feature); 25 | 26 | ISpawnBuilder addBlock(String blockName); 27 | 28 | ISpawnBuilder addBlock(String blockName, String blockState); 29 | 30 | ISpawnBuilder addBlock(String blockName, int blockMetadata); 31 | 32 | ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); 33 | 34 | ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); 35 | 36 | ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); 37 | 38 | ISpawnBuilder addBlock(Block block); 39 | 40 | ISpawnBuilder addBlock(IBlockState block); 41 | 42 | ISpawnBuilder addBlockWithChance(String blockName, int chance); 43 | 44 | ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); 45 | 46 | ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); 47 | 48 | ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); 49 | 50 | ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, 51 | int chance); 52 | 53 | ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, 54 | int chance); 55 | 56 | ISpawnBuilder addBlockWithChance(Block block, int chance); 57 | 58 | ISpawnBuilder addBlockWithChance(IBlockState block, int chance); 59 | 60 | ISpawnEntry create(); 61 | 62 | ISpawnBuilder addBlock(IBlockDefinition block); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.api.BiomeLocation; 6 | import com.mcmoddev.orespawn.api.IBlockList; 7 | import com.mcmoddev.orespawn.api.IDimensionList; 8 | 9 | import net.minecraft.util.ResourceLocation; 10 | import net.minecraft.util.math.ChunkPos; 11 | import net.minecraft.world.World; 12 | import net.minecraft.world.biome.Biome; 13 | import net.minecraft.world.chunk.IChunkProvider; 14 | import net.minecraft.world.gen.IChunkGenerator; 15 | 16 | public interface ISpawnEntry { 17 | 18 | default boolean isEnabled() { 19 | return false; 20 | } 21 | 22 | default boolean isRetrogen() { 23 | return false; 24 | } 25 | 26 | String getSpawnName(); 27 | 28 | boolean dimensionAllowed(int dimension); 29 | 30 | boolean biomeAllowed(ResourceLocation biomeName); 31 | 32 | boolean biomeAllowed(Biome biome); 33 | 34 | IFeatureEntry getFeature(); 35 | 36 | OreSpawnBlockMatcher getMatcher(); 37 | 38 | IBlockList getBlocks(); 39 | 40 | void generate(Random random, World world, IChunkGenerator chunkGenerator, 41 | IChunkProvider chunkProvider, ChunkPos pos); 42 | 43 | IDimensionList getDimensions(); 44 | 45 | BiomeLocation getBiomes(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import java.nio.file.Path; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.mcmoddev.orespawn.api.IFeature; 8 | import com.mcmoddev.orespawn.data.PresetsStorage; 9 | import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; 10 | 11 | import net.minecraft.block.state.IBlockState; 12 | import net.minecraft.util.ResourceLocation; 13 | 14 | public interface OS3API { 15 | 16 | void addSpawn(ISpawnEntry spawnEntry); 17 | 18 | void addFeature(String featureName, IFeature feature); 19 | 20 | void addReplacement(IReplacementEntry replacementEntry); 21 | 22 | Map getReplacements(); 23 | 24 | IReplacementEntry getReplacement(String replacementName); 25 | 26 | List getSpawns(int dimensionID); 27 | 28 | ISpawnEntry getSpawn(String spawnName); 29 | 30 | Map getAllSpawns(); 31 | 32 | List getDimensionDefaultReplacements(int dimensionID); 33 | 34 | ISpawnBuilder getSpawnBuilder(); 35 | 36 | IDimensionBuilder getDimensionBuilder(); 37 | 38 | IFeatureBuilder getFeatureBuilder(); 39 | 40 | IBlockBuilder getBlockBuilder(); 41 | 42 | IBiomeBuilder getBiomeBuilder(); 43 | 44 | IReplacementBuilder getReplacementBuilder(); 45 | 46 | boolean featureExists(String featureName); 47 | 48 | boolean featureExists(ResourceLocation featureName); 49 | 50 | IFeature getFeature(String featureName); 51 | 52 | IFeature getFeature(ResourceLocation featureName); 53 | 54 | PresetsStorage copyPresets(); 55 | 56 | void loadConfigFiles(); 57 | 58 | boolean hasReplacement(ResourceLocation resourceLocation); 59 | 60 | boolean hasReplacement(String name); 61 | 62 | void mapEntryToFile(Path p, String entryName); 63 | 64 | List getSpawnsForFile(String fileName); 65 | 66 | Map> getSpawnsByFile(); 67 | 68 | void addGenerator(final OreSpawnFeatureGenerator generator); 69 | 70 | List getGenerators(); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | public interface OS3FeatureGenerator { 4 | public ISpawnEntry getSpawnData(); 5 | public String getSpawnName(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.os3; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.function.Predicate; 7 | 8 | import com.google.gson.JsonArray; 9 | import com.google.gson.JsonObject; 10 | import com.mcmoddev.orespawn.data.Constants; 11 | import com.mcmoddev.orespawn.util.StateUtil; 12 | 13 | import net.minecraft.block.state.IBlockState; 14 | import net.minecraft.init.Blocks; 15 | 16 | public class OreSpawnBlockMatcher implements Predicate { 17 | 18 | private final List possibles; 19 | 20 | public OreSpawnBlockMatcher(final IBlockState... matches) { 21 | this.possibles = Arrays.asList(matches); 22 | } 23 | 24 | public OreSpawnBlockMatcher(final List matches) { 25 | this.possibles = new ArrayList<>(); 26 | this.possibles.addAll(matches); 27 | } 28 | 29 | private boolean has(final IBlockState bs) { 30 | return this.possibles.stream().filter(bs::equals).count() > 0; 31 | } 32 | 33 | public boolean test(final IBlockState other) { 34 | return (!other.getBlock().equals(Blocks.AIR)) && this.has(other); 35 | } 36 | 37 | public JsonArray serialize() { 38 | final JsonArray rv = new JsonArray(); 39 | 40 | possibles.stream().forEach(bs -> { 41 | final JsonObject t = new JsonObject(); 42 | t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); 43 | if (!bs.equals(bs.getBlock().getDefaultState())) { 44 | final String state = StateUtil.serializeState(bs); 45 | t.addProperty(Constants.ConfigNames.STATE, state); 46 | } 47 | rv.add(t); 48 | }); 49 | 50 | return rv; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java: -------------------------------------------------------------------------------- 1 | @javax.annotation.ParametersAreNonnullByDefault 2 | package com.mcmoddev.orespawn.api.os3; 3 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.plugin; 2 | 3 | import com.mcmoddev.orespawn.api.os3.OS3API; 4 | 5 | public interface IOreSpawnPlugin { 6 | 7 | void register(OS3API apiInterface); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.plugin; 2 | 3 | import static java.lang.annotation.ElementType.TYPE; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.Target; 8 | 9 | @Retention(RUNTIME) 10 | @Target(TYPE) 11 | public @interface OreSpawnPlugin { 12 | 13 | // the Mod this is for - will be used for 14 | // generating the name of the json the config 15 | // will get saved to and should also be the 16 | // actual mod-id we can use for creating a 17 | // resource location 18 | String modid(); 19 | 20 | // resource location segment to look in 21 | // for registered config files 22 | 23 | String resourcePath() default "orespawn"; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.api.plugin; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.URI; 6 | import java.net.URISyntaxException; 7 | import java.net.URL; 8 | import java.nio.file.FileSystem; 9 | import java.nio.file.FileSystems; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import java.nio.file.Paths; 13 | import java.util.ArrayList; 14 | import java.util.Collections; 15 | import java.util.Iterator; 16 | import java.util.List; 17 | import java.util.Locale; 18 | import java.util.stream.Stream; 19 | 20 | import org.apache.commons.io.FileUtils; 21 | import org.apache.commons.io.FilenameUtils; 22 | import org.apache.commons.io.IOUtils; 23 | 24 | import com.mcmoddev.orespawn.OreSpawn; 25 | import com.mcmoddev.orespawn.data.Config; 26 | import com.mcmoddev.orespawn.data.Constants; 27 | 28 | import net.minecraft.crash.CrashReport; 29 | import net.minecraft.util.ResourceLocation; 30 | import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData; 31 | import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; 32 | 33 | public enum PluginLoader { 34 | 35 | INSTANCE; 36 | 37 | private class PluginData { 38 | 39 | public final String modId; 40 | public final String resourcePath; 41 | public final IOreSpawnPlugin plugin; 42 | 43 | PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { 44 | this.modId = modId; 45 | this.resourcePath = resourcePath; 46 | this.plugin = plugin; 47 | } 48 | } 49 | 50 | private static List dataStore = new ArrayList<>(); 51 | 52 | private String getAnnotationItem(final String item, final ASMData asmData) { 53 | if (asmData.getAnnotationInfo().get(item) != null) { 54 | return asmData.getAnnotationInfo().get(item).toString(); 55 | } else { 56 | return ""; 57 | } 58 | } 59 | 60 | public void load(final FMLPreInitializationEvent event) { 61 | for (final ASMData asmDataItem : event.getAsmData() 62 | .getAll(OreSpawnPlugin.class.getCanonicalName())) { 63 | final String modId = getAnnotationItem("modid", asmDataItem); 64 | final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); 65 | final String clazz = asmDataItem.getClassName(); 66 | IOreSpawnPlugin integration; 67 | 68 | try { 69 | integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); 70 | final PluginData pd = new PluginData(modId, resourceBase, integration); 71 | OreSpawn.LOGGER.info("Loading Integration For {}", modId); 72 | dataStore.add(pd); 73 | } catch (final Exception ex) { 74 | OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); 75 | } 76 | } 77 | } 78 | 79 | public void register() { 80 | dataStore.forEach(pd -> { 81 | scanResources(pd); 82 | pd.plugin.register(OreSpawn.API); 83 | }); 84 | } 85 | 86 | public void scanResources(final PluginData pd) { 87 | if (Config.getKnownMods().contains(pd.modId)) { 88 | return; 89 | } 90 | 91 | final String base = String.format(Locale.ENGLISH, "assets/%s/%s", pd.modId, pd.resourcePath); 92 | final URL resURL = getClass().getClassLoader().getResource(base); 93 | 94 | if (resURL == null) { 95 | OreSpawn.LOGGER.warn("Unable to access file {}: got 'null' when trying to resolve it", 96 | base); 97 | return; 98 | } 99 | 100 | URI uri; 101 | 102 | try { 103 | uri = resURL.toURI(); 104 | } catch (URISyntaxException ex) { 105 | CrashReport report = CrashReport.makeCrashReport(ex, 106 | String.format(Locale.ENGLISH, "Failed to get URI for %s", 107 | (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); 108 | report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); 109 | return; 110 | } 111 | 112 | if (uri.getScheme().equals("jar")) { 113 | try (FileSystem fileSystem = FileSystems.newFileSystem(uri, 114 | Collections.emptyMap())) { 115 | copyout(fileSystem.getPath(base), pd.modId); 116 | } catch (IOException exc) { 117 | CrashReport report = CrashReport.makeCrashReport(exc, String.format( 118 | Locale.ENGLISH, "Failed in getting FileSystem handler set up for %s", uri.getPath())); 119 | report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); 120 | OreSpawn.LOGGER.info(report.getCompleteReport()); 121 | } 122 | } else { 123 | copyout(Paths.get(uri), pd.modId); 124 | } 125 | 126 | Config.addKnownMod(pd.modId); 127 | } 128 | 129 | private void copyout(final Path myPath, final String modId) { 130 | try (Stream walk = Files.walk(myPath, 1)) { 131 | for (final Iterator it = walk.iterator(); it.hasNext();) { 132 | final Path p = it.next(); 133 | final String name = p.getFileName().toString(); 134 | 135 | if ("json".equals(FilenameUtils.getExtension(name))) { 136 | InputStream reader = null; 137 | Path target; 138 | 139 | if ("_features".equals(FilenameUtils.getBaseName(name))) { 140 | target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, 141 | Constants.FileBits.SYSCONF, 142 | String.format(Locale.ENGLISH, "features-%s.json", modId)); 143 | } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { 144 | target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, 145 | Constants.FileBits.SYSCONF, 146 | String.format(Locale.ENGLISH, "replacements-%s.json", modId)); 147 | } else { 148 | target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, 149 | String.format(Locale.ENGLISH, "%s.json", modId)); 150 | } 151 | 152 | if (!target.toFile().exists()) { 153 | reader = Files.newInputStream(p); 154 | FileUtils.copyInputStreamToFile(reader, target.toFile()); 155 | IOUtils.closeQuietly(reader); 156 | } 157 | } 158 | } 159 | } catch (IOException exc) { 160 | CrashReport report = CrashReport.makeCrashReport(exc, String.format( 161 | Locale.ENGLISH, "Faulted while iterating %s for config files or copying them out", myPath)); 162 | report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); 163 | OreSpawn.LOGGER.error(report.getCompleteReport()); 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.commands; 2 | 3 | import org.apache.commons.io.FilenameUtils; 4 | 5 | import com.google.gson.JsonArray; 6 | import com.google.gson.JsonElement; 7 | import com.google.gson.JsonObject; 8 | import com.google.gson.JsonParser; 9 | import com.mcmoddev.orespawn.OreSpawn; 10 | import com.mcmoddev.orespawn.data.Constants.ConfigNames; 11 | import com.mcmoddev.orespawn.json.OreSpawnReader; 12 | import com.mcmoddev.orespawn.json.OreSpawnWriter; 13 | import com.mcmoddev.orespawn.util.StateUtil; 14 | 15 | import net.minecraft.block.Block; 16 | import net.minecraft.block.state.IBlockState; 17 | import net.minecraft.command.CommandBase; 18 | import net.minecraft.command.CommandException; 19 | import net.minecraft.command.ICommand; 20 | import net.minecraft.command.ICommandSender; 21 | import net.minecraft.entity.player.EntityPlayer; 22 | import net.minecraft.item.ItemBlock; 23 | import net.minecraft.item.ItemStack; 24 | import net.minecraft.server.MinecraftServer; 25 | import net.minecraft.util.EnumHand; 26 | 27 | public class AddOreCommand extends CommandBase { 28 | 29 | @Override 30 | public String getName() { 31 | return "addore"; 32 | } 33 | 34 | @Override 35 | public String getUsage(final ICommandSender sender) { 36 | return "/addore "; 37 | } 38 | 39 | @Override 40 | public void execute(final MinecraftServer server, final ICommandSender sender, 41 | final String[] args) throws CommandException { 42 | if (!(sender instanceof EntityPlayer)) { 43 | throw new CommandException("Only players can use this command"); 44 | } 45 | 46 | final EntityPlayer player = (EntityPlayer) sender; 47 | final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); 48 | 49 | if (stack == null) { 50 | throw new CommandException("You have no item in your main hand"); 51 | } else if (!(stack.getItem() instanceof ItemBlock)) { 52 | throw new CommandException("The item in your main hand isn't a block"); 53 | } else if (args.length < 1) { 54 | throw new CommandException(this.getUsage(sender)); 55 | } 56 | 57 | final String file = args[0]; 58 | @SuppressWarnings("deprecation") 59 | final IBlockState state = Block.getBlockFromItem(stack.getItem()) 60 | .getStateFromMeta(stack.getItemDamage()); 61 | 62 | final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); 63 | final JsonParser p = new JsonParser(); 64 | final JsonElement parsed; 65 | if(rawData != null && rawData.length() > 0) { 66 | parsed = mergeDefaults(p.parse(rawData), state); 67 | } else { 68 | parsed = mergeDefaults(p.parse("{}"), state); 69 | } 70 | OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); 71 | OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); 72 | } 73 | 74 | private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { 75 | final JsonObject work = parse.getAsJsonObject(); 76 | final JsonObject emptyBlacklist = new JsonObject(); 77 | emptyBlacklist.add("excludes", new JsonArray()); 78 | 79 | if (!work.has(ConfigNames.ENABLED)) { 80 | work.addProperty(ConfigNames.ENABLED, true); 81 | } 82 | if (!work.has(ConfigNames.RETROGEN)) { 83 | work.addProperty(ConfigNames.RETROGEN, false); 84 | } 85 | if (!work.has(ConfigNames.FEATURE)) { 86 | work.addProperty(ConfigNames.FEATURE, "orespawn:default"); 87 | } 88 | if (!work.has(ConfigNames.REPLACEMENT)) { 89 | work.addProperty(ConfigNames.REPLACEMENT, "orespawn:default"); 90 | } 91 | if (!work.has(ConfigNames.PARAMETERS)) { 92 | work.add(ConfigNames.PARAMETERS, 93 | OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) 94 | .getDefaultParameters()); 95 | } 96 | if (!work.has(ConfigNames.DIMENSIONS)) { 97 | work.add(ConfigNames.DIMENSIONS, emptyBlacklist); 98 | } 99 | if (!work.has(ConfigNames.BIOMES)) { 100 | work.add(ConfigNames.BIOMES, emptyBlacklist); 101 | } 102 | 103 | final JsonObject block = new JsonObject(); 104 | block.addProperty(ConfigNames.CHANCE, 100); 105 | block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); 106 | block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); 107 | final JsonArray blocks = new JsonArray(); 108 | blocks.add(block); 109 | work.add(ConfigNames.BLOCK, blocks); 110 | 111 | return work; 112 | } 113 | 114 | @Override 115 | public int compareTo(final ICommand command) { 116 | return this.getName().compareTo(command.getName()); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.commands; 2 | 3 | import java.util.Arrays; 4 | import java.util.LinkedList; 5 | import java.util.List; 6 | import java.util.stream.Collectors; 7 | 8 | import com.mcmoddev.orespawn.OreSpawn; 9 | 10 | import net.minecraft.block.Block; 11 | import net.minecraft.block.state.IBlockState; 12 | import net.minecraft.command.CommandBase; 13 | import net.minecraft.command.CommandException; 14 | import net.minecraft.command.ICommand; 15 | import net.minecraft.command.ICommandSender; 16 | import net.minecraft.entity.player.EntityPlayer; 17 | import net.minecraft.init.Blocks; 18 | import net.minecraft.item.ItemStack; 19 | import net.minecraft.server.MinecraftServer; 20 | import net.minecraft.util.ResourceLocation; 21 | import net.minecraft.util.math.BlockPos; 22 | import net.minecraft.util.math.ChunkPos; 23 | import net.minecraft.util.text.TextComponentString; 24 | import net.minecraft.world.chunk.Chunk; 25 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 26 | import net.minecraftforge.oredict.OreDictionary; 27 | 28 | public class ClearChunkCommand extends CommandBase { 29 | 30 | private static final String STONE_ID = "minecraft:stone"; 31 | private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", 32 | "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", 33 | "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); 34 | private static final List baseStones = Arrays.asList(STONE_ID, "minecraft:netherrack", 35 | "minecraft:end_stone", "minecraft:cobblestone", "minecraft:obsidian", "minecraft:magma", 36 | "minecraft:soul_sand"); 37 | 38 | private static final List dirtVariants = Arrays.asList("minecraft:dirt", 39 | "minecraft:grass"); 40 | private static final List otherVariants = Arrays.asList("minecraft:gravel", 41 | "minecraft:sand"); 42 | 43 | @Override 44 | public String getName() { 45 | return "clearchunk"; 46 | } 47 | 48 | @Override 49 | public String getUsage(final ICommandSender sender) { 50 | return "/clearchunk "; 51 | } 52 | 53 | @Override 54 | public void execute(final MinecraftServer server, final ICommandSender sender, 55 | final String[] args) throws CommandException { 56 | if (!(sender instanceof EntityPlayer)) { 57 | throw new CommandException("Only players can use this command"); 58 | } 59 | 60 | final EntityPlayer player = (EntityPlayer) sender; 61 | final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); 62 | final ChunkPos chunkPos = chunk.getPos(); 63 | final List blocks; 64 | 65 | final boolean flagClassic = args.length > 0 && args[0].toLowerCase().equalsIgnoreCase("classic"); 66 | 67 | final List blockNames = new LinkedList<>(); 68 | getBlocks(args, blockNames); 69 | 70 | blocks = blockNames.stream() 71 | .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) 72 | .map(Block::getDefaultState).collect(Collectors.toList()); 73 | 74 | blocks.addAll(OreSpawn.API 75 | .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) 76 | .stream().collect(Collectors.toList())); 77 | final List overburden = Arrays 78 | .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", 79 | "minecraft:sandstone", "minecraft:red_sandstone") 80 | .stream() 81 | .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) 82 | .map(Block::getDefaultState).collect(Collectors.toList()); 83 | 84 | clearBlocks(chunkPos, blocks, overburden, flagClassic, player); 85 | 86 | player.sendStatusMessage( 87 | new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); 88 | } 89 | 90 | private void clearBlocks(final ChunkPos chunkPos, final List blocks, 91 | final List overburden, final boolean flagClassic, 92 | final EntityPlayer player) { 93 | for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { 94 | for (int y = 256; y >= 0; y--) { 95 | for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { 96 | final BlockPos pos = new BlockPos(x, y, z); 97 | final IBlockState block = player.getEntityWorld().getBlockState(pos); 98 | removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); 99 | removeIfFluid(pos, player); 100 | } 101 | } 102 | } 103 | } 104 | 105 | private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { 106 | if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { 107 | final IBlockState bs = player.getEntityWorld().getBlockState(pos); 108 | 109 | if (bs.getMaterial().isLiquid()) { 110 | player.getEntityWorld().setBlockToAir(pos); 111 | } 112 | } 113 | } 114 | 115 | private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, 116 | final IBlockState block, final List blocks, 117 | final List overburden, final boolean flagClassic) { 118 | if (blocks.contains(block) 119 | || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { 120 | player.getEntityWorld().setBlockToAir(pos); 121 | } 122 | } 123 | 124 | private void getBlocks(final String[] args, final List blockNames) { 125 | if (args.length > 0) { 126 | switch (args[0].toLowerCase()) { 127 | case "viewores": 128 | blockNames.addAll(stoneVariants); 129 | blockNames.addAll(dirtVariants); 130 | blockNames.addAll(otherVariants); 131 | break; 132 | 133 | case "dirtandgravel": 134 | blockNames.add(STONE_ID); 135 | blockNames.addAll(dirtVariants); 136 | blockNames.addAll(otherVariants); 137 | break; 138 | 139 | case "classic": 140 | blockNames.add(Blocks.STONE.getRegistryName().toString()); 141 | blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); 142 | blockNames.add(Blocks.END_STONE.getRegistryName().toString()); 143 | blockNames 144 | .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) 145 | .map(Block::getBlockFromItem).map(Block::getRegistryName) 146 | .map(ResourceLocation::toString).collect(Collectors.toList())); 147 | break; 148 | 149 | default: 150 | blockNames.addAll(baseStones); 151 | } 152 | } else { 153 | blockNames.addAll(baseStones); 154 | } 155 | } 156 | 157 | @Override 158 | public int compareTo(final ICommand command) { 159 | return this.getName().compareTo(command.getName()); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.commands; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.charset.StandardCharsets; 6 | 7 | import org.apache.commons.io.FileUtils; 8 | import org.apache.commons.lang3.StringEscapeUtils; 9 | 10 | import com.google.gson.Gson; 11 | import com.google.gson.GsonBuilder; 12 | import com.google.gson.JsonArray; 13 | import com.google.gson.JsonPrimitive; 14 | 15 | import net.minecraft.command.CommandBase; 16 | import net.minecraft.command.CommandException; 17 | import net.minecraft.command.ICommand; 18 | import net.minecraft.command.ICommandSender; 19 | import net.minecraft.server.MinecraftServer; 20 | import net.minecraft.util.text.TextComponentString; 21 | import net.minecraft.world.biome.Biome; 22 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 23 | 24 | public class DumpBiomesCommand extends CommandBase { 25 | 26 | @Override 27 | public String getName() { 28 | return "dumpbiomes"; 29 | } 30 | 31 | @Override 32 | public String getUsage(final ICommandSender sender) { 33 | return "/dumpbiomes"; 34 | } 35 | 36 | @Override 37 | public void execute(final MinecraftServer server, final ICommandSender sender, 38 | final String[] args) throws CommandException { 39 | JsonArray array = new JsonArray(); 40 | 41 | for (final Biome biome : ForgeRegistries.BIOMES) { 42 | array.add(new JsonPrimitive(biome.getRegistryName().toString())); 43 | } 44 | 45 | final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 46 | final String json = gson.toJson(array); 47 | 48 | try { 49 | FileUtils.writeStringToFile(new File(".", "biome_dump.json"), 50 | StringEscapeUtils.unescapeJson(json), StandardCharsets.UTF_8); 51 | } catch (final IOException e) { 52 | throw new CommandException("Failed to save the json file"); 53 | } 54 | 55 | sender.sendMessage(new TextComponentString("Done")); 56 | } 57 | 58 | @Override 59 | public int compareTo(final ICommand command) { 60 | return this.getName().compareTo(command.getName()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.commands; 2 | 3 | import com.mcmoddev.orespawn.json.OreSpawnWriter; 4 | 5 | import net.minecraft.command.CommandBase; 6 | import net.minecraft.command.CommandException; 7 | import net.minecraft.command.ICommandSender; 8 | import net.minecraft.server.MinecraftServer; 9 | import net.minecraft.util.text.TextComponentString; 10 | 11 | public class WriteConfigsCommand extends CommandBase { 12 | 13 | @Override 14 | public String getName() { 15 | return "osSaveConfigs"; 16 | } 17 | 18 | @Override 19 | public String getUsage(final ICommandSender sender) { 20 | return "/osSaveConfigs"; 21 | } 22 | 23 | @Override 24 | public void execute(final MinecraftServer server, final ICommandSender sender, 25 | final String[] args) throws CommandException { 26 | sender.sendMessage(new TextComponentString( 27 | "Forcing configs as OreSpawn sees them to be written to disk")); 28 | OreSpawnWriter.saveConfigs(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/data/Config.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.data; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.charset.Charset; 6 | import java.nio.file.FileSystems; 7 | import java.nio.file.Path; 8 | import java.util.ArrayList; 9 | import java.util.HashMap; 10 | import java.util.List; 11 | 12 | import org.apache.commons.io.FileUtils; 13 | 14 | import com.google.common.collect.ImmutableList; 15 | import com.google.gson.Gson; 16 | import com.google.gson.GsonBuilder; 17 | import com.google.gson.JsonArray; 18 | import com.google.gson.JsonParser; 19 | import com.mcmoddev.orespawn.OreSpawn; 20 | 21 | import net.minecraft.crash.CrashReport; 22 | import net.minecraftforge.common.config.Configuration; 23 | 24 | public class Config { 25 | 26 | private static Configuration configuration; 27 | 28 | private Config() { 29 | } 30 | 31 | public static void loadConfig() { 32 | configuration = new Configuration(new File(Constants.CONFIG_FILE)); 33 | 34 | // Load our Boolean Values 35 | boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, 36 | Configuration.CATEGORY_GENERAL, false, 37 | "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); 38 | boolVals.put(Constants.FORCE_RETROGEN_KEY, 39 | configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, 40 | Configuration.CATEGORY_GENERAL, false, 41 | "Force all chunks to retrogen regardless of anything else")); 42 | boolVals.put(Constants.REPLACE_VANILLA_OREGEN, 43 | configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, 44 | Configuration.CATEGORY_GENERAL, false, 45 | "Replace vanilla ore-generation entirely")); 46 | boolVals.put(Constants.FLAT_BEDROCK, 47 | configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, 48 | false, "Flatten the bedrock during world generation")); 49 | boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, 50 | Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); 51 | boolVals.put(Constants.REPLACE_ALL, configuration.getBoolean(Constants.REPLACE_ALL, Configuration.CATEGORY_GENERAL, false, "Replace all ore generation")); 52 | intVals.put(Constants.BEDROCK_LAYERS, 53 | configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, 54 | 4, "How thick should the shell of bedrock be?")); 55 | knownKeys.add(Constants.RETROGEN_KEY); 56 | knownKeys.add(Constants.FORCE_RETROGEN_KEY); 57 | knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); 58 | knownKeys.add(Constants.KNOWN_MODS); 59 | knownKeys.add(Constants.FLAT_BEDROCK); 60 | knownKeys.add(Constants.RETRO_BEDROCK); 61 | knownKeys.add(Constants.BEDROCK_LAYERS); 62 | 63 | loadExtractedConfigs(); 64 | } 65 | 66 | private static void loadExtractedConfigs() { 67 | final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", 68 | "known-configs.json"); 69 | 70 | if (!p.toFile().exists()) { 71 | return; 72 | } 73 | 74 | final File in = p.toFile(); 75 | String rawData; 76 | 77 | try { 78 | rawData = FileUtils.readFileToString(in, Charset.defaultCharset()); 79 | } catch (IOException e) { 80 | return; 81 | } 82 | 83 | if (rawData.isEmpty()) { 84 | return; 85 | } 86 | 87 | final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); 88 | data.forEach(item -> addKnownMod(item.getAsString())); 89 | } 90 | 91 | public static List getKnownMods() { 92 | return ImmutableList.copyOf(extractedConfigs); 93 | } 94 | 95 | public static void addKnownMod(final String modId) { 96 | extractedConfigs.add(modId); 97 | } 98 | 99 | public static boolean getBoolean(final String keyname) { 100 | if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { 101 | return boolVals.get(keyname); 102 | } 103 | 104 | return false; 105 | } 106 | 107 | public static String getString(final String keyname) { 108 | if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { 109 | return stringVals.get(keyname); 110 | } 111 | 112 | return ""; 113 | } 114 | 115 | public static int getInt(final String keyname) { 116 | if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { 117 | return intVals.get(keyname); 118 | } 119 | 120 | return 0; 121 | } 122 | 123 | public static float getFloat(final String keyname) { 124 | if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { 125 | return floatVals.get(keyname); 126 | } 127 | 128 | return 0.0f; 129 | } 130 | 131 | public static void saveConfig() { 132 | if (!extractedConfigs.isEmpty()) { 133 | saveKnownConfigs(); 134 | } 135 | 136 | configuration.save(); 137 | } 138 | 139 | private static void saveKnownConfigs() { 140 | final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 141 | final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", 142 | "known-configs.json"); 143 | 144 | if (!p.toFile().getParentFile().exists()) { 145 | p.toFile().mkdirs(); 146 | } 147 | 148 | final File in = p.toFile(); 149 | 150 | final JsonArray data = new JsonArray(); 151 | 152 | extractedConfigs.forEach(data::add); 153 | 154 | try { 155 | FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); 156 | } catch (final IOException e) { 157 | CrashReport report = CrashReport.makeCrashReport(e, 158 | "Failed saving list of already extracted mod configs"); 159 | report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); 160 | OreSpawn.LOGGER.info(report.getCompleteReport()); 161 | } 162 | } 163 | 164 | private static final HashMap boolVals = new HashMap<>(); 165 | private static final HashMap stringVals = new HashMap<>(); 166 | private static final HashMap intVals = new HashMap<>(); 167 | private static final HashMap floatVals = new HashMap<>(); 168 | private static final List knownKeys = new ArrayList<>(); 169 | private static final List extractedConfigs = new ArrayList<>(); 170 | } 171 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/data/Constants.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.data; 2 | 3 | import java.nio.file.Path; 4 | import java.nio.file.Paths; 5 | 6 | public class Constants { 7 | 8 | public static final String MODID = "orespawn"; 9 | public static final String NAME = "MMD OreSpawn"; 10 | public static final String VERSION = "3.4.0"; 11 | public static final String RETROGEN_KEY = "Retrogen"; 12 | public static final String CONFIG_FILE = "config/orespawn.cfg"; 13 | public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; 14 | public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; 15 | public static final String ORE_TAG = "ores"; 16 | public static final String FEATURES_TAG = "features"; 17 | public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; 18 | public static final String OVERWORLD = "overworld"; 19 | public static final String THE_OVERWORLD = "the overworld"; 20 | public static final String NETHER = "nether"; 21 | public static final String THE_NETHER = "the nether"; 22 | public static final String END = "end"; 23 | public static final String THE_END = "the end"; 24 | public static final String DEFAULT_GEN = "default"; 25 | public static final String VEIN_GEN = "vein"; 26 | public static final String NORMAL_CLOUD = "normal-cloud"; 27 | public static final String CLUSTERS = "clusters"; 28 | public static final String CRASH_SECTION = "OreSpawn Version"; 29 | public static final String KNOWN_MODS = "already-extracted"; 30 | public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; 31 | public static final String FLAT_BEDROCK = "Flatten Bedrock"; 32 | public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; 33 | public static final String BEDROCK_LAYERS = "Bedrock Thickness"; 34 | public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; 35 | public static final String PRECISION = "precision"; 36 | public static final Path CONFDIR = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3); 37 | public static final Path SYSCONF = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3, FileBits.SYSCONF); 38 | public static final String REPLACE_ALL = "Replace All Generation"; 39 | 40 | public final class FormatBits { 41 | 42 | private FormatBits() { 43 | } 44 | 45 | public static final String MAX_SPREAD = "maxSpread"; 46 | public static final String MEDIAN_SIZE = "medianSize"; 47 | public static final String MIN_HEIGHT = "minHeight"; 48 | public static final String MAX_HEIGHT = "maxHeight"; 49 | public static final String VARIATION = "variation"; 50 | public static final String FREQUENCY = "frequency"; 51 | public static final String NODE_SIZE = "size"; 52 | public static final String ATTEMPTS = "attempts"; 53 | public static final String LENGTH = "length"; 54 | public static final String NODE_COUNT = "numObjects"; 55 | public static final String ATTEMPTS_MIN = "minAttempts"; 56 | public static final String ATTEMPTS_MAX = "maxAttempts"; 57 | public static final String STARTINGFACE = "startFacing"; 58 | public static final String FLUID = "fluid"; 59 | } 60 | 61 | public final class FileBits { 62 | 63 | private FileBits() { 64 | } 65 | 66 | public static final String CONFIG_DIR = "config"; 67 | public static final String OS3 = "orespawn3"; 68 | public static final String SYSCONF = "sysconf"; 69 | public static final String PRESETS = "presets.json"; 70 | } 71 | 72 | public final class ConfigNames { 73 | 74 | private ConfigNames() { 75 | } 76 | 77 | public static final String DEFAULT = "default"; 78 | public static final String STATE_NORMAL = "normal"; 79 | public static final String DIMENSIONS = "dimensions"; 80 | public static final String CHANCE = "chance"; 81 | public static final String METADATA = "metaData"; 82 | public static final String BIOMES = "biomes"; 83 | public static final String STATE = "state"; 84 | public static final String REPLACEMENT = "replaces"; 85 | public static final String FEATURE = "feature"; 86 | public static final String PARAMETERS = "parameters"; 87 | public static final String FILE_VERSION = "version"; 88 | public static final String BLOCK = "blocks"; 89 | public static final String SPAWNS = "spawns"; 90 | public static final String RETROGEN = "retrogen"; 91 | public static final String ENABLED = "enabled"; 92 | public static final String NAME = "name"; 93 | public static final String WHITELIST = "includes"; 94 | public static final String BLACKLIST = "excludes"; 95 | public static final String PRESETS = "presets"; 96 | 97 | public final class DefaultFeatureProperties { 98 | 99 | private DefaultFeatureProperties() { 100 | } 101 | 102 | public static final String SIZE = "size"; 103 | public static final String VARIATION = "variation"; 104 | public static final String FREQUENCY = "frequency"; 105 | public static final String MAXHEIGHT = "maxHeight"; 106 | public static final String MINHEIGHT = "minHeight"; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.data; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.lang.reflect.Constructor; 6 | import java.nio.charset.Charset; 7 | import java.nio.charset.StandardCharsets; 8 | import java.util.Collections; 9 | import java.util.Map; 10 | import java.util.TreeMap; 11 | 12 | import org.apache.commons.io.FileUtils; 13 | import org.apache.commons.lang3.StringEscapeUtils; 14 | 15 | import com.google.gson.Gson; 16 | import com.google.gson.GsonBuilder; 17 | import com.google.gson.JsonArray; 18 | import com.google.gson.JsonElement; 19 | import com.google.gson.JsonObject; 20 | import com.google.gson.JsonParser; 21 | import com.mcmoddev.orespawn.OreSpawn; 22 | import com.mcmoddev.orespawn.api.IFeature; 23 | 24 | import net.minecraft.crash.CrashReport; 25 | import net.minecraft.util.ResourceLocation; 26 | import net.minecraftforge.registries.IForgeRegistry; 27 | import net.minecraftforge.registries.RegistryBuilder; 28 | 29 | public class FeatureRegistry { 30 | 31 | private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; 32 | private static final IForgeRegistry registry = new RegistryBuilder() 33 | .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) 34 | .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO 35 | .create(); 36 | 37 | public FeatureRegistry() { 38 | // 39 | } 40 | 41 | public Map getFeatures() { 42 | final Map tempMap = new TreeMap<>(); 43 | registry.getEntries().stream() 44 | .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); 45 | 46 | return Collections.unmodifiableMap(tempMap); 47 | } 48 | 49 | public String getFeatureName(final IFeature feature) { 50 | return feature.getRegistryName().toString(); 51 | } 52 | 53 | public IFeature getFeature(final String name) { 54 | return getFeature(new ResourceLocation(name)); 55 | } 56 | 57 | public IFeature getFeature(final ResourceLocation featureResourceLocation) { 58 | final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); 59 | if (registry.containsKey(featureResourceLocation)) { 60 | return registry.getValue(featureResourceLocation); 61 | } else { 62 | return registry.getValue(defaultGen); 63 | } 64 | } 65 | 66 | public boolean hasFeature(final String name) { 67 | return hasFeature(new ResourceLocation(name)); 68 | } 69 | 70 | public boolean hasFeature(final ResourceLocation featureResourceLocation) { 71 | return registry.containsKey(featureResourceLocation); 72 | } 73 | 74 | public boolean hasFeature(final IFeature feature) { 75 | return registry.containsKey(feature.getRegistryName()); 76 | } 77 | 78 | public void addFeature(final String name, final IFeature feature) { 79 | feature.setRegistryName(new ResourceLocation("orespawn", name)); 80 | registry.register(feature); 81 | } 82 | 83 | public void addFeature(final JsonObject entry) { 84 | addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); 85 | } 86 | 87 | public void addFeature(final String name, final String className) { 88 | final IFeature feature = getInstance(className); 89 | 90 | if (feature != null && !hasFeature(name)) { 91 | addFeature(name, feature); 92 | } 93 | } 94 | 95 | private static IFeature getInstance(final String className) { 96 | Class featureClazz; 97 | Constructor featureCons; 98 | IFeature feature; 99 | 100 | try { 101 | featureClazz = Class.forName(className); 102 | featureCons = featureClazz.getConstructor(); 103 | feature = (IFeature) featureCons.newInstance(); 104 | } catch (final Exception e) { 105 | final CrashReport report = CrashReport.makeCrashReport(e, 106 | "Failed to load and instantiate an instance of the feature generator named " 107 | + className + " that was specified as a feature generator"); 108 | report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); 109 | OreSpawn.LOGGER.info(report.getCompleteReport()); 110 | return null; 111 | } 112 | 113 | return feature; 114 | } 115 | 116 | public void loadFeaturesFile(final File file) { 117 | final JsonParser parser = new JsonParser(); 118 | String rawJson; 119 | JsonArray elements; 120 | 121 | try { 122 | rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); 123 | } catch (final IOException e) { 124 | final CrashReport report = CrashReport.makeCrashReport(e, 125 | "Failed reading config " + file.getName()); 126 | report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); 127 | OreSpawn.LOGGER.info(report.getCompleteReport()); 128 | return; 129 | } 130 | 131 | elements = parser.parse(rawJson).getAsJsonArray(); 132 | 133 | for (final JsonElement elem : elements) { 134 | addFeature(elem.getAsJsonObject()); 135 | } 136 | } 137 | 138 | public void writeFeatures(final File file) { 139 | final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 140 | 141 | final JsonArray root = new JsonArray(); 142 | 143 | registry.getEntries().stream().map(ent -> { 144 | final JsonObject e = new JsonObject(); 145 | e.addProperty("name", ent.getKey().getPath()); 146 | e.addProperty("class", ent.getValue().getClass().getName()); 147 | return e; 148 | }).forEach(root::add); 149 | 150 | final String json = gson.toJson(root); 151 | 152 | try { 153 | FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), 154 | StandardCharsets.UTF_8); 155 | } catch (final IOException e) { 156 | final CrashReport report = CrashReport.makeCrashReport(e, 157 | "Failed writing config " + file.getName()); 158 | report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); 159 | OreSpawn.LOGGER.info(report.getCompleteReport()); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.data; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.TreeMap; 10 | import java.util.regex.Matcher; 11 | import java.util.regex.Pattern; 12 | 13 | import com.google.gson.JsonElement; 14 | import com.google.gson.JsonIOException; 15 | import com.google.gson.JsonParser; 16 | import com.google.gson.JsonPrimitive; 17 | import com.google.gson.JsonSyntaxException; 18 | import com.mcmoddev.orespawn.OreSpawn; 19 | 20 | import net.minecraft.crash.CrashReport; 21 | 22 | public class PresetsStorage { 23 | 24 | private final Map> storage; 25 | private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; 26 | 27 | public PresetsStorage() { 28 | storage = new TreeMap<>(); 29 | } 30 | 31 | public void setSymbolSection(final String sectionName, final String itemName, 32 | final JsonElement value) { 33 | final Map temp = storage.getOrDefault(sectionName, 34 | new HashMap()); 35 | temp.put(itemName, value); 36 | storage.put(sectionName, temp); 37 | } 38 | 39 | public JsonElement getSymbolSection(final String sectionName, final String itemName) { 40 | if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { 41 | return storage.get(sectionName).get(itemName); 42 | } else { 43 | return new JsonPrimitive(itemName); 44 | } 45 | } 46 | 47 | public void copy(final PresetsStorage dest) { 48 | storage.entrySet().stream().forEach(ensm -> { 49 | final String section = ensm.getKey(); 50 | ensm.getValue().entrySet().forEach( 51 | ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); 52 | }); 53 | } 54 | 55 | public void clear() { 56 | this.storage.clear(); 57 | } 58 | 59 | public void load(final Path inputFile) { 60 | final JsonParser p = new JsonParser(); 61 | JsonElement parsed = null; 62 | 63 | try (BufferedReader r = Files.newBufferedReader(inputFile)) { 64 | parsed = p.parse(r); 65 | } catch (final IOException e) { 66 | CrashReport report = CrashReport.makeCrashReport(e, 67 | "Failed reading presets from" + inputFile.toString()); 68 | report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); 69 | OreSpawn.LOGGER.info(report.getCompleteReport()); 70 | } catch (final JsonIOException | JsonSyntaxException e) { 71 | CrashReport report = CrashReport.makeCrashReport(e, 72 | "JSON Parsing Error in " + inputFile.toString()); 73 | report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); 74 | OreSpawn.LOGGER.info(report.getCompleteReport()); 75 | } 76 | 77 | if (parsed != null) { 78 | parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { 79 | final String section = entry.getKey(); 80 | entry.getValue().getAsJsonObject().entrySet().stream().forEach( 81 | sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); 82 | }); 83 | } 84 | } 85 | 86 | public JsonElement get(final String asString) { 87 | final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); 88 | final Matcher m = p.matcher(asString); 89 | if (m.matches()) { 90 | return this.getSymbolSection(m.group(1), m.group(2)); 91 | } 92 | return new JsonPrimitive("Unknown Variable " + asString); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.data; 2 | 3 | import com.mcmoddev.orespawn.api.os3.OS3API; 4 | import com.mcmoddev.orespawn.api.plugin.IOreSpawnPlugin; 5 | import com.mcmoddev.orespawn.api.plugin.OreSpawnPlugin; 6 | 7 | @OreSpawnPlugin(modid = "orespawn", resourcePath = "configs") 8 | public class VanillaOres implements IOreSpawnPlugin { 9 | 10 | @Override 11 | public void register(final OS3API apiInterface) { 12 | // nothing for us to do - all of our ores are in the 13 | // jar and the code handles that 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.features; 2 | 3 | import java.util.Random; 4 | 5 | import com.google.gson.JsonObject; 6 | import com.mcmoddev.orespawn.OreSpawn; 7 | import com.mcmoddev.orespawn.api.FeatureBase; 8 | import com.mcmoddev.orespawn.api.IFeature; 9 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 10 | import com.mcmoddev.orespawn.data.Constants; 11 | 12 | import net.minecraft.block.state.IBlockState; 13 | import net.minecraft.util.math.BlockPos; 14 | import net.minecraft.util.math.ChunkPos; 15 | import net.minecraft.util.math.Vec3i; 16 | import net.minecraft.world.World; 17 | import net.minecraft.world.chunk.IChunkProvider; 18 | import net.minecraft.world.gen.IChunkGenerator; 19 | 20 | public class ClusterGenerator extends FeatureBase implements IFeature { 21 | 22 | private ClusterGenerator(final Random rand) { 23 | super(rand); 24 | } 25 | 26 | public ClusterGenerator() { 27 | this(new Random()); 28 | } 29 | 30 | private class SpawnParameters { 31 | public final int clusterSize; 32 | public final int variance; 33 | public final int clusterCount; 34 | public final int maxSpread; 35 | public final int minHeight; 36 | public final int maxHeight; 37 | 38 | SpawnParameters(final int clusterSize, final int variance, final int clusterCount, 39 | final int maxSpread, final int minHeight, final int maxHeight) { 40 | this.clusterSize = clusterSize; 41 | this.variance = variance; 42 | this.clusterCount = clusterCount; 43 | this.maxSpread = maxSpread; 44 | this.minHeight = minHeight; 45 | this.maxHeight = maxHeight; 46 | } 47 | } 48 | @Override 49 | public void generate(final World world, final IChunkGenerator chunkGenerator, 50 | final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos posIn) { 51 | final ChunkPos pos = posIn; 52 | final JsonObject params = spawnData.getFeature().getFeatureParameters(); 53 | 54 | // First, load cached blocks for neighboring chunk ore spawns 55 | final int chunkX = pos.x; 56 | final int chunkZ = pos.z; 57 | 58 | mergeDefaults(params, getDefaultParameters()); 59 | 60 | runCache(chunkX, chunkZ, world, spawnData); 61 | 62 | // now to ore spawn 63 | 64 | final int blockX = chunkX * 16 + 8; 65 | final int blockZ = chunkZ * 16 + 8; 66 | 67 | final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); 68 | final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); 69 | final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); 70 | final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); 71 | final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); 72 | final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); 73 | final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); 74 | final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); 75 | final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); 76 | 77 | int tries; 78 | 79 | if (triesMax == triesMin) { 80 | tries = triesMax; 81 | } else { 82 | tries = random.nextInt(triesMax - triesMin) + triesMin; 83 | } 84 | 85 | while (tries > 0) { 86 | if (this.random.nextInt(100) <= frequency) { 87 | final int xRand = random.nextInt(16); 88 | final int zRand = random.nextInt(16); 89 | 90 | final int x = blockX + xRand - (maxSpread / 2); 91 | final int y = random.nextInt(maxHeight - minHeight) + minHeight; 92 | final int z = blockZ + zRand - (maxSpread / 2); 93 | 94 | spawnCluster(new SpawnParameters(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight), 95 | spawnData, world, new BlockPos(x, y, z)); 96 | } 97 | 98 | tries--; 99 | } 100 | } 101 | 102 | private void spawnCluster(final SpawnParameters params, 103 | final ISpawnEntry spawnData, final World world, final BlockPos pos) { 104 | // spawn a cluster at the center, then a bunch around the outside... 105 | int r = params.clusterSize - params.variance; 106 | 107 | if (params.variance > 0) { 108 | r += this.random.nextInt(2 * params.variance) - params.variance; 109 | } 110 | 111 | spawnChunk(world, pos, spawnData, r); 112 | 113 | int count = this.random.nextInt(params.clusterCount - 1); // always at least the first, but vary 114 | // inside that 115 | 116 | if (params.variance > 0) { 117 | count += this.random.nextInt(2 * params.variance) - params.variance; 118 | } 119 | 120 | while (count >= 0) { 121 | r = params.clusterSize - params.variance; 122 | 123 | if (params.variance > 0) { 124 | r += this.random.nextInt(2 * params.variance) - params.variance; 125 | } 126 | 127 | final int radius = params.maxSpread / 2; 128 | 129 | final int xp = getPoint(-radius, radius, 0); 130 | final int yp = getPoint(params.minHeight, params.maxHeight, (params.maxHeight - params.minHeight) / 2); 131 | final int zp = getPoint(-radius, radius, 0); 132 | 133 | final BlockPos p = pos.add(xp, yp, zp); 134 | spawnChunk(world, p, spawnData, r); 135 | 136 | count -= r; 137 | } 138 | } 139 | 140 | private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, 141 | final int quantity) { 142 | int count = quantity; 143 | final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; 144 | final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; 145 | final Vec3i[] offs = new Vec3i[lutType]; 146 | 147 | System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); 148 | 149 | final int dimension = world.provider.getDimension(); 150 | 151 | if (quantity < 27) { 152 | final int[] scrambledLUT = new int[lutType]; 153 | System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); 154 | scramble(scrambledLUT, this.random); 155 | int z = 0; 156 | 157 | while (count > 0) { 158 | final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); 159 | if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; 160 | 161 | if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, 162 | spawnData)) { 163 | count++; 164 | z++; 165 | scramble(scrambledLUT, this.random); // rescramble the LUT 166 | } else { 167 | z = 0; 168 | } 169 | 170 | if (z > 5) { 171 | count--; 172 | z = 0; 173 | OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); 174 | } 175 | } 176 | 177 | return; 178 | } 179 | 180 | doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); 181 | } 182 | 183 | private void doSpawnFill(final boolean nextBoolean, final int quantity, 184 | final ISpawnEntry spawnData, final World world, final BlockPos pos) { 185 | final int count = quantity; 186 | final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; 187 | final int rSqr = (int) (radius * radius); 188 | if (nextBoolean) { 189 | spawnMungeNE(world, pos, rSqr, radius, spawnData, count); 190 | } else { 191 | spawnMungeSW(world, pos, rSqr, radius, spawnData, count); 192 | } 193 | } 194 | 195 | @Override 196 | public void setRandom(final Random rand) { 197 | this.random = rand; 198 | } 199 | 200 | @Override 201 | public JsonObject getDefaultParameters() { 202 | final JsonObject defParams = new JsonObject(); 203 | defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); 204 | defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); 205 | defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); 206 | defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); 207 | defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); 208 | defParams.addProperty(Constants.FormatBits.VARIATION, 4); 209 | defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); 210 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); 211 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); 212 | return defParams; 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.features; 2 | 3 | import java.util.Random; 4 | 5 | import com.google.gson.JsonObject; 6 | import com.mcmoddev.orespawn.api.FeatureBase; 7 | import com.mcmoddev.orespawn.api.IFeature; 8 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 9 | import com.mcmoddev.orespawn.data.Constants; 10 | 11 | import net.minecraft.block.state.IBlockState; 12 | import net.minecraft.util.math.BlockPos; 13 | import net.minecraft.util.math.ChunkPos; 14 | import net.minecraft.util.math.Vec3i; 15 | import net.minecraft.world.World; 16 | import net.minecraft.world.chunk.IChunkProvider; 17 | import net.minecraft.world.gen.IChunkGenerator; 18 | 19 | public class DefaultFeatureGenerator extends FeatureBase implements IFeature { 20 | 21 | public DefaultFeatureGenerator() { 22 | super(new Random()); 23 | } 24 | 25 | @Override 26 | public void generate(final World world, final IChunkGenerator chunkGenerator, 27 | final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { 28 | final ChunkPos pos = chunkPos; 29 | final JsonObject params = spawnData.getFeature().getFeatureParameters(); 30 | 31 | // First, load cached blocks for neighboring chunk ore spawns 32 | final int chunkX = pos.x; 33 | final int chunkZ = pos.z; 34 | 35 | mergeDefaults(params, getDefaultParameters()); 36 | 37 | runCache(chunkX, chunkZ, world, spawnData); 38 | 39 | // now to ore spawn 40 | 41 | final int blockX = chunkX * 16 + 8; 42 | final int blockZ = chunkZ * 16 + 8; 43 | 44 | final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); 45 | final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); 46 | final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); 47 | final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); 48 | final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); 49 | 50 | if (freq >= 1) { 51 | for (int i = 0; i < freq; i++) { 52 | final int x = blockX + random.nextInt(16); 53 | final int y = random.nextInt(maxY - minY) + minY; 54 | final int z = blockZ + random.nextInt(16); 55 | 56 | final int r; 57 | 58 | if (vari > 0) { 59 | r = random.nextInt(2 * vari) - vari; 60 | } else { 61 | r = 0; 62 | } 63 | spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); 64 | } 65 | } else if (random.nextFloat() < freq) { 66 | final int x = blockX + random.nextInt(8); 67 | final int y = random.nextInt(maxY - minY) + minY; 68 | final int z = blockZ + random.nextInt(8); 69 | final int r; 70 | 71 | if (vari > 0) { 72 | r = random.nextInt(2 * vari) - vari; 73 | } else { 74 | r = 0; 75 | } 76 | 77 | spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); 78 | } 79 | 80 | } 81 | 82 | private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, 83 | final int quantity) { 84 | int count = quantity; 85 | final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; 86 | final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; 87 | final Vec3i[] offs = new Vec3i[lutType]; 88 | 89 | System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); 90 | 91 | if (quantity < 27) { 92 | final int[] scrambledLUT = new int[lutType]; 93 | System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); 94 | scramble(scrambledLUT, this.random); 95 | 96 | while (count > 0) { 97 | final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); 98 | if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; 99 | final BlockPos target = pos.add(offs[scrambledLUT[--count]]); 100 | spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); 101 | } 102 | 103 | return; 104 | } 105 | 106 | doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); 107 | } 108 | 109 | private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, 110 | final ISpawnEntry spawnData, final BlockPos pos) { 111 | final int count = quantity; 112 | final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; 113 | final int rSqr = (int) (radius * radius); 114 | if (nextBoolean) { 115 | spawnMungeNE(world, pos, rSqr, radius, spawnData, count); 116 | } else { 117 | spawnMungeSW(world, pos, rSqr, radius, spawnData, count); 118 | } 119 | } 120 | 121 | @Override 122 | public JsonObject getDefaultParameters() { 123 | final JsonObject defParams = new JsonObject(); 124 | defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); 125 | defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); 126 | defParams.addProperty(Constants.FormatBits.VARIATION, 16); 127 | defParams.addProperty(Constants.FormatBits.FREQUENCY, 0.5); 128 | defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); 129 | return defParams; 130 | } 131 | 132 | @Override 133 | public void setRandom(final Random rand) { 134 | this.random = rand; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.features; 2 | 3 | import java.util.Random; 4 | 5 | import com.google.gson.JsonObject; 6 | import com.mcmoddev.orespawn.OreSpawn; 7 | import com.mcmoddev.orespawn.api.FeatureBase; 8 | import com.mcmoddev.orespawn.api.IFeature; 9 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 10 | import com.mcmoddev.orespawn.data.Constants; 11 | 12 | import net.minecraft.util.math.BlockPos; 13 | import net.minecraft.util.math.ChunkPos; 14 | import net.minecraft.world.World; 15 | import net.minecraft.world.chunk.IChunkProvider; 16 | import net.minecraft.world.gen.IChunkGenerator; 17 | 18 | public class NormalCloudGenerator extends FeatureBase implements IFeature { 19 | 20 | private NormalCloudGenerator(final Random rand) { 21 | super(rand); 22 | } 23 | 24 | public NormalCloudGenerator() { 25 | this(new Random()); 26 | } 27 | 28 | @Override 29 | public void generate(final World world, final IChunkGenerator chunkGenerator, 30 | final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { 31 | final ChunkPos pos = chunkPos; 32 | final JsonObject params = spawnData.getFeature().getFeatureParameters(); 33 | 34 | // First, load cached blocks for neighboring chunk ore spawns 35 | final int chunkX = pos.x; 36 | final int chunkZ = pos.z; 37 | 38 | mergeDefaults(params, getDefaultParameters()); 39 | 40 | runCache(chunkX, chunkZ, world, spawnData); 41 | 42 | // now to ore spawn 43 | 44 | // lets not offset blind, 45 | final int blockX = chunkX * 16; 46 | final int blockZ = chunkZ * 16; 47 | 48 | final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); 49 | final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); 50 | final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); 51 | final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); 52 | final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); 53 | int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); 54 | final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); 55 | final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); 56 | 57 | // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get 58 | // a size that will let us insert by the radius 59 | final int offsetXZ = 32 - maxSpread; 60 | 61 | // you have the distance between minHeight and maxHeight 62 | // this is the actual size of the space 63 | final int sizeY = (maxHeight - minHeight); 64 | final int offsetY = sizeY - maxSpread; 65 | final int radiusXZ = offsetXZ / 2; 66 | 67 | // actual radius for placement is the size minus the spread to center it in the space and 68 | // keep 69 | // from overflowing 70 | final int radiusY = offsetY / 2; 71 | 72 | // we center at the minimum plus the half the height 73 | final int blockY = minHeight + (sizeY / 2); 74 | 75 | final int fSave = frequency; 76 | int tryCount = 0; 77 | 78 | int tries; 79 | 80 | if (triesMax == triesMin) { 81 | tries = triesMax; 82 | } else { 83 | tries = random.nextInt(triesMax - triesMin) + triesMin; 84 | } 85 | 86 | while (tries > 0) { 87 | if (this.random.nextInt(100) <= frequency) { 88 | frequency = fSave; 89 | final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; 90 | // this should, hopefully, keep us centered between minHeight and maxHeight with 91 | // nothing going above/below those values 92 | final int y = blockY + getPoint(0, offsetY, radiusY); 93 | final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; 94 | 95 | int r = medianSize - variance; 96 | 97 | if (variance > 0) { 98 | r += random.nextInt(2 * variance) - variance; 99 | } 100 | 101 | final BlockPos p = new BlockPos(x, y, z); 102 | 103 | if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) 104 | && tryCount < 5) { 105 | // make another try! 106 | tries++; 107 | frequency = 100; 108 | tryCount++; 109 | } else { 110 | tryCount = 0; 111 | } 112 | } 113 | 114 | tries--; 115 | } 116 | } 117 | 118 | private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, 119 | final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, 120 | final World world) { 121 | // spawn one right at the center here, then generate for the cloud and do the math 122 | 123 | if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, 124 | world.provider.getDimension(), true, spawnData)) { 125 | return false; 126 | } 127 | 128 | final int radius = maxSpread / 2; 129 | boolean alreadySpewed = false; 130 | int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); 131 | 132 | while (count > 0) { 133 | int xp = getPoint(0, maxSpread, radius); 134 | int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); 135 | int zp = getPoint(0, maxSpread, radius); 136 | 137 | BlockPos p = pos.add(xp, yp, zp); 138 | 139 | int z = 0; 140 | 141 | while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, 142 | world.provider.getDimension(), true, spawnData)) { 143 | xp = getPoint(0, maxSpread, radius); 144 | yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); 145 | zp = getPoint(0, maxSpread, radius); 146 | 147 | p = pos.add(xp, yp, zp); 148 | 149 | z++; 150 | } 151 | 152 | if (z >= 5 && !alreadySpewed) { 153 | OreSpawn.LOGGER.info( 154 | "unable to achieve requested cloud density for cloud centered at %s", pos); 155 | alreadySpewed = true; 156 | } 157 | 158 | count--; 159 | } 160 | 161 | return true; 162 | } 163 | 164 | @Override 165 | public void setRandom(final Random rand) { 166 | this.random = rand; 167 | } 168 | 169 | @Override 170 | public JsonObject getDefaultParameters() { 171 | final JsonObject defParams = new JsonObject(); 172 | defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); 173 | defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); 174 | defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); 175 | defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); 176 | defParams.addProperty(Constants.FormatBits.VARIATION, 4); 177 | defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); 178 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); 179 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); 180 | return defParams; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.mcmoddev.orespawn.impl.features; 5 | 6 | import java.util.Random; 7 | import java.util.Set; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | import java.util.stream.StreamSupport; 11 | import java.util.stream.Collectors; 12 | 13 | import com.google.gson.JsonObject; 14 | import com.mcmoddev.orespawn.api.FeatureBase; 15 | import com.mcmoddev.orespawn.api.IFeature; 16 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 17 | import com.mcmoddev.orespawn.data.Constants; 18 | 19 | import net.minecraft.block.Block; 20 | import net.minecraft.block.state.IBlockState; 21 | import net.minecraft.util.math.BlockPos; 22 | import net.minecraft.util.math.ChunkPos; 23 | import net.minecraft.util.math.Vec3i; 24 | import net.minecraft.world.World; 25 | import net.minecraft.world.chunk.Chunk; 26 | import net.minecraft.world.chunk.IChunkProvider; 27 | import net.minecraft.world.gen.IChunkGenerator; 28 | import net.minecraftforge.fluids.Fluid; 29 | import net.minecraftforge.fluids.FluidRegistry; 30 | 31 | /** 32 | * @author Daniel Hazelton 33 | * 34 | */ 35 | public class UnderFluid extends FeatureBase implements IFeature { 36 | 37 | public UnderFluid() { 38 | super(new Random()); 39 | } 40 | 41 | /** 42 | * Try to generate this feature to the specified parameters in the specified chunk. 43 | *
44 | *

Theory: 45 | *

For up to 2*maximum_tries pick a random spot in the spawn zone do: 46 | *

Check the 5x5x5 region around that spot for the fluid: 47 | *

if found, store the BlockPos of the fluid, if this store has reached maximum_tries entries, stop iteration 48 | *

For each of the found positions, if any, seek up and down from the position to find the lower bound of the fluid 49 | *

At the fluids lower bound, generate the node. 50 | *

51 | * 52 | * @param world {@link net.minecraft.world.World} World this chunk is in 53 | * @param chunkGenerator {@link net.minecraft.world.gen.IChunkGenerator} Chunk generator for this chunk 54 | * @param chunkProvider {@link net.minecraft.world.chunk.IChunkProvider} Chunk provider for this chunk 55 | * @param spawnData {@link com.mcmoddev.orespawn.api.os3.ISpawnEntry} Parameters and data on this spawn from the configuration file 56 | * @param chunkPos {@link net.minecraft.util.math.ChunkPos} Absolute in-world coordinates, on the chunk grid, for this chunk (can get lowest value X/Z block coordinates for this chunk by multiplying provided X/Z by 16) 57 | * @see com.mcmoddev.orespawn.api.IFeature#generate(net.minecraft.world.World, net.minecraft.world.gen.IChunkGenerator, net.minecraft.world.chunk.IChunkProvider, com.mcmoddev.orespawn.api.os3.ISpawnEntry, net.minecraft.util.math.ChunkPos) 58 | */ 59 | @Override 60 | public void generate(final World world, final IChunkGenerator chunkGenerator, 61 | final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { 62 | final ChunkPos pos = chunkPos; 63 | final JsonObject params = spawnData.getFeature().getFeatureParameters(); 64 | 65 | // First, load cached blocks for neighboring chunk ore spawns 66 | final int chunkX = pos.x; 67 | final int chunkZ = pos.z; 68 | 69 | mergeDefaults(params, getDefaultParameters()); 70 | 71 | runCache(chunkX, chunkZ, world, spawnData); 72 | 73 | // now to ore spawn 74 | 75 | final int blockX = chunkX * 16 + 8; 76 | final int blockZ = chunkZ * 16 + 8; 77 | 78 | 79 | final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); 80 | final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); 81 | final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); 82 | final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); 83 | final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); 84 | final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); 85 | final Fluid fluid = FluidRegistry.getFluid(params.get(Constants.FormatBits.FLUID).getAsString()); 86 | 87 | int tries = this.random.nextInt(triesMax - triesMin + 1) + triesMin; 88 | int ySpan = maxHeight - minHeight; 89 | int surveySize = ((256 * (16 * ySpan)) / 4) / 125; 90 | BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); 91 | Block fluidBlock = fluid.getBlock(); 92 | 93 | Set found = new HashSet<>(); 94 | 95 | int surveyCount = 0; 96 | int spawnCount = 0; 97 | 98 | while(surveyCount < surveySize && spawnCount < tries) { 99 | BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); 100 | BlockPos lowSide = sampleCenter.add(-2,-2,-2); 101 | BlockPos highSide = sampleCenter.add(2,2,2); 102 | Chunk chunk = world.getChunk(sampleCenter); 103 | 104 | if(!found.contains(sampleCenter)) { 105 | found.addAll(findPossibleTargets(chunk, lowSide, highSide, fluidBlock, minHeight)); 106 | 107 | if(!found.isEmpty()) { 108 | BlockPos target = found.toArray(new BlockPos[0])[this.random.nextInt(found.size())]; 109 | spawnCount += maybeSpawn(target, minHeight, maxHeight, nodeSize, variance, world, spawnData); 110 | } 111 | surveyCount++; 112 | } 113 | } 114 | } 115 | 116 | private int maybeSpawn(BlockPos target, int minHeight, int maxHeight, int nodeSize, 117 | int variance, World world, ISpawnEntry spawnData) { 118 | BlockPos mp = target; 119 | while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { 120 | mp = mp.down(); 121 | } 122 | 123 | if (mp.getY() > minHeight && mp.getY() < maxHeight) { 124 | // calculate actual size for this node 125 | int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); 126 | // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... 127 | // so... we copy vanilla spawn logic, to a degree, I think 128 | spawnOre(world, spawnData, mp, size); 129 | return 1; 130 | } 131 | 132 | 133 | return 0; 134 | } 135 | 136 | private List findPossibleTargets(Chunk chunk, BlockPos lowSide, BlockPos highSide, 137 | Block fluidBlock, int minHeight) { 138 | return StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) 139 | .filter( bp -> chunk.getBlockState(bp).getMaterial().isLiquid() && 140 | chunk.getBlockState(bp).getBlock().equals(fluidBlock) && 141 | bp.getY() >= minHeight ) 142 | .map(BlockPos.MutableBlockPos::toImmutable) 143 | .collect(Collectors.toList()); 144 | } 145 | 146 | private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, 147 | final int quantity) { 148 | int count = quantity; 149 | final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; 150 | final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; 151 | final Vec3i[] offs = new Vec3i[lutType]; 152 | 153 | System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); 154 | 155 | if (quantity < 27) { 156 | final int[] scrambledLUT = new int[lutType]; 157 | System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); 158 | scramble(scrambledLUT, this.random); 159 | 160 | while (count > 0) { 161 | final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); 162 | if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; 163 | final BlockPos target = pos.add(offs[scrambledLUT[--count]]); 164 | spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); 165 | } 166 | 167 | return; 168 | } 169 | 170 | doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); 171 | } 172 | 173 | private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, 174 | final ISpawnEntry spawnData, final BlockPos pos) { 175 | final int count = quantity; 176 | final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; 177 | final int rSqr = (int) (radius * radius); 178 | if (nextBoolean) { 179 | spawnMungeNE(world, pos, rSqr, radius, spawnData, count); 180 | } else { 181 | spawnMungeSW(world, pos, rSqr, radius, spawnData, count); 182 | } 183 | } 184 | 185 | /* (non-Javadoc) 186 | * @see com.mcmoddev.orespawn.api.IFeature#setRandom(java.util.Random) 187 | */ 188 | @Override 189 | public void setRandom(Random rand) { 190 | this.random = rand; 191 | } 192 | 193 | /* (non-Javadoc) 194 | * @see com.mcmoddev.orespawn.api.IFeature#getDefaultParameters() 195 | */ 196 | @Override 197 | public JsonObject getDefaultParameters() { 198 | final JsonObject defParams = new JsonObject(); 199 | defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); 200 | defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); 201 | defParams.addProperty(Constants.FormatBits.VARIATION, 16); 202 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); 203 | defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); 204 | defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); 205 | defParams.addProperty(Constants.FormatBits.FLUID, "water"); 206 | return defParams; 207 | } 208 | 209 | } 210 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonElement; 5 | import com.google.gson.JsonObject; 6 | import com.mcmoddev.orespawn.api.BiomeLocation; 7 | import com.mcmoddev.orespawn.data.Constants.ConfigNames; 8 | 9 | import net.minecraft.world.biome.Biome; 10 | 11 | public class BiomeLocationAcceptAny implements BiomeLocation { 12 | 13 | @Override 14 | public boolean matches(final Biome biome) { 15 | return true; 16 | } 17 | 18 | @Override 19 | public JsonElement serialize() { 20 | final JsonObject rv = new JsonObject(); 21 | rv.add(ConfigNames.BLACKLIST, new JsonArray()); 22 | return rv; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | import com.google.common.collect.ImmutableList; 8 | import com.google.gson.JsonElement; 9 | import com.google.gson.JsonObject; 10 | import com.mcmoddev.orespawn.api.BiomeLocation; 11 | import com.mcmoddev.orespawn.data.Constants; 12 | 13 | import net.minecraft.world.biome.Biome; 14 | 15 | public final class BiomeLocationComposition implements BiomeLocation { 16 | 17 | private final BiomeLocation inclusions; 18 | 19 | private final BiomeLocation exclusions; 20 | 21 | private final int hash; 22 | 23 | public BiomeLocationComposition(final BiomeLocation inclusions, 24 | final BiomeLocation exclusions) { 25 | this.inclusions = inclusions; 26 | this.exclusions = exclusions; 27 | this.hash = Objects.hash(inclusions, exclusions); 28 | } 29 | 30 | @Override 31 | public boolean matches(final Biome biome) { 32 | final boolean inWhite = this.inclusions.matches(biome); 33 | final boolean inBlack = this.exclusions.matches(biome); 34 | 35 | return !inBlack && inWhite; 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return this.hash; 41 | } 42 | 43 | @Override 44 | public boolean equals(final Object obj) { 45 | if (obj == this) { 46 | return true; 47 | } 48 | 49 | if (obj instanceof BiomeLocationComposition) { 50 | final BiomeLocationComposition other = (BiomeLocationComposition) obj; 51 | return this.inclusions.equals(other.inclusions) 52 | && this.exclusions.equals(other.exclusions); 53 | } 54 | 55 | return false; 56 | } 57 | 58 | @Override 59 | public ImmutableList getBiomes() { 60 | final List temp = new LinkedList<>(); 61 | temp.addAll(this.inclusions.getBiomes()); 62 | temp.addAll(this.exclusions.getBiomes()); 63 | return ImmutableList.copyOf(temp); 64 | } 65 | 66 | public BiomeLocation getInclusions() { 67 | return this.inclusions; 68 | } 69 | 70 | public BiomeLocation getExclusions() { 71 | return this.exclusions; 72 | } 73 | 74 | @Override 75 | public JsonElement serialize() { 76 | final JsonObject rv = new JsonObject(); 77 | 78 | rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); 79 | if (!(this.inclusions instanceof BiomeLocationEmpty)) { 80 | rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); 81 | } 82 | 83 | return rv; 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.gson.JsonElement; 5 | import com.google.gson.JsonPrimitive; 6 | import com.mcmoddev.orespawn.api.BiomeLocation; 7 | 8 | import net.minecraft.world.biome.Biome; 9 | import net.minecraftforge.common.BiomeDictionary; 10 | 11 | public final class BiomeLocationDictionary implements BiomeLocation { 12 | 13 | private final BiomeDictionary.Type type; 14 | 15 | private final int hash; 16 | 17 | public BiomeLocationDictionary(final BiomeDictionary.Type type) { 18 | this.type = type; 19 | this.hash = type.hashCode(); 20 | } 21 | 22 | @Override 23 | public boolean matches(final Biome biome) { 24 | return BiomeDictionary.hasType(biome, this.type); 25 | } 26 | 27 | @Override 28 | public int hashCode() { 29 | return this.hash; 30 | } 31 | 32 | @Override 33 | public boolean equals(final Object obj) { 34 | return (obj == this) || ((obj instanceof BiomeLocationDictionary) 35 | && this.type.equals(((BiomeLocationDictionary) obj).type)); 36 | } 37 | 38 | public BiomeDictionary.Type getType() { 39 | return this.type; 40 | } 41 | 42 | @Override 43 | public ImmutableList getBiomes() { 44 | return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); 45 | } 46 | 47 | @Override 48 | public JsonElement serialize() { 49 | return new JsonPrimitive(this.type.toString().toUpperCase()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonElement; 5 | import com.mcmoddev.orespawn.api.BiomeLocation; 6 | 7 | import net.minecraft.world.biome.Biome; 8 | 9 | public class BiomeLocationEmpty implements BiomeLocation { 10 | 11 | @Override 12 | public boolean matches(final Biome biome) { 13 | return false; 14 | } 15 | 16 | @Override 17 | public JsonElement serialize() { 18 | return new JsonArray(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import com.google.common.collect.ImmutableList; 7 | import com.google.common.collect.ImmutableSet; 8 | import com.google.gson.JsonArray; 9 | import com.google.gson.JsonElement; 10 | import com.mcmoddev.orespawn.api.BiomeLocation; 11 | 12 | import net.minecraft.world.biome.Biome; 13 | 14 | public final class BiomeLocationList implements BiomeLocation { 15 | 16 | private final ImmutableSet locations; 17 | 18 | private final int hash; 19 | 20 | public BiomeLocationList(final ImmutableSet locations) { 21 | this.locations = locations; 22 | this.hash = locations.hashCode(); 23 | } 24 | 25 | @Override 26 | public boolean matches(final Biome biome) { 27 | return this.locations.stream().anyMatch(loc -> loc.matches(biome)); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return this.hash; 33 | } 34 | 35 | @Override 36 | public boolean equals(final Object obj) { 37 | return (obj == this) || ((obj instanceof BiomeLocationList) 38 | && this.locations.equals(((BiomeLocationList) obj).locations)); 39 | } 40 | 41 | @Override 42 | public ImmutableList getBiomes() { 43 | final List temp = new LinkedList<>(); 44 | locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); 45 | return ImmutableList.copyOf(temp); 46 | } 47 | 48 | public ImmutableSet getLocations() { 49 | return this.locations; 50 | } 51 | 52 | @Override 53 | public JsonElement serialize() { 54 | final JsonArray rv = new JsonArray(); 55 | this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) 56 | .forEach(bl -> rv.add(bl.serialize())); 57 | 58 | return rv; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.location; 2 | 3 | import com.google.common.collect.ImmutableList; 4 | import com.google.gson.JsonElement; 5 | import com.google.gson.JsonPrimitive; 6 | import com.mcmoddev.orespawn.api.BiomeLocation; 7 | 8 | import net.minecraft.world.biome.Biome; 9 | 10 | public final class BiomeLocationSingle implements BiomeLocation { 11 | 12 | private final Biome biome; 13 | 14 | private final int hash; 15 | 16 | public BiomeLocationSingle(final Biome biome) { 17 | this.biome = biome; 18 | this.hash = biome.hashCode(); 19 | } 20 | 21 | @Override 22 | public boolean matches(final Biome biome) { 23 | return this.biome.equals(biome); 24 | } 25 | 26 | @Override 27 | public ImmutableList getBiomes() { 28 | return ImmutableList.of(this.biome); 29 | } 30 | 31 | @Override 32 | public int hashCode() { 33 | return this.hash; 34 | } 35 | 36 | @Override 37 | public boolean equals(final Object obj) { 38 | return (obj == this) || ((obj instanceof BiomeLocationSingle) 39 | && this.biome.equals(((BiomeLocationSingle) obj).biome)); 40 | } 41 | 42 | public Biome getBiome() { 43 | return this.biome; 44 | } 45 | 46 | @Override 47 | public JsonElement serialize() { 48 | return new JsonPrimitive(this.biome.getRegistryName().toString()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.stream.Collectors; 6 | 7 | import com.google.common.collect.ImmutableSet; 8 | import com.mcmoddev.orespawn.api.BiomeLocation; 9 | import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; 10 | import com.mcmoddev.orespawn.impl.location.BiomeLocationAcceptAny; 11 | import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; 12 | import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; 13 | import com.mcmoddev.orespawn.impl.location.BiomeLocationList; 14 | import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; 15 | 16 | import net.minecraft.util.ResourceLocation; 17 | import net.minecraft.world.biome.Biome; 18 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 19 | 20 | public class BiomeBuilder implements IBiomeBuilder { 21 | 22 | private final List whitelist = new LinkedList<>(); 23 | private final List blacklist = new LinkedList<>(); 24 | 25 | private boolean acceptAll = false; 26 | 27 | public BiomeBuilder() { 28 | // 29 | } 30 | 31 | @Override 32 | public IBiomeBuilder addWhitelistEntry(final Biome biome) { 33 | this.whitelist.add(biome); 34 | return this; 35 | } 36 | 37 | @Override 38 | public IBiomeBuilder addWhitelistEntry(final String biomeName) { 39 | return this.addWhitelistEntry(new ResourceLocation(biomeName)); 40 | } 41 | 42 | @Override 43 | public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { 44 | return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); 45 | } 46 | 47 | @Override 48 | public IBiomeBuilder addBlacklistEntry(final Biome biome) { 49 | this.blacklist.add(biome); 50 | return this; 51 | } 52 | 53 | @Override 54 | public IBiomeBuilder addBlacklistEntry(final String biomeName) { 55 | return this.addBlacklistEntry(new ResourceLocation(biomeName)); 56 | } 57 | 58 | @Override 59 | public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { 60 | return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); 61 | } 62 | 63 | @Override 64 | public IBiomeBuilder setAcceptAll() { 65 | this.acceptAll = true; 66 | return this; 67 | } 68 | 69 | @Override 70 | public BiomeLocation create() { 71 | if (this.acceptAll) { 72 | return new BiomeLocationAcceptAny(); 73 | } 74 | 75 | BiomeLocation whitelistI; 76 | BiomeLocation blacklistI; 77 | if (this.whitelist.isEmpty()) { 78 | if (!this.blacklist.isEmpty()) { 79 | whitelistI = new BiomeLocationAcceptAny(); 80 | } else { 81 | whitelistI = new BiomeLocationEmpty(); 82 | } 83 | } else { 84 | whitelistI = new BiomeLocationList(ImmutableSet.copyOf( 85 | this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) 86 | .collect(Collectors.toList()))); 87 | } 88 | 89 | if (this.blacklist.isEmpty()) { 90 | blacklistI = new BiomeLocationEmpty(); 91 | } else { 92 | blacklistI = new BiomeLocationList(ImmutableSet.copyOf( 93 | this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) 94 | .collect(Collectors.toList()))); 95 | } 96 | 97 | return new BiomeLocationComposition(whitelistI, blacklistI); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.mcmoddev.orespawn.OreSpawn; 4 | import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; 5 | import com.mcmoddev.orespawn.api.os3.IBlockBuilder; 6 | import com.mcmoddev.orespawn.api.os3.IBlockDefinition; 7 | import com.mcmoddev.orespawn.util.StateUtil; 8 | 9 | import net.minecraft.block.Block; 10 | import net.minecraft.block.state.IBlockState; 11 | import net.minecraft.util.ResourceLocation; 12 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 13 | 14 | public class BlockBuilder implements IBlockBuilder { 15 | 16 | private IBlockState blockState; 17 | private int chance; 18 | private boolean isValid = true; 19 | 20 | public BlockBuilder() { 21 | // nothing to do here 22 | } 23 | 24 | @Override 25 | public IBlockBuilder setFromBlockState(final IBlockState blockState) { 26 | final ResourceLocation key = blockState.getBlock().getRegistryName(); 27 | if (!ForgeRegistries.BLOCKS.containsKey(key)) { 28 | this.isValid = false; 29 | } 30 | return this.setFromBlockStateWithChance(blockState, 100); 31 | } 32 | 33 | @Override 34 | public IBlockBuilder setFromBlock(final Block block) { 35 | final ResourceLocation key = block.getRegistryName(); 36 | if (!ForgeRegistries.BLOCKS.containsKey(key)) { 37 | this.isValid = false; 38 | } 39 | return this.setFromBlockState(block.getDefaultState()); 40 | } 41 | 42 | @Override 43 | public IBlockBuilder setFromName(final String blockName) { 44 | return this.setFromName(new ResourceLocation(blockName)); 45 | } 46 | 47 | @Override 48 | public IBlockBuilder setFromName(final String blockName, final String state) { 49 | return this.setFromName(new ResourceLocation(blockName), state); 50 | } 51 | 52 | @Override 53 | public IBlockBuilder setFromName(final String blockName, final int metadata) { 54 | return this.setFromName(new ResourceLocation(blockName), metadata); 55 | } 56 | 57 | @Override 58 | public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { 59 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 60 | this.isValid = false; 61 | } 62 | return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); 63 | } 64 | 65 | @Override 66 | public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, 67 | final String state) { 68 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 69 | this.isValid = false; 70 | } 71 | final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); 72 | try { 73 | return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); 74 | } catch (BadStateValueException e) { 75 | StringBuilder p = new StringBuilder(); 76 | for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); 77 | OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); 78 | return this; 79 | } 80 | } 81 | 82 | /** 83 | * 84 | * @deprecated 85 | */ 86 | @Override 87 | @Deprecated 88 | public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, 89 | final int metadata) { 90 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 91 | this.isValid = false; 92 | } 93 | final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); 94 | return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); 95 | } 96 | 97 | @Override 98 | public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, 99 | final int chance) { 100 | final ResourceLocation key = blockState.getBlock().getRegistryName(); 101 | if (!ForgeRegistries.BLOCKS.containsKey(key)) { 102 | this.isValid = false; 103 | } 104 | this.blockState = blockState; 105 | this.chance = chance; 106 | return this; 107 | } 108 | 109 | @Override 110 | public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { 111 | final ResourceLocation key = block.getRegistryName(); 112 | if (!ForgeRegistries.BLOCKS.containsKey(key)) { 113 | this.isValid = false; 114 | } 115 | return this.setFromBlockStateWithChance(block.getDefaultState(), chance); 116 | } 117 | 118 | @Override 119 | public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { 120 | return this.setFromNameWithChance(new ResourceLocation(blockName), chance); 121 | } 122 | 123 | @Override 124 | public IBlockBuilder setFromNameWithChance(final String blockName, final String state, 125 | final int chance) { 126 | return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); 127 | } 128 | 129 | @Override 130 | public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, 131 | final int chance) { 132 | return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); 133 | } 134 | 135 | @Override 136 | public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, 137 | final int chance) { 138 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 139 | this.isValid = false; 140 | } 141 | return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), 142 | chance); 143 | } 144 | 145 | @Override 146 | public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, 147 | final String state, final int chance) { 148 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 149 | this.isValid = false; 150 | } 151 | final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); 152 | try { 153 | return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), 154 | chance); 155 | } catch (BadStateValueException e) { 156 | StringBuilder p = new StringBuilder(); 157 | for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%d)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); 158 | OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); 159 | return this; 160 | } 161 | } 162 | 163 | /** 164 | * 165 | * @deprecated 166 | */ 167 | @Override 168 | @Deprecated 169 | public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, 170 | final int metadata, final int chance) { 171 | if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { 172 | this.isValid = false; 173 | } 174 | final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); 175 | return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); 176 | } 177 | 178 | @Override 179 | public IBlockBuilder setChance(final int chance) { 180 | this.chance = chance; 181 | return this; 182 | } 183 | 184 | @Override 185 | public IBlockDefinition create() { 186 | return new BlockDefinition(this.blockState, this.chance, this.isValid); 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.mcmoddev.orespawn.api.os3.IBlockDefinition; 4 | 5 | import net.minecraft.block.state.IBlockState; 6 | 7 | public class BlockDefinition implements IBlockDefinition { 8 | 9 | private final IBlockState blockState; 10 | private final int blockChance; 11 | private final boolean isValid; 12 | 13 | public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { 14 | this.blockState = blockState; 15 | this.blockChance = chance; 16 | this.isValid = isValid; 17 | } 18 | 19 | @Override 20 | public IBlockState getBlock() { 21 | return this.blockState; 22 | } 23 | 24 | @Override 25 | public int getChance() { 26 | return this.blockChance; 27 | } 28 | 29 | @Override 30 | public boolean isValid() { 31 | return this.isValid; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Random; 6 | 7 | import com.mcmoddev.orespawn.OreSpawn; 8 | import com.mcmoddev.orespawn.api.IBlockList; 9 | import com.mcmoddev.orespawn.api.os3.IBlockDefinition; 10 | 11 | import net.minecraft.block.state.IBlockState; 12 | 13 | public class BlockList implements IBlockList { 14 | 15 | private final List myBlocks; 16 | private final List workingList; 17 | 18 | public BlockList() { 19 | this.myBlocks = new LinkedList<>(); 20 | this.workingList = new LinkedList<>(); 21 | } 22 | 23 | @Override 24 | public void addBlock(final IBlockDefinition block) { 25 | this.myBlocks.add(block); 26 | } 27 | 28 | @Override 29 | public IBlockState getRandomBlock(final Random rand) { 30 | if (this.workingList.isEmpty()) { 31 | this.startNewSpawn(); 32 | if (this.workingList.isEmpty()) { 33 | return net.minecraft.init.Blocks.AIR.getDefaultState(); 34 | } 35 | } 36 | 37 | final int spot = rand.nextInt(this.workingList.size()); 38 | final IBlockState rv = this.workingList.get(spot); 39 | this.workingList.remove(spot); 40 | return rv; 41 | } 42 | 43 | @Override 44 | public void startNewSpawn() { 45 | this.workingList.clear(); 46 | 47 | this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { 48 | for (int i = 0; i < b.getChance(); i++) { 49 | this.workingList.add(b.getBlock()); 50 | } 51 | }); 52 | } 53 | 54 | @Override 55 | public void dump() { 56 | this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( 57 | bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); 58 | } 59 | 60 | @Override 61 | public int count() { 62 | return this.myBlocks.size(); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | import com.mcmoddev.orespawn.api.IDimensionList; 7 | import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; 8 | 9 | public class DimensionBuilder implements IDimensionBuilder { 10 | 11 | private final List dimensionWhitelist = new LinkedList<>(); 12 | private final List dimensionBlacklist = new LinkedList<>(); 13 | private boolean acceptAll = false; 14 | private boolean denyAll = false; 15 | private boolean acceptAllOverworld = true; 16 | 17 | public DimensionBuilder() { 18 | // 19 | } 20 | 21 | @Override 22 | public IDimensionBuilder addWhitelistEntry(final int dimensionID) { 23 | this.acceptAllOverworld = false; 24 | this.dimensionWhitelist.add(dimensionID); 25 | return this; 26 | } 27 | 28 | @Override 29 | public IDimensionBuilder addBlacklistEntry(final int dimensionID) { 30 | this.acceptAllOverworld = false; 31 | this.dimensionBlacklist.add(dimensionID); 32 | return this; 33 | } 34 | 35 | @Override 36 | public IDimensionBuilder setAcceptAll() { 37 | if (this.denyAll) { 38 | this.denyAll = false; 39 | } 40 | this.acceptAll = true; 41 | return this; 42 | } 43 | 44 | @Override 45 | public IDimensionBuilder setDenyAll() { 46 | if (this.acceptAll) { 47 | this.acceptAll = false; 48 | } 49 | this.denyAll = true; 50 | return this; 51 | } 52 | 53 | @Override 54 | public IDimensionList create() { 55 | if (this.acceptAll 56 | || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) 57 | && !(this.acceptAllOverworld)) { 58 | return new DimensionListAcceptAll(); 59 | } else if (this.denyAll) { 60 | return new DimensionListDenyAll(); 61 | } else if (this.acceptAllOverworld) { 62 | return new DimensionListAcceptAllOverworld(); 63 | } else { 64 | return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); 65 | } 66 | } 67 | 68 | @Override 69 | public IDimensionBuilder setAcceptAllOverworld() { 70 | this.acceptAll = false; 71 | this.denyAll = false; 72 | this.acceptAllOverworld = true; 73 | return this; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.google.gson.JsonArray; 7 | import com.google.gson.JsonObject; 8 | import com.mcmoddev.orespawn.data.Constants; 9 | 10 | public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { 11 | 12 | private final List whitelist = new ArrayList<>(); 13 | private final List blacklist = new ArrayList<>(); 14 | 15 | public DimensionList(final List whitelist, final List blacklist) { 16 | this.whitelist.addAll(whitelist); 17 | this.blacklist.addAll(blacklist); 18 | } 19 | 20 | @Override 21 | public boolean matches(final int dimensionID) { 22 | if (this.whitelist.contains(Integer.valueOf(dimensionID))) { 23 | return true; 24 | } 25 | if (this.blacklist.contains(Integer.valueOf(dimensionID))) { 26 | return false; 27 | } 28 | if (!this.whitelist.isEmpty()) { 29 | return false; 30 | } 31 | if (!this.blacklist.isEmpty()) { 32 | return true; 33 | } 34 | 35 | // if it gets here, the whitelist and blacklist are empty... 36 | // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... 37 | return true; 38 | } 39 | 40 | @Override 41 | public JsonObject serialize() { 42 | final JsonObject rv = new JsonObject(); 43 | if (!this.whitelist.isEmpty()) { 44 | final JsonArray wl = new JsonArray(); 45 | whitelist.stream().forEach(wl::add); 46 | rv.add(Constants.ConfigNames.WHITELIST, wl); 47 | } 48 | 49 | if (!this.blacklist.isEmpty()) { 50 | final JsonArray bl = new JsonArray(); 51 | blacklist.stream().forEach(bl::add); 52 | rv.add(Constants.ConfigNames.WHITELIST, bl); 53 | } else if (this.whitelist.isEmpty()) { 54 | return new DimensionListAcceptAllOverworld().serialize(); 55 | } 56 | 57 | return rv; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonObject; 5 | import com.mcmoddev.orespawn.api.IDimensionList; 6 | import com.mcmoddev.orespawn.data.Constants.ConfigNames; 7 | 8 | public class DimensionListAcceptAll implements IDimensionList { 9 | 10 | @Override 11 | public boolean matches(final int dimensionID) { 12 | return true; 13 | } 14 | 15 | @Override 16 | public JsonObject serialize() { 17 | final JsonObject rv = new JsonObject(); 18 | rv.add(ConfigNames.BLACKLIST, new JsonArray()); 19 | return rv; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonObject; 5 | import com.mcmoddev.orespawn.api.IDimensionList; 6 | import com.mcmoddev.orespawn.data.Constants; 7 | 8 | public class DimensionListAcceptAllOverworld implements IDimensionList { 9 | 10 | @Override 11 | public boolean matches(final int dimensionID) { 12 | return dimensionID != -1 && dimensionID != 1; 13 | } 14 | 15 | @Override 16 | public JsonObject serialize() { 17 | final JsonObject rv = new JsonObject(); 18 | final JsonArray bl = new JsonArray(); 19 | bl.add(-1); 20 | bl.add(1); 21 | rv.add(Constants.ConfigNames.BLACKLIST, bl); 22 | 23 | return rv; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.google.gson.JsonArray; 4 | import com.google.gson.JsonObject; 5 | import com.mcmoddev.orespawn.api.IDimensionList; 6 | import com.mcmoddev.orespawn.data.Constants; 7 | 8 | public class DimensionListDenyAll implements IDimensionList { 9 | 10 | @Override 11 | public boolean matches(final int dimensionID) { 12 | return false; 13 | } 14 | 15 | @Override 16 | public JsonObject serialize() { 17 | final JsonObject rv = new JsonObject(); 18 | rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); 19 | 20 | return rv; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.Locale; 4 | 5 | import com.google.gson.JsonElement; 6 | import com.google.gson.JsonObject; 7 | import com.mcmoddev.orespawn.OreSpawn; 8 | import com.mcmoddev.orespawn.api.IFeature; 9 | import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; 10 | import com.mcmoddev.orespawn.api.os3.IFeatureEntry; 11 | 12 | import net.minecraft.util.ResourceLocation; 13 | 14 | public class FeatureBuilder implements IFeatureBuilder { 15 | 16 | private IFeature feature; 17 | private JsonObject parameters; 18 | private boolean useDefaults; 19 | 20 | public FeatureBuilder() { 21 | this.useDefaults = false; 22 | this.parameters = new JsonObject(); 23 | } 24 | 25 | @Override 26 | public IFeatureBuilder setFeature(final String featureName) { 27 | String actName = featureName; 28 | if (!actName.contains(":")) { 29 | actName = String.format(Locale.ENGLISH, "orespawn:%s", featureName); 30 | } 31 | return this.setFeature(new ResourceLocation(actName)); 32 | } 33 | 34 | @Override 35 | public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { 36 | if (!OreSpawn.API.featureExists(featureResourceLocation)) { 37 | OreSpawn.LOGGER.warn( 38 | "Feature %s is not known, feature for this will be set to the default feature", 39 | featureResourceLocation.getPath()); 40 | } 41 | return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); 42 | } 43 | 44 | @Override 45 | public IFeatureBuilder setFeature(final IFeature feature) { 46 | this.feature = feature; 47 | return this; 48 | } 49 | 50 | @Override 51 | public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { 52 | this.parameters.addProperty(parameterName, parameterValue); 53 | return this; 54 | } 55 | 56 | @Override 57 | public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { 58 | this.parameters.addProperty(parameterName, parameterValue); 59 | return this; 60 | } 61 | 62 | @Override 63 | public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { 64 | this.parameters.addProperty(parameterName, parameterValue); 65 | return this; 66 | } 67 | 68 | @Override 69 | public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { 70 | this.parameters.addProperty(parameterName, parameterValue); 71 | return this; 72 | } 73 | 74 | @Override 75 | public IFeatureBuilder setParameter(final String parameterName, 76 | final JsonElement parameterValue) { 77 | this.parameters.add(parameterName, parameterValue); 78 | return this; 79 | } 80 | 81 | private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, 82 | final FeatureEntry feat) { 83 | if (parameterValue.getAsJsonPrimitive().isBoolean()) { 84 | feat.setParameter(parameterName, parameterValue.getAsBoolean()); 85 | } else if (parameterValue.getAsJsonPrimitive().isString()) { 86 | feat.setParameter(parameterName, parameterValue.getAsString()); 87 | } else { 88 | float paramAsFloat = parameterValue.getAsFloat(); 89 | if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { 90 | feat.setParameter(parameterName, parameterValue.getAsFloat()); 91 | } else { 92 | feat.setParameter(parameterName, parameterValue.getAsInt()); 93 | } 94 | } 95 | } 96 | 97 | @Override 98 | public IFeatureBuilder setUseFeatureDefaults() { 99 | this.useDefaults = true; 100 | return this; 101 | } 102 | 103 | @Override 104 | public IFeatureEntry create() { 105 | final FeatureEntry res = new FeatureEntry(this.feature); 106 | if (!this.useDefaults) { 107 | // only copy in the parameters we need 108 | this.feature.getDefaultParameters().entrySet().stream() 109 | .filter(ent -> !this.parameters.has(ent.getKey())) 110 | .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); 111 | } else { 112 | // overwrite - they've said to just use the defaults 113 | this.feature.getDefaultParameters().entrySet().stream() 114 | .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); 115 | } 116 | 117 | this.parameters.entrySet().stream() 118 | .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); 119 | 120 | return res; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.mcmoddev.orespawn.api.IFeature; 5 | import com.mcmoddev.orespawn.api.os3.IFeatureEntry; 6 | 7 | public class FeatureEntry implements IFeatureEntry { 8 | 9 | private final IFeature feature; 10 | private final JsonObject parameters; 11 | 12 | public FeatureEntry(final IFeature feature) { 13 | this.feature = feature; 14 | this.parameters = new JsonObject(); 15 | } 16 | 17 | @Override 18 | public IFeature getFeature() { 19 | return this.feature; 20 | } 21 | 22 | @Override 23 | public String getFeatureName() { 24 | return this.feature.getRegistryName().getPath(); 25 | } 26 | 27 | @Override 28 | public JsonObject getFeatureParameters() { 29 | final JsonObject defs = feature.getDefaultParameters(); 30 | this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); 31 | return defs; 32 | } 33 | 34 | @Override 35 | public void setParameter(final String parameterName, final String parameterValue) { 36 | this.parameters.addProperty(parameterName, parameterValue); 37 | } 38 | 39 | @Override 40 | public void setParameter(final String parameterName, final int parameterValue) { 41 | this.parameters.addProperty(parameterName, parameterValue); 42 | } 43 | 44 | @Override 45 | public void setParameter(final String parameterName, final boolean parameterValue) { 46 | this.parameters.addProperty(parameterName, parameterValue); 47 | } 48 | 49 | @Override 50 | public void setParameter(final String parameterName, final float parameterValue) { 51 | this.parameters.addProperty(parameterName, parameterValue); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | import java.util.Locale; 6 | 7 | import org.apache.commons.lang3.RandomStringUtils; 8 | 9 | import com.mcmoddev.orespawn.OreSpawn; 10 | import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; 11 | import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; 12 | import com.mcmoddev.orespawn.api.os3.IReplacementEntry; 13 | import com.mcmoddev.orespawn.util.StateUtil; 14 | 15 | import net.minecraft.block.state.IBlockState; 16 | import net.minecraft.util.ResourceLocation; 17 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 18 | 19 | public class ReplacementBuilder implements IReplacementBuilder { 20 | 21 | private String replacementName = null; 22 | private List entries; 23 | 24 | public ReplacementBuilder() { 25 | this.entries = new LinkedList<>(); 26 | } 27 | 28 | @Override 29 | public IReplacementBuilder setFromName(final String entryName) { 30 | this.replacementName = entryName; 31 | this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); 32 | return this; 33 | } 34 | 35 | @Override 36 | public IReplacementBuilder setName(final String name) { 37 | this.replacementName = name; 38 | return this; 39 | } 40 | 41 | @Override 42 | public IReplacementBuilder addEntry(final IBlockState blockState) { 43 | this.entries.add(blockState); 44 | return this; 45 | } 46 | 47 | @Override 48 | public IReplacementBuilder addEntry(final String blockName) { 49 | return this.addEntry(new ResourceLocation(blockName)); 50 | } 51 | 52 | @Override 53 | public IReplacementBuilder addEntry(final String blockName, final String state) { 54 | return this.addEntry(new ResourceLocation(blockName), state); 55 | } 56 | 57 | /** 58 | * 59 | * @deprecated 60 | */ 61 | @Override 62 | @Deprecated 63 | public IReplacementBuilder addEntry(final String blockName, final int metadata) { 64 | return this.addEntry(new ResourceLocation(blockName), metadata); 65 | } 66 | 67 | @Override 68 | public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { 69 | return this 70 | .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); 71 | } 72 | 73 | @Override 74 | public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, 75 | final String state) { 76 | try { 77 | return this.addEntry(StateUtil 78 | .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); 79 | } catch (BadStateValueException e) { 80 | StringBuilder p = new StringBuilder(); 81 | for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); 82 | OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); 83 | return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); 84 | } 85 | } 86 | 87 | /** 88 | * 89 | * @deprecated 90 | */ 91 | @Override 92 | @Deprecated 93 | public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, 94 | final int metadata) { 95 | return this.addEntry( 96 | ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); 97 | } 98 | 99 | @Override 100 | public boolean hasEntries() { 101 | return !this.entries.isEmpty(); 102 | } 103 | 104 | @Override 105 | public IReplacementEntry create() { 106 | if (this.replacementName == null) { 107 | this.replacementName = String.format(Locale.ENGLISH, "replacement_%s", 108 | RandomStringUtils.randomAlphanumeric(8, 16)); 109 | } 110 | 111 | return new ReplacementEntry(this.replacementName, this.entries); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import com.google.common.collect.ImmutableList; 8 | import com.mcmoddev.orespawn.api.os3.IReplacementEntry; 9 | import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; 10 | 11 | import net.minecraft.block.state.IBlockState; 12 | import net.minecraftforge.registries.IForgeRegistryEntry; 13 | 14 | public class ReplacementEntry extends IForgeRegistryEntry.Impl 15 | implements IReplacementEntry { 16 | 17 | private final List matchVal; 18 | private OreSpawnBlockMatcher matcher = null; 19 | 20 | public ReplacementEntry(final String name, final IBlockState... toMatch) { 21 | super.setRegistryName(name); 22 | this.matchVal = Arrays.asList(toMatch); 23 | } 24 | 25 | public ReplacementEntry(final String name, final List toMatch) { 26 | super.setRegistryName(name); 27 | this.matchVal = new ArrayList<>(); 28 | this.matchVal.addAll(toMatch); 29 | } 30 | 31 | @Override 32 | public OreSpawnBlockMatcher getMatcher() { 33 | if (this.matcher == null) { 34 | this.matcher = new OreSpawnBlockMatcher(this.matchVal); 35 | } 36 | return this.matcher; 37 | } 38 | 39 | public List getEntries() { 40 | return ImmutableList.copyOf(this.matchVal); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import com.mcmoddev.orespawn.OreSpawn; 4 | import com.mcmoddev.orespawn.api.BiomeLocation; 5 | import com.mcmoddev.orespawn.api.IBlockList; 6 | import com.mcmoddev.orespawn.api.IDimensionList; 7 | import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; 8 | import com.mcmoddev.orespawn.api.os3.IBlockDefinition; 9 | import com.mcmoddev.orespawn.api.os3.IFeatureEntry; 10 | import com.mcmoddev.orespawn.api.os3.IReplacementEntry; 11 | import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; 12 | import com.mcmoddev.orespawn.util.StateUtil; 13 | 14 | import net.minecraft.block.Block; 15 | import net.minecraft.block.state.IBlockState; 16 | import net.minecraft.util.ResourceLocation; 17 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 18 | 19 | public class SpawnBuilder implements ISpawnBuilder { 20 | 21 | private String spawnName; 22 | private boolean enabled; 23 | private boolean retrogen; 24 | private IBlockList blocks; 25 | private IFeatureEntry feature; 26 | private BiomeLocation biomes; 27 | private IDimensionList dimensions; 28 | private IReplacementEntry replacements; 29 | 30 | public SpawnBuilder() { 31 | this.enabled = false; 32 | this.retrogen = false; 33 | this.blocks = new BlockList(); 34 | } 35 | 36 | public SpawnBuilder(final String spawnName) { 37 | this(); 38 | this.spawnName = spawnName; 39 | } 40 | 41 | @Override 42 | public ISpawnBuilder setName(final String name) { 43 | this.spawnName = name; 44 | return this; 45 | } 46 | 47 | @Override 48 | public ISpawnBuilder setDimensions(final IDimensionList dimensions) { 49 | this.dimensions = dimensions; 50 | return this; 51 | } 52 | 53 | @Override 54 | public ISpawnBuilder setBiomes(final BiomeLocation biomes) { 55 | this.biomes = biomes; 56 | return this; 57 | } 58 | 59 | @Override 60 | public ISpawnBuilder setEnabled(final boolean enabled) { 61 | this.enabled = enabled; 62 | return this; 63 | } 64 | 65 | @Override 66 | public ISpawnBuilder setRetrogen(final boolean retrogen) { 67 | this.retrogen = retrogen; 68 | return this; 69 | } 70 | 71 | @Override 72 | public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { 73 | this.replacements = replacements; 74 | return this; 75 | } 76 | 77 | @Override 78 | public ISpawnBuilder setFeature(final IFeatureEntry feature) { 79 | this.feature = feature; 80 | return this; 81 | } 82 | 83 | @Override 84 | public ISpawnBuilder addBlock(final String blockName) { 85 | return this.addBlock(new ResourceLocation(blockName)); 86 | } 87 | 88 | @Override 89 | public ISpawnBuilder addBlock(final String blockName, final String blockState) { 90 | return this.addBlock(new ResourceLocation(blockName), blockState); 91 | } 92 | 93 | /** 94 | * 95 | * @deprecated 96 | */ 97 | @Override 98 | @Deprecated 99 | public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { 100 | return this.addBlock(new ResourceLocation(blockName), blockMetadata); 101 | } 102 | 103 | @Override 104 | public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { 105 | return this.addBlockWithChance(blockResourceLocation, 100); 106 | } 107 | 108 | @Override 109 | public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, 110 | final String blockState) { 111 | return this.addBlockWithChance(blockResourceLocation, blockState, 100); 112 | } 113 | 114 | /** 115 | * 116 | * @deprecated 117 | */ 118 | @Override 119 | @Deprecated 120 | public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, 121 | final int blockMetadata) { 122 | return this.addBlockWithChance(blockResourceLocation, 100); 123 | } 124 | 125 | @Override 126 | public ISpawnBuilder addBlock(final Block block) { 127 | return this.addBlockWithChance(block, 100); 128 | } 129 | 130 | @Override 131 | public ISpawnBuilder addBlock(final IBlockState block) { 132 | return this.addBlockWithChance(block, 100); 133 | } 134 | 135 | @Override 136 | public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { 137 | return this.addBlockWithChance(new ResourceLocation(blockName), chance); 138 | } 139 | 140 | @Override 141 | public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, 142 | final int chance) { 143 | return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); 144 | } 145 | 146 | /** 147 | * 148 | * @deprecated 149 | */ 150 | @Override 151 | @Deprecated 152 | public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, 153 | final int chance) { 154 | return this.addBlockWithChance(blockName, blockMetadata, chance); 155 | } 156 | 157 | @Override 158 | public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, 159 | final int chance) { 160 | final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) 161 | .getDefaultState(); 162 | return this.addBlockWithChance(tempVar, chance); 163 | } 164 | 165 | @Override 166 | public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, 167 | final String blockState, final int chance) { 168 | final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); 169 | IBlockState tempVar; 170 | try { 171 | tempVar = StateUtil.deserializeState(tempBlock, blockState); 172 | } catch (BadStateValueException e) { 173 | StringBuilder p = new StringBuilder(); 174 | for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); 175 | OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); 176 | tempVar = tempBlock.getDefaultState(); 177 | } 178 | return this.addBlockWithChance(tempVar, chance); 179 | } 180 | 181 | /** 182 | * 183 | * @deprecated 184 | */ 185 | @Override 186 | @Deprecated 187 | public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, 188 | final int blockMetadata, final int chance) { 189 | final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) 190 | .getStateFromMeta(blockMetadata); 191 | return this.addBlockWithChance(tempVar, chance); 192 | } 193 | 194 | @Override 195 | public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { 196 | final IBlockState tempVar = block.getDefaultState(); 197 | return this.addBlockWithChance(tempVar, chance); 198 | } 199 | 200 | @Override 201 | public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { 202 | final BlockBuilder bb = new BlockBuilder(); 203 | bb.setFromBlockStateWithChance(block, chance); 204 | return this.addBlock(bb.create()); 205 | } 206 | 207 | @Override 208 | public ISpawnBuilder addBlock(final IBlockDefinition block) { 209 | if (block.isValid()) { 210 | this.blocks.addBlock(block); 211 | } 212 | return this; 213 | } 214 | 215 | @Override 216 | public SpawnEntry create() { 217 | if (this.blocks.count() > 0) { 218 | if (this.dimensions == null) this.dimensions = new DimensionBuilder().setAcceptAll().create(); 219 | if (this.biomes == null) this.biomes = new BiomeBuilder().setAcceptAll().create(); 220 | if (this.replacements == null) this.replacements = com.mcmoddev.orespawn.OreSpawn.API.getReplacement("default"); 221 | if (this.feature == null) { 222 | com.mcmoddev.orespawn.OreSpawn.LOGGER.error("Spawn entry {} does not have a stated feature, ignoring.", this.spawnName); 223 | return null; 224 | } 225 | return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, 226 | this.biomes, this.replacements, this.blocks, this.feature); 227 | } else { 228 | return null; 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.impl.os3; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.api.BiomeLocation; 6 | import com.mcmoddev.orespawn.api.IBlockList; 7 | import com.mcmoddev.orespawn.api.IDimensionList; 8 | import com.mcmoddev.orespawn.api.os3.IFeatureEntry; 9 | import com.mcmoddev.orespawn.api.os3.IReplacementEntry; 10 | import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; 11 | 12 | import net.minecraft.util.ResourceLocation; 13 | import net.minecraft.util.math.ChunkPos; 14 | import net.minecraft.world.World; 15 | import net.minecraft.world.biome.Biome; 16 | import net.minecraft.world.chunk.IChunkProvider; 17 | import net.minecraft.world.gen.IChunkGenerator; 18 | import net.minecraftforge.fml.common.registry.ForgeRegistries; 19 | 20 | public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { 21 | 22 | private final String spawnName; 23 | private final IDimensionList dimensions; 24 | private final IReplacementEntry replacements; 25 | private final IBlockList blocks; 26 | private final BiomeLocation biomes; 27 | private final IFeatureEntry feature; 28 | private final boolean enabled; 29 | private final boolean retrogen; 30 | 31 | public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, 32 | final IDimensionList dimensions, final BiomeLocation biomes, 33 | final IReplacementEntry replacements, final IBlockList blocks, 34 | final IFeatureEntry feature) { 35 | this.spawnName = spawnName; 36 | this.enabled = enabled; 37 | this.retrogen = retrogen; 38 | this.dimensions = dimensions; 39 | this.biomes = biomes; 40 | this.replacements = replacements; 41 | this.blocks = blocks; 42 | this.feature = feature; 43 | } 44 | 45 | @Override 46 | public boolean isRetrogen() { 47 | return this.retrogen; 48 | } 49 | 50 | @Override 51 | public boolean isEnabled() { 52 | return this.enabled; 53 | } 54 | 55 | @Override 56 | public String getSpawnName() { 57 | return this.spawnName; 58 | } 59 | 60 | @Override 61 | public boolean dimensionAllowed(final int dimension) { 62 | return this.dimensions.matches(dimension); 63 | } 64 | 65 | @Override 66 | public boolean biomeAllowed(final ResourceLocation biomeName) { 67 | return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); 68 | } 69 | 70 | @Override 71 | public boolean biomeAllowed(final Biome biome) { 72 | return this.biomes.matches(biome); 73 | } 74 | 75 | @Override 76 | public IFeatureEntry getFeature() { 77 | return this.feature; 78 | } 79 | 80 | @Override 81 | public OreSpawnBlockMatcher getMatcher() { 82 | return this.replacements.getMatcher(); 83 | } 84 | 85 | @Override 86 | public IBlockList getBlocks() { 87 | return this.blocks; 88 | } 89 | 90 | @Override 91 | public void generate(final Random random, final World world, 92 | final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, 93 | final ChunkPos pos) { 94 | this.feature.getFeature().setRandom(random); 95 | this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); 96 | } 97 | 98 | @Override 99 | public IDimensionList getDimensions() { 100 | return this.dimensions; 101 | } 102 | 103 | @Override 104 | public BiomeLocation getBiomes() { 105 | return this.biomes; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.json; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.nio.file.StandardOpenOption; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import com.google.gson.Gson; 12 | import com.google.gson.GsonBuilder; 13 | import com.google.gson.JsonObject; 14 | import com.mcmoddev.orespawn.OreSpawn; 15 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 16 | import com.mcmoddev.orespawn.data.Constants; 17 | import com.mcmoddev.orespawn.data.Constants.ConfigNames; 18 | 19 | import net.minecraft.crash.CrashReport; 20 | 21 | public class OreSpawnWriter { 22 | 23 | /* 24 | * Write out the configs as the system knows them to the 'forced-saves' directory 25 | */ 26 | public static void saveConfigs() { 27 | final Map> configs = OreSpawn.API.getSpawnsByFile(); 28 | final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 29 | configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); 30 | } 31 | 32 | private static void saveSingle(final Path filePath, final Gson gson) { 33 | final JsonObject root = new JsonObject(); 34 | root.addProperty(ConfigNames.FILE_VERSION, "2.0"); 35 | final JsonObject spawns = new JsonObject(); 36 | final String k = filePath.getFileName().toString(); 37 | final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); 38 | final Path conf = saveDir.resolve(k); 39 | if (!saveDir.toFile().exists()) { 40 | saveDir.toFile().mkdirs(); 41 | } 42 | try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, 43 | StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { 44 | OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { 45 | final JsonObject thisSpawn = new JsonObject(); 46 | final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); 47 | thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); 48 | thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); 49 | thisSpawn.addProperty(ConfigNames.FEATURE, 50 | spawnEntry.getFeature().getFeatureName()); 51 | thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); 52 | thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); 53 | thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); 54 | thisSpawn.add(ConfigNames.PARAMETERS, 55 | spawnEntry.getFeature().getFeatureParameters()); 56 | spawns.add(spawnName, thisSpawn); 57 | }); 58 | root.add(ConfigNames.SPAWNS, spawns); 59 | p.write(gson.toJson(root)); 60 | } catch (final IOException e) { 61 | CrashReport report = CrashReport.makeCrashReport(e, 62 | "Failed writing config data " + conf.toString()); 63 | report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); 64 | OreSpawn.LOGGER.info(report.getCompleteReport()); 65 | } 66 | 67 | } 68 | 69 | public static void saveSingle(final String fileName) { 70 | final Gson gson = new GsonBuilder().setPrettyPrinting().create(); 71 | saveSingle(Constants.CONFDIR.resolve(fileName), gson); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/util/Collectors2.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.util; 2 | 3 | import java.util.stream.Collector; 4 | 5 | import com.google.common.collect.ImmutableList; 6 | import com.google.common.collect.ImmutableSet; 7 | 8 | public final class Collectors2 { 9 | 10 | private Collectors2() { 11 | } 12 | 13 | public static Collector, ImmutableList> toImmutableList() { 14 | return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, 15 | (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); 16 | } 17 | 18 | public static Collector, ImmutableSet> toImmutableSet() { 19 | return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, 20 | (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/util/StateUtil.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.util; 2 | 3 | import com.google.common.base.Optional; 4 | import com.mcmoddev.orespawn.OreSpawn; 5 | import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; 6 | 7 | import net.minecraft.block.Block; 8 | import net.minecraft.block.properties.IProperty; 9 | import net.minecraft.block.state.IBlockState; 10 | 11 | public class StateUtil { 12 | 13 | private StateUtil() { 14 | throw new InstantiationError("This class cannot be instantiated!"); 15 | } 16 | 17 | public static String serializeState(final IBlockState state) { 18 | String string = state.toString(); 19 | string = string.substring(string.indexOf('[') + 1, 20 | string.length() - (string.endsWith("]") ? 1 : 0)); 21 | 22 | if (string.equals(state.getBlock().getRegistryName().toString())) { 23 | string = "normal"; 24 | } 25 | 26 | OreSpawn.LOGGER.debug("State is %s (for block %s)", string, 27 | state.getBlock().getRegistryName()); 28 | return string; 29 | } 30 | 31 | @SuppressWarnings({ "unchecked", "rawtypes" }) 32 | public static IBlockState deserializeState(final Block block, final String state) throws BadStateValueException { 33 | String bits[]; 34 | if(state.contains(",")) bits = state.split(","); 35 | else bits = new String[] { state }; 36 | 37 | IBlockState rv = block.getDefaultState(); 38 | 39 | for(String sv : bits) { 40 | String kvp[] = sv.split("="); 41 | IProperty prop = block.getBlockState().getProperty(kvp[0]); 42 | if(prop != null) { 43 | Optional propValue = prop.parseValue(kvp[1]); 44 | if(propValue.isPresent()) 45 | rv = rv.withProperty(prop, propValue.get()); 46 | else 47 | throw new BadStateValueException(String.format("%s is not a valid value for property %s", kvp[1], kvp[0])); 48 | } else { 49 | throw new BadStateValueException(String.format("%s is not a known property of %s", kvp[0], block.getRegistryName())); 50 | } 51 | } 52 | 53 | return rv; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.worldgen; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.data.Config; 6 | import com.mcmoddev.orespawn.data.Constants; 7 | 8 | import net.minecraft.block.Block; 9 | import net.minecraft.init.Blocks; 10 | import net.minecraft.util.math.BlockPos; 11 | import net.minecraft.util.math.ChunkPos; 12 | import net.minecraft.world.World; 13 | import net.minecraft.world.WorldType; 14 | import net.minecraft.world.chunk.IChunkProvider; 15 | import net.minecraft.world.gen.IChunkGenerator; 16 | import net.minecraftforge.fml.common.IWorldGenerator; 17 | 18 | public class FlatBedrock implements IWorldGenerator { 19 | 20 | @Override 21 | public void generate(final Random random, final int chunkX, final int chunkZ, final World world, 22 | final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { 23 | // no need to do flat-bedrock on a "FLAT" world 24 | if (world.getWorldType() != WorldType.FLAT) { 25 | if (world.provider.getDimension() == -1) { 26 | genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); 27 | genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); 28 | } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { 29 | genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); 30 | } 31 | } 32 | } 33 | 34 | public void retrogen(final World world, final int chunkX, final int chunkZ) { 35 | if (world.getWorldType() != WorldType.FLAT) { 36 | if (world.provider.getDimension() == -1) { 37 | genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); 38 | genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); 39 | } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { 40 | genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); 41 | } 42 | } 43 | } 44 | 45 | private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { 46 | final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); 47 | 48 | for (int xP = 0; xP < 16; xP++) { 49 | for (int zP = 0; zP < 16; zP++) { 50 | for (int yP = 5; yP > 0; yP--) { 51 | final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, 52 | chunkPos.z * 16 + zP); 53 | 54 | if (yP < plateThickness 55 | && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { 56 | world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); 57 | } else if (yP >= plateThickness 58 | && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { 59 | world.setBlockState(target, repBlock.getDefaultState(), 26); 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { 67 | final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); 68 | final int thickness = 127 - plateThickness; // layer where the flat for the top starts 69 | 70 | for (int xP = 0; xP < 16; xP++) { 71 | for (int zP = 0; zP < 16; zP++) { 72 | for (int yP = 126; yP > 121; yP--) { 73 | final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, 74 | chunkPos.z * 16 + zP); 75 | 76 | if (yP > thickness 77 | && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { 78 | world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); 79 | } else if (yP <= thickness 80 | && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { 81 | world.setBlockState(target, repBlock.getDefaultState(), 26); 82 | } 83 | } 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.worldgen; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 6 | import com.mcmoddev.orespawn.api.os3.OS3FeatureGenerator; 7 | import com.mcmoddev.orespawn.data.Config; 8 | import com.mcmoddev.orespawn.data.Constants; 9 | 10 | import net.minecraft.world.World; 11 | import net.minecraft.world.chunk.IChunkProvider; 12 | import net.minecraft.world.gen.IChunkGenerator; 13 | import net.minecraftforge.fml.common.IWorldGenerator; 14 | import net.minecraft.util.math.ChunkPos; 15 | 16 | public class OreSpawnFeatureGenerator implements IWorldGenerator, OS3FeatureGenerator { 17 | private final ISpawnEntry spawn; 18 | private final String name; 19 | 20 | public OreSpawnFeatureGenerator( final ISpawnEntry spawn, final String name ) { 21 | this.spawn = spawn; 22 | this.name = name; 23 | } 24 | 25 | @Override 26 | public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, 27 | IChunkProvider chunkProvider) { 28 | final int thisDim = world.provider.getDimension(); 29 | 30 | if ((Config.getBoolean(Constants.RETROGEN_KEY) && 31 | ((this.spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)))) || 32 | (this.spawn.isEnabled() && this.spawn.dimensionAllowed(thisDim))) { 33 | this.spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); 34 | } 35 | } 36 | 37 | @Override 38 | public ISpawnEntry getSpawnData() { 39 | return this.spawn; 40 | } 41 | 42 | @Override 43 | public String getSpawnName() { 44 | return this.name; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java: -------------------------------------------------------------------------------- 1 | package com.mcmoddev.orespawn.worldgen; 2 | 3 | import java.util.Random; 4 | 5 | import com.mcmoddev.orespawn.OreSpawn; 6 | import com.mcmoddev.orespawn.api.os3.ISpawnEntry; 7 | import com.mcmoddev.orespawn.data.Config; 8 | import com.mcmoddev.orespawn.data.Constants; 9 | 10 | import net.minecraft.util.math.ChunkPos; 11 | import net.minecraft.world.World; 12 | import net.minecraft.world.chunk.IChunkProvider; 13 | import net.minecraft.world.gen.IChunkGenerator; 14 | import net.minecraftforge.fml.common.IWorldGenerator; 15 | 16 | public class OreSpawnWorldGen implements IWorldGenerator { 17 | 18 | @Override 19 | public void generate(final Random random, final int chunkX, final int chunkZ, final World world, 20 | final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { 21 | 22 | final int thisDim = world.provider.getDimension(); 23 | 24 | OreSpawn.API.getSpawns(thisDim).stream().filter(ISpawnEntry::isEnabled) 25 | .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) 26 | || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) 27 | .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, 28 | new ChunkPos(chunkX, chunkZ))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/resources/assets/orespawn/configs/_features.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "default", 4 | "class": "com.mcmoddev.orespawn.impl.features.DefaultFeatureGenerator" 5 | }, 6 | { 7 | "name": "vein", 8 | "class": "com.mcmoddev.orespawn.impl.features.VeinGenerator" 9 | }, 10 | { 11 | "name": "normal-cloud", 12 | "class": "com.mcmoddev.orespawn.impl.features.NormalCloudGenerator" 13 | }, 14 | { 15 | "name": "precision", 16 | "class": "com.mcmoddev.orespawn.impl.features.PrecisionGenerator" 17 | }, 18 | { 19 | "name": "clusters", 20 | "class": "com.mcmoddev.orespawn.impl.features.ClusterGenerator" 21 | }, 22 | { 23 | "name": "underfluids", 24 | "class": "com.mcmoddev.orespawn.impl.features.UnderFluid" 25 | } 26 | ] -------------------------------------------------------------------------------- /src/main/resources/assets/orespawn/configs/_replacements.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": [ { "name": "minecraft:stone" }, 3 | { "name": "minecraft:andesite" }, 4 | { "name": "minecraft:diorite" }, 5 | { "name": "minecraft:granite" }, 6 | { "name": "minecraft:netherrack" }, 7 | { "name": "minecraft:end_stone" } ] 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/assets/orespawn/configs/orespawn.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "spawns": { 4 | "quartz_ore": { 5 | "retrogen": false, 6 | "enabled": true, 7 | "feature": "default", 8 | "replaces": "default", 9 | "dimensions": [ 10 | -1 11 | ], 12 | "biomes": { 13 | "excludes": [] 14 | }, 15 | "parameters": { 16 | "size": 15, 17 | "variation": 4, 18 | "frequency": 7, 19 | "minHeight": 0, 20 | "maxHeight": 128 21 | }, 22 | "blocks": [ 23 | { 24 | "name": "minecraft:quartz_ore", 25 | "chance": 100 26 | } 27 | ] 28 | }, 29 | "coal_ore": { 30 | "retrogen": false, 31 | "enabled": true, 32 | "feature": "default", 33 | "replaces": "default", 34 | "dimensions": [], 35 | "biomes": { 36 | "excludes": [] 37 | }, 38 | "parameters": { 39 | "size": 25, 40 | "variation": 12, 41 | "frequency": 20, 42 | "minHeight": 0, 43 | "maxHeight": 128 44 | }, 45 | "blocks": [ 46 | { 47 | "name": "minecraft:coal_ore", 48 | "chance": 100 49 | } 50 | ] 51 | }, 52 | "iron_ore": { 53 | "retrogen": false, 54 | "enabled": true, 55 | "feature": "default", 56 | "replaces": "default", 57 | "dimensions": [], 58 | "biomes": { 59 | "excludes": [] 60 | }, 61 | "parameters": { 62 | "size": 8, 63 | "variation": 4, 64 | "frequency": 20, 65 | "minHeight": 0, 66 | "maxHeight": 64 67 | }, 68 | "blocks": [ 69 | { 70 | "name": "minecraft:iron_ore", 71 | "chance": 100 72 | } 73 | ] 74 | }, 75 | "gold_ore_standard": { 76 | "retrogen": false, 77 | "enabled": true, 78 | "feature": "default", 79 | "replaces": "default", 80 | "dimensions": [], 81 | "biomes": { 82 | "excludes": [] 83 | }, 84 | "parameters": { 85 | "size": 8, 86 | "variation": 2, 87 | "frequency": 2, 88 | "minHeight": 0, 89 | "maxHeight": 32 90 | }, 91 | "blocks": [ 92 | { 93 | "name": "minecraft:gold_ore", 94 | "chance": 100 95 | } 96 | ] 97 | }, 98 | "gold_ore_mesa": { 99 | "retrogen": false, 100 | "enabled": true, 101 | "feature": "default", 102 | "replaces": "default", 103 | "dimensions": [], 104 | "biomes": { 105 | "includes": [ "MESA" ] 106 | }, 107 | "parameters": { 108 | "size": 8, 109 | "variation": 2, 110 | "frequency": 2, 111 | "minHeight": 32, 112 | "maxHeight": 79 113 | }, 114 | "blocks": [ 115 | { 116 | "name": "minecraft:gold_ore", 117 | "chance": 100 118 | } 119 | ] 120 | }, 121 | "diamond_ore": { 122 | "retrogen": false, 123 | "enabled": true, 124 | "feature": "precision", 125 | "replaces": "default", 126 | "dimensions": [], 127 | "biomes": { 128 | "excludes": [] 129 | }, 130 | "parameters": { 131 | "size": 3, 132 | "numObjects": 2, 133 | "minHeight": 0, 134 | "maxHeight": 16 135 | }, 136 | "blocks": [ 137 | { 138 | "name": "minecraft:diamond_ore", 139 | "chance": 100 140 | } 141 | ] 142 | }, 143 | "redstone_ore": { 144 | "retrogen": false, 145 | "enabled": true, 146 | "feature": "default", 147 | "replaces": "default", 148 | "dimensions": [], 149 | "biomes": { 150 | "excludes": [] 151 | }, 152 | "parameters": { 153 | "size": 6, 154 | "variation": 3, 155 | "frequency": 8, 156 | "minHeight": 0, 157 | "maxHeight": 16 158 | }, 159 | "blocks": [ 160 | { 161 | "name": "minecraft:redstone_ore", 162 | "chance": 100 163 | } 164 | ] 165 | }, 166 | "lapis_ore": { 167 | "retrogen": false, 168 | "enabled": false, 169 | "feature": "default", 170 | "replaces": "default", 171 | "dimensions": [], 172 | "biomes": { 173 | "excludes": [] 174 | }, 175 | "parameters": { 176 | "size": 5, 177 | "variation": 2, 178 | "frequency": 1, 179 | "minHeight": 0, 180 | "maxHeight": 32 181 | }, 182 | "blocks": [ 183 | { 184 | "name": "minecraft:lapis_ore", 185 | "chance": 100 186 | } 187 | ] 188 | }, 189 | "emerald_ore": { 190 | "retrogen": false, 191 | "enabled": true, 192 | "feature": "default", 193 | "replaces": "default", 194 | "dimensions": [], 195 | "biomes": { 196 | "includes": [ "MOUNTAIN" ] 197 | }, 198 | "parameters": { 199 | "size": 1, 200 | "variation": 0, 201 | "frequency": 8, 202 | "minHeight": 4, 203 | "maxHeight": 32 204 | }, 205 | "blocks": [ 206 | { 207 | "name": "minecraft:emerald_ore", 208 | "chance": 100 209 | } 210 | ] 211 | }, 212 | "dirt": { 213 | "retrogen": false, 214 | "enabled": true, 215 | "feature": "default", 216 | "replaces": "default", 217 | "dimensions": [], 218 | "biomes": { 219 | "excludes": [] 220 | }, 221 | "parameters": { 222 | "size": 112, 223 | "variation": 50, 224 | "frequency": 10, 225 | "minHeight": 0, 226 | "maxHeight": 255 227 | }, 228 | "blocks": [ 229 | { 230 | "name": "minecraft:dirt", 231 | "chance": 100, 232 | "state": "snowy=false,variant=dirt" 233 | } 234 | ] 235 | }, 236 | "gravel": { 237 | "retrogen": false, 238 | "enabled": true, 239 | "feature": "default", 240 | "replaces": "default", 241 | "dimensions": [], 242 | "biomes": { 243 | "excludes": [] 244 | }, 245 | "parameters": { 246 | "size": 112, 247 | "variation": 50, 248 | "frequency": 8, 249 | "minHeight": 0, 250 | "maxHeight": 255 251 | }, 252 | "blocks": [ 253 | { 254 | "name": "minecraft:gravel", 255 | "chance": 100 256 | } 257 | ] 258 | }, 259 | "andesite": { 260 | "retrogen": false, 261 | "enabled": true, 262 | "feature": "default", 263 | "replaces": "default", 264 | "dimensions": [], 265 | "biomes": { 266 | "excludes": [] 267 | }, 268 | "parameters": { 269 | "size": 112, 270 | "variation": 50, 271 | "frequency": 10, 272 | "minHeight": 0, 273 | "maxHeight": 255 274 | }, 275 | "blocks": [ 276 | { 277 | "name": "minecraft:stone", 278 | "chance": 100, 279 | "state": "variant=andesite" 280 | } 281 | ] 282 | }, 283 | "diorite": { 284 | "retrogen": false, 285 | "enabled": true, 286 | "feature": "default", 287 | "replaces": "default", 288 | "dimensions": [], 289 | "biomes": { 290 | "excludes": [] 291 | }, 292 | "parameters": { 293 | "size": 112, 294 | "variation": 50, 295 | "frequency": 10, 296 | "minHeight": 0, 297 | "maxHeight": 255 298 | }, 299 | "blocks": [ 300 | { 301 | "name": "minecraft:stone", 302 | "chance": 100, 303 | "state": "variant=diorite" 304 | } 305 | ] 306 | }, 307 | "granite": { 308 | "retrogen": false, 309 | "enabled": true, 310 | "feature": "default", 311 | "replaces": "default", 312 | "dimensions": [], 313 | "biomes": { 314 | "excludes": [] 315 | }, 316 | "parameters": { 317 | "size": 112, 318 | "variation": 50, 319 | "frequency": 10, 320 | "minHeight": 0, 321 | "maxHeight": 255 322 | }, 323 | "blocks": [ 324 | { 325 | "name": "minecraft:stone", 326 | "chance": 100, 327 | "state": "variant=granite" 328 | } 329 | ] 330 | } 331 | } 332 | } -------------------------------------------------------------------------------- /src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "orespawn", 4 | "name": "MMD OreSpawn", 5 | "description": "A customizable ore-spawning system that uses JSON files to specify custom ore generation", 6 | "version": "${version}", 7 | "authorList": [ 8 | "dshadowwolf", 9 | "iLexiconn", 10 | "jriwanek", 11 | "DrCyano" 12 | ], 13 | "credits": "The MMD community" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /src/main/resources/pack.mcmeta: -------------------------------------------------------------------------------- 1 | { 2 | "pack":{ 3 | "pack_format":3, 4 | "description":"MMD OreSpawn" 5 | } 6 | } 7 | --------------------------------------------------------------------------------