From a64f05d319cfada5704e4f5c7cc534308458029b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 14 Dec 2017 21:33:00 -0800 Subject: [PATCH 001/205] Jar signing --- build.gradle | 22 +++++++++++++++++++ .../java/com/mcmoddev/orespawn/OreSpawn.java | 9 ++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 47596a56..04dd14a3 100644 --- a/build.gradle +++ b/build.gradle @@ -74,6 +74,8 @@ minecraft { mappings = "snapshot_20170925" // coreMod = "" makeObfSourceJar = false + + replace '@FINGERPRINT@', project.findProperty('signSHA1') } repositories { @@ -179,6 +181,26 @@ task deobfJar(type: Jar) { from sourceSets.main.output } +task signJar(type: SignJar, dependsOn: reobfJar) { + + // Skips if the keyStore property is missing. + onlyIf { + project.hasProperty('keyStore') + } + + // findProperty allows us to reference the property without it existing. + // Using project.propName would cause the script to fail validation if + // the property did not exist. + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + inputFile = jar.archivePath + outputFile = jar.archivePath +} + +build.dependsOn signJar + task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.getDestinationDir() diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 25022f60..3a569c7c 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -22,7 +22,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; @@ -42,7 +41,8 @@ @Mod(modid = Constants.MODID, name = Constants.NAME, version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,)") + acceptedMinecraftVersions = "[1.12,)", + certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { @Instance @@ -61,6 +61,11 @@ public static Map> getSpawns() { return spawns; } + @EventHandler + public void onFingerprintViolation(FMLFingerprintViolationEvent event) { + logger.warn("Invalid fingerprint detected!"); + } + @EventHandler public void preInit(FMLPreInitializationEvent ev) { Config.loadConfig(); From 9d81250da7b997f2e998da93b2ccf9a2547bc547 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 14 Dec 2017 21:36:58 -0800 Subject: [PATCH 002/205] fix --- src/main/java/com/mcmoddev/orespawn/OreSpawn.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 3a569c7c..ff9d64e4 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -26,6 +26,7 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; +import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; From 3dda03c2f40ba0f39f05595ee5332bca6ad85c96 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Wed, 3 Jan 2018 00:41:33 -0800 Subject: [PATCH 003/205] fix logger --- src/main/java/com/mcmoddev/orespawn/OreSpawn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index ff9d64e4..13dcbaa4 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -64,7 +64,7 @@ public static Map> getSpawns() { @EventHandler public void onFingerprintViolation(FMLFingerprintViolationEvent event) { - logger.warn("Invalid fingerprint detected!"); + LOGGER.warn("Invalid fingerprint detected!"); } @EventHandler From eef4099ea3a1666a4a454853fc5cdc3844e8305f Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Wed, 3 Jan 2018 00:41:44 -0800 Subject: [PATCH 004/205] update gradle --- gradle/wrapper/gradle-wrapper.jar | Bin 53319 -> 54708 bytes gradle/wrapper/gradle-wrapper.properties | 3 +-- gradlew | 26 +++++++++++++++-------- gradlew.bat | 6 ------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d3b83982b9b1bccad955349d702be9b884c6e049..7a3265ee94c0ab25cf079ac8ccdf87f41d455d42 100644 GIT binary patch delta 25563 zcmZ6yV{j!**shz2ZQHhO+qP}3XeF7L6Wg{|oJ>41C$?>C&U;SnQ+t2AtGcTiPygz= zyZU2Usc@5WC*zi?n+Oew6t zu~WW>@PYB#dOnNVsNa~A=@gRKHa}ow5y^&U%r)fg880#jCTK# z?dXL0(oJz?h^u=s?kTGdi8kl{ccjP=Ax(8{i&qVksDWed^##)+?kM@_L# zfIC&TgEnBsS;_KJGFpj7m(SAEGSOm+-*J$f-=32PH>X>qr-V<>UewzUDRXvaXK>r* zyaFaGWl(8xEP(9Srn0eiS?)@LOXk~_jGp?k=d?SG2jb2@^oXuR4q<+JP)(AX~Rai^3GP2~PIb+{)L zd&`3RT?7bFUS~gKWcHdJLn8i#(`9UEsRib_0x0=bGdr%7SO8zs*0YLJZj%oNdLTQ8 za<$|_HM;xkB!wy~itYhMm?_s*I+f`^BR$8OGHtabmZo*#4IDpl2aAJ|JMHX}5NJx84Zepn=W@T};OViJ1I~d{Ztfl>wPoUC~+Qw~2S7>aZ{s%z&8L$^>Kl zQM|p2Y`2j{dEkk;k3uZv<%_-KU zpD`T)NZV2%4U@HibJCC5JkwjU0{CLu64g6E&J2pO;c!3Ol$YcXbXP86x4p1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n9`x!0Y8qEj%&mC~N z{@fZ#I^=JCr-R6<6l($yl7C%`r!9sOg1qTQSWb+^ZB832N K`jG<&(EkDPr&!Mb diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 870cffcc..f16d2666 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Aug 27 22:42:28 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip diff --git a/gradlew b/gradlew index 27309d92..cccdd3d5 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f6d5974e..e95643d6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -49,7 +49,6 @@ goto fail @rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line From 95042d71acfce96093e8e37130db615884e401e1 Mon Sep 17 00:00:00 2001 From: "Daniel \"DShadowWolf\" Hazelton" Date: Mon, 8 Jan 2018 00:20:19 -0500 Subject: [PATCH 005/205] fix some issues - the issue reported by Morph about blocks from certain mods was much deeper and actually effected the entirety of the 'default' generator, albeit this only showed in certain conditions. Restore the original version alongside the version utilized by the Precision Generator. --- .../mcmoddev/orespawn/api/FeatureBase.java | 56 ++++++++++++------- .../impl/features/ClusterGenerator.java | 11 ++-- .../features/DefaultFeatureGenerator.java | 15 +++-- .../orespawn/impl/os3/OreBuilderImpl.java | 6 +- .../com/mcmoddev/orespawn/json/OS3Writer.java | 2 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 5 +- 6 files changed, 58 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 0f1f3789..fc55db48 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -108,7 +108,7 @@ private boolean spawnOrCache(World world, BlockPos coord, List bloc IBlockState targetBlock = world.getBlockState(coord); if (canReplace(targetBlock, blockReplace)) { - world.setBlockState(coord, oreBlock, 22); + world.setBlockState(coord, oreBlock); // , 22); return true; } else { return false; @@ -229,33 +229,47 @@ protected int getPoint(int lowerBound, int upperBound, int median) { return t - median; } - - protected void spawnMunge(FunctionParameterWrapper params, double radius, int count, boolean toPositive) { - int rSqr = (int)(radius * radius); + protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius, + List replaceBlock, int count, OreList possibleOres) { + Random prng = this.random; int quantity = count; - - OreList possible = params.getOres(); - World world = params.getWorld(); - BlockPos blockPos = params.getBlockPos(); - List replace = params.getReplacements(); - BiomeLocation biomes = params.getBiomes(); - - for (int dy = (int)(-1 * radius); dy < radius; dy++) { - for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, radius); dx = countItem(dx, toPositive)) { - for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, radius); dz = countItem(dz, toPositive)) { - if (getABC(dx, dy, dz) <= rSqr) { - IBlockState oreBlock = possible.getRandomOre(this.random).getOre(); - spawn(oreBlock, world, blockPos.add(dx, dy, dz), world.provider.getDimension(), true, replace, biomes); - - if (--quantity <= 0) { - return; - } + for(int dy = (int)(-1 * radius); dy < radius; dy++){ + for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){ + for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){ + if((dx*dx + dy*dy + dz*dz) <= rSqr){ + IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre(); + spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension()); + quantity--; + } + if(quantity <= 0) { + return; } } } } } + + protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, + List replaceBlock, int count, OreList possibleOres) { + Random prng = this.random; + int quantity = count; + for(int dy = (int)(-1 * radius); dy < radius; dy++){ + for(int dz = (int)(-1 * radius); dz < radius; dz++){ + for(int dx = (int)(-1 * radius); dx < radius; dx++){ + if((dx*dx + dy*dy + dz*dz) <= rSqr){ + IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre(); + spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension()); + quantity--; + } + if(quantity <= 0) { + return; + } + } + } + } + } + protected int getABC(int dx, int dy, int dz) { return (dx * dx + dy * dy + dz * dz); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 509fd2ec..cd8e226a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -173,12 +173,13 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) { } private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) { - double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - - if (nextBoolean) { - spawnMunge(params, radius, quantity, false); + int count = quantity; + double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int)(radius * radius); + if( nextBoolean ) { + spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); } else { - spawnMunge(params, radius, quantity, true); + spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 068dab73..830c43a5 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -5,6 +5,7 @@ import java.util.Random; import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.GeneratorParameters; @@ -112,7 +113,8 @@ private void spawnOre(FunctionParameterWrapper params, int quantity) { while (count > 0) { IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre(); - spawn(oreBlock, params.getWorld(), params.getBlockPos().add(offs[scrambledLUT[--count]]), + BlockPos target = params.getBlockPos().add(offs[scrambledLUT[--count]]); + spawn(oreBlock, params.getWorld(), target, params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes()); } @@ -123,12 +125,13 @@ private void spawnOre(FunctionParameterWrapper params, int quantity) { } private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) { - double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - - if (nextBoolean) { - spawnMunge(params, radius, quantity, false); + int count = quantity; + double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int)(radius * radius); + if( nextBoolean ) { + spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); } else { - spawnMunge(params, radius, quantity, true); + spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java index b7fe4973..264f9c51 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java @@ -47,13 +47,13 @@ public OreBuilder setOre(String name, String serializedState) { @SuppressWarnings("deprecation") @Override public OreBuilder setOre(String name, int metaData) { - this.setOre(name); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name)); - if (this.ore == null) { + if (block == null) { return this; } - this.ore = this.ore.getBlock().getStateFromMeta(metaData); + this.ore = block.getStateFromMeta(metaData); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java index 578311d8..91fc02a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java @@ -94,7 +94,7 @@ private void writeFile(File file, JsonObject wrapper) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); try { - FileUtils.writeStringToFile(file, gson.toJson(wrapper), Charset.defaultCharset(), false); + FileUtils.writeStringToFile(file, gson.toJson(wrapper), "UTF8", false); } catch (IOException e) { CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed in config %s", file.getName())); report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 645bac1e..348d5628 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.util; +import com.mcmoddev.orespawn.OreSpawn; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -15,7 +17,8 @@ public static String serializeState(IBlockState state) { if (string.equals(state.getBlock().getRegistryName().toString())) { string = "normal"; } - + + OreSpawn.LOGGER.fatal("State is %s (for block %s)", string, state.getBlock().getRegistryName()); return string; } From 631c38060826adadbd9fa1dbecb032c46c7692a2 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 9 Jan 2018 01:48:48 -0800 Subject: [PATCH 006/205] Release 3.2.1 --- build.gradle | 8 ++++---- src/main/java/com/mcmoddev/orespawn/data/Constants.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 04dd14a3..11db9e76 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ buildscript { dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.0.9' - classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5' + classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1' } } @@ -69,9 +69,9 @@ if (secretFile.exists()) { } minecraft { - version = "1.12.1-14.22.1.2485" + version = "1.12.2-14.23.1.2555" runDir = "run" - mappings = "snapshot_20170925" + mappings = "snapshot_20171231" // coreMod = "" makeObfSourceJar = false @@ -254,7 +254,7 @@ curseforge { project { id = "245586" changelog = file("CHANGELOG.txt") - releaseType = "alpha" + releaseType = "release" def projName = "OreSpawn" def displayVersion = getVersion("VERSION", mod_file) if (System.getenv().BUILD_NUMBER) { diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index cd58023b..e1111403 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -3,7 +3,7 @@ public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.2.0"; + public static final String VERSION = "3.2.1"; public static final String RETROGEN_KEY = "Retrogen"; public static final String CONFIG_FILE = "config/orespawn.cfg"; public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; From 1baf182440547e57c550b10f7bb3834ad646273b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 9 Jan 2018 13:44:18 -0800 Subject: [PATCH 007/205] Just a few cleanups --- CHANGELOG.txt | 19 +------------------ build.gradle | 8 ++++---- .../mcmoddev/orespawn/api/FeatureBase.java | 2 +- .../orespawn/commands/ClearChunkCommand.java | 12 ++++++------ .../com/mcmoddev/orespawn/data/Config.java | 1 + .../features/DefaultFeatureGenerator.java | 1 - .../com/mcmoddev/orespawn/json/OS3Writer.java | 1 - .../orespawn/worldgen/OreSpawnWorldGen.java | 1 - 8 files changed, 13 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3ef83513..d119e6d8 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,18 +1 @@ -#Version 3.1.0: -Minor Version number bumped because of major internal changes -New Annotation-based plugin system -New API for new plugin system -Update JSON config format to version 1.1 to allow for new feature -Implement BiomeDictionary support -Implement Whitelisting and Blacklisting support for Biomes -Ensure that resources stored in JAR's can be copied out to the config directory for loading and parsing -Add the ability to specify parameters for the default feature generator to the addore command - -#Version 3.0.0: -Ported to 1.11.2 -Complete rewrite of internals for better stability -Change of JSON config format (See Wiki for details!) -Added ability to specify different types of ore generation -Added ability to specify what block gets replaced -Able to Import both OreSpawn 1 and OreSpawn 2 format config files -Added an operator (permission level 4) command to force-dump current configuration +Version 3.2.1 diff --git a/build.gradle b/build.gradle index 11db9e76..72e5c9b8 100644 --- a/build.gradle +++ b/build.gradle @@ -69,10 +69,10 @@ if (secretFile.exists()) { } minecraft { - version = "1.12.2-14.23.1.2555" - runDir = "run" - mappings = "snapshot_20171231" -// coreMod = "" + version = '1.12.2-14.23.1.2555' + runDir = 'run' + mappings = 'snapshot_20171231' +// coreMod = '' makeObfSourceJar = false replace '@FINGERPRINT@', project.findProperty('signSHA1') diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index fc55db48..fd273c46 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -108,7 +108,7 @@ private boolean spawnOrCache(World world, BlockPos coord, List bloc IBlockState targetBlock = world.getBlockState(coord); if (canReplace(targetBlock, blockReplace)) { - world.setBlockState(coord, oreBlock); // , 22); + world.setBlockState(coord, oreBlock); return true; } else { return false; diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 42713c34..95fa7b31 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -72,7 +72,7 @@ private void clearBlocks(ChunkPos chunkPos, List blocks, List over for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { BlockPos pos = new BlockPos(x, y, z); - Block block = player.world.getBlockState(pos).getBlock(); + Block block = player.getEntityWorld().getBlockState(pos).getBlock(); removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); removeIfFluid(pos, player); } @@ -81,18 +81,18 @@ private void clearBlocks(ChunkPos chunkPos, List blocks, List over } private void removeIfFluid(BlockPos pos, EntityPlayer player) { - if (player.world.getBlockState(pos).getMaterial().isLiquid()) { - IBlockState bs = player.world.getBlockState(pos); + if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { + IBlockState bs = player.getEntityWorld().getBlockState(pos); if (bs.getMaterial().equals(Material.LAVA) || bs.getMaterial().equals(Material.WATER)) { - player.world.setBlockToAir(pos); + player.getEntityWorld().setBlockToAir(pos); } } } private void removeIfBlocks(EntityPlayer player, BlockPos pos, Block block, List blocks, List overburden, boolean flagClassic) { if (blocks.contains(block) || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { - player.world.setBlockToAir(pos); + player.getEntityWorld().setBlockToAir(pos); } } @@ -106,7 +106,7 @@ private void getBlocks(String[] args, List blockNames) { break; case "dirtandgravel": - blockNames.add("minecraft:stone"); + blockNames.add(STONE_ID); blockNames.addAll(dirtVariants); blockNames.addAll(otherVariants); break; diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 91bb5f7d..107a03d2 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -132,6 +132,7 @@ private static void saveKnownConfigs() { File in = p.toFile(); JsonArray data = new JsonArray(); + extractedConfigs.forEach(data::add); try { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 830c43a5..2cc3c93e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -5,7 +5,6 @@ import java.util.Random; import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.GeneratorParameters; diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java index 91fc02a1..f8fe60c9 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java @@ -2,7 +2,6 @@ import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Map.Entry; diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 90e676e3..893489a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -28,7 +28,6 @@ public class OreSpawnWorldGen implements IWorldGenerator { private final Map> dimensions; private static final List SPAWN_BLOCKS = new ArrayList<>(); - @SuppressWarnings("unused") public OreSpawnWorldGen(Map> allDimensions, long nextLong) { this.dimensions = Collections.unmodifiableMap(allDimensions); From 38d29d3f292661c06254445650bad85d669f289c Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 13 Feb 2018 23:48:32 -0800 Subject: [PATCH 008/205] Update orespawn json format --- .../com/mcmoddev/orespawn/data/Constants.java | 2 +- .../assets/orespawn/configs/orespawn.json | 448 ++++++++++-------- 2 files changed, 261 insertions(+), 189 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index e1111403..afd88567 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -3,7 +3,7 @@ public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.2.1"; + public static final String VERSION = "3.2.2"; public static final String RETROGEN_KEY = "Retrogen"; public static final String CONFIG_FILE = "config/orespawn.cfg"; public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; diff --git a/src/main/resources/assets/orespawn/configs/orespawn.json b/src/main/resources/assets/orespawn/configs/orespawn.json index 4cd39ca7..09e85972 100755 --- a/src/main/resources/assets/orespawn/configs/orespawn.json +++ b/src/main/resources/assets/orespawn/configs/orespawn.json @@ -1,190 +1,262 @@ { - "version": "1.1", - "dimensions": [ - { - "dimension": "-1", - "ores": [ - { - "block": "minecraft:quartz_ore", - "parameters": { - "size": 15, - "variation": 4, - "frequency": 7.0, - "minHeight": 0, - "maxHeight": 128 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - } - ] - }, - { - "ores": [ - { - "block": "minecraft:coal_ore", - "parameters": { - "size": 25, - "variation": 12, - "frequency": 20.0, - "minHeight": 0, - "maxHeight": 128 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:iron_ore", - "parameters": { - "size": 8, - "variation": 4, - "frequency": 20.0, - "minHeight": 0, - "maxHeight": 64 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:gold_ore", - "parameters": { - "size": 8, - "variation": 2, - "frequency": 2.0, - "minHeight": 0, - "maxHeight": 32 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:diamond_ore", - "parameters": { - "size": 6, - "variation": 3, - "frequency": 8.0, - "minHeight": 0, - "maxHeight": 16 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:redstone_ore", - "parameters": { - "size": 6, - "variation": 3, - "frequency": 8.0, - "minHeight": 0, - "maxHeight": 16 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:lapis_ore", - "parameters": { - "size": 5, - "variation": 2, - "frequency": 1.0, - "minHeight": 0, - "maxHeight": 32 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:emerald_ore", - "parameters": { - "size": 1, - "variation": 0, - "frequency": 8.0, - "minHeight": 4, - "maxHeight": 32 - }, - "feature": "default", - "replace_block": "default", - "biomes": [ - "minecraft:extreme_hills", - "minecraft:smaller_extreme_hills" - ] - }, - { - "block": "minecraft:dirt", - "state": "snowy=false,variant=dirt", - "parameters": { - "size": 112, - "variation": 50, - "frequency": 10.0, - "minHeight": 0, - "maxHeight": 255 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:gravel", - "parameters": { - "size": 112, - "variation": 50, - "frequency": 8.0, - "minHeight": 0, - "maxHeight": 255 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:stone", - "state": "variant=granite", - "parameters": { - "size": 112, - "variation": 50, - "frequency": 10.0, - "minHeight": 0, - "maxHeight": 255 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:stone", - "state": "variant=diorite", - "parameters": { - "size": 112, - "variation": 50, - "frequency": 10.0, - "minHeight": 0, - "maxHeight": 255 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - }, - { - "block": "minecraft:stone", - "state": "variant=andesite", - "parameters": { - "size": 112, - "variation": 50, - "frequency": 10.0, - "minHeight": 0, - "maxHeight": 255 - }, - "feature": "default", - "replace_block": "default", - "biomes": [] - } - ] - } - ] + "version": "2.0", + "spawns": { + "quartz_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [ + "-1" + ], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 15, + "variation": 4, + "frequency": 7, + "minHeight": 0, + "maxHeight": 128 + }, + "blocks": [ + { + "name": "minecraft:quartz_ore", + "chance": 100 + } + ] + }, + "coal_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 25, + "variation": 12, + "frequency": 20, + "minHeight": 0, + "maxHeight": 128 + }, + "blocks": [ + { + "name": "minecraft:coal_ore", + "chance": 100 + } + ] + }, + "iron_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 8, + "variation": 4, + "frequency": 20, + "minHeight": 0, + "maxHeight": 64 + }, + "blocks": [ + { + "name": "minecraft:iron_ore", + "chance": 100 + } + ] + }, + "gold_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 8, + "variation": 2, + "frequency": 2, + "minHeight": 0, + "maxHeight": 32 + }, + "blocks": [ + { + "name": "minecraft:gold_ore", + "chance": 100 + } + ] + }, + "diamond_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 6, + "variation": 3, + "frequency": 8, + "minHeight": 0, + "maxHeight": 16 + }, + "blocks": [ + { + "name": "minecraft:diamond_ore", + "chance": 100 + } + ] + }, + "redstone_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 6, + "variation": 3, + "frequency": 8, + "minHeight": 0, + "maxHeight": 16 + }, + "blocks": [ + { + "name": "minecraft:redstone_ore", + "chance": 100 + } + ] + }, + "lapis_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 5, + "variation": 2, + "frequency": 1, + "minHeight": 0, + "maxHeight": 32 + }, + "blocks": [ + { + "name": "minecraft:lapis_ore", + "chance": 100 + } + ] + }, + "emerald_ore": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 1, + "variation": 0, + "frequency": 8, + "minHeight": 4, + "maxHeight": 32 + }, + "blocks": [ + { + "name": "minecraft:emerald_ore", + "chance": 100 + } + ] + }, + "dirt": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 112, + "variation": 50, + "frequency": 10, + "minHeight": 0, + "maxHeight": 255 + }, + "blocks": [ + { + "name": "minecraft:dirt", + "chance": 100, + "state": "snowy=false,variant=dirt" + } + ] + }, + "gravel": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 112, + "variation": 50, + "frequency": 8, + "minHeight": 0, + "maxHeight": 255 + }, + "blocks": [ + { + "name": "minecraft:gravel", + "chance": 100 + } + ] + }, + "stone": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 112, + "variation": 50, + "frequency": 10, + "minHeight": 0, + "maxHeight": 255 + }, + "blocks": [ + { + "name": "minecraft:stone", + "chance": 100, + "state": "variant=andesite" + } + ] + } + } } \ No newline at end of file From 6ca3ca377ecdefbe132bcf2325160ba0adcc29b7 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 22 Feb 2018 01:38:22 -0800 Subject: [PATCH 009/205] Fix --- src/main/resources/assets/orespawn/configs/orespawn.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/orespawn/configs/orespawn.json b/src/main/resources/assets/orespawn/configs/orespawn.json index 09e85972..db26a057 100755 --- a/src/main/resources/assets/orespawn/configs/orespawn.json +++ b/src/main/resources/assets/orespawn/configs/orespawn.json @@ -7,7 +7,7 @@ "feature": "default", "replaces": "default", "dimensions": [ - "-1" + -1 ], "biomes": { "excludes": [] From 6764e3ecfe9649b45e4ed544ec6f02b765e8caf0 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 6 Mar 2018 11:44:47 -0500 Subject: [PATCH 010/205] add a hack to the replacements registry to account for Mineralogy --- .../orespawn/data/ReplacementsRegistry.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 9861260d..f77452f5 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -9,8 +9,7 @@ import net.minecraftforge.oredict.OreDictionary; import java.util.*; - -import static java.util.Arrays.asList; +import java.util.stream.Collectors; public class ReplacementsRegistry { private static Map blocks = new HashMap<>(); @@ -21,18 +20,26 @@ private ReplacementsRegistry() { @SuppressWarnings("deprecation") public static List getDimensionDefault(int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; + List mineralogyOres = OreDictionary.getOres("cobblestone").stream() + .filter( iS -> iS.getItem().getRegistryName().getResourceDomain().equals("mineralogy")) + .map( iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) + .collect(Collectors.toList()); if (dimension < -1 || dimension > 1 || dimension == 0) { List rv = new ArrayList<>(); for (ItemStack iS : OreDictionary.getOres("stone")) { rv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); + rv.addAll(mineralogyOres); } - + return rv; } - - return asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension + 1])).getDefaultState()); + + List baseRv = new ArrayList<>(); + baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); + baseRv.addAll(mineralogyOres); + return baseRv; } public static IBlockState getBlock(String name) { From 64245c61d56218d8032ef72dad20039c2c4fb409 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 6 Mar 2018 12:34:25 -0500 Subject: [PATCH 011/205] lets add the replacements registry bits --- .../java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 95fa7b31..6416e771 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.stream.Collectors; +import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -59,6 +60,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args blocks = blockNames.stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).collect(Collectors.toList()); + blocks.addAll(ReplacementsRegistry.getDimensionDefault(player.getEntityWorld().provider.getDimension()).stream().map(bs -> bs.getBlock()).collect(Collectors.toList())); List overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).collect(Collectors.toList()); From 1496f24cf375b7d6e30407c9375fa1e7b89449f5 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 6 Mar 2018 13:13:42 -0500 Subject: [PATCH 012/205] not entirely perfect, but this does catch Mineralogy now in /clearchunk --- .../orespawn/commands/ClearChunkCommand.java | 20 ++++++++++--------- .../orespawn/data/ReplacementsRegistry.java | 14 ++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 6416e771..5f98b9b1 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.stream.Collectors; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; import net.minecraft.block.Block; @@ -50,7 +51,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args EntityPlayer player = (EntityPlayer) sender; Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(player.getPosition()); ChunkPos chunkPos = chunk.getPos(); - List blocks; + List blocks; boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false; @@ -58,23 +59,24 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args getBlocks(args, blockNames); blocks = blockNames.stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).collect(Collectors.toList()); - - blocks.addAll(ReplacementsRegistry.getDimensionDefault(player.getEntityWorld().provider.getDimension()).stream().map(bs -> bs.getBlock()).collect(Collectors.toList())); - List overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).collect(Collectors.toList()); + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList()); + blocks.addAll(ReplacementsRegistry.getDimensionDefault(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList())); + List overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); + clearBlocks(chunkPos, blocks, overburden, flagClassic, player); player.sendStatusMessage(new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); } - private void clearBlocks(ChunkPos chunkPos, List blocks, List overburden, boolean flagClassic, EntityPlayer player) { + private void clearBlocks(ChunkPos chunkPos, List blocks, List overburden, boolean flagClassic, EntityPlayer player) { for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { BlockPos pos = new BlockPos(x, y, z); - Block block = player.getEntityWorld().getBlockState(pos).getBlock(); + IBlockState block = player.getEntityWorld().getBlockState(pos); removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); removeIfFluid(pos, player); } @@ -92,7 +94,7 @@ private void removeIfFluid(BlockPos pos, EntityPlayer player) { } } - private void removeIfBlocks(EntityPlayer player, BlockPos pos, Block block, List blocks, List overburden, boolean flagClassic) { + private void removeIfBlocks(EntityPlayer player, BlockPos pos, IBlockState block, List blocks, List overburden, boolean flagClassic) { if (blocks.contains(block) || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { player.getEntityWorld().setBlockToAir(pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index f77452f5..840cb89e 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -24,21 +24,19 @@ public static List getDimensionDefault(int dimension) { .filter( iS -> iS.getItem().getRegistryName().getResourceDomain().equals("mineralogy")) .map( iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) .collect(Collectors.toList()); + List baseRv = new ArrayList<>(); + baseRv.addAll(mineralogyOres); + if (dimension < -1 || dimension > 1 || dimension == 0) { - List rv = new ArrayList<>(); - for (ItemStack iS : OreDictionary.getOres("stone")) { - rv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); - rv.addAll(mineralogyOres); + baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); } - return rv; - } + return baseRv; + } - List baseRv = new ArrayList<>(); baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); - baseRv.addAll(mineralogyOres); return baseRv; } From 19ac7c03077d75c75bb581fccdef1aebc95ea195 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 6 Mar 2018 15:09:48 -0500 Subject: [PATCH 013/205] use Material.isLiquid() instead of checking specifically for LAVA and WATER - this way all fluids get removed --- .../com/mcmoddev/orespawn/commands/ClearChunkCommand.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 5f98b9b1..081f88d6 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -5,11 +5,8 @@ import java.util.List; import java.util.stream.Collectors; -import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -88,7 +85,7 @@ private void removeIfFluid(BlockPos pos, EntityPlayer player) { if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { IBlockState bs = player.getEntityWorld().getBlockState(pos); - if (bs.getMaterial().equals(Material.LAVA) || bs.getMaterial().equals(Material.WATER)) { + if (bs.getMaterial().isLiquid()) { player.getEntityWorld().setBlockToAir(pos); } } From 15dfa875b180cabf766b70b6eceb4eff9b8730e3 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 19 Mar 2018 20:50:47 -0400 Subject: [PATCH 014/205] hopefully fix the zombie-hole issue (again) --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 2 +- src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index fd273c46..956b9437 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -31,7 +31,7 @@ public FeatureBase(Random rand) { private boolean fullMatch(ImmutableSet locs, Biome biome) { for (BiomeLocation b : locs) { for (Biome bm : b.getBiomes()) { - if (bm.equals(biome)) { + if (bm.equals(biome) || bm.equals(biome.getRegistryName().toString())) { return true; } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java index dc8c6114..32f03888 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; @@ -150,7 +151,12 @@ private static void finallyParse(JsonObject parseJson, String filename) { JsonObject nw = ore.getAsJsonObject(); SpawnBuilder spawn = builder.newSpawnBuilder(null); // load the "ores" as "OreBuilder" - we should always have a "blocks" here, so... - List blocks = Helpers.loadOres(nw.getAsJsonArray(ConfigNames.BLOCKS), spawn); + // filter out all null entries + List blocks = Helpers.loadOres(nw.getAsJsonArray(ConfigNames.BLOCKS), spawn).stream() + .filter(ob -> !ob.getOre().getBlock().equals(net.minecraft.init.Blocks.AIR)).collect(Collectors.toList()); + // null entry + if (blocks.size() == 0) return; + List replacements = getReplacements(nw.get(ConfigNames.V2.REPLACES).getAsString(), dimension); BiomeBuilder biomes = spawn.newBiomeBuilder(); From a13c1af00d30c9c2aa37560bda550c4f0b8c4212 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 20 Mar 2018 00:36:54 -0400 Subject: [PATCH 015/205] If the parse fails and the posting of the crash report does not halt the load, then we can run into a situation where we have inconsistent state and the set of SpawnBuilder objects can contain a null value for the feature generator. This adds a simple sanity check for such. --- src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java | 2 -- .../java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java | 3 ++- .../java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java index 32f03888..1f00619d 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java @@ -93,7 +93,6 @@ public static void loadEntries() { JsonElement full = parser.parse(rawData); JsonObject parsed = full.getAsJsonObject(); - String version = parsed.get("version").getAsString(); IOS3Reader reader = getReader(version); @@ -145,7 +144,6 @@ private static void finallyParse(JsonObject parseJson, String filename) { work.entrySet().forEach(entry -> { int dimension = Integer.parseInt(entry.getKey()); DimensionBuilder builder = logic.newDimensionBuilder(dimension); - entry.getValue().getAsJsonArray().forEach(ore -> { try { JsonObject nw = ore.getAsJsonObject(); diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java index d61ccbb1..9cf629b2 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java +++ b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java @@ -8,6 +8,7 @@ import com.google.common.collect.ImmutableSet; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.os3.OreBuilder; import com.mcmoddev.orespawn.api.os3.SpawnBuilder; @@ -138,7 +139,7 @@ public static List loadOres(JsonArray oresArray, SpawnBuilder spawn) JsonObject work = oreEntry.getAsJsonObject(); String oreName = work.get(ConfigNames.BLOCK_V2).getAsString(); OreBuilder ores = spawn.newOreBuilder(); - + if (work.has(ConfigNames.STATE) || work.has(ConfigNames.METADATA)) { Helpers.handleState(work, ores, oreName); rV.add(ores); diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 893489a1..57a4a891 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -60,6 +60,10 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG .filter(SpawnBuilder::enabled) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.retrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) .forEach(sE -> { + if (sE == null || sE.getFeatureGen() == null) { + OreSpawn.LOGGER.fatal("From the state of things right now, you've likely had a parse-error happen and you have invalid JSON. You'll likely find some ores have not been generated."); + return; + } IFeature currentFeatureGen = sE.getFeatureGen().getGenerator(); List replacement = sE.getReplacementBlocks(); replacement = replacement.isEmpty() ? ReplacementsRegistry.getDimensionDefault(thisDim) : replacement; From 3a760566c1a8f949cf5c39afa723777aaadca84d Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 20 Mar 2018 02:23:32 -0400 Subject: [PATCH 016/205] testing seems to show this fixes the issue of the biome whit/black lists not being obeyed --- .../mcmoddev/orespawn/api/FeatureBase.java | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 956b9437..18c1329a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -28,38 +28,6 @@ public FeatureBase(Random rand) { this.random = rand; } - private boolean fullMatch(ImmutableSet locs, Biome biome) { - for (BiomeLocation b : locs) { - for (Biome bm : b.getBiomes()) { - if (bm.equals(biome) || bm.equals(biome.getRegistryName().toString())) { - return true; - } - } - } - - return false; - } - - private boolean biomeMatch(Biome chunkBiome, BiomeLocation inp) { - if (inp.getBiomes().isEmpty()) { - return false; - } - - if (inp instanceof BiomeLocationComposition) { - BiomeLocationComposition loc = (BiomeLocationComposition) inp; - boolean exclMatch = fullMatch(loc.getExclusions(), chunkBiome); - boolean inclMatch = fullMatch(loc.getInclusions(), chunkBiome); - - if ((loc.getInclusions().isEmpty() || inclMatch) && !exclMatch) { - return false; - } - } else if (inp.matches(chunkBiome)) { - return false; - } - - return true; - } - protected void runCache(int chunkX, int chunkZ, World world, List blockReplace) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); @@ -80,7 +48,7 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d Biome thisBiome = world.getBiome(coord); - if (biomeMatch(thisBiome, biomes)) { + if (!biomes.matches(thisBiome) && !biomes.getBiomes().isEmpty()) { return false; } From e97d2152382d4ef115d4e4fe291570b737d6950a Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 03:44:29 -0400 Subject: [PATCH 017/205] Start of the work on fixing the mess that was the API. This changes things to use a set of related builders that return properly created data ready for use in creating the final spawn entry. At the moment the work only covers the SpawnBuilder, DimensionBuilder and BiomeBuilder classes, along with their resulting objects. Interfaces are provided in the "API" package, for use by others, as needed. --- .../mcmoddev/orespawn/api/BiomeBuilder.java | 15 ++ .../mcmoddev/orespawn/api/DimensionList.java | 7 + .../mcmoddev/orespawn/api/FeatureEntry.java | 12 ++ .../orespawn/api/ReplacementEntry.java | 7 + .../com/mcmoddev/orespawn/api/SpawnEntry.java | 31 +++ .../orespawn/api/os3/BiomeBuilder.java | 22 --- .../orespawn/api/os3/BuilderLogic.java | 19 -- .../orespawn/api/os3/DimensionBuilder.java | 25 ++- .../orespawn/api/os3/DimensionList.java | 6 - .../orespawn/api/os3/FeatureBuilder.java | 20 -- .../mcmoddev/orespawn/api/os3/OreBuilder.java | 29 --- .../orespawn/api/os3/SpawnBuilder.java | 78 ++++---- .../orespawn/impl/features/BiomeBuilder.java | 94 +++++++++ .../impl/location/BiomeLocationEmpty.java | 14 ++ .../orespawn/impl/os3/BiomeBuilderImpl.java | 102 ---------- .../orespawn/impl/os3/BuilderLogicImpl.java | 94 --------- .../orespawn/impl/os3/DimensionBuilder.java | 54 +++++ .../impl/os3/DimensionBuilderImpl.java | 51 ----- .../orespawn/impl/os3/DimensionList.java | 26 +++ .../impl/os3/DimensionListAcceptAll.java | 11 ++ .../impl/os3/DimensionListDenyAll.java | 11 ++ .../orespawn/impl/os3/DimensionListImpl.java | 29 --- .../orespawn/impl/os3/FeatureBuilderImpl.java | 80 -------- .../orespawn/impl/os3/OreBuilderImpl.java | 125 ------------ .../orespawn/impl/os3/SpawnBuilder.java | 183 +++++++++++++++++ .../orespawn/impl/os3/SpawnBuilderImpl.java | 184 ------------------ .../orespawn/impl/os3/SpawnEntry.java | 88 +++++++++ 27 files changed, 602 insertions(+), 815 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/DimensionList.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/BiomeBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/BuilderLogic.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/DimensionList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/FeatureBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OreBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilderImpl.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BuilderLogicImpl.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilderImpl.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListImpl.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilderImpl.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilderImpl.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java new file mode 100644 index 00000000..0e6f80f1 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java @@ -0,0 +1,15 @@ +package com.mcmoddev.orespawn.api; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; + +public interface BiomeBuilder { + public BiomeBuilder addWhitelistEntry(final Biome biome); + public BiomeBuilder addWhitelistEntry(final String biomeName); + public BiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation); + public BiomeBuilder addBlacklistEntry(Biome biome); + public BiomeBuilder addBlacklistEntry(final String biomeName); + public BiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); + public BiomeBuilder setAcceptAll(); + public BiomeLocation create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/DimensionList.java new file mode 100644 index 00000000..f7a2622d --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/DimensionList.java @@ -0,0 +1,7 @@ +package com.mcmoddev.orespawn.api; + +public interface DimensionList { + default public boolean matches(final int dimensionId) { + return false; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java new file mode 100644 index 00000000..9a77d4fb --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java @@ -0,0 +1,12 @@ +package com.mcmoddev.orespawn.api; +import com.google.gson.JsonObject; + +public interface FeatureEntry { + public IFeature getFeature(); + public String getFeatureName(); + public JsonObject getFeatureParameters(); + public void setStringParameter(final String parameterName, final String parameterValue); + public void setIntegerParameter(final String parameterName, final int parameterValue); + public void setBooleanParameter(final String parameterName, final boolean parameterValue); + public void setFloatParameter(final String parameterName, final float parameterValue); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java new file mode 100644 index 00000000..ec3ff433 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java @@ -0,0 +1,7 @@ +package com.mcmoddev.orespawn.api; + +import net.minecraft.block.state.pattern.BlockMatcher; + +public interface ReplacementEntry { + public BlockMatcher getMatcher(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java new file mode 100644 index 00000000..0f22e9ab --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java @@ -0,0 +1,31 @@ +package com.mcmoddev.orespawn.api; + +import net.minecraft.block.state.pattern.BlockMatcher; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; + +import org.apache.commons.lang3.tuple.Pair; + +import com.google.common.collect.ImmutableList; + +import net.minecraft.block.state.IBlockState; + +public interface SpawnEntry { + default public boolean isEnabled() { + return false; + } + + default public boolean isRetrogen() { + return false; + } + + public String getSpawnName(); + public boolean dimensionAllowed(final int dimension); + public boolean biomeAllowed(final ResourceLocation biomeName); + public boolean biomeAllowed(final Biome biome); + public FeatureEntry getFeature(); + public BlockMatcher getMatcher(); + public ImmutableList getOreList(); + public ImmutableList> getOreListWithChances(); + +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/BiomeBuilder.java deleted file mode 100644 index d06592a4..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/BiomeBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import javax.annotation.Nonnull; - -import com.mcmoddev.orespawn.api.BiomeLocation; - -import net.minecraft.world.biome.Biome; - -public interface BiomeBuilder { - // should have left this for @pau101 as he's the genius behind the BiomeLocation stuff - // but I'm on a roll :) - - BiomeBuilder whitelistBiome(@Nonnull Biome biome); - BiomeBuilder whitelistBiomeByName(@Nonnull String biomeName); - BiomeBuilder whitelistBiomeByDictionary(@Nonnull String biomeDictionaryName); - BiomeBuilder blacklistBiome(@Nonnull Biome biome); - BiomeBuilder blacklistBiomeByName(@Nonnull String biomeName); - BiomeBuilder blacklistBiomeByDictionary(@Nonnull String biomeDictionaryName); - BiomeBuilder setFromBiomeLocation(@Nonnull BiomeLocation biomes); - - BiomeLocation getBiomes(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/BuilderLogic.java b/src/main/java/com/mcmoddev/orespawn/api/os3/BuilderLogic.java deleted file mode 100644 index 2323a30a..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/BuilderLogic.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import javax.annotation.Nonnull; - -import com.google.common.collect.ImmutableMap; - -public interface BuilderLogic { - // at this level all we track are the dimensions, really - DimensionBuilder newDimensionBuilder(@Nonnull String name); // use "+" to mean "all overworld" - DimensionBuilder newDimensionBuilder(int id); // legacy support - referencing dimensions this way needs to stop - DimensionBuilder newDimensionBuilder(); // literally all dimensions - - // register dimension spawn data created with one of the DimensionBuilders - BuilderLogic create(@Nonnull DimensionBuilder... dimensions); - - DimensionBuilder getDimension(@Nonnull String name); - DimensionBuilder getDimension(int id); - ImmutableMap getAllDimensions(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java index b71e3fe2..11204ab0 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java @@ -1,14 +1,11 @@ -package com.mcmoddev.orespawn.api.os3; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; - -public interface DimensionBuilder { - SpawnBuilder newSpawnBuilder(@Nullable String name); - DimensionBuilder create(@Nonnull SpawnBuilder... spawns); - - ImmutableList getSpawnByName(@Nonnull String name); - ImmutableList getAllSpawns(); -} +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.DimensionList; + +public interface DimensionBuilder { + public DimensionBuilder addWhitelistEntry(final int dimensionID); + public DimensionBuilder addBlacklistEntry(final int dimensionID); + public DimensionBuilder setAcceptAll(); + public DimensionBuilder setDenyAll(); + public DimensionList create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionList.java deleted file mode 100644 index 27911963..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionList.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -public interface DimensionList { - boolean match(int dimensionId); - void create(int[] whitelist, int[] blacklist); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/FeatureBuilder.java deleted file mode 100644 index 71079a19..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/FeatureBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import javax.annotation.Nonnull; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.IFeature; - -public interface FeatureBuilder { - FeatureBuilder setGenerator(@Nonnull String name); - FeatureBuilder addParameter(@Nonnull String name, boolean value); - FeatureBuilder addParameter(@Nonnull String name, int value); - FeatureBuilder addParameter(@Nonnull String name, float value); - FeatureBuilder addParameter(@Nonnull String name, @Nonnull String value); - FeatureBuilder setParameters(@Nonnull JsonObject parameters); - FeatureBuilder setDefaultParameters(); - - IFeature getGenerator(); - JsonObject getParameters(); - String getFeatureName(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreBuilder.java deleted file mode 100644 index 394145d5..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import javax.annotation.Nonnull; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -public interface OreBuilder { - OreBuilder setOre(@Nonnull String name); - OreBuilder setOre(@Nonnull String name, @Nonnull String serializedState); - OreBuilder setOre(@Nonnull String name, int metaData); - OreBuilder setOre(@Nonnull Block base); - OreBuilder setOre(@Nonnull Block base, @Nonnull String serializedState); - OreBuilder setOre(@Nonnull Item base, int metaData); - OreBuilder setOre(@Nonnull ItemStack item); - // Allow specifying size as an extra parameter - for those cases where it could be meta - // or size, skip them to save a potential error condition - OreBuilder setOre(@Nonnull String name, @Nonnull String serializedState, int chance); - OreBuilder setOre(@Nonnull String name, int metaData, int chance); - OreBuilder setOre(@Nonnull Block base, @Nonnull String serializedState, int chance); - OreBuilder setOre(@Nonnull Item base, int metaData, int chance); - OreBuilder setOre(@Nonnull ItemStack item, int chance); - OreBuilder setChance(@Nonnull int chance); - - IBlockState getOre(); - int getChance(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java index 0b3b7b9a..85255a0d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java @@ -1,40 +1,38 @@ -package com.mcmoddev.orespawn.api.os3; - -import java.util.List; -import java.util.Random; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.util.OreList; - -import net.minecraft.block.state.IBlockState; - -public interface SpawnBuilder { - FeatureBuilder newFeatureBuilder(@Nullable String featureName); - BiomeBuilder newBiomeBuilder(); - OreBuilder newOreBuilder(); - SpawnBuilder create(@Nonnull BiomeBuilder biomes, @Nonnull FeatureBuilder feature, - @Nonnull List replacements, @Nonnull OreBuilder... ores); - SpawnBuilder create(@Nonnull BiomeBuilder biomes, @Nonnull FeatureBuilder feature, - @Nonnull List replacements, JsonObject exDim, - @Nonnull OreBuilder... ores); - - BiomeLocation getBiomes(); - ImmutableList getOres(); - ImmutableList getReplacementBlocks(); - FeatureBuilder getFeatureGen(); - - // added for OreSpawn 3.2 and version 1.2 of the config - OreBuilder getRandomOre(Random rand); - OreList getOreSpawns(); - boolean enabled(); - void enabled(boolean enabled); - boolean retrogen(); - void retrogen(boolean enabled); - boolean hasExtendedDimensions(); - boolean extendedDimensionsMatch(int dimension); -} +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.DimensionList; +import com.mcmoddev.orespawn.api.FeatureEntry; +import com.mcmoddev.orespawn.api.ReplacementEntry; +import com.mcmoddev.orespawn.api.SpawnEntry; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; + +public interface SpawnBuilder { + public SpawnBuilder setName(final String name); + public SpawnBuilder setDimensions(final DimensionList dimensions); + public SpawnBuilder setBiomes(final BiomeLocationComposition biomes); + public SpawnBuilder setEnabled(final boolean enabled); + public SpawnBuilder setRetrogen(final boolean retrogen); + public SpawnBuilder setReplacement(final ReplacementEntry replacements); + public SpawnBuilder setFeature(final FeatureEntry feature); + public SpawnBuilder addBlock(final String blockName); + public SpawnBuilder addBlock(final String blockName, final String blockState); + public SpawnBuilder addBlock(final String blockName, final int blockMetadata); + public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation); + public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState); + public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata); + public SpawnBuilder addBlock(final Block block); + public SpawnBuilder addBlock(final IBlockState block); + public SpawnBuilder addBlockWithChance(final String blockName, final int chance); + public SpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance); + public SpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance); + public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance); + public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance); + public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int blockMetadata, final int chance); + public SpawnBuilder addBlockWithChance(final Block block, final int chance); + public SpawnBuilder addBlockWithChance(final IBlockState block, final int chance); + public SpawnEntry create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java new file mode 100644 index 00000000..64c86889 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java @@ -0,0 +1,94 @@ +package com.mcmoddev.orespawn.impl.features; + +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +import com.google.common.collect.ImmutableSet; +import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; +import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; +import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class BiomeBuilder implements com.mcmoddev.orespawn.api.BiomeBuilder { + private final List whitelist = new LinkedList<>(); + private final List blacklist = new LinkedList<>(); + + private boolean acceptAll = false; + + public BiomeBuilder() { + + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(Biome biome) { + this.whitelist.add(biome); + return this; + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(String biomeName) { + return this.addWhitelistEntry(new ResourceLocation(biomeName)); + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation) { + return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(Biome biome) { + this.blacklist.add(biome); + return this; + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(String biomeName) { + return this.addBlacklistEntry(new ResourceLocation(biomeName)); + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation) { + return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public com.mcmoddev.orespawn.api.BiomeBuilder setAcceptAll() { + this.acceptAll = true; + return this; + } + + @Override + public BiomeLocation create() { + ImmutableSet whitelist; + ImmutableSet blacklist; + if (this.whitelist.size() == 0) { + whitelist = ImmutableSet.of(new BiomeLocationEmpty()); + } else { + whitelist = ImmutableSet.copyOf( + this.whitelist.stream() + .map( biome -> new BiomeLocationSingle(biome) ) + .collect(Collectors.toList())); + } + + if (this.blacklist.size() == 0) { + blacklist = ImmutableSet.of(new BiomeLocation() { + public boolean matches(Biome b) { + return true; + } + }); + } else { + blacklist = ImmutableSet.copyOf( + this.blacklist.stream() + .map( biome -> new BiomeLocationSingle(biome) ) + .collect(Collectors.toList())); + } + + return new BiomeLocationComposition(whitelist, blacklist); + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java new file mode 100644 index 00000000..8194aee1 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -0,0 +1,14 @@ +package com.mcmoddev.orespawn.impl.location; + +import com.mcmoddev.orespawn.api.BiomeLocation; + +import net.minecraft.world.biome.Biome; + +public class BiomeLocationEmpty implements BiomeLocation { + + @Override + public boolean matches(Biome biome) { + return false; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilderImpl.java deleted file mode 100644 index d50e16e8..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilderImpl.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import java.util.List; -import java.util.ArrayList; -import javax.annotation.Nonnull; - -import com.google.common.collect.ImmutableSet; -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.os3.BiomeBuilder; -import com.mcmoddev.orespawn.impl.location.*; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -public class BiomeBuilderImpl implements BiomeBuilder { - private List biomeWhitelist; - private List biomeBlacklist; - private BiomeLocation loc; - - BiomeBuilderImpl() { - this.biomeWhitelist = new ArrayList<>(); - this.biomeBlacklist = new ArrayList<>(); - } - - private Biome getBiomeByName(String name) { - return ForgeRegistries.BIOMES.getValue(new ResourceLocation(name)); - } - - private BiomeDictionary.Type getBiomeDictionaryType(String name) { - return BiomeDictionary.Type.getType(name); - } - - @Override - public BiomeBuilder whitelistBiome(@Nonnull Biome biome) { - this.biomeWhitelist.add(new BiomeLocationSingle(biome)); - return this; - } - - @Override - public BiomeBuilder whitelistBiomeByName(@Nonnull String biomeName) { - Biome b = getBiomeByName(biomeName); - BiomeLocation bL = new BiomeLocationSingle(b); - - if (!this.biomeWhitelist.contains(bL)) { - this.biomeWhitelist.add(bL); - } - - return this; - } - - @Override - public BiomeBuilder whitelistBiomeByDictionary(@Nonnull String biomeDictionaryName) { - this.biomeWhitelist.add(new BiomeLocationDictionary(getBiomeDictionaryType(biomeDictionaryName))); - return this; - } - - @Override - public BiomeBuilder blacklistBiome(@Nonnull Biome biome) { - this.biomeBlacklist.add(new BiomeLocationSingle(biome)); - return this; - } - - @Override - public BiomeBuilder blacklistBiomeByName(@Nonnull String biomeName) { - this.biomeBlacklist.add(new BiomeLocationSingle(getBiomeByName(biomeName))); - return this; - } - - @Override - public BiomeBuilder blacklistBiomeByDictionary(@Nonnull String biomeDictionaryName) { - this.biomeBlacklist.add(new BiomeLocationDictionary(getBiomeDictionaryType(biomeDictionaryName))); - return this; - } - - @Override - public BiomeLocation getBiomes() { - if (this.loc != null) { - return this.loc; - } - - if (!this.biomeBlacklist.isEmpty()) { - this.loc = new BiomeLocationComposition(ImmutableSet.copyOf(this.biomeWhitelist), - ImmutableSet.copyOf(this.biomeBlacklist)); - } else { - if (this.biomeWhitelist.size() == 1) { - this.loc = this.biomeWhitelist.toArray(new BiomeLocation[0])[0]; - } else { - this.loc = new BiomeLocationList(ImmutableSet.copyOf(this.biomeWhitelist)); - } - } - - return this.loc; - } - - @Override - public BiomeBuilder setFromBiomeLocation(@Nonnull BiomeLocation biomes) { - this.loc = biomes; - return this; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BuilderLogicImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BuilderLogicImpl.java deleted file mode 100644 index 26ebd491..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BuilderLogicImpl.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import com.google.common.collect.ImmutableMap; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; -import com.mcmoddev.orespawn.data.Constants; - -public class BuilderLogicImpl implements BuilderLogic { - private final Map dimensions; - - public BuilderLogicImpl() { - this.dimensions = new HashMap<>(); - } - - @Override - public DimensionBuilder newDimensionBuilder(String name) { - int id = this.dimensionNameToId(name); - - if (id == OreSpawn.API.dimensionWildcard()) { - return this.newDimensionBuilder(); - } - - return this.newDimensionBuilder(id); - } - - @Override - public DimensionBuilder newDimensionBuilder(int id) { - if (dimensions.containsKey(id)) { - return this.getDimension(id); - } - - DimensionBuilder db = new DimensionBuilderImpl(); - dimensions.put(id, db); - return db; - } - - @Override - public DimensionBuilder newDimensionBuilder() { - return this.newDimensionBuilder(OreSpawn.API.dimensionWildcard()); - } - - @Override - public BuilderLogic create(DimensionBuilder... dimensions) { - // for future expansion/orthagonality - return this; - } - - @Override - public DimensionBuilder getDimension(String name) { - Integer id = this.dimensionNameToId(name); - return this.getDimension(id); - } - - @Override - public DimensionBuilder getDimension(int id) { - if (dimensions.containsKey(id)) { - return dimensions.get(id); - } - - return null; - } - - @Override - public ImmutableMap getAllDimensions() { - return ImmutableMap.copyOf(dimensions); - } - - - private int dimensionNameToId(String name) { - switch (name.toLowerCase(Locale.ROOT)) { - case Constants.OVERWORLD: - case Constants.THE_OVERWORLD: - return 0; - - case Constants.NETHER: - case Constants.THE_NETHER: - return -1; - - case Constants.END: - case Constants.THE_END: - return 1; - - case "+": - default: - return OreSpawn.API.dimensionWildcard(); - } - } - -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java new file mode 100644 index 00000000..aeb09027 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -0,0 +1,54 @@ +package com.mcmoddev.orespawn.impl.os3; + +import java.util.LinkedList; +import java.util.List; + +public class DimensionBuilder implements com.mcmoddev.orespawn.api.os3.DimensionBuilder { + private final List dimensionWhitelist = new LinkedList<>(); + private final List dimensionBlacklist = new LinkedList<>(); + private boolean acceptAll = true; + private boolean denyAll = false; + + public DimensionBuilder() { + } + + @Override + public com.mcmoddev.orespawn.api.os3.DimensionBuilder addWhitelistEntry(int dimensionID) { + this.dimensionWhitelist.add(dimensionID); + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.DimensionBuilder addBlacklistEntry(int dimensionID) { + this.dimensionBlacklist.add(dimensionID); + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.DimensionBuilder setAcceptAll() { + if (this.denyAll) this.denyAll = false; + this.acceptAll = true; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.DimensionBuilder setDenyAll() { + if (this.acceptAll) this.acceptAll = false; + this.denyAll = true; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.DimensionList create() { + if (this.acceptAll || + ((this.dimensionWhitelist.size() == 0) && + (this.dimensionBlacklist.size() == 0))) { + return new DimensionListAcceptAll(); + } else if (this.denyAll) { + return new DimensionListDenyAll(); + } else { + return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); + } + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilderImpl.java deleted file mode 100644 index 68cb7fc6..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilderImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.annotation.Nullable; - -import com.google.common.collect.ImmutableList; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; - -public class DimensionBuilderImpl implements DimensionBuilder { - private static final String UNNAMED = "unnamed"; - private Map> spawns; - - public DimensionBuilderImpl() { - this.spawns = new HashMap<>(); - } - - @Override - public SpawnBuilder newSpawnBuilder(@Nullable String name) { - String entName = (name == null) ? UNNAMED : name; - spawns.computeIfAbsent(entName, tempName -> new ArrayList()); - SpawnBuilder sb = new SpawnBuilderImpl(); - spawns.get(entName).add(sb); - return sb; - } - - @Override - public DimensionBuilder create(SpawnBuilder... addedSpawns) { - return this; - } - - @Override - public ImmutableList getSpawnByName(String name) { - if (spawns.containsKey(name)) { - return ImmutableList.copyOf(spawns.get(name)); - } - - return null; - } - - @Override - public ImmutableList getAllSpawns() { - return ImmutableList.copyOf(spawns.values().stream().collect(Collectors.toList()).get(0)); - } - -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java new file mode 100644 index 00000000..79ba6910 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -0,0 +1,26 @@ +package com.mcmoddev.orespawn.impl.os3; + +import java.util.List; +import java.util.ArrayList; + +public class DimensionList implements com.mcmoddev.orespawn.api.DimensionList { + private final List whitelist = new ArrayList<>(); + private final List blacklist = new ArrayList<>(); + + public DimensionList(List whitelist, List blacklist) { + this.whitelist.addAll(whitelist); + this.blacklist.addAll(blacklist); + } + + @Override + public boolean matches(final int dimensionID) { + if (this.whitelist.contains(dimensionID)) return true; + if (this.blacklist.contains(dimensionID)) return false; + if (this.whitelist.size() > 0) return false; + if (this.blacklist.size() > 0) return true; + + // if it gets here, the whitelist and blacklist are empty... + // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... + return true; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java new file mode 100644 index 00000000..0e28f5e5 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -0,0 +1,11 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.DimensionList; + +public class DimensionListAcceptAll implements DimensionList { + @Override + @SuppressWarnings("unused") + public boolean matches(final int dimensionID) { + return true; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java new file mode 100644 index 00000000..f412b9c8 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -0,0 +1,11 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.DimensionList; + +public class DimensionListDenyAll implements DimensionList { + @Override + @SuppressWarnings("unused") + public boolean matches(final int dimensionID) { + return false; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListImpl.java deleted file mode 100644 index 043b8c05..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import com.mcmoddev.orespawn.api.os3.DimensionList; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -public class DimensionListImpl implements DimensionList { - private List whitelist; - private List blacklist; - - DimensionListImpl() { - this.whitelist = new LinkedList<> (); - this.blacklist = new LinkedList<> (); - } - - @Override - public boolean match(int dimensionId) { - return (whitelist.isEmpty() && blacklist.isEmpty() && dimensionId != -1 && dimensionId != 1) || - whitelist.contains(dimensionId) || !blacklist.contains(dimensionId); - } - - @Override - public void create(int[] whitelist, int[] blacklist) { - Arrays.stream(whitelist).map(Integer::new).forEach(this.whitelist::add); - Arrays.stream(blacklist).map(Integer::new).forEach(this.blacklist::add); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilderImpl.java deleted file mode 100644 index 51356609..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilderImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.api.os3.FeatureBuilder; -import com.mcmoddev.orespawn.impl.features.DefaultFeatureGenerator; - -public class FeatureBuilderImpl implements FeatureBuilder { - private String featureName; - private JsonObject parameters; - private IFeature feature; - - public FeatureBuilderImpl() { - this.featureName = "default"; - this.feature = new DefaultFeatureGenerator(); - this.parameters = new JsonObject(); - } - - @Override - public FeatureBuilder setGenerator(String name) { - if (OreSpawn.FEATURES.hasFeature(name)) { - this.featureName = name; - this.feature = OreSpawn.FEATURES.getFeature(name); - } - - return this; - } - - @Override - public FeatureBuilder addParameter(String name, boolean value) { - this.parameters.addProperty(name, value); - return this; - } - - @Override - public FeatureBuilder addParameter(String name, int value) { - this.parameters.addProperty(name, value); - return this; - } - - @Override - public FeatureBuilder addParameter(String name, float value) { - this.parameters.addProperty(name, value); - return this; - } - - @Override - public FeatureBuilder addParameter(String name, String value) { - this.parameters.addProperty(name, value); - return this; - } - - @Override - public FeatureBuilder setParameters(JsonObject parameters) { - this.parameters = parameters; - return this; - } - - @Override - public FeatureBuilder setDefaultParameters() { - this.parameters = this.feature.getDefaultParameters(); - return this; - } - - @Override - public IFeature getGenerator() { - return this.feature; - } - - @Override - public JsonObject getParameters() { - return this.parameters; - } - - @Override - public String getFeatureName() { - return this.featureName; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java deleted file mode 100644 index 264f9c51..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OreBuilderImpl.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.util.StateUtil; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -public class OreBuilderImpl implements OreBuilder { - private IBlockState ore; - private int chance; - - public OreBuilderImpl() { - this.ore = null; - this.chance = 100; - } - @Override - public OreBuilder setOre(String name) { - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name)); - - if (block == null) { - OreSpawn.LOGGER.warn("Block {} not found!", name); - return this; - } - - this.ore = block.getDefaultState(); - return this; - } - - @Override - public OreBuilder setOre(String name, String serializedState) { - this.setOre(name); - - if (this.ore == null) { - return this; - } - - this.ore = StateUtil.deserializeState(this.ore.getBlock(), serializedState); - return this; - } - - @SuppressWarnings("deprecation") - @Override - public OreBuilder setOre(String name, int metaData) { - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name)); - - if (block == null) { - return this; - } - - this.ore = block.getStateFromMeta(metaData); - return this; - } - - @Override - public OreBuilder setOre(Block base) { - this.ore = base.getDefaultState(); - return this; - } - - @Override - public OreBuilder setOre(Block base, String serializedState) { - this.ore = StateUtil.deserializeState(base, serializedState); - return this; - } - - @SuppressWarnings("deprecation") - @Override - public OreBuilder setOre(Item base, int metaData) { - this.ore = Block.getBlockFromItem(base).getStateFromMeta(metaData); - return this; - } - - @Override - public OreBuilder setOre(ItemStack item) { - return this.setOre(Block.getBlockFromItem(item.getItem())); - } - - @Override - public OreBuilder setOre(String name, String serializedState, int chance) { - return this.setOre(name, serializedState).setChance(chance); - } - - @Override - public OreBuilder setOre(String name, int metaData, int chance) { - return this.setOre(name, metaData).setChance(chance); - } - - @Override - public OreBuilder setOre(Block base, String serializedState, int chance) { - return this.setOre(base, serializedState).setChance(chance); - } - - @Override - public OreBuilder setOre(Item base, int metaData, int chance) { - return this.setOre(base, metaData).setChance(chance); - } - - @Override - public OreBuilder setOre(ItemStack item, int chance) { - return this.setOre(item).setChance(chance); - } - - @Override - public OreBuilder setChance(int chance) { - this.chance = chance; - return this; - } - - - @Override - public IBlockState getOre() { - return this.ore; - } - - @Override - public int getChance() { - return this.chance; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java new file mode 100644 index 00000000..5377079c --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -0,0 +1,183 @@ +package com.mcmoddev.orespawn.impl.os3; + +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang3.tuple.Pair; + +import com.mcmoddev.orespawn.api.DimensionList; +import com.mcmoddev.orespawn.api.FeatureEntry; +import com.mcmoddev.orespawn.api.ReplacementEntry; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; +import com.mcmoddev.orespawn.util.StateUtil; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class SpawnBuilder implements com.mcmoddev.orespawn.api.os3.SpawnBuilder { + private String spawnName; + private boolean enabled; + private boolean retrogen; + private List> blocks = new LinkedList<>(); + private FeatureEntry feature; + private BiomeLocationComposition biomes; + private DimensionList dimensions; + private ReplacementEntry replacements; + + public SpawnBuilder() { + this.enabled = false; + this.retrogen = false; + } + + public SpawnBuilder(final String spawnName) { + this(); + this.spawnName = spawnName; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setName(String name) { + this.spawnName = name; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setDimensions(DimensionList dimensions) { + this.dimensions = dimensions; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setBiomes(BiomeLocationComposition biomes) { + this.biomes = biomes; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setRetrogen(boolean retrogen) { + this.retrogen = retrogen; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setReplacement(ReplacementEntry replacements) { + this.replacements = replacements; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder setFeature(FeatureEntry feature) { + this.feature = feature; + return this; + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName) { + return this.addBlock(new ResourceLocation(blockName)); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName, String blockState) { + return this.addBlock(new ResourceLocation(blockName), blockState); + } + + @Override + @Deprecated + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName, int blockMetadata) { + return this.addBlock(new ResourceLocation(blockName), blockMetadata); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation, + String blockState) { + return this.addBlockWithChance(blockResourceLocation, blockState, 100); + } + + @Override + @Deprecated + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation, + int blockMetadata) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(Block block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(IBlockState block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, int chance) { + return this.addBlockWithChance( new ResourceLocation(blockName), chance); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, String blockState, + int chance) { + return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); + } + + @Override + @Deprecated + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, int blockMetadata, + int chance) { + return this.addBlockWithChance(blockName, blockMetadata, chance); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + int chance) { + IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + String blockState, int chance) { + Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + @Deprecated + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + int blockMetadata, int chance) { + IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(blockMetadata); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(Block block, int chance) { + IBlockState tempVar = block.getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(IBlockState block, int chance) { + this.blocks.add(Pair.of(block, chance)); + return this; + } + + @Override + public SpawnEntry create() { + return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, + this.biomes, this.replacements, this.blocks, this.feature); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilderImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilderImpl.java deleted file mode 100644 index 9c41e2d7..00000000 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilderImpl.java +++ /dev/null @@ -1,184 +0,0 @@ -package com.mcmoddev.orespawn.impl.os3; - -import com.google.common.collect.ImmutableList; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.os3.*; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.OreList; -import net.minecraft.block.state.IBlockState; -import org.apache.commons.lang3.ArrayUtils; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.*; - -public class SpawnBuilderImpl implements SpawnBuilder { - private BiomeLocation biomeLocs; - private FeatureBuilder featureGen; - private List replacementBlocks; - private List myOres; - private OreList oreList; - private boolean enabled = true; - private boolean retrogen = false; - private boolean extendedDimensionsBool = false; - private DimensionList extendedDimensions; - - SpawnBuilderImpl() { - this.biomeLocs = null; - this.featureGen = null; - this.replacementBlocks = new ArrayList<>(); - this.myOres = new ArrayList<>(); - } - - @Override - public FeatureBuilder newFeatureBuilder(@Nullable String featureName) { - String featName; - this.featureGen = new FeatureBuilderImpl(); - - if (OreSpawn.FEATURES.getFeature(featureName) == null || featureName == null) { - featName = "default"; - } else { - featName = featureName; - } - - this.featureGen.setGenerator(featName); - return this.featureGen; - } - - @Override - public BiomeBuilder newBiomeBuilder() { - return new BiomeBuilderImpl(); - } - - @Override - public OreBuilder newOreBuilder() { - return new OreBuilderImpl(); - } - - @Override - public SpawnBuilder create(@Nonnull BiomeBuilder biomes, @Nonnull FeatureBuilder feature, - @Nonnull List replacements, @Nonnull OreBuilder... ores) { - this.biomeLocs = biomes.getBiomes(); - this.featureGen = feature; - this.replacementBlocks.addAll(replacements); - - if (ores.length > 1) { - this.myOres.addAll(Arrays.asList(ores)); - } else { - this.myOres.add(ores[0]); - } - - return this; - } - - @Override - public SpawnBuilder create(@Nonnull BiomeBuilder biomes, @Nonnull FeatureBuilder feature, - @Nonnull List replacements, JsonObject exDim, - @Nonnull OreBuilder... ores) { - this.create(biomes, feature, replacements, ores); - - this.setupDimensionWhitelist(exDim); - return this; - } - - private void setupDimensionWhitelist(JsonObject exDim) { - JsonArray whitelist = exDim.getAsJsonArray(Constants.ConfigNames.DimensionStuff.INCLUDE); - JsonArray blacklist = exDim.getAsJsonArray(Constants.ConfigNames.DimensionStuff.EXCLUDE); - List tempW = new ArrayList<> (); - List tempB = new ArrayList<> (); - - if (whitelist != null) { - whitelist.forEach(it -> tempW.add(it.getAsInt())); - } - - if (blacklist != null) { - blacklist.forEach(it -> tempB.add(it.getAsInt())); - } - - this.extendedDimensionsBool = true; - this.extendedDimensions = new DimensionListImpl(); - this.extendedDimensions.create(ArrayUtils.toPrimitive(tempW.toArray(new Integer[0])), - ArrayUtils.toPrimitive(tempB.toArray(new Integer[0]))); - } - - @Override - public BiomeLocation getBiomes() { - return this.biomeLocs; - } - - @Override - public ImmutableList getOres() { - return ImmutableList.copyOf(this.myOres); - } - - @Override - public ImmutableList getReplacementBlocks() { - return ImmutableList.copyOf(this.replacementBlocks); - } - - @Override - public FeatureBuilder getFeatureGen() { - return this.featureGen; - } - - private void buildSpawnList() { - if (this.oreList != null) { - return; - } - - this.oreList = new OreList(); - - this.oreList.build(Collections.unmodifiableList(this.myOres)); - } - - @Override - public boolean enabled() { - return this.enabled; - } - - @Override - public void enabled(boolean enabled) { - this.enabled = enabled; - } - - @Override - public boolean retrogen() { - return this.retrogen; - } - - @Override - public void retrogen(boolean enabled) { - this.retrogen = enabled; - } - - @Override - public boolean hasExtendedDimensions() { - return this.extendedDimensionsBool; - } - - @Override - public boolean extendedDimensionsMatch(int dimension) { - return !this.extendedDimensionsBool || this.extendedDimensions.match(dimension); - } - - @Override - public OreBuilder getRandomOre(Random rand) { - if (this.oreList == null) { - this.buildSpawnList(); - } - - return this.oreList.getRandomOre(rand); - } - - @Override - public OreList getOreSpawns() { - if (this.oreList == null) { - this.buildSpawnList(); - } - - return this.oreList; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java new file mode 100644 index 00000000..60d442ed --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -0,0 +1,88 @@ +package com.mcmoddev.orespawn.impl.os3; + +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.tuple.Pair; + +import com.google.common.collect.ImmutableList; +import com.mcmoddev.orespawn.api.DimensionList; +import com.mcmoddev.orespawn.api.FeatureEntry; +import com.mcmoddev.orespawn.api.ReplacementEntry; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.block.state.pattern.BlockMatcher; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class SpawnEntry implements com.mcmoddev.orespawn.api.SpawnEntry { + private final String spawnName; + private final DimensionList dimensions; + private final ReplacementEntry replacements; + private final List> blocks; + private final BiomeLocationComposition biomes; + private final FeatureEntry feature; + private final boolean enabled; + private final boolean retrogen; + + public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, + final DimensionList dimensions, final BiomeLocationComposition biomes, + final ReplacementEntry replacements, final List> blocks, + final FeatureEntry feature) { + this.spawnName = spawnName; + this.enabled = enabled; + this.retrogen = retrogen; + this.dimensions = dimensions; + this.biomes = biomes; + this.replacements = replacements; + this.blocks = new LinkedList<>(); + this.blocks.addAll(blocks); + this.feature = feature; + } + + @Override + public String getSpawnName() { + return this.spawnName; + } + + @Override + public boolean dimensionAllowed(int dimension) { + return this.dimensions.matches(dimension); + } + + @Override + public boolean biomeAllowed(ResourceLocation biomeName) { + return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); + } + + @Override + public boolean biomeAllowed(Biome biome) { + return this.biomes.matches(biome); + } + + @Override + public FeatureEntry getFeature() { + return this.feature; + } + + @Override + public BlockMatcher getMatcher() { + return this.replacements.getMatcher(); + } + + @Override + public ImmutableList getOreList() { + return ImmutableList.copyOf(this.blocks.stream() + .map(pair -> pair.getLeft()) + .collect(Collectors.toList())); + } + + @Override + public ImmutableList> getOreListWithChances() { + return ImmutableList.copyOf(this.blocks); + } + +} From 404e5fbe2369f58d83ef2fcd83225c49c15e34f6 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 05:57:09 -0400 Subject: [PATCH 018/205] More work completed 1) Interfaces renamed to follow standards for class-name 2) Had some stuff in the wrong package - that is corrected 3) Implement the DimensionBuilder and BiomeBuilder 4) Implement the DimensionList stuff 5) Get a skeleton in place for the ReplacementBuilder 6) Other stuff I've likely forgotten ***___BIG NOTE___*** This commit is still a non-building one. There will be a patch-set rebuild and commit fixup prior to the actual Pull Request and merge for 3.3 --- .../com/mcmoddev/orespawn/EventHandlers.java | 24 ++-- .../java/com/mcmoddev/orespawn/OreSpawn.java | 6 +- .../mcmoddev/orespawn/api/BiomeBuilder.java | 15 --- .../mcmoddev/orespawn/api/FeatureEntry.java | 12 -- ...DimensionList.java => IDimensionList.java} | 2 +- .../com/mcmoddev/orespawn/api/IFeature.java | 3 +- .../orespawn/api/os3/DimensionBuilder.java | 11 -- .../orespawn/api/os3/IBiomeBuilder.java | 17 +++ .../orespawn/api/os3/IDimensionBuilder.java | 11 ++ .../orespawn/api/os3/IFeatureBuilder.java | 17 +++ .../orespawn/api/os3/IFeatureEntry.java | 13 ++ .../orespawn/api/os3/IReplacementBuilder.java | 19 +++ .../IReplacementEntry.java} | 4 +- .../orespawn/api/os3/ISpawnBuilder.java | 35 ++++++ .../{SpawnEntry.java => os3/ISpawnEntry.java} | 6 +- .../orespawn/api/os3/SpawnBuilder.java | 38 ------ .../orespawn/commands/AddOreCommand.java | 14 +-- .../orespawn/data/FeatureRegistry.java | 119 ++++++++---------- .../impl/{features => os3}/BiomeBuilder.java | 28 +++-- .../orespawn/impl/os3/DimensionBuilder.java | 14 ++- .../orespawn/impl/os3/DimensionList.java | 2 +- .../impl/os3/DimensionListAcceptAll.java | 4 +- .../impl/os3/DimensionListDenyAll.java | 4 +- .../orespawn/impl/os3/FeatureBuilder.java | 107 ++++++++++++++++ .../orespawn/impl/os3/FeatureEntry.java | 53 ++++++++ .../orespawn/impl/os3/OS3APIImpl.java | 8 +- .../orespawn/impl/os3/ReplacementBuilder.java | 71 +++++++++++ .../orespawn/impl/os3/SpawnBuilder.java | 61 ++++----- .../orespawn/impl/os3/SpawnEntry.java | 22 ++-- .../com/mcmoddev/orespawn/json/OS3Reader.java | 8 +- .../com/mcmoddev/orespawn/json/OS3Writer.java | 14 +-- .../orespawn/json/os3/readers/Helpers.java | 8 +- .../orespawn/worldgen/OreSpawnWorldGen.java | 10 +- 33 files changed, 526 insertions(+), 254 deletions(-) delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java rename src/main/java/com/mcmoddev/orespawn/api/{DimensionList.java => IDimensionList.java} (73%) delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java rename src/main/java/com/mcmoddev/orespawn/api/{ReplacementEntry.java => os3/IReplacementEntry.java} (53%) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java rename src/main/java/com/mcmoddev/orespawn/api/{SpawnEntry.java => os3/ISpawnEntry.java} (84%) delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java rename src/main/java/com/mcmoddev/orespawn/impl/{features => os3}/BiomeBuilder.java (69%) create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index f18dc064..e664bb31 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -10,10 +10,10 @@ import java.util.stream.Collectors; import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; -import com.mcmoddev.orespawn.api.os3.FeatureBuilder; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; +import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; @@ -63,7 +63,7 @@ public void onChunkSave(ChunkDataEvent.Save ev) { features.appendTag(new NBTTagString("orespawn:default")); - List spawns = OreSpawn.API.getSpawns().entrySet().stream() + List spawns = OreSpawn.API.getSpawns().entrySet().stream() .filter(ent -> ent.getValue().getAllDimensions().containsKey(ev.getWorld().provider.getDimension())) .map(ent -> ent.getValue().getDimension(ev.getWorld().provider.getDimension())) .collect(Collectors.toList()); @@ -75,18 +75,18 @@ public void onChunkSave(ChunkDataEvent.Save ev) { .collect(Collectors.toList())); } - List spc = new LinkedList<>(); + List spc = new LinkedList<>(); List oreList = new LinkedList<>(); - spawns.stream().map(DimensionBuilder::getAllSpawns).forEach(spc::addAll); - spc.stream().map(SpawnBuilder::getOres).forEach(oreList::addAll); + spawns.stream().map(IDimensionBuilder::getAllSpawns).forEach(spc::addAll); + spc.stream().map(ISpawnBuilder::getOres).forEach(oreList::addAll); oreList.stream() .map(oreEnt -> new NBTTagString(oreEnt.getOre().getBlock().getRegistryName().toString())) .forEach(ores::appendTag); - List featureList = new LinkedList<>(); + List featureList = new LinkedList<>(); - spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(SpawnBuilder::getFeatureGen).collect(Collectors.toList()))); + spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(ISpawnBuilder::getFeatureGen).collect(Collectors.toList()))); featureList.stream() .map(feat -> new NBTTagString(feat.getFeatureName())) @@ -129,7 +129,7 @@ private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim) { } private boolean compFeatures(NBTTagList tagList, int dim) { - List spawns = OreSpawn.API.getSpawns().entrySet().stream() + List spawns = OreSpawn.API.getSpawns().entrySet().stream() .filter(ent -> ent.getValue().getAllDimensions().containsKey(dim)) .map(ent -> ent.getValue().getDimension(dim)) .collect(Collectors.toList()); @@ -141,9 +141,9 @@ private boolean compFeatures(NBTTagList tagList, int dim) { .collect(Collectors.toList())); } - List featureList = new LinkedList<>(); + List featureList = new LinkedList<>(); - spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(SpawnBuilder::getFeatureGen).collect(Collectors.toList()))); + spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(ISpawnBuilder::getFeatureGen).collect(Collectors.toList()))); return featureList.size() == tagList.tagCount(); } diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 13dcbaa4..de88707f 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -11,7 +11,7 @@ import com.mcmoddev.orespawn.commands.DumpBiomesCommand; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.api.os3.OS3API; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.api.plugin.PluginLoader; import com.mcmoddev.orespawn.worldgen.FlatBedrock; @@ -54,11 +54,11 @@ public class OreSpawn { public static final OS3Writer writer = new OS3Writer(); static final EventHandlers eventHandlers = new EventHandlers(); public static final FeatureRegistry FEATURES = new FeatureRegistry(); - protected static final Map> spawns = new HashMap<>(); + protected static final Map> spawns = new HashMap<>(); static final FlatBedrock flatBedrock = new FlatBedrock(); - public static Map> getSpawns() { + public static Map> getSpawns() { return spawns; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java deleted file mode 100644 index 0e6f80f1..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeBuilder.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; - -public interface BiomeBuilder { - public BiomeBuilder addWhitelistEntry(final Biome biome); - public BiomeBuilder addWhitelistEntry(final String biomeName); - public BiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation); - public BiomeBuilder addBlacklistEntry(Biome biome); - public BiomeBuilder addBlacklistEntry(final String biomeName); - public BiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); - public BiomeBuilder setAcceptAll(); - public BiomeLocation create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java deleted file mode 100644 index 9a77d4fb..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureEntry.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mcmoddev.orespawn.api; -import com.google.gson.JsonObject; - -public interface FeatureEntry { - public IFeature getFeature(); - public String getFeatureName(); - public JsonObject getFeatureParameters(); - public void setStringParameter(final String parameterName, final String parameterValue); - public void setIntegerParameter(final String parameterName, final int parameterValue); - public void setBooleanParameter(final String parameterName, final boolean parameterValue); - public void setFloatParameter(final String parameterName, final float parameterValue); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java similarity index 73% rename from src/main/java/com/mcmoddev/orespawn/api/DimensionList.java rename to src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index f7a2622d..c16d7236 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -1,6 +1,6 @@ package com.mcmoddev.orespawn.api; -public interface DimensionList { +public interface IDimensionList { default public boolean matches(final int dimensionId) { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java index 30165c81..126494c9 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java @@ -6,9 +6,10 @@ import net.minecraft.world.World; import net.minecraft.world.gen.IChunkGenerator; +import net.minecraftforge.registries.IForgeRegistryEntry; import net.minecraft.world.chunk.IChunkProvider; -public interface IFeature { +public interface IFeature extends IForgeRegistryEntry { void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, GeneratorParameters parameters); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java deleted file mode 100644 index 11204ab0..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/DimensionBuilder.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.mcmoddev.orespawn.api.DimensionList; - -public interface DimensionBuilder { - public DimensionBuilder addWhitelistEntry(final int dimensionID); - public DimensionBuilder addBlacklistEntry(final int dimensionID); - public DimensionBuilder setAcceptAll(); - public DimensionBuilder setDenyAll(); - public DimensionList create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java new file mode 100644 index 00000000..14d25fd7 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -0,0 +1,17 @@ +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.BiomeLocation; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.biome.Biome; + +public interface IBiomeBuilder { + public IBiomeBuilder addWhitelistEntry(final Biome biome); + public IBiomeBuilder addWhitelistEntry(final String biomeName); + public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation); + public IBiomeBuilder addBlacklistEntry(Biome biome); + public IBiomeBuilder addBlacklistEntry(final String biomeName); + public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); + public IBiomeBuilder setAcceptAll(); + public BiomeLocation create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java new file mode 100644 index 00000000..d481b210 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -0,0 +1,11 @@ +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.IDimensionList; + +public interface IDimensionBuilder { + public IDimensionBuilder addWhitelistEntry(final int dimensionID); + public IDimensionBuilder addBlacklistEntry(final int dimensionID); + public IDimensionBuilder setAcceptAll(); + public IDimensionBuilder setDenyAll(); + public IDimensionList create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java new file mode 100644 index 00000000..ea64f930 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -0,0 +1,17 @@ +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.IFeature; + +import net.minecraft.util.ResourceLocation; + +public interface IFeatureBuilder { + public IFeatureBuilder setFeature(final String featureName); + public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation); + public IFeatureBuilder setFeature(final IFeature feature); + public IFeatureBuilder setParameter(final String parameterName, final String parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final int parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final float parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue); + public IFeatureBuilder setUseFeatureDefaults(); + public IFeatureEntry create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java new file mode 100644 index 00000000..738cd926 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java @@ -0,0 +1,13 @@ +package com.mcmoddev.orespawn.api.os3; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.api.IFeature; + +public interface IFeatureEntry { + public IFeature getFeature(); + public String getFeatureName(); + public JsonObject getFeatureParameters(); + public void setParameter(final String parameterName, final String parameterValue); + public void setParameter(final String parameterName, final int parameterValue); + public void setParameter(final String parameterName, final boolean parameterValue); + public void setParameter(final String parameterName, final float parameterValue); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java new file mode 100644 index 00000000..e5608601 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -0,0 +1,19 @@ +package com.mcmoddev.orespawn.api.os3; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; + +public interface IReplacementBuilder { + public IReplacementBuilder setFromName(final String entryName); + public IReplacementBuilder setName(final String name); + public IReplacementBuilder addEntry(final IBlockState blockState); + public IReplacementBuilder addEntry(final String blockName); + public IReplacementBuilder addEntry(final String blockName, final String state); + @Deprecated + public IReplacementBuilder addEntry(final String blockName, final int metadata); + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation); + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state); + @Deprecated + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata); + public IReplacementEntry create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java similarity index 53% rename from src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java rename to src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index ec3ff433..28060ae4 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -1,7 +1,7 @@ -package com.mcmoddev.orespawn.api; +package com.mcmoddev.orespawn.api.os3; import net.minecraft.block.state.pattern.BlockMatcher; -public interface ReplacementEntry { +public interface IReplacementEntry { public BlockMatcher getMatcher(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java new file mode 100644 index 00000000..277a8442 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -0,0 +1,35 @@ +package com.mcmoddev.orespawn.api.os3; + +import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; + +public interface ISpawnBuilder { + public ISpawnBuilder setName(final String name); + public ISpawnBuilder setDimensions(final IDimensionList dimensions); + public ISpawnBuilder setBiomes(final BiomeLocationComposition biomes); + public ISpawnBuilder setEnabled(final boolean enabled); + public ISpawnBuilder setRetrogen(final boolean retrogen); + public ISpawnBuilder setReplacement(final IReplacementEntry replacements); + public ISpawnBuilder setFeature(final IFeatureEntry feature); + public ISpawnBuilder addBlock(final String blockName); + public ISpawnBuilder addBlock(final String blockName, final String blockState); + public ISpawnBuilder addBlock(final String blockName, final int blockMetadata); + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation); + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState); + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata); + public ISpawnBuilder addBlock(final Block block); + public ISpawnBuilder addBlock(final IBlockState block); + public ISpawnBuilder addBlockWithChance(final String blockName, final int chance); + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance); + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance); + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance); + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance); + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int blockMetadata, final int chance); + public ISpawnBuilder addBlockWithChance(final Block block, final int chance); + public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance); + public ISpawnEntry create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java similarity index 84% rename from src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java rename to src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 0f22e9ab..666983ed 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -1,4 +1,4 @@ -package com.mcmoddev.orespawn.api; +package com.mcmoddev.orespawn.api.os3; import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.util.ResourceLocation; @@ -10,7 +10,7 @@ import net.minecraft.block.state.IBlockState; -public interface SpawnEntry { +public interface ISpawnEntry { default public boolean isEnabled() { return false; } @@ -23,7 +23,7 @@ default public boolean isRetrogen() { public boolean dimensionAllowed(final int dimension); public boolean biomeAllowed(final ResourceLocation biomeName); public boolean biomeAllowed(final Biome biome); - public FeatureEntry getFeature(); + public IFeatureEntry getFeature(); public BlockMatcher getMatcher(); public ImmutableList getOreList(); public ImmutableList> getOreListWithChances(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java deleted file mode 100644 index 85255a0d..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/SpawnBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.mcmoddev.orespawn.api.DimensionList; -import com.mcmoddev.orespawn.api.FeatureEntry; -import com.mcmoddev.orespawn.api.ReplacementEntry; -import com.mcmoddev.orespawn.api.SpawnEntry; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.ResourceLocation; - -public interface SpawnBuilder { - public SpawnBuilder setName(final String name); - public SpawnBuilder setDimensions(final DimensionList dimensions); - public SpawnBuilder setBiomes(final BiomeLocationComposition biomes); - public SpawnBuilder setEnabled(final boolean enabled); - public SpawnBuilder setRetrogen(final boolean retrogen); - public SpawnBuilder setReplacement(final ReplacementEntry replacements); - public SpawnBuilder setFeature(final FeatureEntry feature); - public SpawnBuilder addBlock(final String blockName); - public SpawnBuilder addBlock(final String blockName, final String blockState); - public SpawnBuilder addBlock(final String blockName, final int blockMetadata); - public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation); - public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState); - public SpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata); - public SpawnBuilder addBlock(final Block block); - public SpawnBuilder addBlock(final IBlockState block); - public SpawnBuilder addBlockWithChance(final String blockName, final int chance); - public SpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance); - public SpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance); - public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance); - public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance); - public SpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int blockMetadata, final int chance); - public SpawnBuilder addBlockWithChance(final Block block, final int chance); - public SpawnBuilder addBlockWithChance(final IBlockState block, final int chance); - public SpawnEntry create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 678ae6f7..4d98b815 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -3,10 +3,10 @@ import com.google.gson.*; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.os3.BiomeBuilder; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; -import com.mcmoddev.orespawn.api.os3.FeatureBuilder; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; +import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.data.Constants.ConfigNames; import com.mcmoddev.orespawn.util.StateUtil; @@ -117,8 +117,8 @@ private void setOre(JsonObject ore, JsonObject oreArgs) { } private void putFile(String file, JsonObject ore, int id) { - DimensionBuilder db = OreSpawn.API.getLogic(file).newDimensionBuilder(id); - SpawnBuilder sb = db.newSpawnBuilder(null); + IDimensionBuilder db = OreSpawn.API.getLogic(file).newDimensionBuilder(id); + ISpawnBuilder sb = db.newSpawnBuilder(null); OreBuilder ob = sb.newOreBuilder(); String b = ore.get(ConfigNames.BLOCK).getAsString(); ore.remove(ConfigNames.BLOCK); @@ -131,9 +131,9 @@ private void putFile(String file, JsonObject ore, int id) { ob.setOre(b, s); } - FeatureBuilder fb = sb.newFeatureBuilder(ConfigNames.DEFAULT); + IFeatureBuilder fb = sb.newFeatureBuilder(ConfigNames.DEFAULT); fb.setGenerator(ConfigNames.DEFAULT).setDefaultParameters().setParameters(ore); - BiomeBuilder bb = sb.newBiomeBuilder(); + IBiomeBuilder bb = sb.newBiomeBuilder(); IBlockState rep = ReplacementsRegistry.getDimensionDefault(id).get(0); List rl = new ArrayList<>(); rl.add(rep); diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index c45879fc..fde0860e 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -5,9 +5,8 @@ import java.lang.reflect.Constructor; import java.nio.charset.Charset; import java.util.Collections; -import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; +import java.util.TreeMap; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringEscapeUtils; @@ -21,85 +20,77 @@ import com.google.gson.JsonParser; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.impl.features.ClusterGenerator; -import com.mcmoddev.orespawn.impl.features.DefaultFeatureGenerator; -import com.mcmoddev.orespawn.impl.features.NormalCloudGenerator; -import com.mcmoddev.orespawn.impl.features.PrecisionGenerator; -import com.mcmoddev.orespawn.impl.features.VeinGenerator; import net.minecraft.crash.CrashReport; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.RegistryBuilder; public class FeatureRegistry { private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private Map features; - private Map featuresInverse; - - public FeatureRegistry() { - features = new HashMap<>(); - featuresInverse = new HashMap<>(); - IFeature defaultGen = new DefaultFeatureGenerator(); - features.put(Constants.DEFAULT_GEN, defaultGen); - featuresInverse.put(defaultGen, Constants.DEFAULT_GEN); - IFeature veinGen = new VeinGenerator(); - features.put(Constants.VEIN_GEN, veinGen); - featuresInverse.put(veinGen, Constants.VEIN_GEN); - IFeature normalCloudGen = new NormalCloudGenerator(); - features.put(Constants.NORMAL_CLOUD, normalCloudGen); - featuresInverse.put(normalCloudGen, Constants.NORMAL_CLOUD); - IFeature clusterGen = new ClusterGenerator(); - features.put(Constants.CLUSTERS, clusterGen); - featuresInverse.put(clusterGen, Constants.CLUSTERS); - IFeature precision = new PrecisionGenerator(); - features.put(Constants.PRECISION, precision); - featuresInverse.put(precision, Constants.PRECISION); + private static final IForgeRegistry registry = new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "feature_registry")) + .setType(IFeature.class) + .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO + .create(); + + private FeatureRegistry() { } - public Map getFeatures() { - return Collections.unmodifiableMap(features); + public static Map getFeatures() { + Map tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); + + return Collections.unmodifiableMap(tempMap); } - public String getFeatureName(IFeature feature) { - if (this.hasFeature(feature)) { - return this.featuresInverse.get(feature); - } else { - return Constants.DEFAULT_GEN; - } + public static String getFeatureName(IFeature feature) { + return feature.getRegistryName().toString(); } - public IFeature getFeature(String name) { - if (this.hasFeature(name)) { - return this.features.get(name); + public static IFeature getFeature(String name) { + return getFeature(new ResourceLocation(name)); + } + + public static IFeature getFeature(ResourceLocation featureResourceLocation) { + ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); + if (registry.containsKey(featureResourceLocation)) { + return registry.getValue(featureResourceLocation); } else { - return this.features.get(Constants.DEFAULT_GEN); + return registry.getValue(defaultGen); } } - public boolean hasFeature(String name) { - return features.containsKey(name); + public static boolean hasFeature(String name) { + return hasFeature(new ResourceLocation(name)); } - public boolean hasFeature(IFeature feature) { - return featuresInverse.containsKey(feature); + public static boolean hasFeature(ResourceLocation featureResourceLocation) { + return registry.containsKey(featureResourceLocation); + } + public static boolean hasFeature(IFeature feature) { + return registry.containsKey(feature.getRegistryName()); } - public void addFeature(String name, IFeature feature) { - this.addFeature(name, feature.getClass().getName()); + public static void addFeature(String name, IFeature feature) { + feature.setRegistryName(new ResourceLocation(name)); + registry.register(feature); } - public void addFeature(JsonObject entry) { - this.addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); + public static void addFeature(JsonObject entry) { + addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); } - public void addFeature(String name, String className) { + public static void addFeature(String name, String className) { IFeature feature = getInstance(className); - if (feature != null && !features.containsKey(name)) { - features.put(name, feature); - featuresInverse.put(feature, name); + if (feature != null && !hasFeature(name)) { + addFeature(name, feature); } } - private IFeature getInstance(String className) { + private static IFeature getInstance(String className) { Class featureClazz; Constructor featureCons; IFeature feature; @@ -118,7 +109,7 @@ private IFeature getInstance(String className) { return feature; } - public void loadFeaturesFile(File file) { + public static void loadFeaturesFile(File file) { JsonParser parser = new JsonParser(); String rawJson; JsonArray elements; @@ -135,23 +126,23 @@ public void loadFeaturesFile(File file) { elements = parser.parse(rawJson).getAsJsonArray(); for (JsonElement elem : elements) { - this.addFeature(elem.getAsJsonObject()); + addFeature(elem.getAsJsonObject()); } } - public void writeFeatures(File file) { + public static void writeFeatures(File file) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonArray root = new JsonArray(); - if (!features.equals(Collections.emptyMap())) { - for (Entry feature : features.entrySet()) { - JsonObject entry = new JsonObject(); - entry.addProperty("name", feature.getKey()); - entry.addProperty("class", feature.getValue().getClass().getName()); - root.add(entry); - } - } + registry.getEntries().stream() + .map( ent -> { + JsonObject e = new JsonObject(); + e.addProperty("name", ent.getKey().getResourcePath()); + e.addProperty("class", ent.getValue().getClass().getName()); + return e; + }) + .forEach( root::add ); String json = gson.toJson(root); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java similarity index 69% rename from src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java rename to src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 64c86889..d0242a21 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -1,4 +1,4 @@ -package com.mcmoddev.orespawn.impl.features; +package com.mcmoddev.orespawn.impl.os3; import java.util.LinkedList; import java.util.List; @@ -9,12 +9,13 @@ import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; +import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; -public class BiomeBuilder implements com.mcmoddev.orespawn.api.BiomeBuilder { +public class BiomeBuilder implements IBiomeBuilder { private final List whitelist = new LinkedList<>(); private final List blacklist = new LinkedList<>(); @@ -25,45 +26,54 @@ public BiomeBuilder() { } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(Biome biome) { + public IBiomeBuilder addWhitelistEntry(Biome biome) { this.whitelist.add(biome); return this; } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(String biomeName) { + public IBiomeBuilder addWhitelistEntry(String biomeName) { return this.addWhitelistEntry(new ResourceLocation(biomeName)); } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation) { + public IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation) { return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(Biome biome) { + public IBiomeBuilder addBlacklistEntry(Biome biome) { this.blacklist.add(biome); return this; } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(String biomeName) { + public IBiomeBuilder addBlacklistEntry(String biomeName) { return this.addBlacklistEntry(new ResourceLocation(biomeName)); } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation) { + public IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation) { return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); } @Override - public com.mcmoddev.orespawn.api.BiomeBuilder setAcceptAll() { + public IBiomeBuilder setAcceptAll() { this.acceptAll = true; return this; } @Override public BiomeLocation create() { + if (this.acceptAll) { + return new BiomeLocationComposition(ImmutableSet.of(new BiomeLocationEmpty()), + ImmutableSet.of(new BiomeLocation() { + public boolean matches(Biome b) { + return true; + } + })); + } + ImmutableSet whitelist; ImmutableSet blacklist; if (this.whitelist.size() == 0) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index aeb09027..72f16d9e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -2,8 +2,10 @@ import java.util.LinkedList; import java.util.List; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; +import com.mcmoddev.orespawn.api.IDimensionList; -public class DimensionBuilder implements com.mcmoddev.orespawn.api.os3.DimensionBuilder { +public class DimensionBuilder implements IDimensionBuilder { private final List dimensionWhitelist = new LinkedList<>(); private final List dimensionBlacklist = new LinkedList<>(); private boolean acceptAll = true; @@ -13,33 +15,33 @@ public DimensionBuilder() { } @Override - public com.mcmoddev.orespawn.api.os3.DimensionBuilder addWhitelistEntry(int dimensionID) { + public IDimensionBuilder addWhitelistEntry(int dimensionID) { this.dimensionWhitelist.add(dimensionID); return this; } @Override - public com.mcmoddev.orespawn.api.os3.DimensionBuilder addBlacklistEntry(int dimensionID) { + public IDimensionBuilder addBlacklistEntry(int dimensionID) { this.dimensionBlacklist.add(dimensionID); return this; } @Override - public com.mcmoddev.orespawn.api.os3.DimensionBuilder setAcceptAll() { + public IDimensionBuilder setAcceptAll() { if (this.denyAll) this.denyAll = false; this.acceptAll = true; return this; } @Override - public com.mcmoddev.orespawn.api.os3.DimensionBuilder setDenyAll() { + public IDimensionBuilder setDenyAll() { if (this.acceptAll) this.acceptAll = false; this.denyAll = true; return this; } @Override - public com.mcmoddev.orespawn.api.DimensionList create() { + public IDimensionList create() { if (this.acceptAll || ((this.dimensionWhitelist.size() == 0) && (this.dimensionBlacklist.size() == 0))) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 79ba6910..40032d01 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -3,7 +3,7 @@ import java.util.List; import java.util.ArrayList; -public class DimensionList implements com.mcmoddev.orespawn.api.DimensionList { +public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { private final List whitelist = new ArrayList<>(); private final List blacklist = new ArrayList<>(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index 0e28f5e5..e924c425 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -1,8 +1,8 @@ package com.mcmoddev.orespawn.impl.os3; -import com.mcmoddev.orespawn.api.DimensionList; +import com.mcmoddev.orespawn.api.IDimensionList; -public class DimensionListAcceptAll implements DimensionList { +public class DimensionListAcceptAll implements IDimensionList { @Override @SuppressWarnings("unused") public boolean matches(final int dimensionID) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index f412b9c8..fb23197e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -1,8 +1,8 @@ package com.mcmoddev.orespawn.impl.os3; -import com.mcmoddev.orespawn.api.DimensionList; +import com.mcmoddev.orespawn.api.IDimensionList; -public class DimensionListDenyAll implements DimensionList { +public class DimensionListDenyAll implements IDimensionList { @Override @SuppressWarnings("unused") public boolean matches(final int dimensionID) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java new file mode 100644 index 00000000..59ae50ad --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -0,0 +1,107 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; +import com.mcmoddev.orespawn.api.os3.IFeatureEntry; +import com.mcmoddev.orespawn.data.FeatureRegistry; + +import net.minecraft.util.ResourceLocation; + +public class FeatureBuilder implements IFeatureBuilder { + private IFeature feature; + private JsonObject parameters; + private boolean useDefaults; + + public FeatureBuilder() { + this.useDefaults = false; + this.parameters = new JsonObject(); + } + + @Override + public IFeatureBuilder setFeature(String featureName) { + return this.setFeature(new ResourceLocation(featureName)); + } + + @Override + public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { + if (!FeatureRegistry.hasFeature(featureResourceLocation)) { + OreSpawn.LOGGER.warn("Feature %s is not known, feature for this will be set to the default feature", featureResourceLocation.getResourcePath()); + } + return this.setFeature(FeatureRegistry.getFeature(featureResourceLocation)); + } + + @Override + public IFeatureBuilder setFeature(IFeature feature) { + this.feature = feature; + return this; + } + + @Override + public IFeatureBuilder setParameter(String parameterName, String parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(String parameterName, int parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(String parameterName, float parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(String parameterName, boolean parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + private void setFeatureParameter(String parameterName, JsonElement parameterValue, FeatureEntry feat) { + if (parameterValue.getAsJsonPrimitive().isBoolean()) { + feat.setParameter(parameterName,parameterValue.getAsBoolean()); + } else if (parameterValue.getAsJsonPrimitive().isString()) { + feat.setParameter(parameterName, parameterValue.getAsString()); + } else { + float paramAsFloat = parameterValue.getAsFloat(); + if ( (paramAsFloat - Math.floor(paramAsFloat)) > 0 ) { + feat.setParameter(parameterName, parameterValue.getAsFloat()); + } else { + feat.setParameter(parameterName, parameterValue.getAsInt()); + } + } + } + + @Override + public IFeatureBuilder setUseFeatureDefaults() { + this.useDefaults = true; + return this; + } + + @Override + public IFeatureEntry create() { + FeatureEntry res = new FeatureEntry(this.feature); + if (!this.useDefaults) { + // only copy in the parameters we need + this.feature.getDefaultParameters().entrySet().stream() + .filter(ent -> !this.parameters.has(ent.getKey())) + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } else { + // overwrite - they've said to just use the defaults + this.feature.getDefaultParameters().entrySet().stream() + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } + + this.parameters.entrySet().stream() + .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); + + return res; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java new file mode 100644 index 00000000..72aa4261 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -0,0 +1,53 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.IFeatureEntry; + +public class FeatureEntry implements IFeatureEntry { + public FeatureEntry(IFeature feature) { + + } + @Override + public IFeature getFeature() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getFeatureName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public JsonObject getFeatureParameters() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setParameter(String parameterName, String parameterValue) { + // TODO Auto-generated method stub + + } + + @Override + public void setParameter(String parameterName, int parameterValue) { + // TODO Auto-generated method stub + + } + + @Override + public void setParameter(String parameterName, boolean parameterValue) { + // TODO Auto-generated method stub + + } + + @Override + public void setParameter(String parameterName, float parameterValue) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 972a829f..fd07e461 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -11,9 +11,9 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; import com.mcmoddev.orespawn.api.os3.OS3API; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.util.OS3V2PresetStorage; import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; @@ -90,11 +90,11 @@ public ImmutableMap getSpawns() { @Override public void registerSpawns() { - Map> spawns = OreSpawn.getSpawns(); + Map> spawns = OreSpawn.getSpawns(); // build a proper tracking of data for the spawner for (Entry ent : logic.entrySet()) { - for (Entry dL : ent.getValue().getAllDimensions().entrySet()) { + for (Entry dL : ent.getValue().getAllDimensions().entrySet()) { if (spawns.containsKey(dL.getKey())) { spawns.get(dL.getKey()).addAll(dL.getValue().getAllSpawns()); } else { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java new file mode 100644 index 00000000..cfbd2bc7 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -0,0 +1,71 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; + +public class ReplacementBuilder implements IReplacementBuilder { + + @Override + public IReplacementBuilder setFromName(String entryName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder setName(String name) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(IBlockState blockState) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(String blockName) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(String blockName, String state) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(String blockName, int metadata) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IReplacementEntry create() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 5377079c..966cf952 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -5,26 +5,27 @@ import org.apache.commons.lang3.tuple.Pair; -import com.mcmoddev.orespawn.api.DimensionList; -import com.mcmoddev.orespawn.api.FeatureEntry; -import com.mcmoddev.orespawn.api.ReplacementEntry; +import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.util.StateUtil; +import com.mcmoddev.orespawn.api.os3.IFeatureEntry; +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; -public class SpawnBuilder implements com.mcmoddev.orespawn.api.os3.SpawnBuilder { +public class SpawnBuilder implements ISpawnBuilder { private String spawnName; private boolean enabled; private boolean retrogen; private List> blocks = new LinkedList<>(); - private FeatureEntry feature; + private IFeatureEntry feature; private BiomeLocationComposition biomes; - private DimensionList dimensions; - private ReplacementEntry replacements; + private IDimensionList dimensions; + private IReplacementEntry replacements; public SpawnBuilder() { this.enabled = false; @@ -37,118 +38,118 @@ public SpawnBuilder(final String spawnName) { } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setName(String name) { + public ISpawnBuilder setName(String name) { this.spawnName = name; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setDimensions(DimensionList dimensions) { + public ISpawnBuilder setDimensions(IDimensionList dimensions) { this.dimensions = dimensions; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setBiomes(BiomeLocationComposition biomes) { + public ISpawnBuilder setBiomes(BiomeLocationComposition biomes) { this.biomes = biomes; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setEnabled(boolean enabled) { + public ISpawnBuilder setEnabled(boolean enabled) { this.enabled = enabled; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setRetrogen(boolean retrogen) { + public ISpawnBuilder setRetrogen(boolean retrogen) { this.retrogen = retrogen; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setReplacement(ReplacementEntry replacements) { + public ISpawnBuilder setReplacement(IReplacementEntry replacements) { this.replacements = replacements; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder setFeature(FeatureEntry feature) { + public ISpawnBuilder setFeature(IFeatureEntry feature) { this.feature = feature; return this; } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName) { + public ISpawnBuilder addBlock(String blockName) { return this.addBlock(new ResourceLocation(blockName)); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName, String blockState) { + public ISpawnBuilder addBlock(String blockName, String blockState) { return this.addBlock(new ResourceLocation(blockName), blockState); } @Override @Deprecated - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(String blockName, int blockMetadata) { + public ISpawnBuilder addBlock(String blockName, int blockMetadata) { return this.addBlock(new ResourceLocation(blockName), blockMetadata); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation) { + public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation) { return this.addBlockWithChance(blockResourceLocation, 100); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation, + public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState) { return this.addBlockWithChance(blockResourceLocation, blockState, 100); } @Override @Deprecated - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(ResourceLocation blockResourceLocation, + public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata) { return this.addBlockWithChance(blockResourceLocation, 100); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(Block block) { + public ISpawnBuilder addBlock(Block block) { return this.addBlockWithChance(block, 100); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlock(IBlockState block) { + public ISpawnBuilder addBlock(IBlockState block) { return this.addBlockWithChance(block, 100); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, int chance) { + public ISpawnBuilder addBlockWithChance(String blockName, int chance) { return this.addBlockWithChance( new ResourceLocation(blockName), chance); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, String blockState, + public ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance) { return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); } @Override @Deprecated - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(String blockName, int blockMetadata, + public ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance) { return this.addBlockWithChance(blockName, blockMetadata, chance); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance) { IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, int chance) { Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); @@ -157,20 +158,20 @@ public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLoc @Override @Deprecated - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, int chance) { IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(blockMetadata); return this.addBlockWithChance(tempVar, chance); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(Block block, int chance) { + public ISpawnBuilder addBlockWithChance(Block block, int chance) { IBlockState tempVar = block.getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @Override - public com.mcmoddev.orespawn.api.os3.SpawnBuilder addBlockWithChance(IBlockState block, int chance) { + public ISpawnBuilder addBlockWithChance(IBlockState block, int chance) { this.blocks.add(Pair.of(block, chance)); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 60d442ed..9c9b3832 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -7,9 +7,9 @@ import org.apache.commons.lang3.tuple.Pair; import com.google.common.collect.ImmutableList; -import com.mcmoddev.orespawn.api.DimensionList; -import com.mcmoddev.orespawn.api.FeatureEntry; -import com.mcmoddev.orespawn.api.ReplacementEntry; +import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.api.os3.IFeatureEntry; +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.block.state.IBlockState; @@ -18,20 +18,20 @@ import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; -public class SpawnEntry implements com.mcmoddev.orespawn.api.SpawnEntry { +public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { private final String spawnName; - private final DimensionList dimensions; - private final ReplacementEntry replacements; + private final IDimensionList dimensions; + private final IReplacementEntry replacements; private final List> blocks; private final BiomeLocationComposition biomes; - private final FeatureEntry feature; + private final IFeatureEntry feature; private final boolean enabled; private final boolean retrogen; public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, - final DimensionList dimensions, final BiomeLocationComposition biomes, - final ReplacementEntry replacements, final List> blocks, - final FeatureEntry feature) { + final IDimensionList dimensions, final BiomeLocationComposition biomes, + final IReplacementEntry replacements, final List> blocks, + final IFeatureEntry feature) { this.spawnName = spawnName; this.enabled = enabled; this.retrogen = retrogen; @@ -64,7 +64,7 @@ public boolean biomeAllowed(Biome biome) { } @Override - public FeatureEntry getFeature() { + public IFeatureEntry getFeature() { return this.feature; } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java index 1f00619d..098b69cc 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java @@ -143,11 +143,11 @@ private static void finallyParse(JsonObject parseJson, String filename) { // at the top-most level we have the dimension sets work.entrySet().forEach(entry -> { int dimension = Integer.parseInt(entry.getKey()); - DimensionBuilder builder = logic.newDimensionBuilder(dimension); + IDimensionBuilder builder = logic.newDimensionBuilder(dimension); entry.getValue().getAsJsonArray().forEach(ore -> { try { JsonObject nw = ore.getAsJsonObject(); - SpawnBuilder spawn = builder.newSpawnBuilder(null); + ISpawnBuilder spawn = builder.newSpawnBuilder(null); // load the "ores" as "OreBuilder" - we should always have a "blocks" here, so... // filter out all null entries List blocks = Helpers.loadOres(nw.getAsJsonArray(ConfigNames.BLOCKS), spawn).stream() @@ -156,13 +156,13 @@ private static void finallyParse(JsonObject parseJson, String filename) { if (blocks.size() == 0) return; List replacements = getReplacements(nw.get(ConfigNames.V2.REPLACES).getAsString(), dimension); - BiomeBuilder biomes = spawn.newBiomeBuilder(); + IBiomeBuilder biomes = spawn.newBiomeBuilder(); if (nw.get(ConfigNames.BIOMES).isJsonObject()) { biomes.setFromBiomeLocation(Helpers.deserializeBiomeLocationComposition(nw.getAsJsonObject(ConfigNames.BIOMES))); } - FeatureBuilder gen = spawn.newFeatureBuilder(nw.get(ConfigNames.FEATURE).getAsString()); + IFeatureBuilder gen = spawn.newFeatureBuilder(nw.get(ConfigNames.FEATURE).getAsString()); gen.setDefaultParameters(); handleParameterFixes(nw); gen.setParameters(nw.getAsJsonObject(ConfigNames.PARAMETERS)); diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java index f8fe60c9..4cba4cb1 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java @@ -18,9 +18,9 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.DimensionBuilder; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Constants; import com.mcmoddev.orespawn.data.Constants.ConfigNames; import com.mcmoddev.orespawn.impl.location.*; @@ -48,7 +48,7 @@ public void writeSpawnEntries() { OreSpawn.API.getSpawns().entrySet().forEach(ent -> { JsonArray dimensions = new JsonArray(); - for (Entry dim : ent.getValue().getAllDimensions().entrySet()) { + for (Entry dim : ent.getValue().getAllDimensions().entrySet()) { JsonObject dimension = new JsonObject(); if (dim.getKey() != OreSpawn.API.dimensionWildcard()) { @@ -73,10 +73,10 @@ public void writeSpawnEntries() { }); } - private JsonArray genSpawns(ImmutableList allSpawns) { + private JsonArray genSpawns(ImmutableList allSpawns) { JsonArray rv = new JsonArray(); - for (SpawnBuilder spawn : allSpawns) { + for (ISpawnBuilder spawn : allSpawns) { if (spawn.getOres().isEmpty() || spawn.getOres().get(0).getOre() == null || "minecraft:air".equals(spawn.getOres().get(0).getOre().getBlock().getRegistryName().toString())) { @@ -101,7 +101,7 @@ private void writeFile(File file, JsonObject wrapper) { } } - private JsonObject genSpawn(SpawnBuilder spawn) { + private JsonObject genSpawn(ISpawnBuilder spawn) { JsonObject ore = new JsonObject(); ore.add(ConfigNames.BLOCKS, genBlocks(spawn.getOres())); @@ -195,7 +195,7 @@ public void writeAddOreEntry(String fileName) { JsonArray dimensions = new JsonArray(); - for (Entry dim : ent.getAllDimensions().entrySet()) { + for (Entry dim : ent.getAllDimensions().entrySet()) { JsonObject dimension = new JsonObject(); if (dim.getKey() != OreSpawn.API.dimensionWildcard()) { diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java index 9cf629b2..dffb58f3 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java +++ b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java @@ -11,7 +11,7 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Constants.ConfigNames; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.impl.location.BiomeLocationDictionary; @@ -101,7 +101,7 @@ private static void handleState(JsonObject ore, OreBuilder oreB, String oreName) } } - private static OreBuilder parseOreEntry(JsonObject oreSpawn, SpawnBuilder spawn) { + private static OreBuilder parseOreEntry(JsonObject oreSpawn, ISpawnBuilder spawn) { String blockName = oreSpawn.has(ConfigNames.BLOCK) ? ConfigNames.BLOCK : ConfigNames.BLOCK_V2; String oreName = oreSpawn.get(blockName).getAsString(); int chance = oreSpawn.has(ConfigNames.CHANCE) ? oreSpawn.get(ConfigNames.CHANCE).getAsInt() : 100; @@ -115,7 +115,7 @@ private static OreBuilder parseOreEntry(JsonObject oreSpawn, SpawnBuilder spawn) return thisOre; } - private static List loadOreDict(JsonObject oreObj, SpawnBuilder spawn) { + private static List loadOreDict(JsonObject oreObj, ISpawnBuilder spawn) { String oreName = oreObj.get(ConfigNames.BLOCK).getAsString().split(":")[1]; int chance = oreObj.has(ConfigNames.CHANCE) ? oreObj.get(ConfigNames.CHANCE).getAsInt() : 100; List retval = new ArrayList<>(); @@ -132,7 +132,7 @@ private static List loadOreDict(JsonObject oreObj, SpawnBuilder spaw return retval; } - public static List loadOres(JsonArray oresArray, SpawnBuilder spawn) { + public static List loadOres(JsonArray oresArray, ISpawnBuilder spawn) { List rV = new LinkedList<>(); oresArray.forEach(oreEntry -> { diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 57a4a891..0ca89975 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -7,7 +7,7 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.GeneratorParameters; import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.api.os3.SpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; import com.mcmoddev.orespawn.data.ReplacementsRegistry; @@ -25,10 +25,10 @@ public class OreSpawnWorldGen implements IWorldGenerator { - private final Map> dimensions; + private final Map> dimensions; private static final List SPAWN_BLOCKS = new ArrayList<>(); - public OreSpawnWorldGen(Map> allDimensions, long nextLong) { + public OreSpawnWorldGen(Map> allDimensions, long nextLong) { this.dimensions = Collections.unmodifiableMap(allDimensions); if (SPAWN_BLOCKS.isEmpty()) { @@ -48,7 +48,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG IChunkProvider chunkProvider) { int thisDim = world.provider.getDimension(); - List entries = new ArrayList<> (this.dimensions.getOrDefault(thisDim, new ArrayList<> ())); + List entries = new ArrayList<> (this.dimensions.getOrDefault(thisDim, new ArrayList<> ())); if (!this.dimensions.getOrDefault(OreSpawn.API.dimensionWildcard(), new ArrayList<>()).isEmpty()) entries.addAll(this.dimensions.get(OreSpawn.API.dimensionWildcard()).stream() @@ -57,7 +57,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG .collect(Collectors.toList())); entries.stream() - .filter(SpawnBuilder::enabled) + .filter(ISpawnBuilder::enabled) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.retrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) .forEach(sE -> { if (sE == null || sE.getFeatureGen() == null) { From 1560c965d75655805214f660140eb80d9033d2f2 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 07:20:29 -0400 Subject: [PATCH 019/205] ReplacementBuilder and related things done. Last is just writing the loading/saving code for the ReplacementsRegistry, doing the BlockBuilder and its related pieces and creating the _features.json and _replacements.json for OreSpawn - ie: the two things that cover the default values. --- .../orespawn/api/os3/IReplacementEntry.java | 5 +- .../orespawn/data/ReplacementsRegistry.java | 34 +++++++++++--- .../orespawn/impl/os3/ReplacementBuilder.java | 46 +++++++++++-------- .../orespawn/impl/os3/ReplacementEntry.java | 26 +++++++++++ 4 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index 28060ae4..2e72f834 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -1,7 +1,10 @@ package com.mcmoddev.orespawn.api.os3; +import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.pattern.BlockMatcher; +import net.minecraftforge.registries.IForgeRegistryEntry; -public interface IReplacementEntry { +public interface IReplacementEntry extends IForgeRegistryEntry { public BlockMatcher getMatcher(); + public IBlockState getBlockState(); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 840cb89e..991acb11 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -1,18 +1,29 @@ package com.mcmoddev.orespawn.data; import com.mcmoddev.orespawn.util.StateUtil; +import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; +import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; + import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; +import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.oredict.OreDictionary; +import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.RegistryBuilder; import java.util.*; import java.util.stream.Collectors; public class ReplacementsRegistry { - private static Map blocks = new HashMap<>(); + private static final IForgeRegistry registry = new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "replacements_registry")) + .setType(IReplacementEntry.class) + .setMaxID(65535) // 16 bits should be enough... + .create(); private ReplacementsRegistry() { } @@ -40,20 +51,29 @@ public static List getDimensionDefault(int dimension) { return baseRv; } - public static IBlockState getBlock(String name) { - return blocks.get(name); + public static IReplacementEntry getReplacement(String name) { + if (registry.containsKey(new ResourceLocation(name))) { + return registry.getValue(new ResourceLocation(name)); + } else { + return registry.getValue(new ResourceLocation("default")); + } } public static void addBlock(String name, String blockName, String blockState) { - Block nb = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - blocks.put(name, "default".equals(blockState) ? nb.getDefaultState() : StateUtil.deserializeState(nb, blockState)); + IBlockState b = StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + addBlock(name, b); } public static Map getBlocks() { - return Collections.unmodifiableMap(blocks); + Map tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getBlockState())); + + return Collections.unmodifiableMap(tempMap); } public static void addBlock(String name, IBlockState state) { - blocks.put(name, state); + IReplacementEntry r = new ReplacementEntry(name, state); + registry.register(r); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index cfbd2bc7..97d4a096 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -1,65 +1,73 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.LinkedList; +import java.util.List; + import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; +import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; public class ReplacementBuilder implements IReplacementBuilder { - + private String replacementName; + private List entries; + + public ReplacementBuilder() { + this.entries = new LinkedList<>(); + } + @Override public IReplacementBuilder setFromName(String entryName) { - // TODO Auto-generated method stub - return null; + this.replacementName = entryName; + this.entries.addAll(ReplacementsRegistry.getEntry(entryName)); + return this; } @Override public IReplacementBuilder setName(String name) { - // TODO Auto-generated method stub - return null; + this.replacementName = name; + return this; } @Override public IReplacementBuilder addEntry(IBlockState blockState) { - // TODO Auto-generated method stub - return null; + this.entries.add(blockState); + return this; } @Override public IReplacementBuilder addEntry(String blockName) { - // TODO Auto-generated method stub - return null; + return this.addEntry(new ResourceLocation(blockName)); } @Override public IReplacementBuilder addEntry(String blockName, String state) { - // TODO Auto-generated method stub - return null; + return this.addEntry(new ResourceLocation(blockName), state); } @Override + @Deprecated public IReplacementBuilder addEntry(String blockName, int metadata) { - // TODO Auto-generated method stub - return null; + return this.addEntry(new ResourceLocation(blockName), metadata); } @Override public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation) { - // TODO Auto-generated method stub - return null; + return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); } @Override public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state) { - // TODO Auto-generated method stub - return null; + return this.addEntry(StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); } @Override + @Deprecated public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata) { - // TODO Auto-generated method stub - return null; + return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java new file mode 100644 index 00000000..b6de7c5f --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -0,0 +1,26 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.block.state.pattern.BlockMatcher; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class ReplacementEntry extends IForgeRegistryEntry.Impl implements IReplacementEntry { + private final IBlockState matchVal; + + public ReplacementEntry(final String name, final IBlockState toMatch) { + super.setRegistryName(name); + this.matchVal = toMatch; + } + + @Override + public BlockMatcher getMatcher() { + return BlockMatcher.forBlock(this.matchVal.getBlock()); + } + + @Override + public IBlockState getBlockState() { + return this.matchVal; + } +} From 1bfc15f72ea0347a88c402395fd5d06e4cada426 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 08:31:07 -0400 Subject: [PATCH 020/205] More fixes for me not thinking clearly - includes a change to use a custom class for handling the matching of possible replacements instead of just BlockMatcher... which matches Block instances and not actual IBlockState sets. --- .../orespawn/api/os3/IReplacementEntry.java | 7 +++-- .../api/os3/OreSpawnBlockMatcher.java | 26 ++++++++++++++++ .../orespawn/data/ReplacementsRegistry.java | 31 ++++++++++++++++--- .../orespawn/impl/os3/ReplacementEntry.java | 21 +++++++------ 4 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index 2e72f834..c8017225 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -1,10 +1,11 @@ package com.mcmoddev.orespawn.api.os3; +import java.util.List; + import net.minecraft.block.state.IBlockState; -import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraftforge.registries.IForgeRegistryEntry; public interface IReplacementEntry extends IForgeRegistryEntry { - public BlockMatcher getMatcher(); - public IBlockState getBlockState(); + public OreSpawnBlockMatcher getMatcher(); + public List getEntries(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java new file mode 100644 index 00000000..e798706f --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -0,0 +1,26 @@ +package com.mcmoddev.orespawn.api.os3; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.function.Predicate; + +import net.minecraft.block.state.IBlockState; + +public class OreSpawnBlockMatcher implements Predicate { + private final List possibles; + + public OreSpawnBlockMatcher(final IBlockState...matches) { + this.possibles = Arrays.asList(matches); + } + + public OreSpawnBlockMatcher(final List matches) { + this.possibles = new ArrayList<>(); + Collections.copy(this.possibles, matches); + } + + public boolean test(final IBlockState other) { + return other != null && possibles.contains(other); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 991acb11..ab70aa3a 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -13,14 +13,17 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.registries.IForgeRegistry; +import net.minecraftforge.registries.IForgeRegistryModifiable; import net.minecraftforge.registries.RegistryBuilder; +import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; public class ReplacementsRegistry { - private static final IForgeRegistry registry = new RegistryBuilder() + private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() .setName(new ResourceLocation("orespawn", "replacements_registry")) + .allowModification() .setType(IReplacementEntry.class) .setMaxID(65535) // 16 bits should be enough... .create(); @@ -28,7 +31,7 @@ public class ReplacementsRegistry { private ReplacementsRegistry() { } - @SuppressWarnings("deprecation") + @Deprecated public static List getDimensionDefault(int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; List mineralogyOres = OreDictionary.getOres("cobblestone").stream() @@ -64,16 +67,34 @@ public static void addBlock(String name, String blockName, String blockState) { addBlock(name, b); } - public static Map getBlocks() { - Map tempMap = new TreeMap<>(); + public static Map> getBlocks() { + Map> tempMap = new TreeMap<>(); registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getBlockState())); + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); return Collections.unmodifiableMap(tempMap); } public static void addBlock(String name, IBlockState state) { + ResourceLocation regName = new ResourceLocation(name); + if (registry.containsKey(regName)) { + IReplacementEntry old = registry.getValue(regName); + IReplacementEntry newRE; + List oldList = old.getEntries(); + oldList.add(state); + IBlockState ents[] = new IBlockState[oldList.size()]; + newRE = new ReplacementEntry(name, oldList.toArray(ents)); + registry.remove(regName); + newRE.setRegistryName(regName); + registry.register(newRE); + return; + } + IReplacementEntry r = new ReplacementEntry(name, state); registry.register(r); } + + public static void loadFile(Path file) { + + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index b6de7c5f..d16c9e82 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -1,26 +1,29 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.Arrays; +import java.util.List; + +import com.google.common.collect.ImmutableList; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import net.minecraft.block.state.IBlockState; -import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraftforge.registries.IForgeRegistryEntry; public class ReplacementEntry extends IForgeRegistryEntry.Impl implements IReplacementEntry { - private final IBlockState matchVal; + private final List matchVal; - public ReplacementEntry(final String name, final IBlockState toMatch) { + public ReplacementEntry(final String name, final IBlockState...toMatch) { super.setRegistryName(name); - this.matchVal = toMatch; + this.matchVal = Arrays.asList(toMatch); } @Override - public BlockMatcher getMatcher() { - return BlockMatcher.forBlock(this.matchVal.getBlock()); + public OreSpawnBlockMatcher getMatcher() { + return new OreSpawnBlockMatcher(this.matchVal); } - @Override - public IBlockState getBlockState() { - return this.matchVal; + public List getEntries() { + return ImmutableList.copyOf(this.matchVal); } } From f1ac56aa29bd0e9fdd870a2458d55b5b5acbd38e Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 10:22:41 -0400 Subject: [PATCH 021/205] Only one major bit of infrastructure left - the "BlockList" that will handle working out which block from a list gets spawned. Should possibly have a variant that removes blocks as they are given to the spawner or should be the default... --- .../com/mcmoddev/orespawn/api/IBlockList.java | 5 + .../orespawn/api/os3/IBlockBuilder.java | 30 +++++ .../orespawn/api/os3/IBlockDefition.java | 8 ++ .../orespawn/api/os3/ISpawnEntry.java | 3 +- .../orespawn/data/ReplacementsRegistry.java | 70 ++++++++++- .../orespawn/impl/os3/BlockBuilder.java | 118 ++++++++++++++++++ .../orespawn/impl/os3/BlockDefinition.java | 26 ++++ .../orespawn/impl/os3/ReplacementBuilder.java | 6 +- .../orespawn/impl/os3/ReplacementEntry.java | 6 + .../orespawn/impl/os3/SpawnEntry.java | 14 ++- 10 files changed, 277 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/IBlockList.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java new file mode 100644 index 00000000..9d977364 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -0,0 +1,5 @@ +package com.mcmoddev.orespawn.api; + +public interface IBlockList { +// TODO: Define This +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java new file mode 100644 index 00000000..583677a8 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -0,0 +1,30 @@ +package com.mcmoddev.orespawn.api.os3; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; + +public interface IBlockBuilder { + public IBlockBuilder setFromBlockState(final IBlockState blockState); + public IBlockBuilder setFromBlock(final Block block); + public IBlockBuilder setFromName(final String blockName); + public IBlockBuilder setFromName(final String blockName, final String state); + @Deprecated + public IBlockBuilder setFromName(final String blockName, final int metadata); + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation); + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final String state); + @Deprecated + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final int metadata); + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance); + public IBlockBuilder setFromBlockWithChance(final Block block, final int chance); + public IBlockBuilder setFromNameWithChance(final String blockName, final int chance); + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, final int chance); + @Deprecated + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, final int chance); + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int chance); + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final String state, final int chance); + @Deprecated + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, final int chance); + public IBlockBuilder setChance(int chance); + public IBlockDefition create(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java new file mode 100644 index 00000000..42c11cfe --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java @@ -0,0 +1,8 @@ +package com.mcmoddev.orespawn.api.os3; + +import net.minecraft.block.state.IBlockState; + +public interface IBlockDefition { + public IBlockState getBlock(); + public int getChance(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 666983ed..e4792192 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -1,6 +1,5 @@ package com.mcmoddev.orespawn.api.os3; -import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; @@ -24,7 +23,7 @@ default public boolean isRetrogen() { public boolean biomeAllowed(final ResourceLocation biomeName); public boolean biomeAllowed(final Biome biome); public IFeatureEntry getFeature(); - public BlockMatcher getMatcher(); + public OreSpawnBlockMatcher getMatcher(); public ImmutableList getOreList(); public ImmutableList> getOreListWithChances(); diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index ab70aa3a..96a7308b 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -1,6 +1,12 @@ package com.mcmoddev.orespawn.data; import com.mcmoddev.orespawn.util.StateUtil; +import com.google.common.hash.Hashing; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; @@ -8,6 +14,7 @@ import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.pattern.BlockMatcher; +import net.minecraft.crash.CrashReport; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; @@ -16,11 +23,18 @@ import net.minecraftforge.registries.IForgeRegistryModifiable; import net.minecraftforge.registries.RegistryBuilder; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; + public class ReplacementsRegistry { + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() .setName(new ResourceLocation("orespawn", "replacements_registry")) .allowModification() @@ -82,8 +96,7 @@ public static void addBlock(String name, IBlockState state) { IReplacementEntry newRE; List oldList = old.getEntries(); oldList.add(state); - IBlockState ents[] = new IBlockState[oldList.size()]; - newRE = new ReplacementEntry(name, oldList.toArray(ents)); + newRE = new ReplacementEntry(name, oldList); registry.remove(regName); newRE.setRegistryName(regName); registry.register(newRE); @@ -95,6 +108,59 @@ public static void addBlock(String name, IBlockState state) { } public static void loadFile(Path file) { + JsonParser parser = new JsonParser(); + JsonObject elements; + String rawJson; + String modName = getModName(FilenameUtils.getBaseName(file.toString())); + + try { + rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getFileName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return; + } + + elements = parser.parse(rawJson).getAsJsonObject(); + elements.entrySet().stream() + .forEach( elem -> { + String entName = elem.getKey(); + JsonArray entries = elem.getValue().getAsJsonArray(); + List blocks = new LinkedList<>(); + for (JsonElement e : entries) { + JsonObject asObj = e.getAsJsonObject(); + String blockName = asObj.get(Constants.ConfigNames.BLOCK_V2).getAsString(); + String state = null; + if (asObj.has(Constants.ConfigNames.METADATA)) { + state = String.format("variant=%s", asObj.get(Constants.ConfigNames.METADATA).getAsInt()); + } else if(asObj.has(Constants.ConfigNames.STATE)) { + state = asObj.get(Constants.ConfigNames.STATE).getAsString(); + } + + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + if (state != null) { + blocks.add(StateUtil.deserializeState(block, state)); + } else { + blocks.add(block.getDefaultState()); + } + } + IReplacementEntry replacer = new ReplacementEntry(entName, blocks); + replacer.setRegistryName(new ResourceLocation(modName, entName)); + registry.register(replacer); + }); + } + + public void saveFile(String modName) { + // TODO: write this + } + + private static String getModName(String baseName) { + if(baseName.indexOf("-") > 0) { + String[] bits = baseName.split("-"); + return bits[1]; + } + return baseName; } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java new file mode 100644 index 00000000..00be6dc7 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -0,0 +1,118 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.os3.IBlockBuilder; +import com.mcmoddev.orespawn.api.os3.IBlockDefition; +import com.mcmoddev.orespawn.util.StateUtil; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +public class BlockBuilder implements IBlockBuilder { + private IBlockState blockState; + private int chance; + + public BlockBuilder() { + // nothing to do here + } + + @Override + public IBlockBuilder setFromBlockState(IBlockState blockState) { + return this.setFromBlockStateWithChance(blockState, 100); + } + + @Override + public IBlockBuilder setFromBlock(Block block) { + return this.setFromBlockState(block.getDefaultState()); + } + + @Override + public IBlockBuilder setFromName(String blockName) { + return this.setFromName(new ResourceLocation(blockName)); + } + + @Override + public IBlockBuilder setFromName(String blockName, String state) { + return this.setFromName(new ResourceLocation(blockName), state); + } + + @Override + public IBlockBuilder setFromName(String blockName, int metadata) { + return this.setFromName(new ResourceLocation(blockName), metadata); + } + + @Override + public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { + return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); + } + + @Override + public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state) { + Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); + } + + @Override + @Deprecated + public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata) { + Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); + } + + @Override + public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance) { + this.blockState = blockState; + this.chance = chance; + return this; + } + + @Override + public IBlockBuilder setFromBlockWithChance(Block block, int chance) { + return this.setFromBlockStateWithChance(block.getDefaultState(), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(String blockName, int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(String blockName, String state, int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance) { + return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, int chance) { + Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); + } + + @Override + @Deprecated + public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, int chance) { + Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); + } + + @Override + public IBlockBuilder setChance(int chance) { + this.chance = chance; + return this; + } + + @Override + public IBlockDefition create() { + return new BlockDefinition(this.blockState, this.chance); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java new file mode 100644 index 00000000..5dae9ee9 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -0,0 +1,26 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.os3.IBlockDefition; + +import net.minecraft.block.state.IBlockState; + +public class BlockDefinition implements IBlockDefition { + private final IBlockState blockState; + private final int blockChance; + + public BlockDefinition(final IBlockState blockState, final int chance) { + this.blockState = blockState; + this.blockChance = chance; + } + + @Override + public IBlockState getBlock() { + return this.blockState; + } + + @Override + public int getChance() { + return this.blockChance; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 97d4a096..fe6dc9cb 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -6,6 +6,7 @@ import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; +import com.mcmoddev.orespawn.data.ReplacementsRegistry; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; @@ -22,7 +23,7 @@ public ReplacementBuilder() { @Override public IReplacementBuilder setFromName(String entryName) { this.replacementName = entryName; - this.entries.addAll(ReplacementsRegistry.getEntry(entryName)); + this.entries.addAll(ReplacementsRegistry.getReplacement(entryName).getEntries()); return this; } @@ -72,8 +73,7 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int @Override public IReplacementEntry create() { - // TODO Auto-generated method stub - return null; + return new ReplacementEntry(this.replacementName, this.entries); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index d16c9e82..5d63b53c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -1,5 +1,6 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,6 +19,11 @@ public ReplacementEntry(final String name, final IBlockState...toMatch) { this.matchVal = Arrays.asList(toMatch); } + public ReplacementEntry(final String name, final List toMatch) { + super.setRegistryName(name); + this.matchVal = new ArrayList<>(); + this.matchVal.addAll(toMatch); + } @Override public OreSpawnBlockMatcher getMatcher() { return new OreSpawnBlockMatcher(this.matchVal); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 9c9b3832..09392788 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -10,10 +10,10 @@ import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.block.state.IBlockState; -import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; @@ -43,6 +43,16 @@ public SpawnEntry(final String spawnName, final boolean enabled, final boolean r this.feature = feature; } + @Override + public boolean isRetrogen() { + return this.retrogen; + } + + @Override + public boolean isEnabled() { + return this.enabled; + } + @Override public String getSpawnName() { return this.spawnName; @@ -69,7 +79,7 @@ public IFeatureEntry getFeature() { } @Override - public BlockMatcher getMatcher() { + public OreSpawnBlockMatcher getMatcher() { return this.replacements.getMatcher(); } From 10dc9d1ab468b27560aaeae1b003f2ef1f638916 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 11:56:33 -0400 Subject: [PATCH 022/205] Just have the OS3API centralizing/access point to do in the Infrastructure and the cleanups to the JSON loading and API users in the core code to manage. Then its just a matter of adding a couple data files. ...And, of course, handing off some of the fecking block loading code in the ReplacementsRegistry to the stuff in Helpers so people can use OreDictionary entries in the Replacements list. --- .../com/mcmoddev/orespawn/api/IBlockList.java | 10 ++- .../orespawn/api/os3/IBlockBuilder.java | 2 +- ...ockDefition.java => IBlockDefinition.java} | 5 +- .../orespawn/api/os3/ISpawnEntry.java | 10 +-- .../orespawn/impl/os3/BlockBuilder.java | 61 ++++++++++++++++++- .../orespawn/impl/os3/BlockDefinition.java | 12 +++- .../mcmoddev/orespawn/impl/os3/BlockList.java | 51 ++++++++++++++++ .../orespawn/impl/os3/FeatureEntry.java | 31 +++++----- .../orespawn/impl/os3/SpawnBuilder.java | 13 ++-- .../orespawn/impl/os3/SpawnEntry.java | 27 ++------ 10 files changed, 162 insertions(+), 60 deletions(-) rename src/main/java/com/mcmoddev/orespawn/api/os3/{IBlockDefition.java => IBlockDefinition.java} (59%) create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 9d977364..0fb056c9 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -1,5 +1,13 @@ package com.mcmoddev.orespawn.api; +import java.util.Random; + +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; + +import net.minecraft.block.state.IBlockState; + public interface IBlockList { -// TODO: Define This + public void addBlock(IBlockDefinition block); + public IBlockState getRandomBlock(Random rand); + public void startNewSpawn(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 583677a8..44867603 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -26,5 +26,5 @@ public interface IBlockBuilder { @Deprecated public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, final int chance); public IBlockBuilder setChance(int chance); - public IBlockDefition create(); + public IBlockDefinition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java similarity index 59% rename from src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java rename to src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index 42c11cfe..f1a9c010 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -2,7 +2,10 @@ import net.minecraft.block.state.IBlockState; -public interface IBlockDefition { +public interface IBlockDefinition { public IBlockState getBlock(); public int getChance(); + default public boolean isValid() { + return true; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index e4792192..8e7a2291 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -3,11 +3,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; -import org.apache.commons.lang3.tuple.Pair; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.block.state.IBlockState; +import com.mcmoddev.orespawn.api.IBlockList; public interface ISpawnEntry { default public boolean isEnabled() { @@ -24,7 +20,5 @@ default public boolean isRetrogen() { public boolean biomeAllowed(final Biome biome); public IFeatureEntry getFeature(); public OreSpawnBlockMatcher getMatcher(); - public ImmutableList getOreList(); - public ImmutableList> getOreListWithChances(); - + public IBlockList getBlocks(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index 00be6dc7..a6d0671d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -1,7 +1,7 @@ package com.mcmoddev.orespawn.impl.os3; import com.mcmoddev.orespawn.api.os3.IBlockBuilder; -import com.mcmoddev.orespawn.api.os3.IBlockDefition; +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.Block; @@ -12,6 +12,7 @@ public class BlockBuilder implements IBlockBuilder { private IBlockState blockState; private int chance; + private boolean isValid; public BlockBuilder() { // nothing to do here @@ -19,11 +20,23 @@ public BlockBuilder() { @Override public IBlockBuilder setFromBlockState(IBlockState blockState) { + ResourceLocation key = blockState.getBlock().getRegistryName(); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = true; + } else { + this.isValid = false; + } return this.setFromBlockStateWithChance(blockState, 100); } @Override public IBlockBuilder setFromBlock(Block block) { + ResourceLocation key = block.getRegistryName(); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = true; + } else { + this.isValid = false; + } return this.setFromBlockState(block.getDefaultState()); } @@ -44,11 +57,21 @@ public IBlockBuilder setFromName(String blockName, int metadata) { @Override public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); } @Override public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); } @@ -56,12 +79,23 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String @Override @Deprecated public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); } @Override public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance) { + ResourceLocation key = blockState.getBlock().getRegistryName(); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = true; + } else { + this.isValid = false; + } this.blockState = blockState; this.chance = chance; return this; @@ -69,6 +103,12 @@ public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int cha @Override public IBlockBuilder setFromBlockWithChance(Block block, int chance) { + ResourceLocation key = block.getRegistryName(); + if (ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = true; + } else { + this.isValid = false; + } return this.setFromBlockStateWithChance(block.getDefaultState(), chance); } @@ -89,11 +129,21 @@ public IBlockBuilder setFromNameWithChance(String blockName, int metadata, int c @Override public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), chance); } @Override public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, int chance) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); } @@ -101,6 +151,11 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio @Override @Deprecated public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, int chance) { + if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = true; + } else { + this.isValid = false; + } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); } @@ -112,7 +167,7 @@ public IBlockBuilder setChance(int chance) { } @Override - public IBlockDefition create() { - return new BlockDefinition(this.blockState, this.chance); + public IBlockDefinition create() { + return new BlockDefinition(this.blockState, this.chance, this.isValid); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java index 5dae9ee9..e3fec368 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -1,16 +1,18 @@ package com.mcmoddev.orespawn.impl.os3; -import com.mcmoddev.orespawn.api.os3.IBlockDefition; +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import net.minecraft.block.state.IBlockState; -public class BlockDefinition implements IBlockDefition { +public class BlockDefinition implements IBlockDefinition { private final IBlockState blockState; private final int blockChance; + private final boolean isValid; - public BlockDefinition(final IBlockState blockState, final int chance) { + public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { this.blockState = blockState; this.blockChance = chance; + this.isValid = isValid; } @Override @@ -23,4 +25,8 @@ public int getChance() { return this.blockChance; } + @Override + public boolean isValid() { + return this.isValid; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java new file mode 100644 index 00000000..9146838a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -0,0 +1,51 @@ +package com.mcmoddev.orespawn.impl.os3; + +import java.util.LinkedList; +import java.util.List; +import java.util.Random; + +import com.mcmoddev.orespawn.api.IBlockList; +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; + +import net.minecraft.block.state.IBlockState; + +public class BlockList implements IBlockList { + private final List myBlocks; + private List workingList; + + public BlockList() { + this.myBlocks = new LinkedList<>(); + this.workingList = new LinkedList<>(); + } + + @Override + public void addBlock(IBlockDefinition block) { + this.myBlocks.add(block); + } + + @Override + public IBlockState getRandomBlock(Random rand) { + if (this.workingList.size() == 0) { + this.startNewSpawn(); + } + + int spot = rand.nextInt(this.workingList.size()); + IBlockState rv = this.workingList.get(spot); + this.workingList.remove(spot); + return rv; + } + + @Override + public void startNewSpawn() { + this.workingList.clear(); + + this.myBlocks.stream() + .filter(b -> b.isValid()) + .forEach(b -> { + for(int i = 0; i < b.getChance(); i++) { + this.workingList.add(b.getBlock()); + } + }); + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 72aa4261..9cc0a90d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -5,49 +5,50 @@ import com.mcmoddev.orespawn.api.os3.IFeatureEntry; public class FeatureEntry implements IFeatureEntry { + private final IFeature feature; + private final JsonObject parameters; + public FeatureEntry(IFeature feature) { - + this.feature = feature; + this.parameters = new JsonObject(); } + @Override public IFeature getFeature() { - // TODO Auto-generated method stub - return null; + return this.feature; } @Override public String getFeatureName() { - // TODO Auto-generated method stub - return null; + return this.feature.getRegistryName().getResourcePath(); } @Override public JsonObject getFeatureParameters() { - // TODO Auto-generated method stub - return null; + JsonObject defs = feature.getDefaultParameters(); + this.parameters.entrySet().stream() + .forEach(ent -> defs.add(ent.getKey(), ent.getValue())); + return defs; } @Override public void setParameter(String parameterName, String parameterValue) { - // TODO Auto-generated method stub - + this.parameters.addProperty(parameterName, parameterValue); } @Override public void setParameter(String parameterName, int parameterValue) { - // TODO Auto-generated method stub - + this.parameters.addProperty(parameterName, parameterValue); } @Override public void setParameter(String parameterName, boolean parameterValue) { - // TODO Auto-generated method stub - + this.parameters.addProperty(parameterName, parameterValue); } @Override public void setParameter(String parameterName, float parameterValue) { - // TODO Auto-generated method stub - + this.parameters.addProperty(parameterName, parameterValue); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 966cf952..40d590d0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -1,10 +1,6 @@ package com.mcmoddev.orespawn.impl.os3; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.lang3.tuple.Pair; - +import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.util.StateUtil; @@ -21,7 +17,7 @@ public class SpawnBuilder implements ISpawnBuilder { private String spawnName; private boolean enabled; private boolean retrogen; - private List> blocks = new LinkedList<>(); + private IBlockList blocks; private IFeatureEntry feature; private BiomeLocationComposition biomes; private IDimensionList dimensions; @@ -30,6 +26,7 @@ public class SpawnBuilder implements ISpawnBuilder { public SpawnBuilder() { this.enabled = false; this.retrogen = false; + this.blocks = new BlockList(); } public SpawnBuilder(final String spawnName) { @@ -172,7 +169,9 @@ public ISpawnBuilder addBlockWithChance(Block block, int chance) { @Override public ISpawnBuilder addBlockWithChance(IBlockState block, int chance) { - this.blocks.add(Pair.of(block, chance)); + BlockBuilder bb = new BlockBuilder(); + bb.setFromBlockStateWithChance(block, chance); + this.blocks.addBlock(bb.create()); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 09392788..fcfc5029 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -1,19 +1,12 @@ package com.mcmoddev.orespawn.impl.os3; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.tuple.Pair; - -import com.google.common.collect.ImmutableList; +import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; -import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; @@ -22,7 +15,7 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { private final String spawnName; private final IDimensionList dimensions; private final IReplacementEntry replacements; - private final List> blocks; + private final IBlockList blocks; private final BiomeLocationComposition biomes; private final IFeatureEntry feature; private final boolean enabled; @@ -30,7 +23,7 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, final IDimensionList dimensions, final BiomeLocationComposition biomes, - final IReplacementEntry replacements, final List> blocks, + final IReplacementEntry replacements, final IBlockList blocks, final IFeatureEntry feature) { this.spawnName = spawnName; this.enabled = enabled; @@ -38,8 +31,7 @@ public SpawnEntry(final String spawnName, final boolean enabled, final boolean r this.dimensions = dimensions; this.biomes = biomes; this.replacements = replacements; - this.blocks = new LinkedList<>(); - this.blocks.addAll(blocks); + this.blocks = blocks; this.feature = feature; } @@ -84,15 +76,8 @@ public OreSpawnBlockMatcher getMatcher() { } @Override - public ImmutableList getOreList() { - return ImmutableList.copyOf(this.blocks.stream() - .map(pair -> pair.getLeft()) - .collect(Collectors.toList())); - } - - @Override - public ImmutableList> getOreListWithChances() { - return ImmutableList.copyOf(this.blocks); + public IBlockList getBlocks() { + return this.blocks; } } From a1154cff0ece0cace7cd44fd89930357a8819f35 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 25 Mar 2018 22:39:11 -0400 Subject: [PATCH 023/205] add my notes to the .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4f38052b..4fd03c87 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ run /forge-*-changelog.txt .DS_Store .DS_Store/* +OS3 API Redesign Notes.txt From 48c7bd939f8a059c5ee976f320978bd14d9fd16c Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 26 Mar 2018 17:49:05 -0400 Subject: [PATCH 024/205] Finish the infrastructure and config loading work. --- .../api/exceptions/BadValueException.java | 20 + .../exceptions/MissingVersionException.java | 5 + .../exceptions/NotAProperConfigException.java | 5 + .../api/exceptions/OldVersionException.java | 5 + .../api/exceptions/UnknownFieldException.java | 17 + .../api/exceptions/UnknownNameException.java | 20 + .../exceptions/UnknownVersionException.java | 5 + .../orespawn/api/os3/IBiomeBuilder.java | 3 +- .../orespawn/api/os3/IDimensionBuilder.java | 1 + .../orespawn/api/os3/IFeatureBuilder.java | 2 + .../com/mcmoddev/orespawn/api/os3/OS3API.java | 50 +-- .../orespawn/api/os3/package-info.java | 2 + .../com/mcmoddev/orespawn/data/Constants.java | 34 +- .../orespawn/data/FeatureRegistry.java | 26 +- .../orespawn/data/PresetsStorage.java | 96 +++++ .../orespawn/data/ReplacementsRegistry.java | 112 +++-- .../orespawn/impl/os3/BiomeBuilder.java | 2 +- .../orespawn/impl/os3/DimensionBuilder.java | 13 +- .../os3/DimensionListAcceptAllOverworld.java | 11 + .../orespawn/impl/os3/FeatureBuilder.java | 10 +- .../orespawn/impl/os3/OS3APIImpl.java | 207 +++++++--- .../orespawn/impl/os3/ReplacementBuilder.java | 3 +- .../com/mcmoddev/orespawn/json/OS3Reader.java | 240 ----------- .../com/mcmoddev/orespawn/json/OS3Writer.java | 227 ----------- .../orespawn/json/OreSpawnReader.java | 382 +++++++++++++++--- .../mcmoddev/orespawn/json/Replacements.java | 81 ---- .../orespawn/json/os3/IOS3Reader.java | 173 -------- .../orespawn/json/os3/readers/Helpers.java | 158 -------- .../json/os3/readers/OS3V1Reader.java | 75 ---- .../json/os3/readers/OS3V2Reader.java | 105 ----- .../orespawn/util/OS3V2PresetStorage.java | 42 -- .../com/mcmoddev/orespawn/util/OreList.java | 70 ---- 32 files changed, 811 insertions(+), 1391 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java create mode 100644 src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/Replacements.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/os3/IOS3Reader.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V2Reader.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/util/OS3V2PresetStorage.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/util/OreList.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java new file mode 100644 index 00000000..8a78c6ba --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -0,0 +1,20 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class BadValueException extends Exception { + private static final long serialVersionUID = 1143938140559149506L; + private String keyName; + private String keyValue; + + public BadValueException(String keyName, String keyValue) { + super(); + this.keyName = keyName; + this.keyValue = keyValue; + } + + @Override + public String getMessage() { + String baseMessage = super.getMessage(); + String fullMessage = String.format("Unknown value %s for key %s\n%s", this.keyValue, this.keyName, baseMessage); + return fullMessage; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java new file mode 100644 index 00000000..4f6f339b --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java @@ -0,0 +1,5 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class MissingVersionException extends Exception { + +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java new file mode 100644 index 00000000..3d4c908f --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java @@ -0,0 +1,5 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class NotAProperConfigException extends Exception { + +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java new file mode 100644 index 00000000..e9bbb3c2 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java @@ -0,0 +1,5 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class OldVersionException extends Exception { + +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java new file mode 100644 index 00000000..dd928a58 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -0,0 +1,17 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class UnknownFieldException extends Exception { + private static final long serialVersionUID = 1L; + private String message; + + public UnknownFieldException(String theField) { + super(); + this.message = String.format("Unkown field %s in config", theField); + } + + @Override + public String getMessage() { + String baseMessage = super.getMessage(); + return String.format("%s\n%s", this.message, baseMessage); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java new file mode 100644 index 00000000..623d3e39 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -0,0 +1,20 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class UnknownNameException extends Exception { + private static final long serialVersionUID = -3426121906665390773L; + private String fieldName; + private String fieldValue; + + public UnknownNameException(String fieldName, String fieldValue) { + super(); + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } + + @Override + public String getMessage() { + String baseMessage = super.getMessage(); + String fullMessage = String.format("Unknown %s name %s\n%s", this.fieldName, this.fieldValue, baseMessage); + return fullMessage; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java new file mode 100644 index 00000000..9cd2a6b3 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java @@ -0,0 +1,5 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class UnknownVersionException extends Exception { + +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index 14d25fd7..f8586e2a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -1,6 +1,7 @@ package com.mcmoddev.orespawn.api.os3; import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; @@ -13,5 +14,5 @@ public interface IBiomeBuilder { public IBiomeBuilder addBlacklistEntry(final String biomeName); public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); public IBiomeBuilder setAcceptAll(); - public BiomeLocation create(); + public BiomeLocationComposition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java index d481b210..c5114937 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -7,5 +7,6 @@ public interface IDimensionBuilder { public IDimensionBuilder addBlacklistEntry(final int dimensionID); public IDimensionBuilder setAcceptAll(); public IDimensionBuilder setDenyAll(); + public IDimensionBuilder setAcceptAllOverworld(); public IDimensionList create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index ea64f930..1959160b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -1,5 +1,6 @@ package com.mcmoddev.orespawn.api.os3; +import com.google.gson.JsonElement; import com.mcmoddev.orespawn.api.IFeature; import net.minecraft.util.ResourceLocation; @@ -12,6 +13,7 @@ public interface IFeatureBuilder { public IFeatureBuilder setParameter(final String parameterName, final int parameterValue); public IFeatureBuilder setParameter(final String parameterName, final float parameterValue); public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final JsonElement parameterValue); public IFeatureBuilder setUseFeatureDefaults(); public IFeatureEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index 17e6c7eb..d754b1d7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -1,33 +1,33 @@ package com.mcmoddev.orespawn.api.os3; -import javax.annotation.Nonnull; +import java.util.List; +import java.util.Map; -import com.google.common.collect.ImmutableMap; import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.util.OS3V2PresetStorage; -import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; +import com.mcmoddev.orespawn.data.PresetsStorage; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; +import net.minecraft.util.ResourceLocation; public interface OS3API { - int dimensionWildcard(); - int biomeWildcard(); - - // register replacement blocks - void registerReplacementBlock(@Nonnull String name, @Nonnull Block itemBlock); - void registerReplacementBlock(@Nonnull String name, @Nonnull IBlockState itemBlock); - - //register feature generators - void registerFeatureGenerator(@Nonnull String name, @Nonnull IFeature feature); - void registerFeatureGenerator(@Nonnull String name, @Nonnull Class feature); - void registerFeatureGenerator(@Nonnull String name, @Nonnull String className); - - BuilderLogic getLogic(@Nonnull String name); - void registerLogic(@Nonnull BuilderLogic logic); - ImmutableMap getSpawns(); - void registerSpawns(); - - OreSpawnWorldGen getGenerator(); - OS3V2PresetStorage getPresets(); + public void addSpawn(ISpawnEntry spawnEntry); + public void addFeature(String featureName, IFeature feature); + public void addReplacement(IReplacementEntry replacementEntry); + + public Map getReplacements(); + public IReplacementEntry getReplacement(String replacementName); + public List getSpawns(int dimensionID); + public ISpawnEntry getSpawn(String spawnName); + public Map getAllSpawns(); + + public ISpawnBuilder getSpawnBuilder(); + public IDimensionBuilder getDimensionBuilder(); + public IFeatureBuilder getFeatureBuilder(); + public IBlockBuilder getBlockBuilder(); + public IBiomeBuilder getBiomeBuilder(); + public IReplacementBuilder getReplacementBuilder(); + public boolean featureExists(String featureName); + public boolean featureExists(ResourceLocation featureName); + public IFeature getFeature(String featureName); + public IFeature getFeature(ResourceLocation featureName); + public PresetsStorage copyPresets(); } \ No newline at end of file diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java b/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java new file mode 100644 index 00000000..3db5c1b9 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java @@ -0,0 +1,2 @@ +@javax.annotation.ParametersAreNonnullByDefault +package com.mcmoddev.orespawn.api.os3; diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index afd88567..b2faccb4 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -1,5 +1,8 @@ package com.mcmoddev.orespawn.data; +import java.nio.file.Path; +import java.nio.file.Paths; + public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; @@ -29,7 +32,9 @@ public class Constants { public static final String BEDROCK_LAYERS = "Bedrock Thickness"; public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; public static final String PRECISION = "precision"; - + public static final Path CONFDIR = Paths.get("config", "orespawn3"); + public static final Path SYSCONF = Paths.get("config", "orespawn3", "sysconf"); + public final class FormatBits { private FormatBits() {} @@ -65,20 +70,23 @@ private ConfigNames() {} public static final String DIMENSION = "dimension"; public static final String ORES = "ores"; public static final String DIMENSIONS = "dimensions"; - public static final String BLOCKID = "blockID"; - public static final String BLOCK = "block"; - public static final String BLOCKS = "blocks"; public static final String CHANCE = "chance"; public static final String METADATA = "metaData"; public static final String BIOMES = "biomes"; public static final String STATE = "state"; - public static final String REPLACEMENT = "replace_block"; - public static final String REPLACEMENT_V2 = "replaces"; + public static final String REPLACEMENT = "replaces"; public static final String FEATURE = "feature"; public static final String PARAMETERS = "parameters"; public static final String FILE_VERSION = "version"; - public static final String BLOCK_V2 = "name"; - + public static final String BLOCK = "name"; + public static final String SPAWNS = "spawns"; + public static final String RETROGEN = "retrogen"; + public static final String ENABLED = "enabled"; + public static final String NAME = "name"; + public static final String WHITELIST = "includes"; + public static final String BLACKLIST = "excludes"; + public static final String PRESETS = "presets"; + public final class V2 { private V2() {} public static final String ENABLED = "enabled"; @@ -89,11 +97,6 @@ private V2() {} public static final String MAXIMUM = "maximum"; } - public final class BiomeStuff { - private BiomeStuff() {} - public static final String WHITELIST = "includes"; - public static final String BLACKLIST = "excludes"; - } public final class DefaultFeatureProperties { private DefaultFeatureProperties() {} public static final String SIZE = "size"; @@ -102,10 +105,5 @@ private DefaultFeatureProperties() {} public static final String MAXHEIGHT = "maxHeight"; public static final String MINHEIGHT = "minHeight"; } - public final class DimensionStuff { - private DimensionStuff() {} - public static final String INCLUDE = "includes"; - public static final String EXCLUDE = "excludes"; - } } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index fde0860e..09eebfc4 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -34,10 +34,10 @@ public class FeatureRegistry { .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO .create(); - private FeatureRegistry() { + public FeatureRegistry() { } - public static Map getFeatures() { + public Map getFeatures() { Map tempMap = new TreeMap<>(); registry.getEntries().stream() .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); @@ -45,15 +45,15 @@ public static Map getFeatures() { return Collections.unmodifiableMap(tempMap); } - public static String getFeatureName(IFeature feature) { + public String getFeatureName(IFeature feature) { return feature.getRegistryName().toString(); } - public static IFeature getFeature(String name) { + public IFeature getFeature(String name) { return getFeature(new ResourceLocation(name)); } - public static IFeature getFeature(ResourceLocation featureResourceLocation) { + public IFeature getFeature(ResourceLocation featureResourceLocation) { ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); if (registry.containsKey(featureResourceLocation)) { return registry.getValue(featureResourceLocation); @@ -62,27 +62,27 @@ public static IFeature getFeature(ResourceLocation featureResourceLocation) { } } - public static boolean hasFeature(String name) { + public boolean hasFeature(String name) { return hasFeature(new ResourceLocation(name)); } - public static boolean hasFeature(ResourceLocation featureResourceLocation) { + public boolean hasFeature(ResourceLocation featureResourceLocation) { return registry.containsKey(featureResourceLocation); } - public static boolean hasFeature(IFeature feature) { + public boolean hasFeature(IFeature feature) { return registry.containsKey(feature.getRegistryName()); } - public static void addFeature(String name, IFeature feature) { + public void addFeature(String name, IFeature feature) { feature.setRegistryName(new ResourceLocation(name)); registry.register(feature); } - public static void addFeature(JsonObject entry) { + public void addFeature(JsonObject entry) { addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); } - public static void addFeature(String name, String className) { + public void addFeature(String name, String className) { IFeature feature = getInstance(className); if (feature != null && !hasFeature(name)) { @@ -109,7 +109,7 @@ private static IFeature getInstance(String className) { return feature; } - public static void loadFeaturesFile(File file) { + public void loadFeaturesFile(File file) { JsonParser parser = new JsonParser(); String rawJson; JsonArray elements; @@ -130,7 +130,7 @@ public static void loadFeaturesFile(File file) { } } - public static void writeFeatures(File file) { + public void writeFeatures(File file) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonArray root = new JsonArray(); diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java new file mode 100644 index 00000000..d170b954 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -0,0 +1,96 @@ +package com.mcmoddev.orespawn.data; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.io.FileUtils; + +import com.google.gson.JsonElement; +import com.google.gson.JsonIOException; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSyntaxException; +import com.mcmoddev.orespawn.OreSpawn; + +import net.minecraft.crash.CrashReport; + +public class PresetsStorage { + private final Map> storage; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + + public PresetsStorage() { + storage = new TreeMap<>(); + } + + public void setSymbolSection(String sectionName, String itemName, JsonElement value) { + Map temp = storage.getOrDefault(sectionName, new HashMap()); + temp.put(itemName, value); + storage.put(sectionName, temp); + } + + public JsonElement getSymbolSection(String sectionName, String itemName) { + if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { + return storage.get(sectionName).get(itemName); + } else { + return new JsonPrimitive(itemName); + } + } + + public void copy(PresetsStorage dest) { + storage.entrySet().stream() + .forEach(ensm -> { + String section = ensm.getKey(); + ensm.getValue().entrySet().forEach(ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); + }); + } + + public void clear() { + this.storage.clear(); + } + + public void load(Path inputFile) { + JsonParser p = new JsonParser(); + JsonElement parsed = null; + + try( BufferedReader r = Files.newBufferedReader(inputFile)) { + parsed = p.parse(r); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading presets from" + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch(JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + if(parsed != null) { + parsed.getAsJsonObject().entrySet().stream() + .forEach( entry -> { + String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream() + .forEach( sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); + }); + } + } + + public JsonElement get(String asString) { + Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); + Matcher m = p.matcher(asString); + if(m.matches()) { + return this.getSymbolSection(m.group(1), m.group(2)); + } + JsonPrimitive pm = new JsonPrimitive("Unknown Variable "+asString); + return pm; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 96a7308b..59b8f334 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -1,33 +1,41 @@ package com.mcmoddev.orespawn.data; -import com.mcmoddev.orespawn.util.StateUtil; -import com.google.common.hash.Hashing; +import com.google.common.collect.ImmutableMap; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; + import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; +import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; -import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.crash.CrashReport; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; import net.minecraftforge.oredict.OreDictionary; -import net.minecraftforge.registries.IForgeRegistry; import net.minecraftforge.registries.IForgeRegistryModifiable; import net.minecraftforge.registries.RegistryBuilder; -import java.io.File; +import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; @@ -42,11 +50,14 @@ public class ReplacementsRegistry { .setMaxID(65535) // 16 bits should be enough... .create(); - private ReplacementsRegistry() { + public ReplacementsRegistry() { } + public Map getReplacements() { + return ImmutableMap.copyOf(registry.getEntries()); + } @Deprecated - public static List getDimensionDefault(int dimension) { + public List getDimensionDefault(int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; List mineralogyOres = OreDictionary.getOres("cobblestone").stream() .filter( iS -> iS.getItem().getRegistryName().getResourceDomain().equals("mineralogy")) @@ -68,7 +79,7 @@ public static List getDimensionDefault(int dimension) { return baseRv; } - public static IReplacementEntry getReplacement(String name) { + public IReplacementEntry getReplacement(String name) { if (registry.containsKey(new ResourceLocation(name))) { return registry.getValue(new ResourceLocation(name)); } else { @@ -76,12 +87,12 @@ public static IReplacementEntry getReplacement(String name) { } } - public static void addBlock(String name, String blockName, String blockState) { + public void addBlock(String name, String blockName, String blockState) { IBlockState b = StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); addBlock(name, b); } - public static Map> getBlocks() { + public Map> getBlocks() { Map> tempMap = new TreeMap<>(); registry.getEntries().stream() .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); @@ -89,7 +100,11 @@ public static Map> getBlocks() { return Collections.unmodifiableMap(tempMap); } - public static void addBlock(String name, IBlockState state) { + public void addReplacement(IReplacementEntry replacement) { + registry.register(replacement); + } + + public void addBlock(String name, IBlockState state) { ResourceLocation regName = new ResourceLocation(name); if (registry.containsKey(regName)) { IReplacementEntry old = registry.getValue(regName); @@ -107,7 +122,8 @@ public static void addBlock(String name, IBlockState state) { registry.register(r); } - public static void loadFile(Path file) { + @SuppressWarnings("deprecation") + public void loadFile(Path file) { JsonParser parser = new JsonParser(); JsonObject elements; String rawJson; @@ -130,21 +146,38 @@ public static void loadFile(Path file) { List blocks = new LinkedList<>(); for (JsonElement e : entries) { JsonObject asObj = e.getAsJsonObject(); - String blockName = asObj.get(Constants.ConfigNames.BLOCK_V2).getAsString(); - String state = null; - if (asObj.has(Constants.ConfigNames.METADATA)) { - state = String.format("variant=%s", asObj.get(Constants.ConfigNames.METADATA).getAsInt()); - } else if(asObj.has(Constants.ConfigNames.STATE)) { - state = asObj.get(Constants.ConfigNames.STATE).getAsString(); - } + String blockName = asObj.get(Constants.ConfigNames.BLOCK).getAsString().toLowerCase(); - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - if (state != null) { - blocks.add(StateUtil.deserializeState(block, state)); + // is this an OreDictionary entry ? + if(blockName.startsWith("ore:")) { + // yes, it is + String oreDictName = blockName.split(":")[1]; + OreDictionary.getOres(oreDictName).forEach(iS -> { + if(iS.getMetadata() != 0) { + blocks.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); + } else { + blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); + } + }); } else { - blocks.add(block.getDefaultState()); + String state = null; + ResourceLocation blockRL = new ResourceLocation(blockName); + Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); + if (asObj.has(Constants.ConfigNames.METADATA)) { + // has metadata + int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); + blocks.add(theBlock.getStateFromMeta(meta)); + } else if(asObj.has(Constants.ConfigNames.STATE)) { + // has a state + state = asObj.get(Constants.ConfigNames.STATE).getAsString(); + blocks.add(StateUtil.deserializeState(theBlock, state)); + } else { + // use the default state + blocks.add(theBlock.getDefaultState()); + } } } + IReplacementEntry replacer = new ReplacementEntry(entName, blocks); replacer.setRegistryName(new ResourceLocation(modName, entName)); registry.register(replacer); @@ -152,7 +185,34 @@ public static void loadFile(Path file) { } public void saveFile(String modName) { - // TODO: write this + JsonObject outs = new JsonObject(); + + registry.getEntries().stream() + .filter(ent -> ent.getKey().getResourceDomain().equals(modName)) + .forEach(ent -> { + JsonArray entry = new JsonArray(); + IReplacementEntry workVal = ent.getValue(); + workVal.getEntries().stream() + .forEach(bs -> { + JsonObject block = new JsonObject(); + block.addProperty(Constants.ConfigNames.BLOCK, bs.getBlock().getRegistryName().toString()); + if(!bs.toString().matches("\\[normal\\]")) { + block.addProperty(Constants.ConfigNames.STATE, bs.toString().replaceAll("[\\[\\]]", "")); + } + entry.add(block); + }); + outs.add(ent.getKey().toString(), entry); + }); + Path p = Paths.get("config","orespawn3", "sysconfig", String.format("replacements-%s.json", modName)); + try(BufferedWriter w = Files.newBufferedWriter(p)) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String ov = gson.toJson(outs); + w.write(ov); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed writing replacements file %s", p.toAbsolutePath().toString())); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } } private static String getModName(String baseName) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index d0242a21..290030a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -64,7 +64,7 @@ public IBiomeBuilder setAcceptAll() { } @Override - public BiomeLocation create() { + public BiomeLocationComposition create() { if (this.acceptAll) { return new BiomeLocationComposition(ImmutableSet.of(new BiomeLocationEmpty()), ImmutableSet.of(new BiomeLocation() { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 72f16d9e..b16c01fe 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -8,8 +8,9 @@ public class DimensionBuilder implements IDimensionBuilder { private final List dimensionWhitelist = new LinkedList<>(); private final List dimensionBlacklist = new LinkedList<>(); - private boolean acceptAll = true; + private boolean acceptAll = false; private boolean denyAll = false; + private boolean acceptAllOverworld = true; public DimensionBuilder() { } @@ -48,9 +49,19 @@ public IDimensionList create() { return new DimensionListAcceptAll(); } else if (this.denyAll) { return new DimensionListDenyAll(); + } else if (this.acceptAllOverworld) { + return new DimensionListAcceptAllOverworld(); } else { return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); } } + @Override + public IDimensionBuilder setAcceptAllOverworld() { + this.acceptAll = false; + this.denyAll = false; + this.acceptAllOverworld = true; + return this; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java new file mode 100644 index 00000000..fb3c881c --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -0,0 +1,11 @@ +package com.mcmoddev.orespawn.impl.os3; + +import com.mcmoddev.orespawn.api.IDimensionList; + +public class DimensionListAcceptAllOverworld implements IDimensionList { + @Override + public boolean matches(final int dimensionID) { + return dimensionID != -1 && dimensionID != 1; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 59ae50ad..254b1428 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -27,10 +27,10 @@ public IFeatureBuilder setFeature(String featureName) { @Override public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { - if (!FeatureRegistry.hasFeature(featureResourceLocation)) { + if (!OreSpawn.API.featureExists(featureResourceLocation)) { OreSpawn.LOGGER.warn("Feature %s is not known, feature for this will be set to the default feature", featureResourceLocation.getResourcePath()); } - return this.setFeature(FeatureRegistry.getFeature(featureResourceLocation)); + return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); } @Override @@ -63,6 +63,12 @@ public IFeatureBuilder setParameter(String parameterName, boolean parameterValue return this; } + @Override + public IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue) { + this.parameters.add(parameterName, parameterValue); + return this; + } + private void setFeatureParameter(String parameterName, JsonElement parameterValue, FeatureEntry feat) { if (parameterValue.getAsJsonPrimitive().isBoolean()) { feat.setParameter(parameterName,parameterValue.getAsBoolean()); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index fd07e461..e72eb438 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -1,126 +1,201 @@ package com.mcmoddev.orespawn.impl.os3; -import java.util.ArrayList; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.PathMatcher; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Random; -import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.api.os3.BuilderLogic; +import com.mcmoddev.orespawn.api.exceptions.MissingVersionException; +import com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException; +import com.mcmoddev.orespawn.api.exceptions.OldVersionException; +import com.mcmoddev.orespawn.api.exceptions.UnknownVersionException; +import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; +import com.mcmoddev.orespawn.api.os3.IBlockBuilder; import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; -import com.mcmoddev.orespawn.api.os3.OS3API; +import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; +import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; +import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OS3API; +import com.mcmoddev.orespawn.data.Constants; +import com.mcmoddev.orespawn.data.FeatureRegistry; +import com.mcmoddev.orespawn.data.PresetsStorage; import com.mcmoddev.orespawn.data.ReplacementsRegistry; -import com.mcmoddev.orespawn.util.OS3V2PresetStorage; -import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; +import com.mcmoddev.orespawn.json.OreSpawnReader; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraft.crash.CrashReport; +import net.minecraft.util.ResourceLocation; public class OS3APIImpl implements OS3API { - private final Map logic; - private OreSpawnWorldGen generator; - private OS3V2PresetStorage presets; - - public OS3APIImpl() { - this.logic = new HashMap<>(); - this.presets = new OS3V2PresetStorage(); + private static final Map spawns; + private static final FeatureRegistry features; + private static final ReplacementsRegistry replacements; + private static final PresetsStorage presets; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + + static { + spawns = new ConcurrentHashMap<>(); + features = new FeatureRegistry(); + replacements = new ReplacementsRegistry(); + presets = new PresetsStorage(); } + + public OS3APIImpl() { + PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:features-*.json"); + PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:replacements-*.json"); + PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:*.json"); + + try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { + stream.filter(featuresFiles::matches) + .map(Path::toFile) + .forEach(features::loadFeaturesFile); + + stream.filter(replacementsFiles::matches) + .forEach(replacements::loadFile); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + if(Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { + presets.load(Constants.SYSCONF.resolve("presets-default.json")); + } + + try(Stream stream = Files.walk(Constants.CONFDIR, 1)) { + stream.filter(jsonMatcher::matches) + .forEach(conf -> { + try { + OreSpawnReader.tryReadFile(conf, this); + } catch (MissingVersionException | NotAProperConfigException | OldVersionException + | UnknownVersionException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.CONFDIR.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + @Override - public void registerReplacementBlock(String name, Block itemBlock) { - this.registerReplacementBlock(name, itemBlock.getDefaultState()); + public void addSpawn(ISpawnEntry spawnEntry) { + spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); } @Override - public void registerReplacementBlock(String name, IBlockState itemBlock) { - ReplacementsRegistry.addBlock(name, itemBlock); + public void addFeature(String featureName, IFeature feature) { + features.addFeature(featureName, feature); } @Override - public void registerFeatureGenerator(String name, String className) { - OreSpawn.FEATURES.addFeature(name, className); + public void addReplacement(IReplacementEntry replacementEntry) { + replacements.addReplacement(replacementEntry); } @Override - public void registerFeatureGenerator(String name, IFeature feature) { - this.registerFeatureGenerator(name, feature.getClass().getName()); + public ISpawnBuilder getSpawnBuilder() { + return new SpawnBuilder(); } @Override - public void registerFeatureGenerator(String name, Class feature) { - this.registerFeatureGenerator(name, feature.getName()); + public IDimensionBuilder getDimensionBuilder() { + return new DimensionBuilder(); } @Override - public BuilderLogic getLogic(String name) { - if (logic.containsKey(name)) { - return logic.get(name); - } else { - BuilderLogic bl = new BuilderLogicImpl(); - logic.put(name, bl); - return bl; - } + public IFeatureBuilder getFeatureBuilder() { + return new FeatureBuilder(); } @Override - public void registerLogic(BuilderLogic logic) { - // we do nothing - this is here for orthogonality, really + public IBlockBuilder getBlockBuilder() { + return new BlockBuilder(); } @Override - public int dimensionWildcard() { - return 0xCAFEBABE; + public IBiomeBuilder getBiomeBuilder() { + return new BiomeBuilder(); } @Override - public int biomeWildcard() { - return 0xF00DF00D; + public IReplacementBuilder getReplacementBuilder() { + return new ReplacementBuilder(); } - + @Override - public ImmutableMap getSpawns() { - return ImmutableMap.copyOf(logic); + public Map getReplacements() { + Map temp = new HashMap<>(); + replacements.getReplacements().entrySet().stream() + .forEach(e -> temp.put(e.getKey().getResourcePath(), e.getValue())); + return ImmutableMap.copyOf(temp); } @Override - public void registerSpawns() { - Map> spawns = OreSpawn.getSpawns(); - - // build a proper tracking of data for the spawner - for (Entry ent : logic.entrySet()) { - for (Entry dL : ent.getValue().getAllDimensions().entrySet()) { - if (spawns.containsKey(dL.getKey())) { - spawns.get(dL.getKey()).addAll(dL.getValue().getAllSpawns()); - } else { - spawns.put(dL.getKey(), new ArrayList<>()); - spawns.get(dL.getKey()).addAll(dL.getValue().getAllSpawns()); - } - } + public IReplacementEntry getReplacement(String replacementName) { + return replacements.getReplacement(replacementName); + } - OreSpawn.LOGGER.info("Registered spawn logic from data-file (maybe mod) %s", ent.getKey()); - } + @Override + public List getSpawns(int dimensionID) { + return ImmutableList.copyOf(spawns.entrySet().stream() + .filter(e -> e.getValue().dimensionAllowed(dimensionID)) + .map(e -> e.getValue()) + .collect(Collectors.toList())); + } - Random random = new Random(); + @Override + public ISpawnEntry getSpawn(String spawnName) { + return spawns.get(new ResourceLocation(spawnName)); + } - this.generator = new OreSpawnWorldGen(spawns, random.nextLong()); + @Override + public Map getAllSpawns() { + Map sp = new HashMap<>(); + spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getResourcePath(), ent.getValue())); + return ImmutableMap.copyOf(sp); + } - GameRegistry.registerWorldGenerator(generator, 100); + @Override + public boolean featureExists(String featureName) { + return this.featureExists(new ResourceLocation(featureName)); + } + + @Override + public boolean featureExists(ResourceLocation featureName) { + return features.hasFeature(featureName); + } + @Override + public IFeature getFeature(String featureName) { + return this.getFeature(new ResourceLocation(featureName)); } @Override - public OreSpawnWorldGen getGenerator() { - return this.generator; + public IFeature getFeature(ResourceLocation featureName) { + return features.getFeature(featureName); } @Override - public OS3V2PresetStorage getPresets() { - return this.presets; + public PresetsStorage copyPresets() { + PresetsStorage copy = new PresetsStorage(); + presets.copy(copy); + return copy; } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index fe6dc9cb..40c3aa65 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -3,6 +3,7 @@ import java.util.LinkedList; import java.util.List; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; @@ -23,7 +24,7 @@ public ReplacementBuilder() { @Override public IReplacementBuilder setFromName(String entryName) { this.replacementName = entryName; - this.entries.addAll(ReplacementsRegistry.getReplacement(entryName).getEntries()); + this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java deleted file mode 100644 index 098b69cc..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Reader.java +++ /dev/null @@ -1,240 +0,0 @@ -package com.mcmoddev.orespawn.json; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; - -import com.google.common.base.Charsets; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import com.google.gson.JsonParser; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.os3.*; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; -import com.mcmoddev.orespawn.json.os3.IOS3Reader; -import com.mcmoddev.orespawn.json.os3.readers.*; - -import net.minecraft.crash.CrashReport; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.registry.ForgeRegistries; -import net.minecraftforge.oredict.OreDictionary; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; - -public class OS3Reader { - - private OS3Reader() { - - } - private static void loadFeatures(File file) { - OreSpawn.FEATURES.loadFeaturesFile(file); - } - - public static void loadEntries() { - File directory = new File(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3); - JsonParser parser = new JsonParser(); - - if (!directory.exists()) { - directory.mkdirs(); - return; - } - - if (!directory.isDirectory()) { - OreSpawn.LOGGER.fatal("OreSpawn data directory inaccessible - " + directory + " is not a directory!"); - return; - } - - File[] files = directory.listFiles(); - - if (files.length == 0) { - // nothing to load - return; - } - - Path presets = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF, Constants.FileBits.PRESETS); - loadPresets(presets); - - if (Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().exists() && Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().isDirectory()) { - Arrays.stream(Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().listFiles()) - .filter(file -> "json".equals(FilenameUtils.getExtension(file.getName()))) - .forEach(file -> { - String filename = file.getName(); - - if (FilenameUtils.getBaseName(filename).matches("features-.+")) { - loadFeatures(file); - } else if (FilenameUtils.getBaseName(filename).matches("replacements-.+")) { - Replacements.load(file); - } - }); - } - - Arrays.stream(files).filter(file -> file.getName().endsWith(".json")).forEach( - file -> { - try { - String rawData = FileUtils.readFileToString(file, Charset.defaultCharset()); - - if (rawData.isEmpty()) { - return; - } - - JsonElement full = parser.parse(rawData); - JsonObject parsed = full.getAsJsonObject(); - String version = parsed.get("version").getAsString(); - IOS3Reader reader = getReader(version); - - if (reader != null) { - finallyParse(reader.parseJson(parsed, FilenameUtils.getBaseName(file.getName())), FilenameUtils.getBaseName(file.getName())); - } - } catch (Exception e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getName()); - report.getCategory().addCrashSection(Constants.ORESPAWN_VERSION_CRASH_MESSAGE, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - }); - - } - - private static void loadPresets(Path presets) { - if (presets.toFile().exists()) { - try { - JsonParser parser = new JsonParser(); - String rawJson = FileUtils.readFileToString(presets.toFile(), Charsets.UTF_8); - JsonObject top = parser.parse(rawJson).getAsJsonObject(); - top.entrySet() - .forEach(entry -> { - String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet() - .forEach(pres -> OreSpawn.API.getPresets().setSymbolSection(section, pres.getKey(), pres.getValue())); - }); - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, "Failed reading presets " + presets.toFile().getName()); - report.getCategory().addCrashSection(Constants.ORESPAWN_VERSION_CRASH_MESSAGE, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (JsonParseException ex) { - CrashReport report = CrashReport.makeCrashReport(ex, "Failed loading or parsing " + presets.toFile().getName()); - report.getCategory().addCrashSection(Constants.ORESPAWN_VERSION_CRASH_MESSAGE, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - } - - /** - * Actually parse the normalized data - * @param parseJson normalized data returned by the file loader/normalizer - */ - private static void finallyParse(JsonObject parseJson, String filename) { - JsonObject work = parseJson.getAsJsonObject("dimensions"); - BuilderLogic logic = OreSpawn.API.getLogic(filename); - - // at the top-most level we have the dimension sets - work.entrySet().forEach(entry -> { - int dimension = Integer.parseInt(entry.getKey()); - IDimensionBuilder builder = logic.newDimensionBuilder(dimension); - entry.getValue().getAsJsonArray().forEach(ore -> { - try { - JsonObject nw = ore.getAsJsonObject(); - ISpawnBuilder spawn = builder.newSpawnBuilder(null); - // load the "ores" as "OreBuilder" - we should always have a "blocks" here, so... - // filter out all null entries - List blocks = Helpers.loadOres(nw.getAsJsonArray(ConfigNames.BLOCKS), spawn).stream() - .filter(ob -> !ob.getOre().getBlock().equals(net.minecraft.init.Blocks.AIR)).collect(Collectors.toList()); - // null entry - if (blocks.size() == 0) return; - - List replacements = getReplacements(nw.get(ConfigNames.V2.REPLACES).getAsString(), dimension); - IBiomeBuilder biomes = spawn.newBiomeBuilder(); - - if (nw.get(ConfigNames.BIOMES).isJsonObject()) { - biomes.setFromBiomeLocation(Helpers.deserializeBiomeLocationComposition(nw.getAsJsonObject(ConfigNames.BIOMES))); - } - - IFeatureBuilder gen = spawn.newFeatureBuilder(nw.get(ConfigNames.FEATURE).getAsString()); - gen.setDefaultParameters(); - handleParameterFixes(nw); - gen.setParameters(nw.getAsJsonObject(ConfigNames.PARAMETERS)); - spawn.enabled(nw.get(ConfigNames.V2.ENABLED).getAsBoolean()); - spawn.retrogen(nw.get(ConfigNames.V2.RETROGEN).getAsBoolean()); - - if (nw.has(ConfigNames.DIMENSION)) { - OreSpawn.LOGGER.fatal("Entry has %s tag with contents: %s", ConfigNames.DIMENSION, nw.getAsJsonObject(ConfigNames.DIMENSION)); - spawn.create(biomes, gen, replacements, nw.getAsJsonObject(ConfigNames.DIMENSION), blocks.toArray(new OreBuilder[0])); - } else { - spawn.create(biomes, gen, replacements, blocks.toArray(new OreBuilder[0])); - } - - builder.create(spawn); - } catch (JsonParseException ex) { - OreSpawn.LOGGER.error("Error parsing entry %s : %s", ore.getAsJsonObject().get("name").getAsString(), ex); - } catch (NullPointerException npe) { - OreSpawn.LOGGER.error("Exception parsing entry %s : possibly mis-named or missing item ?", ore.getAsJsonObject().get("name").getAsString()); - } - }); - logic.create(builder); - }); - } - - private static void handleParameterFixes(JsonObject nw) { - JsonObject p = nw.getAsJsonObject(ConfigNames.PARAMETERS); - - if (p.has(Constants.FormatBits.ATTEMPTS)) { - if (p.get(Constants.FormatBits.ATTEMPTS).isJsonObject()) { - p.add(Constants.FormatBits.ATTEMPTS_MIN, p.getAsJsonObject(Constants.FormatBits.ATTEMPTS).get(ConfigNames.V2.MINIMUM)); - p.add(Constants.FormatBits.ATTEMPTS_MAX, p.getAsJsonObject(Constants.FormatBits.ATTEMPTS).get(ConfigNames.V2.MAXIMUM)); - } else { - p.addProperty(Constants.FormatBits.ATTEMPTS_MIN, p.get(Constants.FormatBits.ATTEMPTS).getAsInt()); - p.addProperty(Constants.FormatBits.ATTEMPTS_MAX, p.get(Constants.FormatBits.ATTEMPTS).getAsInt()); - } - - p.remove(Constants.FormatBits.ATTEMPTS); - nw.remove(ConfigNames.PARAMETERS); - nw.add(ConfigNames.PARAMETERS, p); - } - } - - private static List getReplacements(String configField, int dimension) { - String work = configField.toLowerCase(); - - if (work.equals(ConfigNames.DEFAULT)) { - return ReplacementsRegistry.getDimensionDefault(dimension); - } else if (work.startsWith("ore:")) { - NonNullList ores = OreDictionary.getOres(work.substring(4)); - List reps = new ArrayList<>(); - ores.forEach(ore -> reps.add(Block.getBlockFromItem(ore.getItem()).getDefaultState())); - return reps; - } else if (!work.contains(":")) { // probably a "replacements registry" entry - return Arrays.asList(ReplacementsRegistry.getBlock(work)); - } else { - return Arrays.asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(configField)).getDefaultState()); - } - } - - public static IOS3Reader getReader(String version) { - switch (version) { - case "1": - case "1.1": - case "1.2": - return new OS3V1Reader(); - - case "2.0": - return new OS3V2Reader(); - - default: - OreSpawn.LOGGER.error("Unknown version %s", version); - return null; - } - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java b/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java deleted file mode 100644 index 4cba4cb1..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/OS3Writer.java +++ /dev/null @@ -1,227 +0,0 @@ -package com.mcmoddev.orespawn.json; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Map.Entry; - -import org.apache.commons.io.FileUtils; - -import com.google.common.collect.ImmutableList; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.impl.location.*; -import com.mcmoddev.orespawn.util.StateUtil; - -import net.minecraft.crash.CrashReport; -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -public class OS3Writer { - private void writeFeatures(String base) { - File file = new File(Paths.get(base, Constants.FileBits.SYSCONF).toString(), "features-default.json"); - OreSpawn.FEATURES.writeFeatures(file); - } - - private void writeReplacements(String base) { - File file = new File(Paths.get(base, Constants.FileBits.SYSCONF).toString(), "replacements-default.json"); - Replacements.save(file); - } - - public void writeSpawnEntries() { - String basePath = Paths.get("config", "orespawn3", "force-written").toString(); - writeFeatures(basePath); - writeReplacements(basePath); - - OreSpawn.API.getSpawns().entrySet().forEach(ent -> { - JsonArray dimensions = new JsonArray(); - - for (Entry dim : ent.getValue().getAllDimensions().entrySet()) { - JsonObject dimension = new JsonObject(); - - if (dim.getKey() != OreSpawn.API.dimensionWildcard()) { - dimension.addProperty(ConfigNames.DIMENSION, String.format("%d", dim.getKey())); - } - - JsonArray spawns = this.genSpawns(dim.getValue().getAllSpawns()); - - if (spawns.size() > 0) { - dimension.add(ConfigNames.ORES, spawns); - dimensions.add(dimension); - } - } - - if (countOres(dimensions) > 0) { - File file = new File(basePath, String.format("%s.json", ent.getKey())); - JsonObject wrapper = new JsonObject(); - wrapper.addProperty(ConfigNames.FILE_VERSION, "1.2"); - wrapper.add(ConfigNames.DIMENSIONS, dimensions); - this.writeFile(file, wrapper); - } - }); - } - - private JsonArray genSpawns(ImmutableList allSpawns) { - JsonArray rv = new JsonArray(); - - for (ISpawnBuilder spawn : allSpawns) { - if (spawn.getOres().isEmpty() || - spawn.getOres().get(0).getOre() == null || - "minecraft:air".equals(spawn.getOres().get(0).getOre().getBlock().getRegistryName().toString())) { - continue; - } - - rv.add(this.genSpawn(spawn)); - } - - return rv; - } - - private void writeFile(File file, JsonObject wrapper) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - try { - FileUtils.writeStringToFile(file, gson.toJson(wrapper), "UTF8", false); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed in config %s", file.getName())); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - private JsonObject genSpawn(ISpawnBuilder spawn) { - JsonObject ore = new JsonObject(); - - ore.add(ConfigNames.BLOCKS, genBlocks(spawn.getOres())); - ore.add(ConfigNames.PARAMETERS, spawn.getFeatureGen().getParameters()); - ore.addProperty(ConfigNames.FEATURE, spawn.getFeatureGen().getFeatureName()); - ore.addProperty(ConfigNames.REPLACEMENT, ConfigNames.DEFAULT); - ore.add(ConfigNames.BIOMES, biomeLocationToJsonObject(spawn.getBiomes())); - return ore; - } - - private JsonArray genBlocks(ImmutableList ores) { - JsonArray retval = new JsonArray(); - - ores.forEach(ore -> { - JsonObject obj = new JsonObject(); - obj.addProperty(ConfigNames.BLOCK, ore.getOre().getBlock().getRegistryName().toString()); - obj.addProperty(ConfigNames.STATE, StateUtil.serializeState(ore.getOre())); - obj.addProperty(ConfigNames.CHANCE, ore.getChance()); - retval.add(obj); - }); - return retval; - } - - private int countOres(JsonArray dims) { - int count = 0; - - for (JsonElement dim : dims) { - count += dim.getAsJsonObject().get(ConfigNames.ORES).getAsJsonArray().size(); - } - - return count; - } - - private JsonElement biomeLocationToJsonObject(BiomeLocation value) { - if ((value instanceof BiomeLocationSingle) || (value instanceof BiomeLocationDictionary)) { - return getString(value); - } else if (value instanceof BiomeLocationList) { - return getList(value); - } else if (value instanceof BiomeLocationComposition) { - return getComposition(value); - } - - return null; - } - - private JsonElement getComposition(BiomeLocation value) { - JsonObject rv = new JsonObject(); - rv.add(ConfigNames.BiomeStuff.WHITELIST, getList(new BiomeLocationList(((BiomeLocationComposition)value).getInclusions()))); - rv.add(ConfigNames.BiomeStuff.BLACKLIST, getList(new BiomeLocationList(((BiomeLocationComposition)value).getExclusions()))); - return rv; - } - - private JsonArray getList(BiomeLocation value) { - JsonArray rv = new JsonArray(); - ((BiomeLocationList)value).getLocations().forEach(loc -> { - if ((loc instanceof BiomeLocationSingle) || (loc instanceof BiomeLocationDictionary)) { - rv.add(getString(loc)); - } else if (loc instanceof BiomeLocationComposition) { - rv.add(getComposition(loc)); - } - }); - return rv; - } - - private JsonElement getString(BiomeLocation value) { - String val = null; - - if (value instanceof BiomeLocationSingle) { - val = ForgeRegistries.BIOMES.getKey(((BiomeLocationSingle)value).getBiome()).toString(); - } else { - val = ((BiomeLocationDictionary)value).getType().toString(); - } - - return new JsonPrimitive(val); - } - - public void writeSysconfIfNonexistent() { - String base = String.format(".%1$sconfig%1$sorespawn3", File.separator); - - if (!Paths.get(base, Constants.FileBits.SYSCONF, "features-default.json").toFile().exists()) { - writeFeatures(base); - } - - if (!Paths.get(base, Constants.FileBits.SYSCONF, "replacements-default.json").toFile().exists()) { - writeReplacements(base); - } - } - - public void writeAddOreEntry(String fileName) { - BuilderLogic ent = OreSpawn.API.getLogic(fileName); - - JsonArray dimensions = new JsonArray(); - - for (Entry dim : ent.getAllDimensions().entrySet()) { - JsonObject dimension = new JsonObject(); - - if (dim.getKey() != OreSpawn.API.dimensionWildcard()) { - dimension.addProperty(ConfigNames.DIMENSION, String.format("%d", dim.getKey())); - } - - JsonArray spawns = this.genSpawns(dim.getValue().getAllSpawns()); - - if (spawns.size() > 0) { - dimension.add(ConfigNames.ORES, spawns); - dimensions.add(dimension); - } - } - - if (countOres(dimensions) > 0) { - Path p = Paths.get("config", "orespawn3", "force-written"); - - if (!p.toFile().exists()) { - p.toFile().mkdirs(); - } - - File file = Paths.get(p.toString(), String.format("%s-addOre.json", fileName)).toFile(); - JsonObject wrapper = new JsonObject(); - wrapper.addProperty(ConfigNames.FILE_VERSION, "1.2"); - wrapper.add(ConfigNames.DIMENSIONS, dimensions); - this.writeFile(file, wrapper); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index dad12301..eb0468b5 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -1,100 +1,350 @@ package com.mcmoddev.orespawn.json; -import java.io.File; -import java.nio.charset.Charset; -import java.nio.file.Paths; +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; +import java.util.Map.Entry; +import java.util.stream.Collectors; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; - +import com.google.common.collect.ImmutableList; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; +import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.exceptions.BadValueException; +import com.mcmoddev.orespawn.api.exceptions.MissingVersionException; +import com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException; +import com.mcmoddev.orespawn.api.exceptions.OldVersionException; +import com.mcmoddev.orespawn.api.exceptions.UnknownFieldException; +import com.mcmoddev.orespawn.api.exceptions.UnknownNameException; +import com.mcmoddev.orespawn.api.exceptions.UnknownVersionException; +import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; +import com.mcmoddev.orespawn.api.os3.IBlockBuilder; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; +import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; +import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.json.os3.IOS3Reader; +import com.mcmoddev.orespawn.data.PresetsStorage; +import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; +import com.mcmoddev.orespawn.util.StateUtil; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.crash.CrashReport; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.BiomeDictionary; +import net.minecraftforge.fml.common.registry.ForgeRegistries; +import net.minecraftforge.oredict.OreDictionary; public class OreSpawnReader { - private List spawns; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + + public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { + JsonParser parser = new JsonParser(); + try(BufferedReader data = Files.newBufferedReader(conf)) { + JsonElement json = parser.parse(data); + + if(!json.isJsonObject()) { + throw new NotAProperConfigException(); + } + + + JsonObject root = json.getAsJsonObject(); + if(!root.has(Constants.ConfigNames.FILE_VERSION)) { + throw new MissingVersionException(); + } + + float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); + if( version < 2f ) { + throw new OldVersionException(); + } else if( version != 2f ) { + throw new UnknownVersionException(); + } + + if( !root.has(Constants.ConfigNames.SPAWNS)) { + throw new NotAProperConfigException(); + } + + JsonObject spawnData = doHandlePresets(root); + spawnData.entrySet().stream() + .forEach(e -> { + try { + loadSingleEntry(e); + } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { + CrashReport report = CrashReport.makeCrashReport(e1, "Error parsing an entry " + e.getKey() + " in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config data " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch(JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } - public OreSpawnReader() { - this.spawns = new LinkedList<>(); + private static JsonObject doHandlePresets(JsonObject spawnData) { + PresetsStorage configPresets = OreSpawn.API.copyPresets(); + if(spawnData.has(Constants.ConfigNames.PRESETS)) { + spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() + .forEach( entry -> { + String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream() + .forEach( sect -> configPresets.setSymbolSection(section, sect.getKey(), sect.getValue())); + }); + } + + JsonObject spawnDataFixed = new JsonObject(); + for( Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS).getAsJsonObject().entrySet()) { + spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); + } + return spawnData; } - public void loadSpawnData() { - // first we parse the OS3 format spawns, as we prefer them over other versions - parseSpawnsV3(); + private static JsonElement doPresetFix(JsonElement value, PresetsStorage configPresets) { + if (value.isJsonObject()) { + return doPresetForObject(value.getAsJsonObject(), configPresets); + } else if(value.isJsonArray()) { + return doPresetForArray(value.getAsJsonArray(), configPresets); + } else if(value.isJsonPrimitive() && !value.isJsonNull()) { + if (value.getAsJsonPrimitive().isString() && + value.getAsString().matches("^\\$.*")) { + return configPresets.get(value.getAsString()); + } else { + return value; + } + } else { + OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item "+value.toString()); + return value; + } + } + + private static JsonElement doPresetForArray(JsonArray value, PresetsStorage configPresets) { + JsonArray rv = new JsonArray(); + value.forEach(it -> rv.add(doPresetFix(it, configPresets))); + return rv; + } + private static JsonElement doPresetForObject(JsonObject value, PresetsStorage configPresets) { + JsonObject rv = new JsonObject(); + + value.entrySet().stream().forEach( entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); + return rv; } - private void parseSpawnsV3() { - File directory = new File(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3); - File[] files; + + private static void loadSingleEntry(Entry entry) throws UnknownFieldException, BadValueException, UnknownNameException { + ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); + IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); + sb.setName(entry.getKey()); - if (!directory.exists()) { - return; + for( Entry ent : entry.getValue().getAsJsonObject().entrySet()) { + switch(ent.getKey()) { + case Constants.ConfigNames.RETROGEN: + sb.setRetrogen(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.ENABLED: + sb.setEnabled(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.DIMENSIONS: + IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + if (ent.getValue().isJsonArray()) { + JsonArray dims = ent.getValue().getAsJsonArray(); + if(dims.size() == 0) { + // blank list, accept all overworld + db.setAcceptAllOverworld(); + } else { + dims.forEach(item -> { + if (item.isJsonPrimitive() && + item.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(item.getAsInt()); + } + }); + } + } else if(ent.getValue().isJsonObject()) { + loadDimensions(db,ent.getValue().getAsJsonObject()); + } else { + throw new BadValueException(Constants.ConfigNames.DIMENSIONS, ent.getValue().toString()); + } + sb.setDimensions(db.create()); + break; + case Constants.ConfigNames.BIOMES: + if(!ent.getValue().isJsonObject()) { + throw new BadValueException(Constants.ConfigNames.BIOMES, ent.getValue().toString()); + } + IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); + loadBiomes(bb, ent.getValue().getAsJsonObject()); + sb.setBiomes(bb.create()); + break; + case Constants.ConfigNames.FEATURE: + if(ent.getValue().isJsonPrimitive() && + !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString()); + } + String featureName = ent.getValue().getAsString(); + if(!OreSpawn.API.featureExists(featureName)) { + throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); + } + fb.setFeature(featureName); + break; + case Constants.ConfigNames.REPLACEMENT: + if(!ent.getValue().isJsonArray()) { + throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); + } + IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + for( JsonElement e : ent.getValue().getAsJsonArray() ) { + if(e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString()); + } + } + sb.setReplacement(rb.create()); + break; + case Constants.ConfigNames.BLOCK: + if (ent.getValue().isJsonArray()) { + for( JsonElement elem : ent.getValue().getAsJsonArray()) { + IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + if (elem.isJsonObject()) { + JsonObject bl = elem.getAsJsonObject(); + if(bl.has(Constants.ConfigNames.STATE)) { + block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.STATE).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else if(bl.has(Constants.ConfigNames.METADATA)) { + block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.METADATA).getAsInt(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else { + block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } + sb.addBlock(block.create().getBlock()); + } else { + OreSpawn.LOGGER.error("Skipping value %s in blocks list as it is not the correct format", elem.toString()); + } + } + } else { + throw new BadValueException(Constants.ConfigNames.BLOCK, ent.getValue().toString()); + } + case Constants.ConfigNames.PARAMETERS: + if(ent.getValue().isJsonObject()) { + ent.getValue().getAsJsonObject().entrySet().stream() + .forEach(e -> fb.setParameter(e.getKey(),e.getValue())); + } + break; + default: + throw new UnknownFieldException(ent.getKey()); + } + OreSpawn.API.addSpawn(sb.create()); } + } - if (!directory.isDirectory()) { - OreSpawn.LOGGER.fatal("OreSpawn data directory inaccessible - " + directory + " is not a directory!"); - return; + private static List loadBlock(JsonObject json) { + String blockName = json.get(Constants.ConfigNames.BLOCK).getAsString(); + if(json.has(Constants.ConfigNames.STATE)) { + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(StateUtil.deserializeState(block, json.get(Constants.ConfigNames.STATE).getAsString())); + } else if(json.has(Constants.ConfigNames.METADATA)) { + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); } - - files = directory.listFiles(); - - if (files.length == 0) { - // nothing to load - return; + + if(blockName.startsWith("ore:")) { + String entry = blockName.split(":")[1]; + return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream() + .map( is -> { + Block b = Block.getBlockFromItem(is.getItem()); + return b.getStateFromMeta(is.getMetadata()); + }) + .collect(Collectors.toList())); } - - loadFeaturesAndReplacements(); - loadSpawns(files); + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(block.getDefaultState()); } - private void loadSpawns(File[] files) { - JsonParser parser = new JsonParser(); - Arrays.stream(files).filter(file -> file.getName().endsWith(".json")).forEach( - file -> { - try { - String rawData = FileUtils.readFileToString(file, Charset.defaultCharset()); - - if (rawData.isEmpty()) { - return; + private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { + boolean emptyWhitelist = false; + + if (biomeList.has(Constants.ConfigNames.WHITELIST) && + biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for( JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray() ) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + String xN = elem.getAsString(); + if (xN.matches(":")) { + // not a BiomeDictionary entry (we hope) + bb.addWhitelistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addWhitelistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); } - - JsonElement full = parser.parse(rawData); - JsonObject parsed = full.getAsJsonObject(); - - String version = parsed.get("version").getAsString(); - IOS3Reader reader = OS3Reader.getReader(version); - - spawns.add(reader.parseJson(parsed, file.getName().substring(0, file.getName().lastIndexOf('.')))); - } catch (Exception e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getName()); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); } - }); + } else { + emptyWhitelist = true; + } + + if (biomeList.has(Constants.ConfigNames.BLACKLIST) && + biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for( JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + String xN = elem.getAsString(); + if (xN.matches(":")) { + // not a BiomeDictionary entry (we hope) + bb.addBlacklistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addBlacklistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", elem.getAsString()); + } + } + } else if(emptyWhitelist) { + bb.setAcceptAll(); + } } - private void loadFeaturesAndReplacements() { - if (Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().exists() && Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().isDirectory()) { - Arrays.stream(Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF).toFile().listFiles()) - .filter(file -> "json".equals(FilenameUtils.getExtension(file.getName()))) - .forEach(file -> { - String filename = file.getName(); - - if (FilenameUtils.getBaseName(filename).matches("features-.+")) { - OreSpawn.FEATURES.loadFeaturesFile(file); - } else if (FilenameUtils.getBaseName(filename).matches("replacements-.+")) { - Replacements.load(file); + private static void loadDimensions(IDimensionBuilder db, JsonObject dimensionList) { + boolean emptyWhitelist = false; + + if (dimensionList.has(Constants.ConfigNames.WHITELIST) && + dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for( JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray() ) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); } - }); + } + } else { + emptyWhitelist = true; } - } + + if (dimensionList.has(Constants.ConfigNames.BLACKLIST) && + dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for( JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addBlacklistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); + } + } + } else if(emptyWhitelist) { + db.setAcceptAllOverworld(); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/Replacements.java b/src/main/java/com/mcmoddev/orespawn/json/Replacements.java deleted file mode 100644 index 32f8c034..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/Replacements.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.mcmoddev.orespawn.json; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.commons.codec.CharEncoding; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringEscapeUtils; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; -import com.mcmoddev.orespawn.util.StateUtil; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.crash.CrashReport; - -public class Replacements { - private Replacements() { - - } - public static void load(File file) { - JsonParser parser = new JsonParser(); - String rawJson = "[]"; - JsonArray elements; - - try { - rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getName()); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return; - } - - elements = parser.parse(rawJson).getAsJsonArray(); - - for (JsonElement elem : elements) { - JsonObject obj = elem.getAsJsonObject(); - String name = obj.get("name").getAsString(); - String blockName = obj.get("blockName").getAsString(); - String blockState = obj.get("blockState").getAsString(); - ReplacementsRegistry.addBlock(name, blockName, blockState); - } - } - - public static void save(File file) { - Map blocks = ReplacementsRegistry.getBlocks(); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - - if (blocks != null) { - JsonArray root = new JsonArray(); - - for (Entry block : blocks.entrySet()) { - JsonObject entry = new JsonObject(); - entry.addProperty("name", block.getKey()); - entry.addProperty("blockName", block.getValue().getBlock().getRegistryName().toString()); - entry.addProperty("blockState", StateUtil.serializeState(block.getValue())); - root.add(entry); - } - - String json = gson.toJson(root); - - try { - FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); - } catch (IOException e) { - OreSpawn.LOGGER.fatal("Error writing " + file.toString() + " - " + e.getLocalizedMessage()); - } - } - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/IOS3Reader.java b/src/main/java/com/mcmoddev/orespawn/json/os3/IOS3Reader.java deleted file mode 100644 index 995cb738..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/IOS3Reader.java +++ /dev/null @@ -1,173 +0,0 @@ -package com.mcmoddev.orespawn.json.os3; - -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.Map.Entry; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.util.OS3V2PresetStorage; - -public interface IOS3Reader { - -default OS3V2PresetStorage getStorage() { - return null; - } - - JsonObject parseJson(JsonObject entries, String fileName); - - -default void copyOverSingleBlock(JsonObject ore, JsonObject oreOut) { - JsonObject blockEntry = new JsonObject(); - - for (Entry prop : ore.entrySet()) { - switch (prop.getKey()) { - case ConfigNames.BLOCK: - case ConfigNames.BLOCKID: - blockEntry.addProperty(ConfigNames.BLOCK_V2, prop.getValue().getAsString()); - break; - - case ConfigNames.METADATA: - blockEntry.addProperty(ConfigNames.METADATA, prop.getValue().getAsNumber()); - break; - - case ConfigNames.STATE: - blockEntry.addProperty(ConfigNames.STATE, prop.getValue().getAsString()); - break; - - case ConfigNames.CHANCE: - blockEntry.addProperty(ConfigNames.CHANCE, prop.getValue().getAsNumber()); - break; - - case ConfigNames.REPLACEMENT: - oreOut.addProperty(ConfigNames.REPLACEMENT_V2, prop.getValue().getAsString()); - break; - - default: - if (!oreOut.has(prop.getKey())) { - oreOut.add(prop.getKey(), prop.getValue()); - } - } - } - - if (!blockEntry.has(ConfigNames.CHANCE)) { - blockEntry.addProperty(ConfigNames.CHANCE, 100); - } - - if (!oreOut.has(ConfigNames.BLOCKS)) { - oreOut.add(ConfigNames.BLOCKS, new JsonArray()); - } - - JsonArray temp = oreOut.getAsJsonArray(ConfigNames.BLOCKS); - temp.add(blockEntry); - oreOut.add(ConfigNames.BLOCKS, temp); - } - -default void normalizeBlockData(JsonObject ore, JsonObject oreOut) { - JsonObject blockEntry = new JsonObject(); - String blockName; - - if (ore.has(ConfigNames.STATE)) { - blockEntry.addProperty(ConfigNames.STATE, ore.get(ConfigNames.STATE).getAsString()); - } else if (ore.has(ConfigNames.METADATA)) { - blockEntry.addProperty(ConfigNames.METADATA, ore.get(ConfigNames.METADATA).getAsInt()); - } - - if (ore.has(ConfigNames.BLOCKID)) { - blockName = ore.get(ConfigNames.BLOCKID).getAsString(); - } else if (ore.has(ConfigNames.BLOCK)) { - blockName = ore.get(ConfigNames.BLOCK).getAsString(); - } else { - blockName = "i_am_a_dumbass"; - } - - blockEntry.addProperty(ConfigNames.BLOCK_V2, blockName); - - oreOut.add(ConfigNames.BLOCKS, blockEntry); - } - -default JsonArray getDimensionData(JsonObject retVal, int dimension) { - if (!retVal.has("dimensions")) { - retVal.add("dimensions", new JsonObject()); - } - - if (!retVal.getAsJsonObject("dimensions").has(String.format("%d", dimension))) { - retVal.getAsJsonObject("dimensions").add(String.format("%d", dimension), new JsonArray()); - } - - return retVal.getAsJsonObject("dimensions").getAsJsonArray(String.format("%d", dimension)); - } - - /** - * called with a JsonObject that has to be iterated, copied and all variable references replaced with the data they - * refer to - * @param objReplace object to do variable replacement on - * @return copy of objReplace with all variables interpolated in - */ -default JsonObject replaceVariables(JsonObject objReplace) { - JsonObject retVal = new JsonObject(); - - objReplace.entrySet().forEach(entry -> retVal.add(entry.getKey(), replaceVariablesBase(entry.getValue()))); - - return retVal; - } - -default JsonElement replaceVariablesBase(JsonElement value) { - if (value.isJsonPrimitive() && value.getAsString().startsWith("$.")) { - return replaceVariablePrimitive(value); - } else if (value.isJsonPrimitive()) { - return value; - } else if (value.isJsonArray()) { - return replaceVariableArray(value); - } else if (value.isJsonObject()) { - return replaceVariables(value.getAsJsonObject()); - } else { - return value; - } - } - -default JsonElement replaceVariableArray(JsonElement value) { - JsonArray retVal = new JsonArray(); - - value.getAsJsonArray().forEach(item -> retVal.add(replaceVariablesBase(item))); - return retVal; - } - - // variable looks like: "$.

." -default JsonElement replaceVariablePrimitive(JsonElement value) { - String rawVal = value.getAsString().substring(2); - String[] bits = rawVal.split("\\."); - String section = bits[0]; - String item = bits[1]; - return getStorage().getSymbolSection(section, item); - } - -default String getBlockName(JsonObject ore) { - String key; - - if (ore.has(Constants.ConfigNames.BLOCK)) { - key = Constants.ConfigNames.BLOCK; - } else if (ore.has(Constants.ConfigNames.BLOCKID)) { - key = Constants.ConfigNames.BLOCKID; - } else { - return String.format("ore-%d", new Random().nextInt()); - } - - return ore.get(key).getAsString(); - } - -default String getBlockNameMulti(JsonObject ore) { - List rv = new LinkedList<>(); - JsonArray ores = ore.get(Constants.ConfigNames.BLOCKS).getAsJsonArray(); - - for (JsonElement o : ores) { - rv.add(o.getAsJsonObject().get(Constants.ConfigNames.BLOCK_V2).getAsString()); - } - - return String.join("-", rv.toArray(new String[0])); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java deleted file mode 100644 index dffb58f3..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/Helpers.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.mcmoddev.orespawn.json.os3.readers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -import com.google.common.collect.ImmutableSet; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; -import com.mcmoddev.orespawn.impl.location.BiomeLocationDictionary; -import com.mcmoddev.orespawn.impl.location.BiomeLocationList; -import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.common.BiomeDictionary; -import net.minecraftforge.fml.common.registry.ForgeRegistries; -import net.minecraftforge.oredict.OreDictionary; - -public class Helpers { - - private Helpers() {} - - private static BiomeLocation deserializeSingleEntry(String in) { - if (in.contains(":")) { - String[] parts = in.split(":"); - return new BiomeLocationSingle(ForgeRegistries.BIOMES.getValue(new ResourceLocation(parts[0], parts[1]))); - } else { - return new BiomeLocationDictionary(BiomeDictionary.Type.getType(in)); - } - } - - private static BiomeLocation deserializeBiomeLocationList(JsonArray in) { - List myData = new ArrayList<>(); - - if (in.size() == 0) { - return new BiomeLocationList(ImmutableSet.copyOf(Collections.emptySet())); - } - - in.forEach(elem -> { - if (elem.isJsonPrimitive()) { - myData.add(deserializeSingleEntry(elem.getAsString())); - } else if (elem.isJsonObject()) { - myData.add(deserializeBiomeLocationComposition(elem.getAsJsonObject())); - } - }); - - return new BiomeLocationList(ImmutableSet.copyOf(myData)); - } - - public static BiomeLocationComposition deserializeBiomeLocationComposition(JsonObject in) { - JsonArray includeArr = in.getAsJsonArray(ConfigNames.BiomeStuff.WHITELIST); - JsonArray excludeArr = in.getAsJsonArray(ConfigNames.BiomeStuff.BLACKLIST); - - if (includeArr == null) { - includeArr = new JsonArray(); - } - - if (excludeArr == null) { - excludeArr = new JsonArray(); - } - - BiomeLocation includes = null; - BiomeLocation excludes = null; - - if (includeArr.size() > 0) { - includes = deserializeBiomeLocationList(includeArr); - } - - if (excludeArr.size() > 0) { - excludes = deserializeBiomeLocationList(excludeArr); - } - - return new BiomeLocationComposition((includes == null) ? ImmutableSet.copyOf(Collections.emptySet()) : ImmutableSet.of(includes), - (excludes == null) ? ImmutableSet.copyOf(Collections.emptySet()) : ImmutableSet.of(excludes)); - } - - private static void handleState(JsonObject ore, OreBuilder oreB, String oreName) { - if (ore.has(ConfigNames.STATE)) { - String stateString = ore.get(ConfigNames.STATE).getAsString(); - - if (ConfigNames.STATE_NORMAL.equals(stateString)) { - oreB.setOre(oreName); - } else { - oreB.setOre(oreName, stateString); - } - } else { - if (ore.has(ConfigNames.METADATA)) { - oreB.setOre(oreName, ore.get(ConfigNames.METADATA).getAsInt()); - } else { - oreB.setOre(oreName); - } - } - } - - private static OreBuilder parseOreEntry(JsonObject oreSpawn, ISpawnBuilder spawn) { - String blockName = oreSpawn.has(ConfigNames.BLOCK) ? ConfigNames.BLOCK : ConfigNames.BLOCK_V2; - String oreName = oreSpawn.get(blockName).getAsString(); - int chance = oreSpawn.has(ConfigNames.CHANCE) ? oreSpawn.get(ConfigNames.CHANCE).getAsInt() : 100; - - OreBuilder thisOre = spawn.newOreBuilder(); - - handleState(oreSpawn, thisOre, oreName); - - thisOre.setChance(chance); - - return thisOre; - } - - private static List loadOreDict(JsonObject oreObj, ISpawnBuilder spawn) { - String oreName = oreObj.get(ConfigNames.BLOCK).getAsString().split(":")[1]; - int chance = oreObj.has(ConfigNames.CHANCE) ? oreObj.get(ConfigNames.CHANCE).getAsInt() : 100; - List retval = new ArrayList<>(); - - NonNullList ores = OreDictionary.getOres(oreName); - - for (ItemStack ore : ores) { - OreBuilder thisOre = spawn.newOreBuilder(); - thisOre.setOre(ore.getItem(), ore.getMetadata()); - thisOre.setChance(chance); - retval.add(thisOre); - } - - return retval; - } - - public static List loadOres(JsonArray oresArray, ISpawnBuilder spawn) { - List rV = new LinkedList<>(); - - oresArray.forEach(oreEntry -> { - JsonObject work = oreEntry.getAsJsonObject(); - String oreName = work.get(ConfigNames.BLOCK_V2).getAsString(); - OreBuilder ores = spawn.newOreBuilder(); - - if (work.has(ConfigNames.STATE) || work.has(ConfigNames.METADATA)) { - Helpers.handleState(work, ores, oreName); - rV.add(ores); - } else { - if (oreName.toLowerCase().startsWith("ore:")) { - rV.addAll(Helpers.loadOreDict(work, spawn)); - } else { - rV.add(Helpers.parseOreEntry(work, spawn)); - } - } - }); - - return rV; - } - -} diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java deleted file mode 100644 index 13129a6f..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V1Reader.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.mcmoddev.orespawn.json.os3.readers; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.json.os3.IOS3Reader; - -public final class OS3V1Reader implements IOS3Reader { - - @Override - public JsonObject parseJson(JsonObject entries, String fileName) { - JsonArray elements = entries.get(ConfigNames.DIMENSIONS).getAsJsonArray(); - - JsonObject retVal = new JsonObject(); - - for (JsonElement element : elements) { - JsonObject object = element.getAsJsonObject(); - JsonArray dimData; - int dimension = object.has(ConfigNames.DIMENSION) ? object.get(ConfigNames.DIMENSION).getAsInt() : OreSpawn.API.dimensionWildcard(); - - dimData = getDimensionData(retVal, dimension); - - JsonArray ores = object.get(ConfigNames.ORES).getAsJsonArray(); - - for (JsonElement oresEntry : ores) { - JsonObject ore = oresEntry.getAsJsonObject(); - ore.addProperty("retrogen", true); - ore.addProperty("enabled", true); - - JsonObject oreOut = handleVersionDifferences(ore, entries.get(ConfigNames.FILE_VERSION).getAsString()); - dimData.add(oreOut); - } - - retVal.getAsJsonObject("dimensions").add(Integer.toString(dimension), dimData); - } - - return retVal; - } - - private JsonObject handleVersionDifferences(JsonObject ore, String version) { - JsonObject returnValue = new JsonObject(); - - if ("1".equals(version) || "1.1".equals(version)) { - copyOverSingleBlock(ore, returnValue); - } - - switch (version) { - case "1.2": - ore.entrySet().forEach(prop -> returnValue.add(prop.getKey(), prop.getValue())); - break; - - case "1.1": - JsonArray biomes = ore.has(ConfigNames.BIOMES) ? ore.getAsJsonArray(ConfigNames.BIOMES) : new JsonArray(); - JsonObject biomeObj = new JsonObject(); - biomeObj.add(biomes.size() < 1 ? ConfigNames.BiomeStuff.BLACKLIST : ConfigNames.BiomeStuff.WHITELIST, biomes); - returnValue.add(ConfigNames.BIOMES, biomeObj); - returnValue.add(ConfigNames.BIOMES, new JsonObject()); - returnValue.addProperty(ConfigNames.BLOCK_V2, getBlockName(ore)); - break; - - case "1": - returnValue.add(ConfigNames.BIOMES, new JsonObject()); - returnValue.addProperty(ConfigNames.BLOCK_V2, getBlockName(ore)); - break; - - default: - break; - } - - return returnValue; - } - -} diff --git a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V2Reader.java b/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V2Reader.java deleted file mode 100644 index 99e24740..00000000 --- a/src/main/java/com/mcmoddev/orespawn/json/os3/readers/OS3V2Reader.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.mcmoddev.orespawn.json.os3.readers; - -import java.util.Map.Entry; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.data.Constants.ConfigNames; -import com.mcmoddev.orespawn.json.os3.IOS3Reader; -import com.mcmoddev.orespawn.util.OS3V2PresetStorage; - -public class OS3V2Reader implements IOS3Reader { - private OS3V2PresetStorage storage = new OS3V2PresetStorage(); - - @Override - public OS3V2PresetStorage getStorage() { - return this.storage; - } - - @Override - public JsonObject parseJson(JsonObject entries, String fileName) { - // do we have any presets ? - JsonObject spawns = entries.getAsJsonObject("spawns"); - JsonObject retVal = new JsonObject(); - - storage.clear(); - OreSpawn.API.getPresets().copy(storage); - - loadLocalPresets(entries); - - // 'work' contains the reduced, no-variables-here data - JsonObject work = new JsonObject(); - spawns.entrySet().forEach(entry -> work.add(entry.getKey(), replaceVariables(entry.getValue().getAsJsonObject()))); - - work.entrySet().forEach(entry -> { - JsonObject lw = setHandleDimensions(entry.getValue().getAsJsonObject()); - - lw.getAsJsonArray(ConfigNames.DIMENSIONS).getAsJsonArray().forEach( - dim -> { - JsonObject nw = new JsonObject(); - nw.addProperty("name", entry.getKey()); - - if (lw.has(ConfigNames.DIMENSION)) - nw.add(ConfigNames.DIMENSION, lw.getAsJsonObject(ConfigNames.DIMENSION)); - - entry.getValue().getAsJsonObject().entrySet().stream() - .filter(e -> !e.getKey().equals(ConfigNames.DIMENSIONS)) - .forEach(ent -> nw.add(ent.getKey(), ent.getValue())); - JsonArray thisDim = getDimensionData(retVal, dim.getAsInt()); - thisDim.add(nw); - - JsonObject dimStore; - if (retVal.has(ConfigNames.DIMENSIONS)) { - dimStore = retVal.getAsJsonObject(ConfigNames.DIMENSIONS); - } else { - dimStore = new JsonObject(); - } - dimStore.add(dim.getAsString(), thisDim); - retVal.add(ConfigNames.DIMENSIONS, dimStore); - }); - }); - - return retVal; - } - - private JsonObject setHandleDimensions(JsonObject spawnEntry) { - JsonObject lw = spawnEntry; - - if (lw.get(ConfigNames.DIMENSIONS).isJsonArray()) { - if (lw.getAsJsonArray(ConfigNames.DIMENSIONS).size() < 1) { - JsonArray temp = lw.getAsJsonArray(ConfigNames.DIMENSIONS); - temp.add(OreSpawn.API.dimensionWildcard()); - lw.remove(ConfigNames.DIMENSIONS); - lw.add(ConfigNames.DIMENSIONS, temp); - } - } else { - JsonObject dimSet = lw.getAsJsonObject(ConfigNames.DIMENSIONS); - lw.add(ConfigNames.DIMENSION, dimSet); - lw.remove(ConfigNames.DIMENSIONS); - JsonArray temp = new JsonArray(); - temp.add(OreSpawn.API.dimensionWildcard()); - lw.add(ConfigNames.DIMENSIONS, temp); - } - - return lw; - } - - private void loadLocalPresets(JsonObject entries) { - boolean hasPresets = entries.has("presets"); - - if (hasPresets) { - for (Entry preset : entries.get("presets").getAsJsonObject().entrySet()) { - String sectionName = preset.getKey(); - JsonObject entry = preset.getValue().getAsJsonObject(); - - for (Entry variables : entry.entrySet()) { - String itemName = variables.getKey(); - JsonElement varValue = variables.getValue(); - storage.setSymbolSection(sectionName, itemName, varValue); - } - } - } - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/util/OS3V2PresetStorage.java b/src/main/java/com/mcmoddev/orespawn/util/OS3V2PresetStorage.java deleted file mode 100644 index 0f577b4b..00000000 --- a/src/main/java/com/mcmoddev/orespawn/util/OS3V2PresetStorage.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.mcmoddev.orespawn.util; - -import java.util.HashMap; -import java.util.Map; -import java.util.TreeMap; - -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; - -public class OS3V2PresetStorage { - private final Map> storage; - - public OS3V2PresetStorage() { - storage = new TreeMap<>(); - } - - public void setSymbolSection(String sectionName, String itemName, JsonElement value) { - Map temp = storage.getOrDefault(sectionName, new HashMap()); - temp.put(itemName, value); - storage.put(sectionName, temp); - } - - public JsonElement getSymbolSection(String sectionName, String itemName) { - if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { - return storage.get(sectionName).get(itemName); - } else { - return new JsonPrimitive(itemName); - } - } - - public void copy(OS3V2PresetStorage dest) { - storage.entrySet().stream() - .forEach(ensm -> { - String section = ensm.getKey(); - ensm.getValue().entrySet().forEach(ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); - }); - } - - public void clear() { - this.storage.clear(); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/util/OreList.java b/src/main/java/com/mcmoddev/orespawn/util/OreList.java deleted file mode 100644 index 1ee99ac9..00000000 --- a/src/main/java/com/mcmoddev/orespawn/util/OreList.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.mcmoddev.orespawn.util; - -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Random; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import net.minecraft.block.state.IBlockState; - -public class OreList { - private List myChanceList; - private List myCopy; - - private Integer listCount = 0; - - public OreList() { - this.myChanceList = new LinkedList<>(); - this.myCopy = new LinkedList<>(); - } - - public void build(List ores) { - ores.stream().sorted(Comparator.comparingInt(OreBuilder::getChance)) - .forEach(ob -> { myChanceList.add(ob.getChance()); myCopy.add(ob); }); - - this.listCount = myChanceList.stream().mapToInt(Integer::intValue).max().getAsInt(); - } - - public OreBuilder getRandomOre(Random rand) { - int v = rand.nextInt(this.listCount); - - int c = 0; - - for (Integer i : this.myChanceList) { - c += i; - - if (c > v) { - OreBuilder rv = this.getOreWithChance(i); - - if (rv == null) { - break; - } else { - return rv; - } - } - } - - return this.getMaxChanceOre(); - } - - private OreBuilder getMaxChanceOre() { - return this.getOreWithChance(this.myChanceList.stream().mapToInt(Integer::intValue).max().getAsInt()); - } - - private OreBuilder getOreWithChance(int intValue) { - for (OreBuilder o : this.myCopy) { - if (o.getChance() == intValue) { - return o; - } - } - - return null; - } - - public ImmutableList getOres() { - return ImmutableList.copyOf(this.myCopy.stream().map(OreBuilder::getOre).distinct().collect(Collectors.toList())); - } -} From ffd2f82694cb1a220100f10d2ccbec9e60860cc3 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 01:18:20 -0400 Subject: [PATCH 025/205] clean up the API change errors in the actual generation code. This just leaves the commands and the core mod code. --- .../mcmoddev/orespawn/api/FeatureBase.java | 55 +++++++-------- .../orespawn/api/GeneratorParameters.java | 55 --------------- .../com/mcmoddev/orespawn/api/IFeature.java | 4 +- .../orespawn/api/os3/ISpawnEntry.java | 6 ++ .../impl/features/ClusterGenerator.java | 55 ++++++--------- .../features/DefaultFeatureGenerator.java | 50 +++++-------- .../impl/features/NormalCloudGenerator.java | 47 +++++-------- .../impl/features/PrecisionGenerator.java | 70 ++++++++----------- .../orespawn/impl/features/VeinGenerator.java | 54 ++++++-------- .../orespawn/impl/os3/SpawnEntry.java | 9 +++ .../orespawn/worldgen/OreSpawnWorldGen.java | 61 ++-------------- 11 files changed, 155 insertions(+), 311 deletions(-) delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeneratorParameters.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 18c1329a..998bff96 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -1,22 +1,21 @@ package com.mcmoddev.orespawn.api; -import com.google.common.collect.ImmutableSet; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; -import com.mcmoddev.orespawn.util.OreList; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import net.minecraftforge.registries.IForgeRegistryEntry; import java.util.*; import java.util.Map.Entry; -public class FeatureBase { +public class FeatureBase extends IForgeRegistryEntry.Impl { private static final int MAX_CACHE_SIZE = 2048; /** overflow cache so that ores that spawn at edge of chunk can * appear in the neighboring chunk without triggering a chunk-load */ @@ -28,19 +27,19 @@ public FeatureBase(Random rand) { this.random = rand; } - protected void runCache(int chunkX, int chunkZ, World world, List blockReplace) { + protected void runCache(int chunkX, int chunkZ, World world, OreSpawnBlockMatcher replacer) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it for (Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), blockReplace); + spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), replacer); } } } protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow, - List blockReplace, BiomeLocation biomes) { + ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return false; @@ -48,7 +47,7 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d Biome thisBiome = world.getBiome(coord); - if (!biomes.matches(thisBiome) && !biomes.getBiomes().isEmpty()) { + if (!spawnData.biomeAllowed(thisBiome)) { return false; } @@ -59,7 +58,7 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d return false; } - return spawnOrCache(world, np, blockReplace, oreBlock, cacheOverflow, dimension); + return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension); } private BlockPos mungeFixYcoord(BlockPos coord) { @@ -71,11 +70,11 @@ private BlockPos mungeFixYcoord(BlockPos coord) { } } - private boolean spawnOrCache(World world, BlockPos coord, List blockReplace, IBlockState oreBlock, boolean cacheOverflow, int dimension) { + private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, IBlockState oreBlock, boolean cacheOverflow, int dimension) { if (world.isBlockLoaded(coord)) { IBlockState targetBlock = world.getBlockState(coord); - if (canReplace(targetBlock, blockReplace)) { + if (replacer.test(targetBlock)) { world.setBlockState(coord, oreBlock); return true; } else { @@ -90,7 +89,7 @@ private boolean spawnOrCache(World world, BlockPos coord, List bloc } private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int dimension, - List blockReplace) { + OreSpawnBlockMatcher replacer) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return; @@ -103,7 +102,7 @@ private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int return; } - spawnOrCache(world, np, blockReplace, oreBlock, false, dimension); + spawnOrCache(world, np, replacer, oreBlock, false, dimension); } private void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension) { @@ -145,10 +144,6 @@ protected void scramble(int[] target, Random prng) { } } - private boolean canReplace(IBlockState target, List blockToReplace) { - return !target.getBlock().equals(Blocks.AIR) && blockToReplace.contains(target); - } - protected static final Vec3i[] offsets_small = { new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), @@ -198,15 +193,15 @@ protected int getPoint(int lowerBound, int upperBound, int median) { } protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius, - List replaceBlock, int count, OreList possibleOres) { + OreSpawnBlockMatcher replacer, int count, IBlockList possibleOres) { Random prng = this.random; int quantity = count; for(int dy = (int)(-1 * radius); dy < radius; dy++){ for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){ for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){ if((dx*dx + dy*dy + dz*dz) <= rSqr){ - IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre(); - spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension()); + IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension()); quantity--; } if(quantity <= 0) { @@ -219,15 +214,15 @@ protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double rad protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, - List replaceBlock, int count, OreList possibleOres) { + OreSpawnBlockMatcher replacer, int count, IBlockList possibleOres) { Random prng = this.random; int quantity = count; for(int dy = (int)(-1 * radius); dy < radius; dy++){ for(int dz = (int)(-1 * radius); dz < radius; dz++){ for(int dx = (int)(-1 * radius); dx < radius; dx++){ if((dx*dx + dy*dy + dz*dz) <= rSqr){ - IBlockState oreBlock = possibleOres.getRandomOre(prng).getOre(); - spawnOrCache(world,blockPos.add(dx,dy,dz),replaceBlock, oreBlock, true, world.provider.getDimension()); + IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension()); quantity--; } if(quantity <= 0) { @@ -258,7 +253,7 @@ public class FunctionParameterWrapper { private World world; private BlockPos blockPos; private List replacements; - private OreList ores; + private IBlockList blocks; private BiomeLocation biomes; private ChunkPos chunkPos; private IBlockState block; @@ -269,7 +264,7 @@ public FunctionParameterWrapper(FunctionParameterWrapper other) { world = other.getWorld(); blockPos = other.getBlockPos(); replacements = other.getReplacements(); - ores = other.getOres(); + blocks = other.getOres(); biomes = other.getBiomes(); chunkPos = other.getChunkPos(); block = other.getBlock(); @@ -307,12 +302,12 @@ public void setReplacements(List replacements) { this.replacements = replacements; } - public OreList getOres() { - return ores; + public IBlockList getOres() { + return blocks; } - public void setOres(OreList ores) { - this.ores = ores; + public void setOres(IBlockList ores) { + this.blocks = ores; } public ChunkPos getChunkPos() { diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeneratorParameters.java b/src/main/java/com/mcmoddev/orespawn/api/GeneratorParameters.java deleted file mode 100644 index c7929ef3..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/GeneratorParameters.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import com.google.common.collect.ImmutableList; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.util.OreList; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.ChunkPos; - -import java.util.List; -import java.util.Map; - -public class GeneratorParameters { - - private final ChunkPos chunk; - private final OreList ores; - private final ImmutableList replacements; - private final JsonObject parameters; - private final BiomeLocation biomes; - - public GeneratorParameters(ChunkPos chunkPos, OreList oreList, List replacementBlocks, - BiomeLocation biomes, JsonObject generatorParameters) { - this.parameters = new JsonObject(); - - for (Map.Entry stringJsonElementEntry : generatorParameters.entrySet()) { - this.parameters.add(stringJsonElementEntry.getKey(), stringJsonElementEntry.getValue()); - } - - this.chunk = new ChunkPos(chunkPos.x, chunkPos.z); - this.ores = oreList; - this.replacements = ImmutableList.copyOf(replacementBlocks); - this.biomes = biomes; - } - - public ChunkPos getChunk() { - return chunk; - } - - public BiomeLocation getBiomes() { - return biomes; - } - - public ImmutableList getReplacements() { - return replacements; - } - - public JsonObject getParameters() { - return parameters; - } - - public OreList getOres() { - return ores; - } - -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java index 126494c9..32458843 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java @@ -3,7 +3,9 @@ import java.util.Random; import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.registries.IForgeRegistryEntry; @@ -11,7 +13,7 @@ public interface IFeature extends IForgeRegistryEntry { void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters); + ISpawnEntry spawn, ChunkPos pos); void setRandom(Random rand); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 8e7a2291..515b0845 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -1,7 +1,11 @@ package com.mcmoddev.orespawn.api.os3; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; import com.mcmoddev.orespawn.api.IBlockList; @@ -21,4 +25,6 @@ default public boolean isRetrogen() { public IFeatureEntry getFeature(); public OreSpawnBlockMatcher getMatcher(); public IBlockList getBlocks(); + + public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index cd8e226a..1ab81ad2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -2,12 +2,11 @@ import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.GeneratorParameters; import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.OreList; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; @@ -16,8 +15,6 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; -import java.util.LinkedList; -import java.util.List; import java.util.Random; public class ClusterGenerator extends FeatureBase implements IFeature { @@ -32,13 +29,10 @@ public ClusterGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters) { - ChunkPos pos = parameters.getChunk(); - List blockReplace = new LinkedList<>(); - blockReplace.addAll(parameters.getReplacements()); - JsonObject params = parameters.getParameters(); - OreList ores = parameters.getOres(); - BiomeLocation biomes = parameters.getBiomes(); + ISpawnEntry spawnData, ChunkPos _pos) { + ChunkPos pos = _pos; + OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); + JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; @@ -46,7 +40,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, blockReplace); + runCache(chunkX, chunkZ, world, replaceMatch); // now to ore spawn @@ -80,14 +74,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int y = random.nextInt(maxHeight - minHeight) + minHeight; int z = blockZ + zRand - (maxSpread / 2); - FunctionParameterWrapper fp = new FunctionParameterWrapper(); - fp.setBlockPos(new BlockPos(x, y, z)); - fp.setWorld(world); - fp.setReplacements(blockReplace); - fp.setBiomes(biomes); - fp.setOres(ores); - - spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, fp); + spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, spawnData, world, new BlockPos(x,y,z)); } tries--; @@ -95,7 +82,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } private void spawnCluster(int clusterSize, int variance, int clusterCount, int maxSpread, int minHeight, - int maxHeight, FunctionParameterWrapper params) { + int maxHeight, ISpawnEntry spawnData, World world, BlockPos pos) { // spawn a cluster at the center, then a bunch around the outside... int r = clusterSize - variance; @@ -103,7 +90,7 @@ private void spawnCluster(int clusterSize, int variance, int clusterCount, int m r += this.random.nextInt(2 * variance) - variance; } - spawnChunk(params, r); + spawnChunk(world, pos, spawnData, r); int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary inside that @@ -124,16 +111,14 @@ private void spawnCluster(int clusterSize, int variance, int clusterCount, int m int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); int zp = getPoint(-radius, radius, 0); - BlockPos p = params.getBlockPos().add(xp, yp, zp); - FunctionParameterWrapper np = new FunctionParameterWrapper(params); - np.setBlockPos(p); - spawnChunk(np, r); + BlockPos p = pos.add(xp, yp, zp); + spawnChunk(world, p, spawnData, r); count -= r; } } - private void spawnChunk(FunctionParameterWrapper params, int quantity) { + private void spawnChunk(World world, BlockPos pos, ISpawnEntry spawnData, int quantity) { int count = quantity; int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -141,7 +126,7 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) { System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - int dimension = params.getWorld().provider.getDimension(); + int dimension = world.provider.getDimension(); if (quantity < 27) { int[] scrambledLUT = new int[lutType]; @@ -150,9 +135,9 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) { int z = 0; while (count > 0) { - IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre(); + IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - if (!spawn(oreBlock, params.getWorld(), params.getBlockPos().add(offs[scrambledLUT[--count]]), dimension, true, params.getReplacements(), params.getBiomes())) { + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, spawnData)) { count++; z++; } else { @@ -169,17 +154,17 @@ private void spawnChunk(FunctionParameterWrapper params, int quantity) { return; } - doSpawnFill(this.random.nextBoolean(), count, params); + doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) { + private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnData, World world, BlockPos pos) { int count = quantity; double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int)(radius * radius); if( nextBoolean ) { - spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); + spawnMungeNE( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); } else { - spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); + spawnMungeSW( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 2cc3c93e..cb7daaef 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -1,16 +1,13 @@ package com.mcmoddev.orespawn.impl.features; -import java.util.LinkedList; -import java.util.List; import java.util.Random; import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.GeneratorParameters; import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.OreList; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -29,13 +26,10 @@ public DefaultFeatureGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters) { - ChunkPos pos = parameters.getChunk(); - List replaceBlock = new LinkedList<>(); - replaceBlock.addAll(parameters.getReplacements()); - JsonObject params = parameters.getParameters(); - OreList ores = parameters.getOres(); - BiomeLocation biomes = parameters.getBiomes(); + ISpawnEntry spawnData, ChunkPos _pos) { + ChunkPos pos = _pos; + OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); + JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; @@ -43,7 +37,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, replaceBlock); + runCache(chunkX, chunkZ, world, replaceMatch); // now to ore spawn @@ -56,12 +50,6 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - FunctionParameterWrapper fp = new FunctionParameterWrapper(); - fp.setWorld(world); - fp.setReplacements(replaceBlock); - fp.setBiomes(biomes); - fp.setOres(ores); - if (freq >= 1) { for (int i = 0; i < freq; i++) { int x = blockX + random.nextInt(16); @@ -76,8 +64,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r = 0; } - fp.setBlockPos(new BlockPos(x, y, z)); - spawnOre(fp, size + r); + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); } } else if (random.nextFloat() < freq) { int x = blockX + random.nextInt(8); @@ -91,13 +78,12 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r = 0; } - fp.setBlockPos(new BlockPos(x, y, z)); - spawnOre(fp, size + r); + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); } } - private void spawnOre(FunctionParameterWrapper params, int quantity) { + private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quantity) { int count = quantity; int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -111,26 +97,26 @@ private void spawnOre(FunctionParameterWrapper params, int quantity) { scramble(scrambledLUT, this.random); while (count > 0) { - IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre(); - BlockPos target = params.getBlockPos().add(offs[scrambledLUT[--count]]); - spawn(oreBlock, params.getWorld(), target, - params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes()); + IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, + world.provider.getDimension(), true, spawnData); } return; } - doSpawnFill(this.random.nextBoolean(), count, params); + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, FunctionParameterWrapper params) { + private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, BlockPos pos) { int count = quantity; double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int)(radius * radius); if( nextBoolean ) { - spawnMungeNE( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); + spawnMungeNE( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); } else { - spawnMungeSW( params.getWorld(), params.getBlockPos(), rSqr, radius, params.getReplacements(), count, params.getOres() ); + spawnMungeSW( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index ac43b7e3..96bcc477 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -1,19 +1,15 @@ package com.mcmoddev.orespawn.impl.features; -import java.util.LinkedList; -import java.util.List; import java.util.Random; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.GeneratorParameters; import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.OreList; -import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; @@ -32,20 +28,18 @@ public NormalCloudGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters) { - ChunkPos pos = parameters.getChunk(); - List blockReplace = new LinkedList<>(); - blockReplace.addAll(parameters.getReplacements()); - JsonObject params = parameters.getParameters(); - OreList ores = parameters.getOres(); - BiomeLocation biomes = parameters.getBiomes(); + ISpawnEntry spawnData, ChunkPos _pos) { + ChunkPos pos = _pos; + OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); + JsonObject params = spawnData.getFeature().getFeatureParameters(); + // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; int chunkZ = pos.z; mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, blockReplace); + runCache(chunkX, chunkZ, world, replaceMatch); // now to ore spawn @@ -104,14 +98,9 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r += random.nextInt(2 * variance) - variance; } - FunctionParameterWrapper fp = new FunctionParameterWrapper(); - fp.setBlockPos(new BlockPos(x, y, z)); - fp.setWorld(world); - fp.setReplacements(blockReplace); - fp.setBiomes(biomes); - fp.setOres(ores); + BlockPos p = new BlockPos(x, y, z); - if (!spawnCloud(r, maxSpread, minHeight, maxHeight, fp) && tryCount < 5) { + if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) && tryCount < 5) { // make another try! tries++; frequency = 100; @@ -125,11 +114,11 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight, FunctionParameterWrapper params) { + private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight, BlockPos pos, ISpawnEntry spawnData, World world) { // spawn one right at the center here, then generate for the cloud and do the math - if (!spawn(params.getOres().getRandomOre(random).getOre(), params.getWorld(), params.getBlockPos(), - params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes())) { + if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, + world.provider.getDimension(), true, spawnData)) { return false; } @@ -142,23 +131,23 @@ private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); int zp = getPoint(0, maxSpread, radius); - BlockPos p = params.getBlockPos().add(xp, yp, zp); + BlockPos p = pos.add(xp, yp, zp); int z = 0; - while (z < 5 && !spawn(params.getOres().getRandomOre(random).getOre(), params.getWorld(), p, - params.getWorld().provider.getDimension(), true, params.getReplacements(), params.getBiomes())) { + while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, + world.provider.getDimension(), true, spawnData)) { xp = getPoint(0, maxSpread, radius); yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); zp = getPoint(0, maxSpread, radius); - p = params.getBlockPos().add(xp, yp, zp); + p = pos.add(xp, yp, zp); z++; } if (z >= 5 && !alreadySpewed) { - OreSpawn.LOGGER.info("unable to achieve requested cloud density for cloud centered at %s", params.getBlockPos()); + OreSpawn.LOGGER.info("unable to achieve requested cloud density for cloud centered at %s", pos); alreadySpewed = true; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index f2dec73c..66447119 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -9,10 +9,10 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.GeneratorParameters; import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants.FormatBits; -import com.mcmoddev.orespawn.util.OreList; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -35,13 +35,10 @@ public PrecisionGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters) { - ChunkPos pos = parameters.getChunk(); - List blockReplace = new LinkedList<>(); - blockReplace.addAll(parameters.getReplacements()); - JsonObject params = parameters.getParameters(); - OreList ores = parameters.getOres(); - BiomeLocation biomes = parameters.getBiomes(); + ISpawnEntry spawnData, ChunkPos _pos) { + ChunkPos pos = _pos; + OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); + JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; @@ -49,7 +46,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, blockReplace); + runCache(chunkX, chunkZ, world, replaceMatch); // extract parameters int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); @@ -64,15 +61,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int sc; HeightRange hr = new HeightRange(minHeight, maxHeight); BlockPos spot = chooseSpot(chunkX, chunkZ, hr); - FunctionParameterWrapper fp = new FunctionParameterWrapper(); - fp.setBlockPos(spot); - fp.setWorld(world); - fp.setReplacements(blockReplace); - fp.setBiomes(biomes); - fp.setOres(ores); - fp.setChunkPos(new ChunkPos(chunkX, chunkZ)); - sc = spawnAtSpot(thisNode, hr, fp); + sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); // bit of feedback - if we underproduce or overproduce a node, the next one gets a correction if (sc != thisNode && sc != 0) { @@ -91,21 +81,19 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private int spawnAtSpot(int nodeSize, HeightRange heightRange, FunctionParameterWrapper params) { + private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, ChunkPos pos, ISpawnEntry spawnData, World world) { int spawned = 0; int c; - FunctionParameterWrapper np = new FunctionParameterWrapper(params); - BlockPos act = params.getBlockPos(); + BlockPos act = spot; int counter = nodeSize; while (counter > 0 && spawned < nodeSize) { - np.setBlockPos(act); - c = spawnOreNode(np, nodeSize, heightRange); + c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); if (c == 0) { - OreSpawn.LOGGER.debug("Unable to place block at %s (chunk %s)", np.getBlockPos(), np.getChunkPos()); - act = chooseSpot(Math.floorDiv(params.getBlockPos().getX(), 16), Math.floorDiv(params.getBlockPos().getZ(), 16), heightRange); + OreSpawn.LOGGER.debug("Unable to place block at %s (chunk %s)", spot, pos); + act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), heightRange); } counter -= (c + 1); @@ -115,7 +103,7 @@ private int spawnAtSpot(int nodeSize, HeightRange heightRange, FunctionParameter return spawned; } - private int spawnOreNode(FunctionParameterWrapper params, int nodeSize, HeightRange heightRange) { + private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, World world, int nodeSize, HeightRange heightRange) { int count = nodeSize; int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; @@ -132,12 +120,12 @@ private int spawnOreNode(FunctionParameterWrapper params, int nodeSize, HeightRa int nc = 0; for (; count > 0 && nc <= nodeSize; count--) { - IBlockState oreBlock = params.getOres().getRandomOre(this.random).getOre(); + IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); Vec3i offset = offs[scrambledLUT[--count]]; - BlockPos p = fixMungeOffset(offset, params.getBlockPos(), heightRange, params.getChunkPos()); - int dimension = params.getWorld().provider.getDimension(); + BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); + int dimension = world.provider.getDimension(); - if (spawn(oreBlock, params.getWorld(), p, dimension, true, params.getReplacements(), params.getBiomes())) { + if (spawn(oreBlock, world, p, dimension, true, spawnData)) { nc++; } } @@ -145,7 +133,7 @@ private int spawnOreNode(FunctionParameterWrapper params, int nodeSize, HeightRa return nc; } - return spawnFill(params, nodeSize, heightRange); + return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); } private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightRange, ChunkPos pos) { @@ -205,19 +193,19 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini return workingPoint - centerIn; } - private int spawnFill(FunctionParameterWrapper params, int nodeSize, HeightRange heightRange) { + private int spawnFill(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, int nodeSize, HeightRange heightRange) { double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int)Math.ceil(radius * radius); if (this.random.nextBoolean()) { - return spawnPrecise(params, heightRange, false, radius, rSqr, nodeSize); + return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, nodeSize); } else { - return spawnPrecise(params, heightRange, true, radius, rSqr, nodeSize); + return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, nodeSize); } } - private int spawnPrecise(FunctionParameterWrapper params, HeightRange heightRange, boolean toPositive, double radius, + private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, HeightRange heightRange, boolean toPositive, double radius, int rSqr, int nodeSize) { int quantity = nodeSize; int nc = 0; @@ -225,7 +213,7 @@ private int spawnPrecise(FunctionParameterWrapper params, HeightRange heightRang for (int dy = (int)(-1 * radius); dy < radius; dy++) { for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, radius); dx = countItem(dx, toPositive)) { for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, radius); dz = countItem(dz, toPositive)) { - if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, params) >= 0) { + if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, loc) >= 0) { nc++; quantity--; @@ -240,12 +228,12 @@ private int spawnPrecise(FunctionParameterWrapper params, HeightRange heightRang return nc; } - private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRange, FunctionParameterWrapper params) { + private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRange, ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc) { if (getABC(dx, dy, dz) <= rSqr) { - BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), params.getBlockPos(), heightRange, params.getChunkPos()); - IBlockState bl = params.getOres().getRandomOre(this.random).getOre(); - return spawn(bl, params.getWorld(), p, params.getWorld().provider.getDimension(), true, - params.getReplacements(), params.getBiomes()) ? 1 : 0; + BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); + IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); + return spawn(bl, world, p, world.provider.getDimension(), true, + spawnData) ? 1 : 0; } return -1; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 780f9986..b4e0a507 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -1,18 +1,15 @@ package com.mcmoddev.orespawn.impl.features; -import java.util.LinkedList; -import java.util.List; import java.util.Random; import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.GeneratorParameters; +import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.OreList; -import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; @@ -32,19 +29,16 @@ public VeinGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - GeneratorParameters parameters) { - ChunkPos pos = parameters.getChunk(); - List blockReplace = new LinkedList<>(); - blockReplace.addAll(parameters.getReplacements()); - JsonObject params = parameters.getParameters(); - OreList ores = parameters.getOres(); - BiomeLocation biomes = parameters.getBiomes(); - + ISpawnEntry spawnData, ChunkPos _pos) { + ChunkPos pos = _pos; + OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); + JsonObject params = spawnData.getFeature().getFeatureParameters(); + // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; int chunkZ = pos.z; - runCache(chunkX, chunkZ, world, blockReplace); + runCache(chunkX, chunkZ, world, replaceMatch); mergeDefaults(params, getDefaultParameters()); // now to ore spawn @@ -85,14 +79,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r = 0; } - FunctionParameterWrapper fp = new FunctionParameterWrapper(); - fp.setBlockPos(new BlockPos(x, y, z)); - fp.setWorld(world); - fp.setReplacements(blockReplace); - fp.setBiomes(biomes); - fp.setOres(ores); - - spawnVein(length + r, nodeSize, wander, fp); + spawnVein(length + r, nodeSize, wander, new BlockPos(x, y, z), spawnData, world); } tries--; @@ -185,13 +172,13 @@ private BlockPos adjustPos(BlockPos pos, int row, int col, EnumFace face) { return pos.add(adjust[0], adjust[1], adjust[2]); } - private void spawnVein(int length, int nodeSize, int wander, FunctionParameterWrapper params) { + private void spawnVein(int length, int nodeSize, int wander, BlockPos pos, ISpawnEntry spawnData, World world) { // passed in POS is our start - we start with a weighting favoring straight directions // and three-quarters that to the edges // and one-half to the corners // generate a node here - spawnOre(params, nodeSize); + spawnOre(pos, spawnData, world, nodeSize); // select a direction, decrement length, repeat float curRow = 1.00f; float curCol = 1.00f; @@ -199,7 +186,7 @@ private void spawnVein(int length, int nodeSize, int wander, FunctionParameterWr int rowAdj = 2; EnumFace faceToUse = EnumFace.getRandomFace(random); int l = length; - BlockPos workPos = new BlockPos(params.getBlockPos()); + BlockPos workPos = new BlockPos(pos); while (l > 0) { workPos = adjustPos(workPos, colAdj, rowAdj, faceToUse); @@ -222,9 +209,7 @@ private void spawnVein(int length, int nodeSize, int wander, FunctionParameterWr curRow /= 10; } - FunctionParameterWrapper np = new FunctionParameterWrapper(params); - np.setBlockPos(workPos); - spawnOre(np, nodeSize); + spawnOre(workPos, spawnData, world, nodeSize); // when nodes are small, the veins get badly broken if we do face wandering if (nodeSize > 2) { @@ -234,7 +219,7 @@ private void spawnVein(int length, int nodeSize, int wander, FunctionParameterWr } } - private void spawnOre(FunctionParameterWrapper params, int nodeSize) { + private void spawnOre(BlockPos pos, ISpawnEntry spawnData, World world, int nodeSize) { int count = nodeSize; int lutType = (count < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (count < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -245,12 +230,13 @@ private void spawnOre(FunctionParameterWrapper params, int nodeSize) { int[] scrambledLUT = new int[lutType]; System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); - int dimension = params.getWorld().provider.getDimension(); + int dimension = world.provider.getDimension(); + IBlockList blocks = spawnData.getBlocks(); while (count > 0) { - spawn(params.getOres().getRandomOre(random).getOre(), params.getWorld(), - params.getBlockPos().add(offs[scrambledLUT[--count]]), dimension, true, - params.getReplacements(), params.getBiomes()); + spawn(blocks.getRandomBlock(this.random), world, + pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index fcfc5029..b0f33fe8 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -8,7 +8,11 @@ import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.world.World; import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { @@ -80,4 +84,9 @@ public IBlockList getBlocks() { return this.blocks; } + @Override + public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos) { + this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 0ca89975..fd5bc551 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -1,46 +1,18 @@ package com.mcmoddev.orespawn.worldgen; import java.util.*; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.GeneratorParameters; -import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemBlock; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.chunk.IChunkProvider; import net.minecraftforge.fml.common.IWorldGenerator; -import net.minecraftforge.oredict.OreDictionary; public class OreSpawnWorldGen implements IWorldGenerator { - - private final Map> dimensions; - private static final List SPAWN_BLOCKS = new ArrayList<>(); - - public OreSpawnWorldGen(Map> allDimensions, long nextLong) { - this.dimensions = Collections.unmodifiableMap(allDimensions); - - if (SPAWN_BLOCKS.isEmpty()) { - SPAWN_BLOCKS.add(Blocks.STONE); - SPAWN_BLOCKS.add(Blocks.NETHERRACK); - SPAWN_BLOCKS.add(Blocks.END_STONE); - SPAWN_BLOCKS.addAll(OreDictionary.getOres("stone").stream().filter(stack -> stack.getItem() instanceof ItemBlock).map(stack -> ((ItemBlock) stack.getItem()).getBlock()).collect(Collectors.toList())); - } - } - - public static ImmutableList getSpawnBlocks() { - return ImmutableList.copyOf(SPAWN_BLOCKS); + public OreSpawnWorldGen() { } @Override @@ -48,31 +20,12 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG IChunkProvider chunkProvider) { int thisDim = world.provider.getDimension(); - List entries = new ArrayList<> (this.dimensions.getOrDefault(thisDim, new ArrayList<> ())); - - if (!this.dimensions.getOrDefault(OreSpawn.API.dimensionWildcard(), new ArrayList<>()).isEmpty()) - entries.addAll(this.dimensions.get(OreSpawn.API.dimensionWildcard()).stream() - .filter(ent -> (!ent.hasExtendedDimensions() && thisDim > 0 && thisDim != 1) || - ent.extendedDimensionsMatch(thisDim)) - .collect(Collectors.toList())); - - entries.stream() - .filter(ISpawnBuilder::enabled) - .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.retrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(sE -> { - if (sE == null || sE.getFeatureGen() == null) { - OreSpawn.LOGGER.fatal("From the state of things right now, you've likely had a parse-error happen and you have invalid JSON. You'll likely find some ores have not been generated."); - return; - } - IFeature currentFeatureGen = sE.getFeatureGen().getGenerator(); - List replacement = sE.getReplacementBlocks(); - replacement = replacement.isEmpty() ? ReplacementsRegistry.getDimensionDefault(thisDim) : replacement; - - GeneratorParameters parameters = new GeneratorParameters(new ChunkPos(chunkX, chunkZ), sE.getOreSpawns(), replacement, sE.getBiomes(), sE.getFeatureGen().getParameters()); - - currentFeatureGen.setRandom(random); - currentFeatureGen.generate(world, chunkGenerator, chunkProvider, parameters); - }); + + OreSpawn.API.getSpawns(thisDim).stream() + .filter(spawn -> spawn.isEnabled()) + .filter(spawn -> (spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) + || (!Config.getBoolean(Constants.RETROGEN_KEY))) + .forEach(spawn -> spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); } } From a3fb7b1ac1cd383011f3f0c3922190d728f88bdb Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 02:23:29 -0400 Subject: [PATCH 026/205] Clean up the code in the commands (mostly) along with some other roving cleanups. Of the commands, only /writeconfigs is left unfinished. --- .../exceptions/MissingVersionException.java | 5 + .../exceptions/NotAProperConfigException.java | 5 + .../api/exceptions/OldVersionException.java | 5 + .../exceptions/UnknownVersionException.java | 5 + .../com/mcmoddev/orespawn/api/os3/OS3API.java | 2 + .../orespawn/commands/AddOreCommand.java | 126 +++++------------- .../orespawn/commands/ClearChunkCommand.java | 18 ++- .../com/mcmoddev/orespawn/data/Constants.java | 14 +- .../orespawn/data/PresetsStorage.java | 4 - .../impl/features/PrecisionGenerator.java | 2 - .../orespawn/impl/os3/OS3APIImpl.java | 6 + .../orespawn/json/OreSpawnReader.java | 12 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 2 +- 13 files changed, 89 insertions(+), 117 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java index 4f6f339b..e2446a98 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java @@ -2,4 +2,9 @@ public class MissingVersionException extends Exception { + /** + * + */ + private static final long serialVersionUID = -4306852267351590384L; + } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java index 3d4c908f..99b6686b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java @@ -2,4 +2,9 @@ public class NotAProperConfigException extends Exception { + /** + * + */ + private static final long serialVersionUID = -7748241590958198482L; + } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java index e9bbb3c2..1d8c5f2d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java @@ -2,4 +2,9 @@ public class OldVersionException extends Exception { + /** + * + */ + private static final long serialVersionUID = 3760017140789193369L; + } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java index 9cd2a6b3..0ac73287 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java @@ -2,4 +2,9 @@ public class UnknownVersionException extends Exception { + /** + * + */ + private static final long serialVersionUID = 3817238409227005355L; + } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index d754b1d7..513346da 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -6,6 +6,7 @@ import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.data.PresetsStorage; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; public interface OS3API { @@ -18,6 +19,7 @@ public interface OS3API { public List getSpawns(int dimensionID); public ISpawnEntry getSpawn(String spawnName); public Map getAllSpawns(); + public List getDimensionDefaultReplacements(int dimensionID); public ISpawnBuilder getSpawnBuilder(); public IDimensionBuilder getDimensionBuilder(); diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 4d98b815..7cd3960b 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -2,14 +2,11 @@ import com.google.gson.*; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.os3.BiomeBuilder; -import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; -import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.data.Constants.ConfigNames; +import com.mcmoddev.orespawn.json.OreSpawnReader; import com.mcmoddev.orespawn.util.StateUtil; + +import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -20,14 +17,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.util.EnumHand; -import net.minecraft.util.text.TextComponentString; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; +import org.apache.commons.io.FilenameUtils; public class AddOreCommand extends CommandBase { - private static final String ALL = "all"; @Override public String getName() { @@ -36,7 +29,7 @@ public String getName() { @Override public String getUsage(ICommandSender sender) { - return "/addore "; + return "/addore "; } @Override @@ -47,7 +40,6 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args EntityPlayer player = (EntityPlayer) sender; ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); - String jsonArgs = null; if (stack == null) { throw new CommandException("You have no item in your main hand"); @@ -55,93 +47,39 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args throw new CommandException("The item in your main hand isn't a block"); } else if (args.length < 2) { throw new CommandException(this.getUsage(sender)); - } else if (args.length > 2) { - jsonArgs = getChatComponentFromNthArg(sender, args, 2).getUnformattedText(); } String file = args[0]; @SuppressWarnings("deprecation") - IBlockState state = ((ItemBlock) stack.getItem()).getBlock().getStateFromMeta(stack.getItemDamage()); - - int dimension = OreSpawn.API.dimensionWildcard(); - - try { - if (!args[1].equalsIgnoreCase(ALL)) { - dimension = Integer.parseInt(args[1]); - } - } catch (NumberFormatException e) { - throw new CommandException(args[1] + " isn't a valid dimension"); - } - - - JsonObject ore = new JsonObject(); - JsonObject oreArgs = null; - int size = 25; - int variation = 12; - int frequency = 20; - int minHeight = 0; - int maxHeight = 128; - - oreArgs = new JsonObject(); - oreArgs.addProperty(ConfigNames.DefaultFeatureProperties.SIZE, size); - oreArgs.addProperty(ConfigNames.DefaultFeatureProperties.VARIATION, variation); - oreArgs.addProperty(ConfigNames.DefaultFeatureProperties.FREQUENCY, frequency); - oreArgs.addProperty(ConfigNames.DefaultFeatureProperties.MINHEIGHT, minHeight); - oreArgs.addProperty(ConfigNames.DefaultFeatureProperties.MAXHEIGHT, maxHeight); - ore.addProperty(ConfigNames.BLOCK, state.getBlock().getRegistryName().toString()); - ore.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); - - if (jsonArgs != null) { - JsonObject newOreArgs = (new JsonParser()).parse(jsonArgs).getAsJsonObject(); - setProperties(oreArgs, newOreArgs); - } - - setOre(ore, oreArgs); - - this.putFile(file, ore, dimension); + IBlockState state = Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getItemDamage()); - player.sendStatusMessage(new TextComponentString("Added " + state.getBlock().getRegistryName().toString() + " to the json"), true); + String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); + JsonParser p = new JsonParser(); + JsonElement parsed = mergeDefaults(p.parse(rawData), state); + OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); } - - private void setProperties(JsonObject oreArgs, JsonObject newOreArgs) { - for (Entry ent : newOreArgs.entrySet()) { - oreArgs.remove(ent.getKey()); - oreArgs.add(ent.getKey(), ent.getValue()); - } - } - - private void setOre(JsonObject ore, JsonObject oreArgs) { - for (Entry ent : oreArgs.entrySet()) { - ore.add(ent.getKey(), ent.getValue()); - } - } - - private void putFile(String file, JsonObject ore, int id) { - IDimensionBuilder db = OreSpawn.API.getLogic(file).newDimensionBuilder(id); - ISpawnBuilder sb = db.newSpawnBuilder(null); - OreBuilder ob = sb.newOreBuilder(); - String b = ore.get(ConfigNames.BLOCK).getAsString(); - ore.remove(ConfigNames.BLOCK); - String s = ore.get(ConfigNames.STATE).getAsString(); - ore.remove(ConfigNames.STATE); - - if (ConfigNames.STATE_NORMAL.equals(s)) { - ob.setOre(b); - } else { - ob.setOre(b, s); - } - - IFeatureBuilder fb = sb.newFeatureBuilder(ConfigNames.DEFAULT); - fb.setGenerator(ConfigNames.DEFAULT).setDefaultParameters().setParameters(ore); - IBiomeBuilder bb = sb.newBiomeBuilder(); - IBlockState rep = ReplacementsRegistry.getDimensionDefault(id).get(0); - List rl = new ArrayList<>(); - rl.add(rep); - sb.create(bb, fb, rl, ob); - db.create(sb); - OreSpawn.API.getLogic(file).create(db); - OreSpawn.API.registerLogic(OreSpawn.API.getLogic(file)); - OreSpawn.writer.writeAddOreEntry(file); + + private JsonElement mergeDefaults(JsonElement parse, IBlockState state) { + JsonObject work = parse.getAsJsonObject(); + JsonObject emptyBlacklist = new JsonObject(); + emptyBlacklist.add("excludes", new JsonArray()); + + if(!work.has(ConfigNames.ENABLED)) work.addProperty(ConfigNames.ENABLED, true); + if(!work.has(ConfigNames.RETROGEN)) work.addProperty(ConfigNames.RETROGEN, false); + if(!work.has(ConfigNames.FEATURE)) work.addProperty(ConfigNames.FEATURE, "default"); + if(!work.has(ConfigNames.REPLACEMENT)) work.addProperty(ConfigNames.REPLACEMENT, "default"); + if(!work.has(ConfigNames.PARAMETERS)) work.add(ConfigNames.PARAMETERS, + OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()).getDefaultParameters()); + if(!work.has(ConfigNames.DIMENSIONS)) work.add(ConfigNames.DIMENSIONS, emptyBlacklist); + if(!work.has(ConfigNames.BIOMES)) work.add(ConfigNames.BIOMES, emptyBlacklist); + + JsonObject block = new JsonObject(); + block.addProperty(ConfigNames.CHANCE, 100); + block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); + block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); + work.add(ConfigNames.BLOCK, block); + + return work; } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 081f88d6..accf4b22 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -5,14 +5,19 @@ import java.util.List; import java.util.stream.Collectors; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; + +import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommand; import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; @@ -20,6 +25,7 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.fml.common.registry.ForgeRegistries; +import net.minecraftforge.oredict.OreDictionary; public class ClearChunkCommand extends CommandBase { private static final String STONE_ID = "minecraft:stone"; @@ -58,7 +64,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args blocks = blockNames.stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList()); - blocks.addAll(ReplacementsRegistry.getDimensionDefault(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList())); + blocks.addAll(OreSpawn.API.getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList())); List overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); @@ -113,7 +119,15 @@ private void getBlocks(String[] args, List blockNames) { break; case "classic": - blockNames.addAll(OreSpawnWorldGen.getSpawnBlocks().stream().map(block -> block.getRegistryName().toString()).collect(Collectors.toList())); + blockNames.add(Blocks.STONE.getRegistryName().toString()); + blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); + blockNames.add(Blocks.END_STONE.getRegistryName().toString()); + blockNames.addAll(OreDictionary.getOres("stone").stream() + .map(ItemStack::getItem) + .map(Block::getBlockFromItem) + .map(Block::getRegistryName) + .map(ResourceLocation::toString) + .collect(Collectors.toList())); break; default: diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index b2faccb4..2708efc4 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -67,8 +67,6 @@ public final class ConfigNames { private ConfigNames() {} public static final String DEFAULT = "default"; public static final String STATE_NORMAL = "normal"; - public static final String DIMENSION = "dimension"; - public static final String ORES = "ores"; public static final String DIMENSIONS = "dimensions"; public static final String CHANCE = "chance"; public static final String METADATA = "metaData"; @@ -78,7 +76,7 @@ private ConfigNames() {} public static final String FEATURE = "feature"; public static final String PARAMETERS = "parameters"; public static final String FILE_VERSION = "version"; - public static final String BLOCK = "name"; + public static final String BLOCK = "blocks"; public static final String SPAWNS = "spawns"; public static final String RETROGEN = "retrogen"; public static final String ENABLED = "enabled"; @@ -87,16 +85,6 @@ private ConfigNames() {} public static final String BLACKLIST = "excludes"; public static final String PRESETS = "presets"; - public final class V2 { - private V2() {} - public static final String ENABLED = "enabled"; - public static final String RETROGEN = "retrogen"; - public static final String REPLACES = "replaces"; - public static final String GENERATOR = "generator"; - public static final String MINIMUM = "minimum"; - public static final String MAXIMUM = "maximum"; - } - public final class DefaultFeatureProperties { private DefaultFeatureProperties() {} public static final String SIZE = "size"; diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index d170b954..882ab404 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -2,7 +2,6 @@ import java.io.BufferedReader; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -11,11 +10,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.FileUtils; - import com.google.gson.JsonElement; import com.google.gson.JsonIOException; -import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSyntaxException; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 66447119..229df62c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -1,13 +1,11 @@ package com.mcmoddev.orespawn.impl.features; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import java.util.Random; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index e72eb438..87fe140e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -37,6 +37,7 @@ import net.minecraft.crash.CrashReport; import net.minecraft.util.ResourceLocation; +import net.minecraft.block.state.IBlockState; public class OS3APIImpl implements OS3API { private static final Map spawns; @@ -198,4 +199,9 @@ public PresetsStorage copyPresets() { return copy; } + @Override + public List getDimensionDefaultReplacements(int dimensionID) { + return replacements.getDimensionDefault(dimensionID); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index eb0468b5..97a96f18 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.AbstractMap; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; @@ -143,7 +144,16 @@ private static JsonElement doPresetForObject(JsonObject value, PresetsStorage co return rv; } - + public static void loadFromJson(String name, JsonElement json) { + Entry t = new AbstractMap.SimpleEntry(name, json); + try { + loadSingleEntry(t); + } catch (UnknownFieldException | BadValueException | UnknownNameException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Error parsing an manual JSON read for " + name); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } private static void loadSingleEntry(Entry entry) throws UnknownFieldException, BadValueException, UnknownNameException { ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 348d5628..42593a45 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -18,7 +18,7 @@ public static String serializeState(IBlockState state) { string = "normal"; } - OreSpawn.LOGGER.fatal("State is %s (for block %s)", string, state.getBlock().getRegistryName()); + OreSpawn.LOGGER.debug("State is %s (for block %s)", string, state.getBlock().getRegistryName()); return string; } From b7e7af7e3e666291773252948412ddc787cd85e1 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 15:03:52 -0400 Subject: [PATCH 027/205] Only the write-out command and some book-keeping bits need to be done. --- .../com/mcmoddev/orespawn/EventHandlers.java | 178 ++++++++---------- .../java/com/mcmoddev/orespawn/OreSpawn.java | 9 +- 2 files changed, 84 insertions(+), 103 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index e664bb31..bc2b41ed 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -1,27 +1,28 @@ package com.mcmoddev.orespawn; -import java.util.LinkedList; import java.util.Arrays; import java.util.Deque; import java.util.List; -import java.util.Map.Entry; +import java.util.Map; import java.util.Random; +import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.stream.Collectors; -import com.mcmoddev.orespawn.api.os3.BuilderLogic; -import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; -import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; -import com.mcmoddev.orespawn.api.os3.OreBuilder; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.collect.MapDifference; +import com.google.common.collect.Maps; +import com.google.common.collect.Queues; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.gen.ChunkProviderServer; import net.minecraftforge.event.terraingen.OreGenEvent; @@ -36,12 +37,12 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; public class EventHandlers { - private Deque chunks; private Deque retroChunks; + private Map> chunks; EventHandlers() { - chunks = new ConcurrentLinkedDeque<>(); retroChunks = new ConcurrentLinkedDeque<>(); + chunks = new ConcurrentHashMap<>(); } private List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, @@ -58,47 +59,22 @@ public void onGenerateMinable(OreGenEvent.GenerateMinable event) { @SubscribeEvent public void onChunkSave(ChunkDataEvent.Save ev) { NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - NBTTagList ores = new NBTTagList(); - NBTTagList features = new NBTTagList(); - - features.appendTag(new NBTTagString("orespawn:default")); - - List spawns = OreSpawn.API.getSpawns().entrySet().stream() - .filter(ent -> ent.getValue().getAllDimensions().containsKey(ev.getWorld().provider.getDimension())) - .map(ent -> ent.getValue().getDimension(ev.getWorld().provider.getDimension())) - .collect(Collectors.toList()); - - if (ev.getWorld().provider.getDimension() > 0 && ev.getWorld().provider.getDimension() != 1) { - spawns.addAll(OreSpawn.API.getSpawns().entrySet().stream() - .filter(ent -> ent.getValue().getAllDimensions().containsKey(OreSpawn.API.dimensionWildcard())) - .map(ent -> ent.getValue().getDimension(OreSpawn.API.dimensionWildcard())) - .collect(Collectors.toList())); - } - - List spc = new LinkedList<>(); - List oreList = new LinkedList<>(); - spawns.stream().map(IDimensionBuilder::getAllSpawns).forEach(spc::addAll); - spc.stream().map(ISpawnBuilder::getOres).forEach(oreList::addAll); - - oreList.stream() - .map(oreEnt -> new NBTTagString(oreEnt.getOre().getBlock().getRegistryName().toString())) - .forEach(ores::appendTag); - - List featureList = new LinkedList<>(); - - spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(ISpawnBuilder::getFeatureGen).collect(Collectors.toList()))); - - featureList.stream() - .map(feat -> new NBTTagString(feat.getFeatureName())) - .forEach(features::appendTag); - - ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); - - if (!Config.getBoolean(Constants.RETROGEN_KEY) || chunks.contains(chunkCoords)) { - dataTag.setTag(Constants.ORE_TAG, ores); - dataTag.setTag(Constants.FEATURES_TAG, features); - } - + NBTTagCompound features = new NBTTagCompound(); + + // save a list of the spawns that were configured and available - in this dimension - when the chunk + // was first generated. + + // collect that data + int thisDimension = ev.getWorld().provider.getDimension(); + BlockPos thisPos = new BlockPos( ev.getChunk().x+8, 128, ev.getChunk().z+8 ); + Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter( ent -> ent.getValue().dimensionAllowed(thisDimension) ) + .filter( ent -> ent.getValue().biomeAllowed(thisBiome) ) + .forEach( ent -> features.setString(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); + dataTag.setTag(Constants.FEATURES_TAG, features); + ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); } @@ -109,43 +85,63 @@ public void onChunkLoad(ChunkDataEvent.Load ev) { doBedrockRetrogen(chunkCoords); - if (chunks.contains(chunkCoords)) { + if (chunks.containsKey(chunkCoords)) { return; } if (Config.getBoolean(Constants.RETROGEN_KEY)) { NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + int thisDimension = world.provider.getDimension(); + BlockPos thisPos = new BlockPos( ev.getChunk().x+8, 128, ev.getChunk().z+8 ); + Biome thisBiome = ev.getChunk().getBiome(thisPos, world.getBiomeProvider()); - if (featuresAreDifferent(chunkTag, world.provider.getDimension()) || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.addLast(chunkCoords); + if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { + chunks.put(chunkCoords, getDifferingTags(chunkTag, thisDimension, thisBiome)); } } } - - private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim) { - return ((countOres(dim) != chunkTag.getTagList(Constants.ORE_TAG, 8).tagCount()) || - compFeatures(chunkTag.getTagList(Constants.FEATURES_TAG, 8), dim)); + private List getDifferingTags(NBTTagCompound chunkTag, int dim, Biome biome) { + NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + Map currentBits = new TreeMap<>(); + Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter( ent -> ent.getValue().dimensionAllowed(dim) ) + .filter( ent -> ent.getValue().biomeAllowed(biome) ) + .forEach( ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); + + tagList.getKeySet().stream() + .forEach( tag -> oldBits.put(tag, tagList.getString(tag))); + + MapDifference diff = Maps.difference(oldBits, currentBits); + + List stuff = Lists.newLinkedList(); + stuff.addAll(diff.entriesDiffering().entrySet() + .stream().map(ent -> ent.getKey()).collect(Collectors.toList())); + stuff.addAll(diff.entriesOnlyOnRight().entrySet() + .stream().map(ent -> ent.getKey()).collect(Collectors.toList())); + return ImmutableList.copyOf(stuff); } - private boolean compFeatures(NBTTagList tagList, int dim) { - List spawns = OreSpawn.API.getSpawns().entrySet().stream() - .filter(ent -> ent.getValue().getAllDimensions().containsKey(dim)) - .map(ent -> ent.getValue().getDimension(dim)) - .collect(Collectors.toList()); - - if (dim > 0 && dim != 1) { - spawns.addAll(OreSpawn.API.getSpawns().entrySet().stream() - .filter(ent -> ent.getValue().getAllDimensions().containsKey(OreSpawn.API.dimensionWildcard())) - .map(ent -> ent.getValue().getDimension(OreSpawn.API.dimensionWildcard())) - .collect(Collectors.toList())); - } - - List featureList = new LinkedList<>(); - - spawns.forEach(sp -> featureList.addAll(sp.getAllSpawns().stream().map(ISpawnBuilder::getFeatureGen).collect(Collectors.toList()))); - - return featureList.size() == tagList.tagCount(); + private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim, Biome biome) { + NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + Map currentBits = new TreeMap<>(); + Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter( ent -> ent.getValue().dimensionAllowed(dim) ) + .filter( ent -> ent.getValue().biomeAllowed(biome) ) + .forEach( ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); + + tagList.getKeySet().stream() + .forEach( tag -> oldBits.put(tag, tagList.getString(tag))); + + MapDifference diff = Maps.difference(oldBits, currentBits); + + return diff.entriesDiffering().size() == 0 && + diff.entriesOnlyOnLeft().size() == 0 && + diff.entriesOnlyOnRight().size() == 0; } private void doBedrockRetrogen(ChunkPos chunkCoords) { @@ -158,22 +154,6 @@ private void doBedrockRetrogen(ChunkPos chunkCoords) { } } - private int countOres(int dim) { - int acc = 0; - - for (Entry sL : OreSpawn.API.getSpawns().entrySet()) { - if (sL.getValue().getAllDimensions().containsKey(dim)) { - acc += sL.getValue().getAllDimensions().get(dim).getAllSpawns().size(); - } - - if (sL.getValue().getAllDimensions().containsKey(OreSpawn.API.dimensionWildcard())) { - acc += sL.getValue().getAllDimensions().get(OreSpawn.API.dimensionWildcard()).getAllSpawns().size(); - } - } - - return acc; - } - @SubscribeEvent public void worldTick(WorldTickEvent ev) { if (ev.side != Side.SERVER) { @@ -181,16 +161,22 @@ public void worldTick(WorldTickEvent ev) { } World world = ev.world; - + if (ev.phase == Phase.END) { + Deque keys = Queues.newArrayDeque(chunks.keySet()); + for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { - ChunkPos p = chunks.pop(); + ChunkPos p = keys.pop(); + List spawns = chunks.remove(p); + Random random = new Random(world.getSeed()); // re-seed with something totally new :P random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider(); IChunkGenerator chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator"); - OreSpawn.API.getGenerator().generate(random, p.x, p.z, world, chunkGenerator, chunkProvider); + for(String s : spawns) { + OreSpawn.API.getSpawn(s).generate(world, chunkGenerator, chunkProvider, p); + } } for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index de88707f..ed5f8d73 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -3,8 +3,6 @@ import com.mcmoddev.orespawn.data.Constants; import com.mcmoddev.orespawn.data.FeatureRegistry; import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; -import com.mcmoddev.orespawn.json.OS3Reader; -import com.mcmoddev.orespawn.json.OS3Writer; import com.mcmoddev.orespawn.commands.AddOreCommand; import com.mcmoddev.orespawn.commands.ClearChunkCommand; import com.mcmoddev.orespawn.commands.WriteConfigsCommand; @@ -50,8 +48,7 @@ public class OreSpawn { public static OreSpawn instance; public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID); - public static final OS3API API = new OS3APIImpl(); - public static final OS3Writer writer = new OS3Writer(); + public static OS3API API; static final EventHandlers eventHandlers = new EventHandlers(); public static final FeatureRegistry FEATURES = new FeatureRegistry(); protected static final Map> spawns = new HashMap<>(); @@ -87,9 +84,7 @@ public void preInit(FMLPreInitializationEvent ev) { public void init(FMLInitializationEvent ev) { PluginLoader.INSTANCE.register(); - OS3Reader.loadEntries(); - writer.writeSysconfIfNonexistent(); - API.registerSpawns(); + API = new OS3APIImpl(); } @EventHandler From 21974293aa3031e95957196aa6468ee30267ba1a Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 15:28:18 -0400 Subject: [PATCH 028/205] no more errors, but /osSaveConfigs and lots of book-keeping are not done - this will take a bit --- .../com/mcmoddev/orespawn/commands/WriteConfigsCommand.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index 3576f02d..e2dce8ee 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -1,11 +1,10 @@ package com.mcmoddev.orespawn.commands; -import com.mcmoddev.orespawn.OreSpawn; - import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.TextComponentString; public class WriteConfigsCommand extends CommandBase { @@ -21,7 +20,7 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - OreSpawn.writer.writeSpawnEntries(); + sender.sendMessage(new TextComponentString("not re-implemented yet, sorry")); } } From 68aba71f50d06cb8440754dd68aaff2938851b77 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 16:45:38 -0400 Subject: [PATCH 029/205] add these two since they aren't being magically generated anymore along with the crash-bug fixed API Implementation --- .../orespawn/impl/os3/OS3APIImpl.java | 9 +++++++- .../assets/orespawn/configs/_features.json | 22 +++++++++++++++++++ .../orespawn/configs/_replacements.json | 8 +++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/orespawn/configs/_features.json create mode 100644 src/main/resources/assets/orespawn/configs/_replacements.json diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 87fe140e..f0d94a9c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -62,7 +62,14 @@ public OS3APIImpl() { stream.filter(featuresFiles::matches) .map(Path::toFile) .forEach(features::loadFeaturesFile); - + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + // have to do this twice or we have issues + try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { stream.filter(replacementsFiles::matches) .forEach(replacements::loadFile); } catch (IOException e) { diff --git a/src/main/resources/assets/orespawn/configs/_features.json b/src/main/resources/assets/orespawn/configs/_features.json new file mode 100644 index 00000000..970456c7 --- /dev/null +++ b/src/main/resources/assets/orespawn/configs/_features.json @@ -0,0 +1,22 @@ +[ + { + "name": "default", + "class": "com.mcmoddev.orespawn.impl.features.DefaultFeatureGenerator" + }, + { + "name": "vein", + "class": "com.mcmoddev.orespawn.impl.features.VeinGenerator" + }, + { + "name": "normal-cloud", + "class": "com.mcmoddev.orespawn.impl.features.NormalCloudGenerator" + }, + { + "name": "precision", + "class": "com.mcmoddev.orespawn.impl.features.PrecisionGenerator" + }, + { + "name": "clusters", + "class": "com.mcmoddev.orespawn.impl.features.ClusterGenerator" + } +] \ No newline at end of file diff --git a/src/main/resources/assets/orespawn/configs/_replacements.json b/src/main/resources/assets/orespawn/configs/_replacements.json new file mode 100644 index 00000000..cf21ccea --- /dev/null +++ b/src/main/resources/assets/orespawn/configs/_replacements.json @@ -0,0 +1,8 @@ +{ + "default": [ { "name": "minecraft:stone" }, + { "name": "minecraft:andesite" }, + { "name": "minecraft:diorite" }, + { "name": "minecraft:granite" }, + { "name": "minecraft:netherrack" }, + { "name": "minecraft:end_stone" } ]; +} From 36e9c1dc6d10d9c80e7e2b266f06477be0f23d66 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 19:12:29 -0400 Subject: [PATCH 030/205] fix lots of issues, can actually get into the game and have files extracted from jars and configs loaded now, though, without issue --- .../java/com/mcmoddev/orespawn/OreSpawn.java | 4 +-- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 4 +++ .../com/mcmoddev/orespawn/data/Constants.java | 2 +- .../orespawn/data/FeatureRegistry.java | 6 +++- .../orespawn/data/ReplacementsRegistry.java | 19 ++++++++++-- .../orespawn/impl/os3/FeatureBuilder.java | 2 +- .../orespawn/impl/os3/OS3APIImpl.java | 19 ++++++++++-- .../orespawn/json/OreSpawnReader.java | 30 +++++++++++-------- .../orespawn/configs/_replacements.json | 2 +- 9 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index ed5f8d73..98242797 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -48,7 +48,7 @@ public class OreSpawn { public static OreSpawn instance; public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID); - public static OS3API API; + public static final OS3API API = new OS3APIImpl(); static final EventHandlers eventHandlers = new EventHandlers(); public static final FeatureRegistry FEATURES = new FeatureRegistry(); protected static final Map> spawns = new HashMap<>(); @@ -84,7 +84,7 @@ public void preInit(FMLPreInitializationEvent ev) { public void init(FMLInitializationEvent ev) { PluginLoader.INSTANCE.register(); - API = new OS3APIImpl(); + API.loadConfigFiles(); } @EventHandler diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index 513346da..719afe8b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -32,4 +32,8 @@ public interface OS3API { public IFeature getFeature(String featureName); public IFeature getFeature(ResourceLocation featureName); public PresetsStorage copyPresets(); + + public void loadConfigFiles(); + public boolean hasReplacement(ResourceLocation resourceLocation); + public boolean hasReplacement(String name); } \ No newline at end of file diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 2708efc4..20d5eb3d 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -6,7 +6,7 @@ public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.2.2"; + public static final String VERSION = "3.3.0"; public static final String RETROGEN_KEY = "Retrogen"; public static final String CONFIG_FILE = "config/orespawn.cfg"; public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 09eebfc4..9912f570 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -74,7 +74,7 @@ public boolean hasFeature(IFeature feature) { } public void addFeature(String name, IFeature feature) { - feature.setRegistryName(new ResourceLocation(name)); + feature.setRegistryName(new ResourceLocation("orespawn", name)); registry.register(feature); } @@ -114,6 +114,7 @@ public void loadFeaturesFile(File file) { String rawJson; JsonArray elements; + OreSpawn.LOGGER.fatal("Loading features file %s", file.getAbsolutePath()); try { rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); } catch (IOException e) { @@ -128,6 +129,9 @@ public void loadFeaturesFile(File file) { for (JsonElement elem : elements) { addFeature(elem.getAsJsonObject()); } + + registry.getEntries().stream() + .forEach(ent -> OreSpawn.LOGGER.fatal("Features Entry %s -> %s", ent.getKey().toString(), ent.getValue().toString())); } public void writeFeatures(File file) { diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 59b8f334..0df3a088 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -129,6 +129,10 @@ public void loadFile(Path file) { String rawJson; String modName = getModName(FilenameUtils.getBaseName(file.toString())); + OreSpawn.LOGGER.fatal("Replacements Registry Dump:"); + registry.getEntries().stream().forEach(ent -> OreSpawn.LOGGER.fatal("Replacement Entry %s -> %s", ent.getKey().toString(), ent.getValue().toString())); + OreSpawn.LOGGER.fatal("Loading replacements file %s", file.toAbsolutePath().toString()); + try { rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); } catch (IOException e) { @@ -143,10 +147,11 @@ public void loadFile(Path file) { .forEach( elem -> { String entName = elem.getKey(); JsonArray entries = elem.getValue().getAsJsonArray(); + OreSpawn.LOGGER.fatal("Handling entry %s:%s", modName, entName); List blocks = new LinkedList<>(); for (JsonElement e : entries) { JsonObject asObj = e.getAsJsonObject(); - String blockName = asObj.get(Constants.ConfigNames.BLOCK).getAsString().toLowerCase(); + String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString().toLowerCase(); // is this an OreDictionary entry ? if(blockName.startsWith("ore:")) { @@ -159,6 +164,7 @@ public void loadFile(Path file) { blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); } }); + OreSpawn.LOGGER.fatal("added OreDictionary entry %s to %s:%s", oreDictName, modName, entName); } else { String state = null; ResourceLocation blockRL = new ResourceLocation(blockName); @@ -167,19 +173,22 @@ public void loadFile(Path file) { // has metadata int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); blocks.add(theBlock.getStateFromMeta(meta)); + OreSpawn.LOGGER.fatal("added Block %s with Metadata %d to %s:%s", blockRL.toString(), meta, modName, entName); } else if(asObj.has(Constants.ConfigNames.STATE)) { // has a state state = asObj.get(Constants.ConfigNames.STATE).getAsString(); blocks.add(StateUtil.deserializeState(theBlock, state)); + OreSpawn.LOGGER.fatal("added Block %s with state %s to %s:%s", blockRL.toString(), state, modName, entName); } else { // use the default state blocks.add(theBlock.getDefaultState()); + OreSpawn.LOGGER.fatal("added Block %s to %s:%s", blockRL.toString(), modName, entName); } } } - IReplacementEntry replacer = new ReplacementEntry(entName, blocks); - replacer.setRegistryName(new ResourceLocation(modName, entName)); + IReplacementEntry replacer = new ReplacementEntry("orespawn:"+entName, blocks); + OreSpawn.LOGGER.fatal("Adding Replacer %s to the registry", replacer.getRegistryName().toString()); registry.register(replacer); }); } @@ -223,4 +232,8 @@ private static String getModName(String baseName) { return baseName; } + + public boolean has(ResourceLocation resourceLocation) { + return registry.containsKey(resourceLocation); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 254b1428..8d4e2912 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -22,7 +22,7 @@ public FeatureBuilder() { @Override public IFeatureBuilder setFeature(String featureName) { - return this.setFeature(new ResourceLocation(featureName)); + return this.setFeature(new ResourceLocation("orespawn", featureName)); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index f0d94a9c..9e6d7f04 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -54,9 +54,12 @@ public class OS3APIImpl implements OS3API { } public OS3APIImpl() { - PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:features-*.json"); - PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:replacements-*.json"); - PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:*.json"); + } + + public void loadConfigFiles() { + PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:**/features-*.json"); + PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:**/replacements-*.json"); + PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { stream.filter(featuresFiles::matches) @@ -211,4 +214,14 @@ public List getDimensionDefaultReplacements(int dimensionID) { return replacements.getDimensionDefault(dimensionID); } + @Override + public boolean hasReplacement(ResourceLocation resourceLocation) { + return this.replacements.has(resourceLocation); + } + + @Override + public boolean hasReplacement(String name) { + return this.hasReplacement(new ResourceLocation("orespawn", name)); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 97a96f18..029e438e 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -49,6 +49,7 @@ public class OreSpawnReader { public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { JsonParser parser = new JsonParser(); + OreSpawn.LOGGER.fatal("trying to load config file %s", conf.toAbsolutePath().toString()); try(BufferedReader data = Files.newBufferedReader(conf)) { JsonElement json = parser.parse(data); @@ -73,7 +74,7 @@ public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingV throw new NotAProperConfigException(); } - JsonObject spawnData = doHandlePresets(root); + JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS).getAsJsonObject(); spawnData.entrySet().stream() .forEach(e -> { try { @@ -203,24 +204,29 @@ private static void loadSingleEntry(Entry entry) throws Unk throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString()); } String featureName = ent.getValue().getAsString(); - if(!OreSpawn.API.featureExists(featureName)) { + if(!OreSpawn.API.featureExists(new ResourceLocation("orespawn", featureName))) { throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); } fb.setFeature(featureName); break; case Constants.ConfigNames.REPLACEMENT: - if(!ent.getValue().isJsonArray()) { + if(!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); - } - IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); - for( JsonElement e : ent.getValue().getAsJsonArray() ) { - if(e.isJsonObject()) { - loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); - } else { - OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString()); + } else if(ent.getValue().getAsJsonPrimitive().isString()) { + if(OreSpawn.API.hasReplacement(new ResourceLocation("orespawn", ent.getValue().getAsString()))) { + sb.setReplacement(OreSpawn.API.getReplacement(ent.getValue().getAsString())); } + } else { + IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + for( JsonElement e : ent.getValue().getAsJsonArray() ) { + if(e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString()); + } + } + sb.setReplacement(rb.create()); } - sb.setReplacement(rb.create()); break; case Constants.ConfigNames.BLOCK: if (ent.getValue().isJsonArray()) { @@ -308,7 +314,7 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { } if (biomeList.has(Constants.ConfigNames.BLACKLIST) && - biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { for( JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { String xN = elem.getAsString(); diff --git a/src/main/resources/assets/orespawn/configs/_replacements.json b/src/main/resources/assets/orespawn/configs/_replacements.json index cf21ccea..8e378cfa 100644 --- a/src/main/resources/assets/orespawn/configs/_replacements.json +++ b/src/main/resources/assets/orespawn/configs/_replacements.json @@ -4,5 +4,5 @@ { "name": "minecraft:diorite" }, { "name": "minecraft:granite" }, { "name": "minecraft:netherrack" }, - { "name": "minecraft:end_stone" } ]; + { "name": "minecraft:end_stone" } ] } From 16bc7d8322c796e80fd5740e9af9ae6fe1b08c66 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 19:17:51 -0400 Subject: [PATCH 031/205] remove debugging outs that helped me track the JSON parsing issues and the issues with the various registries appearing to not function properly --- .../com/mcmoddev/orespawn/data/FeatureRegistry.java | 6 +----- .../mcmoddev/orespawn/data/ReplacementsRegistry.java | 11 ----------- .../mcmoddev/orespawn/impl/os3/FeatureBuilder.java | 6 +++++- .../com/mcmoddev/orespawn/json/OreSpawnReader.java | 2 +- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 9912f570..13660f3b 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -114,7 +114,6 @@ public void loadFeaturesFile(File file) { String rawJson; JsonArray elements; - OreSpawn.LOGGER.fatal("Loading features file %s", file.getAbsolutePath()); try { rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); } catch (IOException e) { @@ -128,10 +127,7 @@ public void loadFeaturesFile(File file) { for (JsonElement elem : elements) { addFeature(elem.getAsJsonObject()); - } - - registry.getEntries().stream() - .forEach(ent -> OreSpawn.LOGGER.fatal("Features Entry %s -> %s", ent.getKey().toString(), ent.getValue().toString())); + } } public void writeFeatures(File file) { diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 0df3a088..7252cf5a 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -127,12 +127,7 @@ public void loadFile(Path file) { JsonParser parser = new JsonParser(); JsonObject elements; String rawJson; - String modName = getModName(FilenameUtils.getBaseName(file.toString())); - OreSpawn.LOGGER.fatal("Replacements Registry Dump:"); - registry.getEntries().stream().forEach(ent -> OreSpawn.LOGGER.fatal("Replacement Entry %s -> %s", ent.getKey().toString(), ent.getValue().toString())); - OreSpawn.LOGGER.fatal("Loading replacements file %s", file.toAbsolutePath().toString()); - try { rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); } catch (IOException e) { @@ -147,7 +142,6 @@ public void loadFile(Path file) { .forEach( elem -> { String entName = elem.getKey(); JsonArray entries = elem.getValue().getAsJsonArray(); - OreSpawn.LOGGER.fatal("Handling entry %s:%s", modName, entName); List blocks = new LinkedList<>(); for (JsonElement e : entries) { JsonObject asObj = e.getAsJsonObject(); @@ -164,7 +158,6 @@ public void loadFile(Path file) { blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); } }); - OreSpawn.LOGGER.fatal("added OreDictionary entry %s to %s:%s", oreDictName, modName, entName); } else { String state = null; ResourceLocation blockRL = new ResourceLocation(blockName); @@ -173,22 +166,18 @@ public void loadFile(Path file) { // has metadata int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); blocks.add(theBlock.getStateFromMeta(meta)); - OreSpawn.LOGGER.fatal("added Block %s with Metadata %d to %s:%s", blockRL.toString(), meta, modName, entName); } else if(asObj.has(Constants.ConfigNames.STATE)) { // has a state state = asObj.get(Constants.ConfigNames.STATE).getAsString(); blocks.add(StateUtil.deserializeState(theBlock, state)); - OreSpawn.LOGGER.fatal("added Block %s with state %s to %s:%s", blockRL.toString(), state, modName, entName); } else { // use the default state blocks.add(theBlock.getDefaultState()); - OreSpawn.LOGGER.fatal("added Block %s to %s:%s", blockRL.toString(), modName, entName); } } } IReplacementEntry replacer = new ReplacementEntry("orespawn:"+entName, blocks); - OreSpawn.LOGGER.fatal("Adding Replacer %s to the registry", replacer.getRegistryName().toString()); registry.register(replacer); }); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 8d4e2912..9f69750d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -22,7 +22,11 @@ public FeatureBuilder() { @Override public IFeatureBuilder setFeature(String featureName) { - return this.setFeature(new ResourceLocation("orespawn", featureName)); + String actName = featureName; + if(!actName.contains(":")) { + actName = String.format("orespawn:%s", featureName); + } + return this.setFeature(new ResourceLocation(actName)); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 029e438e..8251e1c0 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -49,7 +49,7 @@ public class OreSpawnReader { public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { JsonParser parser = new JsonParser(); - OreSpawn.LOGGER.fatal("trying to load config file %s", conf.toAbsolutePath().toString()); + try(BufferedReader data = Files.newBufferedReader(conf)) { JsonElement json = parser.parse(data); From 12e73c93036ab1dbbcf20470a2a7eae7b0e9b270 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 20:09:27 -0400 Subject: [PATCH 032/205] actually register the generator and fix the dimension builder so it works and doesn't trip over itself because the 'acceptAllOverworld' flag wasn't reset --- .../java/com/mcmoddev/orespawn/OreSpawn.java | 5 ++++- .../orespawn/impl/os3/DimensionBuilder.java | 2 ++ .../orespawn/impl/os3/DimensionList.java | 16 ++++++++++++++-- .../mcmoddev/orespawn/json/OreSpawnReader.java | 3 +++ .../orespawn/worldgen/OreSpawnWorldGen.java | 8 ++++---- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 98242797..40540ed3 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -12,6 +12,7 @@ import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.api.plugin.PluginLoader; import com.mcmoddev.orespawn.worldgen.FlatBedrock; +import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; import java.util.HashMap; import java.util.List; @@ -74,6 +75,8 @@ public void preInit(FMLPreInitializationEvent ev) { GameRegistry.registerWorldGenerator(flatBedrock, 100); } + GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); + if (Config.getBoolean(Constants.RETROGEN_KEY) || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) || Config.getBoolean(Constants.RETRO_BEDROCK)) { MinecraftForge.EVENT_BUS.register(eventHandlers); MinecraftForge.ORE_GEN_BUS.register(eventHandlers); @@ -84,7 +87,7 @@ public void preInit(FMLPreInitializationEvent ev) { public void init(FMLInitializationEvent ev) { PluginLoader.INSTANCE.register(); - API.loadConfigFiles(); + API.loadConfigFiles(); } @EventHandler diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index b16c01fe..1aec0938 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -17,12 +17,14 @@ public DimensionBuilder() { @Override public IDimensionBuilder addWhitelistEntry(int dimensionID) { + this.acceptAllOverworld = false; this.dimensionWhitelist.add(dimensionID); return this; } @Override public IDimensionBuilder addBlacklistEntry(int dimensionID) { + this.acceptAllOverworld = false; this.dimensionBlacklist.add(dimensionID); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 40032d01..455be952 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -1,6 +1,9 @@ package com.mcmoddev.orespawn.impl.os3; import java.util.List; + +import com.mcmoddev.orespawn.OreSpawn; + import java.util.ArrayList; public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { @@ -14,11 +17,20 @@ public DimensionList(List whitelist, List blacklist) { @Override public boolean matches(final int dimensionID) { - if (this.whitelist.contains(dimensionID)) return true; - if (this.blacklist.contains(dimensionID)) return false; + OreSpawn.LOGGER.fatal("Dimension Whitelist:"); + whitelist.stream().forEach(id -> OreSpawn.LOGGER.fatal("Dimension %d", id)); + OreSpawn.LOGGER.fatal("Dimension Blacklist:"); + blacklist.stream().forEach(id -> OreSpawn.LOGGER.fatal("Dimension %d", id)); + + OreSpawn.LOGGER.fatal("Test ID is %d", dimensionID); + + if (this.whitelist.contains(Integer.valueOf(dimensionID))) return true; + if (this.blacklist.contains(Integer.valueOf(dimensionID))) return false; if (this.whitelist.size() > 0) return false; if (this.blacklist.size() > 0) return true; + OreSpawn.LOGGER.fatal("Reached a point we should not be able to reach"); + // if it gets here, the whitelist and blacklist are empty... // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... return true; diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 8251e1c0..cdea2e72 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -170,15 +170,18 @@ private static void loadSingleEntry(Entry entry) throws Unk break; case Constants.ConfigNames.DIMENSIONS: IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + OreSpawn.LOGGER.fatal("Dimensions Tag: %s", ent.getValue()); if (ent.getValue().isJsonArray()) { JsonArray dims = ent.getValue().getAsJsonArray(); if(dims.size() == 0) { // blank list, accept all overworld + OreSpawn.LOGGER.fatal("Empty Dimensions Array, setting to accept all overworld"); db.setAcceptAllOverworld(); } else { dims.forEach(item -> { if (item.isJsonPrimitive() && item.getAsJsonPrimitive().isNumber()) { + OreSpawn.LOGGER.fatal("Adding %d to the whitelist", item.getAsInt()); db.addWhitelistEntry(item.getAsInt()); } }); diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index fd5bc551..11c7b576 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -12,9 +12,6 @@ import net.minecraftforge.fml.common.IWorldGenerator; public class OreSpawnWorldGen implements IWorldGenerator { - public OreSpawnWorldGen() { - } - @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { @@ -25,7 +22,10 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG .filter(spawn -> spawn.isEnabled()) .filter(spawn -> (spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) || (!Config.getBoolean(Constants.RETROGEN_KEY))) - .forEach(spawn -> spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); + .forEach(spawn -> { + OreSpawn.LOGGER.fatal("Spawning for entry %s (generator %s) in chunk at %d by %d in dimension %d", spawn.getSpawnName(), spawn.getFeature(), chunkX, chunkZ, thisDim); + spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); + }); } } From 4b3d0852b00203fca425b3c707f510e370a2ce61 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 27 Mar 2018 22:52:31 -0400 Subject: [PATCH 033/205] gets into game, ore spawn runs but nothing seems to actually generate except andesite, diorite, granite, gravel and dirt --- .../orespawn/api/os3/IBiomeBuilder.java | 1 - .../orespawn/api/os3/OreSpawnBlockMatcher.java | 6 +++--- .../orespawn/commands/ClearChunkCommand.java | 2 -- .../orespawn/data/ReplacementsRegistry.java | 17 ++++------------- .../orespawn/impl/os3/DimensionList.java | 10 ---------- .../orespawn/impl/os3/FeatureBuilder.java | 1 - .../mcmoddev/orespawn/impl/os3/OS3APIImpl.java | 6 +++--- .../orespawn/impl/os3/ReplacementBuilder.java | 1 - .../orespawn/impl/os3/ReplacementEntry.java | 6 +++++- .../mcmoddev/orespawn/json/OreSpawnReader.java | 10 ++++------ .../orespawn/worldgen/OreSpawnWorldGen.java | 1 - 11 files changed, 19 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index f8586e2a..bbb873d0 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -1,6 +1,5 @@ package com.mcmoddev.orespawn.api.os3; -import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index e798706f..27f5cc5b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -2,11 +2,11 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.function.Predicate; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; public class OreSpawnBlockMatcher implements Predicate { private final List possibles; @@ -17,10 +17,10 @@ public OreSpawnBlockMatcher(final IBlockState...matches) { public OreSpawnBlockMatcher(final List matches) { this.possibles = new ArrayList<>(); - Collections.copy(this.possibles, matches); + this.possibles.addAll(matches); } public boolean test(final IBlockState other) { - return other != null && possibles.contains(other); + return other != null && other.getBlock() != Blocks.AIR && possibles.contains(other); } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index accf4b22..8808cc90 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -6,8 +6,6 @@ import java.util.stream.Collectors; import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; -import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 7252cf5a..38729b38 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -39,7 +39,6 @@ import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; public class ReplacementsRegistry { private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; @@ -80,10 +79,11 @@ public List getDimensionDefault(int dimension) { } public IReplacementEntry getReplacement(String name) { - if (registry.containsKey(new ResourceLocation(name))) { - return registry.getValue(new ResourceLocation(name)); + ResourceLocation act = new ResourceLocation(name.contains(":")?name:String.format("orespawn:%s", name)); + if (registry.containsKey(act)) { + return registry.getValue(act); } else { - return registry.getValue(new ResourceLocation("default")); + return registry.getValue(new ResourceLocation("orespawn:default")); } } @@ -212,15 +212,6 @@ public void saveFile(String modName) { OreSpawn.LOGGER.info(report.getCompleteReport()); } } - - private static String getModName(String baseName) { - if(baseName.indexOf("-") > 0) { - String[] bits = baseName.split("-"); - return bits[1]; - } - - return baseName; - } public boolean has(ResourceLocation resourceLocation) { return registry.containsKey(resourceLocation); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 455be952..28aebf18 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -2,7 +2,6 @@ import java.util.List; -import com.mcmoddev.orespawn.OreSpawn; import java.util.ArrayList; @@ -17,20 +16,11 @@ public DimensionList(List whitelist, List blacklist) { @Override public boolean matches(final int dimensionID) { - OreSpawn.LOGGER.fatal("Dimension Whitelist:"); - whitelist.stream().forEach(id -> OreSpawn.LOGGER.fatal("Dimension %d", id)); - OreSpawn.LOGGER.fatal("Dimension Blacklist:"); - blacklist.stream().forEach(id -> OreSpawn.LOGGER.fatal("Dimension %d", id)); - - OreSpawn.LOGGER.fatal("Test ID is %d", dimensionID); - if (this.whitelist.contains(Integer.valueOf(dimensionID))) return true; if (this.blacklist.contains(Integer.valueOf(dimensionID))) return false; if (this.whitelist.size() > 0) return false; if (this.blacklist.size() > 0) return true; - OreSpawn.LOGGER.fatal("Reached a point we should not be able to reach"); - // if it gets here, the whitelist and blacklist are empty... // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... return true; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 9f69750d..5770b175 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -6,7 +6,6 @@ import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; -import com.mcmoddev.orespawn.data.FeatureRegistry; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 9e6d7f04..2441aacd 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -184,7 +184,7 @@ public Map getAllSpawns() { @Override public boolean featureExists(String featureName) { - return this.featureExists(new ResourceLocation(featureName)); + return this.featureExists(new ResourceLocation(featureName.contains(":")?featureName:String.format("orespawn:%s", featureName))); } @Override @@ -216,12 +216,12 @@ public List getDimensionDefaultReplacements(int dimensionID) { @Override public boolean hasReplacement(ResourceLocation resourceLocation) { - return this.replacements.has(resourceLocation); + return replacements.has(resourceLocation); } @Override public boolean hasReplacement(String name) { - return this.hasReplacement(new ResourceLocation("orespawn", name)); + return this.hasReplacement(new ResourceLocation(name.contains(":")?name:String.format("orespawn:%s", name))); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 40c3aa65..66042e0d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -7,7 +7,6 @@ import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; -import com.mcmoddev.orespawn.data.ReplacementsRegistry; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index 5d63b53c..c454236b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -13,6 +13,7 @@ public class ReplacementEntry extends IForgeRegistryEntry.Impl implements IReplacementEntry { private final List matchVal; + private OreSpawnBlockMatcher matcher = null; public ReplacementEntry(final String name, final IBlockState...toMatch) { super.setRegistryName(name); @@ -26,7 +27,10 @@ public ReplacementEntry(final String name, final List toMatch) { } @Override public OreSpawnBlockMatcher getMatcher() { - return new OreSpawnBlockMatcher(this.matchVal); + if (this.matcher == null) { + this.matcher = new OreSpawnBlockMatcher(this.matchVal); + } + return this.matcher; } public List getEntries() { diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index cdea2e72..32ef4d0e 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -170,18 +170,15 @@ private static void loadSingleEntry(Entry entry) throws Unk break; case Constants.ConfigNames.DIMENSIONS: IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); - OreSpawn.LOGGER.fatal("Dimensions Tag: %s", ent.getValue()); if (ent.getValue().isJsonArray()) { JsonArray dims = ent.getValue().getAsJsonArray(); if(dims.size() == 0) { // blank list, accept all overworld - OreSpawn.LOGGER.fatal("Empty Dimensions Array, setting to accept all overworld"); db.setAcceptAllOverworld(); } else { dims.forEach(item -> { if (item.isJsonPrimitive() && item.getAsJsonPrimitive().isNumber()) { - OreSpawn.LOGGER.fatal("Adding %d to the whitelist", item.getAsInt()); db.addWhitelistEntry(item.getAsInt()); } }); @@ -207,7 +204,7 @@ private static void loadSingleEntry(Entry entry) throws Unk throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString()); } String featureName = ent.getValue().getAsString(); - if(!OreSpawn.API.featureExists(new ResourceLocation("orespawn", featureName))) { + if(!OreSpawn.API.featureExists(featureName)) { throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); } fb.setFeature(featureName); @@ -216,7 +213,7 @@ private static void loadSingleEntry(Entry entry) throws Unk if(!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); } else if(ent.getValue().getAsJsonPrimitive().isString()) { - if(OreSpawn.API.hasReplacement(new ResourceLocation("orespawn", ent.getValue().getAsString()))) { + if(OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { sb.setReplacement(OreSpawn.API.getReplacement(ent.getValue().getAsString())); } } else { @@ -266,8 +263,9 @@ private static void loadSingleEntry(Entry entry) throws Unk default: throw new UnknownFieldException(ent.getKey()); } - OreSpawn.API.addSpawn(sb.create()); } + sb.setFeature(fb.create()); + OreSpawn.API.addSpawn(sb.create()); } private static List loadBlock(JsonObject json) { diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 11c7b576..93fc9217 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -23,7 +23,6 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG .filter(spawn -> (spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) || (!Config.getBoolean(Constants.RETROGEN_KEY))) .forEach(spawn -> { - OreSpawn.LOGGER.fatal("Spawning for entry %s (generator %s) in chunk at %d by %d in dimension %d", spawn.getSpawnName(), spawn.getFeature(), chunkX, chunkZ, thisDim); spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); }); } From f72c349001e71b27852d6afa445aa41c2cd16eda Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 28 Mar 2018 01:18:18 -0400 Subject: [PATCH 034/205] this almost works, hooray! --- .../java/com/mcmoddev/orespawn/api/IBlockList.java | 1 + .../com/mcmoddev/orespawn/impl/os3/BlockList.java | 8 ++++++++ .../orespawn/worldgen/OreSpawnWorldGen.java | 14 +++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 0fb056c9..c4837bfc 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -10,4 +10,5 @@ public interface IBlockList { public void addBlock(IBlockDefinition block); public IBlockState getRandomBlock(Random rand); public void startNewSpawn(); + public void dump(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 9146838a..94d597e9 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Random; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.os3.IBlockDefinition; @@ -48,4 +49,11 @@ public void startNewSpawn() { }); } + @Override + public void dump() { + this.myBlocks.stream() + .map(bd -> bd.getBlock()) + .forEach(bs -> OreSpawn.LOGGER.fatal("Block %s (with state: %s)", bs.getBlock(), bs)); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 93fc9217..3a805904 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -1,6 +1,7 @@ package com.mcmoddev.orespawn.worldgen; import java.util.*; + import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; @@ -12,6 +13,7 @@ import net.minecraftforge.fml.common.IWorldGenerator; public class OreSpawnWorldGen implements IWorldGenerator { + @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { @@ -20,10 +22,16 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG OreSpawn.API.getSpawns(thisDim).stream() .filter(spawn -> spawn.isEnabled()) - .filter(spawn -> (spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) - || (!Config.getBoolean(Constants.RETROGEN_KEY))) + .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) + .forEach(sp -> { + OreSpawn.LOGGER.fatal("Spawn %s in dimension %s dump:", sp.getSpawnName(), thisDim); + sp.getBlocks().dump(); + }); + OreSpawn.API.getSpawns(thisDim).stream() + .filter(spawn -> spawn.isEnabled()) + .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) .forEach(spawn -> { - spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); + spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); }); } } From 16522dbf22b7565d6d57fc546665822c65f7de22 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 28 Mar 2018 03:42:49 -0400 Subject: [PATCH 035/205] Stuff generates, yay! Might not be 100% correct, but I am seeing generation. Think that Diorite and Granite need to be added to the config. Forced config save command needs implemented. Might be good to add a generic for doing it anyway. Issue with that is that I don't believe we actually keep enough data around to reconstitute the original files in their original format. Will discuss with @jriwanek at a later point. --- .../java/com/mcmoddev/orespawn/EventHandlers.java | 2 +- .../com/mcmoddev/orespawn/api/FeatureBase.java | 3 ++- .../mcmoddev/orespawn/api/os3/IBiomeBuilder.java | 4 ++-- .../mcmoddev/orespawn/api/os3/ISpawnBuilder.java | 4 ++-- .../com/mcmoddev/orespawn/api/os3/ISpawnEntry.java | 4 +++- .../orespawn/api/os3/OreSpawnBlockMatcher.java | 6 +++++- .../impl/location/BiomeLocationAcceptAny.java | 14 ++++++++++++++ .../impl/location/BiomeLocationComposition.java | 13 +++++++++++-- .../mcmoddev/orespawn/impl/os3/BiomeBuilder.java | 10 +++------- .../mcmoddev/orespawn/impl/os3/SpawnBuilder.java | 6 +++--- .../com/mcmoddev/orespawn/impl/os3/SpawnEntry.java | 11 +++++++---- .../orespawn/worldgen/OreSpawnWorldGen.java | 9 +-------- 12 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index bc2b41ed..5584aaf3 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -175,7 +175,7 @@ public void worldTick(WorldTickEvent ev) { ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider(); IChunkGenerator chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator"); for(String s : spawns) { - OreSpawn.API.getSpawn(s).generate(world, chunkGenerator, chunkProvider, p); + OreSpawn.API.getSpawn(s).generate(random, world, chunkGenerator, chunkProvider, p); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 998bff96..390ef800 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -47,7 +47,8 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d Biome thisBiome = world.getBiome(coord); - if (!spawnData.biomeAllowed(thisBiome)) { + if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { + OreSpawn.LOGGER.fatal("biome of chunk containing %s (%s) is invalid for this spawn (%s)", coord, thisBiome.getRegistryName(), spawnData.getSpawnName()); return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index bbb873d0..14d25fd7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -1,6 +1,6 @@ package com.mcmoddev.orespawn.api.os3; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; +import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; @@ -13,5 +13,5 @@ public interface IBiomeBuilder { public IBiomeBuilder addBlacklistEntry(final String biomeName); public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); public IBiomeBuilder setAcceptAll(); - public BiomeLocationComposition create(); + public BiomeLocation create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 277a8442..87507f30 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -1,7 +1,7 @@ package com.mcmoddev.orespawn.api.os3; +import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IDimensionList; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -10,7 +10,7 @@ public interface ISpawnBuilder { public ISpawnBuilder setName(final String name); public ISpawnBuilder setDimensions(final IDimensionList dimensions); - public ISpawnBuilder setBiomes(final BiomeLocationComposition biomes); + public ISpawnBuilder setBiomes(final BiomeLocation biomes); public ISpawnBuilder setEnabled(final boolean enabled); public ISpawnBuilder setRetrogen(final boolean retrogen); public ISpawnBuilder setReplacement(final IReplacementEntry replacements); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 515b0845..ed7622f5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -7,6 +7,8 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; +import java.util.Random; + import com.mcmoddev.orespawn.api.IBlockList; public interface ISpawnEntry { @@ -26,5 +28,5 @@ default public boolean isRetrogen() { public OreSpawnBlockMatcher getMatcher(); public IBlockList getBlocks(); - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); + public void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index 27f5cc5b..c2fc413f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -20,7 +20,11 @@ public OreSpawnBlockMatcher(final List matches) { this.possibles.addAll(matches); } + private boolean has(final IBlockState bs) { + return this.possibles.stream().filter(bs::equals).count() > 0; + } + public boolean test(final IBlockState other) { - return other != null && other.getBlock() != Blocks.AIR && possibles.contains(other); + return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java new file mode 100644 index 00000000..c8098a0a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -0,0 +1,14 @@ +package com.mcmoddev.orespawn.impl.location; + +import com.mcmoddev.orespawn.api.BiomeLocation; + +import net.minecraft.world.biome.Biome; + +public class BiomeLocationAcceptAny implements BiomeLocation { + + @Override + public boolean matches(Biome biome) { + return true; + } + +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 10debedb..817d8b34 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -30,8 +30,17 @@ private boolean matchBiome(Biome biome, BiomeLocation loc) { public boolean matches(Biome biome) { boolean inWhite = this.inclusions.asList().stream().anyMatch(bl -> matchBiome(biome, bl)); boolean inBlack = this.exclusions.asList().stream().anyMatch(bl -> matchBiome(biome, bl)); - - return !inBlack && inWhite; + if(this.inclusions.size() > 0 && this.exclusions.size() > 0) { + return !inBlack && inWhite; + } else if( this.inclusions.size() > 0 && this.exclusions.size() == 0) { + return inWhite; + } else if( this.inclusions.size() == 0 && this.exclusions.size() > 0) { + return !inBlack; + } else { + // both are empty! Mein Gott! Lets assume this was a mistake and the user actually + // wants all biomes allowed. + return true; + } } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 290030a1..4f884bff 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableSet; import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.impl.location.BiomeLocationAcceptAny; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; @@ -64,14 +65,9 @@ public IBiomeBuilder setAcceptAll() { } @Override - public BiomeLocationComposition create() { + public BiomeLocation create() { if (this.acceptAll) { - return new BiomeLocationComposition(ImmutableSet.of(new BiomeLocationEmpty()), - ImmutableSet.of(new BiomeLocation() { - public boolean matches(Biome b) { - return true; - } - })); + return new BiomeLocationAcceptAny(); } ImmutableSet whitelist; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 40d590d0..a40b5643 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -1,8 +1,8 @@ package com.mcmoddev.orespawn.impl.os3; +import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.util.StateUtil; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; @@ -19,7 +19,7 @@ public class SpawnBuilder implements ISpawnBuilder { private boolean retrogen; private IBlockList blocks; private IFeatureEntry feature; - private BiomeLocationComposition biomes; + private BiomeLocation biomes; private IDimensionList dimensions; private IReplacementEntry replacements; @@ -47,7 +47,7 @@ public ISpawnBuilder setDimensions(IDimensionList dimensions) { } @Override - public ISpawnBuilder setBiomes(BiomeLocationComposition biomes) { + public ISpawnBuilder setBiomes(BiomeLocation biomes) { this.biomes = biomes; return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index b0f33fe8..2bdaeabe 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -1,11 +1,13 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.Random; + +import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; -import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.ChunkPos; @@ -20,13 +22,13 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { private final IDimensionList dimensions; private final IReplacementEntry replacements; private final IBlockList blocks; - private final BiomeLocationComposition biomes; + private final BiomeLocation biomes; private final IFeatureEntry feature; private final boolean enabled; private final boolean retrogen; public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, - final IDimensionList dimensions, final BiomeLocationComposition biomes, + final IDimensionList dimensions, final BiomeLocation biomes, final IReplacementEntry replacements, final IBlockList blocks, final IFeatureEntry feature) { this.spawnName = spawnName; @@ -85,7 +87,8 @@ public IBlockList getBlocks() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos) { + public void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos) { + this.feature.getFeature().setRandom(random); this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 3a805904..1cd41a1e 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -20,18 +20,11 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG int thisDim = world.provider.getDimension(); - OreSpawn.API.getSpawns(thisDim).stream() - .filter(spawn -> spawn.isEnabled()) - .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(sp -> { - OreSpawn.LOGGER.fatal("Spawn %s in dimension %s dump:", sp.getSpawnName(), thisDim); - sp.getBlocks().dump(); - }); OreSpawn.API.getSpawns(thisDim).stream() .filter(spawn -> spawn.isEnabled()) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) .forEach(spawn -> { - spawn.generate(world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); + spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); }); } } From 54fa832f161144c2bbf60f1bf71fd380938b2c65 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 28 Mar 2018 17:28:34 -0400 Subject: [PATCH 036/205] Output is not, exactly, what was intended but /osSaveConfigs does work and /addore now writes out the specified file with the data on the new entry as well. This means that we are, approximately, at parity with OreSpawn 3.2 --- .../mcmoddev/orespawn/api/BiomeLocation.java | 8 ++- .../mcmoddev/orespawn/api/IDimensionList.java | 3 + .../orespawn/api/os3/ISpawnEntry.java | 5 ++ .../com/mcmoddev/orespawn/api/os3/OS3API.java | 4 ++ .../api/os3/OreSpawnBlockMatcher.java | 22 ++++++ .../orespawn/commands/AddOreCommand.java | 2 + .../commands/WriteConfigsCommand.java | 5 +- .../impl/location/BiomeLocationAcceptAny.java | 11 +++ .../location/BiomeLocationComposition.java | 49 +++++++------ .../location/BiomeLocationDictionary.java | 7 ++ .../impl/location/BiomeLocationEmpty.java | 7 ++ .../impl/location/BiomeLocationList.java | 12 ++++ .../impl/location/BiomeLocationSingle.java | 7 ++ .../orespawn/impl/os3/BiomeBuilder.java | 35 +++++---- .../orespawn/impl/os3/DimensionList.java | 25 +++++++ .../impl/os3/DimensionListAcceptAll.java | 10 +++ .../os3/DimensionListAcceptAllOverworld.java | 14 ++++ .../impl/os3/DimensionListDenyAll.java | 12 ++++ .../orespawn/impl/os3/OS3APIImpl.java | 35 +++++++++ .../orespawn/impl/os3/SpawnEntry.java | 10 +++ .../orespawn/json/OreSpawnReader.java | 1 + .../orespawn/json/OreSpawnWriter.java | 72 +++++++++++++++++++ 22 files changed, 309 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index 64022765..22ea69c2 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -1,15 +1,17 @@ package com.mcmoddev.orespawn.api; import com.google.common.collect.ImmutableList; - +import com.google.gson.JsonElement; import com.mcmoddev.orespawn.util.Collectors2; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; public interface BiomeLocation { boolean matches(Biome biome); - -default ImmutableList getBiomes() { + + public JsonElement serialize(); + + default ImmutableList getBiomes() { return ForgeRegistries.BIOMES.getValues().stream().filter(this::matches).collect(Collectors2.toImmutableList()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index c16d7236..29e2c2bb 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -1,6 +1,9 @@ package com.mcmoddev.orespawn.api; +import com.google.gson.JsonObject; + public interface IDimensionList { + public JsonObject serialize(); default public boolean matches(final int dimensionId) { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index ed7622f5..229c435d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -9,7 +9,9 @@ import java.util.Random; +import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; +import com.mcmoddev.orespawn.api.IDimensionList; public interface ISpawnEntry { default public boolean isEnabled() { @@ -29,4 +31,7 @@ default public boolean isRetrogen() { public IBlockList getBlocks(); public void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); + + public IDimensionList getDimensions(); + public BiomeLocation getBiomes(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index 719afe8b..3e125104 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -1,5 +1,6 @@ package com.mcmoddev.orespawn.api.os3; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -36,4 +37,7 @@ public interface OS3API { public void loadConfigFiles(); public boolean hasReplacement(ResourceLocation resourceLocation); public boolean hasReplacement(String name); + public void mapEntryToFile(Path p, String entryName); + public List getSpawnsForFile(String fileName); + public Map> getSpawnsByFile(); } \ No newline at end of file diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index c2fc413f..23639061 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -5,6 +5,11 @@ import java.util.List; import java.util.function.Predicate; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.data.Constants; +import com.mcmoddev.orespawn.util.StateUtil; + import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -27,4 +32,21 @@ private boolean has(final IBlockState bs) { public boolean test(final IBlockState other) { return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); } + + public JsonArray serialize() { + JsonArray rv = new JsonArray(); + + possibles.stream() + .forEach(bs -> { + JsonObject t = new JsonObject(); + t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); + if(!bs.equals(bs.getBlock().getDefaultState())) { + String state = StateUtil.serializeState(bs); + t.addProperty(Constants.ConfigNames.STATE, state); + } + rv.add(t); + }); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 7cd3960b..5390b6d9 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -4,6 +4,7 @@ import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.Constants.ConfigNames; import com.mcmoddev.orespawn.json.OreSpawnReader; +import com.mcmoddev.orespawn.json.OreSpawnWriter; import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.Block; @@ -57,6 +58,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args JsonParser p = new JsonParser(); JsonElement parsed = mergeDefaults(p.parse(rawData), state); OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); + OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); } private JsonElement mergeDefaults(JsonElement parse, IBlockState state) { diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index e2dce8ee..c312f94d 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.commands; +import com.mcmoddev.orespawn.json.OreSpawnWriter; + import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; @@ -20,7 +22,8 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - sender.sendMessage(new TextComponentString("not re-implemented yet, sorry")); + sender.sendMessage(new TextComponentString("Forcing configs as OreSpawn sees them to be written to disk")); + OreSpawnWriter.saveConfigs(); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java index c8098a0a..37a2b8e7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -1,6 +1,10 @@ package com.mcmoddev.orespawn.impl.location; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.data.Constants.ConfigNames; import net.minecraft.world.biome.Biome; @@ -11,4 +15,11 @@ public boolean matches(Biome biome) { return true; } + @Override + public JsonElement serialize() { + JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 817d8b34..987165d0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -1,8 +1,11 @@ package com.mcmoddev.orespawn.impl.location; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.data.Constants; + import net.minecraft.world.biome.Biome; import java.util.Objects; @@ -10,37 +13,24 @@ import java.util.LinkedList; public final class BiomeLocationComposition implements BiomeLocation { - private final ImmutableSet inclusions; + private final BiomeLocation inclusions; - private final ImmutableSet exclusions; + private final BiomeLocation exclusions; private final int hash; - public BiomeLocationComposition(ImmutableSet inclusions, ImmutableSet exclusions) { + public BiomeLocationComposition(BiomeLocation inclusions, BiomeLocation exclusions) { this.inclusions = inclusions; this.exclusions = exclusions; this.hash = Objects.hash(inclusions, exclusions); } - private boolean matchBiome(Biome biome, BiomeLocation loc) { - return (loc.getBiomes().stream().filter(b -> b.equals(biome)).distinct().count() > 0); - } - @Override public boolean matches(Biome biome) { - boolean inWhite = this.inclusions.asList().stream().anyMatch(bl -> matchBiome(biome, bl)); - boolean inBlack = this.exclusions.asList().stream().anyMatch(bl -> matchBiome(biome, bl)); - if(this.inclusions.size() > 0 && this.exclusions.size() > 0) { - return !inBlack && inWhite; - } else if( this.inclusions.size() > 0 && this.exclusions.size() == 0) { - return inWhite; - } else if( this.inclusions.size() == 0 && this.exclusions.size() > 0) { - return !inBlack; - } else { - // both are empty! Mein Gott! Lets assume this was a mistake and the user actually - // wants all biomes allowed. - return true; - } + boolean inWhite = this.inclusions.matches(biome); + boolean inBlack = this.exclusions.matches(biome); + + return !inBlack && inWhite; } @Override @@ -65,17 +55,26 @@ public boolean equals(Object obj) { @Override public ImmutableList getBiomes() { List temp = new LinkedList<>(); - this.inclusions.stream().forEach(bl -> temp.addAll(bl.getBiomes())); - this.exclusions.stream().forEach(bl -> temp.addAll(bl.getBiomes())); + temp.addAll(this.inclusions.getBiomes()); + temp.addAll(this.exclusions.getBiomes()); return ImmutableList.copyOf(temp); } - public ImmutableSet getInclusions() { + public BiomeLocation getInclusions() { return this.inclusions; } - public ImmutableSet getExclusions() { + public BiomeLocation getExclusions() { return this.exclusions; } + @Override + public JsonElement serialize() { + JsonObject rv = new JsonObject(); + rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); + rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); + + return rv; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java index ca26b096..b34f542d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java @@ -1,6 +1,8 @@ package com.mcmoddev.orespawn.impl.location; import com.google.common.collect.ImmutableList; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.world.biome.Biome; import net.minecraftforge.common.BiomeDictionary; @@ -38,4 +40,9 @@ public BiomeDictionary.Type getType() { public ImmutableList getBiomes() { return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.type.toString().toUpperCase()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java index 8194aee1..dc1ebf08 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.impl.location; +import com.google.gson.JsonElement; +import com.google.gson.JsonArray; import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.world.biome.Biome; @@ -11,4 +13,9 @@ public boolean matches(Biome biome) { return false; } + @Override + public JsonElement serialize() { + return new JsonArray(); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index e16a50da..6c885f94 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -2,6 +2,8 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.world.biome.Biome; @@ -43,4 +45,14 @@ public ImmutableList getBiomes() { public ImmutableSet getLocations() { return this.locations; } + + @Override + public JsonElement serialize() { + JsonArray rv = new JsonArray(); + this.locations.stream() + .filter(bl -> (!(bl instanceof BiomeLocationEmpty) && (!(bl instanceof BiomeLocationAcceptAny)))) + .forEach(bl -> rv.add(bl.serialize())); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java index bd144835..96fa110f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java @@ -1,6 +1,8 @@ package com.mcmoddev.orespawn.impl.location; import com.google.common.collect.ImmutableList; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.world.biome.Biome; @@ -37,4 +39,9 @@ public boolean equals(Object obj) { public Biome getBiome() { return this.biome; } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.biome.getRegistryName().toString()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 4f884bff..2e3e89e5 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -9,6 +9,7 @@ import com.mcmoddev.orespawn.impl.location.BiomeLocationAcceptAny; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; +import com.mcmoddev.orespawn.impl.location.BiomeLocationList; import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; @@ -69,29 +70,27 @@ public BiomeLocation create() { if (this.acceptAll) { return new BiomeLocationAcceptAny(); } - - ImmutableSet whitelist; - ImmutableSet blacklist; + + BiomeLocation whitelist; + BiomeLocation blacklist; if (this.whitelist.size() == 0) { - whitelist = ImmutableSet.of(new BiomeLocationEmpty()); + whitelist = new BiomeLocationEmpty(); } else { - whitelist = ImmutableSet.copyOf( - this.whitelist.stream() - .map( biome -> new BiomeLocationSingle(biome) ) - .collect(Collectors.toList())); + whitelist = new BiomeLocationList( + ImmutableSet.copyOf( + this.whitelist.stream() + .map( biome -> new BiomeLocationSingle(biome) ) + .collect(Collectors.toList())) ); } - + if (this.blacklist.size() == 0) { - blacklist = ImmutableSet.of(new BiomeLocation() { - public boolean matches(Biome b) { - return true; - } - }); + blacklist = new BiomeLocationAcceptAny(); } else { - blacklist = ImmutableSet.copyOf( - this.blacklist.stream() - .map( biome -> new BiomeLocationSingle(biome) ) - .collect(Collectors.toList())); + blacklist = new BiomeLocationList( + ImmutableSet.copyOf( + this.blacklist.stream() + .map( biome -> new BiomeLocationSingle(biome) ) + .collect(Collectors.toList()))); } return new BiomeLocationComposition(whitelist, blacklist); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 28aebf18..ff46deb4 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -2,6 +2,9 @@ import java.util.List; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.data.Constants; import java.util.ArrayList; @@ -25,4 +28,26 @@ public boolean matches(final int dimensionID) { // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... return true; } + + @Override + public JsonObject serialize() { + JsonObject rv = new JsonObject(); + if(this.whitelist.size() > 0) { + JsonArray wl = new JsonArray(); + whitelist.stream() + .forEach(i -> wl.add(i.intValue())); + rv.add(Constants.ConfigNames.WHITELIST, wl); + } + + if(this.blacklist.size() > 0) { + JsonArray bl = new JsonArray(); + blacklist.stream() + .forEach(i -> bl.add(i.intValue())); + rv.add(Constants.ConfigNames.WHITELIST, bl); + } else if(this.whitelist.size() == 0) { + return new DimensionListAcceptAllOverworld().serialize(); + } + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index e924c425..ceb63df6 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -1,6 +1,9 @@ package com.mcmoddev.orespawn.impl.os3; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.data.Constants.ConfigNames; public class DimensionListAcceptAll implements IDimensionList { @Override @@ -8,4 +11,11 @@ public class DimensionListAcceptAll implements IDimensionList { public boolean matches(final int dimensionID) { return true; } + + @Override + public JsonObject serialize() { + JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java index fb3c881c..d61037fa 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -1,6 +1,9 @@ package com.mcmoddev.orespawn.impl.os3; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.data.Constants; public class DimensionListAcceptAllOverworld implements IDimensionList { @Override @@ -8,4 +11,15 @@ public boolean matches(final int dimensionID) { return dimensionID != -1 && dimensionID != 1; } + @Override + public JsonObject serialize() { + JsonObject rv = new JsonObject(); + JsonArray bl = new JsonArray(); + bl.add(-1); + bl.add(1); + rv.add(Constants.ConfigNames.BLACKLIST, bl); + + return rv; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index fb23197e..876c24dc 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -1,6 +1,9 @@ package com.mcmoddev.orespawn.impl.os3; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.data.Constants; public class DimensionListDenyAll implements IDimensionList { @Override @@ -8,4 +11,13 @@ public class DimensionListDenyAll implements IDimensionList { public boolean matches(final int dimensionID) { return false; } + + @Override + public JsonObject serialize() { + JsonObject rv = new JsonObject(); + rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); + + return rv; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 2441aacd..3eafb7cc 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -5,15 +5,19 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.PathMatcher; +import java.nio.file.Paths; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.exceptions.MissingVersionException; @@ -45,6 +49,7 @@ public class OS3APIImpl implements OS3API { private static final ReplacementsRegistry replacements; private static final PresetsStorage presets; private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final Map spawnsToSourceFiles = new TreeMap<>(); static { spawns = new ConcurrentHashMap<>(); @@ -224,4 +229,34 @@ public boolean hasReplacement(String name) { return this.hasReplacement(new ResourceLocation(name.contains(":")?name:String.format("orespawn:%s", name))); } + @Override + public void mapEntryToFile(Path p, String entryName) { + spawnsToSourceFiles.put(entryName, p); + } + + @Override + public List getSpawnsForFile(String fileName) { + Path p = Constants.CONFDIR.resolve(fileName); + List values = spawnsToSourceFiles.entrySet().stream() + .filter(ent -> ent.getValue().equals(p)) + .map(ent -> ent.getKey()) + .collect(Collectors.toList()); + return ImmutableList.copyOf(values); + } + + @Override + public Map> getSpawnsByFile() { + Map> temp = new HashMap<>(); + spawnsToSourceFiles.entrySet().stream() + .forEach(ent -> { + if(temp.containsKey(ent.getValue())) { + temp.get(ent.getValue()).add(ent.getKey()); + } else { + temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); + } + }); + + return ImmutableMap.copyOf(temp); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 2bdaeabe..6cde1b7f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -92,4 +92,14 @@ public void generate(Random random, World world, IChunkGenerator chunkGenerator, this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); } + @Override + public IDimensionList getDimensions() { + return this.dimensions; + } + + @Override + public BiomeLocation getBiomes() { + return this.biomes; + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 32ef4d0e..d906ddd8 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -78,6 +78,7 @@ public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingV spawnData.entrySet().stream() .forEach(e -> { try { + OreSpawn.API.mapEntryToFile(conf, e.getKey()); loadSingleEntry(e); } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { CrashReport report = CrashReport.makeCrashReport(e1, "Error parsing an entry " + e.getKey() + " in " + conf.toString()); diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java new file mode 100644 index 00000000..de11c48a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -0,0 +1,72 @@ +package com.mcmoddev.orespawn.json; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardOpenOption; +import java.util.List; +import java.util.Map; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.data.Constants; +import com.mcmoddev.orespawn.data.Constants.ConfigNames; + +import net.minecraft.crash.CrashReport; + +public class OreSpawnWriter { + /* + * Write out the configs as the system knows them to the 'forced-saves' directory + */ + public static void saveConfigs() { + Map> configs = OreSpawn.API.getSpawnsByFile(); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + configs.entrySet().stream() + .forEach( ent -> { + saveSingle(ent.getKey(), gson); + }); + } + + private static void saveSingle(Path filePath, Gson gson) { + JsonObject root = new JsonObject(); + root.addProperty(ConfigNames.FILE_VERSION, "2.0"); + JsonObject spawns = new JsonObject(); + String k = filePath.getFileName().toString(); + Path saveDir = Constants.CONFDIR.resolve("forced-saves"); + Path conf = saveDir.resolve(k); + if(!saveDir.toFile().exists()) { + saveDir.toFile().mkdirs(); + } + try(BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { + OreSpawn.API.getSpawnsForFile(k).stream() + .forEach( spawnName -> { + JsonObject thisSpawn = new JsonObject(); + ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); + thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); + thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); + thisSpawn.addProperty(ConfigNames.FEATURE, spawnEntry.getFeature().getFeatureName()); + thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); + thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); + thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); + thisSpawn.add(ConfigNames.PARAMETERS, spawnEntry.getFeature().getFeatureParameters()); + spawns.add(spawnName, thisSpawn); + }); + root.add(ConfigNames.SPAWNS, spawns); + p.write(gson.toJson(root)); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config data " + conf.toString()); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + } + + public static void saveSingle(String fileName) { + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + saveSingle(Constants.CONFDIR.resolve(fileName), gson); + } +} From 7e3c9604455d7940df1fe4b588d67c47e3261de1 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 28 Mar 2018 17:32:00 -0400 Subject: [PATCH 037/205] update the default orespawn.json that is supposed to replicate Vanilla to more closely match vanilla --- .../assets/orespawn/configs/orespawn.json | 86 +++++++++++++++++-- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/src/main/resources/assets/orespawn/configs/orespawn.json b/src/main/resources/assets/orespawn/configs/orespawn.json index db26a057..4021c4fe 100755 --- a/src/main/resources/assets/orespawn/configs/orespawn.json +++ b/src/main/resources/assets/orespawn/configs/orespawn.json @@ -72,7 +72,7 @@ } ] }, - "gold_ore": { + "gold_ore_standard": { "retrogen": false, "enabled": true, "feature": "default", @@ -95,19 +95,41 @@ } ] }, - "diamond_ore": { + "gold_ore_mesa": { "retrogen": false, "enabled": true, "feature": "default", "replaces": "default", "dimensions": [], + "biomes": { + "includes": [ "MESA" ] + }, + "parameters": { + "size": 8, + "variation": 2, + "frequency": 2, + "minHeight": 32, + "maxHeight": 79 + }, + "blocks": [ + { + "name": "minecraft:gold_ore", + "chance": 100 + } + ] + }, + "diamond_ore": { + "retrogen": false, + "enabled": true, + "feature": "precision", + "replaces": "default", + "dimensions": [], "biomes": { "excludes": [] }, "parameters": { - "size": 6, - "variation": 3, - "frequency": 8, + "size": 3, + "numObjects": 2, "minHeight": 0, "maxHeight": 16 }, @@ -143,7 +165,7 @@ }, "lapis_ore": { "retrogen": false, - "enabled": true, + "enabled": false, "feature": "default", "replaces": "default", "dimensions": [], @@ -171,7 +193,7 @@ "replaces": "default", "dimensions": [], "biomes": { - "excludes": [] + "includes": [ "MOUNTAIN" ] }, "parameters": { "size": 1, @@ -234,7 +256,7 @@ } ] }, - "stone": { + "andesite": { "retrogen": false, "enabled": true, "feature": "default", @@ -257,6 +279,54 @@ "state": "variant=andesite" } ] + }, + "diorite": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 112, + "variation": 50, + "frequency": 10, + "minHeight": 0, + "maxHeight": 255 + }, + "blocks": [ + { + "name": "minecraft:stone", + "chance": 100, + "state": "variant=diorite" + } + ] + }, + "granite": { + "retrogen": false, + "enabled": true, + "feature": "default", + "replaces": "default", + "dimensions": [], + "biomes": { + "excludes": [] + }, + "parameters": { + "size": 112, + "variation": 50, + "frequency": 10, + "minHeight": 0, + "maxHeight": 255 + }, + "blocks": [ + { + "name": "minecraft:stone", + "chance": 100, + "state": "variant=granite" + } + ] } } } \ No newline at end of file From e777d487585266049229380d29b5430624ae8898 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 29 Mar 2018 14:10:42 -0400 Subject: [PATCH 038/205] cleanups and finally figure out why the biome blacklists weren't always being respected... seems that the supposedly centralized spawn function wasn't - thats been fixed. More cleanups possible as the ISpawnEntry interface grows to accommodate the span of what is needed --- .../mcmoddev/orespawn/api/FeatureBase.java | 109 +++--------------- .../impl/features/ClusterGenerator.java | 8 +- .../features/DefaultFeatureGenerator.java | 8 +- .../impl/features/NormalCloudGenerator.java | 4 +- .../impl/features/PrecisionGenerator.java | 4 +- .../orespawn/impl/features/VeinGenerator.java | 4 +- .../location/BiomeLocationComposition.java | 6 +- .../impl/location/BiomeLocationList.java | 2 +- .../orespawn/impl/os3/BiomeBuilder.java | 17 +-- .../mcmoddev/orespawn/impl/os3/BlockList.java | 2 +- .../orespawn/json/OreSpawnReader.java | 5 +- 11 files changed, 46 insertions(+), 123 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 390ef800..ae799986 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -6,7 +6,6 @@ import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; @@ -27,13 +26,13 @@ public FeatureBase(Random rand) { this.random = rand; } - protected void runCache(int chunkX, int chunkZ, World world, OreSpawnBlockMatcher replacer) { + protected void runCache(int chunkX, int chunkZ, World world, ISpawnEntry spawnData) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it for (Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), replacer); + spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), spawnData); } } } @@ -48,10 +47,9 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d Biome thisBiome = world.getBiome(coord); if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { - OreSpawn.LOGGER.fatal("biome of chunk containing %s (%s) is invalid for this spawn (%s)", coord, thisBiome.getRegistryName(), spawnData.getSpawnName()); return false; } - + BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { @@ -59,7 +57,7 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d return false; } - return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension); + return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, spawnData); } private BlockPos mungeFixYcoord(BlockPos coord) { @@ -71,11 +69,12 @@ private BlockPos mungeFixYcoord(BlockPos coord) { } } - private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, IBlockState oreBlock, boolean cacheOverflow, int dimension) { + private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, IBlockState oreBlock, boolean cacheOverflow, int dimension, ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { IBlockState targetBlock = world.getBlockState(coord); + Biome thisBiome = world.getBiome(coord); - if (replacer.test(targetBlock)) { + if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { world.setBlockState(coord, oreBlock); return true; } else { @@ -90,7 +89,7 @@ private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher r } private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int dimension, - OreSpawnBlockMatcher replacer) { + ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return; @@ -103,7 +102,7 @@ private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int return; } - spawnOrCache(world, np, replacer, oreBlock, false, dimension); + spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); } private void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension) { @@ -194,15 +193,17 @@ protected int getPoint(int lowerBound, int upperBound, int median) { } protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius, - OreSpawnBlockMatcher replacer, int count, IBlockList possibleOres) { + ISpawnEntry spawnData, int count) { Random prng = this.random; int quantity = count; + IBlockList possibleOres = spawnData.getBlocks(); + OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for(int dy = (int)(-1 * radius); dy < radius; dy++){ for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){ for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){ if((dx*dx + dy*dy + dz*dz) <= rSqr){ IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension()); + spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; } if(quantity <= 0) { @@ -215,15 +216,17 @@ protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double rad protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, - OreSpawnBlockMatcher replacer, int count, IBlockList possibleOres) { + ISpawnEntry spawnData, int count) { Random prng = this.random; int quantity = count; + IBlockList possibleOres = spawnData.getBlocks(); + OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for(int dy = (int)(-1 * radius); dy < radius; dy++){ for(int dz = (int)(-1 * radius); dz < radius; dz++){ for(int dx = (int)(-1 * radius); dx < radius; dx++){ if((dx*dx + dy*dy + dz*dz) <= rSqr){ IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension()); + spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; } if(quantity <= 0) { @@ -249,82 +252,4 @@ protected boolean endCheck(boolean toPositive, int dx, double radius) { protected int getStart(boolean toPositive, double radius) { return ((int)(radius * (toPositive ? 1 : -1))); } - - public class FunctionParameterWrapper { - private World world; - private BlockPos blockPos; - private List replacements; - private IBlockList blocks; - private BiomeLocation biomes; - private ChunkPos chunkPos; - private IBlockState block; - - public FunctionParameterWrapper() {} - - public FunctionParameterWrapper(FunctionParameterWrapper other) { - world = other.getWorld(); - blockPos = other.getBlockPos(); - replacements = other.getReplacements(); - blocks = other.getOres(); - biomes = other.getBiomes(); - chunkPos = other.getChunkPos(); - block = other.getBlock(); - } - - public BiomeLocation getBiomes() { - return biomes; - } - - public void setBiomes(BiomeLocation biomes) { - this.biomes = biomes; - } - - public World getWorld() { - return world; - } - - public void setWorld(World world) { - this.world = world; - } - - public BlockPos getBlockPos() { - return blockPos; - } - - public void setBlockPos(BlockPos blockPos) { - this.blockPos = blockPos; - } - - public List getReplacements() { - return replacements; - } - - public void setReplacements(List replacements) { - this.replacements = replacements; - } - - public IBlockList getOres() { - return blocks; - } - - public void setOres(IBlockList ores) { - this.blocks = ores; - } - - public ChunkPos getChunkPos() { - return chunkPos; - } - - public void setChunkPos(ChunkPos chunkPos) { - this.chunkPos = chunkPos; - } - - public IBlockState getBlock() { - return block; - } - - public void setBlock(IBlockState block) { - this.block = block; - } - } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 1ab81ad2..4e23fc4c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -5,7 +5,6 @@ import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; @@ -31,7 +30,6 @@ public ClusterGenerator() { public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; - OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -40,7 +38,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, replaceMatch); + runCache(chunkX, chunkZ, world, spawnData); // now to ore spawn @@ -162,9 +160,9 @@ private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnDat double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int)(radius * radius); if( nextBoolean ) { - spawnMungeNE( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); + spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); } else { - spawnMungeSW( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); + spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index cb7daaef..40c4b7a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -6,7 +6,6 @@ import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.block.state.IBlockState; @@ -28,7 +27,6 @@ public DefaultFeatureGenerator() { public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; - OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -37,7 +35,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, replaceMatch); + runCache(chunkX, chunkZ, world, spawnData); // now to ore spawn @@ -114,9 +112,9 @@ private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnE double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int)(radius * radius); if( nextBoolean ) { - spawnMungeNE( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); + spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); } else { - spawnMungeSW( world, pos, rSqr, radius, spawnData.getMatcher(), count, spawnData.getBlocks() ); + spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 96bcc477..8dfa3459 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -7,7 +7,6 @@ import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.util.math.BlockPos; @@ -30,7 +29,6 @@ public NormalCloudGenerator() { public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; - OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -39,7 +37,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, replaceMatch); + runCache(chunkX, chunkZ, world, spawnData); // now to ore spawn diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 229df62c..c58c2318 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -9,7 +9,6 @@ import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants.FormatBits; import net.minecraft.block.state.IBlockState; @@ -35,7 +34,6 @@ public PrecisionGenerator() { public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; - OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -44,7 +42,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, replaceMatch); + runCache(chunkX, chunkZ, world, spawnData); // extract parameters int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index b4e0a507..7e4022c7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -7,7 +7,6 @@ import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.util.math.BlockPos; @@ -31,14 +30,13 @@ public VeinGenerator() { public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; - OreSpawnBlockMatcher replaceMatch = spawnData.getMatcher(); JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; int chunkZ = pos.z; - runCache(chunkX, chunkZ, world, replaceMatch); + runCache(chunkX, chunkZ, world, spawnData); mergeDefaults(params, getDefaultParameters()); // now to ore spawn diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 987165d0..be2e661e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -3,6 +3,7 @@ import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; import com.google.gson.JsonObject; + import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.data.Constants; @@ -71,8 +72,11 @@ public BiomeLocation getExclusions() { @Override public JsonElement serialize() { JsonObject rv = new JsonObject(); + rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); - rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); + if (!(this.inclusions instanceof BiomeLocationEmpty)) { + rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); + } return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index 6c885f94..ad649ac2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -50,7 +50,7 @@ public ImmutableSet getLocations() { public JsonElement serialize() { JsonArray rv = new JsonArray(); this.locations.stream() - .filter(bl -> (!(bl instanceof BiomeLocationEmpty) && (!(bl instanceof BiomeLocationAcceptAny)))) + .filter(bl -> (!(bl instanceof BiomeLocationEmpty))) .forEach(bl -> rv.add(bl.serialize())); return rv; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 2e3e89e5..1d7a784e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -5,6 +5,7 @@ import java.util.stream.Collectors; import com.google.common.collect.ImmutableSet; + import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.impl.location.BiomeLocationAcceptAny; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; @@ -71,12 +72,12 @@ public BiomeLocation create() { return new BiomeLocationAcceptAny(); } - BiomeLocation whitelist; - BiomeLocation blacklist; + BiomeLocation whitelistI; + BiomeLocation blacklistI; if (this.whitelist.size() == 0) { - whitelist = new BiomeLocationEmpty(); + whitelistI = new BiomeLocationEmpty(); } else { - whitelist = new BiomeLocationList( + whitelistI = new BiomeLocationList( ImmutableSet.copyOf( this.whitelist.stream() .map( biome -> new BiomeLocationSingle(biome) ) @@ -84,16 +85,18 @@ public BiomeLocation create() { } if (this.blacklist.size() == 0) { - blacklist = new BiomeLocationAcceptAny(); + blacklistI = new BiomeLocationEmpty(); } else { - blacklist = new BiomeLocationList( + blacklistI = new BiomeLocationList( ImmutableSet.copyOf( this.blacklist.stream() .map( biome -> new BiomeLocationSingle(biome) ) .collect(Collectors.toList()))); } - return new BiomeLocationComposition(whitelist, blacklist); + + BiomeLocation res = new BiomeLocationComposition(whitelistI, blacklistI); + return res; } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 94d597e9..81128583 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -53,7 +53,7 @@ public void startNewSpawn() { public void dump() { this.myBlocks.stream() .map(bd -> bd.getBlock()) - .forEach(bs -> OreSpawn.LOGGER.fatal("Block %s (with state: %s)", bs.getBlock(), bs)); + .forEach(bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index d906ddd8..a59f9f7c 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -300,7 +300,7 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { for( JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray() ) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { String xN = elem.getAsString(); - if (xN.matches(":")) { + if (xN.contains(":")) { // not a BiomeDictionary entry (we hope) bb.addWhitelistEntry(xN); } else { @@ -320,7 +320,7 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { for( JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { String xN = elem.getAsString(); - if (xN.matches(":")) { + if (xN.contains(":")) { // not a BiomeDictionary entry (we hope) bb.addBlacklistEntry(xN); } else { @@ -332,6 +332,7 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { } } } else if(emptyWhitelist) { + // empty whitelist and blacklist - accept everything bb.setAcceptAll(); } } From 832eae3680c7d2aea30bb01b036d08e78f4b037b Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 1 Apr 2018 22:26:25 -0400 Subject: [PATCH 039/205] lots of little changes all over the code - some debug outs that slowed generation down are removed and the zombie-holes issue is fixed --- .../mcmoddev/orespawn/api/FeatureBase.java | 13 ++++++ .../com/mcmoddev/orespawn/api/IBlockList.java | 1 + .../orespawn/api/os3/ISpawnBuilder.java | 1 + .../orespawn/api/plugin/PluginLoader.java | 5 +++ .../impl/features/PrecisionGenerator.java | 4 -- .../orespawn/impl/os3/BlockBuilder.java | 42 +++++-------------- .../mcmoddev/orespawn/impl/os3/BlockList.java | 5 +++ .../orespawn/impl/os3/OS3APIImpl.java | 7 ++-- .../orespawn/impl/os3/SpawnBuilder.java | 21 ++++++++-- .../orespawn/json/OreSpawnReader.java | 5 ++- .../orespawn/worldgen/OreSpawnWorldGen.java | 4 +- 11 files changed, 61 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index ae799986..67814a8e 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -5,6 +5,7 @@ import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; @@ -26,6 +27,10 @@ public FeatureBase(Random rand) { this.random = rand; } + public boolean isValidBlock(IBlockState oreBlock) { + return oreBlock.getBlock() != Blocks.AIR; + } + protected void runCache(int chunkX, int chunkZ, World world, ISpawnEntry spawnData) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); @@ -44,6 +49,10 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d return false; } + if(!isValidBlock(oreBlock)) { + return false; + } + Biome thisBiome = world.getBiome(coord); if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { @@ -71,6 +80,10 @@ private BlockPos mungeFixYcoord(BlockPos coord) { private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, IBlockState oreBlock, boolean cacheOverflow, int dimension, ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { + if(!isValidBlock(oreBlock)) { + return false; + } + IBlockState targetBlock = world.getBlockState(coord); Biome thisBiome = world.getBiome(coord); diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index c4837bfc..6df82f20 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -11,4 +11,5 @@ public interface IBlockList { public IBlockState getRandomBlock(Random rand); public void startNewSpawn(); public void dump(); + public int count(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 87507f30..5d667627 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -32,4 +32,5 @@ public interface ISpawnBuilder { public ISpawnBuilder addBlockWithChance(final Block block, final int chance); public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance); public ISpawnEntry create(); + public ISpawnBuilder addBlock(IBlockDefinition block); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index ec4898fe..ff9799ab 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -85,6 +85,11 @@ public void scanResources(PluginData pd) { String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); URL resURL = getClass().getClassLoader().getResource(base); + if(resURL == null) { + OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", base); + return; + } + URI uri; try { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index c58c2318..87ed15c4 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -63,8 +63,6 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider // bit of feedback - if we underproduce or overproduce a node, the next one gets a correction if (sc != thisNode && sc != 0) { thisNode += (nodeSize - sc); - OreSpawn.LOGGER.debug("node at %s of size %d instead of %d - modding to %d", - spot, sc, nodeSize, thisNode); } else if (sc == thisNode) { // if we produced exact size, reset the size thisNode = nodeSize; @@ -88,7 +86,6 @@ private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, Ch c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); if (c == 0) { - OreSpawn.LOGGER.debug("Unable to place block at %s (chunk %s)", spot, pos); act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), heightRange); } @@ -158,7 +155,6 @@ private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightR } BlockPos rVal = spot.add(xmod, ymod, zmod); - OreSpawn.LOGGER.debug("rescaled %s to %s", spot, rVal); return rVal; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index a6d0671d..e3de4267 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -12,7 +12,7 @@ public class BlockBuilder implements IBlockBuilder { private IBlockState blockState; private int chance; - private boolean isValid; + private boolean isValid = true; public BlockBuilder() { // nothing to do here @@ -21,9 +21,7 @@ public BlockBuilder() { @Override public IBlockBuilder setFromBlockState(IBlockState blockState) { ResourceLocation key = blockState.getBlock().getRegistryName(); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } return this.setFromBlockStateWithChance(blockState, 100); @@ -32,9 +30,7 @@ public IBlockBuilder setFromBlockState(IBlockState blockState) { @Override public IBlockBuilder setFromBlock(Block block) { ResourceLocation key = block.getRegistryName(); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } return this.setFromBlockState(block.getDefaultState()); @@ -57,9 +53,7 @@ public IBlockBuilder setFromName(String blockName, int metadata) { @Override public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); @@ -67,9 +61,7 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { @Override public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); @@ -79,9 +71,7 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String @Override @Deprecated public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); @@ -91,9 +81,7 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int met @Override public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance) { ResourceLocation key = blockState.getBlock().getRegistryName(); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } this.blockState = blockState; @@ -104,9 +92,7 @@ public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int cha @Override public IBlockBuilder setFromBlockWithChance(Block block, int chance) { ResourceLocation key = block.getRegistryName(); - if (ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } return this.setFromBlockStateWithChance(block.getDefaultState(), chance); @@ -129,9 +115,7 @@ public IBlockBuilder setFromNameWithChance(String blockName, int metadata, int c @Override public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), chance); @@ -139,9 +123,7 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio @Override public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, int chance) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); @@ -151,9 +133,7 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio @Override @Deprecated public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, int chance) { - if (ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = true; - } else { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 81128583..09d45fb4 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -56,4 +56,9 @@ public void dump() { .forEach(bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); } + @Override + public int count() { + return this.myBlocks.size(); + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 3eafb7cc..3dd7b622 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -5,7 +5,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.PathMatcher; -import java.nio.file.Paths; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -111,9 +110,11 @@ public void loadConfigFiles() { @Override public void addSpawn(ISpawnEntry spawnEntry) { - spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); + if (spawnEntry != null) { + spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); + } } - + @Override public void addFeature(String featureName, IFeature feature) { features.addFeature(featureName, feature); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index a40b5643..24b4b677 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -1,9 +1,11 @@ package com.mcmoddev.orespawn.impl.os3; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; import com.mcmoddev.orespawn.util.StateUtil; +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; @@ -171,13 +173,24 @@ public ISpawnBuilder addBlockWithChance(Block block, int chance) { public ISpawnBuilder addBlockWithChance(IBlockState block, int chance) { BlockBuilder bb = new BlockBuilder(); bb.setFromBlockStateWithChance(block, chance); - this.blocks.addBlock(bb.create()); - return this; + return this.addBlock(bb.create()); } + @Override + public ISpawnBuilder addBlock(IBlockDefinition block) { + if(block.isValid()) { + this.blocks.addBlock(block); + } + return this; + } + @Override public SpawnEntry create() { - return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, - this.biomes, this.replacements, this.blocks, this.feature); + if(this.blocks.count() > 0) { + return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, + this.biomes, this.replacements, this.blocks, this.feature); + } else { + return null; + } } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index a59f9f7c..12decc0d 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -27,6 +27,7 @@ import com.mcmoddev.orespawn.api.exceptions.UnknownVersionException; import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; import com.mcmoddev.orespawn.api.os3.IBlockBuilder; +import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; @@ -245,9 +246,9 @@ private static void loadSingleEntry(Entry entry) throws Unk bl.get(Constants.ConfigNames.CHANCE).getAsInt()); } else { block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); } - sb.addBlock(block.create().getBlock()); + sb.addBlock(block.create()); } else { OreSpawn.LOGGER.error("Skipping value %s in blocks list as it is not the correct format", elem.toString()); } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 1cd41a1e..38460289 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -23,9 +23,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG OreSpawn.API.getSpawns(thisDim).stream() .filter(spawn -> spawn.isEnabled()) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> { - spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); - }); + .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); } } From 6cab1593bab1326d57a245c0925b25aef94e218d Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 1 Apr 2018 23:20:45 -0400 Subject: [PATCH 040/205] update the changelog in prep for a CurseForge release --- CHANGELOG.txt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d119e6d8..b1e0cb9c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1 +1,12 @@ -Version 3.2.1 +Version 3.3.0 + +* Rewrite the internal API to be a little more flexible +* Rewrite the loading and saving of the JSON configs - the current form is less flexible but will be easier to extend or replace in the future +* Fix the Dimension and Biome blacklist/whitelist code +* Fix the "zombie holes" issue that cropped up if a block was present in a config but not actually present in the game +* Change the default feature's (features-default.json in previous versions) to be defined in the _features.json in orespawn instead of programatically +* Change the default replacements (replacements-default.json in previous versions) to be defined in _replacements.json in orespawn instead of programatically +* Define the actual format of the replacements files +* fully define the format of the presets files (need to add, I believe, an _presets.json) +* remove any loading of any format of config other than those tagged as being version 2.0 (this capability will return at a later date) + From 219318777028b8c64c42cc36023071d5f359709d Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 2 Apr 2018 00:04:44 -0400 Subject: [PATCH 041/205] blargh - fixes #117 report of empty whitelist+partial blacklist equaling no spawns --- .../java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 1d7a784e..3e5b5f34 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -75,7 +75,11 @@ public BiomeLocation create() { BiomeLocation whitelistI; BiomeLocation blacklistI; if (this.whitelist.size() == 0) { - whitelistI = new BiomeLocationEmpty(); + if(this.blacklist.size() > 0) { + whitelistI = new BiomeLocationAcceptAny(); + } else { + whitelistI = new BiomeLocationEmpty(); + } } else { whitelistI = new BiomeLocationList( ImmutableSet.copyOf( From 637d9cf58ebd22a34efb2dd3145e7e1b9f85a7dd Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 2 Apr 2018 08:01:36 -0400 Subject: [PATCH 042/205] blank whitelist and blacklist without 'acceptAll' being set doesn't always mean 'acceptAll' - check of 'acceptAllOverworld' is flagged first --- .../java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 1aec0938..b64bfe1b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -47,7 +47,8 @@ public IDimensionBuilder setDenyAll() { public IDimensionList create() { if (this.acceptAll || ((this.dimensionWhitelist.size() == 0) && - (this.dimensionBlacklist.size() == 0))) { + (this.dimensionBlacklist.size() == 0)) && + !(this.acceptAllOverworld)) { return new DimensionListAcceptAll(); } else if (this.denyAll) { return new DimensionListDenyAll(); From 405cd161e076f237e4787afa7852decb92ffbace Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 2 Apr 2018 16:26:20 -0400 Subject: [PATCH 043/205] update changelog --- CHANGELOG.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b1e0cb9c..27993542 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -9,4 +9,4 @@ Version 3.3.0 * Define the actual format of the replacements files * fully define the format of the presets files (need to add, I believe, an _presets.json) * remove any loading of any format of config other than those tagged as being version 2.0 (this capability will return at a later date) - +* Fix the Dimension blacklist/whitelist code to make it actually work (there was a missing conditional in the DimensionBuilder create() method) From 94be2bfe2cb7a6c11129651b122542675476b6c8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 12 Apr 2018 00:46:25 -0400 Subject: [PATCH 044/205] WIP fixing the vein generator - it now works, but because of the fact that vertical-moving points are twice as common as horizontally moving, these tend to go vertical and the weighting assures that continues - this needs fixed --- .../com/mcmoddev/orespawn/data/Constants.java | 2 +- .../orespawn/impl/features/VeinGenerator.java | 341 +++++++++++------- 2 files changed, 204 insertions(+), 139 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 20d5eb3d..d1ed3429 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -48,10 +48,10 @@ private FormatBits() {} public static final String NODE_SIZE = "size"; public static final String ATTEMPTS = "attempts"; public static final String LENGTH = "length"; - public static final String WANDER = "wander"; public static final String NODE_COUNT = "numObjects"; public static final String ATTEMPTS_MIN = "minAttempts"; public static final String ATTEMPTS_MAX = "maxAttempts"; + public static final String STARTINGFACE = "startFacing"; } public final class FileBits { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 7e4022c7..f641ecea 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -1,14 +1,21 @@ package com.mcmoddev.orespawn.impl.features; +import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.Random; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.data.Constants; +import com.mojang.realmsclient.util.Pair; +import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; @@ -28,10 +35,10 @@ public VeinGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); - + // First, load cached blocks for neighboring chunk ore spawns int chunkX = pos.x; int chunkZ = pos.z; @@ -49,11 +56,12 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - int wander = params.get(Constants.FormatBits.WANDER).getAsInt(); + int startingFace = getFaceFromString(params.get(Constants.FormatBits.STARTINGFACE).getAsString()); int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + OreSpawn.LOGGER.fatal("parameters: %s", params); int tries; if (triesMax == triesMin) { @@ -77,165 +85,223 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r = 0; } - spawnVein(length + r, nodeSize, wander, new BlockPos(x, y, z), spawnData, world); + spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, world); } tries--; } } - - // for proper use we need to map these in on the selections later - // probability of any given vertex-point of a face being selected, each - // row of this is a row on the face, each float is a point - private float[][] rowMap = new float[][] { - { 0.5f, 0.75f, 0.5f }, - { 0.5f, 1.00f, 0.5f }, - { 0.5f, 0.75f, 0.5f } - }; - - private float[] colMap = new float[] { - 0.75f, 1.00f, 0.75f - }; - - private int triangularDistributionNoRandom(double current) { - if (current < 0.5f) { - return (int) Math.sqrt(current * 2); - } else { - return (int)(2 - Math.sqrt((1 - current) * 2)); + + private int getFaceFromString(String direction) { + String work = direction.toLowerCase(); + switch(work) { + case "north": + return 0; + case "south": + return 5; + case "east": + return 2; + case "west": + return 3; + case "down": + return 1; + case "up": + return 4; + default: + return 0; } } - private enum EnumFace { - UP, - FRONT, - DOWN, - BACK, - LEFT, - RIGHT; - - public static EnumFace getRandomFace(Random random) { - return values()[random.nextInt(values().length)]; + private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos blockPos, ISpawnEntry spawnData, World world) { + int face = startingFace; + int square = this.random.nextInt(8); + BlockPos workingPos = new BlockPos(blockPos); + + if(!spawnData.getMatcher().test(world.getBlockState(blockPos))) { + OreSpawn.LOGGER.info("invalid spawn start location %s", blockPos); + return; + } + + // build vein + List> points = Lists.newLinkedList(); + points.add(Pair.of(face, square)); + for( int j = 0; j < veinLength; j++ ) { + OreSpawn.LOGGER.fatal("spawnVein, face = %d, square = %d", face, square); + Map pos = Maps.newHashMap(); + int[] w = getWeighted(face, square); + for( int k = 0; k < w.length; k++ ) { + pos.put(w[k], k); + } + + int[] t = Arrays.stream(w).distinct().sorted().toArray(); + int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length-5, t.length)).map( it -> pos.get(it)).toArray(); + int temp = this.random.nextInt(5); + face = fpos[temp]%6; + square = fpos[temp]%9; + points.add(Pair.of(face,square)); } + spawnOre(world, spawnData, blockPos, nodeSize); + OreSpawn.LOGGER.info("Spawned node at %s (size %d)", blockPos, nodeSize); + for(Pair point : points) { + OreSpawn.LOGGER.info("Next node at %s (size %d)", workingPos, nodeSize); + spawnOre(world, spawnData, workingPos, nodeSize); + int[] nextMunge = getDirectionValues(point.first().intValue(), point.second().intValue()); + workingPos = workingPos.add(nextMunge[0], nextMunge[1], nextMunge[2]); + } } - private int[][][][] facePosMap = new int[][][][] { - { - // top face - // x y z - { { -1, 1, 1 }, { 0, 1, 1 }, { 1, 1, 1 } }, // line vertex 1 to 2 - { { -1, 1, 0 }, { 0, 1, 0 }, { 1, 0, 1 } }, // center row, no line - { { -1, 1, -1 }, { 0, 1, -1 }, { 1, 1, -1 } } // line vertex 3 to 4 - }, - { - // front face - // x y z - { { -1, 1, 1 }, { 0, 1, 1 }, { 1, 1, 1 } }, // line vertex 1 to 2 - { { -1, 0, 1 }, { 0, 0, 1 }, { 1, 0, 1 } }, // center row, no line - { { -1, -1, 1 }, { 0, -1, 1 }, { 1, -1, 1 } } // line vertex 7 to 8 - }, - { - // down face - // x y z - { { -1, -1, 1 }, { 0, -1, 1 }, { 1, -1, 1 } }, // line vertex 7 to 8 - { { -1, -1, 0 }, { 0, -1, 0 }, { 1, -1, 0 } }, // center, no line - { { -1, -1, -1 }, { 0, -1, -1 }, { 1, -1, -1 } } // line vertex 6 to 5 - }, - { - // back face - // x y z - { { -1, 1, -1 }, { 0, 1, -1 }, { 1, 1, -1 } }, // line vertex 3 to 4 - { { -1, 0, -1 }, { 0, -1, 0 }, { 1, 0, -1 } }, // center, no line - { { -1, -1, -1 }, { 0, -1, -1 }, { 1, -1, -1 } } // line vertex 6 to 5 - }, - { - // left face - // x y z - { { 1, 1, 1 }, { 1, 1, 0 }, { 1, 1, -1 } }, // line vertex 2 to 3 - { { 1, 0, 1 }, { 1, 0, 0 }, { 1, 0, -1 } }, // line, vertex 2 to 8 - { { 1, -1, 1 }, { 1, -1, 0 }, { 1, -1, -1 } } // line, vertex 3 to 5 - }, - { - // right face - // x y z - { { -1, 1, 1 }, { -1, 1, 0 }, { -1, 1, -1 } }, // line vertex 2 to 3 - { { -1, 0, 1 }, { -1, 0, 0 }, { -1, 0, -1 } }, // line, vertex 2 to 8 - { { -1, -1, 1 }, { -1, -1, 0 }, { -1, -1, -1 } } // line, vertex 3 to 5 + private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quantity) { + int count = quantity; + int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, + world.provider.getDimension(), true, spawnData); + } + + return; } - }; - private BlockPos adjustPos(BlockPos pos, int row, int col, EnumFace face) { - int faceOrd = face.ordinal(); - int[] adjust = facePosMap[faceOrd][row][col]; - return pos.add(adjust[0], adjust[1], adjust[2]); + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void spawnVein(int length, int nodeSize, int wander, BlockPos pos, ISpawnEntry spawnData, World world) { - // passed in POS is our start - we start with a weighting favoring straight directions - // and three-quarters that to the edges - // and one-half to the corners - - // generate a node here - spawnOre(pos, spawnData, world, nodeSize); - // select a direction, decrement length, repeat - float curRow = 1.00f; - float curCol = 1.00f; - int colAdj = 2; - int rowAdj = 2; - EnumFace faceToUse = EnumFace.getRandomFace(random); - int l = length; - BlockPos workPos = new BlockPos(pos); - - while (l > 0) { - workPos = adjustPos(workPos, colAdj, rowAdj, faceToUse); - - l--; - - // allow for the "wandering vein" parameter - if (random.nextInt(100) <= wander) { - colAdj = triangularDistributionNoRandom(curCol); - curCol += colMap[colAdj]; - - while (curCol > 1) { - curCol /= 10; - } - - rowAdj = triangularDistributionNoRandom(curCol); - curRow += rowMap[colAdj][rowAdj]; + private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, BlockPos pos) { + int count = quantity; + double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int)(radius * radius); + if( nextBoolean ) { + spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); + } else { + spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); + } + } - while (curRow > 1) { - curRow /= 10; + private int[] getDirectionValues(int face, int square) { + int x = 0; + int y = 0; + int z = 0; + switch(face) { + case 0: + z = -1; + break; + case 2: + x = 1; + break; + case 3: + x = -1; + break; + case 5: + z = 1; + break; + } + if (face == 0 || face == 5) { + y = square < 3?1:(square>5?-1:0); + x = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + } else if (face == 2 || face == 3) { + y = square < 3?1:square>5?-1:0; + z = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + } else if (face == 1 || face == 4) { + z = square < 3?-1:(square>5?1:0); + x = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + } + + if (square < 3 || face == 4) y = 1; + else if (square <= 5) y = 0; + else if (square <= 8 || face == 1) y = -1; + + return new int[] { x, y, z }; + } + /* + * To keep things heading the correct direction, we weight the faces and the "points" of the face + * so that we can choose a semi-intelligent direction to continue in. + */ + private int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; + private int[] pointWeights = Arrays.stream(faceWeights).map(a -> a*2 ).toArray(); + + + private int[] getWeighted(int face, int square) { + int[] rv = new int[54]; + + for( int f = 0; f < 6; f++ ) { + for( int s = 0; s < 9; s++ ) { + if(isNeighborFace(face, f)) { + rv[f+s] += faceWeights[1]; + } else if(face == f) { + rv[f+s] += faceWeights[0]; + } else { + rv[f+s] = 0; } - spawnOre(workPos, spawnData, world, nodeSize); - - // when nodes are small, the veins get badly broken if we do face wandering - if (nodeSize > 2) { - faceToUse = EnumFace.getRandomFace(random); + rv[f+s] += pointWeights[s == square?0:1]; + if( s != 4 ) { + int matchFace = 0; + int matchSquare = 0; + if( s%3 == 0 ) { + // left side + matchFace = getMatchingFace(f, 0); + matchSquare = getMatchingSquare(s, f, 0); + } else if( s == 2 || (s-1)%2 == 0 ) { + // right side + matchFace = getMatchingFace(f, 1); + matchSquare = getMatchingSquare(s, f, 1); + } + int addr = matchFace + matchSquare; + rv[addr] += faceWeights[1] + pointWeights[1]; + + if( s < 3 || s > 5 ) { + if( s < 3 ) { + // top row + matchFace = getMatchingFace(f, 2); + matchSquare = getMatchingSquare(s, f, 2); + } else if( s > 5 ) { + //bottom row + matchFace = getMatchingFace(f, 3); + matchSquare = getMatchingSquare(s, f, 3); + } + rv[matchFace+matchSquare] += faceWeights[1] + pointWeights[1]; + } } } } + + return rv; } - private void spawnOre(BlockPos pos, ISpawnEntry spawnData, World world, int nodeSize) { - int count = nodeSize; - int lutType = (count < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - int[] lut = (count < 8) ? offsetIndexRef_small : offsetIndexRef; - Vec3i[] offs = new Vec3i[lutType]; + private int getMatchingSquare(int s, int face, int direction) { + switch(direction) { + case 0: /* LEFT */ + return (s%3 == 0)? s +2 : s - 1; + case 1: /* RIGHT */ + return ((s+1)%3 == 0)? s - 2: s + 1; + case 2: /* UP */ + return (s<3) ? s + 6 : s - 3; + case 3: /* DOWN */ + return (s>=6) ? s - 6 : s + 3; + } + return s; + } - System.arraycopy((count < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + private int[][] faceMap = new int[][] { { 3, 2, 1, 4 }, { 3, 2, 5, 0 }, { 1, 4, 5, 0 }, + { 4, 1, 5, 0 }, { 2, 3, 5, 0 }, { 3, 2, 4, 1 } }; - int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - int dimension = world.provider.getDimension(); + private int getMatchingFace(int f, int i) { + return faceMap[f][i]; + } - IBlockList blocks = spawnData.getBlocks(); - while (count > 0) { - spawn(blocks.getRandomBlock(this.random), world, - pos.add(offs[scrambledLUT[--count]]), dimension, true, - spawnData); - } + private boolean isNeighborFace(int face, int f) { + return Arrays.stream(faceMap[face]).anyMatch(a -> a == f); } @Override @@ -248,7 +314,7 @@ public JsonObject getDefaultParameters() { defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); defParams.addProperty(Constants.FormatBits.LENGTH, 16); - defParams.addProperty(Constants.FormatBits.WANDER, 75); + defParams.addProperty(Constants.FormatBits.STARTINGFACE, "north"); defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3); return defParams; } @@ -258,5 +324,4 @@ public JsonObject getDefaultParameters() { public void setRandom(Random rand) { this.random = rand; } - } From 6eaea932e05f972be6f173553a76d886f24eeb9e Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 12 Apr 2018 12:56:37 -0400 Subject: [PATCH 045/205] this now works and does so pretty well - might re-add the wander parameter at some point as I also, now, have a means of halting back-tracking --- .../orespawn/impl/features/VeinGenerator.java | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index f641ecea..b3c3f30e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -107,7 +107,14 @@ private int getFaceFromString(String direction) { return 1; case "up": return 4; + case "random": + return this.random.nextInt(5); + case "vertical": + return this.random.nextBoolean()?4:1; + case "horizontal": + return this.random.nextBoolean()?(this.random.nextBoolean()?0:5):(this.random.nextBoolean()?2:3); default: + OreSpawn.LOGGER.error("Invalid value %s found in parameters for vein spawn, returning \"north\"", direction); return 0; } } @@ -118,7 +125,6 @@ private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos BlockPos workingPos = new BlockPos(blockPos); if(!spawnData.getMatcher().test(world.getBlockState(blockPos))) { - OreSpawn.LOGGER.info("invalid spawn start location %s", blockPos); return; } @@ -126,7 +132,6 @@ private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos List> points = Lists.newLinkedList(); points.add(Pair.of(face, square)); for( int j = 0; j < veinLength; j++ ) { - OreSpawn.LOGGER.fatal("spawnVein, face = %d, square = %d", face, square); Map pos = Maps.newHashMap(); int[] w = getWeighted(face, square); for( int k = 0; k < w.length; k++ ) { @@ -137,14 +142,12 @@ private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length-5, t.length)).map( it -> pos.get(it)).toArray(); int temp = this.random.nextInt(5); face = fpos[temp]%6; - square = fpos[temp]%9; + square = fpos[temp]%12; points.add(Pair.of(face,square)); } spawnOre(world, spawnData, blockPos, nodeSize); - OreSpawn.LOGGER.info("Spawned node at %s (size %d)", blockPos, nodeSize); for(Pair point : points) { - OreSpawn.LOGGER.info("Next node at %s (size %d)", workingPos, nodeSize); spawnOre(world, spawnData, workingPos, nodeSize); int[] nextMunge = getDirectionValues(point.first().intValue(), point.second().intValue()); workingPos = workingPos.add(nextMunge[0], nextMunge[1], nextMunge[2]); @@ -235,7 +238,7 @@ private int[] getWeighted(int face, int square) { int[] rv = new int[54]; for( int f = 0; f < 6; f++ ) { - for( int s = 0; s < 9; s++ ) { + for( int s = 0; s < 12; s++ ) { if(isNeighborFace(face, f)) { rv[f+s] += faceWeights[1]; } else if(face == f) { @@ -245,14 +248,14 @@ private int[] getWeighted(int face, int square) { } rv[f+s] += pointWeights[s == square?0:1]; - if( s != 4 ) { + if( s != 4 && s != 7) { int matchFace = 0; int matchSquare = 0; if( s%3 == 0 ) { // left side matchFace = getMatchingFace(f, 0); matchSquare = getMatchingSquare(s, f, 0); - } else if( s == 2 || (s-1)%2 == 0 ) { + } else if( s == 2 || s == 5 || s == 8 || s == 11 ) { // right side matchFace = getMatchingFace(f, 1); matchSquare = getMatchingSquare(s, f, 1); @@ -260,12 +263,12 @@ private int[] getWeighted(int face, int square) { int addr = matchFace + matchSquare; rv[addr] += faceWeights[1] + pointWeights[1]; - if( s < 3 || s > 5 ) { + if( s < 3 || s > 8 ) { if( s < 3 ) { // top row matchFace = getMatchingFace(f, 2); matchSquare = getMatchingSquare(s, f, 2); - } else if( s > 5 ) { + } else if( s > 8 ) { //bottom row matchFace = getMatchingFace(f, 3); matchSquare = getMatchingSquare(s, f, 3); @@ -279,16 +282,32 @@ private int[] getWeighted(int face, int square) { return rv; } + /* + * 0 1 2 + * 3 4 5 + * 6 7 8 + * 9 10 11 + * -------- + * 0 1 2 + * 3 4 5 + * 6 7 8 + * 9 10 11 + * -------- + * 0 1 2 + * 3 4 5 + * 6 7 8 + * 9 10 11 + */ private int getMatchingSquare(int s, int face, int direction) { switch(direction) { case 0: /* LEFT */ return (s%3 == 0)? s +2 : s - 1; case 1: /* RIGHT */ - return ((s+1)%3 == 0)? s - 2: s + 1; + return ( s == 2 || s == 5 || s == 8 || s == 11 )? s - 2: s + 1; case 2: /* UP */ - return (s<3) ? s + 6 : s - 3; + return (s<3) ? s + 9 : s - 3; case 3: /* DOWN */ - return (s>=6) ? s - 6 : s + 3; + return (s>8) ? s - 9 : s + 3; } return s; } From f66306a781d721a03c1c87b24a9d5a26e6764e5a Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 12 Apr 2018 15:35:05 -0400 Subject: [PATCH 046/205] fix the parsing of replacements entries so it matches the docs and what the code was trying to do instead of being badly broken --- .../mcmoddev/orespawn/impl/os3/ReplacementBuilder.java | 8 +++++++- .../java/com/mcmoddev/orespawn/json/OreSpawnReader.java | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 66042e0d..9fccf1bc 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -11,9 +11,11 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; +import org.apache.commons.lang3.RandomStringUtils; + public class ReplacementBuilder implements IReplacementBuilder { - private String replacementName; + private String replacementName = null; private List entries; public ReplacementBuilder() { @@ -73,6 +75,10 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int @Override public IReplacementEntry create() { + if (this.replacementName == null) { + this.replacementName = String.format("replacement_%s", RandomStringUtils.randomAlphanumeric(8, 16)); + } + return new ReplacementEntry(this.replacementName, this.entries); } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 12decc0d..8fabd56f 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -214,7 +214,7 @@ private static void loadSingleEntry(Entry entry) throws Unk case Constants.ConfigNames.REPLACEMENT: if(!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); - } else if(ent.getValue().getAsJsonPrimitive().isString()) { + } else if(ent.getValue().isJsonPrimitive() && ent.getValue().getAsJsonPrimitive().isString()) { if(OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { sb.setReplacement(OreSpawn.API.getReplacement(ent.getValue().getAsString())); } @@ -271,7 +271,7 @@ private static void loadSingleEntry(Entry entry) throws Unk } private static List loadBlock(JsonObject json) { - String blockName = json.get(Constants.ConfigNames.BLOCK).getAsString(); + String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); if(json.has(Constants.ConfigNames.STATE)) { Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList(StateUtil.deserializeState(block, json.get(Constants.ConfigNames.STATE).getAsString())); From 06f6579e11b1b109f82322566891ebcdc6bf8ccf Mon Sep 17 00:00:00 2001 From: dshadowwolf Date: Fri, 8 Jun 2018 08:40:00 -0400 Subject: [PATCH 047/205] Change this a bit Add a line and link pointing people looking for the other OreSpawn (like the person behind #133) to that mods website. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 39dde390..19ce6c43 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # OreSpawn Minecraft library mod that provides better control over the spawning of ores in Minecraft. +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. ## How it works 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: From 6db0f07a1c1944944eca2a983521e260344ef578 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 28 Jun 2018 12:09:17 -0400 Subject: [PATCH 048/205] fix the logic bug where existing replacements registry entries got ignored and new ones were created for every spawn entry --- .../mcmoddev/orespawn/api/os3/IReplacementBuilder.java | 1 + .../mcmoddev/orespawn/impl/os3/ReplacementBuilder.java | 5 +++++ .../java/com/mcmoddev/orespawn/json/OreSpawnReader.java | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index e5608601..4475b03d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -15,5 +15,6 @@ public interface IReplacementBuilder { public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state); @Deprecated public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata); + public boolean hasEntries(); public IReplacementEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 66042e0d..7aa25e5b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -71,6 +71,11 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); } + @Override + public boolean hasEntries() { + return this.entries.isEmpty(); + } + @Override public IReplacementEntry create() { return new ReplacementEntry(this.replacementName, this.entries); diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 12decc0d..39e20322 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -212,14 +212,14 @@ private static void loadSingleEntry(Entry entry) throws Unk fb.setFeature(featureName); break; case Constants.ConfigNames.REPLACEMENT: + IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); if(!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); } else if(ent.getValue().getAsJsonPrimitive().isString()) { if(OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { - sb.setReplacement(OreSpawn.API.getReplacement(ent.getValue().getAsString())); + rb.setFromName(ent.getValue().getAsString()); } } else { - IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); for( JsonElement e : ent.getValue().getAsJsonArray() ) { if(e.isJsonObject()) { loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); @@ -227,8 +227,12 @@ private static void loadSingleEntry(Entry entry) throws Unk OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString()); } } + } + + if(rb.hasEntries()) { sb.setReplacement(rb.create()); } + break; case Constants.ConfigNames.BLOCK: if (ent.getValue().isJsonArray()) { From bfbd3aca87d0e3772ba22200ff6fa9009cf3caaa Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 8 Jul 2018 21:08:41 -0400 Subject: [PATCH 049/205] Seems that event handlers are not run in order and can interrupt each other. This is the only reason that "keys" could be empty when "chunks" is not. Add a check to early exit if "keys" is empty. This should fix the crash that several have reported. --- src/main/java/com/mcmoddev/orespawn/EventHandlers.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 5584aaf3..905c0a59 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -165,7 +165,10 @@ public void worldTick(WorldTickEvent ev) { if (ev.phase == Phase.END) { Deque keys = Queues.newArrayDeque(chunks.keySet()); - for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { + // if 'chunks' is empty, exit + // if 'keys' is empty, exit + // exit after 5 items, regardless + for (int c = 0; c < 5 && !chunks.isEmpty() && !keys.isEmpty(); c++) { ChunkPos p = keys.pop(); List spawns = chunks.remove(p); From f9215fddeef2c0b37b987950e59302fd18a42d86 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 8 Jul 2018 22:40:03 -0400 Subject: [PATCH 050/205] Proper fix for the re-entrancy issue - this also cleans up the logic a bit, splits to more helper functions so almost all "action nodes" are graphed to separate functions and fixes the issue that was causing problems with data sync. --- .../com/mcmoddev/orespawn/EventHandlers.java | 75 +++++++++++++------ 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 905c0a59..7ff4bad0 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.Deque; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -19,6 +20,7 @@ import com.mcmoddev.orespawn.data.Constants; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.Tuple; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; @@ -38,11 +40,12 @@ public class EventHandlers { private Deque retroChunks; - private Map> chunks; + private Deque>> chunks; +// private Map> chunks; EventHandlers() { retroChunks = new ConcurrentLinkedDeque<>(); - chunks = new ConcurrentHashMap<>(); + chunks = new ConcurrentLinkedDeque<>(); } private List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, @@ -78,6 +81,10 @@ public void onChunkSave(ChunkDataEvent.Save ev) { ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); } + private boolean dequeContains(ChunkPos cc) { + return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()).contains(true); + } + @SubscribeEvent public void onChunkLoad(ChunkDataEvent.Load ev) { World world = ev.getWorld(); @@ -85,7 +92,7 @@ public void onChunkLoad(ChunkDataEvent.Load ev) { doBedrockRetrogen(chunkCoords); - if (chunks.containsKey(chunkCoords)) { + if (dequeContains(chunkCoords)) { return; } @@ -96,7 +103,7 @@ public void onChunkLoad(ChunkDataEvent.Load ev) { Biome thisBiome = ev.getChunk().getBiome(thisPos, world.getBiomeProvider()); if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.put(chunkCoords, getDifferingTags(chunkTag, thisDimension, thisBiome)); + chunks.addLast(new Tuple<>(chunkCoords, getDifferingTags(chunkTag, thisDimension, thisBiome))); } } } @@ -154,34 +161,56 @@ private void doBedrockRetrogen(ChunkPos chunkCoords) { } } + private static World world; + private static ChunkProviderServer chunkProvider; + private static IChunkGenerator chunkGenerator; + private static Random random; + + private static void setupData(World nw) { + if (world == null || !world.equals(nw)) { + world = nw; + } + + if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { + chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); + } + + if (chunkGenerator == null) { + chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator"); + } + + if (random == null) { + random = new Random(world.getSeed()); + } + + } + + private void runBits(Tuple> tup) { + ChunkPos p = tup.getFirst(); + List spawns = tup.getSecond(); + + // re-seed with something totally new :P + random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); + spawns.stream().forEach( s -> OreSpawn.API.getSpawn(s).generate(random, world, chunkGenerator, chunkProvider, p) ); + } + @SubscribeEvent public void worldTick(WorldTickEvent ev) { + setupData(ev.world); + if (ev.side != Side.SERVER) { return; } - World world = ev.world; if (ev.phase == Phase.END) { - Deque keys = Queues.newArrayDeque(chunks.keySet()); - - // if 'chunks' is empty, exit - // if 'keys' is empty, exit - // exit after 5 items, regardless - for (int c = 0; c < 5 && !chunks.isEmpty() && !keys.isEmpty(); c++) { - ChunkPos p = keys.pop(); - List spawns = chunks.remove(p); - - Random random = new Random(world.getSeed()); - // re-seed with something totally new :P - random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); - ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider(); - IChunkGenerator chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator"); - for(String s : spawns) { - OreSpawn.API.getSpawn(s).generate(random, world, chunkGenerator, chunkProvider, p); - } + Deque>> b = new LinkedList<>(); + for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { + b.push(chunks.pop()); } - + + b.forEach(this::runBits); + for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { ChunkPos p = retroChunks.pop(); OreSpawn.flatBedrock.retrogen(world, p.x, p.z); From 1a55bb8c06114a910e4d2c5681369356fde1b188 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sat, 21 Jul 2018 04:10:34 -0700 Subject: [PATCH 051/205] Update gradle to 4.9 --- gradle/wrapper/gradle-wrapper.jar | Bin 54708 -> 54413 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee94c0ab25cf079ac8ccdf87f41d455d42..0d4a9516871afd710a9d84d89e31ba77745607bd 100644 GIT binary patch delta 22872 zcmZ6yV|!+8*R&g(9ox2T+qQGYPKRe~+qUhbW7|&0b~?top7-0m{=(d9))-^2I$Em1 zV=KWExFFs()4UV;w4rq#T<%>!K@xBqTTB>W4I_ii#GpYyu9FEF>4Bc=S{UDoC(hv$ zkfOR3Y6S}RArtfF#OMikC|UEI9x&`A;?y>dmW;{pTrY8+H+L0|wR1KMeKr>#k?}SF z3Nh-wh~1!3 zdI1&>Kpqe$mz-`X3dE(0o8d0pH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JVk+n^WvF`5|c4}sBD<`*$ZN$BN+wP zIYB)Ga!IWdJNC1>&kU%LaL27dsk7hZ%t6uRq;b^B=1o;GR%H3hP)SqK1+GaR#Q>58 zY5U920Xu|6#a&a_MYC56>7f^SPPn)1!bE;M?WwZ8Y}5s6ooI{4E?{9I>^CcRooJXV z4dRUE&5aL0|5mMUA^q53k)Bw{kR)$tu-9;$^Y2^*Ly&f`oA{?d>}jj z=b#dXt@o3_js`@5L28ep)Sw6uU*l2C(Zqoz4=MmDH6PXEL200h-lI68M+37Q;sml9 zKdNQMl(5zZ6=?RT-VMnD@oZsWTNaqrFej2L3_2_Y%(8{yfCOQ`hdF`l_75TjOmRdD zIOYuNPNarajmRTe!%jw|sQ>M)1^`(9|0*A^@HdZ8Z8z+Px$t2jqm;ljuLlzotZS5v z`mww3p{HXQ0|1cx%P+$F5dDtf^rQ!nIPA?hKJ`D9!D1u;py=VAi2Vg3{rFF$q>lu! zstNr6lnWCO56eh-oPlo=74{WDit_&oG(R5(F4F!pz)JN`iX82srr!EMnHTsgDgx#{ zsZ9M(Hg)}B-1UL=Ec@3uTh2oeCKz@O?LX5}|C?U@@5gML{{Uo!o%WH!e5NRY`1P>m zRz_I;6d!Q6?Lp*ueE2NWl)$4-nEW&d*wYOwowfyjgv0P>_^JQ-6drcJ1Q0x& Date: Sat, 21 Jul 2018 05:07:25 -0700 Subject: [PATCH 052/205] Update forge and mappings --- build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 72e5c9b8..bfb242e5 100644 --- a/build.gradle +++ b/build.gradle @@ -18,8 +18,8 @@ buildscript { } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.0.9' - classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1' + classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.0.11' + classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2' } } @@ -69,9 +69,9 @@ if (secretFile.exists()) { } minecraft { - version = '1.12.2-14.23.1.2555' + version = '1.12.2-14.23.4.2705' runDir = 'run' - mappings = 'snapshot_20171231' + mappings = 'snapshot_20180716' // coreMod = '' makeObfSourceJar = false From acc40a405543f13be424fadaddff6a2672d2c8c4 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sat, 21 Jul 2018 05:08:55 -0700 Subject: [PATCH 053/205] Fix more stuff reported by sonarqube --- .../com/mcmoddev/orespawn/EventHandlers.java | 4 +- .../mcmoddev/orespawn/api/BiomeLocation.java | 2 +- .../mcmoddev/orespawn/api/IDimensionList.java | 2 +- .../api/exceptions/BadValueException.java | 7 +- .../api/exceptions/UnknownFieldException.java | 4 +- .../api/exceptions/UnknownNameException.java | 9 +- .../orespawn/api/os3/IBlockBuilder.java | 127 ++++++++++++++++++ .../orespawn/api/os3/IBlockDefinition.java | 2 +- .../orespawn/api/os3/IReplacementBuilder.java | 59 ++++++++ .../orespawn/api/os3/ISpawnEntry.java | 4 +- .../orespawn/commands/ClearChunkCommand.java | 2 +- .../orespawn/data/FeatureRegistry.java | 3 +- .../orespawn/data/PresetsStorage.java | 3 +- .../orespawn/data/ReplacementsRegistry.java | 14 +- .../impl/features/PrecisionGenerator.java | 4 +- .../orespawn/impl/os3/BiomeBuilder.java | 11 +- .../orespawn/impl/os3/BlockBuilder.java | 8 ++ .../mcmoddev/orespawn/impl/os3/BlockList.java | 2 +- .../orespawn/impl/os3/DimensionBuilder.java | 7 +- .../orespawn/impl/os3/DimensionList.java | 12 +- .../impl/os3/DimensionListAcceptAll.java | 1 - .../impl/os3/DimensionListDenyAll.java | 1 - .../orespawn/impl/os3/FeatureBuilder.java | 2 +- .../orespawn/impl/os3/FeatureEntry.java | 2 +- .../orespawn/impl/os3/OS3APIImpl.java | 12 +- .../orespawn/impl/os3/ReplacementBuilder.java | 8 ++ .../orespawn/impl/os3/SpawnBuilder.java | 17 ++- .../orespawn/json/OreSpawnReader.java | 3 +- .../orespawn/json/OreSpawnWriter.java | 6 +- 29 files changed, 278 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 7ff4bad0..4ab4610c 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -7,7 +7,6 @@ import java.util.Map; import java.util.Random; import java.util.TreeMap; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.stream.Collectors; @@ -15,7 +14,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.MapDifference; import com.google.common.collect.Maps; -import com.google.common.collect.Queues; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; @@ -41,7 +39,7 @@ public class EventHandlers { private Deque retroChunks; private Deque>> chunks; -// private Map> chunks; +// private Map> chunks EventHandlers() { retroChunks = new ConcurrentLinkedDeque<>(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index 22ea69c2..f3c6eea4 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -12,6 +12,6 @@ public interface BiomeLocation { public JsonElement serialize(); default ImmutableList getBiomes() { - return ForgeRegistries.BIOMES.getValues().stream().filter(this::matches).collect(Collectors2.toImmutableList()); + return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches).collect(Collectors2.toImmutableList()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index 29e2c2bb..4a9dca32 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -4,7 +4,7 @@ public interface IDimensionList { public JsonObject serialize(); - default public boolean matches(final int dimensionId) { + public default boolean matches(final int dimensionId) { return false; } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index 8a78c6ba..8e3653a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -2,8 +2,8 @@ public class BadValueException extends Exception { private static final long serialVersionUID = 1143938140559149506L; - private String keyName; - private String keyValue; + private final String keyName; + private final String keyValue; public BadValueException(String keyName, String keyValue) { super(); @@ -14,7 +14,6 @@ public BadValueException(String keyName, String keyValue) { @Override public String getMessage() { String baseMessage = super.getMessage(); - String fullMessage = String.format("Unknown value %s for key %s\n%s", this.keyValue, this.keyName, baseMessage); - return fullMessage; + return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index dd928a58..417ff05f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -2,7 +2,7 @@ public class UnknownFieldException extends Exception { private static final long serialVersionUID = 1L; - private String message; + private final String message; public UnknownFieldException(String theField) { super(); @@ -12,6 +12,6 @@ public UnknownFieldException(String theField) { @Override public String getMessage() { String baseMessage = super.getMessage(); - return String.format("%s\n%s", this.message, baseMessage); + return String.format("%s%n%s", this.message, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 623d3e39..829497b7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -2,9 +2,9 @@ public class UnknownNameException extends Exception { private static final long serialVersionUID = -3426121906665390773L; - private String fieldName; - private String fieldValue; - + private final String fieldName; + private final String fieldValue; + public UnknownNameException(String fieldName, String fieldValue) { super(); this.fieldName = fieldName; @@ -14,7 +14,6 @@ public UnknownNameException(String fieldName, String fieldValue) { @Override public String getMessage() { String baseMessage = super.getMessage(); - String fullMessage = String.format("Unknown %s name %s\n%s", this.fieldName, this.fieldValue, baseMessage); - return fullMessage; + return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 44867603..fce04f75 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -5,26 +5,153 @@ import net.minecraft.util.ResourceLocation; public interface IBlockBuilder { + + /** + * + * @param blockState + * @return + */ public IBlockBuilder setFromBlockState(final IBlockState blockState); + + /** + * + * @param block + * @return + */ public IBlockBuilder setFromBlock(final Block block); + + /** + * + * @param blockName + * @return + */ public IBlockBuilder setFromName(final String blockName); + + /** + * + * @param blockName + * @param state + * @return + */ public IBlockBuilder setFromName(final String blockName, final String state); + + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ @Deprecated public IBlockBuilder setFromName(final String blockName, final int metadata); + + /** + * + * @param blockResourceLocation + * @return + */ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation); + + /** + * + * @param blockResourceLocation + * @param state + * @return + */ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final String state); + + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ @Deprecated public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final int metadata); + + /** + * + * @param blockState + * @param chance + * @return + */ public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance); + + /** + * + * @param block + * @param chance + * @return + */ public IBlockBuilder setFromBlockWithChance(final Block block, final int chance); + + /** + * + * @param blockName + * @param chance + * @return + */ public IBlockBuilder setFromNameWithChance(final String blockName, final int chance); + + /** + * + * @param blockName + * @param state + * @param chance + * @return + */ public IBlockBuilder setFromNameWithChance(final String blockName, final String state, final int chance); + + /** + * + * @param blockName + * @param metadata + * @param chance + * @return + * @deprecated + */ @Deprecated public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, final int chance); + + /** + * + * @param blockResourceLocation + * @param chance + * @return + */ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int chance); + + /** + * + * @param blockResourceLocation + * @param state + * @param chance + * @return + */ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final String state, final int chance); + + /** + * + * @param blockResourceLocation + * @param metadata + * @param chance + * @return + * @deprecated + */ @Deprecated public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, final int chance); + + /** + * + * @param chance + * @return + */ public IBlockBuilder setChance(int chance); + + /** + * + * @return + */ public IBlockDefinition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index f1a9c010..a35f6198 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -5,7 +5,7 @@ public interface IBlockDefinition { public IBlockState getBlock(); public int getChance(); - default public boolean isValid() { + public default boolean isValid() { return true; } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index 4475b03d..baec108d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -4,15 +4,74 @@ import net.minecraft.util.ResourceLocation; public interface IReplacementBuilder { + + /** + * + * @param entryName + * @return + */ public IReplacementBuilder setFromName(final String entryName); + + /** + * + * @param name + * @return + */ public IReplacementBuilder setName(final String name); + + /** + * + * @param blockState + * @return + */ public IReplacementBuilder addEntry(final IBlockState blockState); + + /** + * + * @param blockName + * @return + */ public IReplacementBuilder addEntry(final String blockName); + + /** + * + * @param blockName + * @param state + * @return + */ public IReplacementBuilder addEntry(final String blockName, final String state); + + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ @Deprecated public IReplacementBuilder addEntry(final String blockName, final int metadata); + /** + * + * @param blockResourceLocation + * @return + */ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation); + + /** + * + * @param blockResourceLocation + * @param state + * @return + */ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state); + + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ @Deprecated public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata); public boolean hasEntries(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 229c435d..9a694a11 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -14,11 +14,11 @@ import com.mcmoddev.orespawn.api.IDimensionList; public interface ISpawnEntry { - default public boolean isEnabled() { + public default boolean isEnabled() { return false; } - default public boolean isRetrogen() { + public default boolean isRetrogen() { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 8808cc90..a0f22e3f 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -50,7 +50,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } EntityPlayer player = (EntityPlayer) sender; - Chunk chunk = player.getEntityWorld().getChunkFromBlockCoords(player.getPosition()); + Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); ChunkPos chunkPos = chunk.getPos(); List blocks; diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 13660f3b..34a2182e 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -35,6 +35,7 @@ public class FeatureRegistry { .create(); public FeatureRegistry() { + // } public Map getFeatures() { @@ -138,7 +139,7 @@ public void writeFeatures(File file) { registry.getEntries().stream() .map( ent -> { JsonObject e = new JsonObject(); - e.addProperty("name", ent.getKey().getResourcePath()); + e.addProperty("name", ent.getKey().getPath()); e.addProperty("class", ent.getValue().getClass().getName()); return e; }) diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index 882ab404..316e63bf 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -85,8 +85,7 @@ public JsonElement get(String asString) { if(m.matches()) { return this.getSymbolSection(m.group(1), m.group(2)); } - JsonPrimitive pm = new JsonPrimitive("Unknown Variable "+asString); - return pm; + return new JsonPrimitive("Unknown Variable "+asString); } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 38729b38..9207ee0a 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -50,16 +50,24 @@ public class ReplacementsRegistry { .create(); public ReplacementsRegistry() { + // } public Map getReplacements() { return ImmutableMap.copyOf(registry.getEntries()); } + + /** + * + * @param dimension + * @return + * @deprecated + */ @Deprecated public List getDimensionDefault(int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; List mineralogyOres = OreDictionary.getOres("cobblestone").stream() - .filter( iS -> iS.getItem().getRegistryName().getResourceDomain().equals("mineralogy")) + .filter( iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) .map( iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) .collect(Collectors.toList()); List baseRv = new ArrayList<>(); @@ -186,7 +194,7 @@ public void saveFile(String modName) { JsonObject outs = new JsonObject(); registry.getEntries().stream() - .filter(ent -> ent.getKey().getResourceDomain().equals(modName)) + .filter(ent -> ent.getKey().getNamespace().equals(modName)) .forEach(ent -> { JsonArray entry = new JsonArray(); IReplacementEntry workVal = ent.getValue(); @@ -208,7 +216,7 @@ public void saveFile(String modName) { w.write(ov); } catch (IOException e) { CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed writing replacements file %s", p.toAbsolutePath().toString())); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 87ed15c4..53d78a55 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -5,7 +5,6 @@ import java.util.Random; import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; @@ -154,8 +153,7 @@ private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightR zmod = rescaleOffset(zmod, spot.getZ(), zMin, zMax); } - BlockPos rVal = spot.add(xmod, ymod, zmod); - return rVal; + return spot.add(xmod, ymod, zmod); } private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, final int maximumIn) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 3e5b5f34..a4cde9da 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -25,7 +25,7 @@ public class BiomeBuilder implements IBiomeBuilder { private boolean acceptAll = false; public BiomeBuilder() { - + // } @Override @@ -74,8 +74,8 @@ public BiomeLocation create() { BiomeLocation whitelistI; BiomeLocation blacklistI; - if (this.whitelist.size() == 0) { - if(this.blacklist.size() > 0) { + if (this.whitelist.isEmpty()) { + if(!this.blacklist.isEmpty()) { whitelistI = new BiomeLocationAcceptAny(); } else { whitelistI = new BiomeLocationEmpty(); @@ -88,7 +88,7 @@ public BiomeLocation create() { .collect(Collectors.toList())) ); } - if (this.blacklist.size() == 0) { + if (this.blacklist.isEmpty()) { blacklistI = new BiomeLocationEmpty(); } else { blacklistI = new BiomeLocationList( @@ -99,8 +99,7 @@ public BiomeLocation create() { } - BiomeLocation res = new BiomeLocationComposition(whitelistI, blacklistI); - return res; + return new BiomeLocationComposition(whitelistI, blacklistI); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index e3de4267..d6992dc6 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -68,6 +68,10 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); } + /** + * + * @deprecated + */ @Override @Deprecated public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata) { @@ -130,6 +134,10 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); } + /** + * + * @deprecated + */ @Override @Deprecated public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, int chance) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 09d45fb4..56f22805 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -26,7 +26,7 @@ public void addBlock(IBlockDefinition block) { @Override public IBlockState getRandomBlock(Random rand) { - if (this.workingList.size() == 0) { + if (this.workingList.isEmpty()) { this.startNewSpawn(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index b64bfe1b..70835319 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -12,7 +12,8 @@ public class DimensionBuilder implements IDimensionBuilder { private boolean denyAll = false; private boolean acceptAllOverworld = true; - public DimensionBuilder() { + public DimensionBuilder() { + // } @Override @@ -46,8 +47,8 @@ public IDimensionBuilder setDenyAll() { @Override public IDimensionList create() { if (this.acceptAll || - ((this.dimensionWhitelist.size() == 0) && - (this.dimensionBlacklist.size() == 0)) && + ((this.dimensionWhitelist.isEmpty()) && + (this.dimensionBlacklist.isEmpty())) && !(this.acceptAllOverworld)) { return new DimensionListAcceptAll(); } else if (this.denyAll) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index ff46deb4..ecbe3673 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -21,9 +21,9 @@ public DimensionList(List whitelist, List blacklist) { public boolean matches(final int dimensionID) { if (this.whitelist.contains(Integer.valueOf(dimensionID))) return true; if (this.blacklist.contains(Integer.valueOf(dimensionID))) return false; - if (this.whitelist.size() > 0) return false; - if (this.blacklist.size() > 0) return true; - + if (!this.whitelist.isEmpty()) return false; + if (!this.blacklist.isEmpty()) return true; + // if it gets here, the whitelist and blacklist are empty... // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... return true; @@ -32,19 +32,19 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { JsonObject rv = new JsonObject(); - if(this.whitelist.size() > 0) { + if(!this.whitelist.isEmpty()) { JsonArray wl = new JsonArray(); whitelist.stream() .forEach(i -> wl.add(i.intValue())); rv.add(Constants.ConfigNames.WHITELIST, wl); } - if(this.blacklist.size() > 0) { + if(!this.blacklist.isEmpty()) { JsonArray bl = new JsonArray(); blacklist.stream() .forEach(i -> bl.add(i.intValue())); rv.add(Constants.ConfigNames.WHITELIST, bl); - } else if(this.whitelist.size() == 0) { + } else if(this.whitelist.isEmpty()) { return new DimensionListAcceptAllOverworld().serialize(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index ceb63df6..952396a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -7,7 +7,6 @@ public class DimensionListAcceptAll implements IDimensionList { @Override - @SuppressWarnings("unused") public boolean matches(final int dimensionID) { return true; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index 876c24dc..3ed55af1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -7,7 +7,6 @@ public class DimensionListDenyAll implements IDimensionList { @Override - @SuppressWarnings("unused") public boolean matches(final int dimensionID) { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 5770b175..61002766 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -31,7 +31,7 @@ public IFeatureBuilder setFeature(String featureName) { @Override public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { if (!OreSpawn.API.featureExists(featureResourceLocation)) { - OreSpawn.LOGGER.warn("Feature %s is not known, feature for this will be set to the default feature", featureResourceLocation.getResourcePath()); + OreSpawn.LOGGER.warn("Feature %s is not known, feature for this will be set to the default feature", featureResourceLocation.getPath()); } return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 9cc0a90d..8f5371dd 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -20,7 +20,7 @@ public IFeature getFeature() { @Override public String getFeatureName() { - return this.feature.getRegistryName().getResourcePath(); + return this.feature.getRegistryName().getPath(); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 3dd7b622..f6d1fd94 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -58,9 +58,11 @@ public class OS3APIImpl implements OS3API { } public OS3APIImpl() { + // } public void loadConfigFiles() { + final String failedReadingConfigsFrom = "Failed reading configs from "; PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:**/features-*.json"); PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:**/replacements-*.json"); PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); @@ -70,7 +72,7 @@ public void loadConfigFiles() { .map(Path::toFile) .forEach(features::loadFeaturesFile); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString()); + CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -80,7 +82,7 @@ public void loadConfigFiles() { stream.filter(replacementsFiles::matches) .forEach(replacements::loadFile); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.SYSCONF.toString()); + CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -102,7 +104,7 @@ public void loadConfigFiles() { } }); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading configs from " + Constants.CONFDIR.toString()); + CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.CONFDIR.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -159,7 +161,7 @@ public IReplacementBuilder getReplacementBuilder() { public Map getReplacements() { Map temp = new HashMap<>(); replacements.getReplacements().entrySet().stream() - .forEach(e -> temp.put(e.getKey().getResourcePath(), e.getValue())); + .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); return ImmutableMap.copyOf(temp); } @@ -184,7 +186,7 @@ public ISpawnEntry getSpawn(String spawnName) { @Override public Map getAllSpawns() { Map sp = new HashMap<>(); - spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getResourcePath(), ent.getValue())); + spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); return ImmutableMap.copyOf(sp); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 5099aa5f..20ecd585 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -51,6 +51,10 @@ public IReplacementBuilder addEntry(String blockName, String state) { return this.addEntry(new ResourceLocation(blockName), state); } + /** + * + * @deprecated + */ @Override @Deprecated public IReplacementBuilder addEntry(String blockName, int metadata) { @@ -67,6 +71,10 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, Stri return this.addEntry(StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); } + /** + * + * @deprecated + */ @Override @Deprecated public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 24b4b677..1de3f661 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -1,6 +1,5 @@ package com.mcmoddev.orespawn.impl.os3; -import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; @@ -88,6 +87,10 @@ public ISpawnBuilder addBlock(String blockName, String blockState) { return this.addBlock(new ResourceLocation(blockName), blockState); } + /** + * + * @deprecated + */ @Override @Deprecated public ISpawnBuilder addBlock(String blockName, int blockMetadata) { @@ -105,6 +108,10 @@ public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, return this.addBlockWithChance(blockResourceLocation, blockState, 100); } + /** + * + * @deprecated + */ @Override @Deprecated public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, @@ -133,6 +140,10 @@ public ISpawnBuilder addBlockWithChance(String blockName, String blockState, return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); } + /** + * + * @deprecated + */ @Override @Deprecated public ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, @@ -155,6 +166,10 @@ public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, return this.addBlockWithChance(tempVar, chance); } + /** + * + * @deprecated + */ @Override @Deprecated public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 43aba48a..87966dc4 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -27,7 +27,6 @@ import com.mcmoddev.orespawn.api.exceptions.UnknownVersionException; import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; import com.mcmoddev.orespawn.api.os3.IBlockBuilder; -import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; import com.mcmoddev.orespawn.api.os3.IFeatureBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; @@ -148,7 +147,7 @@ private static JsonElement doPresetForObject(JsonObject value, PresetsStorage co } public static void loadFromJson(String name, JsonElement json) { - Entry t = new AbstractMap.SimpleEntry(name, json); + Entry t = new AbstractMap.SimpleEntry<>(name, json); try { loadSingleEntry(t); } catch (UnknownFieldException | BadValueException | UnknownNameException e) { diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index de11c48a..7cb76d05 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -26,9 +26,9 @@ public static void saveConfigs() { Map> configs = OreSpawn.API.getSpawnsByFile(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); configs.entrySet().stream() - .forEach( ent -> { - saveSingle(ent.getKey(), gson); - }); + .forEach( ent -> + saveSingle(ent.getKey(), gson) + ); } private static void saveSingle(Path filePath, Gson gson) { From 30e6ed1fe251ed35bb9ee4ff3e2031f519fe31b7 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sat, 21 Jul 2018 05:15:19 -0700 Subject: [PATCH 054/205] Format source --- .../com/mcmoddev/orespawn/EventHandlers.java | 144 +++---- .../java/com/mcmoddev/orespawn/OreSpawn.java | 43 +- .../mcmoddev/orespawn/api/BiomeLocation.java | 9 +- .../mcmoddev/orespawn/api/FeatureBase.java | 117 +++--- .../com/mcmoddev/orespawn/api/IBlockList.java | 5 + .../mcmoddev/orespawn/api/IDimensionList.java | 2 + .../com/mcmoddev/orespawn/api/IFeature.java | 5 +- .../api/exceptions/BadValueException.java | 8 +- .../api/exceptions/UnknownFieldException.java | 3 +- .../api/exceptions/UnknownNameException.java | 6 +- .../orespawn/api/os3/IBiomeBuilder.java | 8 + .../orespawn/api/os3/IBlockBuilder.java | 24 +- .../orespawn/api/os3/IBlockDefinition.java | 3 + .../orespawn/api/os3/IDimensionBuilder.java | 6 + .../orespawn/api/os3/IFeatureBuilder.java | 13 +- .../orespawn/api/os3/IFeatureEntry.java | 8 + .../orespawn/api/os3/IReplacementBuilder.java | 9 +- .../orespawn/api/os3/IReplacementEntry.java | 2 + .../orespawn/api/os3/ISpawnBuilder.java | 46 ++- .../orespawn/api/os3/ISpawnEntry.java | 27 +- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 29 +- .../api/os3/OreSpawnBlockMatcher.java | 22 +- .../orespawn/api/plugin/IOreSpawnPlugin.java | 1 + .../orespawn/api/plugin/OreSpawnPlugin.java | 3 +- .../orespawn/api/plugin/PluginLoader.java | 48 ++- .../orespawn/commands/AddOreCommand.java | 47 ++- .../orespawn/commands/ClearChunkCommand.java | 63 +-- .../orespawn/commands/DumpBiomesCommand.java | 21 +- .../commands/WriteConfigsCommand.java | 6 +- .../com/mcmoddev/orespawn/data/Config.java | 40 +- .../com/mcmoddev/orespawn/data/Constants.java | 40 +- .../orespawn/data/FeatureRegistry.java | 42 +- .../orespawn/data/PresetsStorage.java | 39 +- .../orespawn/data/ReplacementsRegistry.java | 150 +++---- .../mcmoddev/orespawn/data/VanillaOres.java | 3 +- .../impl/features/ClusterGenerator.java | 50 +-- .../features/DefaultFeatureGenerator.java | 22 +- .../impl/features/NormalCloudGenerator.java | 37 +- .../impl/features/PrecisionGenerator.java | 61 +-- .../orespawn/impl/features/VeinGenerator.java | 240 ++++++----- .../location/BiomeLocationComposition.java | 19 +- .../location/BiomeLocationDictionary.java | 5 +- .../impl/location/BiomeLocationEmpty.java | 2 +- .../impl/location/BiomeLocationList.java | 16 +- .../impl/location/BiomeLocationSingle.java | 5 +- .../orespawn/impl/os3/BiomeBuilder.java | 27 +- .../orespawn/impl/os3/BlockBuilder.java | 17 +- .../orespawn/impl/os3/BlockDefinition.java | 5 +- .../mcmoddev/orespawn/impl/os3/BlockList.java | 20 +- .../orespawn/impl/os3/DimensionBuilder.java | 21 +- .../orespawn/impl/os3/DimensionList.java | 36 +- .../impl/os3/DimensionListAcceptAll.java | 1 + .../os3/DimensionListAcceptAllOverworld.java | 1 + .../impl/os3/DimensionListDenyAll.java | 3 +- .../orespawn/impl/os3/FeatureBuilder.java | 30 +- .../orespawn/impl/os3/FeatureEntry.java | 8 +- .../orespawn/impl/os3/OS3APIImpl.java | 89 +++-- .../orespawn/impl/os3/ReplacementBuilder.java | 25 +- .../orespawn/impl/os3/ReplacementEntry.java | 11 +- .../orespawn/impl/os3/SpawnBuilder.java | 40 +- .../orespawn/impl/os3/SpawnEntry.java | 16 +- .../orespawn/json/OreSpawnReader.java | 378 ++++++++++-------- .../orespawn/json/OreSpawnWriter.java | 29 +- .../mcmoddev/orespawn/util/Collectors2.java | 18 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 12 +- .../orespawn/worldgen/FlatBedrock.java | 16 +- .../orespawn/worldgen/OreSpawnWorldGen.java | 23 +- 67 files changed, 1323 insertions(+), 1002 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 4ab4610c..6b5da915 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -23,36 +23,39 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.gen.ChunkProviderServer; +import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.event.terraingen.OreGenEvent; import net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType; import net.minecraftforge.event.world.ChunkDataEvent; +import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent; import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; -import net.minecraftforge.fml.common.eventhandler.Event; -import net.minecraftforge.fml.common.eventhandler.EventPriority; public class EventHandlers { + private Deque retroChunks; private Deque>> chunks; -// private Map> chunks + // private Map> chunks EventHandlers() { retroChunks = new ConcurrentLinkedDeque<>(); chunks = new ConcurrentLinkedDeque<>(); } - private List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, - EventType.EMERALD, EventType.GOLD, EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, EventType.REDSTONE, - EventType.QUARTZ, EventType.SILVERFISH); + private List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, + EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, + EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, + EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) public void onGenerateMinable(OreGenEvent.GenerateMinable event) { - if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) && vanillaEvents.contains(event.getType())) { + if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + && vanillaEvents.contains(event.getType())) { event.setResult(Event.Result.DENY); } } @@ -61,28 +64,30 @@ public void onGenerateMinable(OreGenEvent.GenerateMinable event) { public void onChunkSave(ChunkDataEvent.Save ev) { NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); NBTTagCompound features = new NBTTagCompound(); - - // save a list of the spawns that were configured and available - in this dimension - when the chunk + + // save a list of the spawns that were configured and available - in this dimension - when + // the chunk // was first generated. - + // collect that data int thisDimension = ev.getWorld().provider.getDimension(); - BlockPos thisPos = new BlockPos( ev.getChunk().x+8, 128, ev.getChunk().z+8 ); + BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); - + OreSpawn.API.getAllSpawns().entrySet().stream() - .filter( ent -> ent.getValue().dimensionAllowed(thisDimension) ) - .filter( ent -> ent.getValue().biomeAllowed(thisBiome) ) - .forEach( ent -> features.setString(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); + .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) + .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features + .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); dataTag.setTag(Constants.FEATURES_TAG, features); - + ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); } private boolean dequeContains(ChunkPos cc) { - return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()).contains(true); + return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) + .contains(true); } - + @SubscribeEvent public void onChunkLoad(ChunkDataEvent.Load ev) { World world = ev.getWorld(); @@ -97,56 +102,55 @@ public void onChunkLoad(ChunkDataEvent.Load ev) { if (Config.getBoolean(Constants.RETROGEN_KEY)) { NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); int thisDimension = world.provider.getDimension(); - BlockPos thisPos = new BlockPos( ev.getChunk().x+8, 128, ev.getChunk().z+8 ); + BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); Biome thisBiome = ev.getChunk().getBiome(thisPos, world.getBiomeProvider()); - if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.addLast(new Tuple<>(chunkCoords, getDifferingTags(chunkTag, thisDimension, thisBiome))); + if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) + || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { + chunks.addLast(new Tuple<>(chunkCoords, + getDifferingTags(chunkTag, thisDimension, thisBiome))); } } } private List getDifferingTags(NBTTagCompound chunkTag, int dim, Biome biome) { NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - Map currentBits = new TreeMap<>(); - Map oldBits = new TreeMap<>(); - + Map currentBits = new TreeMap<>(); + Map oldBits = new TreeMap<>(); + OreSpawn.API.getAllSpawns().entrySet().stream() - .filter( ent -> ent.getValue().dimensionAllowed(dim) ) - .filter( ent -> ent.getValue().biomeAllowed(biome) ) - .forEach( ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); - - tagList.getKeySet().stream() - .forEach( tag -> oldBits.put(tag, tagList.getString(tag))); - - MapDifference diff = Maps.difference(oldBits, currentBits); - + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + MapDifference diff = Maps.difference(oldBits, currentBits); + List stuff = Lists.newLinkedList(); - stuff.addAll(diff.entriesDiffering().entrySet() - .stream().map(ent -> ent.getKey()).collect(Collectors.toList())); - stuff.addAll(diff.entriesOnlyOnRight().entrySet() - .stream().map(ent -> ent.getKey()).collect(Collectors.toList())); + stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); + stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); return ImmutableList.copyOf(stuff); } private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim, Biome biome) { NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - Map currentBits = new TreeMap<>(); - Map oldBits = new TreeMap<>(); - + Map currentBits = new TreeMap<>(); + Map oldBits = new TreeMap<>(); + OreSpawn.API.getAllSpawns().entrySet().stream() - .filter( ent -> ent.getValue().dimensionAllowed(dim) ) - .filter( ent -> ent.getValue().biomeAllowed(biome) ) - .forEach( ent -> currentBits.put(ent.getKey(), ent.getValue().getFeature().getFeatureName()) ); - - tagList.getKeySet().stream() - .forEach( tag -> oldBits.put(tag, tagList.getString(tag))); - - MapDifference diff = Maps.difference(oldBits, currentBits); - - return diff.entriesDiffering().size() == 0 && - diff.entriesOnlyOnLeft().size() == 0 && - diff.entriesOnlyOnRight().size() == 0; + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + MapDifference diff = Maps.difference(oldBits, currentBits); + + return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 + && diff.entriesOnlyOnRight().size() == 0; } private void doBedrockRetrogen(ChunkPos chunkCoords) { @@ -163,52 +167,54 @@ private void doBedrockRetrogen(ChunkPos chunkCoords) { private static ChunkProviderServer chunkProvider; private static IChunkGenerator chunkGenerator; private static Random random; - + private static void setupData(World nw) { if (world == null || !world.equals(nw)) { world = nw; } - + if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); } if (chunkGenerator == null) { - chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator"); + chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, + chunkProvider, "field_186029_c", "chunkGenerator"); } - + if (random == null) { random = new Random(world.getSeed()); } - + } - + private void runBits(Tuple> tup) { ChunkPos p = tup.getFirst(); List spawns = tup.getSecond(); - + // re-seed with something totally new :P - random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); - spawns.stream().forEach( s -> OreSpawn.API.getSpawn(s).generate(random, world, chunkGenerator, chunkProvider, p) ); + random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) + ^ world.getSeed()); + spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, + chunkGenerator, chunkProvider, p)); } - + @SubscribeEvent public void worldTick(WorldTickEvent ev) { setupData(ev.world); - + if (ev.side != Side.SERVER) { return; } - if (ev.phase == Phase.END) { - Deque>> b = new LinkedList<>(); + Deque>> b = new LinkedList<>(); for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { b.push(chunks.pop()); } - + b.forEach(this::runBits); - + for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { ChunkPos p = retroChunks.pop(); OreSpawn.flatBedrock.retrogen(world, p.x, p.z); diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 40540ed3..1039363a 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -1,19 +1,5 @@ package com.mcmoddev.orespawn; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.FeatureRegistry; -import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; -import com.mcmoddev.orespawn.commands.AddOreCommand; -import com.mcmoddev.orespawn.commands.ClearChunkCommand; -import com.mcmoddev.orespawn.commands.WriteConfigsCommand; -import com.mcmoddev.orespawn.commands.DumpBiomesCommand; -import com.mcmoddev.orespawn.data.Config; -import com.mcmoddev.orespawn.api.os3.OS3API; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; -import com.mcmoddev.orespawn.api.plugin.PluginLoader; -import com.mcmoddev.orespawn.worldgen.FlatBedrock; -import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; - import java.util.HashMap; import java.util.List; import java.util.Map; @@ -21,11 +7,25 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; +import com.mcmoddev.orespawn.api.os3.OS3API; +import com.mcmoddev.orespawn.api.plugin.PluginLoader; +import com.mcmoddev.orespawn.commands.AddOreCommand; +import com.mcmoddev.orespawn.commands.ClearChunkCommand; +import com.mcmoddev.orespawn.commands.DumpBiomesCommand; +import com.mcmoddev.orespawn.commands.WriteConfigsCommand; +import com.mcmoddev.orespawn.data.Config; +import com.mcmoddev.orespawn.data.Constants; +import com.mcmoddev.orespawn.data.FeatureRegistry; +import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; +import com.mcmoddev.orespawn.worldgen.FlatBedrock; +import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; + import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; -import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; +import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -38,13 +38,10 @@ * @author DShadowWolf <dshadowwolf@gmail.com> */ -@Mod(modid = Constants.MODID, - name = Constants.NAME, - version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,)", - certificateFingerprint = "@FINGERPRINT@") +@Mod(modid = Constants.MODID, name = Constants.NAME, version = Constants.VERSION, acceptedMinecraftVersions = "[1.12,)", certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { + @Instance public static OreSpawn instance; @@ -77,7 +74,9 @@ public void preInit(FMLPreInitializationEvent ev) { GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); - if (Config.getBoolean(Constants.RETROGEN_KEY) || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) || Config.getBoolean(Constants.RETRO_BEDROCK)) { + if (Config.getBoolean(Constants.RETROGEN_KEY) + || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + || Config.getBoolean(Constants.RETRO_BEDROCK)) { MinecraftForge.EVENT_BUS.register(eventHandlers); MinecraftForge.ORE_GEN_BUS.register(eventHandlers); } @@ -87,7 +86,7 @@ public void preInit(FMLPreInitializationEvent ev) { public void init(FMLInitializationEvent ev) { PluginLoader.INSTANCE.register(); - API.loadConfigFiles(); + API.loadConfigFiles(); } @EventHandler diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index f3c6eea4..2d5035d5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -3,15 +3,18 @@ import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; import com.mcmoddev.orespawn.util.Collectors2; + import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; public interface BiomeLocation { + boolean matches(Biome biome); - + public JsonElement serialize(); - + default ImmutableList getBiomes() { - return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches).collect(Collectors2.toImmutableList()); + return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) + .collect(Collectors2.toImmutableList()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 67814a8e..8814083f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -1,9 +1,18 @@ package com.mcmoddev.orespawn.api; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Random; + import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; + import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; @@ -12,14 +21,15 @@ import net.minecraft.world.biome.Biome; import net.minecraftforge.registries.IForgeRegistryEntry; -import java.util.*; -import java.util.Map.Entry; - public class FeatureBase extends IForgeRegistryEntry.Impl { + private static final int MAX_CACHE_SIZE = 2048; - /** overflow cache so that ores that spawn at edge of chunk can - * appear in the neighboring chunk without triggering a chunk-load */ - private static final Map> overflowCache = new HashMap<>(MAX_CACHE_SIZE); + /** + * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk + * without triggering a chunk-load + */ + private static final Map> overflowCache = new HashMap<>( + MAX_CACHE_SIZE); private static final Deque cacheOrder = new LinkedList<>(); protected Random random; @@ -30,35 +40,36 @@ public FeatureBase(Random rand) { public boolean isValidBlock(IBlockState oreBlock) { return oreBlock.getBlock() != Blocks.AIR; } - + protected void runCache(int chunkX, int chunkZ, World world, ISpawnEntry spawnData) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); - if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it + if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it for (Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), spawnData); + spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), + world.provider.getDimension(), spawnData); } } } - protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int dimension, boolean cacheOverflow, - ISpawnEntry spawnData) { + protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int dimension, + boolean cacheOverflow, ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return false; } - if(!isValidBlock(oreBlock)) { + if (!isValidBlock(oreBlock)) { return false; } - + Biome thisBiome = world.getBiome(coord); if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { return false; } - + BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { @@ -66,7 +77,8 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d return false; } - return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, spawnData); + return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, + spawnData); } private BlockPos mungeFixYcoord(BlockPos coord) { @@ -78,9 +90,10 @@ private BlockPos mungeFixYcoord(BlockPos coord) { } } - private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, IBlockState oreBlock, boolean cacheOverflow, int dimension, ISpawnEntry spawnData) { + private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, + IBlockState oreBlock, boolean cacheOverflow, int dimension, ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { - if(!isValidBlock(oreBlock)) { + if (!isValidBlock(oreBlock)) { return false; } @@ -102,7 +115,7 @@ private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher r } private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int dimension, - ISpawnEntry spawnData) { + ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return; @@ -157,30 +170,26 @@ protected void scramble(int[] target, Random prng) { } } - protected static final Vec3i[] offsets_small = { - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), - new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), + protected static final Vec3i[] offsets_small = { new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), + new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), - new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) - }; + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) }; - protected static final Vec3i[] offsets = { - new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), - new Vec3i(-1, 0, -1), new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), - new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), new Vec3i(1, 1, -1), + protected static final Vec3i[] offsets = { new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), + new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), + new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), new Vec3i(1, 1, -1), - new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), - new Vec3i(-1, 0, 0), new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), - new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), + new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), + new Vec3i(1, 1, 0), - new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), - new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), - new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) - }; + new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), + new Vec3i(1, 1, 1) }; - protected static final int[] offsetIndexRef = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26}; - protected static final int[] offsetIndexRef_small = {0, 1, 2, 3, 4, 5, 6, 7}; + protected static final int[] offsetIndexRef = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; + protected static final int[] offsetIndexRef_small = { 0, 1, 2, 3, 4, 5, 6, 7 }; protected static void mergeDefaults(JsonObject parameters, JsonObject defaultParameters) { defaultParameters.entrySet().forEach(entry -> { @@ -201,7 +210,8 @@ private double triangularDistribution(double a, double b, double c) { } protected int getPoint(int lowerBound, int upperBound, int median) { - int t = (int)Math.round(triangularDistribution((float)lowerBound, (float)upperBound, (float)median)); + int t = (int) Math.round( + triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); return t - median; } @@ -211,15 +221,16 @@ protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double rad int quantity = count; IBlockList possibleOres = spawnData.getBlocks(); OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for(int dy = (int)(-1 * radius); dy < radius; dy++){ - for(int dx = (int)(radius); dx >= (int)(-1 * radius); dx--){ - for(int dz = (int)(radius); dz >= (int)(-1 * radius); dz--){ - if((dx*dx + dy*dy + dz*dz) <= rSqr){ + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { + for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); quantity--; } - if(quantity <= 0) { + if (quantity <= 0) { return; } } @@ -227,29 +238,29 @@ protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double rad } } - protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, ISpawnEntry spawnData, int count) { Random prng = this.random; int quantity = count; IBlockList possibleOres = spawnData.getBlocks(); OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for(int dy = (int)(-1 * radius); dy < radius; dy++){ - for(int dz = (int)(-1 * radius); dz < radius; dz++){ - for(int dx = (int)(-1 * radius); dx < radius; dx++){ - if((dx*dx + dy*dy + dz*dz) <= rSqr){ + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dz = (int) (-1 * radius); dz < radius; dz++) { + for (int dx = (int) (-1 * radius); dx < radius; dx++) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world,blockPos.add(dx,dy,dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); quantity--; } - if(quantity <= 0) { + if (quantity <= 0) { return; } } } } } - + protected int getABC(int dx, int dy, int dz) { return (dx * dx + dy * dy + dz * dz); } @@ -263,6 +274,6 @@ protected boolean endCheck(boolean toPositive, int dx, double radius) { } protected int getStart(boolean toPositive, double radius) { - return ((int)(radius * (toPositive ? 1 : -1))); + return ((int) (radius * (toPositive ? 1 : -1))); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 6df82f20..699548f4 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -7,9 +7,14 @@ import net.minecraft.block.state.IBlockState; public interface IBlockList { + public void addBlock(IBlockDefinition block); + public IBlockState getRandomBlock(Random rand); + public void startNewSpawn(); + public void dump(); + public int count(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index 4a9dca32..680ba327 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -3,7 +3,9 @@ import com.google.gson.JsonObject; public interface IDimensionList { + public JsonObject serialize(); + public default boolean matches(final int dimensionId) { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java index 32458843..82f04a60 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java @@ -7,13 +7,14 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.registries.IForgeRegistryEntry; -import net.minecraft.world.chunk.IChunkProvider; public interface IFeature extends IForgeRegistryEntry { + void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawn, ChunkPos pos); + ISpawnEntry spawn, ChunkPos pos); void setRandom(Random rand); diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index 8e3653a7..b6df0ce8 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -1,19 +1,21 @@ package com.mcmoddev.orespawn.api.exceptions; public class BadValueException extends Exception { + private static final long serialVersionUID = 1143938140559149506L; private final String keyName; private final String keyValue; - + public BadValueException(String keyName, String keyValue) { super(); this.keyName = keyName; this.keyValue = keyValue; } - + @Override public String getMessage() { String baseMessage = super.getMessage(); - return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, baseMessage); + return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, + baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 417ff05f..021f0ade 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -1,6 +1,7 @@ package com.mcmoddev.orespawn.api.exceptions; public class UnknownFieldException extends Exception { + private static final long serialVersionUID = 1L; private final String message; @@ -8,7 +9,7 @@ public UnknownFieldException(String theField) { super(); this.message = String.format("Unkown field %s in config", theField); } - + @Override public String getMessage() { String baseMessage = super.getMessage(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 829497b7..41836b5b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -1,6 +1,7 @@ package com.mcmoddev.orespawn.api.exceptions; public class UnknownNameException extends Exception { + private static final long serialVersionUID = -3426121906665390773L; private final String fieldName; private final String fieldValue; @@ -10,10 +11,11 @@ public UnknownNameException(String fieldName, String fieldValue) { this.fieldName = fieldName; this.fieldValue = fieldValue; } - + @Override public String getMessage() { String baseMessage = super.getMessage(); - return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, baseMessage); + return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, + baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index 14d25fd7..f5f166ac 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -6,12 +6,20 @@ import net.minecraft.world.biome.Biome; public interface IBiomeBuilder { + public IBiomeBuilder addWhitelistEntry(final Biome biome); + public IBiomeBuilder addWhitelistEntry(final String biomeName); + public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation); + public IBiomeBuilder addBlacklistEntry(Biome biome); + public IBiomeBuilder addBlacklistEntry(final String biomeName); + public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); + public IBiomeBuilder setAcceptAll(); + public BiomeLocation create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index fce04f75..7712e3b5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -58,7 +58,8 @@ public interface IBlockBuilder { * @param state * @return */ - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final String state); + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final String state); /** * @@ -68,7 +69,8 @@ public interface IBlockBuilder { * @deprecated */ @Deprecated - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final int metadata); + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final int metadata); /** * @@ -76,7 +78,8 @@ public interface IBlockBuilder { * @param chance * @return */ - public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance); + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, + final int chance); /** * @@ -101,7 +104,8 @@ public interface IBlockBuilder { * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final String blockName, final String state, final int chance); + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, + final int chance); /** * @@ -112,7 +116,8 @@ public interface IBlockBuilder { * @deprecated */ @Deprecated - public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, final int chance); + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, + final int chance); /** * @@ -120,7 +125,8 @@ public interface IBlockBuilder { * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int chance); + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int chance); /** * @@ -129,7 +135,8 @@ public interface IBlockBuilder { * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final String state, final int chance); + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final String state, final int chance); /** * @@ -140,7 +147,8 @@ public interface IBlockBuilder { * @deprecated */ @Deprecated - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, final int chance); + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int metadata, final int chance); /** * diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index a35f6198..5d026876 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -3,8 +3,11 @@ import net.minecraft.block.state.IBlockState; public interface IBlockDefinition { + public IBlockState getBlock(); + public int getChance(); + public default boolean isValid() { return true; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java index c5114937..67566a36 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -3,10 +3,16 @@ import com.mcmoddev.orespawn.api.IDimensionList; public interface IDimensionBuilder { + public IDimensionBuilder addWhitelistEntry(final int dimensionID); + public IDimensionBuilder addBlacklistEntry(final int dimensionID); + public IDimensionBuilder setAcceptAll(); + public IDimensionBuilder setDenyAll(); + public IDimensionBuilder setAcceptAllOverworld(); + public IDimensionList create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index 1959160b..f59f6836 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -6,14 +6,25 @@ import net.minecraft.util.ResourceLocation; public interface IFeatureBuilder { + public IFeatureBuilder setFeature(final String featureName); + public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation); + public IFeatureBuilder setFeature(final IFeature feature); + public IFeatureBuilder setParameter(final String parameterName, final String parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final int parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final float parameterValue); + public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue); - public IFeatureBuilder setParameter(final String parameterName, final JsonElement parameterValue); + + public IFeatureBuilder setParameter(final String parameterName, + final JsonElement parameterValue); + public IFeatureBuilder setUseFeatureDefaults(); + public IFeatureEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java index 738cd926..be2ab909 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java @@ -1,13 +1,21 @@ package com.mcmoddev.orespawn.api.os3; + import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.IFeature; public interface IFeatureEntry { + public IFeature getFeature(); + public String getFeatureName(); + public JsonObject getFeatureParameters(); + public void setParameter(final String parameterName, final String parameterValue); + public void setParameter(final String parameterName, final int parameterValue); + public void setParameter(final String parameterName, final boolean parameterValue); + public void setParameter(final String parameterName, final float parameterValue); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index baec108d..e10626e2 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -50,6 +50,7 @@ public interface IReplacementBuilder { */ @Deprecated public IReplacementBuilder addEntry(final String blockName, final int metadata); + /** * * @param blockResourceLocation @@ -63,7 +64,8 @@ public interface IReplacementBuilder { * @param state * @return */ - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state); + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final String state); /** * @@ -73,7 +75,10 @@ public interface IReplacementBuilder { * @deprecated */ @Deprecated - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata); + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final int metadata); + public boolean hasEntries(); + public IReplacementEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index c8017225..cf79864a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -6,6 +6,8 @@ import net.minecraftforge.registries.IForgeRegistryEntry; public interface IReplacementEntry extends IForgeRegistryEntry { + public OreSpawnBlockMatcher getMatcher(); + public List getEntries(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 5d667627..07362966 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -8,29 +8,61 @@ import net.minecraft.util.ResourceLocation; public interface ISpawnBuilder { + public ISpawnBuilder setName(final String name); + public ISpawnBuilder setDimensions(final IDimensionList dimensions); + public ISpawnBuilder setBiomes(final BiomeLocation biomes); + public ISpawnBuilder setEnabled(final boolean enabled); + public ISpawnBuilder setRetrogen(final boolean retrogen); + public ISpawnBuilder setReplacement(final IReplacementEntry replacements); + public ISpawnBuilder setFeature(final IFeatureEntry feature); + public ISpawnBuilder addBlock(final String blockName); + public ISpawnBuilder addBlock(final String blockName, final String blockState); + public ISpawnBuilder addBlock(final String blockName, final int blockMetadata); + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation); - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState); - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata); + + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final String blockState); + + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final int blockMetadata); + public ISpawnBuilder addBlock(final Block block); + public ISpawnBuilder addBlock(final IBlockState block); + public ISpawnBuilder addBlockWithChance(final String blockName, final int chance); - public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance); - public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int blockMetadata, final int chance); + + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, + final int chance); + + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, + final int chance); + + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int chance); + + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final String blockState, final int chance); + + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int blockMetadata, final int chance); + public ISpawnBuilder addBlockWithChance(final Block block, final int chance); + public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance); + public ISpawnEntry create(); + public ISpawnBuilder addBlock(IBlockDefinition block); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 9a694a11..d5cafb30 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -1,5 +1,11 @@ package com.mcmoddev.orespawn.api.os3; +import java.util.Random; + +import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.api.IBlockList; +import com.mcmoddev.orespawn.api.IDimensionList; + import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; @@ -7,31 +13,34 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; -import java.util.Random; - -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.IBlockList; -import com.mcmoddev.orespawn.api.IDimensionList; - public interface ISpawnEntry { + public default boolean isEnabled() { return false; } - + public default boolean isRetrogen() { return false; } - + public String getSpawnName(); + public boolean dimensionAllowed(final int dimension); + public boolean biomeAllowed(final ResourceLocation biomeName); + public boolean biomeAllowed(final Biome biome); + public IFeatureEntry getFeature(); + public OreSpawnBlockMatcher getMatcher(); + public IBlockList getBlocks(); - public void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); + public void generate(Random random, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider, ChunkPos pos); public IDimensionList getDimensions(); + public BiomeLocation getBiomes(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index 3e125104..a01ebd5d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -11,33 +11,56 @@ import net.minecraft.util.ResourceLocation; public interface OS3API { + public void addSpawn(ISpawnEntry spawnEntry); + public void addFeature(String featureName, IFeature feature); + public void addReplacement(IReplacementEntry replacementEntry); public Map getReplacements(); + public IReplacementEntry getReplacement(String replacementName); + public List getSpawns(int dimensionID); + public ISpawnEntry getSpawn(String spawnName); + public Map getAllSpawns(); + public List getDimensionDefaultReplacements(int dimensionID); - + public ISpawnBuilder getSpawnBuilder(); + public IDimensionBuilder getDimensionBuilder(); + public IFeatureBuilder getFeatureBuilder(); + public IBlockBuilder getBlockBuilder(); + public IBiomeBuilder getBiomeBuilder(); + public IReplacementBuilder getReplacementBuilder(); + public boolean featureExists(String featureName); + public boolean featureExists(ResourceLocation featureName); + public IFeature getFeature(String featureName); + public IFeature getFeature(ResourceLocation featureName); + public PresetsStorage copyPresets(); - + public void loadConfigFiles(); + public boolean hasReplacement(ResourceLocation resourceLocation); + public boolean hasReplacement(String name); + public void mapEntryToFile(Path p, String entryName); + public List getSpawnsForFile(String fileName); - public Map> getSpawnsByFile(); + + public Map> getSpawnsByFile(); } \ No newline at end of file diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index 23639061..7d9d0721 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -14,39 +14,39 @@ import net.minecraft.init.Blocks; public class OreSpawnBlockMatcher implements Predicate { + private final List possibles; - - public OreSpawnBlockMatcher(final IBlockState...matches) { + + public OreSpawnBlockMatcher(final IBlockState... matches) { this.possibles = Arrays.asList(matches); } - + public OreSpawnBlockMatcher(final List matches) { this.possibles = new ArrayList<>(); this.possibles.addAll(matches); } - + private boolean has(final IBlockState bs) { return this.possibles.stream().filter(bs::equals).count() > 0; } - + public boolean test(final IBlockState other) { return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); } - + public JsonArray serialize() { JsonArray rv = new JsonArray(); - - possibles.stream() - .forEach(bs -> { + + possibles.stream().forEach(bs -> { JsonObject t = new JsonObject(); t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); - if(!bs.equals(bs.getBlock().getDefaultState())) { + if (!bs.equals(bs.getBlock().getDefaultState())) { String state = StateUtil.serializeState(bs); t.addProperty(Constants.ConfigNames.STATE, state); } rv.add(t); }); - + return rv; } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java index 361e1e60..d3b0bf7c 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java @@ -3,5 +3,6 @@ import com.mcmoddev.orespawn.api.os3.OS3API; public interface IOreSpawnPlugin { + void register(OS3API apiInterface); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java index 6aeeb34c..7120c8be 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java @@ -9,6 +9,7 @@ @Retention(RUNTIME) @Target(TYPE) public @interface OreSpawnPlugin { + // the Mod this is for - will be used for // generating the name of the json the config // will get saved to and should also be the @@ -19,5 +20,5 @@ // resource location segment to look in // for registered config files -String resourcePath() default "orespawn"; + String resourcePath() default "orespawn"; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index ff9799ab..ce900c18 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -16,14 +16,13 @@ import java.util.List; import java.util.stream.Stream; +import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; -import org.apache.commons.io.FileUtils; -import com.mcmoddev.orespawn.api.plugin.IOreSpawnPlugin; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.OreSpawn; import net.minecraft.crash.CrashReport; import net.minecraft.util.ResourceLocation; @@ -35,6 +34,7 @@ public enum PluginLoader { INSTANCE; private class PluginData { + public final String modId; public final String resourcePath; public final IOreSpawnPlugin plugin; @@ -57,7 +57,8 @@ private String getAnnotationItem(String item, final ASMData asmData) { } public void load(FMLPreInitializationEvent event) { - for (final ASMData asmDataItem : event.getAsmData().getAll(OreSpawnPlugin.class.getCanonicalName())) { + for (final ASMData asmDataItem : event.getAsmData() + .getAll(OreSpawnPlugin.class.getCanonicalName())) { final String modId = getAnnotationItem("modid", asmDataItem); final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); final String clazz = asmDataItem.getClassName(); @@ -74,7 +75,10 @@ public void load(FMLPreInitializationEvent event) { } public void register() { - dataStore.forEach(pd -> { scanResources(pd); pd.plugin.register(OreSpawn.API); }); + dataStore.forEach(pd -> { + scanResources(pd); + pd.plugin.register(OreSpawn.API); + }); } public void scanResources(PluginData pd) { @@ -85,27 +89,31 @@ public void scanResources(PluginData pd) { String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); URL resURL = getClass().getClassLoader().getResource(base); - if(resURL == null) { - OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", base); + if (resURL == null) { + OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", + base); return; } - + URI uri; try { uri = resURL.toURI(); } catch (URISyntaxException ex) { - CrashReport report = CrashReport.makeCrashReport(ex, String.format("Failed to get URI for %s", (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); + CrashReport report = CrashReport.makeCrashReport(ex, + String.format("Failed to get URI for %s", + (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); return; } if (uri.getScheme().equals("jar")) { - try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) { + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, + Collections.emptyMap())) { copyout(fileSystem.getPath(base), pd.modId); } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, - String.format("Failed in getting FileSystem handler set up for %s", uri.getPath())); + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Failed in getting FileSystem handler set up for %s", uri.getPath())); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -117,7 +125,7 @@ public void scanResources(PluginData pd) { } private void copyout(Path myPath, String modId) { - try(Stream walk = Files.walk(myPath, 1)) { + try (Stream walk = Files.walk(myPath, 1)) { for (Iterator it = walk.iterator(); it.hasNext();) { Path p = it.next(); String name = p.getFileName().toString(); @@ -127,11 +135,16 @@ private void copyout(Path myPath, String modId) { Path target; if ("_features".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF, String.format("features-%s.json", modId)); + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("features-%s.json", modId)); } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF, String.format("replacements-%s.json", modId)); + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("replacements-%s.json", modId)); } else { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, String.format("%s.json", modId)); + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + String.format("%s.json", modId)); } if (!target.toFile().exists()) { @@ -142,7 +155,8 @@ private void copyout(Path myPath, String modId) { } } } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format("Faulted while iterating %s for config files or copying them out", myPath)); + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Faulted while iterating %s for config files or copying them out", myPath)); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); OreSpawn.LOGGER.error(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 5390b6d9..13d8c62f 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -1,6 +1,11 @@ package com.mcmoddev.orespawn.commands; -import com.google.gson.*; +import org.apache.commons.io.FilenameUtils; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.Constants.ConfigNames; import com.mcmoddev.orespawn.json.OreSpawnReader; @@ -19,8 +24,6 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.EnumHand; -import org.apache.commons.io.FilenameUtils; - public class AddOreCommand extends CommandBase { @Override @@ -34,7 +37,8 @@ public String getUsage(ICommandSender sender) { } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + public void execute(MinecraftServer server, ICommandSender sender, String[] args) + throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); } @@ -52,7 +56,8 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args String file = args[0]; @SuppressWarnings("deprecation") - IBlockState state = Block.getBlockFromItem(stack.getItem()).getStateFromMeta(stack.getItemDamage()); + IBlockState state = Block.getBlockFromItem(stack.getItem()) + .getStateFromMeta(stack.getItemDamage()); String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); JsonParser p = new JsonParser(); @@ -60,27 +65,35 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); } - + private JsonElement mergeDefaults(JsonElement parse, IBlockState state) { JsonObject work = parse.getAsJsonObject(); JsonObject emptyBlacklist = new JsonObject(); emptyBlacklist.add("excludes", new JsonArray()); - - if(!work.has(ConfigNames.ENABLED)) work.addProperty(ConfigNames.ENABLED, true); - if(!work.has(ConfigNames.RETROGEN)) work.addProperty(ConfigNames.RETROGEN, false); - if(!work.has(ConfigNames.FEATURE)) work.addProperty(ConfigNames.FEATURE, "default"); - if(!work.has(ConfigNames.REPLACEMENT)) work.addProperty(ConfigNames.REPLACEMENT, "default"); - if(!work.has(ConfigNames.PARAMETERS)) work.add(ConfigNames.PARAMETERS, - OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()).getDefaultParameters()); - if(!work.has(ConfigNames.DIMENSIONS)) work.add(ConfigNames.DIMENSIONS, emptyBlacklist); - if(!work.has(ConfigNames.BIOMES)) work.add(ConfigNames.BIOMES, emptyBlacklist); - + + if (!work.has(ConfigNames.ENABLED)) + work.addProperty(ConfigNames.ENABLED, true); + if (!work.has(ConfigNames.RETROGEN)) + work.addProperty(ConfigNames.RETROGEN, false); + if (!work.has(ConfigNames.FEATURE)) + work.addProperty(ConfigNames.FEATURE, "default"); + if (!work.has(ConfigNames.REPLACEMENT)) + work.addProperty(ConfigNames.REPLACEMENT, "default"); + if (!work.has(ConfigNames.PARAMETERS)) + work.add(ConfigNames.PARAMETERS, + OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) + .getDefaultParameters()); + if (!work.has(ConfigNames.DIMENSIONS)) + work.add(ConfigNames.DIMENSIONS, emptyBlacklist); + if (!work.has(ConfigNames.BIOMES)) + work.add(ConfigNames.BIOMES, emptyBlacklist); + JsonObject block = new JsonObject(); block.addProperty(ConfigNames.CHANCE, 100); block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); work.add(ConfigNames.BLOCK, block); - + return work; } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index a0f22e3f..464d6ecb 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -26,12 +26,19 @@ import net.minecraftforge.oredict.OreDictionary; public class ClearChunkCommand extends CommandBase { - private static final String STONE_ID = "minecraft:stone"; - private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); - private static final List baseStones = Arrays.asList(STONE_ID, "minecraft:netherrack", "minecraft:end_stone", "minecraft:cobblestone", "minecraft:obsidian", "minecraft:magma", "minecraft:soul_sand"); - private static final List dirtVariants = Arrays.asList("minecraft:dirt", "minecraft:grass"); - private static final List otherVariants = Arrays.asList("minecraft:gravel", "minecraft:sand"); + private static final String STONE_ID = "minecraft:stone"; + private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", + "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", + "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); + private static final List baseStones = Arrays.asList(STONE_ID, "minecraft:netherrack", + "minecraft:end_stone", "minecraft:cobblestone", "minecraft:obsidian", "minecraft:magma", + "minecraft:soul_sand"); + + private static final List dirtVariants = Arrays.asList("minecraft:dirt", + "minecraft:grass"); + private static final List otherVariants = Arrays.asList("minecraft:gravel", + "minecraft:sand"); @Override public String getName() { @@ -44,7 +51,8 @@ public String getUsage(ICommandSender sender) { } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + public void execute(MinecraftServer server, ICommandSender sender, String[] args) + throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); } @@ -54,25 +62,34 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args ChunkPos chunkPos = chunk.getPos(); List blocks; - boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false; + boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") + : false; List blockNames = new LinkedList<>(); getBlocks(args, blockNames); blocks = blockNames.stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))).map(block -> block.getDefaultState()).collect(Collectors.toList()); + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(block -> block.getDefaultState()).collect(Collectors.toList()); + + blocks.addAll(OreSpawn.API + .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) + .stream().collect(Collectors.toList())); + List overburden = Arrays + .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", + "minecraft:sandstone", "minecraft:red_sandstone") + .stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); - blocks.addAll(OreSpawn.API.getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()).stream().collect(Collectors.toList())); - List overburden = Arrays.asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone").stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); - clearBlocks(chunkPos, blocks, overburden, flagClassic, player); - player.sendStatusMessage(new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); + player.sendStatusMessage( + new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); } - private void clearBlocks(ChunkPos chunkPos, List blocks, List overburden, boolean flagClassic, EntityPlayer player) { + private void clearBlocks(ChunkPos chunkPos, List blocks, + List overburden, boolean flagClassic, EntityPlayer player) { for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { @@ -95,8 +112,10 @@ private void removeIfFluid(BlockPos pos, EntityPlayer player) { } } - private void removeIfBlocks(EntityPlayer player, BlockPos pos, IBlockState block, List blocks, List overburden, boolean flagClassic) { - if (blocks.contains(block) || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { + private void removeIfBlocks(EntityPlayer player, BlockPos pos, IBlockState block, + List blocks, List overburden, boolean flagClassic) { + if (blocks.contains(block) + || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { player.getEntityWorld().setBlockToAir(pos); } } @@ -120,12 +139,10 @@ private void getBlocks(String[] args, List blockNames) { blockNames.add(Blocks.STONE.getRegistryName().toString()); blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); blockNames.add(Blocks.END_STONE.getRegistryName().toString()); - blockNames.addAll(OreDictionary.getOres("stone").stream() - .map(ItemStack::getItem) - .map(Block::getBlockFromItem) - .map(Block::getRegistryName) - .map(ResourceLocation::toString) - .collect(Collectors.toList())); + blockNames + .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) + .map(Block::getBlockFromItem).map(Block::getRegistryName) + .map(ResourceLocation::toString).collect(Collectors.toList())); break; default: diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 779b089b..9f7029c2 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -1,9 +1,17 @@ package com.mcmoddev.orespawn.commands; +import java.io.File; +import java.io.IOException; + +import org.apache.commons.codec.CharEncoding; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringEscapeUtils; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonPrimitive; + import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommand; @@ -12,14 +20,9 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringEscapeUtils; -import org.apache.commons.codec.CharEncoding; - -import java.io.File; -import java.io.IOException; public class DumpBiomesCommand extends CommandBase { + @Override public String getName() { return "dumpbiomes"; @@ -31,7 +34,8 @@ public String getUsage(ICommandSender sender) { } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + public void execute(MinecraftServer server, ICommandSender sender, String[] args) + throws CommandException { JsonArray array = new JsonArray(); for (Biome biome : ForgeRegistries.BIOMES) { @@ -42,7 +46,8 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args String json = gson.toJson(array); try { - FileUtils.writeStringToFile(new File(".", "biome_dump.json"), StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); + FileUtils.writeStringToFile(new File(".", "biome_dump.json"), + StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); } catch (IOException e) { throw new CommandException("Failed to save the json file"); } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index c312f94d..c56f6e8e 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -21,8 +21,10 @@ public String getUsage(ICommandSender sender) { } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { - sender.sendMessage(new TextComponentString("Forcing configs as OreSpawn sees them to be written to disk")); + public void execute(MinecraftServer server, ICommandSender sender, String[] args) + throws CommandException { + sender.sendMessage(new TextComponentString( + "Forcing configs as OreSpawn sees them to be written to disk")); OreSpawnWriter.saveConfigs(); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 107a03d2..5d17f2b8 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -5,6 +5,8 @@ import java.nio.charset.Charset; import java.nio.file.FileSystems; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.apache.commons.io.FileUtils; @@ -16,13 +18,11 @@ import com.google.gson.JsonParser; import com.mcmoddev.orespawn.OreSpawn; -import java.util.ArrayList; -import java.util.HashMap; - import net.minecraft.crash.CrashReport; import net.minecraftforge.common.config.Configuration; public class Config { + private static Configuration configuration; private Config() { @@ -32,12 +32,25 @@ public static void loadConfig() { configuration = new Configuration(new File(Constants.CONFIG_FILE)); // Load our Boolean Values - boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, Configuration.CATEGORY_GENERAL, false, "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); - boolVals.put(Constants.FORCE_RETROGEN_KEY, configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, Configuration.CATEGORY_GENERAL, false, "Force all chunks to retrogen regardless of anything else")); - boolVals.put(Constants.REPLACE_VANILLA_OREGEN, configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, Configuration.CATEGORY_GENERAL, false, "Replace vanilla ore-generation entirely")); - boolVals.put(Constants.FLAT_BEDROCK, configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, false, "Flatten the bedrock during world generation")); - boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); - intVals.put(Constants.BEDROCK_LAYERS, configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, 4, "How thick should the shell of bedrock be?")); + boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); + boolVals.put(Constants.FORCE_RETROGEN_KEY, + configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Force all chunks to retrogen regardless of anything else")); + boolVals.put(Constants.REPLACE_VANILLA_OREGEN, + configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, + Configuration.CATEGORY_GENERAL, false, + "Replace vanilla ore-generation entirely")); + boolVals.put(Constants.FLAT_BEDROCK, + configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, + false, "Flatten the bedrock during world generation")); + boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, + Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); + intVals.put(Constants.BEDROCK_LAYERS, + configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, + 4, "How thick should the shell of bedrock be?")); knownKeys.add(Constants.RETROGEN_KEY); knownKeys.add(Constants.FORCE_RETROGEN_KEY); knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); @@ -50,7 +63,8 @@ public static void loadConfig() { } private static void loadExtractedConfigs() { - Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", "known-configs.json"); + Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); if (!p.toFile().exists()) { return; @@ -123,7 +137,8 @@ public static void saveConfig() { private static void saveKnownConfigs() { Gson gson = new GsonBuilder().setPrettyPrinting().create(); - Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", "known-configs.json"); + Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); if (!p.toFile().getParentFile().exists()) { p.toFile().mkdirs(); @@ -138,7 +153,8 @@ private static void saveKnownConfigs() { try { FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed saving list of already extracted mod configs"); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed saving list of already extracted mod configs"); report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index d1ed3429..7c6ea724 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -4,6 +4,7 @@ import java.nio.file.Paths; public class Constants { + public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; public static final String VERSION = "3.3.0"; @@ -34,28 +35,31 @@ public class Constants { public static final String PRECISION = "precision"; public static final Path CONFDIR = Paths.get("config", "orespawn3"); public static final Path SYSCONF = Paths.get("config", "orespawn3", "sysconf"); - + public final class FormatBits { - private FormatBits() {} + private FormatBits() { + } - public static final String MAX_SPREAD = "maxSpread"; + public static final String MAX_SPREAD = "maxSpread"; public static final String MEDIAN_SIZE = "medianSize"; - public static final String MIN_HEIGHT = "minHeight"; - public static final String MAX_HEIGHT = "maxHeight"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String NODE_SIZE = "size"; - public static final String ATTEMPTS = "attempts"; - public static final String LENGTH = "length"; - public static final String NODE_COUNT = "numObjects"; + public static final String MIN_HEIGHT = "minHeight"; + public static final String MAX_HEIGHT = "maxHeight"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String NODE_SIZE = "size"; + public static final String ATTEMPTS = "attempts"; + public static final String LENGTH = "length"; + public static final String NODE_COUNT = "numObjects"; public static final String ATTEMPTS_MIN = "minAttempts"; public static final String ATTEMPTS_MAX = "maxAttempts"; public static final String STARTINGFACE = "startFacing"; } public final class FileBits { - private FileBits() {} + + private FileBits() { + } public static final String CONFIG_DIR = "config"; public static final String OS3 = "orespawn3"; @@ -64,7 +68,10 @@ private FileBits() {} } public final class ConfigNames { - private ConfigNames() {} + + private ConfigNames() { + } + public static final String DEFAULT = "default"; public static final String STATE_NORMAL = "normal"; public static final String DIMENSIONS = "dimensions"; @@ -84,9 +91,12 @@ private ConfigNames() {} public static final String WHITELIST = "includes"; public static final String BLACKLIST = "excludes"; public static final String PRESETS = "presets"; - + public final class DefaultFeatureProperties { - private DefaultFeatureProperties() {} + + private DefaultFeatureProperties() { + } + public static final String SIZE = "size"; public static final String VARIATION = "variation"; public static final String FREQUENCY = "frequency"; diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 34a2182e..160df56e 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -8,9 +8,9 @@ import java.util.Map; import java.util.TreeMap; +import org.apache.commons.codec.CharEncoding; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringEscapeUtils; -import org.apache.commons.codec.CharEncoding; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -27,11 +27,11 @@ import net.minecraftforge.registries.RegistryBuilder; public class FeatureRegistry { + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; private static final IForgeRegistry registry = new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "feature_registry")) - .setType(IFeature.class) - .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO + .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) + .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO .create(); public FeatureRegistry() { @@ -39,10 +39,10 @@ public FeatureRegistry() { } public Map getFeatures() { - Map tempMap = new TreeMap<>(); + Map tempMap = new TreeMap<>(); registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); - + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); + return Collections.unmodifiableMap(tempMap); } @@ -53,7 +53,7 @@ public String getFeatureName(IFeature feature) { public IFeature getFeature(String name) { return getFeature(new ResourceLocation(name)); } - + public IFeature getFeature(ResourceLocation featureResourceLocation) { ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); if (registry.containsKey(featureResourceLocation)) { @@ -70,6 +70,7 @@ public boolean hasFeature(String name) { public boolean hasFeature(ResourceLocation featureResourceLocation) { return registry.containsKey(featureResourceLocation); } + public boolean hasFeature(IFeature feature) { return registry.containsKey(feature.getRegistryName()); } @@ -99,9 +100,11 @@ private static IFeature getInstance(String className) { try { featureClazz = Class.forName(className); featureCons = featureClazz.getConstructor(); - feature = (IFeature)featureCons.newInstance(); + feature = (IFeature) featureCons.newInstance(); } catch (Exception e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed to load and instantiate an instance of the feature generator named " + className + " that was specified as a feature generator"); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed to load and instantiate an instance of the feature generator named " + + className + " that was specified as a feature generator"); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); return null; @@ -118,7 +121,8 @@ public void loadFeaturesFile(File file) { try { rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getName()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getName()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); return; @@ -128,7 +132,7 @@ public void loadFeaturesFile(File file) { for (JsonElement elem : elements) { addFeature(elem.getAsJsonObject()); - } + } } public void writeFeatures(File file) { @@ -136,21 +140,21 @@ public void writeFeatures(File file) { JsonArray root = new JsonArray(); - registry.getEntries().stream() - .map( ent -> { - JsonObject e = new JsonObject(); + registry.getEntries().stream().map(ent -> { + JsonObject e = new JsonObject(); e.addProperty("name", ent.getKey().getPath()); e.addProperty("class", ent.getValue().getClass().getName()); return e; - }) - .forEach( root::add ); + }).forEach(root::add); String json = gson.toJson(root); try { - FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); + FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), + CharEncoding.UTF_8); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config " + file.getName()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config " + file.getName()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index 316e63bf..33bfa006 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -20,6 +20,7 @@ import net.minecraft.crash.CrashReport; public class PresetsStorage { + private final Map> storage; private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; @@ -28,7 +29,8 @@ public PresetsStorage() { } public void setSymbolSection(String sectionName, String itemName, JsonElement value) { - Map temp = storage.getOrDefault(sectionName, new HashMap()); + Map temp = storage.getOrDefault(sectionName, + new HashMap()); temp.put(itemName, value); storage.put(sectionName, temp); } @@ -42,10 +44,10 @@ public JsonElement getSymbolSection(String sectionName, String itemName) { } public void copy(PresetsStorage dest) { - storage.entrySet().stream() - .forEach(ensm -> { + storage.entrySet().stream().forEach(ensm -> { String section = ensm.getKey(); - ensm.getValue().entrySet().forEach(ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); + ensm.getValue().entrySet().forEach( + ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); }); } @@ -56,36 +58,37 @@ public void clear() { public void load(Path inputFile) { JsonParser p = new JsonParser(); JsonElement parsed = null; - - try( BufferedReader r = Files.newBufferedReader(inputFile)) { + + try (BufferedReader r = Files.newBufferedReader(inputFile)) { parsed = p.parse(r); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading presets from" + inputFile.toString()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading presets from" + inputFile.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch(JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + inputFile.toString()); + } catch (JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + inputFile.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } - - if(parsed != null) { - parsed.getAsJsonObject().entrySet().stream() - .forEach( entry -> { + + if (parsed != null) { + parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream() - .forEach( sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); + entry.getValue().getAsJsonObject().entrySet().stream().forEach( + sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); }); - } + } } public JsonElement get(String asString) { Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); Matcher m = p.matcher(asString); - if(m.matches()) { + if (m.matches()) { return this.getSymbolSection(m.group(1), m.group(2)); } - return new JsonPrimitive("Unknown Variable "+asString); + return new JsonPrimitive("Unknown Variable " + asString); } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 9207ee0a..6fe63c96 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -1,5 +1,22 @@ package com.mcmoddev.orespawn.data; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.stream.Collectors; + +import org.apache.commons.io.FileUtils; + import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -7,7 +24,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; @@ -23,37 +39,19 @@ import net.minecraftforge.registries.IForgeRegistryModifiable; import net.minecraftforge.registries.RegistryBuilder; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.stream.Collectors; - -import org.apache.commons.io.FileUtils; - public class ReplacementsRegistry { + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "replacements_registry")) - .allowModification() - .setType(IReplacementEntry.class) - .setMaxID(65535) // 16 bits should be enough... + .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() + .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... .create(); public ReplacementsRegistry() { // } - public Map getReplacements() { + public Map getReplacements() { return ImmutableMap.copyOf(registry.getEntries()); } @@ -66,28 +64,29 @@ public Map getReplacements() { @Deprecated public List getDimensionDefault(int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; - List mineralogyOres = OreDictionary.getOres("cobblestone").stream() - .filter( iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) - .map( iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) + List mineralogyOres = OreDictionary.getOres("cobblestone").stream() + .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) + .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) .collect(Collectors.toList()); List baseRv = new ArrayList<>(); baseRv.addAll(mineralogyOres); - if (dimension < -1 || dimension > 1 || dimension == 0) { for (ItemStack iS : OreDictionary.getOres("stone")) { baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); } - + return baseRv; - } - - baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); + } + + baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS + .getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); return baseRv; } public IReplacementEntry getReplacement(String name) { - ResourceLocation act = new ResourceLocation(name.contains(":")?name:String.format("orespawn:%s", name)); + ResourceLocation act = new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name)); if (registry.containsKey(act)) { return registry.getValue(act); } else { @@ -96,22 +95,23 @@ public IReplacementEntry getReplacement(String name) { } public void addBlock(String name, String blockName, String blockState) { - IBlockState b = StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + IBlockState b = StateUtil.deserializeState( + ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); addBlock(name, b); } public Map> getBlocks() { - Map> tempMap = new TreeMap<>(); + Map> tempMap = new TreeMap<>(); registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); - + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); + return Collections.unmodifiableMap(tempMap); } public void addReplacement(IReplacementEntry replacement) { registry.register(replacement); } - + public void addBlock(String name, IBlockState state) { ResourceLocation regName = new ResourceLocation(name); if (registry.containsKey(regName)) { @@ -125,43 +125,45 @@ public void addBlock(String name, IBlockState state) { registry.register(newRE); return; } - - IReplacementEntry r = new ReplacementEntry(name, state); + + IReplacementEntry r = new ReplacementEntry(name, state); registry.register(r); } - + @SuppressWarnings("deprecation") public void loadFile(Path file) { JsonParser parser = new JsonParser(); JsonObject elements; String rawJson; - + try { rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getFileName()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getFileName()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); return; } - + elements = parser.parse(rawJson).getAsJsonObject(); - elements.entrySet().stream() - .forEach( elem -> { + elements.entrySet().stream().forEach(elem -> { String entName = elem.getKey(); JsonArray entries = elem.getValue().getAsJsonArray(); List blocks = new LinkedList<>(); for (JsonElement e : entries) { JsonObject asObj = e.getAsJsonObject(); - String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString().toLowerCase(); - + String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() + .toLowerCase(); + // is this an OreDictionary entry ? - if(blockName.startsWith("ore:")) { + if (blockName.startsWith("ore:")) { // yes, it is String oreDictName = blockName.split(":")[1]; OreDictionary.getOres(oreDictName).forEach(iS -> { - if(iS.getMetadata() != 0) { - blocks.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); + if (iS.getMetadata() != 0) { + blocks.add(Block.getBlockFromItem(iS.getItem()) + .getStateFromMeta(iS.getMetadata())); } else { blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); } @@ -174,7 +176,7 @@ public void loadFile(Path file) { // has metadata int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); blocks.add(theBlock.getStateFromMeta(meta)); - } else if(asObj.has(Constants.ConfigNames.STATE)) { + } else if (asObj.has(Constants.ConfigNames.STATE)) { // has a state state = asObj.get(Constants.ConfigNames.STATE).getAsString(); blocks.add(StateUtil.deserializeState(theBlock, state)); @@ -184,38 +186,40 @@ public void loadFile(Path file) { } } } - - IReplacementEntry replacer = new ReplacementEntry("orespawn:"+entName, blocks); + + IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); registry.register(replacer); }); } public void saveFile(String modName) { JsonObject outs = new JsonObject(); - - registry.getEntries().stream() - .filter(ent -> ent.getKey().getNamespace().equals(modName)) - .forEach(ent -> { - JsonArray entry = new JsonArray(); - IReplacementEntry workVal = ent.getValue(); - workVal.getEntries().stream() - .forEach(bs -> { - JsonObject block = new JsonObject(); - block.addProperty(Constants.ConfigNames.BLOCK, bs.getBlock().getRegistryName().toString()); - if(!bs.toString().matches("\\[normal\\]")) { - block.addProperty(Constants.ConfigNames.STATE, bs.toString().replaceAll("[\\[\\]]", "")); - } - entry.add(block); - }); - outs.add(ent.getKey().toString(), entry); - }); - Path p = Paths.get("config","orespawn3", "sysconfig", String.format("replacements-%s.json", modName)); - try(BufferedWriter w = Files.newBufferedWriter(p)) { + + registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) + .forEach(ent -> { + JsonArray entry = new JsonArray(); + IReplacementEntry workVal = ent.getValue(); + workVal.getEntries().stream().forEach(bs -> { + JsonObject block = new JsonObject(); + block.addProperty(Constants.ConfigNames.BLOCK, + bs.getBlock().getRegistryName().toString()); + if (!bs.toString().matches("\\[normal\\]")) { + block.addProperty(Constants.ConfigNames.STATE, + bs.toString().replaceAll("[\\[\\]]", "")); + } + entry.add(block); + }); + outs.add(ent.getKey().toString(), entry); + }); + Path p = Paths.get("config", "orespawn3", "sysconfig", + String.format("replacements-%s.json", modName)); + try (BufferedWriter w = Files.newBufferedWriter(p)) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); String ov = gson.toJson(outs); w.write(ov); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, String.format("Failed writing replacements file %s", p.toAbsolutePath().toString())); + CrashReport report = CrashReport.makeCrashReport(e, String + .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java index 56b3194f..52c0f2f3 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java +++ b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java @@ -1,7 +1,6 @@ package com.mcmoddev.orespawn.data; - -import com.mcmoddev.orespawn.api.os3.*; +import com.mcmoddev.orespawn.api.os3.OS3API; import com.mcmoddev.orespawn.api.plugin.IOreSpawnPlugin; import com.mcmoddev.orespawn.api.plugin.OreSpawnPlugin; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 4e23fc4c..42d8c698 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -1,11 +1,14 @@ package com.mcmoddev.orespawn.impl.features; +import java.util.Random; + import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.data.Constants; + import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; @@ -14,8 +17,6 @@ import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; -import java.util.Random; - public class ClusterGenerator extends FeatureBase implements IFeature { private ClusterGenerator(Random rand) { @@ -28,7 +29,7 @@ public ClusterGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -45,14 +46,14 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int blockX = chunkX * 16 + 8; int blockZ = chunkZ * 16 + 8; - int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); int tries; @@ -72,15 +73,16 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int y = random.nextInt(maxHeight - minHeight) + minHeight; int z = blockZ + zRand - (maxSpread / 2); - spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, spawnData, world, new BlockPos(x,y,z)); + spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, + spawnData, world, new BlockPos(x, y, z)); } tries--; } } - private void spawnCluster(int clusterSize, int variance, int clusterCount, int maxSpread, int minHeight, - int maxHeight, ISpawnEntry spawnData, World world, BlockPos pos) { + private void spawnCluster(int clusterSize, int variance, int clusterCount, int maxSpread, + int minHeight, int maxHeight, ISpawnEntry spawnData, World world, BlockPos pos) { // spawn a cluster at the center, then a bunch around the outside... int r = clusterSize - variance; @@ -90,7 +92,8 @@ private void spawnCluster(int clusterSize, int variance, int clusterCount, int m spawnChunk(world, pos, spawnData, r); - int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary inside that + int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary + // inside that if (variance > 0) { count += this.random.nextInt(2 * variance) - variance; @@ -135,7 +138,8 @@ private void spawnChunk(World world, BlockPos pos, ISpawnEntry spawnData, int qu while (count > 0) { IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, spawnData)) { + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData)) { count++; z++; } else { @@ -155,18 +159,18 @@ private void spawnChunk(World world, BlockPos pos, ISpawnEntry spawnData, int qu doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnData, World world, BlockPos pos) { + private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnData, World world, + BlockPos pos) { int count = quantity; - double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int)(radius * radius); - if( nextBoolean ) { - spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); + double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { - spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); } } - @Override public void setRandom(Random rand) { this.random = rand; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 40c4b7a1..fa18ad07 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -13,9 +13,8 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; -import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.chunk.IChunkProvider; - +import net.minecraft.world.gen.IChunkGenerator; public class DefaultFeatureGenerator extends FeatureBase implements IFeature { @@ -25,7 +24,7 @@ public DefaultFeatureGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -97,8 +96,7 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan while (count > 0) { IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, - world.provider.getDimension(), true, spawnData); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } return; @@ -107,14 +105,15 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, BlockPos pos) { + private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, + BlockPos pos) { int count = quantity; - double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int)(radius * radius); - if( nextBoolean ) { - spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); + double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { - spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); } } @@ -129,7 +128,6 @@ public JsonObject getDefaultParameters() { return defParams; } - @Override public void setRandom(Random rand) { this.random = rand; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 8dfa3459..0919218e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -27,7 +27,7 @@ public NormalCloudGenerator() { @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -45,14 +45,14 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int blockX = chunkX * 16; int blockZ = chunkZ * 16; - int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); - int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get // a size that will let us insert by the radius @@ -64,7 +64,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int offsetY = sizeY - maxSpread; int radiusXZ = offsetXZ / 2; - // actual radius for placement is the size minus the spread to center it in the space and keep + // actual radius for placement is the size minus the spread to center it in the space and + // keep // from overflowing int radiusY = offsetY / 2; @@ -86,7 +87,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider if (this.random.nextInt(100) <= frequency) { frequency = fSave; int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; - // this should, hopefully, keep us centered between minHeight and maxHeight with nothing going above/below those values + // this should, hopefully, keep us centered between minHeight and maxHeight with + // nothing going above/below those values int y = blockY + getPoint(0, offsetY, radiusY); int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; @@ -98,7 +100,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider BlockPos p = new BlockPos(x, y, z); - if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) && tryCount < 5) { + if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) + && tryCount < 5) { // make another try! tries++; frequency = 100; @@ -112,17 +115,18 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight, BlockPos pos, ISpawnEntry spawnData, World world) { + private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight, BlockPos pos, + ISpawnEntry spawnData, World world) { // spawn one right at the center here, then generate for the cloud and do the math if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, - world.provider.getDimension(), true, spawnData)) { + world.provider.getDimension(), true, spawnData)) { return false; } int radius = maxSpread / 2; boolean alreadySpewed = false; - int count = Math.min(size, (int)Math.round(Math.PI * Math.pow(radius, 2))); + int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); while (count > 0) { int xp = getPoint(0, maxSpread, radius); @@ -134,7 +138,7 @@ private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight int z = 0; while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, - world.provider.getDimension(), true, spawnData)) { + world.provider.getDimension(), true, spawnData)) { xp = getPoint(0, maxSpread, radius); yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); zp = getPoint(0, maxSpread, radius); @@ -145,7 +149,8 @@ private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight } if (z >= 5 && !alreadySpewed) { - OreSpawn.LOGGER.info("unable to achieve requested cloud density for cloud centered at %s", pos); + OreSpawn.LOGGER.info( + "unable to achieve requested cloud density for cloud centered at %s", pos); alreadySpewed = true; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 53d78a55..77d2c0ab 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -28,10 +28,9 @@ public PrecisionGenerator() { this(new Random()); } - @Override public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + ISpawnEntry spawnData, ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -47,7 +46,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); - int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); + int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); int thisNode = nodeSize; @@ -59,7 +58,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); - // bit of feedback - if we underproduce or overproduce a node, the next one gets a correction + // bit of feedback - if we underproduce or overproduce a node, the next one gets a + // correction if (sc != thisNode && sc != 0) { thisNode += (nodeSize - sc); } else if (sc == thisNode) { @@ -74,7 +74,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, ChunkPos pos, ISpawnEntry spawnData, World world) { + private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, ChunkPos pos, + ISpawnEntry spawnData, World world) { int spawned = 0; int c; @@ -85,7 +86,8 @@ private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, Ch c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); if (c == 0) { - act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), heightRange); + act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), + heightRange); } counter -= (c + 1); @@ -95,7 +97,8 @@ private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, Ch return spawned; } - private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, World world, int nodeSize, HeightRange heightRange) { + private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, World world, + int nodeSize, HeightRange heightRange) { int count = nodeSize; int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; @@ -128,7 +131,8 @@ private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, Worl return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); } - private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightRange, ChunkPos pos) { + private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightRange, + ChunkPos pos) { BlockPos p = spot.add(offset); ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); int xMax = x1z1.getXEnd(); @@ -140,7 +144,8 @@ private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightR int ymod = offset.getY(); int zmod = offset.getZ(); - // correct the points values to not cause the Y coordinate to go outside the permissable range + // correct the points values to not cause the Y coordinate to go outside the permissable + // range if (p.getY() < heightRange.getMin() || p.getY() > heightRange.getMax()) { ymod = rescaleOffset(ymod, spot.getY(), heightRange.getMin(), heightRange.getMax()); } @@ -156,7 +161,8 @@ private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightR return spot.add(xmod, ymod, zmod); } - private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, final int maximumIn) { + private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, + final int maximumIn) { int actual = centerIn + offsetIn; int wrapDistance; int range = maximumIn - minimumIn; @@ -183,27 +189,33 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini return workingPoint - centerIn; } - private int spawnFill(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, int nodeSize, HeightRange heightRange) { + private int spawnFill(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, + int nodeSize, HeightRange heightRange) { double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int)Math.ceil(radius * radius); + int rSqr = (int) Math.ceil(radius * radius); if (this.random.nextBoolean()) { - return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, nodeSize); + return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, + nodeSize); } else { - return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, nodeSize); + return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, + nodeSize); } } - private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, HeightRange heightRange, boolean toPositive, double radius, - int rSqr, int nodeSize) { + private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, + HeightRange heightRange, boolean toPositive, double radius, int rSqr, int nodeSize) { int quantity = nodeSize; int nc = 0; - for (int dy = (int)(-1 * radius); dy < radius; dy++) { - for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, radius); dx = countItem(dx, toPositive)) { - for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, radius); dz = countItem(dz, toPositive)) { - if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, loc) >= 0) { + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, + radius); dx = countItem(dx, toPositive)) { + for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, + radius); dz = countItem(dz, toPositive)) { + if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, + loc) >= 0) { nc++; quantity--; @@ -218,19 +230,19 @@ private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, Block return nc; } - private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRange, ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc) { + private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRange, + ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc) { if (getABC(dx, dy, dz) <= rSqr) { BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); - return spawn(bl, world, p, world.provider.getDimension(), true, - spawnData) ? 1 : 0; + return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; } return -1; } private int getPoint(int lowerBound, int upperBound) { - List arr = new ArrayList<> (); + List arr = new ArrayList<>(); for (int i = lowerBound; i <= upperBound; i++) { arr.add(i); @@ -263,6 +275,7 @@ public JsonObject getDefaultParameters() { } private class HeightRange { + private int min; private int max; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index b3c3f30e..5128f063 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -56,10 +56,11 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - int startingFace = getFaceFromString(params.get(Constants.FormatBits.STARTINGFACE).getAsString()); + int startingFace = getFaceFromString( + params.get(Constants.FormatBits.STARTINGFACE).getAsString()); int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); OreSpawn.LOGGER.fatal("parameters: %s", params); int tries; @@ -85,71 +86,78 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider r = 0; } - spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, world); + spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, + world); } tries--; } } - + private int getFaceFromString(String direction) { String work = direction.toLowerCase(); - switch(work) { - case "north": - return 0; - case "south": - return 5; - case "east": - return 2; - case "west": - return 3; - case "down": - return 1; - case "up": - return 4; - case "random": - return this.random.nextInt(5); - case "vertical": - return this.random.nextBoolean()?4:1; - case "horizontal": - return this.random.nextBoolean()?(this.random.nextBoolean()?0:5):(this.random.nextBoolean()?2:3); - default: - OreSpawn.LOGGER.error("Invalid value %s found in parameters for vein spawn, returning \"north\"", direction); - return 0; + switch (work) { + case "north": + return 0; + case "south": + return 5; + case "east": + return 2; + case "west": + return 3; + case "down": + return 1; + case "up": + return 4; + case "random": + return this.random.nextInt(5); + case "vertical": + return this.random.nextBoolean() ? 4 : 1; + case "horizontal": + return this.random.nextBoolean() ? (this.random.nextBoolean() ? 0 : 5) + : (this.random.nextBoolean() ? 2 : 3); + default: + OreSpawn.LOGGER.error( + "Invalid value %s found in parameters for vein spawn, returning \"north\"", + direction); + return 0; } } - private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos blockPos, ISpawnEntry spawnData, World world) { + private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos blockPos, + ISpawnEntry spawnData, World world) { int face = startingFace; int square = this.random.nextInt(8); BlockPos workingPos = new BlockPos(blockPos); - - if(!spawnData.getMatcher().test(world.getBlockState(blockPos))) { + + if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { return; } - + // build vein - List> points = Lists.newLinkedList(); + List> points = Lists.newLinkedList(); points.add(Pair.of(face, square)); - for( int j = 0; j < veinLength; j++ ) { - Map pos = Maps.newHashMap(); + for (int j = 0; j < veinLength; j++) { + Map pos = Maps.newHashMap(); int[] w = getWeighted(face, square); - for( int k = 0; k < w.length; k++ ) { + for (int k = 0; k < w.length; k++) { pos.put(w[k], k); } - + int[] t = Arrays.stream(w).distinct().sorted().toArray(); - int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length-5, t.length)).map( it -> pos.get(it)).toArray(); + int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length - 5, t.length)) + .map(it -> pos.get(it)).toArray(); int temp = this.random.nextInt(5); - face = fpos[temp]%6; - square = fpos[temp]%12; - points.add(Pair.of(face,square)); + face = fpos[temp] % 6; + square = fpos[temp] % 12; + points.add(Pair.of(face, square)); } spawnOre(world, spawnData, blockPos, nodeSize); - for(Pair point : points) { + for (Pair point : points) { spawnOre(world, spawnData, workingPos, nodeSize); - int[] nextMunge = getDirectionValues(point.first().intValue(), point.second().intValue()); + int[] nextMunge = getDirectionValues(point.first().intValue(), + point.second().intValue()); workingPos = workingPos.add(nextMunge[0], nextMunge[1], nextMunge[2]); } } @@ -170,8 +178,7 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan while (count > 0) { IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, - world.provider.getDimension(), true, spawnData); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } return; @@ -180,14 +187,15 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, BlockPos pos) { + private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, + BlockPos pos) { int count = quantity; - double radius = Math.pow(quantity, 1.0/3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int)(radius * radius); - if( nextBoolean ) { - spawnMungeNE( world, pos, rSqr, radius, spawnData, count ); + double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { - spawnMungeSW( world, pos, rSqr, radius, spawnData, count ); + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); } } @@ -195,85 +203,88 @@ private int[] getDirectionValues(int face, int square) { int x = 0; int y = 0; int z = 0; - switch(face) { - case 0: - z = -1; - break; - case 2: - x = 1; - break; - case 3: - x = -1; - break; - case 5: - z = 1; - break; + switch (face) { + case 0: + z = -1; + break; + case 2: + x = 1; + break; + case 3: + x = -1; + break; + case 5: + z = 1; + break; } if (face == 0 || face == 5) { - y = square < 3?1:(square>5?-1:0); - x = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + y = square < 3 ? 1 : (square > 5 ? -1 : 0); + x = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); } else if (face == 2 || face == 3) { - y = square < 3?1:square>5?-1:0; - z = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + y = square < 3 ? 1 : square > 5 ? -1 : 0; + z = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); } else if (face == 1 || face == 4) { - z = square < 3?-1:(square>5?1:0); - x = (square==0||square%3==0)?-1:(((square+1)%3==0)?1:0); + z = square < 3 ? -1 : (square > 5 ? 1 : 0); + x = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); } - - if (square < 3 || face == 4) y = 1; - else if (square <= 5) y = 0; - else if (square <= 8 || face == 1) y = -1; - + + if (square < 3 || face == 4) + y = 1; + else if (square <= 5) + y = 0; + else if (square <= 8 || face == 1) + y = -1; + return new int[] { x, y, z }; } + /* - * To keep things heading the correct direction, we weight the faces and the "points" of the face - * so that we can choose a semi-intelligent direction to continue in. + * To keep things heading the correct direction, we weight the faces and the "points" of the + * face so that we can choose a semi-intelligent direction to continue in. */ private int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; - private int[] pointWeights = Arrays.stream(faceWeights).map(a -> a*2 ).toArray(); - + private int[] pointWeights = Arrays.stream(faceWeights).map(a -> a * 2).toArray(); private int[] getWeighted(int face, int square) { int[] rv = new int[54]; - for( int f = 0; f < 6; f++ ) { - for( int s = 0; s < 12; s++ ) { - if(isNeighborFace(face, f)) { - rv[f+s] += faceWeights[1]; - } else if(face == f) { - rv[f+s] += faceWeights[0]; + for (int f = 0; f < 6; f++) { + for (int s = 0; s < 12; s++) { + if (isNeighborFace(face, f)) { + rv[f + s] += faceWeights[1]; + } else if (face == f) { + rv[f + s] += faceWeights[0]; } else { - rv[f+s] = 0; + rv[f + s] = 0; } - rv[f+s] += pointWeights[s == square?0:1]; - if( s != 4 && s != 7) { + rv[f + s] += pointWeights[s == square ? 0 : 1]; + if (s != 4 && s != 7) { int matchFace = 0; int matchSquare = 0; - if( s%3 == 0 ) { + if (s % 3 == 0) { // left side matchFace = getMatchingFace(f, 0); matchSquare = getMatchingSquare(s, f, 0); - } else if( s == 2 || s == 5 || s == 8 || s == 11 ) { + } else if (s == 2 || s == 5 || s == 8 || s == 11) { // right side - matchFace = getMatchingFace(f, 1); + matchFace = getMatchingFace(f, 1); matchSquare = getMatchingSquare(s, f, 1); } int addr = matchFace + matchSquare; rv[addr] += faceWeights[1] + pointWeights[1]; - if( s < 3 || s > 8 ) { - if( s < 3 ) { + if (s < 3 || s > 8) { + if (s < 3) { // top row matchFace = getMatchingFace(f, 2); matchSquare = getMatchingSquare(s, f, 2); - } else if( s > 8 ) { - //bottom row + } else if (s > 8) { + // bottom row matchFace = getMatchingFace(f, 3); matchSquare = getMatchingSquare(s, f, 3); } - rv[matchFace+matchSquare] += faceWeights[1] + pointWeights[1]; + rv[matchFace + matchSquare] += faceWeights[1] + pointWeights[1]; } } } @@ -283,39 +294,27 @@ private int[] getWeighted(int face, int square) { } /* - * 0 1 2 - * 3 4 5 - * 6 7 8 - * 9 10 11 - * -------- - * 0 1 2 - * 3 4 5 - * 6 7 8 - * 9 10 11 - * -------- - * 0 1 2 - * 3 4 5 - * 6 7 8 - * 9 10 11 + * 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 + * 11 */ private int getMatchingSquare(int s, int face, int direction) { - switch(direction) { - case 0: /* LEFT */ - return (s%3 == 0)? s +2 : s - 1; - case 1: /* RIGHT */ - return ( s == 2 || s == 5 || s == 8 || s == 11 )? s - 2: s + 1; - case 2: /* UP */ - return (s<3) ? s + 9 : s - 3; - case 3: /* DOWN */ - return (s>8) ? s - 9 : s + 3; + switch (direction) { + case 0: /* LEFT */ + return (s % 3 == 0) ? s + 2 : s - 1; + case 1: /* RIGHT */ + return (s == 2 || s == 5 || s == 8 || s == 11) ? s - 2 : s + 1; + case 2: /* UP */ + return (s < 3) ? s + 9 : s - 3; + case 3: /* DOWN */ + return (s > 8) ? s - 9 : s + 3; } return s; } private int[][] faceMap = new int[][] { { 3, 2, 1, 4 }, { 3, 2, 5, 0 }, { 1, 4, 5, 0 }, - { 4, 1, 5, 0 }, { 2, 3, 5, 0 }, { 3, 2, 4, 1 } }; + { 4, 1, 5, 0 }, { 2, 3, 5, 0 }, { 3, 2, 4, 1 } }; - private int getMatchingFace(int f, int i) { + private int getMatchingFace(int f, int i) { return faceMap[f][i]; } @@ -338,7 +337,6 @@ public JsonObject getDefaultParameters() { return defParams; } - @Override public void setRandom(Random rand) { this.random = rand; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index be2e661e..35fe4e91 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -1,19 +1,19 @@ package com.mcmoddev.orespawn.impl.location; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; + import com.google.common.collect.ImmutableList; import com.google.gson.JsonElement; import com.google.gson.JsonObject; - import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.data.Constants; import net.minecraft.world.biome.Biome; -import java.util.Objects; -import java.util.List; -import java.util.LinkedList; - public final class BiomeLocationComposition implements BiomeLocation { + private final BiomeLocation inclusions; private final BiomeLocation exclusions; @@ -30,7 +30,7 @@ public BiomeLocationComposition(BiomeLocation inclusions, BiomeLocation exclusio public boolean matches(Biome biome) { boolean inWhite = this.inclusions.matches(biome); boolean inBlack = this.exclusions.matches(biome); - + return !inBlack && inWhite; } @@ -47,7 +47,8 @@ public boolean equals(Object obj) { if (obj instanceof BiomeLocationComposition) { BiomeLocationComposition other = (BiomeLocationComposition) obj; - return this.inclusions.equals(other.inclusions) && this.exclusions.equals(other.exclusions); + return this.inclusions.equals(other.inclusions) + && this.exclusions.equals(other.exclusions); } return false; @@ -72,12 +73,12 @@ public BiomeLocation getExclusions() { @Override public JsonElement serialize() { JsonObject rv = new JsonObject(); - + rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); if (!(this.inclusions instanceof BiomeLocationEmpty)) { rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); } - + return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java index b34f542d..f4433414 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java @@ -4,10 +4,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.mcmoddev.orespawn.api.BiomeLocation; + import net.minecraft.world.biome.Biome; import net.minecraftforge.common.BiomeDictionary; public final class BiomeLocationDictionary implements BiomeLocation { + private final BiomeDictionary.Type type; private final int hash; @@ -29,7 +31,8 @@ public int hashCode() { @Override public boolean equals(Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationDictionary) && this.type.equals(((BiomeLocationDictionary) obj).type)); + return (obj == this) || ((obj instanceof BiomeLocationDictionary) + && this.type.equals(((BiomeLocationDictionary) obj).type)); } public BiomeDictionary.Type getType() { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java index dc1ebf08..ac80037c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -1,7 +1,7 @@ package com.mcmoddev.orespawn.impl.location; -import com.google.gson.JsonElement; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.mcmoddev.orespawn.api.BiomeLocation; import net.minecraft.world.biome.Biome; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index ad649ac2..bf616779 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -1,16 +1,18 @@ package com.mcmoddev.orespawn.impl.location; +import java.util.LinkedList; +import java.util.List; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.mcmoddev.orespawn.api.BiomeLocation; -import net.minecraft.world.biome.Biome; -import java.util.List; -import java.util.LinkedList; +import net.minecraft.world.biome.Biome; public final class BiomeLocationList implements BiomeLocation { + private final ImmutableSet locations; private final int hash; @@ -32,7 +34,8 @@ public int hashCode() { @Override public boolean equals(Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationList) && this.locations.equals(((BiomeLocationList) obj).locations)); + return (obj == this) || ((obj instanceof BiomeLocationList) + && this.locations.equals(((BiomeLocationList) obj).locations)); } @Override @@ -49,9 +52,8 @@ public ImmutableSet getLocations() { @Override public JsonElement serialize() { JsonArray rv = new JsonArray(); - this.locations.stream() - .filter(bl -> (!(bl instanceof BiomeLocationEmpty))) - .forEach(bl -> rv.add(bl.serialize())); + this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) + .forEach(bl -> rv.add(bl.serialize())); return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java index 96fa110f..a13bbeb8 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java @@ -4,9 +4,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.mcmoddev.orespawn.api.BiomeLocation; + import net.minecraft.world.biome.Biome; public final class BiomeLocationSingle implements BiomeLocation { + private final Biome biome; private final int hash; @@ -33,7 +35,8 @@ public int hashCode() { @Override public boolean equals(Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationSingle) && this.biome.equals(((BiomeLocationSingle) obj).biome)); + return (obj == this) || ((obj instanceof BiomeLocationSingle) + && this.biome.equals(((BiomeLocationSingle) obj).biome)); } public Biome getBiome() { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index a4cde9da..9b8a1b0c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -5,29 +5,29 @@ import java.util.stream.Collectors; import com.google.common.collect.ImmutableSet; - import com.mcmoddev.orespawn.api.BiomeLocation; +import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; import com.mcmoddev.orespawn.impl.location.BiomeLocationAcceptAny; import com.mcmoddev.orespawn.impl.location.BiomeLocationComposition; import com.mcmoddev.orespawn.impl.location.BiomeLocationEmpty; import com.mcmoddev.orespawn.impl.location.BiomeLocationList; import com.mcmoddev.orespawn.impl.location.BiomeLocationSingle; -import com.mcmoddev.orespawn.api.os3.IBiomeBuilder; import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.registry.ForgeRegistries; public class BiomeBuilder implements IBiomeBuilder { + private final List whitelist = new LinkedList<>(); private final List blacklist = new LinkedList<>(); - + private boolean acceptAll = false; - + public BiomeBuilder() { // } - + @Override public IBiomeBuilder addWhitelistEntry(Biome biome) { this.whitelist.add(biome); @@ -75,30 +75,25 @@ public BiomeLocation create() { BiomeLocation whitelistI; BiomeLocation blacklistI; if (this.whitelist.isEmpty()) { - if(!this.blacklist.isEmpty()) { + if (!this.blacklist.isEmpty()) { whitelistI = new BiomeLocationAcceptAny(); } else { whitelistI = new BiomeLocationEmpty(); } } else { - whitelistI = new BiomeLocationList( - ImmutableSet.copyOf( - this.whitelist.stream() - .map( biome -> new BiomeLocationSingle(biome) ) - .collect(Collectors.toList())) ); + whitelistI = new BiomeLocationList(ImmutableSet.copyOf( + this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) + .collect(Collectors.toList()))); } if (this.blacklist.isEmpty()) { blacklistI = new BiomeLocationEmpty(); } else { - blacklistI = new BiomeLocationList( - ImmutableSet.copyOf( - this.blacklist.stream() - .map( biome -> new BiomeLocationSingle(biome) ) + blacklistI = new BiomeLocationList(ImmutableSet.copyOf( + this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) .collect(Collectors.toList()))); } - return new BiomeLocationComposition(whitelistI, blacklistI); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index d6992dc6..a0e01a73 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -10,14 +10,15 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; public class BlockBuilder implements IBlockBuilder { + private IBlockState blockState; private int chance; private boolean isValid = true; - + public BlockBuilder() { // nothing to do here } - + @Override public IBlockBuilder setFromBlockState(IBlockState blockState) { ResourceLocation key = blockState.getBlock().getRegistryName(); @@ -122,16 +123,19 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } - return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), chance); + return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), + chance); } @Override - public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, int chance) { + public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, + int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); + return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), + chance); } /** @@ -140,7 +144,8 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio */ @Override @Deprecated - public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, int chance) { + public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, + int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java index e3fec368..f30af422 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -5,16 +5,17 @@ import net.minecraft.block.state.IBlockState; public class BlockDefinition implements IBlockDefinition { + private final IBlockState blockState; private final int blockChance; private final boolean isValid; - + public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { this.blockState = blockState; this.blockChance = chance; this.isValid = isValid; } - + @Override public IBlockState getBlock() { return this.blockState; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 56f22805..3e1dc911 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -11,14 +11,15 @@ import net.minecraft.block.state.IBlockState; public class BlockList implements IBlockList { + private final List myBlocks; private List workingList; - + public BlockList() { this.myBlocks = new LinkedList<>(); this.workingList = new LinkedList<>(); } - + @Override public void addBlock(IBlockDefinition block) { this.myBlocks.add(block); @@ -29,7 +30,7 @@ public IBlockState getRandomBlock(Random rand) { if (this.workingList.isEmpty()) { this.startNewSpawn(); } - + int spot = rand.nextInt(this.workingList.size()); IBlockState rv = this.workingList.get(spot); this.workingList.remove(spot); @@ -39,11 +40,9 @@ public IBlockState getRandomBlock(Random rand) { @Override public void startNewSpawn() { this.workingList.clear(); - - this.myBlocks.stream() - .filter(b -> b.isValid()) - .forEach(b -> { - for(int i = 0; i < b.getChance(); i++) { + + this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { + for (int i = 0; i < b.getChance(); i++) { this.workingList.add(b.getBlock()); } }); @@ -51,9 +50,8 @@ public void startNewSpawn() { @Override public void dump() { - this.myBlocks.stream() - .map(bd -> bd.getBlock()) - .forEach(bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); + this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( + bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 70835319..718b836f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -2,20 +2,22 @@ import java.util.LinkedList; import java.util.List; -import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; + import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.api.os3.IDimensionBuilder; public class DimensionBuilder implements IDimensionBuilder { + private final List dimensionWhitelist = new LinkedList<>(); private final List dimensionBlacklist = new LinkedList<>(); private boolean acceptAll = false; private boolean denyAll = false; private boolean acceptAllOverworld = true; - + public DimensionBuilder() { // } - + @Override public IDimensionBuilder addWhitelistEntry(int dimensionID) { this.acceptAllOverworld = false; @@ -32,24 +34,25 @@ public IDimensionBuilder addBlacklistEntry(int dimensionID) { @Override public IDimensionBuilder setAcceptAll() { - if (this.denyAll) this.denyAll = false; + if (this.denyAll) + this.denyAll = false; this.acceptAll = true; return this; } @Override public IDimensionBuilder setDenyAll() { - if (this.acceptAll) this.acceptAll = false; + if (this.acceptAll) + this.acceptAll = false; this.denyAll = true; return this; } @Override public IDimensionList create() { - if (this.acceptAll || - ((this.dimensionWhitelist.isEmpty()) && - (this.dimensionBlacklist.isEmpty())) && - !(this.acceptAllOverworld)) { + if (this.acceptAll + || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) + && !(this.acceptAllOverworld)) { return new DimensionListAcceptAll(); } else if (this.denyAll) { return new DimensionListDenyAll(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index ecbe3673..2fb978ff 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -1,28 +1,32 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.ArrayList; import java.util.List; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.data.Constants; -import java.util.ArrayList; - public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { + private final List whitelist = new ArrayList<>(); private final List blacklist = new ArrayList<>(); - + public DimensionList(List whitelist, List blacklist) { this.whitelist.addAll(whitelist); this.blacklist.addAll(blacklist); } - + @Override public boolean matches(final int dimensionID) { - if (this.whitelist.contains(Integer.valueOf(dimensionID))) return true; - if (this.blacklist.contains(Integer.valueOf(dimensionID))) return false; - if (!this.whitelist.isEmpty()) return false; - if (!this.blacklist.isEmpty()) return true; + if (this.whitelist.contains(Integer.valueOf(dimensionID))) + return true; + if (this.blacklist.contains(Integer.valueOf(dimensionID))) + return false; + if (!this.whitelist.isEmpty()) + return false; + if (!this.blacklist.isEmpty()) + return true; // if it gets here, the whitelist and blacklist are empty... // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... @@ -32,22 +36,20 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { JsonObject rv = new JsonObject(); - if(!this.whitelist.isEmpty()) { + if (!this.whitelist.isEmpty()) { JsonArray wl = new JsonArray(); - whitelist.stream() - .forEach(i -> wl.add(i.intValue())); + whitelist.stream().forEach(i -> wl.add(i.intValue())); rv.add(Constants.ConfigNames.WHITELIST, wl); } - - if(!this.blacklist.isEmpty()) { + + if (!this.blacklist.isEmpty()) { JsonArray bl = new JsonArray(); - blacklist.stream() - .forEach(i -> bl.add(i.intValue())); + blacklist.stream().forEach(i -> bl.add(i.intValue())); rv.add(Constants.ConfigNames.WHITELIST, bl); - } else if(this.whitelist.isEmpty()) { + } else if (this.whitelist.isEmpty()) { return new DimensionListAcceptAllOverworld().serialize(); } - + return rv; } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index 952396a7..463f486b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -6,6 +6,7 @@ import com.mcmoddev.orespawn.data.Constants.ConfigNames; public class DimensionListAcceptAll implements IDimensionList { + @Override public boolean matches(final int dimensionID) { return true; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java index d61037fa..ca49ef48 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -6,6 +6,7 @@ import com.mcmoddev.orespawn.data.Constants; public class DimensionListAcceptAllOverworld implements IDimensionList { + @Override public boolean matches(final int dimensionID) { return dimensionID != -1 && dimensionID != 1; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index 3ed55af1..a140a364 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -6,11 +6,12 @@ import com.mcmoddev.orespawn.data.Constants; public class DimensionListDenyAll implements IDimensionList { + @Override public boolean matches(final int dimensionID) { return false; } - + @Override public JsonObject serialize() { JsonObject rv = new JsonObject(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 61002766..12e2a91a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -10,6 +10,7 @@ import net.minecraft.util.ResourceLocation; public class FeatureBuilder implements IFeatureBuilder { + private IFeature feature; private JsonObject parameters; private boolean useDefaults; @@ -18,11 +19,11 @@ public FeatureBuilder() { this.useDefaults = false; this.parameters = new JsonObject(); } - + @Override public IFeatureBuilder setFeature(String featureName) { String actName = featureName; - if(!actName.contains(":")) { + if (!actName.contains(":")) { actName = String.format("orespawn:%s", featureName); } return this.setFeature(new ResourceLocation(actName)); @@ -31,7 +32,9 @@ public IFeatureBuilder setFeature(String featureName) { @Override public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { if (!OreSpawn.API.featureExists(featureResourceLocation)) { - OreSpawn.LOGGER.warn("Feature %s is not known, feature for this will be set to the default feature", featureResourceLocation.getPath()); + OreSpawn.LOGGER.warn( + "Feature %s is not known, feature for this will be set to the default feature", + featureResourceLocation.getPath()); } return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); } @@ -72,21 +75,22 @@ public IFeatureBuilder setParameter(String parameterName, JsonElement parameterV return this; } - private void setFeatureParameter(String parameterName, JsonElement parameterValue, FeatureEntry feat) { + private void setFeatureParameter(String parameterName, JsonElement parameterValue, + FeatureEntry feat) { if (parameterValue.getAsJsonPrimitive().isBoolean()) { - feat.setParameter(parameterName,parameterValue.getAsBoolean()); + feat.setParameter(parameterName, parameterValue.getAsBoolean()); } else if (parameterValue.getAsJsonPrimitive().isString()) { feat.setParameter(parameterName, parameterValue.getAsString()); } else { float paramAsFloat = parameterValue.getAsFloat(); - if ( (paramAsFloat - Math.floor(paramAsFloat)) > 0 ) { + if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { feat.setParameter(parameterName, parameterValue.getAsFloat()); } else { feat.setParameter(parameterName, parameterValue.getAsInt()); } } } - + @Override public IFeatureBuilder setUseFeatureDefaults() { this.useDefaults = true; @@ -99,17 +103,17 @@ public IFeatureEntry create() { if (!this.useDefaults) { // only copy in the parameters we need this.feature.getDefaultParameters().entrySet().stream() - .filter(ent -> !this.parameters.has(ent.getKey())) - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + .filter(ent -> !this.parameters.has(ent.getKey())) + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); } else { // overwrite - they've said to just use the defaults this.feature.getDefaultParameters().entrySet().stream() - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); } - + this.parameters.entrySet().stream() - .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); - + .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); + return res; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 8f5371dd..7fbbda30 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -5,14 +5,15 @@ import com.mcmoddev.orespawn.api.os3.IFeatureEntry; public class FeatureEntry implements IFeatureEntry { + private final IFeature feature; private final JsonObject parameters; - + public FeatureEntry(IFeature feature) { this.feature = feature; this.parameters = new JsonObject(); } - + @Override public IFeature getFeature() { return this.feature; @@ -26,8 +27,7 @@ public String getFeatureName() { @Override public JsonObject getFeatureParameters() { JsonObject defs = feature.getDefaultParameters(); - this.parameters.entrySet().stream() - .forEach(ent -> defs.add(ent.getKey(), ent.getValue())); + this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); return defs; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index f6d1fd94..a7d3bd78 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -38,85 +38,89 @@ import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.json.OreSpawnReader; +import net.minecraft.block.state.IBlockState; import net.minecraft.crash.CrashReport; import net.minecraft.util.ResourceLocation; -import net.minecraft.block.state.IBlockState; public class OS3APIImpl implements OS3API { - private static final Map spawns; + + private static final Map spawns; private static final FeatureRegistry features; private static final ReplacementsRegistry replacements; private static final PresetsStorage presets; private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; private static final Map spawnsToSourceFiles = new TreeMap<>(); - + static { spawns = new ConcurrentHashMap<>(); features = new FeatureRegistry(); replacements = new ReplacementsRegistry(); presets = new PresetsStorage(); } - + public OS3APIImpl() { // } - + public void loadConfigFiles() { final String failedReadingConfigsFrom = "Failed reading configs from "; - PathMatcher featuresFiles = FileSystems.getDefault().getPathMatcher("glob:**/features-*.json"); - PathMatcher replacementsFiles = FileSystems.getDefault().getPathMatcher("glob:**/replacements-*.json"); + PathMatcher featuresFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/features-*.json"); + PathMatcher replacementsFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/replacements-*.json"); PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); - + try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(featuresFiles::matches) - .map(Path::toFile) - .forEach(features::loadFeaturesFile); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); + stream.filter(featuresFiles::matches).map(Path::toFile) + .forEach(features::loadFeaturesFile); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } - - // have to do this twice or we have issues + + // have to do this twice or we have issues try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(replacementsFiles::matches) - .forEach(replacements::loadFile); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); + stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } - if(Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { + if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { presets.load(Constants.SYSCONF.resolve("presets-default.json")); } - - try(Stream stream = Files.walk(Constants.CONFDIR, 1)) { - stream.filter(jsonMatcher::matches) - .forEach(conf -> { + + try (Stream stream = Files.walk(Constants.CONFDIR, 1)) { + stream.filter(jsonMatcher::matches).forEach(conf -> { try { OreSpawnReader.tryReadFile(conf, this); } catch (MissingVersionException | NotAProperConfigException | OldVersionException | UnknownVersionException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + conf.toString()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } }); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.CONFDIR.toString()); + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.CONFDIR.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } } - + @Override public void addSpawn(ISpawnEntry spawnEntry) { if (spawnEntry != null) { spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); } } - + @Override public void addFeature(String featureName, IFeature feature) { features.addFeature(featureName, feature); @@ -156,12 +160,12 @@ public IBiomeBuilder getBiomeBuilder() { public IReplacementBuilder getReplacementBuilder() { return new ReplacementBuilder(); } - + @Override public Map getReplacements() { Map temp = new HashMap<>(); replacements.getReplacements().entrySet().stream() - .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); + .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); return ImmutableMap.copyOf(temp); } @@ -172,10 +176,9 @@ public IReplacementEntry getReplacement(String replacementName) { @Override public List getSpawns(int dimensionID) { - return ImmutableList.copyOf(spawns.entrySet().stream() - .filter(e -> e.getValue().dimensionAllowed(dimensionID)) - .map(e -> e.getValue()) - .collect(Collectors.toList())); + return ImmutableList.copyOf( + spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) + .map(e -> e.getValue()).collect(Collectors.toList())); } @Override @@ -192,9 +195,10 @@ public Map getAllSpawns() { @Override public boolean featureExists(String featureName) { - return this.featureExists(new ResourceLocation(featureName.contains(":")?featureName:String.format("orespawn:%s", featureName))); + return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName + : String.format("orespawn:%s", featureName))); } - + @Override public boolean featureExists(ResourceLocation featureName) { return features.hasFeature(featureName); @@ -229,7 +233,8 @@ public boolean hasReplacement(ResourceLocation resourceLocation) { @Override public boolean hasReplacement(String name) { - return this.hasReplacement(new ResourceLocation(name.contains(":")?name:String.format("orespawn:%s", name))); + return this.hasReplacement(new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name))); } @Override @@ -241,8 +246,7 @@ public void mapEntryToFile(Path p, String entryName) { public List getSpawnsForFile(String fileName) { Path p = Constants.CONFDIR.resolve(fileName); List values = spawnsToSourceFiles.entrySet().stream() - .filter(ent -> ent.getValue().equals(p)) - .map(ent -> ent.getKey()) + .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) .collect(Collectors.toList()); return ImmutableList.copyOf(values); } @@ -250,15 +254,14 @@ public List getSpawnsForFile(String fileName) { @Override public Map> getSpawnsByFile() { Map> temp = new HashMap<>(); - spawnsToSourceFiles.entrySet().stream() - .forEach(ent -> { - if(temp.containsKey(ent.getValue())) { + spawnsToSourceFiles.entrySet().stream().forEach(ent -> { + if (temp.containsKey(ent.getValue())) { temp.get(ent.getValue()).add(ent.getKey()); } else { temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); } }); - + return ImmutableMap.copyOf(temp); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 20ecd585..cd6b50c7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -3,6 +3,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.lang3.RandomStringUtils; + import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; @@ -11,17 +13,16 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.registry.ForgeRegistries; -import org.apache.commons.lang3.RandomStringUtils; - public class ReplacementBuilder implements IReplacementBuilder { + private String replacementName = null; private List entries; - + public ReplacementBuilder() { this.entries = new LinkedList<>(); } - + @Override public IReplacementBuilder setFromName(String entryName) { this.replacementName = entryName; @@ -63,12 +64,14 @@ public IReplacementBuilder addEntry(String blockName, int metadata) { @Override public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation) { - return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); + return this + .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); } @Override public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state) { - return this.addEntry(StateUtil.deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); + return this.addEntry(StateUtil + .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); } /** @@ -78,20 +81,22 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, Stri @Override @Deprecated public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata) { - return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); + return this.addEntry( + ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); } @Override public boolean hasEntries() { return this.entries.isEmpty(); } - + @Override public IReplacementEntry create() { if (this.replacementName == null) { - this.replacementName = String.format("replacement_%s", RandomStringUtils.randomAlphanumeric(8, 16)); + this.replacementName = String.format("replacement_%s", + RandomStringUtils.randomAlphanumeric(8, 16)); } - + return new ReplacementEntry(this.replacementName, this.entries); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index c454236b..e2e21fce 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -11,11 +11,13 @@ import net.minecraft.block.state.IBlockState; import net.minecraftforge.registries.IForgeRegistryEntry; -public class ReplacementEntry extends IForgeRegistryEntry.Impl implements IReplacementEntry { +public class ReplacementEntry extends IForgeRegistryEntry.Impl + implements IReplacementEntry { + private final List matchVal; private OreSpawnBlockMatcher matcher = null; - - public ReplacementEntry(final String name, final IBlockState...toMatch) { + + public ReplacementEntry(final String name, final IBlockState... toMatch) { super.setRegistryName(name); this.matchVal = Arrays.asList(toMatch); } @@ -25,6 +27,7 @@ public ReplacementEntry(final String name, final List toMatch) { this.matchVal = new ArrayList<>(); this.matchVal.addAll(toMatch); } + @Override public OreSpawnBlockMatcher getMatcher() { if (this.matcher == null) { @@ -32,7 +35,7 @@ public OreSpawnBlockMatcher getMatcher() { } return this.matcher; } - + public List getEntries() { return ImmutableList.copyOf(this.matchVal); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 1de3f661..fdda593b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -3,11 +3,11 @@ import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; -import com.mcmoddev.orespawn.util.StateUtil; import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; +import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -15,6 +15,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; public class SpawnBuilder implements ISpawnBuilder { + private String spawnName; private boolean enabled; private boolean retrogen; @@ -23,18 +24,18 @@ public class SpawnBuilder implements ISpawnBuilder { private BiomeLocation biomes; private IDimensionList dimensions; private IReplacementEntry replacements; - + public SpawnBuilder() { this.enabled = false; this.retrogen = false; this.blocks = new BlockList(); } - + public SpawnBuilder(final String spawnName) { this(); this.spawnName = spawnName; } - + @Override public ISpawnBuilder setName(String name) { this.spawnName = name; @@ -103,8 +104,7 @@ public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation) { } @Override - public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, - String blockState) { + public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState) { return this.addBlockWithChance(blockResourceLocation, blockState, 100); } @@ -114,8 +114,7 @@ public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, */ @Override @Deprecated - public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, - int blockMetadata) { + public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata) { return this.addBlockWithChance(blockResourceLocation, 100); } @@ -131,12 +130,11 @@ public ISpawnBuilder addBlock(IBlockState block) { @Override public ISpawnBuilder addBlockWithChance(String blockName, int chance) { - return this.addBlockWithChance( new ResourceLocation(blockName), chance); + return this.addBlockWithChance(new ResourceLocation(blockName), chance); } @Override - public ISpawnBuilder addBlockWithChance(String blockName, String blockState, - int chance) { + public ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance) { return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); } @@ -146,15 +144,14 @@ public ISpawnBuilder addBlockWithChance(String blockName, String blockState, */ @Override @Deprecated - public ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, - int chance) { + public ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance) { return this.addBlockWithChance(blockName, blockMetadata, chance); } @Override - public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - int chance) { - IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState(); + public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance) { + IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @@ -174,7 +171,8 @@ public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, @Deprecated public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, int chance) { - IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(blockMetadata); + IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getStateFromMeta(blockMetadata); return this.addBlockWithChance(tempVar, chance); } @@ -191,17 +189,17 @@ public ISpawnBuilder addBlockWithChance(IBlockState block, int chance) { return this.addBlock(bb.create()); } - @Override + @Override public ISpawnBuilder addBlock(IBlockDefinition block) { - if(block.isValid()) { + if (block.isValid()) { this.blocks.addBlock(block); } return this; } - + @Override public SpawnEntry create() { - if(this.blocks.count() > 0) { + if (this.blocks.count() > 0) { return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, this.biomes, this.replacements, this.blocks, this.feature); } else { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 6cde1b7f..6806051a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -18,6 +18,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { + private final String spawnName; private final IDimensionList dimensions; private final IReplacementEntry replacements; @@ -26,10 +27,10 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { private final IFeatureEntry feature; private final boolean enabled; private final boolean retrogen; - + public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, final IDimensionList dimensions, final BiomeLocation biomes, - final IReplacementEntry replacements, final IBlockList blocks, + final IReplacementEntry replacements, final IBlockList blocks, final IFeatureEntry feature) { this.spawnName = spawnName; this.enabled = enabled; @@ -40,17 +41,17 @@ public SpawnEntry(final String spawnName, final boolean enabled, final boolean r this.blocks = blocks; this.feature = feature; } - + @Override public boolean isRetrogen() { return this.retrogen; } - - @Override + + @Override public boolean isEnabled() { return this.enabled; } - + @Override public String getSpawnName() { return this.spawnName; @@ -87,7 +88,8 @@ public IBlockList getBlocks() { } @Override - public void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos) { + public void generate(Random random, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider, ChunkPos pos) { this.feature.getFeature().setRandom(random); this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 87966dc4..ede68fbe 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -45,53 +45,57 @@ import net.minecraftforge.oredict.OreDictionary; public class OreSpawnReader { + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - - public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { + + public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, + NotAProperConfigException, OldVersionException, UnknownVersionException { JsonParser parser = new JsonParser(); - try(BufferedReader data = Files.newBufferedReader(conf)) { + try (BufferedReader data = Files.newBufferedReader(conf)) { JsonElement json = parser.parse(data); - - if(!json.isJsonObject()) { + + if (!json.isJsonObject()) { throw new NotAProperConfigException(); } - - + JsonObject root = json.getAsJsonObject(); - if(!root.has(Constants.ConfigNames.FILE_VERSION)) { + if (!root.has(Constants.ConfigNames.FILE_VERSION)) { throw new MissingVersionException(); } - + float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); - if( version < 2f ) { + if (version < 2f) { throw new OldVersionException(); - } else if( version != 2f ) { + } else if (version != 2f) { throw new UnknownVersionException(); } - - if( !root.has(Constants.ConfigNames.SPAWNS)) { + + if (!root.has(Constants.ConfigNames.SPAWNS)) { throw new NotAProperConfigException(); } - - JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS).getAsJsonObject(); - spawnData.entrySet().stream() - .forEach(e -> { + + JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject(); + spawnData.entrySet().stream().forEach(e -> { try { OreSpawn.API.mapEntryToFile(conf, e.getKey()); loadSingleEntry(e); } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { - CrashReport report = CrashReport.makeCrashReport(e1, "Error parsing an entry " + e.getKey() + " in " + conf.toString()); + CrashReport report = CrashReport.makeCrashReport(e1, + "Error parsing an entry " + e.getKey() + " in " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } }); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config data " + conf.toString()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config data " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch(JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + conf.toString()); + } catch (JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -99,17 +103,19 @@ public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingV private static JsonObject doHandlePresets(JsonObject spawnData) { PresetsStorage configPresets = OreSpawn.API.copyPresets(); - if(spawnData.has(Constants.ConfigNames.PRESETS)) { + if (spawnData.has(Constants.ConfigNames.PRESETS)) { spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() - .forEach( entry -> { - String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream() - .forEach( sect -> configPresets.setSymbolSection(section, sect.getKey(), sect.getValue())); - }); + .forEach(entry -> { + String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream() + .forEach(sect -> configPresets.setSymbolSection(section, + sect.getKey(), sect.getValue())); + }); } - + JsonObject spawnDataFixed = new JsonObject(); - for( Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS).getAsJsonObject().entrySet()) { + for (Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject().entrySet()) { spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); } return spawnData; @@ -118,21 +124,21 @@ private static JsonObject doHandlePresets(JsonObject spawnData) { private static JsonElement doPresetFix(JsonElement value, PresetsStorage configPresets) { if (value.isJsonObject()) { return doPresetForObject(value.getAsJsonObject(), configPresets); - } else if(value.isJsonArray()) { + } else if (value.isJsonArray()) { return doPresetForArray(value.getAsJsonArray(), configPresets); - } else if(value.isJsonPrimitive() && !value.isJsonNull()) { - if (value.getAsJsonPrimitive().isString() && - value.getAsString().matches("^\\$.*")) { + } else if (value.isJsonPrimitive() && !value.isJsonNull()) { + if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { return configPresets.get(value.getAsString()); } else { return value; } } else { - OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item "+value.toString()); + OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " + + value.toString()); return value; } } - + private static JsonElement doPresetForArray(JsonArray value, PresetsStorage configPresets) { JsonArray rv = new JsonArray(); value.forEach(it -> rv.add(doPresetFix(it, configPresets))); @@ -141,8 +147,9 @@ private static JsonElement doPresetForArray(JsonArray value, PresetsStorage conf private static JsonElement doPresetForObject(JsonObject value, PresetsStorage configPresets) { JsonObject rv = new JsonObject(); - - value.entrySet().stream().forEach( entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); + + value.entrySet().stream().forEach( + entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); return rv; } @@ -151,122 +158,139 @@ public static void loadFromJson(String name, JsonElement json) { try { loadSingleEntry(t); } catch (UnknownFieldException | BadValueException | UnknownNameException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Error parsing an manual JSON read for " + name); + CrashReport report = CrashReport.makeCrashReport(e, + "Error parsing an manual JSON read for " + name); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } } - private static void loadSingleEntry(Entry entry) throws UnknownFieldException, BadValueException, UnknownNameException { + + private static void loadSingleEntry(Entry entry) + throws UnknownFieldException, BadValueException, UnknownNameException { ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); sb.setName(entry.getKey()); - for( Entry ent : entry.getValue().getAsJsonObject().entrySet()) { - switch(ent.getKey()) { - case Constants.ConfigNames.RETROGEN: - sb.setRetrogen(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.ENABLED: - sb.setEnabled(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.DIMENSIONS: - IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); - if (ent.getValue().isJsonArray()) { - JsonArray dims = ent.getValue().getAsJsonArray(); - if(dims.size() == 0) { - // blank list, accept all overworld - db.setAcceptAllOverworld(); + for (Entry ent : entry.getValue().getAsJsonObject().entrySet()) { + switch (ent.getKey()) { + case Constants.ConfigNames.RETROGEN: + sb.setRetrogen(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.ENABLED: + sb.setEnabled(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.DIMENSIONS: + IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + if (ent.getValue().isJsonArray()) { + JsonArray dims = ent.getValue().getAsJsonArray(); + if (dims.size() == 0) { + // blank list, accept all overworld + db.setAcceptAllOverworld(); + } else { + dims.forEach(item -> { + if (item.isJsonPrimitive() + && item.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(item.getAsInt()); + } + }); + } + } else if (ent.getValue().isJsonObject()) { + loadDimensions(db, ent.getValue().getAsJsonObject()); } else { - dims.forEach(item -> { - if (item.isJsonPrimitive() && - item.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(item.getAsInt()); - } - }); + throw new BadValueException(Constants.ConfigNames.DIMENSIONS, + ent.getValue().toString()); } - } else if(ent.getValue().isJsonObject()) { - loadDimensions(db,ent.getValue().getAsJsonObject()); - } else { - throw new BadValueException(Constants.ConfigNames.DIMENSIONS, ent.getValue().toString()); - } - sb.setDimensions(db.create()); - break; - case Constants.ConfigNames.BIOMES: - if(!ent.getValue().isJsonObject()) { - throw new BadValueException(Constants.ConfigNames.BIOMES, ent.getValue().toString()); - } - IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); - loadBiomes(bb, ent.getValue().getAsJsonObject()); - sb.setBiomes(bb.create()); - break; - case Constants.ConfigNames.FEATURE: - if(ent.getValue().isJsonPrimitive() && - !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString()); - } - String featureName = ent.getValue().getAsString(); - if(!OreSpawn.API.featureExists(featureName)) { - throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); - } - fb.setFeature(featureName); - break; - case Constants.ConfigNames.REPLACEMENT: - IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); - if(!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.REPLACEMENT, ent.getValue().toString()); - } else if(ent.getValue().isJsonPrimitive() && ent.getValue().getAsJsonPrimitive().isString()) { - if(OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { - rb.setFromName(ent.getValue().getAsString()); + sb.setDimensions(db.create()); + break; + case Constants.ConfigNames.BIOMES: + if (!ent.getValue().isJsonObject()) { + throw new BadValueException(Constants.ConfigNames.BIOMES, + ent.getValue().toString()); } - } else { - for( JsonElement e : ent.getValue().getAsJsonArray() ) { - if(e.isJsonObject()) { - loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); - } else { - OreSpawn.LOGGER.error("Skipping value %s in replacements list as it is not the correct format", e.toString()); + IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); + loadBiomes(bb, ent.getValue().getAsJsonObject()); + sb.setBiomes(bb.create()); + break; + case Constants.ConfigNames.FEATURE: + if (ent.getValue().isJsonPrimitive() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.FEATURE, + ent.getValue().toString()); + } + String featureName = ent.getValue().getAsString(); + if (!OreSpawn.API.featureExists(featureName)) { + throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); + } + fb.setFeature(featureName); + break; + case Constants.ConfigNames.REPLACEMENT: + IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + if (!ent.getValue().isJsonArray() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.REPLACEMENT, + ent.getValue().toString()); + } else if (ent.getValue().isJsonPrimitive() + && ent.getValue().getAsJsonPrimitive().isString()) { + if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { + rb.setFromName(ent.getValue().getAsString()); + } + } else { + for (JsonElement e : ent.getValue().getAsJsonArray()) { + if (e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in replacements list as it is not the correct format", + e.toString()); + } } } - } - - if(rb.hasEntries()) { - sb.setReplacement(rb.create()); - } - - break; - case Constants.ConfigNames.BLOCK: - if (ent.getValue().isJsonArray()) { - for( JsonElement elem : ent.getValue().getAsJsonArray()) { - IBlockBuilder block = OreSpawn.API.getBlockBuilder(); - if (elem.isJsonObject()) { - JsonObject bl = elem.getAsJsonObject(); - if(bl.has(Constants.ConfigNames.STATE)) { - block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.STATE).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else if(bl.has(Constants.ConfigNames.METADATA)) { - block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.METADATA).getAsInt(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + + if (rb.hasEntries()) { + sb.setReplacement(rb.create()); + } + + break; + case Constants.ConfigNames.BLOCK: + if (ent.getValue().isJsonArray()) { + for (JsonElement elem : ent.getValue().getAsJsonArray()) { + IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + if (elem.isJsonObject()) { + JsonObject bl = elem.getAsJsonObject(); + if (bl.has(Constants.ConfigNames.STATE)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.STATE).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else if (bl.has(Constants.ConfigNames.METADATA)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.METADATA).getAsInt(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } + sb.addBlock(block.create()); } else { - block.setFromNameWithChance(bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + OreSpawn.LOGGER.error( + "Skipping value %s in blocks list as it is not the correct format", + elem.toString()); } - sb.addBlock(block.create()); - } else { - OreSpawn.LOGGER.error("Skipping value %s in blocks list as it is not the correct format", elem.toString()); } + } else { + throw new BadValueException(Constants.ConfigNames.BLOCK, + ent.getValue().toString()); } - } else { - throw new BadValueException(Constants.ConfigNames.BLOCK, ent.getValue().toString()); - } - case Constants.ConfigNames.PARAMETERS: - if(ent.getValue().isJsonObject()) { - ent.getValue().getAsJsonObject().entrySet().stream() - .forEach(e -> fb.setParameter(e.getKey(),e.getValue())); - } - break; - default: - throw new UnknownFieldException(ent.getKey()); + case Constants.ConfigNames.PARAMETERS: + if (ent.getValue().isJsonObject()) { + ent.getValue().getAsJsonObject().entrySet().stream() + .forEach(e -> fb.setParameter(e.getKey(), e.getValue())); + } + break; + default: + throw new UnknownFieldException(ent.getKey()); } } sb.setFeature(fb.create()); @@ -275,22 +299,22 @@ private static void loadSingleEntry(Entry entry) throws Unk private static List loadBlock(JsonObject json) { String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); - if(json.has(Constants.ConfigNames.STATE)) { + if (json.has(Constants.ConfigNames.STATE)) { Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(StateUtil.deserializeState(block, json.get(Constants.ConfigNames.STATE).getAsString())); - } else if(json.has(Constants.ConfigNames.METADATA)) { + return Arrays.asList(StateUtil.deserializeState(block, + json.get(Constants.ConfigNames.STATE).getAsString())); + } else if (json.has(Constants.ConfigNames.METADATA)) { Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); + return Arrays.asList( + block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); } - - if(blockName.startsWith("ore:")) { + + if (blockName.startsWith("ore:")) { String entry = blockName.split(":")[1]; - return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream() - .map( is -> { - Block b = Block.getBlockFromItem(is.getItem()); - return b.getStateFromMeta(is.getMetadata()); - }) - .collect(Collectors.toList())); + return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { + Block b = Block.getBlockFromItem(is.getItem()); + return b.getStateFromMeta(is.getMetadata()); + }).collect(Collectors.toList())); } Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList(block.getDefaultState()); @@ -298,10 +322,11 @@ private static List loadBlock(JsonObject json) { private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { boolean emptyWhitelist = false; - - if (biomeList.has(Constants.ConfigNames.WHITELIST) && - biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for( JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray() ) { + + if (biomeList.has(Constants.ConfigNames.WHITELIST) + && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { String xN = elem.getAsString(); if (xN.contains(":")) { @@ -309,19 +334,21 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { bb.addWhitelistEntry(xN); } else { BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addWhitelistEntry); + .forEach(bb::addWhitelistEntry); } } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); } } } else { emptyWhitelist = true; } - - if (biomeList.has(Constants.ConfigNames.BLACKLIST) && - biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for( JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { + + if (biomeList.has(Constants.ConfigNames.BLACKLIST) + && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { String xN = elem.getAsString(); if (xN.contains(":")) { @@ -329,13 +356,14 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { bb.addBlacklistEntry(xN); } else { BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addBlacklistEntry); + .forEach(bb::addBlacklistEntry); } } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", elem.getAsString()); + OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", + elem.getAsString()); } } - } else if(emptyWhitelist) { + } else if (emptyWhitelist) { // empty whitelist and blacklist - accept everything bb.setAcceptAll(); } @@ -343,31 +371,35 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { private static void loadDimensions(IDimensionBuilder db, JsonObject dimensionList) { boolean emptyWhitelist = false; - - if (dimensionList.has(Constants.ConfigNames.WHITELIST) && - dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for( JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray() ) { + + if (dimensionList.has(Constants.ConfigNames.WHITELIST) + && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { db.addWhitelistEntry(elem.getAsInt()); } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); } } } else { emptyWhitelist = true; } - - if (dimensionList.has(Constants.ConfigNames.BLACKLIST) && - dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for( JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray() ) { + + if (dimensionList.has(Constants.ConfigNames.BLACKLIST) + && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { db.addBlacklistEntry(elem.getAsInt()); } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", elem.getAsString()); + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); } } - } else if(emptyWhitelist) { + } else if (emptyWhitelist) { db.setAcceptAllOverworld(); } - } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index 7cb76d05..cf7dc35c 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -19,18 +19,16 @@ import net.minecraft.crash.CrashReport; public class OreSpawnWriter { + /* * Write out the configs as the system knows them to the 'forced-saves' directory */ public static void saveConfigs() { Map> configs = OreSpawn.API.getSpawnsByFile(); Gson gson = new GsonBuilder().setPrettyPrinting().create(); - configs.entrySet().stream() - .forEach( ent -> - saveSingle(ent.getKey(), gson) - ); + configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); } - + private static void saveSingle(Path filePath, Gson gson) { JsonObject root = new JsonObject(); root.addProperty(ConfigNames.FILE_VERSION, "2.0"); @@ -38,33 +36,36 @@ private static void saveSingle(Path filePath, Gson gson) { String k = filePath.getFileName().toString(); Path saveDir = Constants.CONFDIR.resolve("forced-saves"); Path conf = saveDir.resolve(k); - if(!saveDir.toFile().exists()) { + if (!saveDir.toFile().exists()) { saveDir.toFile().mkdirs(); } - try(BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { - OreSpawn.API.getSpawnsForFile(k).stream() - .forEach( spawnName -> { + try (BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { + OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { JsonObject thisSpawn = new JsonObject(); ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); - thisSpawn.addProperty(ConfigNames.FEATURE, spawnEntry.getFeature().getFeatureName()); + thisSpawn.addProperty(ConfigNames.FEATURE, + spawnEntry.getFeature().getFeatureName()); thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); - thisSpawn.add(ConfigNames.PARAMETERS, spawnEntry.getFeature().getFeatureParameters()); + thisSpawn.add(ConfigNames.PARAMETERS, + spawnEntry.getFeature().getFeatureParameters()); spawns.add(spawnName, thisSpawn); }); root.add(ConfigNames.SPAWNS, spawns); p.write(gson.toJson(root)); } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config data " + conf.toString()); + CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config data " + conf.toString()); report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } - + } - + public static void saveSingle(String fileName) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); saveSingle(Constants.CONFDIR.resolve(fileName), gson); diff --git a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java index e71d3aeb..bbe8ade9 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java +++ b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java @@ -6,21 +6,17 @@ import com.google.common.collect.ImmutableSet; public final class Collectors2 { - private Collectors2() {} + + private Collectors2() { + } public static Collector, ImmutableList> toImmutableList() { - return Collector.of( - ImmutableList.Builder::new, ImmutableList.Builder::add, - (left, right) -> left.addAll(right.build()), - ImmutableList.Builder::build - ); + return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); } public static Collector, ImmutableSet> toImmutableSet() { - return Collector.of( - ImmutableSet.Builder::new, ImmutableSet.Builder::add, - (left, right) -> left.addAll(right.build()), - ImmutableSet.Builder::build - ); + return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 42593a45..df8cac9f 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -6,26 +6,30 @@ import net.minecraft.block.state.IBlockState; public class StateUtil { + private StateUtil() { throw new InstantiationError("This class cannot be instantiated!"); } public static String serializeState(IBlockState state) { String string = state.toString(); - string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0)); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); if (string.equals(state.getBlock().getRegistryName().toString())) { string = "normal"; } - - OreSpawn.LOGGER.debug("State is %s (for block %s)", string, state.getBlock().getRegistryName()); + + OreSpawn.LOGGER.debug("State is %s (for block %s)", string, + state.getBlock().getRegistryName()); return string; } public static IBlockState deserializeState(Block block, String state) { for (IBlockState validState : block.getBlockState().getValidStates()) { String string = validState.toString(); - string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0)); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); if (string.equals(block.getRegistryName().toString())) { string = ""; diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index 51dad013..2724bd84 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -18,8 +18,8 @@ public class FlatBedrock implements IWorldGenerator { @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider) { + public void generate(Random random, int chunkX, int chunkZ, World world, + IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { // no need to do flat-bedrock on a "FLAT" world if (world.getWorldType() != WorldType.FLAT) { if (world.provider.getDimension() == -1) { @@ -50,9 +50,11 @@ private void genBottomPlate(World world, ChunkPos chunkPos, Block repBlock) { for (int yP = 5; yP > 0; yP--) { BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); - if (yP < plateThickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + if (yP < plateThickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP >= plateThickness && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + } else if (yP >= plateThickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { world.setBlockState(target, repBlock.getDefaultState(), 26); } } @@ -69,9 +71,11 @@ private void genTopPlate(World world, ChunkPos chunkPos, Block repBlock) { for (int yP = 126; yP > 121; yP--) { BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); - if (yP > thickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + if (yP > thickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP <= thickness && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + } else if (yP <= thickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { world.setBlockState(target, repBlock.getDefaultState(), 26); } } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 38460289..60490d79 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -1,6 +1,6 @@ package com.mcmoddev.orespawn.worldgen; -import java.util.*; +import java.util.Random; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.data.Config; @@ -8,23 +8,22 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; -import net.minecraft.world.gen.IChunkGenerator; import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.fml.common.IWorldGenerator; public class OreSpawnWorldGen implements IWorldGenerator { - + @Override - public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider) { + public void generate(Random random, int chunkX, int chunkZ, World world, + IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { int thisDim = world.provider.getDimension(); - - OreSpawn.API.getSpawns(thisDim).stream() - .filter(spawn -> spawn.isEnabled()) - .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); + + OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) + .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) + || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) + .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, + new ChunkPos(chunkX, chunkZ))); } } - - From 866f72da7a744fa6a6427ba9e1e3ed46ed40b9ab Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sat, 21 Jul 2018 06:20:15 -0700 Subject: [PATCH 055/205] Checkstyle happyness --- .../com/mcmoddev/orespawn/EventHandlers.java | 20 +++--- .../java/com/mcmoddev/orespawn/OreSpawn.java | 12 ++-- .../mcmoddev/orespawn/api/BiomeLocation.java | 2 +- .../mcmoddev/orespawn/api/FeatureBase.java | 53 +++++++-------- .../com/mcmoddev/orespawn/api/IBlockList.java | 10 +-- .../mcmoddev/orespawn/api/IDimensionList.java | 4 +- .../api/exceptions/BadValueException.java | 2 +- .../exceptions/MissingVersionException.java | 2 +- .../exceptions/NotAProperConfigException.java | 2 +- .../api/exceptions/OldVersionException.java | 2 +- .../api/exceptions/UnknownFieldException.java | 2 +- .../api/exceptions/UnknownNameException.java | 2 +- .../exceptions/UnknownVersionException.java | 2 +- .../orespawn/api/os3/IBiomeBuilder.java | 16 ++--- .../orespawn/api/os3/IBlockBuilder.java | 52 +++++++-------- .../orespawn/api/os3/IBlockDefinition.java | 6 +- .../orespawn/api/os3/IDimensionBuilder.java | 12 ++-- .../orespawn/api/os3/IFeatureBuilder.java | 22 +++---- .../orespawn/api/os3/IFeatureEntry.java | 14 ++-- .../orespawn/api/os3/IReplacementBuilder.java | 40 ++++++------ .../orespawn/api/os3/IReplacementEntry.java | 4 +- .../orespawn/api/os3/ISpawnBuilder.java | 64 +++++++++---------- .../orespawn/api/os3/ISpawnEntry.java | 24 +++---- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 54 ++++++++-------- .../orespawn/api/plugin/PluginLoader.java | 10 +-- .../orespawn/commands/AddOreCommand.java | 29 +++++---- .../orespawn/commands/ClearChunkCommand.java | 22 +++---- .../orespawn/commands/DumpBiomesCommand.java | 6 +- .../commands/WriteConfigsCommand.java | 4 +- .../com/mcmoddev/orespawn/data/Config.java | 10 +-- .../orespawn/data/FeatureRegistry.java | 24 +++---- .../orespawn/data/PresetsStorage.java | 10 +-- .../orespawn/data/ReplacementsRegistry.java | 16 ++--- .../mcmoddev/orespawn/data/VanillaOres.java | 2 +- .../impl/features/ClusterGenerator.java | 18 +++--- .../features/DefaultFeatureGenerator.java | 12 ++-- .../impl/features/NormalCloudGenerator.java | 12 ++-- .../impl/features/PrecisionGenerator.java | 38 +++++------ .../orespawn/impl/features/VeinGenerator.java | 37 +++++------ .../impl/location/BiomeLocationAcceptAny.java | 2 +- .../location/BiomeLocationComposition.java | 6 +- .../location/BiomeLocationDictionary.java | 6 +- .../impl/location/BiomeLocationEmpty.java | 2 +- .../impl/location/BiomeLocationList.java | 6 +- .../impl/location/BiomeLocationSingle.java | 6 +- .../orespawn/impl/os3/BiomeBuilder.java | 12 ++-- .../orespawn/impl/os3/BlockBuilder.java | 42 ++++++------ .../mcmoddev/orespawn/impl/os3/BlockList.java | 4 +- .../orespawn/impl/os3/DimensionBuilder.java | 10 +-- .../orespawn/impl/os3/DimensionList.java | 14 ++-- .../orespawn/impl/os3/FeatureBuilder.java | 20 +++--- .../orespawn/impl/os3/FeatureEntry.java | 10 +-- .../orespawn/impl/os3/OS3APIImpl.java | 30 ++++----- .../orespawn/impl/os3/ReplacementBuilder.java | 18 +++--- .../orespawn/impl/os3/SpawnBuilder.java | 52 +++++++-------- .../orespawn/impl/os3/SpawnEntry.java | 10 +-- .../orespawn/json/OreSpawnReader.java | 20 +++--- .../orespawn/json/OreSpawnWriter.java | 4 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 4 +- .../orespawn/worldgen/FlatBedrock.java | 10 +-- .../orespawn/worldgen/OreSpawnWorldGen.java | 4 +- 61 files changed, 490 insertions(+), 475 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 6b5da915..21879299 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -53,7 +53,7 @@ public class EventHandlers { EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) - public void onGenerateMinable(OreGenEvent.GenerateMinable event) { + public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) && vanillaEvents.contains(event.getType())) { event.setResult(Event.Result.DENY); @@ -61,7 +61,7 @@ public void onGenerateMinable(OreGenEvent.GenerateMinable event) { } @SubscribeEvent - public void onChunkSave(ChunkDataEvent.Save ev) { + public void onChunkSave(final ChunkDataEvent.Save ev) { NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); NBTTagCompound features = new NBTTagCompound(); @@ -83,13 +83,13 @@ public void onChunkSave(ChunkDataEvent.Save ev) { ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); } - private boolean dequeContains(ChunkPos cc) { + private boolean dequeContains(final ChunkPos cc) { return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) .contains(true); } @SubscribeEvent - public void onChunkLoad(ChunkDataEvent.Load ev) { + public void onChunkLoad(final ChunkDataEvent.Load ev) { World world = ev.getWorld(); ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); @@ -113,7 +113,7 @@ public void onChunkLoad(ChunkDataEvent.Load ev) { } } - private List getDifferingTags(NBTTagCompound chunkTag, int dim, Biome biome) { + private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, final Biome biome) { NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); Map currentBits = new TreeMap<>(); Map oldBits = new TreeMap<>(); @@ -135,7 +135,7 @@ private List getDifferingTags(NBTTagCompound chunkTag, int dim, Biome bi return ImmutableList.copyOf(stuff); } - private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim, Biome biome) { + private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, final Biome biome) { NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); Map currentBits = new TreeMap<>(); Map oldBits = new TreeMap<>(); @@ -153,7 +153,7 @@ private boolean featuresAreDifferent(NBTTagCompound chunkTag, int dim, Biome bio && diff.entriesOnlyOnRight().size() == 0; } - private void doBedrockRetrogen(ChunkPos chunkCoords) { + private void doBedrockRetrogen(final ChunkPos chunkCoords) { if (retroChunks.contains(chunkCoords)) { return; } @@ -168,7 +168,7 @@ private void doBedrockRetrogen(ChunkPos chunkCoords) { private static IChunkGenerator chunkGenerator; private static Random random; - private static void setupData(World nw) { + private static void setupData(final World nw) { if (world == null || !world.equals(nw)) { world = nw; } @@ -188,7 +188,7 @@ private static void setupData(World nw) { } - private void runBits(Tuple> tup) { + private void runBits(final Tuple> tup) { ChunkPos p = tup.getFirst(); List spawns = tup.getSecond(); @@ -200,7 +200,7 @@ private void runBits(Tuple> tup) { } @SubscribeEvent - public void worldTick(WorldTickEvent ev) { + public void worldTick(final WorldTickEvent ev) { setupData(ev.world); if (ev.side != Side.SERVER) { diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 1039363a..230e7d5b 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -33,7 +33,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry; /** - * Main entry point for the mod, everything runs through this + * Main entry point for the mod, everything runs through this. * * @author DShadowWolf <dshadowwolf@gmail.com> */ @@ -58,12 +58,12 @@ public static Map> getSpawns() { } @EventHandler - public void onFingerprintViolation(FMLFingerprintViolationEvent event) { + public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { LOGGER.warn("Invalid fingerprint detected!"); } @EventHandler - public void preInit(FMLPreInitializationEvent ev) { + public void preInit(final FMLPreInitializationEvent ev) { Config.loadConfig(); PluginLoader.INSTANCE.load(ev); @@ -83,19 +83,19 @@ public void preInit(FMLPreInitializationEvent ev) { } @EventHandler - public void init(FMLInitializationEvent ev) { + public void init(final FMLInitializationEvent ev) { PluginLoader.INSTANCE.register(); API.loadConfigFiles(); } @EventHandler - public void postInit(FMLPostInitializationEvent ev) { + public void postInit(final FMLPostInitializationEvent ev) { Config.saveConfig(); } @EventHandler - public void onServerStarting(FMLServerStartingEvent ev) { + public void onServerStarting(final FMLServerStartingEvent ev) { ev.registerServerCommand(new ClearChunkCommand()); ev.registerServerCommand(new DumpBiomesCommand()); ev.registerServerCommand(new AddOreCommand()); diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index 2d5035d5..6870c78a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -11,7 +11,7 @@ public interface BiomeLocation { boolean matches(Biome biome); - public JsonElement serialize(); + JsonElement serialize(); default ImmutableList getBiomes() { return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 8814083f..14af8539 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -26,22 +26,22 @@ public class FeatureBase extends IForgeRegistryEntry.Impl { private static final int MAX_CACHE_SIZE = 2048; /** * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk - * without triggering a chunk-load + * without triggering a chunk-load. */ private static final Map> overflowCache = new HashMap<>( MAX_CACHE_SIZE); private static final Deque cacheOrder = new LinkedList<>(); protected Random random; - public FeatureBase(Random rand) { + public FeatureBase(final Random rand) { this.random = rand; } - public boolean isValidBlock(IBlockState oreBlock) { + public boolean isValidBlock(final IBlockState oreBlock) { return oreBlock.getBlock() != Blocks.AIR; } - protected void runCache(int chunkX, int chunkZ, World world, ISpawnEntry spawnData) { + protected void runCache(final int chunkX, final int chunkZ, final World world, final ISpawnEntry spawnData) { Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); Map cache = retrieveCache(chunkCoord); @@ -53,8 +53,8 @@ protected void runCache(int chunkX, int chunkZ, World world, ISpawnEntry spawnDa } } - protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int dimension, - boolean cacheOverflow, ISpawnEntry spawnData) { + protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, + final boolean cacheOverflow, final ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return false; @@ -81,7 +81,7 @@ protected boolean spawn(IBlockState oreBlock, World world, BlockPos coord, int d spawnData); } - private BlockPos mungeFixYcoord(BlockPos coord) { + private BlockPos mungeFixYcoord(final BlockPos coord) { if (coord.getY() < 0) { int newYCoord = coord.getY() * -1; return new BlockPos(coord.getX(), newYCoord, coord.getZ()); @@ -90,8 +90,8 @@ private BlockPos mungeFixYcoord(BlockPos coord) { } } - private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher replacer, - IBlockState oreBlock, boolean cacheOverflow, int dimension, ISpawnEntry spawnData) { + private boolean spawnOrCache(final World world, final BlockPos coord, final OreSpawnBlockMatcher replacer, + final IBlockState oreBlock, final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { if (!isValidBlock(oreBlock)) { return false; @@ -114,8 +114,8 @@ private boolean spawnOrCache(World world, BlockPos coord, OreSpawnBlockMatcher r return false; } - private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int dimension, - ISpawnEntry spawnData) { + private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, + final ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return; @@ -131,7 +131,7 @@ private void spawnNoCheck(IBlockState oreBlock, World world, BlockPos coord, int spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); } - private void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension) { + private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, final int dimension) { Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); if (overflowCache.containsKey(chunkCoord)) { @@ -150,7 +150,7 @@ private void cacheOverflowBlock(IBlockState bs, BlockPos coord, int dimension) { cache.put(coord, bs); } - private Map retrieveCache(Vec3i chunkCoord) { + private Map retrieveCache(final Vec3i chunkCoord) { if (overflowCache.containsKey(chunkCoord)) { Map cache = overflowCache.get(chunkCoord); cacheOrder.remove(chunkCoord); @@ -161,7 +161,7 @@ private Map retrieveCache(Vec3i chunkCoord) { } } - protected void scramble(int[] target, Random prng) { + protected void scramble(final int[] target, final Random prng) { for (int i = target.length - 1; i > 0; i--) { int n = prng.nextInt(i); int temp = target[i]; @@ -191,14 +191,15 @@ protected void scramble(int[] target, Random prng) { 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; protected static final int[] offsetIndexRef_small = { 0, 1, 2, 3, 4, 5, 6, 7 }; - protected static void mergeDefaults(JsonObject parameters, JsonObject defaultParameters) { + protected static void mergeDefaults(final JsonObject parameters, final JsonObject defaultParameters) { defaultParameters.entrySet().forEach(entry -> { - if (!parameters.has(entry.getKey())) + if (!parameters.has(entry.getKey())) { parameters.add(entry.getKey(), entry.getValue()); + } }); } - private double triangularDistribution(double a, double b, double c) { + private double triangularDistribution(final double a, final double b, final double c) { double base = (c - a) / (b - a); double rand = this.random.nextDouble(); @@ -209,14 +210,14 @@ private double triangularDistribution(double a, double b, double c) { } } - protected int getPoint(int lowerBound, int upperBound, int median) { + protected int getPoint(final int lowerBound, final int upperBound, final int median) { int t = (int) Math.round( triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); return t - median; } - protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double radius, - ISpawnEntry spawnData, int count) { + protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, final double radius, + final ISpawnEntry spawnData, final int count) { Random prng = this.random; int quantity = count; IBlockList possibleOres = spawnData.getBlocks(); @@ -238,8 +239,8 @@ protected void spawnMungeSW(World world, BlockPos blockPos, int rSqr, double rad } } - protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double radius, - ISpawnEntry spawnData, int count) { + protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, final double radius, + final ISpawnEntry spawnData, final int count) { Random prng = this.random; int quantity = count; IBlockList possibleOres = spawnData.getBlocks(); @@ -261,19 +262,19 @@ protected void spawnMungeNE(World world, BlockPos blockPos, int rSqr, double rad } } - protected int getABC(int dx, int dy, int dz) { + protected int getABC(final int dx, final int dy, final int dz) { return (dx * dx + dy * dy + dz * dz); } - protected int countItem(int dx, boolean toPositive) { + protected int countItem(final int dx, final boolean toPositive) { return toPositive ? dx + 1 : dx - 1; } - protected boolean endCheck(boolean toPositive, int dx, double radius) { + protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); } - protected int getStart(boolean toPositive, double radius) { + protected int getStart(final boolean toPositive, final double radius) { return ((int) (radius * (toPositive ? 1 : -1))); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 699548f4..26e12bb6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -8,13 +8,13 @@ public interface IBlockList { - public void addBlock(IBlockDefinition block); + void addBlock(IBlockDefinition block); - public IBlockState getRandomBlock(Random rand); + IBlockState getRandomBlock(Random rand); - public void startNewSpawn(); + void startNewSpawn(); - public void dump(); + void dump(); - public int count(); + int count(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index 680ba327..11564819 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -4,9 +4,9 @@ public interface IDimensionList { - public JsonObject serialize(); + JsonObject serialize(); - public default boolean matches(final int dimensionId) { + default boolean matches(int dimensionId) { return false; } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index b6df0ce8..08615e79 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -6,7 +6,7 @@ public class BadValueException extends Exception { private final String keyName; private final String keyValue; - public BadValueException(String keyName, String keyValue) { + public BadValueException(final String keyName, final String keyValue) { super(); this.keyName = keyName; this.keyValue = keyValue; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java index e2446a98..8c98fffa 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java @@ -3,7 +3,7 @@ public class MissingVersionException extends Exception { /** - * + * */ private static final long serialVersionUID = -4306852267351590384L; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java index 99b6686b..2f31a433 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java @@ -3,7 +3,7 @@ public class NotAProperConfigException extends Exception { /** - * + * */ private static final long serialVersionUID = -7748241590958198482L; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java index 1d8c5f2d..62b5fa71 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java @@ -3,7 +3,7 @@ public class OldVersionException extends Exception { /** - * + * */ private static final long serialVersionUID = 3760017140789193369L; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 021f0ade..685327cf 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -5,7 +5,7 @@ public class UnknownFieldException extends Exception { private static final long serialVersionUID = 1L; private final String message; - public UnknownFieldException(String theField) { + public UnknownFieldException(final String theField) { super(); this.message = String.format("Unkown field %s in config", theField); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 41836b5b..e63a357f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -6,7 +6,7 @@ public class UnknownNameException extends Exception { private final String fieldName; private final String fieldValue; - public UnknownNameException(String fieldName, String fieldValue) { + public UnknownNameException(final String fieldName, final String fieldValue) { super(); this.fieldName = fieldName; this.fieldValue = fieldValue; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java index 0ac73287..fa369ca9 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java @@ -3,7 +3,7 @@ public class UnknownVersionException extends Exception { /** - * + * */ private static final long serialVersionUID = 3817238409227005355L; diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index f5f166ac..1bda5db5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -7,19 +7,19 @@ public interface IBiomeBuilder { - public IBiomeBuilder addWhitelistEntry(final Biome biome); + IBiomeBuilder addWhitelistEntry(Biome biome); - public IBiomeBuilder addWhitelistEntry(final String biomeName); + IBiomeBuilder addWhitelistEntry(String biomeName); - public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation); + IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); - public IBiomeBuilder addBlacklistEntry(Biome biome); + IBiomeBuilder addBlacklistEntry(Biome biome); - public IBiomeBuilder addBlacklistEntry(final String biomeName); + IBiomeBuilder addBlacklistEntry(String biomeName); - public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation); + IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); - public IBiomeBuilder setAcceptAll(); + IBiomeBuilder setAcceptAll(); - public BiomeLocation create(); + BiomeLocation create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 7712e3b5..768e3bc6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -11,21 +11,21 @@ public interface IBlockBuilder { * @param blockState * @return */ - public IBlockBuilder setFromBlockState(final IBlockState blockState); + IBlockBuilder setFromBlockState(IBlockState blockState); /** * * @param block * @return */ - public IBlockBuilder setFromBlock(final Block block); + IBlockBuilder setFromBlock(Block block); /** * * @param blockName * @return */ - public IBlockBuilder setFromName(final String blockName); + IBlockBuilder setFromName(String blockName); /** * @@ -33,7 +33,7 @@ public interface IBlockBuilder { * @param state * @return */ - public IBlockBuilder setFromName(final String blockName, final String state); + IBlockBuilder setFromName(String blockName, String state); /** * @@ -43,14 +43,14 @@ public interface IBlockBuilder { * @deprecated */ @Deprecated - public IBlockBuilder setFromName(final String blockName, final int metadata); + IBlockBuilder setFromName(String blockName, int metadata); /** * * @param blockResourceLocation * @return */ - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation); + IBlockBuilder setFromName(ResourceLocation blockResourceLocation); /** * @@ -58,8 +58,8 @@ public interface IBlockBuilder { * @param state * @return */ - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final String state); + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, + String state); /** * @@ -69,8 +69,8 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, * @deprecated */ @Deprecated - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final int metadata); + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, + int metadata); /** * @@ -78,8 +78,8 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, * @param chance * @return */ - public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, - final int chance); + IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, + int chance); /** * @@ -87,7 +87,7 @@ public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, * @param chance * @return */ - public IBlockBuilder setFromBlockWithChance(final Block block, final int chance); + IBlockBuilder setFromBlockWithChance(Block block, int chance); /** * @@ -95,7 +95,7 @@ public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final String blockName, final int chance); + IBlockBuilder setFromNameWithChance(String blockName, int chance); /** * @@ -104,8 +104,8 @@ public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final String blockName, final String state, - final int chance); + IBlockBuilder setFromNameWithChance(String blockName, String state, + int chance); /** * @@ -116,8 +116,8 @@ public IBlockBuilder setFromNameWithChance(final String blockName, final String * @deprecated */ @Deprecated - public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, - final int chance); + IBlockBuilder setFromNameWithChance(String blockName, int metadata, + int chance); /** * @@ -125,8 +125,8 @@ public IBlockBuilder setFromNameWithChance(final String blockName, final int met * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, + int chance); /** * @@ -135,8 +135,8 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL * @param chance * @return */ - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final String state, final int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, + String state, int chance); /** * @@ -147,19 +147,19 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL * @deprecated */ @Deprecated - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int metadata, final int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, + int metadata, int chance); /** * * @param chance * @return */ - public IBlockBuilder setChance(int chance); + IBlockBuilder setChance(int chance); /** * * @return */ - public IBlockDefinition create(); + IBlockDefinition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index 5d026876..03bec55b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -4,11 +4,11 @@ public interface IBlockDefinition { - public IBlockState getBlock(); + IBlockState getBlock(); - public int getChance(); + int getChance(); - public default boolean isValid() { + default boolean isValid() { return true; } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java index 67566a36..1fe97bb7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -4,15 +4,15 @@ public interface IDimensionBuilder { - public IDimensionBuilder addWhitelistEntry(final int dimensionID); + IDimensionBuilder addWhitelistEntry(int dimensionID); - public IDimensionBuilder addBlacklistEntry(final int dimensionID); + IDimensionBuilder addBlacklistEntry(int dimensionID); - public IDimensionBuilder setAcceptAll(); + IDimensionBuilder setAcceptAll(); - public IDimensionBuilder setDenyAll(); + IDimensionBuilder setDenyAll(); - public IDimensionBuilder setAcceptAllOverworld(); + IDimensionBuilder setAcceptAllOverworld(); - public IDimensionList create(); + IDimensionList create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index f59f6836..34c45c1c 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -7,24 +7,24 @@ public interface IFeatureBuilder { - public IFeatureBuilder setFeature(final String featureName); + IFeatureBuilder setFeature(String featureName); - public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation); + IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); - public IFeatureBuilder setFeature(final IFeature feature); + IFeatureBuilder setFeature(IFeature feature); - public IFeatureBuilder setParameter(final String parameterName, final String parameterValue); + IFeatureBuilder setParameter(String parameterName, String parameterValue); - public IFeatureBuilder setParameter(final String parameterName, final int parameterValue); + IFeatureBuilder setParameter(String parameterName, int parameterValue); - public IFeatureBuilder setParameter(final String parameterName, final float parameterValue); + IFeatureBuilder setParameter(String parameterName, float parameterValue); - public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue); + IFeatureBuilder setParameter(String parameterName, boolean parameterValue); - public IFeatureBuilder setParameter(final String parameterName, - final JsonElement parameterValue); + IFeatureBuilder setParameter(String parameterName, + JsonElement parameterValue); - public IFeatureBuilder setUseFeatureDefaults(); + IFeatureBuilder setUseFeatureDefaults(); - public IFeatureEntry create(); + IFeatureEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java index be2ab909..6f5fb06b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java @@ -5,17 +5,17 @@ public interface IFeatureEntry { - public IFeature getFeature(); + IFeature getFeature(); - public String getFeatureName(); + String getFeatureName(); - public JsonObject getFeatureParameters(); + JsonObject getFeatureParameters(); - public void setParameter(final String parameterName, final String parameterValue); + void setParameter(String parameterName, String parameterValue); - public void setParameter(final String parameterName, final int parameterValue); + void setParameter(String parameterName, int parameterValue); - public void setParameter(final String parameterName, final boolean parameterValue); + void setParameter(String parameterName, boolean parameterValue); - public void setParameter(final String parameterName, final float parameterValue); + void setParameter(String parameterName, float parameterValue); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index e10626e2..275f58dd 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -6,57 +6,57 @@ public interface IReplacementBuilder { /** - * + * * @param entryName * @return */ - public IReplacementBuilder setFromName(final String entryName); + IReplacementBuilder setFromName(String entryName); /** - * + * * @param name * @return */ - public IReplacementBuilder setName(final String name); + IReplacementBuilder setName(String name); /** - * + * * @param blockState * @return */ - public IReplacementBuilder addEntry(final IBlockState blockState); + IReplacementBuilder addEntry(IBlockState blockState); /** - * + * * @param blockName * @return */ - public IReplacementBuilder addEntry(final String blockName); + IReplacementBuilder addEntry(String blockName); /** - * + * * @param blockName * @param state * @return */ - public IReplacementBuilder addEntry(final String blockName, final String state); + IReplacementBuilder addEntry(String blockName, String state); /** - * + * * @param blockName * @param metadata * @return * @deprecated */ @Deprecated - public IReplacementBuilder addEntry(final String blockName, final int metadata); + IReplacementBuilder addEntry(String blockName, int metadata); /** - * + * * @param blockResourceLocation * @return */ - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation); + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); /** * @@ -64,8 +64,8 @@ public interface IReplacementBuilder { * @param state * @return */ - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final String state); + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, + String state); /** * @@ -75,10 +75,10 @@ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation * @deprecated */ @Deprecated - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final int metadata); + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, + int metadata); - public boolean hasEntries(); + boolean hasEntries(); - public IReplacementEntry create(); + IReplacementEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index cf79864a..e9f03f91 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -7,7 +7,7 @@ public interface IReplacementEntry extends IForgeRegistryEntry { - public OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - public List getEntries(); + List getEntries(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 07362966..027b1c70 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -9,60 +9,60 @@ public interface ISpawnBuilder { - public ISpawnBuilder setName(final String name); + ISpawnBuilder setName(String name); - public ISpawnBuilder setDimensions(final IDimensionList dimensions); + ISpawnBuilder setDimensions(IDimensionList dimensions); - public ISpawnBuilder setBiomes(final BiomeLocation biomes); + ISpawnBuilder setBiomes(BiomeLocation biomes); - public ISpawnBuilder setEnabled(final boolean enabled); + ISpawnBuilder setEnabled(boolean enabled); - public ISpawnBuilder setRetrogen(final boolean retrogen); + ISpawnBuilder setRetrogen(boolean retrogen); - public ISpawnBuilder setReplacement(final IReplacementEntry replacements); + ISpawnBuilder setReplacement(IReplacementEntry replacements); - public ISpawnBuilder setFeature(final IFeatureEntry feature); + ISpawnBuilder setFeature(IFeatureEntry feature); - public ISpawnBuilder addBlock(final String blockName); + ISpawnBuilder addBlock(String blockName); - public ISpawnBuilder addBlock(final String blockName, final String blockState); + ISpawnBuilder addBlock(String blockName, String blockState); - public ISpawnBuilder addBlock(final String blockName, final int blockMetadata); + ISpawnBuilder addBlock(String blockName, int blockMetadata); - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final String blockState); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, + String blockState); - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final int blockMetadata); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, + int blockMetadata); - public ISpawnBuilder addBlock(final Block block); + ISpawnBuilder addBlock(Block block); - public ISpawnBuilder addBlock(final IBlockState block); + ISpawnBuilder addBlock(IBlockState block); - public ISpawnBuilder addBlockWithChance(final String blockName, final int chance); + ISpawnBuilder addBlockWithChance(String blockName, int chance); - public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, - final int chance); + ISpawnBuilder addBlockWithChance(String blockName, String blockState, + int chance); - public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, - final int chance); + ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, + int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final String blockState, final int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + String blockState, int chance); - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int blockMetadata, final int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, + int blockMetadata, int chance); - public ISpawnBuilder addBlockWithChance(final Block block, final int chance); + ISpawnBuilder addBlockWithChance(Block block, int chance); - public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance); + ISpawnBuilder addBlockWithChance(IBlockState block, int chance); - public ISpawnEntry create(); + ISpawnEntry create(); - public ISpawnBuilder addBlock(IBlockDefinition block); + ISpawnBuilder addBlock(IBlockDefinition block); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index d5cafb30..7fdaceb4 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -15,32 +15,32 @@ public interface ISpawnEntry { - public default boolean isEnabled() { + default boolean isEnabled() { return false; } - public default boolean isRetrogen() { + default boolean isRetrogen() { return false; } - public String getSpawnName(); + String getSpawnName(); - public boolean dimensionAllowed(final int dimension); + boolean dimensionAllowed(int dimension); - public boolean biomeAllowed(final ResourceLocation biomeName); + boolean biomeAllowed(ResourceLocation biomeName); - public boolean biomeAllowed(final Biome biome); + boolean biomeAllowed(Biome biome); - public IFeatureEntry getFeature(); + IFeatureEntry getFeature(); - public OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - public IBlockList getBlocks(); + IBlockList getBlocks(); - public void generate(Random random, World world, IChunkGenerator chunkGenerator, + void generate(Random random, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, ChunkPos pos); - public IDimensionList getDimensions(); + IDimensionList getDimensions(); - public BiomeLocation getBiomes(); + BiomeLocation getBiomes(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index a01ebd5d..aba87455 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -12,55 +12,55 @@ public interface OS3API { - public void addSpawn(ISpawnEntry spawnEntry); + void addSpawn(ISpawnEntry spawnEntry); - public void addFeature(String featureName, IFeature feature); + void addFeature(String featureName, IFeature feature); - public void addReplacement(IReplacementEntry replacementEntry); + void addReplacement(IReplacementEntry replacementEntry); - public Map getReplacements(); + Map getReplacements(); - public IReplacementEntry getReplacement(String replacementName); + IReplacementEntry getReplacement(String replacementName); - public List getSpawns(int dimensionID); + List getSpawns(int dimensionID); - public ISpawnEntry getSpawn(String spawnName); + ISpawnEntry getSpawn(String spawnName); - public Map getAllSpawns(); + Map getAllSpawns(); - public List getDimensionDefaultReplacements(int dimensionID); + List getDimensionDefaultReplacements(int dimensionID); - public ISpawnBuilder getSpawnBuilder(); + ISpawnBuilder getSpawnBuilder(); - public IDimensionBuilder getDimensionBuilder(); + IDimensionBuilder getDimensionBuilder(); - public IFeatureBuilder getFeatureBuilder(); + IFeatureBuilder getFeatureBuilder(); - public IBlockBuilder getBlockBuilder(); + IBlockBuilder getBlockBuilder(); - public IBiomeBuilder getBiomeBuilder(); + IBiomeBuilder getBiomeBuilder(); - public IReplacementBuilder getReplacementBuilder(); + IReplacementBuilder getReplacementBuilder(); - public boolean featureExists(String featureName); + boolean featureExists(String featureName); - public boolean featureExists(ResourceLocation featureName); + boolean featureExists(ResourceLocation featureName); - public IFeature getFeature(String featureName); + IFeature getFeature(String featureName); - public IFeature getFeature(ResourceLocation featureName); + IFeature getFeature(ResourceLocation featureName); - public PresetsStorage copyPresets(); + PresetsStorage copyPresets(); - public void loadConfigFiles(); + void loadConfigFiles(); - public boolean hasReplacement(ResourceLocation resourceLocation); + boolean hasReplacement(ResourceLocation resourceLocation); - public boolean hasReplacement(String name); + boolean hasReplacement(String name); - public void mapEntryToFile(Path p, String entryName); + void mapEntryToFile(Path p, String entryName); - public List getSpawnsForFile(String fileName); + List getSpawnsForFile(String fileName); - public Map> getSpawnsByFile(); -} \ No newline at end of file + Map> getSpawnsByFile(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index ce900c18..46a7dd81 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -39,7 +39,7 @@ private class PluginData { public final String resourcePath; public final IOreSpawnPlugin plugin; - public PluginData(String modId, String resourcePath, IOreSpawnPlugin plugin) { + PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { this.modId = modId; this.resourcePath = resourcePath; this.plugin = plugin; @@ -48,7 +48,7 @@ public PluginData(String modId, String resourcePath, IOreSpawnPlugin plugin) { private static List dataStore = new ArrayList<>(); - private String getAnnotationItem(String item, final ASMData asmData) { + private String getAnnotationItem(final String item, final ASMData asmData) { if (asmData.getAnnotationInfo().get(item) != null) { return asmData.getAnnotationInfo().get(item).toString(); } else { @@ -56,7 +56,7 @@ private String getAnnotationItem(String item, final ASMData asmData) { } } - public void load(FMLPreInitializationEvent event) { + public void load(final FMLPreInitializationEvent event) { for (final ASMData asmDataItem : event.getAsmData() .getAll(OreSpawnPlugin.class.getCanonicalName())) { final String modId = getAnnotationItem("modid", asmDataItem); @@ -81,7 +81,7 @@ public void register() { }); } - public void scanResources(PluginData pd) { + public void scanResources(final PluginData pd) { if (Config.getKnownMods().contains(pd.modId)) { return; } @@ -124,7 +124,7 @@ public void scanResources(PluginData pd) { Config.addKnownMod(pd.modId); } - private void copyout(Path myPath, String modId) { + private void copyout(final Path myPath, final String modId) { try (Stream walk = Files.walk(myPath, 1)) { for (Iterator it = walk.iterator(); it.hasNext();) { Path p = it.next(); diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 13d8c62f..e3820e8f 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -32,12 +32,12 @@ public String getName() { } @Override - public String getUsage(ICommandSender sender) { + public String getUsage(final ICommandSender sender) { return "/addore "; } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) + public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); @@ -66,27 +66,34 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); } - private JsonElement mergeDefaults(JsonElement parse, IBlockState state) { + private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { JsonObject work = parse.getAsJsonObject(); JsonObject emptyBlacklist = new JsonObject(); emptyBlacklist.add("excludes", new JsonArray()); - if (!work.has(ConfigNames.ENABLED)) + if (!work.has(ConfigNames.ENABLED)) { work.addProperty(ConfigNames.ENABLED, true); - if (!work.has(ConfigNames.RETROGEN)) + } + if (!work.has(ConfigNames.RETROGEN)) { work.addProperty(ConfigNames.RETROGEN, false); - if (!work.has(ConfigNames.FEATURE)) + } + if (!work.has(ConfigNames.FEATURE)) { work.addProperty(ConfigNames.FEATURE, "default"); - if (!work.has(ConfigNames.REPLACEMENT)) + } + if (!work.has(ConfigNames.REPLACEMENT)) { work.addProperty(ConfigNames.REPLACEMENT, "default"); - if (!work.has(ConfigNames.PARAMETERS)) + } + if (!work.has(ConfigNames.PARAMETERS)) { work.add(ConfigNames.PARAMETERS, OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) .getDefaultParameters()); - if (!work.has(ConfigNames.DIMENSIONS)) + } + if (!work.has(ConfigNames.DIMENSIONS)) { work.add(ConfigNames.DIMENSIONS, emptyBlacklist); - if (!work.has(ConfigNames.BIOMES)) + } + if (!work.has(ConfigNames.BIOMES)) { work.add(ConfigNames.BIOMES, emptyBlacklist); + } JsonObject block = new JsonObject(); block.addProperty(ConfigNames.CHANCE, 100); @@ -98,7 +105,7 @@ private JsonElement mergeDefaults(JsonElement parse, IBlockState state) { } @Override - public int compareTo(ICommand command) { + public int compareTo(final ICommand command) { return this.getName().compareTo(command.getName()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 464d6ecb..eec4849c 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -46,12 +46,12 @@ public String getName() { } @Override - public String getUsage(ICommandSender sender) { + public String getUsage(final ICommandSender sender) { return "/clearchunk "; } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) + public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); @@ -59,10 +59,10 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args EntityPlayer player = (EntityPlayer) sender; Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); - ChunkPos chunkPos = chunk.getPos(); + final ChunkPos chunkPos = chunk.getPos(); List blocks; - boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") + final boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false; List blockNames = new LinkedList<>(); @@ -88,8 +88,8 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); } - private void clearBlocks(ChunkPos chunkPos, List blocks, - List overburden, boolean flagClassic, EntityPlayer player) { + private void clearBlocks(final ChunkPos chunkPos, final List blocks, + final List overburden, final boolean flagClassic, final EntityPlayer player) { for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { @@ -102,7 +102,7 @@ private void clearBlocks(ChunkPos chunkPos, List blocks, } } - private void removeIfFluid(BlockPos pos, EntityPlayer player) { + private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { IBlockState bs = player.getEntityWorld().getBlockState(pos); @@ -112,15 +112,15 @@ private void removeIfFluid(BlockPos pos, EntityPlayer player) { } } - private void removeIfBlocks(EntityPlayer player, BlockPos pos, IBlockState block, - List blocks, List overburden, boolean flagClassic) { + private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, final IBlockState block, + final List blocks, final List overburden, final boolean flagClassic) { if (blocks.contains(block) || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { player.getEntityWorld().setBlockToAir(pos); } } - private void getBlocks(String[] args, List blockNames) { + private void getBlocks(final String[] args, final List blockNames) { if (args.length > 0) { switch (args[0].toLowerCase()) { case "viewores": @@ -154,7 +154,7 @@ private void getBlocks(String[] args, List blockNames) { } @Override - public int compareTo(ICommand command) { + public int compareTo(final ICommand command) { return this.getName().compareTo(command.getName()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 9f7029c2..70d57487 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -29,12 +29,12 @@ public String getName() { } @Override - public String getUsage(ICommandSender sender) { + public String getUsage(final ICommandSender sender) { return "/dumpbiomes"; } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) + public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException { JsonArray array = new JsonArray(); @@ -56,7 +56,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args } @Override - public int compareTo(ICommand command) { + public int compareTo(final ICommand command) { return this.getName().compareTo(command.getName()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index c56f6e8e..ed4de9c8 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -16,12 +16,12 @@ public String getName() { } @Override - public String getUsage(ICommandSender sender) { + public String getUsage(final ICommandSender sender) { return "/osSaveConfigs"; } @Override - public void execute(MinecraftServer server, ICommandSender sender, String[] args) + public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException { sender.sendMessage(new TextComponentString( "Forcing configs as OreSpawn sees them to be written to disk")); diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 5d17f2b8..485dd031 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -91,11 +91,11 @@ public static List getKnownMods() { return ImmutableList.copyOf(extractedConfigs); } - public static void addKnownMod(String modId) { + public static void addKnownMod(final String modId) { extractedConfigs.add(modId); } - public static boolean getBoolean(String keyname) { + public static boolean getBoolean(final String keyname) { if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { return boolVals.get(keyname); } @@ -103,7 +103,7 @@ public static boolean getBoolean(String keyname) { return false; } - public static String getString(String keyname) { + public static String getString(final String keyname) { if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { return stringVals.get(keyname); } @@ -111,7 +111,7 @@ public static String getString(String keyname) { return ""; } - public static int getInt(String keyname) { + public static int getInt(final String keyname) { if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { return intVals.get(keyname); } @@ -119,7 +119,7 @@ public static int getInt(String keyname) { return 0; } - public static float getFloat(String keyname) { + public static float getFloat(final String keyname) { if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { return floatVals.get(keyname); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 160df56e..4f22961a 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -46,15 +46,15 @@ public Map getFeatures() { return Collections.unmodifiableMap(tempMap); } - public String getFeatureName(IFeature feature) { + public String getFeatureName(final IFeature feature) { return feature.getRegistryName().toString(); } - public IFeature getFeature(String name) { + public IFeature getFeature(final String name) { return getFeature(new ResourceLocation(name)); } - public IFeature getFeature(ResourceLocation featureResourceLocation) { + public IFeature getFeature(final ResourceLocation featureResourceLocation) { ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); if (registry.containsKey(featureResourceLocation)) { return registry.getValue(featureResourceLocation); @@ -63,28 +63,28 @@ public IFeature getFeature(ResourceLocation featureResourceLocation) { } } - public boolean hasFeature(String name) { + public boolean hasFeature(final String name) { return hasFeature(new ResourceLocation(name)); } - public boolean hasFeature(ResourceLocation featureResourceLocation) { + public boolean hasFeature(final ResourceLocation featureResourceLocation) { return registry.containsKey(featureResourceLocation); } - public boolean hasFeature(IFeature feature) { + public boolean hasFeature(final IFeature feature) { return registry.containsKey(feature.getRegistryName()); } - public void addFeature(String name, IFeature feature) { + public void addFeature(final String name, final IFeature feature) { feature.setRegistryName(new ResourceLocation("orespawn", name)); registry.register(feature); } - public void addFeature(JsonObject entry) { + public void addFeature(final JsonObject entry) { addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); } - public void addFeature(String name, String className) { + public void addFeature(final String name, final String className) { IFeature feature = getInstance(className); if (feature != null && !hasFeature(name)) { @@ -92,7 +92,7 @@ public void addFeature(String name, String className) { } } - private static IFeature getInstance(String className) { + private static IFeature getInstance(final String className) { Class featureClazz; Constructor featureCons; IFeature feature; @@ -113,7 +113,7 @@ private static IFeature getInstance(String className) { return feature; } - public void loadFeaturesFile(File file) { + public void loadFeaturesFile(final File file) { JsonParser parser = new JsonParser(); String rawJson; JsonArray elements; @@ -135,7 +135,7 @@ public void loadFeaturesFile(File file) { } } - public void writeFeatures(File file) { + public void writeFeatures(final File file) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonArray root = new JsonArray(); diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index 33bfa006..b6468191 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -28,14 +28,14 @@ public PresetsStorage() { storage = new TreeMap<>(); } - public void setSymbolSection(String sectionName, String itemName, JsonElement value) { + public void setSymbolSection(final String sectionName, final String itemName, final JsonElement value) { Map temp = storage.getOrDefault(sectionName, new HashMap()); temp.put(itemName, value); storage.put(sectionName, temp); } - public JsonElement getSymbolSection(String sectionName, String itemName) { + public JsonElement getSymbolSection(final String sectionName, final String itemName) { if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { return storage.get(sectionName).get(itemName); } else { @@ -43,7 +43,7 @@ public JsonElement getSymbolSection(String sectionName, String itemName) { } } - public void copy(PresetsStorage dest) { + public void copy(final PresetsStorage dest) { storage.entrySet().stream().forEach(ensm -> { String section = ensm.getKey(); ensm.getValue().entrySet().forEach( @@ -55,7 +55,7 @@ public void clear() { this.storage.clear(); } - public void load(Path inputFile) { + public void load(final Path inputFile) { JsonParser p = new JsonParser(); JsonElement parsed = null; @@ -82,7 +82,7 @@ public void load(Path inputFile) { } } - public JsonElement get(String asString) { + public JsonElement get(final String asString) { Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); Matcher m = p.matcher(asString); if (m.matches()) { diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 6fe63c96..ebc6cc51 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -62,7 +62,7 @@ public Map getReplacements() { * @deprecated */ @Deprecated - public List getDimensionDefault(int dimension) { + public List getDimensionDefault(final int dimension) { String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; List mineralogyOres = OreDictionary.getOres("cobblestone").stream() .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) @@ -84,7 +84,7 @@ public List getDimensionDefault(int dimension) { return baseRv; } - public IReplacementEntry getReplacement(String name) { + public IReplacementEntry getReplacement(final String name) { ResourceLocation act = new ResourceLocation( name.contains(":") ? name : String.format("orespawn:%s", name)); if (registry.containsKey(act)) { @@ -94,7 +94,7 @@ public IReplacementEntry getReplacement(String name) { } } - public void addBlock(String name, String blockName, String blockState) { + public void addBlock(final String name, final String blockName, final String blockState) { IBlockState b = StateUtil.deserializeState( ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); addBlock(name, b); @@ -108,11 +108,11 @@ public Map> getBlocks() { return Collections.unmodifiableMap(tempMap); } - public void addReplacement(IReplacementEntry replacement) { + public void addReplacement(final IReplacementEntry replacement) { registry.register(replacement); } - public void addBlock(String name, IBlockState state) { + public void addBlock(final String name, final IBlockState state) { ResourceLocation regName = new ResourceLocation(name); if (registry.containsKey(regName)) { IReplacementEntry old = registry.getValue(regName); @@ -131,7 +131,7 @@ public void addBlock(String name, IBlockState state) { } @SuppressWarnings("deprecation") - public void loadFile(Path file) { + public void loadFile(final Path file) { JsonParser parser = new JsonParser(); JsonObject elements; String rawJson; @@ -192,7 +192,7 @@ public void loadFile(Path file) { }); } - public void saveFile(String modName) { + public void saveFile(final String modName) { JsonObject outs = new JsonObject(); registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) @@ -225,7 +225,7 @@ public void saveFile(String modName) { } } - public boolean has(ResourceLocation resourceLocation) { + public boolean has(final ResourceLocation resourceLocation) { return registry.containsKey(resourceLocation); } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java index 52c0f2f3..e04934b2 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java +++ b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java @@ -8,7 +8,7 @@ public class VanillaOres implements IOreSpawnPlugin { @Override - public void register(OS3API apiInterface) { + public void register(final OS3API apiInterface) { // nothing for us to do - all of our ores are in the // jar and the code handles that } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 42d8c698..74c750ba 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -19,7 +19,7 @@ public class ClusterGenerator extends FeatureBase implements IFeature { - private ClusterGenerator(Random rand) { + private ClusterGenerator(final Random rand) { super(rand); } @@ -28,8 +28,8 @@ public ClusterGenerator() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ISpawnEntry spawnData, final ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -81,8 +81,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private void spawnCluster(int clusterSize, int variance, int clusterCount, int maxSpread, - int minHeight, int maxHeight, ISpawnEntry spawnData, World world, BlockPos pos) { + private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, final int maxSpread, + final int minHeight, final int maxHeight, final ISpawnEntry spawnData, final World world, final BlockPos pos) { // spawn a cluster at the center, then a bunch around the outside... int r = clusterSize - variance; @@ -119,7 +119,7 @@ private void spawnCluster(int clusterSize, int variance, int clusterCount, int m } } - private void spawnChunk(World world, BlockPos pos, ISpawnEntry spawnData, int quantity) { + private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, final int quantity) { int count = quantity; int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -159,8 +159,8 @@ private void spawnChunk(World world, BlockPos pos, ISpawnEntry spawnData, int qu doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnData, World world, - BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, final ISpawnEntry spawnData, final World world, + final BlockPos pos) { int count = quantity; double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int) (radius * radius); @@ -172,7 +172,7 @@ private void doSpawnFill(boolean nextBoolean, int quantity, ISpawnEntry spawnDat } @Override - public void setRandom(Random rand) { + public void setRandom(final Random rand) { this.random = rand; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index fa18ad07..e93fe872 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -23,8 +23,8 @@ public DefaultFeatureGenerator() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ISpawnEntry spawnData, final ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -80,7 +80,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } - private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quantity) { + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -105,8 +105,8 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, - BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, + final BlockPos pos) { int count = quantity; double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int) (radius * radius); @@ -129,7 +129,7 @@ public JsonObject getDefaultParameters() { } @Override - public void setRandom(Random rand) { + public void setRandom(final Random rand) { this.random = rand; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 0919218e..4acccede 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -17,7 +17,7 @@ public class NormalCloudGenerator extends FeatureBase implements IFeature { - private NormalCloudGenerator(Random rand) { + private NormalCloudGenerator(final Random rand) { super(rand); } @@ -26,8 +26,8 @@ public NormalCloudGenerator() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ISpawnEntry spawnData, final ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -115,8 +115,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight, BlockPos pos, - ISpawnEntry spawnData, World world) { + private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, final int maxHeight, final BlockPos pos, + final ISpawnEntry spawnData, final World world) { // spawn one right at the center here, then generate for the cloud and do the math if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, @@ -161,7 +161,7 @@ private boolean spawnCloud(int size, int maxSpread, int minHeight, int maxHeight } @Override - public void setRandom(Random rand) { + public void setRandom(final Random rand) { this.random = rand; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 77d2c0ab..b1e77086 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -20,7 +20,7 @@ public class PrecisionGenerator extends FeatureBase implements IFeature { - private PrecisionGenerator(Random rand) { + private PrecisionGenerator(final Random rand) { super(rand); } @@ -29,8 +29,8 @@ public PrecisionGenerator() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ISpawnEntry spawnData, final ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -74,8 +74,8 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, ChunkPos pos, - ISpawnEntry spawnData, World world) { + private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, final ChunkPos pos, + final ISpawnEntry spawnData, final World world) { int spawned = 0; int c; @@ -97,8 +97,8 @@ private int spawnAtSpot(int nodeSize, HeightRange heightRange, BlockPos spot, Ch return spawned; } - private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, World world, - int nodeSize, HeightRange heightRange) { + private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, final World world, + final int nodeSize, final HeightRange heightRange) { int count = nodeSize; int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; @@ -131,8 +131,8 @@ private int spawnOreNode(BlockPos loc, ChunkPos pos, ISpawnEntry spawnData, Worl return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); } - private BlockPos fixMungeOffset(Vec3i offset, BlockPos spot, HeightRange heightRange, - ChunkPos pos) { + private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, final HeightRange heightRange, + final ChunkPos pos) { BlockPos p = spot.add(offset); ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); int xMax = x1z1.getXEnd(); @@ -189,8 +189,8 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini return workingPoint - centerIn; } - private int spawnFill(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, - int nodeSize, HeightRange heightRange) { + private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc, + final int nodeSize, final HeightRange heightRange) { double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int) Math.ceil(radius * radius); @@ -204,8 +204,8 @@ private int spawnFill(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos } } - private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc, - HeightRange heightRange, boolean toPositive, double radius, int rSqr, int nodeSize) { + private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc, + final HeightRange heightRange, final boolean toPositive, final double radius, final int rSqr, final int nodeSize) { int quantity = nodeSize; int nc = 0; @@ -230,8 +230,8 @@ private int spawnPrecise(ISpawnEntry spawnData, World world, ChunkPos pos, Block return nc; } - private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRange, - ISpawnEntry spawnData, World world, ChunkPos pos, BlockPos loc) { + private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, final HeightRange heightRange, + final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc) { if (getABC(dx, dy, dz) <= rSqr) { BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); @@ -241,7 +241,7 @@ private int doCheckSpawn(int dx, int dy, int dz, int rSqr, HeightRange heightRan return -1; } - private int getPoint(int lowerBound, int upperBound) { + private int getPoint(final int lowerBound, final int upperBound) { List arr = new ArrayList<>(); for (int i = lowerBound; i <= upperBound; i++) { @@ -251,7 +251,7 @@ private int getPoint(int lowerBound, int upperBound) { return arr.get(this.random.nextInt(arr.size())); } - private BlockPos chooseSpot(int xPosition, int zPosition, HeightRange heightRange) { + private BlockPos chooseSpot(final int xPosition, final int zPosition, final HeightRange heightRange) { int xRet = getPoint(0, 15) + (xPosition * 16); int zRet = getPoint(0, 15) + (zPosition * 16); int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); @@ -260,7 +260,7 @@ private BlockPos chooseSpot(int xPosition, int zPosition, HeightRange heightRang } @Override - public void setRandom(Random rand) { + public void setRandom(final Random rand) { this.random = rand; } @@ -279,7 +279,7 @@ private class HeightRange { private int min; private int max; - HeightRange(int min, int max) { + HeightRange(final int min, final int max) { this.min = min; this.max = max; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 5128f063..2efd565b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -25,7 +25,7 @@ public class VeinGenerator extends FeatureBase implements IFeature { - private VeinGenerator(Random rand) { + private VeinGenerator(final Random rand) { super(rand); } @@ -34,8 +34,8 @@ public VeinGenerator() { } @Override - public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawnData, ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ISpawnEntry spawnData, final ChunkPos _pos) { ChunkPos pos = _pos; JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -94,7 +94,7 @@ public void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider } } - private int getFaceFromString(String direction) { + private int getFaceFromString(final String direction) { String work = direction.toLowerCase(); switch (work) { case "north": @@ -124,8 +124,8 @@ private int getFaceFromString(String direction) { } } - private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos blockPos, - ISpawnEntry spawnData, World world) { + private void spawnVein(final int veinLength, final int nodeSize, final int startingFace, final BlockPos blockPos, + final ISpawnEntry spawnData, final World world) { int face = startingFace; int square = this.random.nextInt(8); BlockPos workingPos = new BlockPos(blockPos); @@ -162,7 +162,7 @@ private void spawnVein(int veinLength, int nodeSize, int startingFace, BlockPos } } - private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quantity) { + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -187,8 +187,8 @@ private void spawnOre(World world, ISpawnEntry spawnData, BlockPos pos, int quan doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnEntry spawnData, - BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, + final BlockPos pos) { int count = quantity; double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; int rSqr = (int) (radius * radius); @@ -199,7 +199,7 @@ private void doSpawnFill(boolean nextBoolean, int quantity, World world, ISpawnE } } - private int[] getDirectionValues(int face, int square) { + private int[] getDirectionValues(final int face, final int square) { int x = 0; int y = 0; int z = 0; @@ -228,12 +228,13 @@ private int[] getDirectionValues(int face, int square) { x = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); } - if (square < 3 || face == 4) + if (square < 3 || face == 4) { y = 1; - else if (square <= 5) + } else if (square <= 5) { y = 0; - else if (square <= 8 || face == 1) + } else if (square <= 8 || face == 1) { y = -1; + } return new int[] { x, y, z }; } @@ -245,7 +246,7 @@ else if (square <= 8 || face == 1) private int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; private int[] pointWeights = Arrays.stream(faceWeights).map(a -> a * 2).toArray(); - private int[] getWeighted(int face, int square) { + private int[] getWeighted(final int face, final int square) { int[] rv = new int[54]; for (int f = 0; f < 6; f++) { @@ -297,7 +298,7 @@ private int[] getWeighted(int face, int square) { * 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 * 11 */ - private int getMatchingSquare(int s, int face, int direction) { + private int getMatchingSquare(final int s, final int face, final int direction) { switch (direction) { case 0: /* LEFT */ return (s % 3 == 0) ? s + 2 : s - 1; @@ -314,11 +315,11 @@ private int getMatchingSquare(int s, int face, int direction) { private int[][] faceMap = new int[][] { { 3, 2, 1, 4 }, { 3, 2, 5, 0 }, { 1, 4, 5, 0 }, { 4, 1, 5, 0 }, { 2, 3, 5, 0 }, { 3, 2, 4, 1 } }; - private int getMatchingFace(int f, int i) { + private int getMatchingFace(final int f, final int i) { return faceMap[f][i]; } - private boolean isNeighborFace(int face, int f) { + private boolean isNeighborFace(final int face, final int f) { return Arrays.stream(faceMap[face]).anyMatch(a -> a == f); } @@ -338,7 +339,7 @@ public JsonObject getDefaultParameters() { } @Override - public void setRandom(Random rand) { + public void setRandom(final Random rand) { this.random = rand; } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java index 37a2b8e7..4577cbca 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -11,7 +11,7 @@ public class BiomeLocationAcceptAny implements BiomeLocation { @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { return true; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 35fe4e91..b887b85b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -20,14 +20,14 @@ public final class BiomeLocationComposition implements BiomeLocation { private final int hash; - public BiomeLocationComposition(BiomeLocation inclusions, BiomeLocation exclusions) { + public BiomeLocationComposition(final BiomeLocation inclusions, final BiomeLocation exclusions) { this.inclusions = inclusions; this.exclusions = exclusions; this.hash = Objects.hash(inclusions, exclusions); } @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { boolean inWhite = this.inclusions.matches(biome); boolean inBlack = this.exclusions.matches(biome); @@ -40,7 +40,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (obj == this) { return true; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java index f4433414..d45d846e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java @@ -14,13 +14,13 @@ public final class BiomeLocationDictionary implements BiomeLocation { private final int hash; - public BiomeLocationDictionary(BiomeDictionary.Type type) { + public BiomeLocationDictionary(final BiomeDictionary.Type type) { this.type = type; this.hash = type.hashCode(); } @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { return BiomeDictionary.hasType(biome, this.type); } @@ -30,7 +30,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { return (obj == this) || ((obj instanceof BiomeLocationDictionary) && this.type.equals(((BiomeLocationDictionary) obj).type)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java index ac80037c..44db55a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -9,7 +9,7 @@ public class BiomeLocationEmpty implements BiomeLocation { @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { return false; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index bf616779..ad2a75c5 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -17,13 +17,13 @@ public final class BiomeLocationList implements BiomeLocation { private final int hash; - public BiomeLocationList(ImmutableSet locations) { + public BiomeLocationList(final ImmutableSet locations) { this.locations = locations; this.hash = locations.hashCode(); } @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { return this.locations.stream().anyMatch(loc -> loc.matches(biome)); } @@ -33,7 +33,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { return (obj == this) || ((obj instanceof BiomeLocationList) && this.locations.equals(((BiomeLocationList) obj).locations)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java index a13bbeb8..0b862c70 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java @@ -13,13 +13,13 @@ public final class BiomeLocationSingle implements BiomeLocation { private final int hash; - public BiomeLocationSingle(Biome biome) { + public BiomeLocationSingle(final Biome biome) { this.biome = biome; this.hash = biome.hashCode(); } @Override - public boolean matches(Biome biome) { + public boolean matches(final Biome biome) { return this.biome.equals(biome); } @@ -34,7 +34,7 @@ public int hashCode() { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { return (obj == this) || ((obj instanceof BiomeLocationSingle) && this.biome.equals(((BiomeLocationSingle) obj).biome)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 9b8a1b0c..21ab9643 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -29,34 +29,34 @@ public BiomeBuilder() { } @Override - public IBiomeBuilder addWhitelistEntry(Biome biome) { + public IBiomeBuilder addWhitelistEntry(final Biome biome) { this.whitelist.add(biome); return this; } @Override - public IBiomeBuilder addWhitelistEntry(String biomeName) { + public IBiomeBuilder addWhitelistEntry(final String biomeName) { return this.addWhitelistEntry(new ResourceLocation(biomeName)); } @Override - public IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation) { + public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); } @Override - public IBiomeBuilder addBlacklistEntry(Biome biome) { + public IBiomeBuilder addBlacklistEntry(final Biome biome) { this.blacklist.add(biome); return this; } @Override - public IBiomeBuilder addBlacklistEntry(String biomeName) { + public IBiomeBuilder addBlacklistEntry(final String biomeName) { return this.addBlacklistEntry(new ResourceLocation(biomeName)); } @Override - public IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation) { + public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index a0e01a73..30f3472f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -20,7 +20,7 @@ public BlockBuilder() { } @Override - public IBlockBuilder setFromBlockState(IBlockState blockState) { + public IBlockBuilder setFromBlockState(final IBlockState blockState) { ResourceLocation key = blockState.getBlock().getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; @@ -29,7 +29,7 @@ public IBlockBuilder setFromBlockState(IBlockState blockState) { } @Override - public IBlockBuilder setFromBlock(Block block) { + public IBlockBuilder setFromBlock(final Block block) { ResourceLocation key = block.getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; @@ -38,22 +38,22 @@ public IBlockBuilder setFromBlock(Block block) { } @Override - public IBlockBuilder setFromName(String blockName) { + public IBlockBuilder setFromName(final String blockName) { return this.setFromName(new ResourceLocation(blockName)); } @Override - public IBlockBuilder setFromName(String blockName, String state) { + public IBlockBuilder setFromName(final String blockName, final String state) { return this.setFromName(new ResourceLocation(blockName), state); } @Override - public IBlockBuilder setFromName(String blockName, int metadata) { + public IBlockBuilder setFromName(final String blockName, final int metadata) { return this.setFromName(new ResourceLocation(blockName), metadata); } @Override - public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -61,7 +61,7 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation) { } @Override - public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state) { + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final String state) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -70,12 +70,12 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String } /** - * + * * @deprecated */ @Override @Deprecated - public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata) { + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final int metadata) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -84,7 +84,7 @@ public IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int met } @Override - public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance) { + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance) { ResourceLocation key = blockState.getBlock().getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; @@ -95,7 +95,7 @@ public IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int cha } @Override - public IBlockBuilder setFromBlockWithChance(Block block, int chance) { + public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { ResourceLocation key = block.getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; @@ -104,22 +104,22 @@ public IBlockBuilder setFromBlockWithChance(Block block, int chance) { } @Override - public IBlockBuilder setFromNameWithChance(String blockName, int chance) { + public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { return this.setFromNameWithChance(new ResourceLocation(blockName), chance); } @Override - public IBlockBuilder setFromNameWithChance(String blockName, String state, int chance) { + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, final int chance) { return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); } @Override - public IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance) { + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, final int chance) { return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); } @Override - public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -128,8 +128,8 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio } @Override - public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, - int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final String state, + final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -139,13 +139,13 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio } /** - * + * * @deprecated */ @Override @Deprecated - public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, - int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, + final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -154,7 +154,7 @@ public IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocatio } @Override - public IBlockBuilder setChance(int chance) { + public IBlockBuilder setChance(final int chance) { this.chance = chance; return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 3e1dc911..159feb93 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -21,12 +21,12 @@ public BlockList() { } @Override - public void addBlock(IBlockDefinition block) { + public void addBlock(final IBlockDefinition block) { this.myBlocks.add(block); } @Override - public IBlockState getRandomBlock(Random rand) { + public IBlockState getRandomBlock(final Random rand) { if (this.workingList.isEmpty()) { this.startNewSpawn(); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 718b836f..9467beb7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -19,14 +19,14 @@ public DimensionBuilder() { } @Override - public IDimensionBuilder addWhitelistEntry(int dimensionID) { + public IDimensionBuilder addWhitelistEntry(final int dimensionID) { this.acceptAllOverworld = false; this.dimensionWhitelist.add(dimensionID); return this; } @Override - public IDimensionBuilder addBlacklistEntry(int dimensionID) { + public IDimensionBuilder addBlacklistEntry(final int dimensionID) { this.acceptAllOverworld = false; this.dimensionBlacklist.add(dimensionID); return this; @@ -34,16 +34,18 @@ public IDimensionBuilder addBlacklistEntry(int dimensionID) { @Override public IDimensionBuilder setAcceptAll() { - if (this.denyAll) + if (this.denyAll) { this.denyAll = false; + } this.acceptAll = true; return this; } @Override public IDimensionBuilder setDenyAll() { - if (this.acceptAll) + if (this.acceptAll) { this.acceptAll = false; + } this.denyAll = true; return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 2fb978ff..7488db42 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -12,21 +12,25 @@ public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { private final List whitelist = new ArrayList<>(); private final List blacklist = new ArrayList<>(); - public DimensionList(List whitelist, List blacklist) { + public DimensionList(final List whitelist, final List blacklist) { this.whitelist.addAll(whitelist); this.blacklist.addAll(blacklist); } @Override public boolean matches(final int dimensionID) { - if (this.whitelist.contains(Integer.valueOf(dimensionID))) + if (this.whitelist.contains(Integer.valueOf(dimensionID))) { return true; - if (this.blacklist.contains(Integer.valueOf(dimensionID))) + } + if (this.blacklist.contains(Integer.valueOf(dimensionID))) { return false; - if (!this.whitelist.isEmpty()) + } + if (!this.whitelist.isEmpty()) { return false; - if (!this.blacklist.isEmpty()) + } + if (!this.blacklist.isEmpty()) { return true; + } // if it gets here, the whitelist and blacklist are empty... // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 12e2a91a..20d745fa 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -21,7 +21,7 @@ public FeatureBuilder() { } @Override - public IFeatureBuilder setFeature(String featureName) { + public IFeatureBuilder setFeature(final String featureName) { String actName = featureName; if (!actName.contains(":")) { actName = String.format("orespawn:%s", featureName); @@ -30,7 +30,7 @@ public IFeatureBuilder setFeature(String featureName) { } @Override - public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { + public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { if (!OreSpawn.API.featureExists(featureResourceLocation)) { OreSpawn.LOGGER.warn( "Feature %s is not known, feature for this will be set to the default feature", @@ -40,43 +40,43 @@ public IFeatureBuilder setFeature(ResourceLocation featureResourceLocation) { } @Override - public IFeatureBuilder setFeature(IFeature feature) { + public IFeatureBuilder setFeature(final IFeature feature) { this.feature = feature; return this; } @Override - public IFeatureBuilder setParameter(String parameterName, String parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { this.parameters.addProperty(parameterName, parameterValue); return this; } @Override - public IFeatureBuilder setParameter(String parameterName, int parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { this.parameters.addProperty(parameterName, parameterValue); return this; } @Override - public IFeatureBuilder setParameter(String parameterName, float parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { this.parameters.addProperty(parameterName, parameterValue); return this; } @Override - public IFeatureBuilder setParameter(String parameterName, boolean parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { this.parameters.addProperty(parameterName, parameterValue); return this; } @Override - public IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, final JsonElement parameterValue) { this.parameters.add(parameterName, parameterValue); return this; } - private void setFeatureParameter(String parameterName, JsonElement parameterValue, - FeatureEntry feat) { + private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, + final FeatureEntry feat) { if (parameterValue.getAsJsonPrimitive().isBoolean()) { feat.setParameter(parameterName, parameterValue.getAsBoolean()); } else if (parameterValue.getAsJsonPrimitive().isString()) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 7fbbda30..6905fdf1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -9,7 +9,7 @@ public class FeatureEntry implements IFeatureEntry { private final IFeature feature; private final JsonObject parameters; - public FeatureEntry(IFeature feature) { + public FeatureEntry(final IFeature feature) { this.feature = feature; this.parameters = new JsonObject(); } @@ -32,22 +32,22 @@ public JsonObject getFeatureParameters() { } @Override - public void setParameter(String parameterName, String parameterValue) { + public void setParameter(final String parameterName, final String parameterValue) { this.parameters.addProperty(parameterName, parameterValue); } @Override - public void setParameter(String parameterName, int parameterValue) { + public void setParameter(final String parameterName, final int parameterValue) { this.parameters.addProperty(parameterName, parameterValue); } @Override - public void setParameter(String parameterName, boolean parameterValue) { + public void setParameter(final String parameterName, final boolean parameterValue) { this.parameters.addProperty(parameterName, parameterValue); } @Override - public void setParameter(String parameterName, float parameterValue) { + public void setParameter(final String parameterName, final float parameterValue) { this.parameters.addProperty(parameterName, parameterValue); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index a7d3bd78..a7eeb37f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -115,19 +115,19 @@ public void loadConfigFiles() { } @Override - public void addSpawn(ISpawnEntry spawnEntry) { + public void addSpawn(final ISpawnEntry spawnEntry) { if (spawnEntry != null) { spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); } } @Override - public void addFeature(String featureName, IFeature feature) { + public void addFeature(final String featureName, final IFeature feature) { features.addFeature(featureName, feature); } @Override - public void addReplacement(IReplacementEntry replacementEntry) { + public void addReplacement(final IReplacementEntry replacementEntry) { replacements.addReplacement(replacementEntry); } @@ -170,19 +170,19 @@ public Map getReplacements() { } @Override - public IReplacementEntry getReplacement(String replacementName) { + public IReplacementEntry getReplacement(final String replacementName) { return replacements.getReplacement(replacementName); } @Override - public List getSpawns(int dimensionID) { + public List getSpawns(final int dimensionID) { return ImmutableList.copyOf( spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) .map(e -> e.getValue()).collect(Collectors.toList())); } @Override - public ISpawnEntry getSpawn(String spawnName) { + public ISpawnEntry getSpawn(final String spawnName) { return spawns.get(new ResourceLocation(spawnName)); } @@ -194,23 +194,23 @@ public Map getAllSpawns() { } @Override - public boolean featureExists(String featureName) { + public boolean featureExists(final String featureName) { return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName : String.format("orespawn:%s", featureName))); } @Override - public boolean featureExists(ResourceLocation featureName) { + public boolean featureExists(final ResourceLocation featureName) { return features.hasFeature(featureName); } @Override - public IFeature getFeature(String featureName) { + public IFeature getFeature(final String featureName) { return this.getFeature(new ResourceLocation(featureName)); } @Override - public IFeature getFeature(ResourceLocation featureName) { + public IFeature getFeature(final ResourceLocation featureName) { return features.getFeature(featureName); } @@ -222,28 +222,28 @@ public PresetsStorage copyPresets() { } @Override - public List getDimensionDefaultReplacements(int dimensionID) { + public List getDimensionDefaultReplacements(final int dimensionID) { return replacements.getDimensionDefault(dimensionID); } @Override - public boolean hasReplacement(ResourceLocation resourceLocation) { + public boolean hasReplacement(final ResourceLocation resourceLocation) { return replacements.has(resourceLocation); } @Override - public boolean hasReplacement(String name) { + public boolean hasReplacement(final String name) { return this.hasReplacement(new ResourceLocation( name.contains(":") ? name : String.format("orespawn:%s", name))); } @Override - public void mapEntryToFile(Path p, String entryName) { + public void mapEntryToFile(final Path p, final String entryName) { spawnsToSourceFiles.put(entryName, p); } @Override - public List getSpawnsForFile(String fileName) { + public List getSpawnsForFile(final String fileName) { Path p = Constants.CONFDIR.resolve(fileName); List values = spawnsToSourceFiles.entrySet().stream() .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index cd6b50c7..c926db65 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -24,31 +24,31 @@ public ReplacementBuilder() { } @Override - public IReplacementBuilder setFromName(String entryName) { + public IReplacementBuilder setFromName(final String entryName) { this.replacementName = entryName; this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); return this; } @Override - public IReplacementBuilder setName(String name) { + public IReplacementBuilder setName(final String name) { this.replacementName = name; return this; } @Override - public IReplacementBuilder addEntry(IBlockState blockState) { + public IReplacementBuilder addEntry(final IBlockState blockState) { this.entries.add(blockState); return this; } @Override - public IReplacementBuilder addEntry(String blockName) { + public IReplacementBuilder addEntry(final String blockName) { return this.addEntry(new ResourceLocation(blockName)); } @Override - public IReplacementBuilder addEntry(String blockName, String state) { + public IReplacementBuilder addEntry(final String blockName, final String state) { return this.addEntry(new ResourceLocation(blockName), state); } @@ -58,18 +58,18 @@ public IReplacementBuilder addEntry(String blockName, String state) { */ @Override @Deprecated - public IReplacementBuilder addEntry(String blockName, int metadata) { + public IReplacementBuilder addEntry(final String blockName, final int metadata) { return this.addEntry(new ResourceLocation(blockName), metadata); } @Override - public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation) { + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { return this .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); } @Override - public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state) { + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state) { return this.addEntry(StateUtil .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); } @@ -80,7 +80,7 @@ public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, Stri */ @Override @Deprecated - public IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata) { + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata) { return this.addEntry( ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index fdda593b..be4586a2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -37,54 +37,54 @@ public SpawnBuilder(final String spawnName) { } @Override - public ISpawnBuilder setName(String name) { + public ISpawnBuilder setName(final String name) { this.spawnName = name; return this; } @Override - public ISpawnBuilder setDimensions(IDimensionList dimensions) { + public ISpawnBuilder setDimensions(final IDimensionList dimensions) { this.dimensions = dimensions; return this; } @Override - public ISpawnBuilder setBiomes(BiomeLocation biomes) { + public ISpawnBuilder setBiomes(final BiomeLocation biomes) { this.biomes = biomes; return this; } @Override - public ISpawnBuilder setEnabled(boolean enabled) { + public ISpawnBuilder setEnabled(final boolean enabled) { this.enabled = enabled; return this; } @Override - public ISpawnBuilder setRetrogen(boolean retrogen) { + public ISpawnBuilder setRetrogen(final boolean retrogen) { this.retrogen = retrogen; return this; } @Override - public ISpawnBuilder setReplacement(IReplacementEntry replacements) { + public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { this.replacements = replacements; return this; } @Override - public ISpawnBuilder setFeature(IFeatureEntry feature) { + public ISpawnBuilder setFeature(final IFeatureEntry feature) { this.feature = feature; return this; } @Override - public ISpawnBuilder addBlock(String blockName) { + public ISpawnBuilder addBlock(final String blockName) { return this.addBlock(new ResourceLocation(blockName)); } @Override - public ISpawnBuilder addBlock(String blockName, String blockState) { + public ISpawnBuilder addBlock(final String blockName, final String blockState) { return this.addBlock(new ResourceLocation(blockName), blockState); } @@ -94,17 +94,17 @@ public ISpawnBuilder addBlock(String blockName, String blockState) { */ @Override @Deprecated - public ISpawnBuilder addBlock(String blockName, int blockMetadata) { + public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { return this.addBlock(new ResourceLocation(blockName), blockMetadata); } @Override - public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation) { + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { return this.addBlockWithChance(blockResourceLocation, 100); } @Override - public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState) { + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState) { return this.addBlockWithChance(blockResourceLocation, blockState, 100); } @@ -114,27 +114,27 @@ public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blo */ @Override @Deprecated - public ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata) { + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata) { return this.addBlockWithChance(blockResourceLocation, 100); } @Override - public ISpawnBuilder addBlock(Block block) { + public ISpawnBuilder addBlock(final Block block) { return this.addBlockWithChance(block, 100); } @Override - public ISpawnBuilder addBlock(IBlockState block) { + public ISpawnBuilder addBlock(final IBlockState block) { return this.addBlockWithChance(block, 100); } @Override - public ISpawnBuilder addBlockWithChance(String blockName, int chance) { + public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { return this.addBlockWithChance(new ResourceLocation(blockName), chance); } @Override - public ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance) { + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance) { return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); } @@ -144,20 +144,20 @@ public ISpawnBuilder addBlockWithChance(String blockName, String blockState, int */ @Override @Deprecated - public ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance) { + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance) { return this.addBlockWithChance(blockName, blockMetadata, chance); } @Override - public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance) { + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance) { IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) .getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @Override - public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - String blockState, int chance) { + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final String blockState, final int chance) { Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); return this.addBlockWithChance(tempVar, chance); @@ -169,28 +169,28 @@ public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, */ @Override @Deprecated - public ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - int blockMetadata, int chance) { + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int blockMetadata, final int chance) { IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) .getStateFromMeta(blockMetadata); return this.addBlockWithChance(tempVar, chance); } @Override - public ISpawnBuilder addBlockWithChance(Block block, int chance) { + public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { IBlockState tempVar = block.getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @Override - public ISpawnBuilder addBlockWithChance(IBlockState block, int chance) { + public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { BlockBuilder bb = new BlockBuilder(); bb.setFromBlockStateWithChance(block, chance); return this.addBlock(bb.create()); } @Override - public ISpawnBuilder addBlock(IBlockDefinition block) { + public ISpawnBuilder addBlock(final IBlockDefinition block) { if (block.isValid()) { this.blocks.addBlock(block); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 6806051a..6d675795 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -58,17 +58,17 @@ public String getSpawnName() { } @Override - public boolean dimensionAllowed(int dimension) { + public boolean dimensionAllowed(final int dimension) { return this.dimensions.matches(dimension); } @Override - public boolean biomeAllowed(ResourceLocation biomeName) { + public boolean biomeAllowed(final ResourceLocation biomeName) { return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); } @Override - public boolean biomeAllowed(Biome biome) { + public boolean biomeAllowed(final Biome biome) { return this.biomes.matches(biome); } @@ -88,8 +88,8 @@ public IBlockList getBlocks() { } @Override - public void generate(Random random, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider, ChunkPos pos) { + public void generate(final Random random, final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ChunkPos pos) { this.feature.getFeature().setRandom(random); this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index ede68fbe..d3989bf4 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -48,7 +48,7 @@ public class OreSpawnReader { private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingVersionException, + public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { JsonParser parser = new JsonParser(); @@ -101,7 +101,7 @@ public static void tryReadFile(Path conf, OS3APIImpl os3apiImpl) throws MissingV } } - private static JsonObject doHandlePresets(JsonObject spawnData) { + private static JsonObject doHandlePresets(final JsonObject spawnData) { PresetsStorage configPresets = OreSpawn.API.copyPresets(); if (spawnData.has(Constants.ConfigNames.PRESETS)) { spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() @@ -121,7 +121,7 @@ private static JsonObject doHandlePresets(JsonObject spawnData) { return spawnData; } - private static JsonElement doPresetFix(JsonElement value, PresetsStorage configPresets) { + private static JsonElement doPresetFix(final JsonElement value, final PresetsStorage configPresets) { if (value.isJsonObject()) { return doPresetForObject(value.getAsJsonObject(), configPresets); } else if (value.isJsonArray()) { @@ -139,13 +139,13 @@ private static JsonElement doPresetFix(JsonElement value, PresetsStorage configP } } - private static JsonElement doPresetForArray(JsonArray value, PresetsStorage configPresets) { + private static JsonElement doPresetForArray(final JsonArray value, final PresetsStorage configPresets) { JsonArray rv = new JsonArray(); value.forEach(it -> rv.add(doPresetFix(it, configPresets))); return rv; } - private static JsonElement doPresetForObject(JsonObject value, PresetsStorage configPresets) { + private static JsonElement doPresetForObject(final JsonObject value, final PresetsStorage configPresets) { JsonObject rv = new JsonObject(); value.entrySet().stream().forEach( @@ -153,7 +153,7 @@ private static JsonElement doPresetForObject(JsonObject value, PresetsStorage co return rv; } - public static void loadFromJson(String name, JsonElement json) { + public static void loadFromJson(final String name, final JsonElement json) { Entry t = new AbstractMap.SimpleEntry<>(name, json); try { loadSingleEntry(t); @@ -165,7 +165,7 @@ public static void loadFromJson(String name, JsonElement json) { } } - private static void loadSingleEntry(Entry entry) + private static void loadSingleEntry(final Entry entry) throws UnknownFieldException, BadValueException, UnknownNameException { ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); @@ -297,7 +297,7 @@ private static void loadSingleEntry(Entry entry) OreSpawn.API.addSpawn(sb.create()); } - private static List loadBlock(JsonObject json) { + private static List loadBlock(final JsonObject json) { String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); if (json.has(Constants.ConfigNames.STATE)) { Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); @@ -320,7 +320,7 @@ private static List loadBlock(JsonObject json) { return Arrays.asList(block.getDefaultState()); } - private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { + private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { boolean emptyWhitelist = false; if (biomeList.has(Constants.ConfigNames.WHITELIST) @@ -369,7 +369,7 @@ private static void loadBiomes(IBiomeBuilder bb, JsonObject biomeList) { } } - private static void loadDimensions(IDimensionBuilder db, JsonObject dimensionList) { + private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { boolean emptyWhitelist = false; if (dimensionList.has(Constants.ConfigNames.WHITELIST) diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index cf7dc35c..c474e957 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -29,7 +29,7 @@ public static void saveConfigs() { configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); } - private static void saveSingle(Path filePath, Gson gson) { + private static void saveSingle(final Path filePath, final Gson gson) { JsonObject root = new JsonObject(); root.addProperty(ConfigNames.FILE_VERSION, "2.0"); JsonObject spawns = new JsonObject(); @@ -66,7 +66,7 @@ private static void saveSingle(Path filePath, Gson gson) { } - public static void saveSingle(String fileName) { + public static void saveSingle(final String fileName) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); saveSingle(Constants.CONFDIR.resolve(fileName), gson); } diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index df8cac9f..e4fd5865 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -11,7 +11,7 @@ private StateUtil() { throw new InstantiationError("This class cannot be instantiated!"); } - public static String serializeState(IBlockState state) { + public static String serializeState(final IBlockState state) { String string = state.toString(); string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0)); @@ -25,7 +25,7 @@ public static String serializeState(IBlockState state) { return string; } - public static IBlockState deserializeState(Block block, String state) { + public static IBlockState deserializeState(final Block block, final String state) { for (IBlockState validState : block.getBlockState().getValidStates()) { String string = validState.toString(); string = string.substring(string.indexOf('[') + 1, diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index 2724bd84..68642888 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -18,8 +18,8 @@ public class FlatBedrock implements IWorldGenerator { @Override - public void generate(Random random, int chunkX, int chunkZ, World world, - IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { // no need to do flat-bedrock on a "FLAT" world if (world.getWorldType() != WorldType.FLAT) { if (world.provider.getDimension() == -1) { @@ -31,7 +31,7 @@ public void generate(Random random, int chunkX, int chunkZ, World world, } } - public void retrogen(World world, int chunkX, int chunkZ) { + public void retrogen(final World world, final int chunkX, final int chunkZ) { if (world.getWorldType() != WorldType.FLAT) { if (world.provider.getDimension() == -1) { genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); @@ -42,7 +42,7 @@ public void retrogen(World world, int chunkX, int chunkZ) { } } - private void genBottomPlate(World world, ChunkPos chunkPos, Block repBlock) { + private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); for (int xP = 0; xP < 16; xP++) { @@ -62,7 +62,7 @@ private void genBottomPlate(World world, ChunkPos chunkPos, Block repBlock) { } } - private void genTopPlate(World world, ChunkPos chunkPos, Block repBlock) { + private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); int thickness = 127 - plateThickness; // layer where the flat for the top starts diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 60490d79..46541f30 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -15,8 +15,8 @@ public class OreSpawnWorldGen implements IWorldGenerator { @Override - public void generate(Random random, int chunkX, int chunkZ, World world, - IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) { + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { int thisDim = world.provider.getDimension(); From a76a19e680c8870717259eb95526a41f99456881 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 14 Aug 2018 05:20:34 -0700 Subject: [PATCH 056/205] sonarlint --- .../java/com/mcmoddev/orespawn/impl/os3/DimensionList.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 7488db42..b9cbb1f5 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -42,13 +42,13 @@ public JsonObject serialize() { JsonObject rv = new JsonObject(); if (!this.whitelist.isEmpty()) { JsonArray wl = new JsonArray(); - whitelist.stream().forEach(i -> wl.add(i.intValue())); + whitelist.stream().forEach(wl::add); rv.add(Constants.ConfigNames.WHITELIST, wl); } if (!this.blacklist.isEmpty()) { JsonArray bl = new JsonArray(); - blacklist.stream().forEach(i -> bl.add(i.intValue())); + blacklist.stream().forEach(bl::add); rv.add(Constants.ConfigNames.WHITELIST, bl); } else if (this.whitelist.isEmpty()) { return new DimensionListAcceptAllOverworld().serialize(); From c15ce818ddae5956aaed5ac73b81b0ae2e74d023 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 14 Aug 2018 10:21:27 -0700 Subject: [PATCH 057/205] Finals! Finals Everywhere!! --- .../com/mcmoddev/orespawn/EventHandlers.java | 54 ++++++------ .../mcmoddev/orespawn/api/FeatureBase.java | 52 ++++++------ .../api/exceptions/BadValueException.java | 2 +- .../api/exceptions/UnknownFieldException.java | 2 +- .../api/exceptions/UnknownNameException.java | 2 +- .../api/os3/OreSpawnBlockMatcher.java | 6 +- .../orespawn/api/plugin/PluginLoader.java | 12 +-- .../orespawn/commands/AddOreCommand.java | 20 ++--- .../orespawn/commands/ClearChunkCommand.java | 16 ++-- .../orespawn/commands/DumpBiomesCommand.java | 8 +- .../com/mcmoddev/orespawn/data/Config.java | 16 ++-- .../orespawn/data/FeatureRegistry.java | 30 +++---- .../orespawn/data/PresetsStorage.java | 16 ++-- .../orespawn/data/ReplacementsRegistry.java | 60 +++++++------- .../impl/features/ClusterGenerator.java | 73 ++++++++--------- .../features/DefaultFeatureGenerator.java | 55 ++++++------- .../impl/features/NormalCloudGenerator.java | 55 ++++++------- .../impl/features/PrecisionGenerator.java | 70 ++++++++-------- .../orespawn/impl/features/VeinGenerator.java | 82 +++++++++---------- .../impl/location/BiomeLocationAcceptAny.java | 2 +- .../location/BiomeLocationComposition.java | 10 +-- .../impl/location/BiomeLocationList.java | 4 +- .../orespawn/impl/os3/BiomeBuilder.java | 1 - .../orespawn/impl/os3/BlockBuilder.java | 16 ++-- .../mcmoddev/orespawn/impl/os3/BlockList.java | 6 +- .../orespawn/impl/os3/DimensionList.java | 6 +- .../impl/os3/DimensionListAcceptAll.java | 2 +- .../os3/DimensionListAcceptAllOverworld.java | 5 +- .../impl/os3/DimensionListDenyAll.java | 3 +- .../orespawn/impl/os3/FeatureBuilder.java | 3 +- .../orespawn/impl/os3/FeatureEntry.java | 3 +- .../orespawn/impl/os3/OS3APIImpl.java | 27 +++--- .../orespawn/impl/os3/ReplacementBuilder.java | 1 - .../orespawn/impl/os3/SpawnBuilder.java | 12 +-- .../orespawn/impl/os3/SpawnEntry.java | 1 - .../orespawn/json/OreSpawnReader.java | 76 ++++++++--------- .../orespawn/json/OreSpawnWriter.java | 24 +++--- .../com/mcmoddev/orespawn/util/StateUtil.java | 2 +- .../orespawn/worldgen/FlatBedrock.java | 11 ++- .../orespawn/worldgen/OreSpawnWorldGen.java | 2 +- 40 files changed, 418 insertions(+), 430 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 21879299..c9d386f5 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -38,8 +38,8 @@ public class EventHandlers { - private Deque retroChunks; - private Deque>> chunks; + private final Deque retroChunks; + private final Deque>> chunks; // private Map> chunks EventHandlers() { @@ -47,7 +47,7 @@ public class EventHandlers { chunks = new ConcurrentLinkedDeque<>(); } - private List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, + private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); @@ -62,17 +62,17 @@ public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { @SubscribeEvent public void onChunkSave(final ChunkDataEvent.Save ev) { - NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - NBTTagCompound features = new NBTTagCompound(); + final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final NBTTagCompound features = new NBTTagCompound(); // save a list of the spawns that were configured and available - in this dimension - when // the chunk // was first generated. // collect that data - int thisDimension = ev.getWorld().provider.getDimension(); - BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); + final int thisDimension = ev.getWorld().provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); OreSpawn.API.getAllSpawns().entrySet().stream() .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) @@ -90,8 +90,8 @@ private boolean dequeContains(final ChunkPos cc) { @SubscribeEvent public void onChunkLoad(final ChunkDataEvent.Load ev) { - World world = ev.getWorld(); - ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); + final World clWorld = ev.getWorld(); + final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); doBedrockRetrogen(chunkCoords); @@ -100,10 +100,10 @@ public void onChunkLoad(final ChunkDataEvent.Load ev) { } if (Config.getBoolean(Constants.RETROGEN_KEY)) { - NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - int thisDimension = world.provider.getDimension(); - BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - Biome thisBiome = ev.getChunk().getBiome(thisPos, world.getBiomeProvider()); + final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final int thisDimension = clWorld.provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { @@ -114,9 +114,9 @@ public void onChunkLoad(final ChunkDataEvent.Load ev) { } private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, final Biome biome) { - NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - Map currentBits = new TreeMap<>(); - Map oldBits = new TreeMap<>(); + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); OreSpawn.API.getAllSpawns().entrySet().stream() .filter(ent -> ent.getValue().dimensionAllowed(dim)) @@ -125,9 +125,9 @@ private List getDifferingTags(final NBTTagCompound chunkTag, final int d tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - MapDifference diff = Maps.difference(oldBits, currentBits); + final MapDifference diff = Maps.difference(oldBits, currentBits); - List stuff = Lists.newLinkedList(); + final List stuff = Lists.newLinkedList(); stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) .collect(Collectors.toList())); stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) @@ -136,9 +136,9 @@ private List getDifferingTags(final NBTTagCompound chunkTag, final int d } private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, final Biome biome) { - NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - Map currentBits = new TreeMap<>(); - Map oldBits = new TreeMap<>(); + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); OreSpawn.API.getAllSpawns().entrySet().stream() .filter(ent -> ent.getValue().dimensionAllowed(dim)) @@ -147,7 +147,7 @@ private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int di tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - MapDifference diff = Maps.difference(oldBits, currentBits); + final MapDifference diff = Maps.difference(oldBits, currentBits); return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 && diff.entriesOnlyOnRight().size() == 0; @@ -189,8 +189,8 @@ private static void setupData(final World nw) { } private void runBits(final Tuple> tup) { - ChunkPos p = tup.getFirst(); - List spawns = tup.getSecond(); + final ChunkPos p = tup.getFirst(); + final List spawns = tup.getSecond(); // re-seed with something totally new :P random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) @@ -208,7 +208,7 @@ public void worldTick(final WorldTickEvent ev) { } if (ev.phase == Phase.END) { - Deque>> b = new LinkedList<>(); + final Deque>> b = new LinkedList<>(); for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { b.push(chunks.pop()); } @@ -216,7 +216,7 @@ public void worldTick(final WorldTickEvent ev) { b.forEach(this::runBits); for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { - ChunkPos p = retroChunks.pop(); + final ChunkPos p = retroChunks.pop(); OreSpawn.flatBedrock.retrogen(world, p.x, p.z); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 14af8539..470a540a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -42,11 +42,11 @@ public boolean isValidBlock(final IBlockState oreBlock) { } protected void runCache(final int chunkX, final int chunkZ, final World world, final ISpawnEntry spawnData) { - Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); - Map cache = retrieveCache(chunkCoord); + final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); + final Map cache = retrieveCache(chunkCoord); if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it - for (Entry ent : cache.entrySet()) { + for (final Entry ent : cache.entrySet()) { spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), world.provider.getDimension(), spawnData); } @@ -64,13 +64,13 @@ protected boolean spawn(final IBlockState oreBlock, final World world, final Blo return false; } - Biome thisBiome = world.getBiome(coord); + final Biome thisBiome = world.getBiome(coord); if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { return false; } - BlockPos np = mungeFixYcoord(coord); + final BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); @@ -83,7 +83,7 @@ protected boolean spawn(final IBlockState oreBlock, final World world, final Blo private BlockPos mungeFixYcoord(final BlockPos coord) { if (coord.getY() < 0) { - int newYCoord = coord.getY() * -1; + final int newYCoord = coord.getY() * -1; return new BlockPos(coord.getX(), newYCoord, coord.getZ()); } else { return new BlockPos(coord); @@ -97,8 +97,8 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final OreS return false; } - IBlockState targetBlock = world.getBlockState(coord); - Biome thisBiome = world.getBiome(coord); + final IBlockState targetBlock = world.getBlockState(coord); + final Biome thisBiome = world.getBiome(coord); if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { world.setBlockState(coord, oreBlock); @@ -121,7 +121,7 @@ private void spawnNoCheck(final IBlockState oreBlock, final World world, final B return; } - BlockPos np = mungeFixYcoord(coord); + final BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); @@ -132,13 +132,13 @@ private void spawnNoCheck(final IBlockState oreBlock, final World world, final B } private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, final int dimension) { - Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); + final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); if (overflowCache.containsKey(chunkCoord)) { cacheOrder.addLast(chunkCoord); if (cacheOrder.size() > MAX_CACHE_SIZE) { - Vec3i drop = cacheOrder.removeFirst(); + final Vec3i drop = cacheOrder.removeFirst(); overflowCache.get(drop).clear(); overflowCache.remove(drop); } @@ -146,13 +146,13 @@ private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, fina overflowCache.put(chunkCoord, new HashMap<>()); } - Map cache = overflowCache.getOrDefault(chunkCoord, new HashMap<>()); + final Map cache = overflowCache.getOrDefault(chunkCoord, new HashMap<>()); cache.put(coord, bs); } private Map retrieveCache(final Vec3i chunkCoord) { if (overflowCache.containsKey(chunkCoord)) { - Map cache = overflowCache.get(chunkCoord); + final Map cache = overflowCache.get(chunkCoord); cacheOrder.remove(chunkCoord); overflowCache.remove(chunkCoord); return cache; @@ -163,8 +163,8 @@ private Map retrieveCache(final Vec3i chunkCoord) { protected void scramble(final int[] target, final Random prng) { for (int i = target.length - 1; i > 0; i--) { - int n = prng.nextInt(i); - int temp = target[i]; + final int n = prng.nextInt(i); + final int temp = target[i]; target[i] = target[n]; target[n] = temp; } @@ -200,8 +200,8 @@ protected static void mergeDefaults(final JsonObject parameters, final JsonObjec } private double triangularDistribution(final double a, final double b, final double c) { - double base = (c - a) / (b - a); - double rand = this.random.nextDouble(); + final double base = (c - a) / (b - a); + final double rand = this.random.nextDouble(); if (rand < base) { return a + Math.sqrt(rand * (b - a) * (c - a)); @@ -211,22 +211,22 @@ private double triangularDistribution(final double a, final double b, final doub } protected int getPoint(final int lowerBound, final int upperBound, final int median) { - int t = (int) Math.round( + final int t = (int) Math.round( triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); return t - median; } protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, final double radius, final ISpawnEntry spawnData, final int count) { - Random prng = this.random; + final Random prng = this.random; int quantity = count; - IBlockList possibleOres = spawnData.getBlocks(); - OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for (int dy = (int) (-1 * radius); dy < radius; dy++) { for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - IBlockState oreBlock = possibleOres.getRandomBlock(prng); + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; @@ -241,15 +241,15 @@ protected void spawnMungeSW(final World world, final BlockPos blockPos, final in protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, final double radius, final ISpawnEntry spawnData, final int count) { - Random prng = this.random; + final Random prng = this.random; int quantity = count; - IBlockList possibleOres = spawnData.getBlocks(); - OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for (int dy = (int) (-1 * radius); dy < radius; dy++) { for (int dz = (int) (-1 * radius); dz < radius; dz++) { for (int dx = (int) (-1 * radius); dx < radius; dx++) { if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - IBlockState oreBlock = possibleOres.getRandomBlock(prng); + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index 08615e79..e45b98a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -14,7 +14,7 @@ public BadValueException(final String keyName, final String keyValue) { @Override public String getMessage() { - String baseMessage = super.getMessage(); + final String baseMessage = super.getMessage(); return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, baseMessage); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 685327cf..9cf2b4ad 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -12,7 +12,7 @@ public UnknownFieldException(final String theField) { @Override public String getMessage() { - String baseMessage = super.getMessage(); + final String baseMessage = super.getMessage(); return String.format("%s%n%s", this.message, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index e63a357f..8e5b6049 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -14,7 +14,7 @@ public UnknownNameException(final String fieldName, final String fieldValue) { @Override public String getMessage() { - String baseMessage = super.getMessage(); + final String baseMessage = super.getMessage(); return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, baseMessage); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index 7d9d0721..ffba56f6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -35,13 +35,13 @@ public boolean test(final IBlockState other) { } public JsonArray serialize() { - JsonArray rv = new JsonArray(); + final JsonArray rv = new JsonArray(); possibles.stream().forEach(bs -> { - JsonObject t = new JsonObject(); + final JsonObject t = new JsonObject(); t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); if (!bs.equals(bs.getBlock().getDefaultState())) { - String state = StateUtil.serializeState(bs); + final String state = StateUtil.serializeState(bs); t.addProperty(Constants.ConfigNames.STATE, state); } rv.add(t); diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index 46a7dd81..2d23b41f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -66,7 +66,7 @@ public void load(final FMLPreInitializationEvent event) { try { integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); - PluginData pd = new PluginData(modId, resourceBase, integration); + final PluginData pd = new PluginData(modId, resourceBase, integration); dataStore.add(pd); } catch (final Exception ex) { OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); @@ -86,8 +86,8 @@ public void scanResources(final PluginData pd) { return; } - String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); - URL resURL = getClass().getClassLoader().getResource(base); + final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); + final URL resURL = getClass().getClassLoader().getResource(base); if (resURL == null) { OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", @@ -126,9 +126,9 @@ public void scanResources(final PluginData pd) { private void copyout(final Path myPath, final String modId) { try (Stream walk = Files.walk(myPath, 1)) { - for (Iterator it = walk.iterator(); it.hasNext();) { - Path p = it.next(); - String name = p.getFileName().toString(); + for (final Iterator it = walk.iterator(); it.hasNext();) { + final Path p = it.next(); + final String name = p.getFileName().toString(); if ("json".equals(FilenameUtils.getExtension(name))) { InputStream reader = null; diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index e3820e8f..70f55fc4 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -43,8 +43,8 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f throw new CommandException("Only players can use this command"); } - EntityPlayer player = (EntityPlayer) sender; - ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); + final EntityPlayer player = (EntityPlayer) sender; + final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); if (stack == null) { throw new CommandException("You have no item in your main hand"); @@ -54,21 +54,21 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f throw new CommandException(this.getUsage(sender)); } - String file = args[0]; + final String file = args[0]; @SuppressWarnings("deprecation") - IBlockState state = Block.getBlockFromItem(stack.getItem()) + final IBlockState state = Block.getBlockFromItem(stack.getItem()) .getStateFromMeta(stack.getItemDamage()); - String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); - JsonParser p = new JsonParser(); - JsonElement parsed = mergeDefaults(p.parse(rawData), state); + final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); + final JsonParser p = new JsonParser(); + final JsonElement parsed = mergeDefaults(p.parse(rawData), state); OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); } private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { - JsonObject work = parse.getAsJsonObject(); - JsonObject emptyBlacklist = new JsonObject(); + final JsonObject work = parse.getAsJsonObject(); + final JsonObject emptyBlacklist = new JsonObject(); emptyBlacklist.add("excludes", new JsonArray()); if (!work.has(ConfigNames.ENABLED)) { @@ -95,7 +95,7 @@ private JsonElement mergeDefaults(final JsonElement parse, final IBlockState sta work.add(ConfigNames.BIOMES, emptyBlacklist); } - JsonObject block = new JsonObject(); + final JsonObject block = new JsonObject(); block.addProperty(ConfigNames.CHANCE, 100); block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index eec4849c..804ad646 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -57,15 +57,15 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f throw new CommandException("Only players can use this command"); } - EntityPlayer player = (EntityPlayer) sender; - Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); + final EntityPlayer player = (EntityPlayer) sender; + final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); final ChunkPos chunkPos = chunk.getPos(); - List blocks; + final List blocks; final boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") : false; - List blockNames = new LinkedList<>(); + final List blockNames = new LinkedList<>(); getBlocks(args, blockNames); blocks = blockNames.stream() @@ -75,7 +75,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f blocks.addAll(OreSpawn.API .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) .stream().collect(Collectors.toList())); - List overburden = Arrays + final List overburden = Arrays .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", "minecraft:sandstone", "minecraft:red_sandstone") .stream() @@ -93,8 +93,8 @@ private void clearBlocks(final ChunkPos chunkPos, final List blocks for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { - BlockPos pos = new BlockPos(x, y, z); - IBlockState block = player.getEntityWorld().getBlockState(pos); + final BlockPos pos = new BlockPos(x, y, z); + final IBlockState block = player.getEntityWorld().getBlockState(pos); removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); removeIfFluid(pos, player); } @@ -104,7 +104,7 @@ private void clearBlocks(final ChunkPos chunkPos, final List blocks private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { - IBlockState bs = player.getEntityWorld().getBlockState(pos); + final IBlockState bs = player.getEntityWorld().getBlockState(pos); if (bs.getMaterial().isLiquid()) { player.getEntityWorld().setBlockToAir(pos); diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 70d57487..62dad5e4 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -38,17 +38,17 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f throws CommandException { JsonArray array = new JsonArray(); - for (Biome biome : ForgeRegistries.BIOMES) { + for (final Biome biome : ForgeRegistries.BIOMES) { array.add(new JsonPrimitive(biome.getRegistryName().toString())); } - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String json = gson.toJson(array); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String json = gson.toJson(array); try { FileUtils.writeStringToFile(new File(".", "biome_dump.json"), StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); - } catch (IOException e) { + } catch (final IOException e) { throw new CommandException("Failed to save the json file"); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 485dd031..08ba58c7 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -63,14 +63,14 @@ public static void loadConfig() { } private static void loadExtractedConfigs() { - Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", "known-configs.json"); if (!p.toFile().exists()) { return; } - File in = p.toFile(); + final File in = p.toFile(); String rawData; try { @@ -83,7 +83,7 @@ private static void loadExtractedConfigs() { return; } - JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); + final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); data.forEach(item -> addKnownMod(item.getAsString())); } @@ -136,23 +136,23 @@ public static void saveConfig() { } private static void saveKnownConfigs() { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", "known-configs.json"); if (!p.toFile().getParentFile().exists()) { p.toFile().mkdirs(); } - File in = p.toFile(); + final File in = p.toFile(); - JsonArray data = new JsonArray(); + final JsonArray data = new JsonArray(); extractedConfigs.forEach(data::add); try { FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed saving list of already extracted mod configs"); report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 4f22961a..8042f745 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -39,7 +39,7 @@ public FeatureRegistry() { } public Map getFeatures() { - Map tempMap = new TreeMap<>(); + final Map tempMap = new TreeMap<>(); registry.getEntries().stream() .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); @@ -55,7 +55,7 @@ public IFeature getFeature(final String name) { } public IFeature getFeature(final ResourceLocation featureResourceLocation) { - ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); + final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); if (registry.containsKey(featureResourceLocation)) { return registry.getValue(featureResourceLocation); } else { @@ -85,7 +85,7 @@ public void addFeature(final JsonObject entry) { } public void addFeature(final String name, final String className) { - IFeature feature = getInstance(className); + final IFeature feature = getInstance(className); if (feature != null && !hasFeature(name)) { addFeature(name, feature); @@ -101,8 +101,8 @@ private static IFeature getInstance(final String className) { featureClazz = Class.forName(className); featureCons = featureClazz.getConstructor(); feature = (IFeature) featureCons.newInstance(); - } catch (Exception e) { - CrashReport report = CrashReport.makeCrashReport(e, + } catch (final Exception e) { + final CrashReport report = CrashReport.makeCrashReport(e, "Failed to load and instantiate an instance of the feature generator named " + className + " that was specified as a feature generator"); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -114,14 +114,14 @@ private static IFeature getInstance(final String className) { } public void loadFeaturesFile(final File file) { - JsonParser parser = new JsonParser(); + final JsonParser parser = new JsonParser(); String rawJson; JsonArray elements; try { rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + file.getName()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); @@ -130,30 +130,30 @@ public void loadFeaturesFile(final File file) { elements = parser.parse(rawJson).getAsJsonArray(); - for (JsonElement elem : elements) { + for (final JsonElement elem : elements) { addFeature(elem.getAsJsonObject()); } } public void writeFeatures(final File file) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - JsonArray root = new JsonArray(); + final JsonArray root = new JsonArray(); registry.getEntries().stream().map(ent -> { - JsonObject e = new JsonObject(); + final JsonObject e = new JsonObject(); e.addProperty("name", ent.getKey().getPath()); e.addProperty("class", ent.getValue().getClass().getName()); return e; }).forEach(root::add); - String json = gson.toJson(root); + final String json = gson.toJson(root); try { FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config " + file.getName()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index b6468191..e8137fcd 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -29,7 +29,7 @@ public PresetsStorage() { } public void setSymbolSection(final String sectionName, final String itemName, final JsonElement value) { - Map temp = storage.getOrDefault(sectionName, + final Map temp = storage.getOrDefault(sectionName, new HashMap()); temp.put(itemName, value); storage.put(sectionName, temp); @@ -45,7 +45,7 @@ public JsonElement getSymbolSection(final String sectionName, final String itemN public void copy(final PresetsStorage dest) { storage.entrySet().stream().forEach(ensm -> { - String section = ensm.getKey(); + final String section = ensm.getKey(); ensm.getValue().entrySet().forEach( ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); }); @@ -56,17 +56,17 @@ public void clear() { } public void load(final Path inputFile) { - JsonParser p = new JsonParser(); + final JsonParser p = new JsonParser(); JsonElement parsed = null; try (BufferedReader r = Files.newBufferedReader(inputFile)) { parsed = p.parse(r); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed reading presets from" + inputFile.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (JsonIOException | JsonSyntaxException e) { + } catch (final JsonIOException | JsonSyntaxException e) { CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + inputFile.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -75,7 +75,7 @@ public void load(final Path inputFile) { if (parsed != null) { parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { - String section = entry.getKey(); + final String section = entry.getKey(); entry.getValue().getAsJsonObject().entrySet().stream().forEach( sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); }); @@ -83,8 +83,8 @@ public void load(final Path inputFile) { } public JsonElement get(final String asString) { - Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); - Matcher m = p.matcher(asString); + final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); + final Matcher m = p.matcher(asString); if (m.matches()) { return this.getSymbolSection(m.group(1), m.group(2)); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index ebc6cc51..9701d3e8 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -63,16 +63,16 @@ public Map getReplacements() { */ @Deprecated public List getDimensionDefault(final int dimension) { - String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; - List mineralogyOres = OreDictionary.getOres("cobblestone").stream() + final String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; + final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) .collect(Collectors.toList()); - List baseRv = new ArrayList<>(); + final List baseRv = new ArrayList<>(); baseRv.addAll(mineralogyOres); if (dimension < -1 || dimension > 1 || dimension == 0) { - for (ItemStack iS : OreDictionary.getOres("stone")) { + for (final ItemStack iS : OreDictionary.getOres("stone")) { baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); } @@ -85,7 +85,7 @@ public List getDimensionDefault(final int dimension) { } public IReplacementEntry getReplacement(final String name) { - ResourceLocation act = new ResourceLocation( + final ResourceLocation act = new ResourceLocation( name.contains(":") ? name : String.format("orespawn:%s", name)); if (registry.containsKey(act)) { return registry.getValue(act); @@ -95,13 +95,13 @@ public IReplacementEntry getReplacement(final String name) { } public void addBlock(final String name, final String blockName, final String blockState) { - IBlockState b = StateUtil.deserializeState( + final IBlockState b = StateUtil.deserializeState( ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); addBlock(name, b); } public Map> getBlocks() { - Map> tempMap = new TreeMap<>(); + final Map> tempMap = new TreeMap<>(); registry.getEntries().stream() .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); @@ -115,7 +115,7 @@ public void addReplacement(final IReplacementEntry replacement) { public void addBlock(final String name, final IBlockState state) { ResourceLocation regName = new ResourceLocation(name); if (registry.containsKey(regName)) { - IReplacementEntry old = registry.getValue(regName); + final IReplacementEntry old = registry.getValue(regName); IReplacementEntry newRE; List oldList = old.getEntries(); oldList.add(state); @@ -126,13 +126,13 @@ public void addBlock(final String name, final IBlockState state) { return; } - IReplacementEntry r = new ReplacementEntry(name, state); + final IReplacementEntry r = new ReplacementEntry(name, state); registry.register(r); } @SuppressWarnings("deprecation") public void loadFile(final Path file) { - JsonParser parser = new JsonParser(); + final JsonParser parser = new JsonParser(); JsonObject elements; String rawJson; @@ -148,18 +148,18 @@ public void loadFile(final Path file) { elements = parser.parse(rawJson).getAsJsonObject(); elements.entrySet().stream().forEach(elem -> { - String entName = elem.getKey(); - JsonArray entries = elem.getValue().getAsJsonArray(); - List blocks = new LinkedList<>(); - for (JsonElement e : entries) { - JsonObject asObj = e.getAsJsonObject(); - String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() + final String entName = elem.getKey(); + final JsonArray entries = elem.getValue().getAsJsonArray(); + final List blocks = new LinkedList<>(); + for (final JsonElement e : entries) { + final JsonObject asObj = e.getAsJsonObject(); + final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() .toLowerCase(); // is this an OreDictionary entry ? if (blockName.startsWith("ore:")) { // yes, it is - String oreDictName = blockName.split(":")[1]; + final String oreDictName = blockName.split(":")[1]; OreDictionary.getOres(oreDictName).forEach(iS -> { if (iS.getMetadata() != 0) { blocks.add(Block.getBlockFromItem(iS.getItem()) @@ -170,11 +170,11 @@ public void loadFile(final Path file) { }); } else { String state = null; - ResourceLocation blockRL = new ResourceLocation(blockName); - Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); + final ResourceLocation blockRL = new ResourceLocation(blockName); + final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); if (asObj.has(Constants.ConfigNames.METADATA)) { // has metadata - int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); + final int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); blocks.add(theBlock.getStateFromMeta(meta)); } else if (asObj.has(Constants.ConfigNames.STATE)) { // has a state @@ -187,20 +187,20 @@ public void loadFile(final Path file) { } } - IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); + final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); registry.register(replacer); }); } public void saveFile(final String modName) { - JsonObject outs = new JsonObject(); + final JsonObject outs = new JsonObject(); registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) .forEach(ent -> { - JsonArray entry = new JsonArray(); - IReplacementEntry workVal = ent.getValue(); + final JsonArray entry = new JsonArray(); + final IReplacementEntry workVal = ent.getValue(); workVal.getEntries().stream().forEach(bs -> { - JsonObject block = new JsonObject(); + final JsonObject block = new JsonObject(); block.addProperty(Constants.ConfigNames.BLOCK, bs.getBlock().getRegistryName().toString()); if (!bs.toString().matches("\\[normal\\]")) { @@ -211,13 +211,13 @@ public void saveFile(final String modName) { }); outs.add(ent.getKey().toString(), entry); }); - Path p = Paths.get("config", "orespawn3", "sysconfig", + final Path p = Paths.get("config", "orespawn3", "sysconfig", String.format("replacements-%s.json", modName)); - try (BufferedWriter w = Files.newBufferedWriter(p)) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String ov = gson.toJson(outs); + try (final BufferedWriter w = Files.newBufferedWriter(p)) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String ov = gson.toJson(outs); w.write(ov); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, String .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 74c750ba..56a65375 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -30,12 +30,12 @@ public ClusterGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - ChunkPos pos = _pos; - JsonObject params = spawnData.getFeature().getFeatureParameters(); + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns - int chunkX = pos.x; - int chunkZ = pos.z; + final int chunkX = pos.x; + final int chunkZ = pos.z; mergeDefaults(params, getDefaultParameters()); @@ -43,18 +43,18 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi // now to ore spawn - int blockX = chunkX * 16 + 8; - int blockZ = chunkZ * 16 + 8; + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; - int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); int tries; @@ -66,12 +66,12 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi while (tries > 0) { if (this.random.nextInt(100) <= frequency) { - int xRand = random.nextInt(16); - int zRand = random.nextInt(16); + final int xRand = random.nextInt(16); + final int zRand = random.nextInt(16); - int x = blockX + xRand - (maxSpread / 2); - int y = random.nextInt(maxHeight - minHeight) + minHeight; - int z = blockZ + zRand - (maxSpread / 2); + final int x = blockX + xRand - (maxSpread / 2); + final int y = random.nextInt(maxHeight - minHeight) + minHeight; + final int z = blockZ + zRand - (maxSpread / 2); spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, spawnData, world, new BlockPos(x, y, z)); @@ -106,13 +106,13 @@ private void spawnCluster(final int clusterSize, final int variance, final int c r += this.random.nextInt(2 * variance) - variance; } - int radius = maxSpread / 2; + final int radius = maxSpread / 2; - int xp = getPoint(-radius, radius, 0); - int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - int zp = getPoint(-radius, radius, 0); + final int xp = getPoint(-radius, radius, 0); + final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + final int zp = getPoint(-radius, radius, 0); - BlockPos p = pos.add(xp, yp, zp); + final BlockPos p = pos.add(xp, yp, zp); spawnChunk(world, p, spawnData, r); count -= r; @@ -120,23 +120,23 @@ private void spawnCluster(final int clusterSize, final int variance, final int c } private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, final int quantity) { - int count = quantity; - int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - Vec3i[] offs = new Vec3i[lutType]; + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - int dimension = world.provider.getDimension(); + final int dimension = world.provider.getDimension(); if (quantity < 27) { - int[] scrambledLUT = new int[lutType]; + final int[] scrambledLUT = new int[lutType]; System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); int z = 0; while (count > 0) { - IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, spawnData)) { @@ -161,9 +161,9 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry private void doSpawnFill(final boolean nextBoolean, final int quantity, final ISpawnEntry spawnData, final World world, final BlockPos pos) { - int count = quantity; - double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int) (radius * radius); + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); if (nextBoolean) { spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { @@ -178,7 +178,7 @@ public void setRandom(final Random rand) { @Override public JsonObject getDefaultParameters() { - JsonObject defParams = new JsonObject(); + final JsonObject defParams = new JsonObject(); defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); @@ -190,5 +190,4 @@ public JsonObject getDefaultParameters() { defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); return defParams; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index e93fe872..b72603e7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -25,12 +25,12 @@ public DefaultFeatureGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - ChunkPos pos = _pos; - JsonObject params = spawnData.getFeature().getFeatureParameters(); + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns - int chunkX = pos.x; - int chunkZ = pos.z; + final int chunkX = pos.x; + final int chunkZ = pos.z; mergeDefaults(params, getDefaultParameters()); @@ -38,20 +38,20 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi // now to ore spawn - int blockX = chunkX * 16 + 8; - int blockZ = chunkZ * 16 + 8; + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; - int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); - int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); + final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); if (freq >= 1) { for (int i = 0; i < freq; i++) { - int x = blockX + random.nextInt(16); - int y = random.nextInt(maxY - minY) + minY; - int z = blockZ + random.nextInt(16); + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); final int r; @@ -64,9 +64,9 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); } } else if (random.nextFloat() < freq) { - int x = blockX + random.nextInt(8); - int y = random.nextInt(maxY - minY) + minY; - int z = blockZ + random.nextInt(8); + final int x = blockX + random.nextInt(8); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(8); final int r; if (vari > 0) { @@ -82,20 +82,20 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; - int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - Vec3i[] offs = new Vec3i[lutType]; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); if (quantity < 27) { - int[] scrambledLUT = new int[lutType]; + final int[] scrambledLUT = new int[lutType]; System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); while (count > 0) { - IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - BlockPos target = pos.add(offs[scrambledLUT[--count]]); + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } @@ -107,9 +107,9 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, final BlockPos pos) { - int count = quantity; - double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int) (radius * radius); + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); if (nextBoolean) { spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { @@ -119,7 +119,7 @@ private void doSpawnFill(final boolean nextBoolean, final int quantity, final Wo @Override public JsonObject getDefaultParameters() { - JsonObject defParams = new JsonObject(); + final JsonObject defParams = new JsonObject(); defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); defParams.addProperty(Constants.FormatBits.VARIATION, 16); @@ -132,5 +132,4 @@ public JsonObject getDefaultParameters() { public void setRandom(final Random rand) { this.random = rand; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 4acccede..06ec5e83 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -28,12 +28,12 @@ public NormalCloudGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - ChunkPos pos = _pos; - JsonObject params = spawnData.getFeature().getFeatureParameters(); + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns - int chunkX = pos.x; - int chunkZ = pos.z; + final int chunkX = pos.x; + final int chunkZ = pos.z; mergeDefaults(params, getDefaultParameters()); @@ -42,37 +42,37 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi // now to ore spawn // lets not offset blind, - int blockX = chunkX * 16; - int blockZ = chunkZ * 16; - - int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); - int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int blockX = chunkX * 16; + final int blockZ = chunkZ * 16; + + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get // a size that will let us insert by the radius - int offsetXZ = 32 - maxSpread; + final int offsetXZ = 32 - maxSpread; // you have the distance between minHeight and maxHeight // this is the actual size of the space - int sizeY = (maxHeight - minHeight); - int offsetY = sizeY - maxSpread; - int radiusXZ = offsetXZ / 2; + final int sizeY = (maxHeight - minHeight); + final int offsetY = sizeY - maxSpread; + final int radiusXZ = offsetXZ / 2; // actual radius for placement is the size minus the spread to center it in the space and // keep // from overflowing - int radiusY = offsetY / 2; + final int radiusY = offsetY / 2; // we center at the minimum plus the half the height - int blockY = minHeight + (sizeY / 2); + final int blockY = minHeight + (sizeY / 2); - int fSave = frequency; + final int fSave = frequency; int tryCount = 0; int tries; @@ -86,11 +86,11 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi while (tries > 0) { if (this.random.nextInt(100) <= frequency) { frequency = fSave; - int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; // this should, hopefully, keep us centered between minHeight and maxHeight with // nothing going above/below those values - int y = blockY + getPoint(0, offsetY, radiusY); - int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + final int y = blockY + getPoint(0, offsetY, radiusY); + final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; int r = medianSize - variance; @@ -98,7 +98,7 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi r += random.nextInt(2 * variance) - variance; } - BlockPos p = new BlockPos(x, y, z); + final BlockPos p = new BlockPos(x, y, z); if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) && tryCount < 5) { @@ -124,7 +124,7 @@ private boolean spawnCloud(final int size, final int maxSpread, final int minHei return false; } - int radius = maxSpread / 2; + final int radius = maxSpread / 2; boolean alreadySpewed = false; int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); @@ -167,7 +167,7 @@ public void setRandom(final Random rand) { @Override public JsonObject getDefaultParameters() { - JsonObject defParams = new JsonObject(); + final JsonObject defParams = new JsonObject(); defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); @@ -178,5 +178,4 @@ public JsonObject getDefaultParameters() { defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); return defParams; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index b1e77086..8f1dc587 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -31,30 +31,30 @@ public PrecisionGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - ChunkPos pos = _pos; - JsonObject params = spawnData.getFeature().getFeatureParameters(); + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns - int chunkX = pos.x; - int chunkZ = pos.z; + final int chunkX = pos.x; + final int chunkZ = pos.z; mergeDefaults(params, getDefaultParameters()); runCache(chunkX, chunkZ, world, spawnData); // extract parameters - int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); - int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); - int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); - int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); + final int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); + final int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); + final int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); + final int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); int thisNode = nodeSize; // now to use them for (int c = nodeCount; c > 0; c--) { int sc; - HeightRange hr = new HeightRange(minHeight, maxHeight); - BlockPos spot = chooseSpot(chunkX, chunkZ, hr); + final HeightRange hr = new HeightRange(minHeight, maxHeight); + final BlockPos spot = chooseSpot(chunkX, chunkZ, hr); sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); @@ -101,24 +101,24 @@ private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEnt final int nodeSize, final HeightRange heightRange) { int count = nodeSize; - int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; - Vec3i[] offs = new Vec3i[lutType]; + final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; System.arraycopy((nodeSize < 8) ? offsets_small : offsets, 0, offs, 0, lutType); if (nodeSize < 27) { - int[] scrambledLUT = new int[lutType]; + final int[] scrambledLUT = new int[lutType]; System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); int nc = 0; for (; count > 0 && nc <= nodeSize; count--) { - IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); - Vec3i offset = offs[scrambledLUT[--count]]; - BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); - int dimension = world.provider.getDimension(); + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); + final Vec3i offset = offs[scrambledLUT[--count]]; + final BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); + final int dimension = world.provider.getDimension(); if (spawn(oreBlock, world, p, dimension, true, spawnData)) { nc++; @@ -133,12 +133,12 @@ private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEnt private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, final HeightRange heightRange, final ChunkPos pos) { - BlockPos p = spot.add(offset); - ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); - int xMax = x1z1.getXEnd(); - int zMax = x1z1.getZEnd(); - int xMin = pos.getXStart(); - int zMin = pos.getZStart(); + final BlockPos p = spot.add(offset); + final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); + final int xMax = x1z1.getXEnd(); + final int zMax = x1z1.getZEnd(); + final int xMin = pos.getXStart(); + final int zMin = pos.getZStart(); int xmod = offset.getX(); int ymod = offset.getY(); @@ -163,9 +163,9 @@ private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, final H private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, final int maximumIn) { - int actual = centerIn + offsetIn; + final int actual = centerIn + offsetIn; int wrapDistance; - int range = maximumIn - minimumIn; + final int range = maximumIn - minimumIn; int workingPoint; if (actual < minimumIn) { @@ -192,8 +192,8 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc, final int nodeSize, final HeightRange heightRange) { - double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int) Math.ceil(radius * radius); + final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) Math.ceil(radius * radius); if (this.random.nextBoolean()) { return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, @@ -233,8 +233,8 @@ private int spawnPrecise(final ISpawnEntry spawnData, final World world, final C private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, final HeightRange heightRange, final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc) { if (getABC(dx, dy, dz) <= rSqr) { - BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); - IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); + final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); + final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; } @@ -242,7 +242,7 @@ private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSq } private int getPoint(final int lowerBound, final int upperBound) { - List arr = new ArrayList<>(); + final List arr = new ArrayList<>(); for (int i = lowerBound; i <= upperBound; i++) { arr.add(i); @@ -252,9 +252,9 @@ private int getPoint(final int lowerBound, final int upperBound) { } private BlockPos chooseSpot(final int xPosition, final int zPosition, final HeightRange heightRange) { - int xRet = getPoint(0, 15) + (xPosition * 16); - int zRet = getPoint(0, 15) + (zPosition * 16); - int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); + final int xRet = getPoint(0, 15) + (xPosition * 16); + final int zRet = getPoint(0, 15) + (zPosition * 16); + final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); return new BlockPos(xRet, yRet, zRet); } @@ -266,7 +266,7 @@ public void setRandom(final Random rand) { @Override public JsonObject getDefaultParameters() { - JsonObject defaults = new JsonObject(); + final JsonObject defaults = new JsonObject(); defaults.addProperty(FormatBits.NODE_COUNT, 4); defaults.addProperty(FormatBits.MIN_HEIGHT, 16); defaults.addProperty(FormatBits.MAX_HEIGHT, 80); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 2efd565b..b96dbcc2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -36,31 +36,31 @@ public VeinGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - ChunkPos pos = _pos; - JsonObject params = spawnData.getFeature().getFeatureParameters(); + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns - int chunkX = pos.x; - int chunkZ = pos.z; + final int chunkX = pos.x; + final int chunkZ = pos.z; runCache(chunkX, chunkZ, world, spawnData); mergeDefaults(params, getDefaultParameters()); // now to ore spawn - int blockX = chunkX * 16 + 8; - int blockZ = chunkZ * 16 + 8; + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; - int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - int startingFace = getFaceFromString( + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); + final int startingFace = getFaceFromString( params.get(Constants.FormatBits.STARTINGFACE).getAsString()); - int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); OreSpawn.LOGGER.fatal("parameters: %s", params); int tries; @@ -74,9 +74,9 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi // we have an offset into the chunk but actually need something more while (tries > 0) { if (this.random.nextInt(100) <= freq) { - int x = blockX + random.nextInt(16); - int y = random.nextInt(maxY - minY) + minY; - int z = blockZ + random.nextInt(16); + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); final int r; @@ -95,7 +95,7 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } private int getFaceFromString(final String direction) { - String work = direction.toLowerCase(); + final String work = direction.toLowerCase(); switch (work) { case "north": return 0; @@ -135,28 +135,28 @@ private void spawnVein(final int veinLength, final int nodeSize, final int start } // build vein - List> points = Lists.newLinkedList(); + final List> points = Lists.newLinkedList(); points.add(Pair.of(face, square)); for (int j = 0; j < veinLength; j++) { - Map pos = Maps.newHashMap(); - int[] w = getWeighted(face, square); + final Map pos = Maps.newHashMap(); + final int[] w = getWeighted(face, square); for (int k = 0; k < w.length; k++) { pos.put(w[k], k); } - int[] t = Arrays.stream(w).distinct().sorted().toArray(); - int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length - 5, t.length)) + final int[] t = Arrays.stream(w).distinct().sorted().toArray(); + final int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length - 5, t.length)) .map(it -> pos.get(it)).toArray(); - int temp = this.random.nextInt(5); + final int temp = this.random.nextInt(5); face = fpos[temp] % 6; square = fpos[temp] % 12; points.add(Pair.of(face, square)); } spawnOre(world, spawnData, blockPos, nodeSize); - for (Pair point : points) { + for (final Pair point : points) { spawnOre(world, spawnData, workingPos, nodeSize); - int[] nextMunge = getDirectionValues(point.first().intValue(), + final int[] nextMunge = getDirectionValues(point.first().intValue(), point.second().intValue()); workingPos = workingPos.add(nextMunge[0], nextMunge[1], nextMunge[2]); } @@ -164,20 +164,20 @@ private void spawnVein(final int veinLength, final int nodeSize, final int start private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; - int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - Vec3i[] offs = new Vec3i[lutType]; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); if (quantity < 27) { - int[] scrambledLUT = new int[lutType]; + final int[] scrambledLUT = new int[lutType]; System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); while (count > 0) { - IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - BlockPos target = pos.add(offs[scrambledLUT[--count]]); + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } @@ -189,9 +189,9 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, final BlockPos pos) { - int count = quantity; - double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - int rSqr = (int) (radius * radius); + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); if (nextBoolean) { spawnMungeNE(world, pos, rSqr, radius, spawnData, count); } else { @@ -243,11 +243,11 @@ private int[] getDirectionValues(final int face, final int square) { * To keep things heading the correct direction, we weight the faces and the "points" of the * face so that we can choose a semi-intelligent direction to continue in. */ - private int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; - private int[] pointWeights = Arrays.stream(faceWeights).map(a -> a * 2).toArray(); + private final int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; + private final int[] pointWeights = Arrays.stream(faceWeights).map(a -> a * 2).toArray(); private int[] getWeighted(final int face, final int square) { - int[] rv = new int[54]; + final int[] rv = new int[54]; for (int f = 0; f < 6; f++) { for (int s = 0; s < 12; s++) { @@ -272,7 +272,7 @@ private int[] getWeighted(final int face, final int square) { matchFace = getMatchingFace(f, 1); matchSquare = getMatchingSquare(s, f, 1); } - int addr = matchFace + matchSquare; + final int addr = matchFace + matchSquare; rv[addr] += faceWeights[1] + pointWeights[1]; if (s < 3 || s > 8) { @@ -325,7 +325,7 @@ private boolean isNeighborFace(final int face, final int f) { @Override public JsonObject getDefaultParameters() { - JsonObject defParams = new JsonObject(); + final JsonObject defParams = new JsonObject(); defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); defParams.addProperty(Constants.FormatBits.VARIATION, 16); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java index 4577cbca..057eacc0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -17,7 +17,7 @@ public boolean matches(final Biome biome) { @Override public JsonElement serialize() { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); rv.add(ConfigNames.BLACKLIST, new JsonArray()); return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index b887b85b..2e62b7ce 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -28,8 +28,8 @@ public BiomeLocationComposition(final BiomeLocation inclusions, final BiomeLocat @Override public boolean matches(final Biome biome) { - boolean inWhite = this.inclusions.matches(biome); - boolean inBlack = this.exclusions.matches(biome); + final boolean inWhite = this.inclusions.matches(biome); + final boolean inBlack = this.exclusions.matches(biome); return !inBlack && inWhite; } @@ -46,7 +46,7 @@ public boolean equals(final Object obj) { } if (obj instanceof BiomeLocationComposition) { - BiomeLocationComposition other = (BiomeLocationComposition) obj; + final BiomeLocationComposition other = (BiomeLocationComposition) obj; return this.inclusions.equals(other.inclusions) && this.exclusions.equals(other.exclusions); } @@ -56,7 +56,7 @@ public boolean equals(final Object obj) { @Override public ImmutableList getBiomes() { - List temp = new LinkedList<>(); + final List temp = new LinkedList<>(); temp.addAll(this.inclusions.getBiomes()); temp.addAll(this.exclusions.getBiomes()); return ImmutableList.copyOf(temp); @@ -72,7 +72,7 @@ public BiomeLocation getExclusions() { @Override public JsonElement serialize() { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); if (!(this.inclusions instanceof BiomeLocationEmpty)) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index ad2a75c5..56b34080 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -40,7 +40,7 @@ public boolean equals(final Object obj) { @Override public ImmutableList getBiomes() { - List temp = new LinkedList<>(); + final List temp = new LinkedList<>(); locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); return ImmutableList.copyOf(temp); } @@ -51,7 +51,7 @@ public ImmutableSet getLocations() { @Override public JsonElement serialize() { - JsonArray rv = new JsonArray(); + final JsonArray rv = new JsonArray(); this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) .forEach(bl -> rv.add(bl.serialize())); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 21ab9643..a8a9bf51 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -96,5 +96,4 @@ public BiomeLocation create() { return new BiomeLocationComposition(whitelistI, blacklistI); } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index 30f3472f..3994de92 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -21,7 +21,7 @@ public BlockBuilder() { @Override public IBlockBuilder setFromBlockState(final IBlockState blockState) { - ResourceLocation key = blockState.getBlock().getRegistryName(); + final ResourceLocation key = blockState.getBlock().getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } @@ -30,7 +30,7 @@ public IBlockBuilder setFromBlockState(final IBlockState blockState) { @Override public IBlockBuilder setFromBlock(final Block block) { - ResourceLocation key = block.getRegistryName(); + final ResourceLocation key = block.getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } @@ -65,7 +65,7 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, f if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } - Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); } @@ -79,13 +79,13 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, f if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } - Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); } @Override public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance) { - ResourceLocation key = blockState.getBlock().getRegistryName(); + final ResourceLocation key = blockState.getBlock().getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } @@ -96,7 +96,7 @@ public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, f @Override public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { - ResourceLocation key = block.getRegistryName(); + final ResourceLocation key = block.getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; } @@ -133,7 +133,7 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } - Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); } @@ -149,7 +149,7 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } - Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 159feb93..5b2b9871 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -13,7 +13,7 @@ public class BlockList implements IBlockList { private final List myBlocks; - private List workingList; + private final List workingList; public BlockList() { this.myBlocks = new LinkedList<>(); @@ -31,8 +31,8 @@ public IBlockState getRandomBlock(final Random rand) { this.startNewSpawn(); } - int spot = rand.nextInt(this.workingList.size()); - IBlockState rv = this.workingList.get(spot); + final int spot = rand.nextInt(this.workingList.size()); + final IBlockState rv = this.workingList.get(spot); this.workingList.remove(spot); return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index b9cbb1f5..61d9ebc2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -39,15 +39,15 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); if (!this.whitelist.isEmpty()) { - JsonArray wl = new JsonArray(); + final JsonArray wl = new JsonArray(); whitelist.stream().forEach(wl::add); rv.add(Constants.ConfigNames.WHITELIST, wl); } if (!this.blacklist.isEmpty()) { - JsonArray bl = new JsonArray(); + final JsonArray bl = new JsonArray(); blacklist.stream().forEach(bl::add); rv.add(Constants.ConfigNames.WHITELIST, bl); } else if (this.whitelist.isEmpty()) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index 463f486b..8f2b1ce0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -14,7 +14,7 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); rv.add(ConfigNames.BLACKLIST, new JsonArray()); return rv; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java index ca49ef48..263272ca 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -14,13 +14,12 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { - JsonObject rv = new JsonObject(); - JsonArray bl = new JsonArray(); + final JsonObject rv = new JsonObject(); + final JsonArray bl = new JsonArray(); bl.add(-1); bl.add(1); rv.add(Constants.ConfigNames.BLACKLIST, bl); return rv; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index a140a364..49eef5c0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -14,10 +14,9 @@ public boolean matches(final int dimensionID) { @Override public JsonObject serialize() { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); return rv; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 20d745fa..bd8048c8 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -99,7 +99,7 @@ public IFeatureBuilder setUseFeatureDefaults() { @Override public IFeatureEntry create() { - FeatureEntry res = new FeatureEntry(this.feature); + final FeatureEntry res = new FeatureEntry(this.feature); if (!this.useDefaults) { // only copy in the parameters we need this.feature.getDefaultParameters().entrySet().stream() @@ -116,5 +116,4 @@ public IFeatureEntry create() { return res; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 6905fdf1..c5d7167d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -26,7 +26,7 @@ public String getFeatureName() { @Override public JsonObject getFeatureParameters() { - JsonObject defs = feature.getDefaultParameters(); + final JsonObject defs = feature.getDefaultParameters(); this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); return defs; } @@ -50,5 +50,4 @@ public void setParameter(final String parameterName, final boolean parameterValu public void setParameter(final String parameterName, final float parameterValue) { this.parameters.addProperty(parameterName, parameterValue); } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index a7eeb37f..aac8165c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -70,10 +70,10 @@ public void loadConfigFiles() { .getPathMatcher("glob:**/replacements-*.json"); PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); - try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { stream.filter(featuresFiles::matches).map(Path::toFile) .forEach(features::loadFeaturesFile); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -81,9 +81,9 @@ public void loadConfigFiles() { } // have to do this twice or we have issues - try (Stream stream = Files.walk(Constants.SYSCONF, 1)) { + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.SYSCONF.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -94,11 +94,11 @@ public void loadConfigFiles() { presets.load(Constants.SYSCONF.resolve("presets-default.json")); } - try (Stream stream = Files.walk(Constants.CONFDIR, 1)) { + try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { stream.filter(jsonMatcher::matches).forEach(conf -> { try { OreSpawnReader.tryReadFile(conf, this); - } catch (MissingVersionException | NotAProperConfigException | OldVersionException + } catch (final MissingVersionException | NotAProperConfigException | OldVersionException | UnknownVersionException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + conf.toString()); @@ -106,7 +106,7 @@ public void loadConfigFiles() { OreSpawn.LOGGER.info(report.getCompleteReport()); } }); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, failedReadingConfigsFrom + Constants.CONFDIR.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -163,7 +163,7 @@ public IReplacementBuilder getReplacementBuilder() { @Override public Map getReplacements() { - Map temp = new HashMap<>(); + final Map temp = new HashMap<>(); replacements.getReplacements().entrySet().stream() .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); return ImmutableMap.copyOf(temp); @@ -188,7 +188,7 @@ public ISpawnEntry getSpawn(final String spawnName) { @Override public Map getAllSpawns() { - Map sp = new HashMap<>(); + final Map sp = new HashMap<>(); spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); return ImmutableMap.copyOf(sp); } @@ -216,7 +216,7 @@ public IFeature getFeature(final ResourceLocation featureName) { @Override public PresetsStorage copyPresets() { - PresetsStorage copy = new PresetsStorage(); + final PresetsStorage copy = new PresetsStorage(); presets.copy(copy); return copy; } @@ -244,8 +244,8 @@ public void mapEntryToFile(final Path p, final String entryName) { @Override public List getSpawnsForFile(final String fileName) { - Path p = Constants.CONFDIR.resolve(fileName); - List values = spawnsToSourceFiles.entrySet().stream() + final Path p = Constants.CONFDIR.resolve(fileName); + final List values = spawnsToSourceFiles.entrySet().stream() .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) .collect(Collectors.toList()); return ImmutableList.copyOf(values); @@ -253,7 +253,7 @@ public List getSpawnsForFile(final String fileName) { @Override public Map> getSpawnsByFile() { - Map> temp = new HashMap<>(); + final Map> temp = new HashMap<>(); spawnsToSourceFiles.entrySet().stream().forEach(ent -> { if (temp.containsKey(ent.getValue())) { temp.get(ent.getValue()).add(ent.getKey()); @@ -264,5 +264,4 @@ public Map> getSpawnsByFile() { return ImmutableMap.copyOf(temp); } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index c926db65..f4605bd7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -99,5 +99,4 @@ public IReplacementEntry create() { return new ReplacementEntry(this.replacementName, this.entries); } - } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index be4586a2..890ef883 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -150,7 +150,7 @@ public ISpawnBuilder addBlockWithChance(final String blockName, final int blockM @Override public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance) { - IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) .getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @@ -158,8 +158,8 @@ public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLoca @Override public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance) { - Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); return this.addBlockWithChance(tempVar, chance); } @@ -171,20 +171,20 @@ public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLoca @Deprecated public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int blockMetadata, final int chance) { - IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) .getStateFromMeta(blockMetadata); return this.addBlockWithChance(tempVar, chance); } @Override public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { - IBlockState tempVar = block.getDefaultState(); + final IBlockState tempVar = block.getDefaultState(); return this.addBlockWithChance(tempVar, chance); } @Override public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { - BlockBuilder bb = new BlockBuilder(); + final BlockBuilder bb = new BlockBuilder(); bb.setFromBlockStateWithChance(block, chance); return this.addBlock(bb.create()); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 6d675795..0e7ec88a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -103,5 +103,4 @@ public IDimensionList getDimensions() { public BiomeLocation getBiomes() { return this.biomes; } - } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index d3989bf4..f19f309a 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -50,21 +50,21 @@ public class OreSpawnReader { public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { - JsonParser parser = new JsonParser(); + final JsonParser parser = new JsonParser(); try (BufferedReader data = Files.newBufferedReader(conf)) { - JsonElement json = parser.parse(data); + final JsonElement json = parser.parse(data); if (!json.isJsonObject()) { throw new NotAProperConfigException(); } - JsonObject root = json.getAsJsonObject(); + final JsonObject root = json.getAsJsonObject(); if (!root.has(Constants.ConfigNames.FILE_VERSION)) { throw new MissingVersionException(); } - float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); + final float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); if (version < 2f) { throw new OldVersionException(); } else if (version != 2f) { @@ -75,7 +75,7 @@ public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) thr throw new NotAProperConfigException(); } - JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) + final JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) .getAsJsonObject(); spawnData.entrySet().stream().forEach(e -> { try { @@ -88,12 +88,12 @@ public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) thr OreSpawn.LOGGER.info(report.getCompleteReport()); } }); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config data " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (JsonIOException | JsonSyntaxException e) { + } catch (final JsonIOException | JsonSyntaxException e) { CrashReport report = CrashReport.makeCrashReport(e, "JSON Parsing Error in " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); @@ -102,7 +102,7 @@ public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) thr } private static JsonObject doHandlePresets(final JsonObject spawnData) { - PresetsStorage configPresets = OreSpawn.API.copyPresets(); + final PresetsStorage configPresets = OreSpawn.API.copyPresets(); if (spawnData.has(Constants.ConfigNames.PRESETS)) { spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() .forEach(entry -> { @@ -113,8 +113,8 @@ private static JsonObject doHandlePresets(final JsonObject spawnData) { }); } - JsonObject spawnDataFixed = new JsonObject(); - for (Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) + final JsonObject spawnDataFixed = new JsonObject(); + for (final Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) .getAsJsonObject().entrySet()) { spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); } @@ -140,13 +140,13 @@ private static JsonElement doPresetFix(final JsonElement value, final PresetsSto } private static JsonElement doPresetForArray(final JsonArray value, final PresetsStorage configPresets) { - JsonArray rv = new JsonArray(); + final JsonArray rv = new JsonArray(); value.forEach(it -> rv.add(doPresetFix(it, configPresets))); return rv; } private static JsonElement doPresetForObject(final JsonObject value, final PresetsStorage configPresets) { - JsonObject rv = new JsonObject(); + final JsonObject rv = new JsonObject(); value.entrySet().stream().forEach( entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); @@ -154,11 +154,11 @@ private static JsonElement doPresetForObject(final JsonObject value, final Prese } public static void loadFromJson(final String name, final JsonElement json) { - Entry t = new AbstractMap.SimpleEntry<>(name, json); + final Entry t = new AbstractMap.SimpleEntry<>(name, json); try { loadSingleEntry(t); } catch (UnknownFieldException | BadValueException | UnknownNameException e) { - CrashReport report = CrashReport.makeCrashReport(e, + final CrashReport report = CrashReport.makeCrashReport(e, "Error parsing an manual JSON read for " + name); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); @@ -167,11 +167,11 @@ public static void loadFromJson(final String name, final JsonElement json) { private static void loadSingleEntry(final Entry entry) throws UnknownFieldException, BadValueException, UnknownNameException { - ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); - IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); + final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); + final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); sb.setName(entry.getKey()); - for (Entry ent : entry.getValue().getAsJsonObject().entrySet()) { + for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { switch (ent.getKey()) { case Constants.ConfigNames.RETROGEN: sb.setRetrogen(ent.getValue().getAsBoolean()); @@ -180,9 +180,9 @@ private static void loadSingleEntry(final Entry entry) sb.setEnabled(ent.getValue().getAsBoolean()); break; case Constants.ConfigNames.DIMENSIONS: - IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); if (ent.getValue().isJsonArray()) { - JsonArray dims = ent.getValue().getAsJsonArray(); + final JsonArray dims = ent.getValue().getAsJsonArray(); if (dims.size() == 0) { // blank list, accept all overworld db.setAcceptAllOverworld(); @@ -207,7 +207,7 @@ private static void loadSingleEntry(final Entry entry) throw new BadValueException(Constants.ConfigNames.BIOMES, ent.getValue().toString()); } - IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); + final IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); loadBiomes(bb, ent.getValue().getAsJsonObject()); sb.setBiomes(bb.create()); break; @@ -217,14 +217,14 @@ private static void loadSingleEntry(final Entry entry) throw new BadValueException(Constants.ConfigNames.FEATURE, ent.getValue().toString()); } - String featureName = ent.getValue().getAsString(); + final String featureName = ent.getValue().getAsString(); if (!OreSpawn.API.featureExists(featureName)) { throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); } fb.setFeature(featureName); break; case Constants.ConfigNames.REPLACEMENT: - IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); if (!ent.getValue().isJsonArray() && !ent.getValue().getAsJsonPrimitive().isString()) { throw new BadValueException(Constants.ConfigNames.REPLACEMENT, @@ -235,7 +235,7 @@ private static void loadSingleEntry(final Entry entry) rb.setFromName(ent.getValue().getAsString()); } } else { - for (JsonElement e : ent.getValue().getAsJsonArray()) { + for (final JsonElement e : ent.getValue().getAsJsonArray()) { if (e.isJsonObject()) { loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); } else { @@ -253,10 +253,10 @@ private static void loadSingleEntry(final Entry entry) break; case Constants.ConfigNames.BLOCK: if (ent.getValue().isJsonArray()) { - for (JsonElement elem : ent.getValue().getAsJsonArray()) { - IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + for (final JsonElement elem : ent.getValue().getAsJsonArray()) { + final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); if (elem.isJsonObject()) { - JsonObject bl = elem.getAsJsonObject(); + final JsonObject bl = elem.getAsJsonObject(); if (bl.has(Constants.ConfigNames.STATE)) { block.setFromNameWithChance( bl.get(Constants.ConfigNames.NAME).getAsString(), @@ -298,25 +298,25 @@ private static void loadSingleEntry(final Entry entry) } private static List loadBlock(final JsonObject json) { - String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); + final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); if (json.has(Constants.ConfigNames.STATE)) { - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList(StateUtil.deserializeState(block, json.get(Constants.ConfigNames.STATE).getAsString())); } else if (json.has(Constants.ConfigNames.METADATA)) { - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList( block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); } if (blockName.startsWith("ore:")) { - String entry = blockName.split(":")[1]; + final String entry = blockName.split(":")[1]; return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { - Block b = Block.getBlockFromItem(is.getItem()); + final Block b = Block.getBlockFromItem(is.getItem()); return b.getStateFromMeta(is.getMetadata()); }).collect(Collectors.toList())); } - Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList(block.getDefaultState()); } @@ -325,10 +325,10 @@ private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeLis if (biomeList.has(Constants.ConfigNames.WHITELIST) && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - String xN = elem.getAsString(); + final String xN = elem.getAsString(); if (xN.contains(":")) { // not a BiomeDictionary entry (we hope) bb.addWhitelistEntry(xN); @@ -347,10 +347,10 @@ private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeLis if (biomeList.has(Constants.ConfigNames.BLACKLIST) && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - String xN = elem.getAsString(); + final String xN = elem.getAsString(); if (xN.contains(":")) { // not a BiomeDictionary entry (we hope) bb.addBlacklistEntry(xN); @@ -374,7 +374,7 @@ private static void loadDimensions(final IDimensionBuilder db, final JsonObject if (dimensionList.has(Constants.ConfigNames.WHITELIST) && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { db.addWhitelistEntry(elem.getAsInt()); @@ -389,7 +389,7 @@ private static void loadDimensions(final IDimensionBuilder db, final JsonObject if (dimensionList.has(Constants.ConfigNames.BLACKLIST) && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) .getAsJsonArray()) { if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { db.addBlacklistEntry(elem.getAsInt()); diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index c474e957..f8edba41 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -24,26 +24,26 @@ public class OreSpawnWriter { * Write out the configs as the system knows them to the 'forced-saves' directory */ public static void saveConfigs() { - Map> configs = OreSpawn.API.getSpawnsByFile(); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Map> configs = OreSpawn.API.getSpawnsByFile(); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); } private static void saveSingle(final Path filePath, final Gson gson) { - JsonObject root = new JsonObject(); + final JsonObject root = new JsonObject(); root.addProperty(ConfigNames.FILE_VERSION, "2.0"); - JsonObject spawns = new JsonObject(); - String k = filePath.getFileName().toString(); - Path saveDir = Constants.CONFDIR.resolve("forced-saves"); - Path conf = saveDir.resolve(k); + final JsonObject spawns = new JsonObject(); + final String k = filePath.getFileName().toString(); + final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); + final Path conf = saveDir.resolve(k); if (!saveDir.toFile().exists()) { saveDir.toFile().mkdirs(); } - try (BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, + try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { - JsonObject thisSpawn = new JsonObject(); - ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); + final JsonObject thisSpawn = new JsonObject(); + final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); thisSpawn.addProperty(ConfigNames.FEATURE, @@ -57,7 +57,7 @@ private static void saveSingle(final Path filePath, final Gson gson) { }); root.add(ConfigNames.SPAWNS, spawns); p.write(gson.toJson(root)); - } catch (IOException e) { + } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config data " + conf.toString()); report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); @@ -67,7 +67,7 @@ private static void saveSingle(final Path filePath, final Gson gson) { } public static void saveSingle(final String fileName) { - Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); saveSingle(Constants.CONFDIR.resolve(fileName), gson); } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index e4fd5865..28f663e5 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -26,7 +26,7 @@ public static String serializeState(final IBlockState state) { } public static IBlockState deserializeState(final Block block, final String state) { - for (IBlockState validState : block.getBlockState().getValidStates()) { + for (final IBlockState validState : block.getBlockState().getValidStates()) { String string = validState.toString(); string = string.substring(string.indexOf('[') + 1, string.length() - (string.endsWith("]") ? 1 : 0)); diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index 68642888..c3f5b146 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -43,12 +43,12 @@ public void retrogen(final World world, final int chunkX, final int chunkZ) { } private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); for (int xP = 0; xP < 16; xP++) { for (int zP = 0; zP < 16; zP++) { for (int yP = 5; yP > 0; yP--) { - BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); if (yP < plateThickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { @@ -63,13 +63,13 @@ private void genBottomPlate(final World world, final ChunkPos chunkPos, final Bl } private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); - int thickness = 127 - plateThickness; // layer where the flat for the top starts + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + final int thickness = 127 - plateThickness; // layer where the flat for the top starts for (int xP = 0; xP < 16; xP++) { for (int zP = 0; zP < 16; zP++) { for (int yP = 126; yP > 121; yP--) { - BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); if (yP > thickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { @@ -82,5 +82,4 @@ private void genTopPlate(final World world, final ChunkPos chunkPos, final Block } } } - } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 46541f30..e0cb7025 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -18,7 +18,7 @@ public class OreSpawnWorldGen implements IWorldGenerator { public void generate(final Random random, final int chunkX, final int chunkZ, final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { - int thisDim = world.provider.getDimension(); + final int thisDim = world.provider.getDimension(); OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) From 207a85b9c50d9f63794229d891260f7df52e4cda Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 17 Aug 2018 15:35:53 -0700 Subject: [PATCH 058/205] Update mappings --- build.gradle | 3 +-- gradle.properties | 2 ++ settings.gradle | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 settings.gradle diff --git a/build.gradle b/build.gradle index bfb242e5..0ebd0008 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,6 @@ if (System.getenv().BUILD_NUMBER) { version += '.' + System.getenv().BUILD_NUMBER } group = "com.mcmoddev" -archivesBaseName = "OreSpawn" sourceCompatibility = targetCompatibility = "1.8" class Secrets { @@ -71,7 +70,7 @@ if (secretFile.exists()) { minecraft { version = '1.12.2-14.23.4.2705' runDir = 'run' - mappings = 'snapshot_20180716' + mappings = 'stable_39' // coreMod = '' makeObfSourceJar = false diff --git a/gradle.properties b/gradle.properties index 22b71b3c..3fb922ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,5 @@ +archivesBaseName = OreSpawn + mc_version=1.12 top_mc_version=1.11 ccl_version=2.4.3.165 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..0e64f4a2 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = archivesBaseName +enableFeaturePreview('STABLE_PUBLISHING') From a32d53e7981a68cfbd9e7e39a9fd81657a7cb958 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 28 Aug 2018 09:29:34 -0400 Subject: [PATCH 059/205] rework this - its a bit stupider than before, but is heading towards working correctly all the time --- .../orespawn/impl/features/VeinGenerator.java | 441 +++++++++++------- 1 file changed, 279 insertions(+), 162 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index b96dbcc2..2d6c53f1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -1,21 +1,20 @@ package com.mcmoddev.orespawn.impl.features; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Random; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.data.Constants; -import com.mojang.realmsclient.util.Pair; import net.minecraft.block.state.IBlockState; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; @@ -56,7 +55,7 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - final int startingFace = getFaceFromString( + final EnumFacing startingFace = getFaceFromString( params.get(Constants.FormatBits.STARTINGFACE).getAsString()); final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); @@ -94,40 +93,53 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } } - private int getFaceFromString(final String direction) { + private EnumFacing getFaceFromString(final String direction) { final String work = direction.toLowerCase(); switch (work) { case "north": - return 0; + return EnumFacing.NORTH; case "south": - return 5; + return EnumFacing.SOUTH; case "east": - return 2; + return EnumFacing.EAST; case "west": - return 3; + return EnumFacing.WEST; case "down": - return 1; + return EnumFacing.DOWN; case "up": - return 4; + return EnumFacing.UP; case "random": - return this.random.nextInt(5); + return EnumFacing.VALUES[this.random.nextInt(EnumFacing.VALUES.length)]; case "vertical": - return this.random.nextBoolean() ? 4 : 1; + return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; case "horizontal": - return this.random.nextBoolean() ? (this.random.nextBoolean() ? 0 : 5) - : (this.random.nextBoolean() ? 2 : 3); + return this.random.nextBoolean() ? (this.random.nextBoolean() ? EnumFacing.EAST : EnumFacing.WEST) + : (this.random.nextBoolean() ? EnumFacing.NORTH : EnumFacing.SOUTH); default: OreSpawn.LOGGER.error( "Invalid value %s found in parameters for vein spawn, returning \"north\"", direction); - return 0; + return EnumFacing.NORTH; } } - private void spawnVein(final int veinLength, final int nodeSize, final int startingFace, final BlockPos blockPos, + private enum EnumSquare { + TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); + + private int index; + private EnumSquare(int index) { + this.index = index; + } + + final public int getIndex() { + return this.index; + } + } + + private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { - int face = startingFace; - int square = this.random.nextInt(8); + EnumFacing face = startingFace; + EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; BlockPos workingPos = new BlockPos(blockPos); if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { @@ -135,31 +147,260 @@ private void spawnVein(final int veinLength, final int nodeSize, final int start } // build vein - final List> points = Lists.newLinkedList(); - points.add(Pair.of(face, square)); + final List points = Lists.newLinkedList(); for (int j = 0; j < veinLength; j++) { - final Map pos = Maps.newHashMap(); - final int[] w = getWeighted(face, square); - for (int k = 0; k < w.length; k++) { - pos.put(w[k], k); + points.add(workingPos); + List nextFaces = getNextFaceSet(square, face); + face = getNextStartingFace(square, face); + + if(!nextFaces.isEmpty()) { + BlockPos temp = workingPos; + for(EnumFacing f : nextFaces) { + temp = temp.offset(f, 1); + } + nextFaces.clear(); + points.add(temp); } - - final int[] t = Arrays.stream(w).distinct().sorted().toArray(); - final int[] fpos = Arrays.stream(Arrays.copyOfRange(t, t.length - 5, t.length)) - .map(it -> pos.get(it)).toArray(); - final int temp = this.random.nextInt(5); - face = fpos[temp] % 6; - square = fpos[temp] % 12; - points.add(Pair.of(face, square)); } spawnOre(world, spawnData, blockPos, nodeSize); - for (final Pair point : points) { - spawnOre(world, spawnData, workingPos, nodeSize); - final int[] nextMunge = getDirectionValues(point.first().intValue(), - point.second().intValue()); - workingPos = workingPos.add(nextMunge[0], nextMunge[1], nextMunge[2]); + for (final BlockPos pos : points) { + spawnOre(world, spawnData, pos, nodeSize); + } + } + + private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { + EnumFacing[][][] pos = new EnumFacing[][][] { + // Index 0 - DOWN + new EnumFacing[][] { + new EnumFacing[] { EnumFacing.WEST, EnumFacing.DOWN, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.DOWN, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.DOWN, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.DOWN, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.DOWN }, // LEFT_TOP + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.DOWN }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.DOWN }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.DOWN }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.DOWN, null, null } // FACE + }, + new EnumFacing[][] { + // Index 1 - UP + new EnumFacing[] { EnumFacing.WEST, EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.UP, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.UP, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.UP, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.UP }, // LEFT_TOP + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.UP }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.UP }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.UP }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.UP, null, null } // FACE + }, + new EnumFacing[][] { + // Index 2 - NORTH + new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.WEST, EnumFacing.NORTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.NORTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, EnumFacing.NORTH }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, EnumFacing.NORTH }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.NORTH }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.NORTH }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.NORTH, null, null } // FACE + }, + new EnumFacing[][] { + // Index 3 - SOUTH + new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.SOUTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.WEST, EnumFacing.SOUTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.SOUTH }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.SOUTH }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, EnumFacing.SOUTH }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, EnumFacing.SOUTH }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.SOUTH, null, null } // FACE + }, + new EnumFacing[][] { + // Index 4 - WEST + new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH, EnumFacing.WEST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH, EnumFacing.WEST }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.WEST }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, EnumFacing.WEST }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.WEST, null, null } // FACE + }, + new EnumFacing[][] { + // Index 5 - EAST + new EnumFacing[] { EnumFacing.EAST, EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.NORTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.EAST, EnumFacing.SOUTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.NORTH }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.SOUTH }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.SOUTH }, // RIGHT_TOP + new EnumFacing[] { EnumFacing.EAST, null, null } // FACE + } + }; + + EnumFacing[] possibles = (EnumFacing[])Arrays.asList(pos[face.getIndex()][square.getIndex()]).stream().filter(it -> it != null).toArray(); + if(possibles.length > 1) { + return possibles[this.random.nextInt(possibles.length)]; } + return possibles[0]; + } + + private List getNextFaceSet(EnumSquare square, EnumFacing face) { + List rv = new ArrayList<>(); + + rv.add(face); + + switch(square) { + case BOTTOM_EDGE: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case TOP_EDGE: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_EDGE: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + break; + default: + break; + } + break; + case RIGHT_EDGE: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.WEST); + break; + default: + break; + } + break; + case FACE: + break; + case LEFT_TOP: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_BOTTOM: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case RIGHT_TOP: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case RIGHT_BOTTOM: + switch(face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + default: + break; + } + + return rv; } private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { @@ -199,130 +440,6 @@ private void doSpawnFill(final boolean nextBoolean, final int quantity, final Wo } } - private int[] getDirectionValues(final int face, final int square) { - int x = 0; - int y = 0; - int z = 0; - switch (face) { - case 0: - z = -1; - break; - case 2: - x = 1; - break; - case 3: - x = -1; - break; - case 5: - z = 1; - break; - } - if (face == 0 || face == 5) { - y = square < 3 ? 1 : (square > 5 ? -1 : 0); - x = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); - } else if (face == 2 || face == 3) { - y = square < 3 ? 1 : square > 5 ? -1 : 0; - z = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); - } else if (face == 1 || face == 4) { - z = square < 3 ? -1 : (square > 5 ? 1 : 0); - x = (square == 0 || square % 3 == 0) ? -1 : (((square + 1) % 3 == 0) ? 1 : 0); - } - - if (square < 3 || face == 4) { - y = 1; - } else if (square <= 5) { - y = 0; - } else if (square <= 8 || face == 1) { - y = -1; - } - - return new int[] { x, y, z }; - } - - /* - * To keep things heading the correct direction, we weight the faces and the "points" of the - * face so that we can choose a semi-intelligent direction to continue in. - */ - private final int[] faceWeights = new int[] { /* self */ 2, /* other */ 1 }; - private final int[] pointWeights = Arrays.stream(faceWeights).map(a -> a * 2).toArray(); - - private int[] getWeighted(final int face, final int square) { - final int[] rv = new int[54]; - - for (int f = 0; f < 6; f++) { - for (int s = 0; s < 12; s++) { - if (isNeighborFace(face, f)) { - rv[f + s] += faceWeights[1]; - } else if (face == f) { - rv[f + s] += faceWeights[0]; - } else { - rv[f + s] = 0; - } - - rv[f + s] += pointWeights[s == square ? 0 : 1]; - if (s != 4 && s != 7) { - int matchFace = 0; - int matchSquare = 0; - if (s % 3 == 0) { - // left side - matchFace = getMatchingFace(f, 0); - matchSquare = getMatchingSquare(s, f, 0); - } else if (s == 2 || s == 5 || s == 8 || s == 11) { - // right side - matchFace = getMatchingFace(f, 1); - matchSquare = getMatchingSquare(s, f, 1); - } - final int addr = matchFace + matchSquare; - rv[addr] += faceWeights[1] + pointWeights[1]; - - if (s < 3 || s > 8) { - if (s < 3) { - // top row - matchFace = getMatchingFace(f, 2); - matchSquare = getMatchingSquare(s, f, 2); - } else if (s > 8) { - // bottom row - matchFace = getMatchingFace(f, 3); - matchSquare = getMatchingSquare(s, f, 3); - } - rv[matchFace + matchSquare] += faceWeights[1] + pointWeights[1]; - } - } - } - } - - return rv; - } - - /* - * 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 11 -------- 0 1 2 3 4 5 6 7 8 9 10 - * 11 - */ - private int getMatchingSquare(final int s, final int face, final int direction) { - switch (direction) { - case 0: /* LEFT */ - return (s % 3 == 0) ? s + 2 : s - 1; - case 1: /* RIGHT */ - return (s == 2 || s == 5 || s == 8 || s == 11) ? s - 2 : s + 1; - case 2: /* UP */ - return (s < 3) ? s + 9 : s - 3; - case 3: /* DOWN */ - return (s > 8) ? s - 9 : s + 3; - } - return s; - } - - private int[][] faceMap = new int[][] { { 3, 2, 1, 4 }, { 3, 2, 5, 0 }, { 1, 4, 5, 0 }, - { 4, 1, 5, 0 }, { 2, 3, 5, 0 }, { 3, 2, 4, 1 } }; - - private int getMatchingFace(final int f, final int i) { - return faceMap[f][i]; - } - - private boolean isNeighborFace(final int face, final int f) { - return Arrays.stream(faceMap[face]).anyMatch(a -> a == f); - } - @Override public JsonObject getDefaultParameters() { final JsonObject defParams = new JsonObject(); From aa7a5e0bcf4cba558468e66fe17079b63b92a8c3 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 28 Aug 2018 10:43:05 -0400 Subject: [PATCH 060/205] add weighted selection of the next square and give a bit of weighting towards continuing in one direction to the selection of the next face --- .../orespawn/impl/features/VeinGenerator.java | 131 ++++++++++-------- 1 file changed, 77 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 2d6c53f1..87938bee 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -15,6 +15,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.util.EnumFacing; +import net.minecraft.util.WeightedRandom; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; @@ -160,7 +161,10 @@ private void spawnVein(final int veinLength, final int nodeSize, final EnumFacin } nextFaces.clear(); points.add(temp); + } else { + j--; } + square = getNextSquare(); } spawnOre(world, spawnData, blockPos, nodeSize); @@ -169,83 +173,102 @@ private void spawnVein(final int veinLength, final int nodeSize, final EnumFacin } } + private class SquareWeight extends WeightedRandom.Item { + public EnumSquare item; + + public SquareWeight(EnumSquare item, int weight) { + super(weight); + this.item = item; + } + } + + private EnumSquare getNextSquare() { + float[] weights = new float[] { 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f }; + List items = new ArrayList<>(); + + for (EnumSquare sq : EnumSquare.values()) { + items.add(new SquareWeight(sq, (int)(weights[sq.getIndex()] * 10000))); + } + + return ((SquareWeight)WeightedRandom.getRandomItem(this.random, items)).item; + } + private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { EnumFacing[][][] pos = new EnumFacing[][][] { // Index 0 - DOWN new EnumFacing[][] { - new EnumFacing[] { EnumFacing.WEST, EnumFacing.DOWN, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.DOWN, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.DOWN, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.DOWN, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.DOWN }, // LEFT_TOP - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.DOWN }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.DOWN }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.DOWN }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.DOWN, null, null } // FACE + new EnumFacing[] { EnumFacing.WEST, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.EAST, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST } // RIGHT_TOP }, new EnumFacing[][] { // Index 1 - UP - new EnumFacing[] { EnumFacing.WEST, EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.UP, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.UP, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.UP, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.UP }, // LEFT_TOP - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.UP }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST, EnumFacing.UP }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, EnumFacing.UP }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.UP, null, null } // FACE + new EnumFacing[] { EnumFacing.WEST, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.EAST, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST } // RIGHT_TOP }, new EnumFacing[][] { // Index 2 - NORTH - new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.WEST, EnumFacing.NORTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.NORTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, EnumFacing.NORTH }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, EnumFacing.NORTH }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.NORTH }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.NORTH }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.NORTH, null, null } // FACE + new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.WEST, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.EAST, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST } // RIGHT_TOP }, new EnumFacing[][] { // Index 3 - SOUTH - new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.SOUTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.WEST, EnumFacing.SOUTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.SOUTH }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.SOUTH }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, EnumFacing.SOUTH }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, EnumFacing.SOUTH }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.SOUTH, null, null } // FACE + new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.EAST, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.WEST, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST } // RIGHT_TOP }, new EnumFacing[][] { // Index 4 - WEST - new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH, EnumFacing.WEST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH, EnumFacing.WEST }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.WEST }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, EnumFacing.WEST }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.WEST, null, null } // FACE + new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.SOUTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.NORTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH } // RIGHT_TOP }, new EnumFacing[][] { // Index 5 - EAST - new EnumFacing[] { EnumFacing.EAST, EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.NORTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.EAST, EnumFacing.SOUTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.NORTH }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.SOUTH }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.SOUTH }, // RIGHT_TOP - new EnumFacing[] { EnumFacing.EAST, null, null } // FACE + new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE + new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE + new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE + new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE + new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH }, // LEFT_TOP + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH }, // LEFT_BOTTOM + new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH }, // RIGHT_BOTTOM + new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH } // RIGHT_TOP } }; + + if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { + return face; + } EnumFacing[] possibles = (EnumFacing[])Arrays.asList(pos[face.getIndex()][square.getIndex()]).stream().filter(it -> it != null).toArray(); + if(possibles.length > 1) { return possibles[this.random.nextInt(possibles.length)]; } From 2ce7eb5826d70d95ef8a52bcd0a96b522ab68407 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 28 Aug 2018 13:31:59 -0400 Subject: [PATCH 061/205] new vein generator code functional, looking decent and ran the formatter across the entire project. --- .../com/mcmoddev/orespawn/EventHandlers.java | 18 +- .../java/com/mcmoddev/orespawn/OreSpawn.java | 17 +- .../mcmoddev/orespawn/api/FeatureBase.java | 72 ++-- .../api/exceptions/BadValueException.java | 6 +- .../api/exceptions/UnknownFieldException.java | 4 +- .../api/exceptions/UnknownNameException.java | 6 +- .../orespawn/api/os3/IBlockBuilder.java | 26 +- .../orespawn/api/os3/IFeatureBuilder.java | 3 +- .../orespawn/api/os3/IReplacementBuilder.java | 6 +- .../orespawn/api/os3/ISpawnBuilder.java | 23 +- .../orespawn/api/plugin/PluginLoader.java | 6 +- .../orespawn/commands/AddOreCommand.java | 4 +- .../orespawn/commands/ClearChunkCommand.java | 31 +- .../orespawn/commands/DumpBiomesCommand.java | 4 +- .../commands/WriteConfigsCommand.java | 4 +- .../com/mcmoddev/orespawn/data/Config.java | 12 +- .../com/mcmoddev/orespawn/data/Constants.java | 143 ++++---- .../orespawn/data/FeatureRegistry.java | 4 +- .../orespawn/data/PresetsStorage.java | 7 +- .../orespawn/data/ReplacementsRegistry.java | 13 +- .../impl/features/ClusterGenerator.java | 20 +- .../features/DefaultFeatureGenerator.java | 11 +- .../impl/features/NormalCloudGenerator.java | 9 +- .../impl/features/PrecisionGenerator.java | 37 ++- .../orespawn/impl/features/VeinGenerator.java | 313 ++++++++++++------ .../location/BiomeLocationComposition.java | 3 +- .../orespawn/impl/os3/BiomeBuilder.java | 4 +- .../orespawn/impl/os3/BlockBuilder.java | 32 +- .../orespawn/impl/os3/BlockDefinition.java | 6 +- .../mcmoddev/orespawn/impl/os3/BlockList.java | 4 +- .../orespawn/impl/os3/DimensionBuilder.java | 10 +- .../orespawn/impl/os3/DimensionList.java | 4 +- .../orespawn/impl/os3/FeatureBuilder.java | 9 +- .../orespawn/impl/os3/FeatureEntry.java | 4 +- .../orespawn/impl/os3/OS3APIImpl.java | 16 +- .../orespawn/impl/os3/ReplacementBuilder.java | 12 +- .../orespawn/impl/os3/ReplacementEntry.java | 4 +- .../orespawn/impl/os3/SpawnBuilder.java | 31 +- .../orespawn/impl/os3/SpawnEntry.java | 21 +- .../orespawn/json/OreSpawnReader.java | 15 +- .../orespawn/worldgen/FlatBedrock.java | 6 +- 41 files changed, 561 insertions(+), 419 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index c9d386f5..51c5137a 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -38,8 +38,8 @@ public class EventHandlers { - private final Deque retroChunks; - private final Deque>> chunks; + private final Deque retroChunks; + private final Deque>> chunks; // private Map> chunks EventHandlers() { @@ -113,7 +113,8 @@ public void onChunkLoad(final ChunkDataEvent.Load ev) { } } - private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, final Biome biome) { + private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); final Map currentBits = new TreeMap<>(); final Map oldBits = new TreeMap<>(); @@ -135,7 +136,8 @@ private List getDifferingTags(final NBTTagCompound chunkTag, final int d return ImmutableList.copyOf(stuff); } - private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, final Biome biome) { + private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); final Map currentBits = new TreeMap<>(); final Map oldBits = new TreeMap<>(); @@ -163,10 +165,10 @@ private void doBedrockRetrogen(final ChunkPos chunkCoords) { } } - private static World world; - private static ChunkProviderServer chunkProvider; - private static IChunkGenerator chunkGenerator; - private static Random random; + private static World world; + private static ChunkProviderServer chunkProvider; + private static IChunkGenerator chunkGenerator; + private static Random random; private static void setupData(final World nw) { if (world == null || !world.equals(nw)) { diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 230e7d5b..855bc10f 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -38,18 +38,23 @@ * @author DShadowWolf <dshadowwolf@gmail.com> */ -@Mod(modid = Constants.MODID, name = Constants.NAME, version = Constants.VERSION, acceptedMinecraftVersions = "[1.12,)", certificateFingerprint = "@FINGERPRINT@") +@Mod(modid = Constants.MODID, + name = Constants.NAME, + version = Constants.VERSION, + acceptedMinecraftVersions = "[1.12,)", + certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { @Instance public static OreSpawn instance; - public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID); - public static final OS3API API = new OS3APIImpl(); - static final EventHandlers eventHandlers = new EventHandlers(); - public static final FeatureRegistry FEATURES = new FeatureRegistry(); - protected static final Map> spawns = new HashMap<>(); + public static final Logger LOGGER = LogManager + .getFormatterLogger(Constants.MODID); + public static final OS3API API = new OS3APIImpl(); + static final EventHandlers eventHandlers = new EventHandlers(); + public static final FeatureRegistry FEATURES = new FeatureRegistry(); + protected static final Map> spawns = new HashMap<>(); static final FlatBedrock flatBedrock = new FlatBedrock(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 470a540a..c3159274 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -23,15 +23,15 @@ public class FeatureBase extends IForgeRegistryEntry.Impl { - private static final int MAX_CACHE_SIZE = 2048; + private static final int MAX_CACHE_SIZE = 2048; /** * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk * without triggering a chunk-load. */ - private static final Map> overflowCache = new HashMap<>( + private static final Map> overflowCache = new HashMap<>( MAX_CACHE_SIZE); - private static final Deque cacheOrder = new LinkedList<>(); - protected Random random; + private static final Deque cacheOrder = new LinkedList<>(); + protected Random random; public FeatureBase(final Random rand) { this.random = rand; @@ -41,7 +41,8 @@ public boolean isValidBlock(final IBlockState oreBlock) { return oreBlock.getBlock() != Blocks.AIR; } - protected void runCache(final int chunkX, final int chunkZ, final World world, final ISpawnEntry spawnData) { + protected void runCache(final int chunkX, final int chunkZ, final World world, + final ISpawnEntry spawnData) { final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); final Map cache = retrieveCache(chunkCoord); @@ -53,8 +54,8 @@ protected void runCache(final int chunkX, final int chunkZ, final World world, f } } - protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, - final boolean cacheOverflow, final ISpawnEntry spawnData) { + protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return false; @@ -90,8 +91,9 @@ private BlockPos mungeFixYcoord(final BlockPos coord) { } } - private boolean spawnOrCache(final World world, final BlockPos coord, final OreSpawnBlockMatcher replacer, - final IBlockState oreBlock, final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { + private boolean spawnOrCache(final World world, final BlockPos coord, + final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, + final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { if (!isValidBlock(oreBlock)) { return false; @@ -114,8 +116,8 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final OreS return false; } - private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, - final ISpawnEntry spawnData) { + private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final ISpawnEntry spawnData) { if (oreBlock == null) { OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); return; @@ -131,7 +133,8 @@ private void spawnNoCheck(final IBlockState oreBlock, final World world, final B spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); } - private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, final int dimension) { + private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, + final int dimension) { final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); if (overflowCache.containsKey(chunkCoord)) { @@ -146,7 +149,8 @@ private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, fina overflowCache.put(chunkCoord, new HashMap<>()); } - final Map cache = overflowCache.getOrDefault(chunkCoord, new HashMap<>()); + final Map cache = overflowCache.getOrDefault(chunkCoord, + new HashMap<>()); cache.put(coord, bs); } @@ -170,14 +174,16 @@ protected void scramble(final int[] target, final Random prng) { } } - protected static final Vec3i[] offsets_small = { new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), - new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), + protected static final Vec3i[] offsets_small = { + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) }; + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) + }; - protected static final Vec3i[] offsets = { new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), - new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), - new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), new Vec3i(1, 1, -1), + protected static final Vec3i[] offsets = { + new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), + new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), + new Vec3i(1, 1, -1), new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), @@ -185,13 +191,19 @@ protected void scramble(final int[] target, final Random prng) { new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), - new Vec3i(1, 1, 1) }; - - protected static final int[] offsetIndexRef = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 }; - protected static final int[] offsetIndexRef_small = { 0, 1, 2, 3, 4, 5, 6, 7 }; - - protected static void mergeDefaults(final JsonObject parameters, final JsonObject defaultParameters) { + new Vec3i(1, 1, 1) + }; + + protected static final int[] offsetIndexRef = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26 + }; + protected static final int[] offsetIndexRef_small = { + 0, 1, 2, 3, 4, 5, 6, 7 + }; + + protected static void mergeDefaults(final JsonObject parameters, + final JsonObject defaultParameters) { defaultParameters.entrySet().forEach(entry -> { if (!parameters.has(entry.getKey())) { parameters.add(entry.getKey(), entry.getValue()); @@ -216,8 +228,8 @@ protected int getPoint(final int lowerBound, final int upperBound, final int med return t - median; } - protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, final double radius, - final ISpawnEntry spawnData, final int count) { + protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { final Random prng = this.random; int quantity = count; final IBlockList possibleOres = spawnData.getBlocks(); @@ -239,8 +251,8 @@ protected void spawnMungeSW(final World world, final BlockPos blockPos, final in } } - protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, final double radius, - final ISpawnEntry spawnData, final int count) { + protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { final Random prng = this.random; int quantity = count; final IBlockList possibleOres = spawnData.getBlocks(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index e45b98a1..e2a82bfa 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -2,9 +2,9 @@ public class BadValueException extends Exception { - private static final long serialVersionUID = 1143938140559149506L; - private final String keyName; - private final String keyValue; + private static final long serialVersionUID = 1143938140559149506L; + private final String keyName; + private final String keyValue; public BadValueException(final String keyName, final String keyValue) { super(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 9cf2b4ad..e3d14167 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -2,8 +2,8 @@ public class UnknownFieldException extends Exception { - private static final long serialVersionUID = 1L; - private final String message; + private static final long serialVersionUID = 1L; + private final String message; public UnknownFieldException(final String theField) { super(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 8e5b6049..06a83368 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -2,9 +2,9 @@ public class UnknownNameException extends Exception { - private static final long serialVersionUID = -3426121906665390773L; - private final String fieldName; - private final String fieldValue; + private static final long serialVersionUID = -3426121906665390773L; + private final String fieldName; + private final String fieldValue; public UnknownNameException(final String fieldName, final String fieldValue) { super(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 768e3bc6..54baec34 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -58,8 +58,7 @@ public interface IBlockBuilder { * @param state * @return */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, - String state); + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); /** * @@ -69,8 +68,7 @@ IBlockBuilder setFromName(ResourceLocation blockResourceLocation, * @deprecated */ @Deprecated - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, - int metadata); + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); /** * @@ -78,8 +76,7 @@ IBlockBuilder setFromName(ResourceLocation blockResourceLocation, * @param chance * @return */ - IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, - int chance); + IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); /** * @@ -104,8 +101,7 @@ IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, * @param chance * @return */ - IBlockBuilder setFromNameWithChance(String blockName, String state, - int chance); + IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); /** * @@ -116,8 +112,7 @@ IBlockBuilder setFromNameWithChance(String blockName, String state, * @deprecated */ @Deprecated - IBlockBuilder setFromNameWithChance(String blockName, int metadata, - int chance); + IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); /** * @@ -125,8 +120,7 @@ IBlockBuilder setFromNameWithChance(String blockName, int metadata, * @param chance * @return */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, - int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); /** * @@ -135,8 +129,8 @@ IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, * @param chance * @return */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, - String state, int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, + int chance); /** * @@ -147,8 +141,8 @@ IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, * @deprecated */ @Deprecated - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, - int metadata, int chance); + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, + int chance); /** * diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index 34c45c1c..20fefa25 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -21,8 +21,7 @@ public interface IFeatureBuilder { IFeatureBuilder setParameter(String parameterName, boolean parameterValue); - IFeatureBuilder setParameter(String parameterName, - JsonElement parameterValue); + IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); IFeatureBuilder setUseFeatureDefaults(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index 275f58dd..ecf91e74 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -64,8 +64,7 @@ public interface IReplacementBuilder { * @param state * @return */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, - String state); + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); /** * @@ -75,8 +74,7 @@ IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, * @deprecated */ @Deprecated - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, - int metadata); + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); boolean hasEntries(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 027b1c70..3808d61a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -31,11 +31,9 @@ public interface ISpawnBuilder { ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, - String blockState); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, - int blockMetadata); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); ISpawnBuilder addBlock(Block block); @@ -43,20 +41,17 @@ ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, ISpawnBuilder addBlockWithChance(String blockName, int chance); - ISpawnBuilder addBlockWithChance(String blockName, String blockState, - int chance); + ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); - ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, - int chance); + ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - String blockState, int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, + int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, - int blockMetadata, int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, + int chance); ISpawnBuilder addBlockWithChance(Block block, int chance); diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index 2d23b41f..fcd96e7e 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -35,9 +35,9 @@ public enum PluginLoader { private class PluginData { - public final String modId; - public final String resourcePath; - public final IOreSpawnPlugin plugin; + public final String modId; + public final String resourcePath; + public final IOreSpawnPlugin plugin; PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { this.modId = modId; diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 70f55fc4..8ec4a687 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -37,8 +37,8 @@ public String getUsage(final ICommandSender sender) { } @Override - public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) - throws CommandException { + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 804ad646..1db09255 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -27,17 +27,17 @@ public class ClearChunkCommand extends CommandBase { - private static final String STONE_ID = "minecraft:stone"; - private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", - "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", + private static final String STONE_ID = "minecraft:stone"; + private static final List stoneVariants = Arrays.asList(STONE_ID, + "minecraft:diorite", "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); - private static final List baseStones = Arrays.asList(STONE_ID, "minecraft:netherrack", - "minecraft:end_stone", "minecraft:cobblestone", "minecraft:obsidian", "minecraft:magma", - "minecraft:soul_sand"); + private static final List baseStones = Arrays.asList(STONE_ID, + "minecraft:netherrack", "minecraft:end_stone", "minecraft:cobblestone", + "minecraft:obsidian", "minecraft:magma", "minecraft:soul_sand"); - private static final List dirtVariants = Arrays.asList("minecraft:dirt", + private static final List dirtVariants = Arrays.asList("minecraft:dirt", "minecraft:grass"); - private static final List otherVariants = Arrays.asList("minecraft:gravel", + private static final List otherVariants = Arrays.asList("minecraft:gravel", "minecraft:sand"); @Override @@ -51,8 +51,8 @@ public String getUsage(final ICommandSender sender) { } @Override - public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) - throws CommandException { + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { if (!(sender instanceof EntityPlayer)) { throw new CommandException("Only players can use this command"); } @@ -62,7 +62,8 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f final ChunkPos chunkPos = chunk.getPos(); final List blocks; - final boolean flagClassic = args.length > 0 ? args[0].toLowerCase().equalsIgnoreCase("classic") + final boolean flagClassic = args.length > 0 + ? args[0].toLowerCase().equalsIgnoreCase("classic") : false; final List blockNames = new LinkedList<>(); @@ -89,7 +90,8 @@ public void execute(final MinecraftServer server, final ICommandSender sender, f } private void clearBlocks(final ChunkPos chunkPos, final List blocks, - final List overburden, final boolean flagClassic, final EntityPlayer player) { + final List overburden, final boolean flagClassic, + final EntityPlayer player) { for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { for (int y = 256; y >= 0; y--) { for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { @@ -112,8 +114,9 @@ private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { } } - private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, final IBlockState block, - final List blocks, final List overburden, final boolean flagClassic) { + private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, + final IBlockState block, final List blocks, + final List overburden, final boolean flagClassic) { if (blocks.contains(block) || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { player.getEntityWorld().setBlockToAir(pos); diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 62dad5e4..74bf10a5 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -34,8 +34,8 @@ public String getUsage(final ICommandSender sender) { } @Override - public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) - throws CommandException { + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { JsonArray array = new JsonArray(); for (final Biome biome : ForgeRegistries.BIOMES) { diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index ed4de9c8..4d1dc064 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -21,8 +21,8 @@ public String getUsage(final ICommandSender sender) { } @Override - public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) - throws CommandException { + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { sender.sendMessage(new TextComponentString( "Forcing configs as OreSpawn sees them to be written to disk")); OreSpawnWriter.saveConfigs(); diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 08ba58c7..95ade634 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -160,10 +160,10 @@ private static void saveKnownConfigs() { } } - private static final HashMap boolVals = new HashMap<>(); - private static final HashMap stringVals = new HashMap<>(); - private static final HashMap intVals = new HashMap<>(); - private static final HashMap floatVals = new HashMap<>(); - private static final List knownKeys = new ArrayList<>(); - private static final List extractedConfigs = new ArrayList<>(); + private static final HashMap boolVals = new HashMap<>(); + private static final HashMap stringVals = new HashMap<>(); + private static final HashMap intVals = new HashMap<>(); + private static final HashMap floatVals = new HashMap<>(); + private static final List knownKeys = new ArrayList<>(); + private static final List extractedConfigs = new ArrayList<>(); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 7c6ea724..cbe7543e 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -5,55 +5,56 @@ public class Constants { - public static final String MODID = "orespawn"; - public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.3.0"; - public static final String RETROGEN_KEY = "Retrogen"; - public static final String CONFIG_FILE = "config/orespawn.cfg"; - public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; - public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; - public static final String ORE_TAG = "ores"; - public static final String FEATURES_TAG = "features"; - public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; - public static final String OVERWORLD = "overworld"; - public static final String THE_OVERWORLD = "the overworld"; - public static final String NETHER = "nether"; - public static final String THE_NETHER = "the nether"; - public static final String END = "end"; - public static final String THE_END = "the end"; - public static final String DEFAULT_GEN = "default"; - public static final String VEIN_GEN = "vein"; - public static final String NORMAL_CLOUD = "normal-cloud"; - public static final String CLUSTERS = "clusters"; - public static final String CRASH_SECTION = "OreSpawn Version"; - public static final String KNOWN_MODS = "already-extracted"; - public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; - public static final String FLAT_BEDROCK = "Flatten Bedrock"; - public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; - public static final String BEDROCK_LAYERS = "Bedrock Thickness"; - public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; - public static final String PRECISION = "precision"; - public static final Path CONFDIR = Paths.get("config", "orespawn3"); - public static final Path SYSCONF = Paths.get("config", "orespawn3", "sysconf"); + public static final String MODID = "orespawn"; + public static final String NAME = "MMD OreSpawn"; + public static final String VERSION = "3.3.0"; + public static final String RETROGEN_KEY = "Retrogen"; + public static final String CONFIG_FILE = "config/orespawn.cfg"; + public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; + public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; + public static final String ORE_TAG = "ores"; + public static final String FEATURES_TAG = "features"; + public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; + public static final String OVERWORLD = "overworld"; + public static final String THE_OVERWORLD = "the overworld"; + public static final String NETHER = "nether"; + public static final String THE_NETHER = "the nether"; + public static final String END = "end"; + public static final String THE_END = "the end"; + public static final String DEFAULT_GEN = "default"; + public static final String VEIN_GEN = "vein"; + public static final String NORMAL_CLOUD = "normal-cloud"; + public static final String CLUSTERS = "clusters"; + public static final String CRASH_SECTION = "OreSpawn Version"; + public static final String KNOWN_MODS = "already-extracted"; + public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; + public static final String FLAT_BEDROCK = "Flatten Bedrock"; + public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; + public static final String BEDROCK_LAYERS = "Bedrock Thickness"; + public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; + public static final String PRECISION = "precision"; + public static final Path CONFDIR = Paths.get("config", "orespawn3"); + public static final Path SYSCONF = Paths.get("config", "orespawn3", + "sysconf"); public final class FormatBits { private FormatBits() { } - public static final String MAX_SPREAD = "maxSpread"; - public static final String MEDIAN_SIZE = "medianSize"; - public static final String MIN_HEIGHT = "minHeight"; - public static final String MAX_HEIGHT = "maxHeight"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String NODE_SIZE = "size"; - public static final String ATTEMPTS = "attempts"; - public static final String LENGTH = "length"; - public static final String NODE_COUNT = "numObjects"; - public static final String ATTEMPTS_MIN = "minAttempts"; - public static final String ATTEMPTS_MAX = "maxAttempts"; - public static final String STARTINGFACE = "startFacing"; + public static final String MAX_SPREAD = "maxSpread"; + public static final String MEDIAN_SIZE = "medianSize"; + public static final String MIN_HEIGHT = "minHeight"; + public static final String MAX_HEIGHT = "maxHeight"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String NODE_SIZE = "size"; + public static final String ATTEMPTS = "attempts"; + public static final String LENGTH = "length"; + public static final String NODE_COUNT = "numObjects"; + public static final String ATTEMPTS_MIN = "minAttempts"; + public static final String ATTEMPTS_MAX = "maxAttempts"; + public static final String STARTINGFACE = "startFacing"; } public final class FileBits { @@ -61,10 +62,10 @@ public final class FileBits { private FileBits() { } - public static final String CONFIG_DIR = "config"; - public static final String OS3 = "orespawn3"; - public static final String SYSCONF = "sysconf"; - public static final String PRESETS = "presets.json"; + public static final String CONFIG_DIR = "config"; + public static final String OS3 = "orespawn3"; + public static final String SYSCONF = "sysconf"; + public static final String PRESETS = "presets.json"; } public final class ConfigNames { @@ -72,36 +73,36 @@ public final class ConfigNames { private ConfigNames() { } - public static final String DEFAULT = "default"; - public static final String STATE_NORMAL = "normal"; - public static final String DIMENSIONS = "dimensions"; - public static final String CHANCE = "chance"; - public static final String METADATA = "metaData"; - public static final String BIOMES = "biomes"; - public static final String STATE = "state"; - public static final String REPLACEMENT = "replaces"; - public static final String FEATURE = "feature"; - public static final String PARAMETERS = "parameters"; - public static final String FILE_VERSION = "version"; - public static final String BLOCK = "blocks"; - public static final String SPAWNS = "spawns"; - public static final String RETROGEN = "retrogen"; - public static final String ENABLED = "enabled"; - public static final String NAME = "name"; - public static final String WHITELIST = "includes"; - public static final String BLACKLIST = "excludes"; - public static final String PRESETS = "presets"; + public static final String DEFAULT = "default"; + public static final String STATE_NORMAL = "normal"; + public static final String DIMENSIONS = "dimensions"; + public static final String CHANCE = "chance"; + public static final String METADATA = "metaData"; + public static final String BIOMES = "biomes"; + public static final String STATE = "state"; + public static final String REPLACEMENT = "replaces"; + public static final String FEATURE = "feature"; + public static final String PARAMETERS = "parameters"; + public static final String FILE_VERSION = "version"; + public static final String BLOCK = "blocks"; + public static final String SPAWNS = "spawns"; + public static final String RETROGEN = "retrogen"; + public static final String ENABLED = "enabled"; + public static final String NAME = "name"; + public static final String WHITELIST = "includes"; + public static final String BLACKLIST = "excludes"; + public static final String PRESETS = "presets"; public final class DefaultFeatureProperties { private DefaultFeatureProperties() { } - public static final String SIZE = "size"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String MAXHEIGHT = "maxHeight"; - public static final String MINHEIGHT = "minHeight"; + public static final String SIZE = "size"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String MAXHEIGHT = "maxHeight"; + public static final String MINHEIGHT = "minHeight"; } } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 8042f745..675f5842 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -28,8 +28,8 @@ public class FeatureRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistry registry = new RegistryBuilder() + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistry registry = new RegistryBuilder() .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO .create(); diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index e8137fcd..6b8c715f 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -21,14 +21,15 @@ public class PresetsStorage { - private final Map> storage; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private final Map> storage; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; public PresetsStorage() { storage = new TreeMap<>(); } - public void setSymbolSection(final String sectionName, final String itemName, final JsonElement value) { + public void setSymbolSection(final String sectionName, final String itemName, + final JsonElement value) { final Map temp = storage.getOrDefault(sectionName, new HashMap()); temp.put(itemName, value); diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 9701d3e8..a78868d7 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -41,8 +41,8 @@ public class ReplacementsRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... .create(); @@ -63,7 +63,9 @@ public Map getReplacements() { */ @Deprecated public List getDimensionDefault(final int dimension) { - final String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; + final String[] names = { + "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" + }; final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) @@ -87,6 +89,7 @@ public List getDimensionDefault(final int dimension) { public IReplacementEntry getReplacement(final String name) { final ResourceLocation act = new ResourceLocation( name.contains(":") ? name : String.format("orespawn:%s", name)); + if (registry.containsKey(act)) { return registry.getValue(act); } else { @@ -136,6 +139,8 @@ public void loadFile(final Path file) { JsonObject elements; String rawJson; + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); + try { rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); } catch (IOException e) { @@ -151,6 +156,7 @@ public void loadFile(final Path file) { final String entName = elem.getKey(); final JsonArray entries = elem.getValue().getAsJsonArray(); final List blocks = new LinkedList<>(); + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); for (final JsonElement e : entries) { final JsonObject asObj = e.getAsJsonObject(); final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() @@ -228,4 +234,5 @@ public void saveFile(final String modName) { public boolean has(final ResourceLocation resourceLocation) { return registry.containsKey(resourceLocation); } + } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 56a65375..ce423979 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -28,8 +28,8 @@ public ClusterGenerator() { } @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ISpawnEntry spawnData, final ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { final ChunkPos pos = _pos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -81,8 +81,9 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } } - private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, final int maxSpread, - final int minHeight, final int maxHeight, final ISpawnEntry spawnData, final World world, final BlockPos pos) { + private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, + final int maxSpread, final int minHeight, final int maxHeight, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { // spawn a cluster at the center, then a bunch around the outside... int r = clusterSize - variance; @@ -93,7 +94,7 @@ private void spawnCluster(final int clusterSize, final int variance, final int c spawnChunk(world, pos, spawnData, r); int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary - // inside that + // inside that if (variance > 0) { count += this.random.nextInt(2 * variance) - variance; @@ -119,8 +120,9 @@ private void spawnCluster(final int clusterSize, final int variance, final int c } } - private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, final int quantity) { - int count = quantity; + private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, + final int quantity) { + int count = quantity; final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; final Vec3i[] offs = new Vec3i[lutType]; @@ -159,8 +161,8 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } - private void doSpawnFill(final boolean nextBoolean, final int quantity, final ISpawnEntry spawnData, final World world, - final BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { final int count = quantity; final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; final int rSqr = (int) (radius * radius); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index b72603e7..fbc9d734 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -23,8 +23,8 @@ public DefaultFeatureGenerator() { } @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ISpawnEntry spawnData, final ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { final ChunkPos pos = _pos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -80,7 +80,8 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { int count = quantity; final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -105,8 +106,8 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, - final BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { final int count = quantity; final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; final int rSqr = (int) (radius * radius); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 06ec5e83..6d6d1cf1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -26,8 +26,8 @@ public NormalCloudGenerator() { } @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ISpawnEntry spawnData, final ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { final ChunkPos pos = _pos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -115,8 +115,9 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } } - private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, final int maxHeight, final BlockPos pos, - final ISpawnEntry spawnData, final World world) { + private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, + final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, + final World world) { // spawn one right at the center here, then generate for the cloud and do the math if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 8f1dc587..50faca25 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -29,8 +29,8 @@ public PrecisionGenerator() { } @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ISpawnEntry spawnData, final ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { final ChunkPos pos = _pos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -74,8 +74,8 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi } } - private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, final ChunkPos pos, - final ISpawnEntry spawnData, final World world) { + private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, + final ChunkPos pos, final ISpawnEntry spawnData, final World world) { int spawned = 0; int c; @@ -97,8 +97,8 @@ private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final return spawned; } - private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, final World world, - final int nodeSize, final HeightRange heightRange) { + private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, + final World world, final int nodeSize, final HeightRange heightRange) { int count = nodeSize; final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; @@ -131,8 +131,8 @@ private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEnt return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); } - private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, final HeightRange heightRange, - final ChunkPos pos) { + private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, + final HeightRange heightRange, final ChunkPos pos) { final BlockPos p = spot.add(offset); final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); final int xMax = x1z1.getXEnd(); @@ -189,8 +189,8 @@ private int rescaleOffset(final int offsetIn, final int centerIn, final int mini return workingPoint - centerIn; } - private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc, - final int nodeSize, final HeightRange heightRange) { + private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final int nodeSize, final HeightRange heightRange) { final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; final int rSqr = (int) Math.ceil(radius * radius); @@ -204,8 +204,9 @@ private int spawnFill(final ISpawnEntry spawnData, final World world, final Chun } } - private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc, - final HeightRange heightRange, final boolean toPositive, final double radius, final int rSqr, final int nodeSize) { + private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final HeightRange heightRange, final boolean toPositive, + final double radius, final int rSqr, final int nodeSize) { int quantity = nodeSize; int nc = 0; @@ -230,8 +231,9 @@ private int spawnPrecise(final ISpawnEntry spawnData, final World world, final C return nc; } - private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, final HeightRange heightRange, - final ISpawnEntry spawnData, final World world, final ChunkPos pos, final BlockPos loc) { + private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, + final HeightRange heightRange, final ISpawnEntry spawnData, final World world, + final ChunkPos pos, final BlockPos loc) { if (getABC(dx, dy, dz) <= rSqr) { final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); @@ -251,7 +253,8 @@ private int getPoint(final int lowerBound, final int upperBound) { return arr.get(this.random.nextInt(arr.size())); } - private BlockPos chooseSpot(final int xPosition, final int zPosition, final HeightRange heightRange) { + private BlockPos chooseSpot(final int xPosition, final int zPosition, + final HeightRange heightRange) { final int xRet = getPoint(0, 15) + (xPosition * 16); final int zRet = getPoint(0, 15) + (zPosition * 16); final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); @@ -276,8 +279,8 @@ public JsonObject getDefaultParameters() { private class HeightRange { - private int min; - private int max; + private int min; + private int max; HeightRange(final int min, final int max) { this.min = min; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index 87938bee..ec2a1292 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -34,8 +34,8 @@ public VeinGenerator() { } @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ISpawnEntry spawnData, final ChunkPos _pos) { + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { final ChunkPos pos = _pos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); @@ -62,7 +62,6 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, fi final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - OreSpawn.LOGGER.fatal("parameters: %s", params); int tries; if (triesMax == triesMin) { @@ -114,8 +113,7 @@ private EnumFacing getFaceFromString(final String direction) { case "vertical": return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; case "horizontal": - return this.random.nextBoolean() ? (this.random.nextBoolean() ? EnumFacing.EAST : EnumFacing.WEST) - : (this.random.nextBoolean() ? EnumFacing.NORTH : EnumFacing.SOUTH); + return EnumFacing.HORIZONTALS[this.random.nextInt(EnumFacing.HORIZONTALS.length)]; default: OreSpawn.LOGGER.error( "Invalid value %s found in parameters for vein spawn, returning \"north\"", @@ -125,20 +123,22 @@ private EnumFacing getFaceFromString(final String direction) { } private enum EnumSquare { - TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); - + TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), + RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); + private int index; + private EnumSquare(int index) { this.index = index; } - + final public int getIndex() { return this.index; } } - - private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, final BlockPos blockPos, - final ISpawnEntry spawnData, final World world) { + + private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, + final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { EnumFacing face = startingFace; EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; BlockPos workingPos = new BlockPos(blockPos); @@ -149,21 +149,21 @@ private void spawnVein(final int veinLength, final int nodeSize, final EnumFacin // build vein final List points = Lists.newLinkedList(); - for (int j = 0; j < veinLength; j++) { + for (; points.size() < veinLength;) { points.add(workingPos); List nextFaces = getNextFaceSet(square, face); - face = getNextStartingFace(square, face); - - if(!nextFaces.isEmpty()) { + + if (!nextFaces.isEmpty()) { BlockPos temp = workingPos; - for(EnumFacing f : nextFaces) { + for (EnumFacing f : nextFaces) { temp = temp.offset(f, 1); } nextFaces.clear(); points.add(temp); - } else { - j--; + workingPos = temp; } + + face = getNextStartingFace(square, face); square = getNextSquare(); } @@ -174,102 +174,198 @@ private void spawnVein(final int veinLength, final int nodeSize, final EnumFacin } private class SquareWeight extends WeightedRandom.Item { + public EnumSquare item; - + public SquareWeight(EnumSquare item, int weight) { super(weight); this.item = item; } } - + private EnumSquare getNextSquare() { - float[] weights = new float[] { 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f }; + float[] weights = new float[] { + 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f + }; List items = new ArrayList<>(); - + for (EnumSquare sq : EnumSquare.values()) { - items.add(new SquareWeight(sq, (int)(weights[sq.getIndex()] * 10000))); + items.add(new SquareWeight(sq, (int) (weights[sq.getIndex()] * 10000))); } - - return ((SquareWeight)WeightedRandom.getRandomItem(this.random, items)).item; + + return ((SquareWeight) WeightedRandom.getRandomItem(this.random, items)).item; } - private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { - EnumFacing[][][] pos = new EnumFacing[][][] { + private static final EnumFacing[][][] congruentSquares = new EnumFacing[][][] { // Index 0 - DOWN new EnumFacing[][] { - new EnumFacing[] { EnumFacing.WEST, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.EAST, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST } // RIGHT_TOP - }, - new EnumFacing[][] { - // Index 1 - UP - new EnumFacing[] { EnumFacing.WEST, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.EAST, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.WEST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.NORTH, EnumFacing.EAST }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.EAST }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.SOUTH, EnumFacing.WEST } // RIGHT_TOP - }, - new EnumFacing[][] { - // Index 2 - NORTH - new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.WEST, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.EAST, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST } // RIGHT_TOP - }, - new EnumFacing[][] { - // Index 3 - SOUTH - new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.EAST, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.WEST, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.EAST }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.WEST }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.WEST } // RIGHT_TOP - }, - new EnumFacing[][] { - // Index 4 - WEST - new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.SOUTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.NORTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH } // RIGHT_TOP - }, - new EnumFacing[][] { - // Index 5 - EAST - new EnumFacing[] { EnumFacing.UP, null }, // TOP_EDGE - new EnumFacing[] { EnumFacing.NORTH, null }, // LEFT_EDGE - new EnumFacing[] { EnumFacing.DOWN, null }, // BOTTOM_EDGE - new EnumFacing[] { EnumFacing.SOUTH, null }, // RIGHT_EDGE - new EnumFacing[] { EnumFacing.UP, EnumFacing.NORTH }, // LEFT_TOP - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.NORTH }, // LEFT_BOTTOM - new EnumFacing[] { EnumFacing.DOWN, EnumFacing.SOUTH }, // RIGHT_BOTTOM - new EnumFacing[] { EnumFacing.UP, EnumFacing.SOUTH } // RIGHT_TOP + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 1 - UP + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 2 - NORTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 3 - SOUTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 4 - WEST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 5 - EAST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + } // RIGHT_TOP } - }; + }; + + private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { return face; } - - EnumFacing[] possibles = (EnumFacing[])Arrays.asList(pos[face.getIndex()][square.getIndex()]).stream().filter(it -> it != null).toArray(); - - if(possibles.length > 1) { + + EnumFacing[] possibles = Arrays.asList(congruentSquares[face.getIndex()][square.getIndex()]) + .stream().filter(it -> it != null).toArray(EnumFacing[]::new); + + if (possibles.length > 1) { return possibles[this.random.nextInt(possibles.length)]; } return possibles[0]; @@ -280,9 +376,9 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { rv.add(face); - switch(square) { + switch (square) { case BOTTOM_EDGE: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -298,7 +394,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case TOP_EDGE: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -314,7 +410,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case LEFT_EDGE: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -330,7 +426,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case RIGHT_EDGE: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -348,7 +444,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { case FACE: break; case LEFT_TOP: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -366,7 +462,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case LEFT_BOTTOM: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -384,7 +480,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case RIGHT_TOP: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -402,7 +498,7 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { } break; case RIGHT_BOTTOM: - switch(face) { + switch (face) { case EAST: case WEST: case NORTH: @@ -422,11 +518,12 @@ private List getNextFaceSet(EnumSquare square, EnumFacing face) { default: break; } - + return rv; } - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { int count = quantity; final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; @@ -451,8 +548,8 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); } - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, final ISpawnEntry spawnData, - final BlockPos pos) { + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { final int count = quantity; final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; final int rSqr = (int) (radius * radius); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 2e62b7ce..4abce926 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -20,7 +20,8 @@ public final class BiomeLocationComposition implements BiomeLocation { private final int hash; - public BiomeLocationComposition(final BiomeLocation inclusions, final BiomeLocation exclusions) { + public BiomeLocationComposition(final BiomeLocation inclusions, + final BiomeLocation exclusions) { this.inclusions = inclusions; this.exclusions = exclusions; this.hash = Objects.hash(inclusions, exclusions); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index a8a9bf51..b4db864f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -19,8 +19,8 @@ public class BiomeBuilder implements IBiomeBuilder { - private final List whitelist = new LinkedList<>(); - private final List blacklist = new LinkedList<>(); + private final List whitelist = new LinkedList<>(); + private final List blacklist = new LinkedList<>(); private boolean acceptAll = false; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index 3994de92..9328c2e1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -11,9 +11,9 @@ public class BlockBuilder implements IBlockBuilder { - private IBlockState blockState; - private int chance; - private boolean isValid = true; + private IBlockState blockState; + private int chance; + private boolean isValid = true; public BlockBuilder() { // nothing to do here @@ -61,7 +61,8 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { } @Override - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final String state) { + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final String state) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -75,7 +76,8 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, f */ @Override @Deprecated - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final int metadata) { + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final int metadata) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -84,7 +86,8 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, f } @Override - public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, final int chance) { + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, + final int chance) { final ResourceLocation key = blockState.getBlock().getRegistryName(); if (!ForgeRegistries.BLOCKS.containsKey(key)) { this.isValid = false; @@ -109,17 +112,20 @@ public IBlockBuilder setFromNameWithChance(final String blockName, final int cha } @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final String state, final int chance) { + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, + final int chance) { return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); } @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, final int chance) { + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, + final int chance) { return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); } @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -128,8 +134,8 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL } @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final String state, - final int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final String state, final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } @@ -144,8 +150,8 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL */ @Override @Deprecated - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, final int metadata, - final int chance) { + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int metadata, final int chance) { if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { this.isValid = false; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java index f30af422..8a3d0574 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -6,9 +6,9 @@ public class BlockDefinition implements IBlockDefinition { - private final IBlockState blockState; - private final int blockChance; - private final boolean isValid; + private final IBlockState blockState; + private final int blockChance; + private final boolean isValid; public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { this.blockState = blockState; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 5b2b9871..7d880935 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -12,8 +12,8 @@ public class BlockList implements IBlockList { - private final List myBlocks; - private final List workingList; + private final List myBlocks; + private final List workingList; public BlockList() { this.myBlocks = new LinkedList<>(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 9467beb7..4e2fd880 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -8,11 +8,11 @@ public class DimensionBuilder implements IDimensionBuilder { - private final List dimensionWhitelist = new LinkedList<>(); - private final List dimensionBlacklist = new LinkedList<>(); - private boolean acceptAll = false; - private boolean denyAll = false; - private boolean acceptAllOverworld = true; + private final List dimensionWhitelist = new LinkedList<>(); + private final List dimensionBlacklist = new LinkedList<>(); + private boolean acceptAll = false; + private boolean denyAll = false; + private boolean acceptAllOverworld = true; public DimensionBuilder() { // diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 61d9ebc2..4997211e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -9,8 +9,8 @@ public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { - private final List whitelist = new ArrayList<>(); - private final List blacklist = new ArrayList<>(); + private final List whitelist = new ArrayList<>(); + private final List blacklist = new ArrayList<>(); public DimensionList(final List whitelist, final List blacklist) { this.whitelist.addAll(whitelist); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index bd8048c8..d143163c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -11,9 +11,9 @@ public class FeatureBuilder implements IFeatureBuilder { - private IFeature feature; - private JsonObject parameters; - private boolean useDefaults; + private IFeature feature; + private JsonObject parameters; + private boolean useDefaults; public FeatureBuilder() { this.useDefaults = false; @@ -70,7 +70,8 @@ public IFeatureBuilder setParameter(final String parameterName, final boolean pa } @Override - public IFeatureBuilder setParameter(final String parameterName, final JsonElement parameterValue) { + public IFeatureBuilder setParameter(final String parameterName, + final JsonElement parameterValue) { this.parameters.add(parameterName, parameterValue); return this; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index c5d7167d..1a6905f8 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -6,8 +6,8 @@ public class FeatureEntry implements IFeatureEntry { - private final IFeature feature; - private final JsonObject parameters; + private final IFeature feature; + private final JsonObject parameters; public FeatureEntry(final IFeature feature) { this.feature = feature; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index aac8165c..ca00982e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -44,12 +44,12 @@ public class OS3APIImpl implements OS3API { - private static final Map spawns; - private static final FeatureRegistry features; - private static final ReplacementsRegistry replacements; - private static final PresetsStorage presets; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final Map spawnsToSourceFiles = new TreeMap<>(); + private static final Map spawns; + private static final FeatureRegistry features; + private static final ReplacementsRegistry replacements; + private static final PresetsStorage presets; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final Map spawnsToSourceFiles = new TreeMap<>(); static { spawns = new ConcurrentHashMap<>(); @@ -98,8 +98,8 @@ public void loadConfigFiles() { stream.filter(jsonMatcher::matches).forEach(conf -> { try { OreSpawnReader.tryReadFile(conf, this); - } catch (final MissingVersionException | NotAProperConfigException | OldVersionException - | UnknownVersionException e) { + } catch (final MissingVersionException | NotAProperConfigException + | OldVersionException | UnknownVersionException e) { CrashReport report = CrashReport.makeCrashReport(e, "Failed reading config " + conf.toString()); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index f4605bd7..1a6aef44 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -16,8 +16,8 @@ public class ReplacementBuilder implements IReplacementBuilder { - private String replacementName = null; - private List entries; + private String replacementName = null; + private List entries; public ReplacementBuilder() { this.entries = new LinkedList<>(); @@ -69,7 +69,8 @@ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation } @Override - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state) { + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final String state) { return this.addEntry(StateUtil .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); } @@ -80,14 +81,15 @@ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation */ @Override @Deprecated - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final int metadata) { + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final int metadata) { return this.addEntry( ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); } @Override public boolean hasEntries() { - return this.entries.isEmpty(); + return !this.entries.isEmpty(); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index e2e21fce..d5bb771a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -14,8 +14,8 @@ public class ReplacementEntry extends IForgeRegistryEntry.Impl implements IReplacementEntry { - private final List matchVal; - private OreSpawnBlockMatcher matcher = null; + private final List matchVal; + private OreSpawnBlockMatcher matcher = null; public ReplacementEntry(final String name, final IBlockState... toMatch) { super.setRegistryName(name); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 890ef883..9f0e6c8e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -16,14 +16,14 @@ public class SpawnBuilder implements ISpawnBuilder { - private String spawnName; - private boolean enabled; - private boolean retrogen; - private IBlockList blocks; - private IFeatureEntry feature; - private BiomeLocation biomes; - private IDimensionList dimensions; - private IReplacementEntry replacements; + private String spawnName; + private boolean enabled; + private boolean retrogen; + private IBlockList blocks; + private IFeatureEntry feature; + private BiomeLocation biomes; + private IDimensionList dimensions; + private IReplacementEntry replacements; public SpawnBuilder() { this.enabled = false; @@ -104,7 +104,8 @@ public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { } @Override - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final String blockState) { + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final String blockState) { return this.addBlockWithChance(blockResourceLocation, blockState, 100); } @@ -114,7 +115,8 @@ public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, fina */ @Override @Deprecated - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, final int blockMetadata) { + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final int blockMetadata) { return this.addBlockWithChance(blockResourceLocation, 100); } @@ -134,7 +136,8 @@ public ISpawnBuilder addBlockWithChance(final String blockName, final int chance } @Override - public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, final int chance) { + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, + final int chance) { return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); } @@ -144,12 +147,14 @@ public ISpawnBuilder addBlockWithChance(final String blockName, final String blo */ @Override @Deprecated - public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, final int chance) { + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, + final int chance) { return this.addBlockWithChance(blockName, blockMetadata, chance); } @Override - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final int chance) { + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int chance) { final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) .getDefaultState(); return this.addBlockWithChance(tempVar, chance); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 0e7ec88a..8935e9fa 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -19,14 +19,14 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { - private final String spawnName; - private final IDimensionList dimensions; - private final IReplacementEntry replacements; - private final IBlockList blocks; - private final BiomeLocation biomes; - private final IFeatureEntry feature; - private final boolean enabled; - private final boolean retrogen; + private final String spawnName; + private final IDimensionList dimensions; + private final IReplacementEntry replacements; + private final IBlockList blocks; + private final BiomeLocation biomes; + private final IFeatureEntry feature; + private final boolean enabled; + private final boolean retrogen; public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, final IDimensionList dimensions, final BiomeLocation biomes, @@ -88,8 +88,9 @@ public IBlockList getBlocks() { } @Override - public void generate(final Random random, final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ChunkPos pos) { + public void generate(final Random random, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ChunkPos pos) { this.feature.getFeature().setRandom(random); this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index f19f309a..989866e7 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -48,8 +48,9 @@ public class OreSpawnReader { private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) throws MissingVersionException, - NotAProperConfigException, OldVersionException, UnknownVersionException { + public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) + throws MissingVersionException, NotAProperConfigException, OldVersionException, + UnknownVersionException { final JsonParser parser = new JsonParser(); try (BufferedReader data = Files.newBufferedReader(conf)) { @@ -121,7 +122,8 @@ private static JsonObject doHandlePresets(final JsonObject spawnData) { return spawnData; } - private static JsonElement doPresetFix(final JsonElement value, final PresetsStorage configPresets) { + private static JsonElement doPresetFix(final JsonElement value, + final PresetsStorage configPresets) { if (value.isJsonObject()) { return doPresetForObject(value.getAsJsonObject(), configPresets); } else if (value.isJsonArray()) { @@ -139,13 +141,15 @@ private static JsonElement doPresetFix(final JsonElement value, final PresetsSto } } - private static JsonElement doPresetForArray(final JsonArray value, final PresetsStorage configPresets) { + private static JsonElement doPresetForArray(final JsonArray value, + final PresetsStorage configPresets) { final JsonArray rv = new JsonArray(); value.forEach(it -> rv.add(doPresetFix(it, configPresets))); return rv; } - private static JsonElement doPresetForObject(final JsonObject value, final PresetsStorage configPresets) { + private static JsonElement doPresetForObject(final JsonObject value, + final PresetsStorage configPresets) { final JsonObject rv = new JsonObject(); value.entrySet().stream().forEach( @@ -249,7 +253,6 @@ private static void loadSingleEntry(final Entry entry) if (rb.hasEntries()) { sb.setReplacement(rb.create()); } - break; case Constants.ConfigNames.BLOCK: if (ent.getValue().isJsonArray()) { diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index c3f5b146..497069e9 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -48,7 +48,8 @@ private void genBottomPlate(final World world, final ChunkPos chunkPos, final Bl for (int xP = 0; xP < 16; xP++) { for (int zP = 0; zP < 16; zP++) { for (int yP = 5; yP > 0; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); if (yP < plateThickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { @@ -69,7 +70,8 @@ private void genTopPlate(final World world, final ChunkPos chunkPos, final Block for (int xP = 0; xP < 16; xP++) { for (int zP = 0; zP < 16; zP++) { for (int yP = 126; yP > 121; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, chunkPos.z * 16 + zP); + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); if (yP > thickness && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { From 09e8ad10932a388d5dcf34624e8a14c9fa2392f2 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 28 Aug 2018 13:49:10 -0400 Subject: [PATCH 062/205] apparently the formatter I had that was listed as 'MMD' somehow had "Tab Only" set for the indentation style. This fixes that brain damage --- .../com/mcmoddev/orespawn/EventHandlers.java | 370 +++--- .../java/com/mcmoddev/orespawn/OreSpawn.java | 128 +- .../mcmoddev/orespawn/api/BiomeLocation.java | 12 +- .../mcmoddev/orespawn/api/FeatureBase.java | 532 ++++---- .../com/mcmoddev/orespawn/api/IBlockList.java | 10 +- .../mcmoddev/orespawn/api/IDimensionList.java | 8 +- .../com/mcmoddev/orespawn/api/IFeature.java | 8 +- .../api/exceptions/BadValueException.java | 28 +- .../exceptions/MissingVersionException.java | 8 +- .../exceptions/NotAProperConfigException.java | 8 +- .../api/exceptions/OldVersionException.java | 8 +- .../api/exceptions/UnknownFieldException.java | 22 +- .../api/exceptions/UnknownNameException.java | 28 +- .../exceptions/UnknownVersionException.java | 8 +- .../orespawn/api/os3/IBiomeBuilder.java | 16 +- .../orespawn/api/os3/IBlockBuilder.java | 300 ++--- .../orespawn/api/os3/IBlockDefinition.java | 10 +- .../orespawn/api/os3/IDimensionBuilder.java | 12 +- .../orespawn/api/os3/IFeatureBuilder.java | 20 +- .../orespawn/api/os3/IFeatureEntry.java | 14 +- .../orespawn/api/os3/IReplacementBuilder.java | 128 +- .../orespawn/api/os3/IReplacementEntry.java | 4 +- .../orespawn/api/os3/ISpawnBuilder.java | 54 +- .../orespawn/api/os3/ISpawnEntry.java | 34 +- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 52 +- .../api/os3/OreSpawnBlockMatcher.java | 68 +- .../orespawn/api/plugin/IOreSpawnPlugin.java | 2 +- .../orespawn/api/plugin/OreSpawnPlugin.java | 18 +- .../orespawn/api/plugin/PluginLoader.java | 260 ++-- .../orespawn/commands/AddOreCommand.java | 164 +-- .../orespawn/commands/ClearChunkCommand.java | 266 ++-- .../orespawn/commands/DumpBiomesCommand.java | 72 +- .../commands/WriteConfigsCommand.java | 30 +- .../com/mcmoddev/orespawn/data/Config.java | 286 ++--- .../com/mcmoddev/orespawn/data/Constants.java | 176 +-- .../orespawn/data/FeatureRegistry.java | 262 ++-- .../orespawn/data/PresetsStorage.java | 122 +- .../orespawn/data/ReplacementsRegistry.java | 386 +++--- .../mcmoddev/orespawn/data/VanillaOres.java | 10 +- .../impl/features/ClusterGenerator.java | 328 ++--- .../features/DefaultFeatureGenerator.java | 230 ++-- .../impl/features/NormalCloudGenerator.java | 324 ++--- .../impl/features/PrecisionGenerator.java | 550 ++++---- .../orespawn/impl/features/VeinGenerator.java | 1108 ++++++++--------- .../impl/location/BiomeLocationAcceptAny.java | 20 +- .../location/BiomeLocationComposition.java | 136 +- .../location/BiomeLocationDictionary.java | 76 +- .../impl/location/BiomeLocationEmpty.java | 16 +- .../impl/location/BiomeLocationList.java | 88 +- .../impl/location/BiomeLocationSingle.java | 76 +- .../orespawn/impl/os3/BiomeBuilder.java | 154 +-- .../orespawn/impl/os3/BlockBuilder.java | 316 ++--- .../orespawn/impl/os3/BlockDefinition.java | 48 +- .../mcmoddev/orespawn/impl/os3/BlockList.java | 92 +- .../orespawn/impl/os3/DimensionBuilder.java | 114 +- .../orespawn/impl/os3/DimensionList.java | 94 +- .../impl/os3/DimensionListAcceptAll.java | 20 +- .../os3/DimensionListAcceptAllOverworld.java | 26 +- .../impl/os3/DimensionListDenyAll.java | 20 +- .../orespawn/impl/os3/FeatureBuilder.java | 212 ++-- .../orespawn/impl/os3/FeatureEntry.java | 88 +- .../orespawn/impl/os3/OS3APIImpl.java | 440 +++---- .../orespawn/impl/os3/ReplacementBuilder.java | 170 +-- .../orespawn/impl/os3/ReplacementEntry.java | 54 +- .../orespawn/impl/os3/SpawnBuilder.java | 390 +++--- .../orespawn/impl/os3/SpawnEntry.java | 170 +-- .../orespawn/json/OreSpawnReader.java | 668 +++++----- .../orespawn/json/OreSpawnWriter.java | 94 +- .../mcmoddev/orespawn/util/Collectors2.java | 20 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 70 +- .../orespawn/worldgen/FlatBedrock.java | 120 +- .../orespawn/worldgen/OreSpawnWorldGen.java | 20 +- 72 files changed, 5148 insertions(+), 5148 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 51c5137a..e624b4bf 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -38,189 +38,189 @@ public class EventHandlers { - private final Deque retroChunks; - private final Deque>> chunks; - // private Map> chunks - - EventHandlers() { - retroChunks = new ConcurrentLinkedDeque<>(); - chunks = new ConcurrentLinkedDeque<>(); - } - - private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, - EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, - EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, - EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); - - @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) - public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { - if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - && vanillaEvents.contains(event.getType())) { - event.setResult(Event.Result.DENY); - } - } - - @SubscribeEvent - public void onChunkSave(final ChunkDataEvent.Save ev) { - final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final NBTTagCompound features = new NBTTagCompound(); - - // save a list of the spawns that were configured and available - in this dimension - when - // the chunk - // was first generated. - - // collect that data - final int thisDimension = ev.getWorld().provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) - .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features - .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - dataTag.setTag(Constants.FEATURES_TAG, features); - - ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); - } - - private boolean dequeContains(final ChunkPos cc) { - return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) - .contains(true); - } - - @SubscribeEvent - public void onChunkLoad(final ChunkDataEvent.Load ev) { - final World clWorld = ev.getWorld(); - final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); - - doBedrockRetrogen(chunkCoords); - - if (dequeContains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETROGEN_KEY)) { - final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final int thisDimension = clWorld.provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); - - if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) - || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.addLast(new Tuple<>(chunkCoords, - getDifferingTags(chunkTag, thisDimension, thisBiome))); - } - } - } - - private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - final List stuff = Lists.newLinkedList(); - stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) - .collect(Collectors.toList())); - stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) - .collect(Collectors.toList())); - return ImmutableList.copyOf(stuff); - } - - private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 - && diff.entriesOnlyOnRight().size() == 0; - } - - private void doBedrockRetrogen(final ChunkPos chunkCoords) { - if (retroChunks.contains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETRO_BEDROCK)) { - retroChunks.addLast(chunkCoords); - } - } - - private static World world; - private static ChunkProviderServer chunkProvider; - private static IChunkGenerator chunkGenerator; - private static Random random; - - private static void setupData(final World nw) { - if (world == null || !world.equals(nw)) { - world = nw; - } - - if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { - chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); - } - - if (chunkGenerator == null) { - chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, - chunkProvider, "field_186029_c", "chunkGenerator"); - } - - if (random == null) { - random = new Random(world.getSeed()); - } - - } - - private void runBits(final Tuple> tup) { - final ChunkPos p = tup.getFirst(); - final List spawns = tup.getSecond(); - - // re-seed with something totally new :P - random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) - ^ world.getSeed()); - spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, - chunkGenerator, chunkProvider, p)); - } - - @SubscribeEvent - public void worldTick(final WorldTickEvent ev) { - setupData(ev.world); - - if (ev.side != Side.SERVER) { - return; - } - - if (ev.phase == Phase.END) { - final Deque>> b = new LinkedList<>(); - for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { - b.push(chunks.pop()); - } - - b.forEach(this::runBits); - - for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { - final ChunkPos p = retroChunks.pop(); - OreSpawn.flatBedrock.retrogen(world, p.x, p.z); - } - } - } + private final Deque retroChunks; + private final Deque>> chunks; + // private Map> chunks + + EventHandlers() { + retroChunks = new ConcurrentLinkedDeque<>(); + chunks = new ConcurrentLinkedDeque<>(); + } + + private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, + EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, + EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, + EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); + + @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) + public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { + if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + && vanillaEvents.contains(event.getType())) { + event.setResult(Event.Result.DENY); + } + } + + @SubscribeEvent + public void onChunkSave(final ChunkDataEvent.Save ev) { + final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final NBTTagCompound features = new NBTTagCompound(); + + // save a list of the spawns that were configured and available - in this dimension - when + // the chunk + // was first generated. + + // collect that data + final int thisDimension = ev.getWorld().provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) + .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features + .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + dataTag.setTag(Constants.FEATURES_TAG, features); + + ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); + } + + private boolean dequeContains(final ChunkPos cc) { + return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) + .contains(true); + } + + @SubscribeEvent + public void onChunkLoad(final ChunkDataEvent.Load ev) { + final World clWorld = ev.getWorld(); + final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); + + doBedrockRetrogen(chunkCoords); + + if (dequeContains(chunkCoords)) { + return; + } + + if (Config.getBoolean(Constants.RETROGEN_KEY)) { + final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final int thisDimension = clWorld.provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); + + if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) + || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { + chunks.addLast(new Tuple<>(chunkCoords, + getDifferingTags(chunkTag, thisDimension, thisBiome))); + } + } + } + + private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + final MapDifference diff = Maps.difference(oldBits, currentBits); + + final List stuff = Lists.newLinkedList(); + stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); + stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); + return ImmutableList.copyOf(stuff); + } + + private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + final MapDifference diff = Maps.difference(oldBits, currentBits); + + return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 + && diff.entriesOnlyOnRight().size() == 0; + } + + private void doBedrockRetrogen(final ChunkPos chunkCoords) { + if (retroChunks.contains(chunkCoords)) { + return; + } + + if (Config.getBoolean(Constants.RETRO_BEDROCK)) { + retroChunks.addLast(chunkCoords); + } + } + + private static World world; + private static ChunkProviderServer chunkProvider; + private static IChunkGenerator chunkGenerator; + private static Random random; + + private static void setupData(final World nw) { + if (world == null || !world.equals(nw)) { + world = nw; + } + + if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { + chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); + } + + if (chunkGenerator == null) { + chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, + chunkProvider, "field_186029_c", "chunkGenerator"); + } + + if (random == null) { + random = new Random(world.getSeed()); + } + + } + + private void runBits(final Tuple> tup) { + final ChunkPos p = tup.getFirst(); + final List spawns = tup.getSecond(); + + // re-seed with something totally new :P + random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) + ^ world.getSeed()); + spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, + chunkGenerator, chunkProvider, p)); + } + + @SubscribeEvent + public void worldTick(final WorldTickEvent ev) { + setupData(ev.world); + + if (ev.side != Side.SERVER) { + return; + } + + if (ev.phase == Phase.END) { + final Deque>> b = new LinkedList<>(); + for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { + b.push(chunks.pop()); + } + + b.forEach(this::runBits); + + for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { + final ChunkPos p = retroChunks.pop(); + OreSpawn.flatBedrock.retrogen(world, p.x, p.z); + } + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 855bc10f..157278b9 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -39,71 +39,71 @@ */ @Mod(modid = Constants.MODID, - name = Constants.NAME, - version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,)", - certificateFingerprint = "@FINGERPRINT@") + name = Constants.NAME, + version = Constants.VERSION, + acceptedMinecraftVersions = "[1.12,)", + certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { - @Instance - public static OreSpawn instance; - - public static final Logger LOGGER = LogManager - .getFormatterLogger(Constants.MODID); - public static final OS3API API = new OS3APIImpl(); - static final EventHandlers eventHandlers = new EventHandlers(); - public static final FeatureRegistry FEATURES = new FeatureRegistry(); - protected static final Map> spawns = new HashMap<>(); - - static final FlatBedrock flatBedrock = new FlatBedrock(); - - public static Map> getSpawns() { - return spawns; - } - - @EventHandler - public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { - LOGGER.warn("Invalid fingerprint detected!"); - } - - @EventHandler - public void preInit(final FMLPreInitializationEvent ev) { - Config.loadConfig(); - - PluginLoader.INSTANCE.load(ev); - - if (Config.getBoolean(Constants.FLAT_BEDROCK)) { - GameRegistry.registerWorldGenerator(flatBedrock, 100); - } - - GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); - - if (Config.getBoolean(Constants.RETROGEN_KEY) - || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - || Config.getBoolean(Constants.RETRO_BEDROCK)) { - MinecraftForge.EVENT_BUS.register(eventHandlers); - MinecraftForge.ORE_GEN_BUS.register(eventHandlers); - } - } - - @EventHandler - public void init(final FMLInitializationEvent ev) { - PluginLoader.INSTANCE.register(); - - API.loadConfigFiles(); - } - - @EventHandler - public void postInit(final FMLPostInitializationEvent ev) { - Config.saveConfig(); - } - - @EventHandler - public void onServerStarting(final FMLServerStartingEvent ev) { - ev.registerServerCommand(new ClearChunkCommand()); - ev.registerServerCommand(new DumpBiomesCommand()); - ev.registerServerCommand(new AddOreCommand()); - ev.registerServerCommand(new WriteConfigsCommand()); - } + @Instance + public static OreSpawn instance; + + public static final Logger LOGGER = LogManager + .getFormatterLogger(Constants.MODID); + public static final OS3API API = new OS3APIImpl(); + static final EventHandlers eventHandlers = new EventHandlers(); + public static final FeatureRegistry FEATURES = new FeatureRegistry(); + protected static final Map> spawns = new HashMap<>(); + + static final FlatBedrock flatBedrock = new FlatBedrock(); + + public static Map> getSpawns() { + return spawns; + } + + @EventHandler + public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { + LOGGER.warn("Invalid fingerprint detected!"); + } + + @EventHandler + public void preInit(final FMLPreInitializationEvent ev) { + Config.loadConfig(); + + PluginLoader.INSTANCE.load(ev); + + if (Config.getBoolean(Constants.FLAT_BEDROCK)) { + GameRegistry.registerWorldGenerator(flatBedrock, 100); + } + + GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); + + if (Config.getBoolean(Constants.RETROGEN_KEY) + || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + || Config.getBoolean(Constants.RETRO_BEDROCK)) { + MinecraftForge.EVENT_BUS.register(eventHandlers); + MinecraftForge.ORE_GEN_BUS.register(eventHandlers); + } + } + + @EventHandler + public void init(final FMLInitializationEvent ev) { + PluginLoader.INSTANCE.register(); + + API.loadConfigFiles(); + } + + @EventHandler + public void postInit(final FMLPostInitializationEvent ev) { + Config.saveConfig(); + } + + @EventHandler + public void onServerStarting(final FMLServerStartingEvent ev) { + ev.registerServerCommand(new ClearChunkCommand()); + ev.registerServerCommand(new DumpBiomesCommand()); + ev.registerServerCommand(new AddOreCommand()); + ev.registerServerCommand(new WriteConfigsCommand()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index 6870c78a..7dfb78dc 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -9,12 +9,12 @@ public interface BiomeLocation { - boolean matches(Biome biome); + boolean matches(Biome biome); - JsonElement serialize(); + JsonElement serialize(); - default ImmutableList getBiomes() { - return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) - .collect(Collectors2.toImmutableList()); - } + default ImmutableList getBiomes() { + return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) + .collect(Collectors2.toImmutableList()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index c3159274..0efe5dc6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -23,270 +23,270 @@ public class FeatureBase extends IForgeRegistryEntry.Impl { - private static final int MAX_CACHE_SIZE = 2048; - /** - * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk - * without triggering a chunk-load. - */ - private static final Map> overflowCache = new HashMap<>( - MAX_CACHE_SIZE); - private static final Deque cacheOrder = new LinkedList<>(); - protected Random random; - - public FeatureBase(final Random rand) { - this.random = rand; - } - - public boolean isValidBlock(final IBlockState oreBlock) { - return oreBlock.getBlock() != Blocks.AIR; - } - - protected void runCache(final int chunkX, final int chunkZ, final World world, - final ISpawnEntry spawnData) { - final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); - final Map cache = retrieveCache(chunkCoord); - - if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it - for (final Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), - world.provider.getDimension(), spawnData); - } - } - } - - protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); - return false; - } - - if (!isValidBlock(oreBlock)) { - return false; - } - - final Biome thisBiome = world.getBiome(coord); - - if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { - return false; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); - return false; - } - - return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, - spawnData); - } - - private BlockPos mungeFixYcoord(final BlockPos coord) { - if (coord.getY() < 0) { - final int newYCoord = coord.getY() * -1; - return new BlockPos(coord.getX(), newYCoord, coord.getZ()); - } else { - return new BlockPos(coord); - } - } - - private boolean spawnOrCache(final World world, final BlockPos coord, - final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, - final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { - if (world.isBlockLoaded(coord)) { - if (!isValidBlock(oreBlock)) { - return false; - } - - final IBlockState targetBlock = world.getBlockState(coord); - final Biome thisBiome = world.getBiome(coord); - - if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { - world.setBlockState(coord, oreBlock); - return true; - } else { - return false; - } - } else if (cacheOverflow) { - cacheOverflowBlock(oreBlock, coord, dimension); - return true; - } - - return false; - } - - private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); - return; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); - return; - } - - spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); - } - - private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, - final int dimension) { - final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); - - if (overflowCache.containsKey(chunkCoord)) { - cacheOrder.addLast(chunkCoord); - - if (cacheOrder.size() > MAX_CACHE_SIZE) { - final Vec3i drop = cacheOrder.removeFirst(); - overflowCache.get(drop).clear(); - overflowCache.remove(drop); - } - - overflowCache.put(chunkCoord, new HashMap<>()); - } - - final Map cache = overflowCache.getOrDefault(chunkCoord, - new HashMap<>()); - cache.put(coord, bs); - } - - private Map retrieveCache(final Vec3i chunkCoord) { - if (overflowCache.containsKey(chunkCoord)) { - final Map cache = overflowCache.get(chunkCoord); - cacheOrder.remove(chunkCoord); - overflowCache.remove(chunkCoord); - return cache; - } else { - return Collections.emptyMap(); - } - } - - protected void scramble(final int[] target, final Random prng) { - for (int i = target.length - 1; i > 0; i--) { - final int n = prng.nextInt(i); - final int temp = target[i]; - target[i] = target[n]; - target[n] = temp; - } - } - - protected static final Vec3i[] offsets_small = { - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), - - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) - }; - - protected static final Vec3i[] offsets = { - new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), - new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), - new Vec3i(1, 1, -1), - - new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), - new Vec3i(1, 1, 0), - - new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), - new Vec3i(1, 1, 1) - }; - - protected static final int[] offsetIndexRef = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26 - }; - protected static final int[] offsetIndexRef_small = { - 0, 1, 2, 3, 4, 5, 6, 7 - }; - - protected static void mergeDefaults(final JsonObject parameters, - final JsonObject defaultParameters) { - defaultParameters.entrySet().forEach(entry -> { - if (!parameters.has(entry.getKey())) { - parameters.add(entry.getKey(), entry.getValue()); - } - }); - } - - private double triangularDistribution(final double a, final double b, final double c) { - final double base = (c - a) / (b - a); - final double rand = this.random.nextDouble(); - - if (rand < base) { - return a + Math.sqrt(rand * (b - a) * (c - a)); - } else { - return b - Math.sqrt((1 - rand) * (b - a) * (b - c)); - } - } - - protected int getPoint(final int lowerBound, final int upperBound, final int median) { - final int t = (int) Math.round( - triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); - return t - median; - } - - protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { - for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } - if (quantity <= 0) { - return; - } - } - } - } - } - - protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dz = (int) (-1 * radius); dz < radius; dz++) { - for (int dx = (int) (-1 * radius); dx < radius; dx++) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } - if (quantity <= 0) { - return; - } - } - } - } - } - - protected int getABC(final int dx, final int dy, final int dz) { - return (dx * dx + dy * dy + dz * dz); - } - - protected int countItem(final int dx, final boolean toPositive) { - return toPositive ? dx + 1 : dx - 1; - } - - protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { - return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); - } - - protected int getStart(final boolean toPositive, final double radius) { - return ((int) (radius * (toPositive ? 1 : -1))); - } + private static final int MAX_CACHE_SIZE = 2048; + /** + * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk + * without triggering a chunk-load. + */ + private static final Map> overflowCache = new HashMap<>( + MAX_CACHE_SIZE); + private static final Deque cacheOrder = new LinkedList<>(); + protected Random random; + + public FeatureBase(final Random rand) { + this.random = rand; + } + + public boolean isValidBlock(final IBlockState oreBlock) { + return oreBlock.getBlock() != Blocks.AIR; + } + + protected void runCache(final int chunkX, final int chunkZ, final World world, + final ISpawnEntry spawnData) { + final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); + final Map cache = retrieveCache(chunkCoord); + + if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it + for (final Entry ent : cache.entrySet()) { + spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), + world.provider.getDimension(), spawnData); + } + } + } + + protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { + if (oreBlock == null) { + OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + return false; + } + + if (!isValidBlock(oreBlock)) { + return false; + } + + final Biome thisBiome = world.getBiome(coord); + + if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { + return false; + } + + final BlockPos np = mungeFixYcoord(coord); + + if (coord.getY() >= world.getHeight()) { + OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + return false; + } + + return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, + spawnData); + } + + private BlockPos mungeFixYcoord(final BlockPos coord) { + if (coord.getY() < 0) { + final int newYCoord = coord.getY() * -1; + return new BlockPos(coord.getX(), newYCoord, coord.getZ()); + } else { + return new BlockPos(coord); + } + } + + private boolean spawnOrCache(final World world, final BlockPos coord, + final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, + final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { + if (world.isBlockLoaded(coord)) { + if (!isValidBlock(oreBlock)) { + return false; + } + + final IBlockState targetBlock = world.getBlockState(coord); + final Biome thisBiome = world.getBiome(coord); + + if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { + world.setBlockState(coord, oreBlock); + return true; + } else { + return false; + } + } else if (cacheOverflow) { + cacheOverflowBlock(oreBlock, coord, dimension); + return true; + } + + return false; + } + + private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final ISpawnEntry spawnData) { + if (oreBlock == null) { + OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + return; + } + + final BlockPos np = mungeFixYcoord(coord); + + if (coord.getY() >= world.getHeight()) { + OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + return; + } + + spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); + } + + private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, + final int dimension) { + final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); + + if (overflowCache.containsKey(chunkCoord)) { + cacheOrder.addLast(chunkCoord); + + if (cacheOrder.size() > MAX_CACHE_SIZE) { + final Vec3i drop = cacheOrder.removeFirst(); + overflowCache.get(drop).clear(); + overflowCache.remove(drop); + } + + overflowCache.put(chunkCoord, new HashMap<>()); + } + + final Map cache = overflowCache.getOrDefault(chunkCoord, + new HashMap<>()); + cache.put(coord, bs); + } + + private Map retrieveCache(final Vec3i chunkCoord) { + if (overflowCache.containsKey(chunkCoord)) { + final Map cache = overflowCache.get(chunkCoord); + cacheOrder.remove(chunkCoord); + overflowCache.remove(chunkCoord); + return cache; + } else { + return Collections.emptyMap(); + } + } + + protected void scramble(final int[] target, final Random prng) { + for (int i = target.length - 1; i > 0; i--) { + final int n = prng.nextInt(i); + final int temp = target[i]; + target[i] = target[n]; + target[n] = temp; + } + } + + protected static final Vec3i[] offsets_small = { + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), + + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) + }; + + protected static final Vec3i[] offsets = { + new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), + new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), + new Vec3i(1, 1, -1), + + new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), + new Vec3i(1, 1, 0), + + new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), + new Vec3i(1, 1, 1) + }; + + protected static final int[] offsetIndexRef = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26 + }; + protected static final int[] offsetIndexRef_small = { + 0, 1, 2, 3, 4, 5, 6, 7 + }; + + protected static void mergeDefaults(final JsonObject parameters, + final JsonObject defaultParameters) { + defaultParameters.entrySet().forEach(entry -> { + if (!parameters.has(entry.getKey())) { + parameters.add(entry.getKey(), entry.getValue()); + } + }); + } + + private double triangularDistribution(final double a, final double b, final double c) { + final double base = (c - a) / (b - a); + final double rand = this.random.nextDouble(); + + if (rand < base) { + return a + Math.sqrt(rand * (b - a) * (c - a)); + } else { + return b - Math.sqrt((1 - rand) * (b - a) * (b - c)); + } + } + + protected int getPoint(final int lowerBound, final int upperBound, final int median) { + final int t = (int) Math.round( + triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); + return t - median; + } + + protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { + final Random prng = this.random; + int quantity = count; + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { + for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); + quantity--; + } + if (quantity <= 0) { + return; + } + } + } + } + } + + protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { + final Random prng = this.random; + int quantity = count; + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dz = (int) (-1 * radius); dz < radius; dz++) { + for (int dx = (int) (-1 * radius); dx < radius; dx++) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); + quantity--; + } + if (quantity <= 0) { + return; + } + } + } + } + } + + protected int getABC(final int dx, final int dy, final int dz) { + return (dx * dx + dy * dy + dz * dz); + } + + protected int countItem(final int dx, final boolean toPositive) { + return toPositive ? dx + 1 : dx - 1; + } + + protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { + return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); + } + + protected int getStart(final boolean toPositive, final double radius) { + return ((int) (radius * (toPositive ? 1 : -1))); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 26e12bb6..86b35071 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -8,13 +8,13 @@ public interface IBlockList { - void addBlock(IBlockDefinition block); + void addBlock(IBlockDefinition block); - IBlockState getRandomBlock(Random rand); + IBlockState getRandomBlock(Random rand); - void startNewSpawn(); + void startNewSpawn(); - void dump(); + void dump(); - int count(); + int count(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index 11564819..034ecd46 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -4,9 +4,9 @@ public interface IDimensionList { - JsonObject serialize(); + JsonObject serialize(); - default boolean matches(int dimensionId) { - return false; - } + default boolean matches(int dimensionId) { + return false; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java index 82f04a60..ac6bc4ec 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java @@ -13,10 +13,10 @@ public interface IFeature extends IForgeRegistryEntry { - void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawn, ChunkPos pos); + void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, + ISpawnEntry spawn, ChunkPos pos); - void setRandom(Random rand); + void setRandom(Random rand); - JsonObject getDefaultParameters(); + JsonObject getDefaultParameters(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index e2a82bfa..e864edcf 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -2,20 +2,20 @@ public class BadValueException extends Exception { - private static final long serialVersionUID = 1143938140559149506L; - private final String keyName; - private final String keyValue; + private static final long serialVersionUID = 1143938140559149506L; + private final String keyName; + private final String keyValue; - public BadValueException(final String keyName, final String keyValue) { - super(); - this.keyName = keyName; - this.keyValue = keyValue; - } + public BadValueException(final String keyName, final String keyValue) { + super(); + this.keyName = keyName; + this.keyValue = keyValue; + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, - baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, + baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java index 8c98fffa..70623e44 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java @@ -2,9 +2,9 @@ public class MissingVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = -4306852267351590384L; + /** + * + */ + private static final long serialVersionUID = -4306852267351590384L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java index 2f31a433..c959466f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java @@ -2,9 +2,9 @@ public class NotAProperConfigException extends Exception { - /** - * - */ - private static final long serialVersionUID = -7748241590958198482L; + /** + * + */ + private static final long serialVersionUID = -7748241590958198482L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java index 62b5fa71..39c8da6a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java @@ -2,9 +2,9 @@ public class OldVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = 3760017140789193369L; + /** + * + */ + private static final long serialVersionUID = 3760017140789193369L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index e3d14167..6aaa81cf 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -2,17 +2,17 @@ public class UnknownFieldException extends Exception { - private static final long serialVersionUID = 1L; - private final String message; + private static final long serialVersionUID = 1L; + private final String message; - public UnknownFieldException(final String theField) { - super(); - this.message = String.format("Unkown field %s in config", theField); - } + public UnknownFieldException(final String theField) { + super(); + this.message = String.format("Unkown field %s in config", theField); + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("%s%n%s", this.message, baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("%s%n%s", this.message, baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 06a83368..79973b0b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -2,20 +2,20 @@ public class UnknownNameException extends Exception { - private static final long serialVersionUID = -3426121906665390773L; - private final String fieldName; - private final String fieldValue; + private static final long serialVersionUID = -3426121906665390773L; + private final String fieldName; + private final String fieldValue; - public UnknownNameException(final String fieldName, final String fieldValue) { - super(); - this.fieldName = fieldName; - this.fieldValue = fieldValue; - } + public UnknownNameException(final String fieldName, final String fieldValue) { + super(); + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, - baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, + baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java index fa369ca9..53e9ac3a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java @@ -2,9 +2,9 @@ public class UnknownVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = 3817238409227005355L; + /** + * + */ + private static final long serialVersionUID = 3817238409227005355L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index 1bda5db5..f622e22e 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -7,19 +7,19 @@ public interface IBiomeBuilder { - IBiomeBuilder addWhitelistEntry(Biome biome); + IBiomeBuilder addWhitelistEntry(Biome biome); - IBiomeBuilder addWhitelistEntry(String biomeName); + IBiomeBuilder addWhitelistEntry(String biomeName); - IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); + IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); - IBiomeBuilder addBlacklistEntry(Biome biome); + IBiomeBuilder addBlacklistEntry(Biome biome); - IBiomeBuilder addBlacklistEntry(String biomeName); + IBiomeBuilder addBlacklistEntry(String biomeName); - IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); + IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); - IBiomeBuilder setAcceptAll(); + IBiomeBuilder setAcceptAll(); - BiomeLocation create(); + BiomeLocation create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 54baec34..226ea16c 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -6,154 +6,154 @@ public interface IBlockBuilder { - /** - * - * @param blockState - * @return - */ - IBlockBuilder setFromBlockState(IBlockState blockState); - - /** - * - * @param block - * @return - */ - IBlockBuilder setFromBlock(Block block); - - /** - * - * @param blockName - * @return - */ - IBlockBuilder setFromName(String blockName); - - /** - * - * @param blockName - * @param state - * @return - */ - IBlockBuilder setFromName(String blockName, String state); - - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(String blockName, int metadata); - - /** - * - * @param blockResourceLocation - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation); - - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); - - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); - - /** - * - * @param blockState - * @param chance - * @return - */ - IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); - - /** - * - * @param block - * @param chance - * @return - */ - IBlockBuilder setFromBlockWithChance(Block block, int chance); - - /** - * - * @param blockName - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, int chance); - - /** - * - * @param blockName - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); - - /** - * - * @param blockName - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); - - /** - * - * @param blockResourceLocation - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); - - /** - * - * @param blockResourceLocation - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, - int chance); - - /** - * - * @param blockResourceLocation - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, - int chance); - - /** - * - * @param chance - * @return - */ - IBlockBuilder setChance(int chance); - - /** - * - * @return - */ - IBlockDefinition create(); + /** + * + * @param blockState + * @return + */ + IBlockBuilder setFromBlockState(IBlockState blockState); + + /** + * + * @param block + * @return + */ + IBlockBuilder setFromBlock(Block block); + + /** + * + * @param blockName + * @return + */ + IBlockBuilder setFromName(String blockName); + + /** + * + * @param blockName + * @param state + * @return + */ + IBlockBuilder setFromName(String blockName, String state); + + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromName(String blockName, int metadata); + + /** + * + * @param blockResourceLocation + * @return + */ + IBlockBuilder setFromName(ResourceLocation blockResourceLocation); + + /** + * + * @param blockResourceLocation + * @param state + * @return + */ + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); + + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); + + /** + * + * @param blockState + * @param chance + * @return + */ + IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); + + /** + * + * @param block + * @param chance + * @return + */ + IBlockBuilder setFromBlockWithChance(Block block, int chance); + + /** + * + * @param blockName + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(String blockName, int chance); + + /** + * + * @param blockName + * @param state + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); + + /** + * + * @param blockName + * @param metadata + * @param chance + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); + + /** + * + * @param blockResourceLocation + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); + + /** + * + * @param blockResourceLocation + * @param state + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, + int chance); + + /** + * + * @param blockResourceLocation + * @param metadata + * @param chance + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, + int chance); + + /** + * + * @param chance + * @return + */ + IBlockBuilder setChance(int chance); + + /** + * + * @return + */ + IBlockDefinition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index 03bec55b..1cb48858 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -4,11 +4,11 @@ public interface IBlockDefinition { - IBlockState getBlock(); + IBlockState getBlock(); - int getChance(); + int getChance(); - default boolean isValid() { - return true; - } + default boolean isValid() { + return true; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java index 1fe97bb7..9d178ecf 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -4,15 +4,15 @@ public interface IDimensionBuilder { - IDimensionBuilder addWhitelistEntry(int dimensionID); + IDimensionBuilder addWhitelistEntry(int dimensionID); - IDimensionBuilder addBlacklistEntry(int dimensionID); + IDimensionBuilder addBlacklistEntry(int dimensionID); - IDimensionBuilder setAcceptAll(); + IDimensionBuilder setAcceptAll(); - IDimensionBuilder setDenyAll(); + IDimensionBuilder setDenyAll(); - IDimensionBuilder setAcceptAllOverworld(); + IDimensionBuilder setAcceptAllOverworld(); - IDimensionList create(); + IDimensionList create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index 20fefa25..111b7a1b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -7,23 +7,23 @@ public interface IFeatureBuilder { - IFeatureBuilder setFeature(String featureName); + IFeatureBuilder setFeature(String featureName); - IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); + IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); - IFeatureBuilder setFeature(IFeature feature); + IFeatureBuilder setFeature(IFeature feature); - IFeatureBuilder setParameter(String parameterName, String parameterValue); + IFeatureBuilder setParameter(String parameterName, String parameterValue); - IFeatureBuilder setParameter(String parameterName, int parameterValue); + IFeatureBuilder setParameter(String parameterName, int parameterValue); - IFeatureBuilder setParameter(String parameterName, float parameterValue); + IFeatureBuilder setParameter(String parameterName, float parameterValue); - IFeatureBuilder setParameter(String parameterName, boolean parameterValue); + IFeatureBuilder setParameter(String parameterName, boolean parameterValue); - IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); + IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); - IFeatureBuilder setUseFeatureDefaults(); + IFeatureBuilder setUseFeatureDefaults(); - IFeatureEntry create(); + IFeatureEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java index 6f5fb06b..ef9c1d94 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java @@ -5,17 +5,17 @@ public interface IFeatureEntry { - IFeature getFeature(); + IFeature getFeature(); - String getFeatureName(); + String getFeatureName(); - JsonObject getFeatureParameters(); + JsonObject getFeatureParameters(); - void setParameter(String parameterName, String parameterValue); + void setParameter(String parameterName, String parameterValue); - void setParameter(String parameterName, int parameterValue); + void setParameter(String parameterName, int parameterValue); - void setParameter(String parameterName, boolean parameterValue); + void setParameter(String parameterName, boolean parameterValue); - void setParameter(String parameterName, float parameterValue); + void setParameter(String parameterName, float parameterValue); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index ecf91e74..a1055ae5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -5,78 +5,78 @@ public interface IReplacementBuilder { - /** - * - * @param entryName - * @return - */ - IReplacementBuilder setFromName(String entryName); + /** + * + * @param entryName + * @return + */ + IReplacementBuilder setFromName(String entryName); - /** - * - * @param name - * @return - */ - IReplacementBuilder setName(String name); + /** + * + * @param name + * @return + */ + IReplacementBuilder setName(String name); - /** - * - * @param blockState - * @return - */ - IReplacementBuilder addEntry(IBlockState blockState); + /** + * + * @param blockState + * @return + */ + IReplacementBuilder addEntry(IBlockState blockState); - /** - * - * @param blockName - * @return - */ - IReplacementBuilder addEntry(String blockName); + /** + * + * @param blockName + * @return + */ + IReplacementBuilder addEntry(String blockName); - /** - * - * @param blockName - * @param state - * @return - */ - IReplacementBuilder addEntry(String blockName, String state); + /** + * + * @param blockName + * @param state + * @return + */ + IReplacementBuilder addEntry(String blockName, String state); - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(String blockName, int metadata); + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IReplacementBuilder addEntry(String blockName, int metadata); - /** - * - * @param blockResourceLocation - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); + /** + * + * @param blockResourceLocation + * @return + */ + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); + /** + * + * @param blockResourceLocation + * @param state + * @return + */ + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); - boolean hasEntries(); + boolean hasEntries(); - IReplacementEntry create(); + IReplacementEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index e9f03f91..b58c5ed7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -7,7 +7,7 @@ public interface IReplacementEntry extends IForgeRegistryEntry { - OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - List getEntries(); + List getEntries(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index 3808d61a..c2772e1d 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -9,55 +9,55 @@ public interface ISpawnBuilder { - ISpawnBuilder setName(String name); + ISpawnBuilder setName(String name); - ISpawnBuilder setDimensions(IDimensionList dimensions); + ISpawnBuilder setDimensions(IDimensionList dimensions); - ISpawnBuilder setBiomes(BiomeLocation biomes); + ISpawnBuilder setBiomes(BiomeLocation biomes); - ISpawnBuilder setEnabled(boolean enabled); + ISpawnBuilder setEnabled(boolean enabled); - ISpawnBuilder setRetrogen(boolean retrogen); + ISpawnBuilder setRetrogen(boolean retrogen); - ISpawnBuilder setReplacement(IReplacementEntry replacements); + ISpawnBuilder setReplacement(IReplacementEntry replacements); - ISpawnBuilder setFeature(IFeatureEntry feature); + ISpawnBuilder setFeature(IFeatureEntry feature); - ISpawnBuilder addBlock(String blockName); + ISpawnBuilder addBlock(String blockName); - ISpawnBuilder addBlock(String blockName, String blockState); + ISpawnBuilder addBlock(String blockName, String blockState); - ISpawnBuilder addBlock(String blockName, int blockMetadata); + ISpawnBuilder addBlock(String blockName, int blockMetadata); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); - ISpawnBuilder addBlock(Block block); + ISpawnBuilder addBlock(Block block); - ISpawnBuilder addBlock(IBlockState block); + ISpawnBuilder addBlock(IBlockState block); - ISpawnBuilder addBlockWithChance(String blockName, int chance); + ISpawnBuilder addBlockWithChance(String blockName, int chance); - ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); + ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); - ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); + ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, - int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, + int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, - int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, + int chance); - ISpawnBuilder addBlockWithChance(Block block, int chance); + ISpawnBuilder addBlockWithChance(Block block, int chance); - ISpawnBuilder addBlockWithChance(IBlockState block, int chance); + ISpawnBuilder addBlockWithChance(IBlockState block, int chance); - ISpawnEntry create(); + ISpawnEntry create(); - ISpawnBuilder addBlock(IBlockDefinition block); + ISpawnBuilder addBlock(IBlockDefinition block); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 7fdaceb4..9361b074 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -15,32 +15,32 @@ public interface ISpawnEntry { - default boolean isEnabled() { - return false; - } + default boolean isEnabled() { + return false; + } - default boolean isRetrogen() { - return false; - } + default boolean isRetrogen() { + return false; + } - String getSpawnName(); + String getSpawnName(); - boolean dimensionAllowed(int dimension); + boolean dimensionAllowed(int dimension); - boolean biomeAllowed(ResourceLocation biomeName); + boolean biomeAllowed(ResourceLocation biomeName); - boolean biomeAllowed(Biome biome); + boolean biomeAllowed(Biome biome); - IFeatureEntry getFeature(); + IFeatureEntry getFeature(); - OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - IBlockList getBlocks(); + IBlockList getBlocks(); - void generate(Random random, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider, ChunkPos pos); + void generate(Random random, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider, ChunkPos pos); - IDimensionList getDimensions(); + IDimensionList getDimensions(); - BiomeLocation getBiomes(); + BiomeLocation getBiomes(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index aba87455..00fab9cd 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -12,55 +12,55 @@ public interface OS3API { - void addSpawn(ISpawnEntry spawnEntry); + void addSpawn(ISpawnEntry spawnEntry); - void addFeature(String featureName, IFeature feature); + void addFeature(String featureName, IFeature feature); - void addReplacement(IReplacementEntry replacementEntry); + void addReplacement(IReplacementEntry replacementEntry); - Map getReplacements(); + Map getReplacements(); - IReplacementEntry getReplacement(String replacementName); + IReplacementEntry getReplacement(String replacementName); - List getSpawns(int dimensionID); + List getSpawns(int dimensionID); - ISpawnEntry getSpawn(String spawnName); + ISpawnEntry getSpawn(String spawnName); - Map getAllSpawns(); + Map getAllSpawns(); - List getDimensionDefaultReplacements(int dimensionID); + List getDimensionDefaultReplacements(int dimensionID); - ISpawnBuilder getSpawnBuilder(); + ISpawnBuilder getSpawnBuilder(); - IDimensionBuilder getDimensionBuilder(); + IDimensionBuilder getDimensionBuilder(); - IFeatureBuilder getFeatureBuilder(); + IFeatureBuilder getFeatureBuilder(); - IBlockBuilder getBlockBuilder(); + IBlockBuilder getBlockBuilder(); - IBiomeBuilder getBiomeBuilder(); + IBiomeBuilder getBiomeBuilder(); - IReplacementBuilder getReplacementBuilder(); + IReplacementBuilder getReplacementBuilder(); - boolean featureExists(String featureName); + boolean featureExists(String featureName); - boolean featureExists(ResourceLocation featureName); + boolean featureExists(ResourceLocation featureName); - IFeature getFeature(String featureName); + IFeature getFeature(String featureName); - IFeature getFeature(ResourceLocation featureName); + IFeature getFeature(ResourceLocation featureName); - PresetsStorage copyPresets(); + PresetsStorage copyPresets(); - void loadConfigFiles(); + void loadConfigFiles(); - boolean hasReplacement(ResourceLocation resourceLocation); + boolean hasReplacement(ResourceLocation resourceLocation); - boolean hasReplacement(String name); + boolean hasReplacement(String name); - void mapEntryToFile(Path p, String entryName); + void mapEntryToFile(Path p, String entryName); - List getSpawnsForFile(String fileName); + List getSpawnsForFile(String fileName); - Map> getSpawnsByFile(); + Map> getSpawnsByFile(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index ffba56f6..ef5a5804 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -15,38 +15,38 @@ public class OreSpawnBlockMatcher implements Predicate { - private final List possibles; - - public OreSpawnBlockMatcher(final IBlockState... matches) { - this.possibles = Arrays.asList(matches); - } - - public OreSpawnBlockMatcher(final List matches) { - this.possibles = new ArrayList<>(); - this.possibles.addAll(matches); - } - - private boolean has(final IBlockState bs) { - return this.possibles.stream().filter(bs::equals).count() > 0; - } - - public boolean test(final IBlockState other) { - return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); - } - - public JsonArray serialize() { - final JsonArray rv = new JsonArray(); - - possibles.stream().forEach(bs -> { - final JsonObject t = new JsonObject(); - t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); - if (!bs.equals(bs.getBlock().getDefaultState())) { - final String state = StateUtil.serializeState(bs); - t.addProperty(Constants.ConfigNames.STATE, state); - } - rv.add(t); - }); - - return rv; - } + private final List possibles; + + public OreSpawnBlockMatcher(final IBlockState... matches) { + this.possibles = Arrays.asList(matches); + } + + public OreSpawnBlockMatcher(final List matches) { + this.possibles = new ArrayList<>(); + this.possibles.addAll(matches); + } + + private boolean has(final IBlockState bs) { + return this.possibles.stream().filter(bs::equals).count() > 0; + } + + public boolean test(final IBlockState other) { + return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); + } + + public JsonArray serialize() { + final JsonArray rv = new JsonArray(); + + possibles.stream().forEach(bs -> { + final JsonObject t = new JsonObject(); + t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); + if (!bs.equals(bs.getBlock().getDefaultState())) { + final String state = StateUtil.serializeState(bs); + t.addProperty(Constants.ConfigNames.STATE, state); + } + rv.add(t); + }); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java index d3b0bf7c..8ffefb38 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java @@ -4,5 +4,5 @@ public interface IOreSpawnPlugin { - void register(OS3API apiInterface); + void register(OS3API apiInterface); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java index 7120c8be..700ce86e 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java @@ -10,15 +10,15 @@ @Target(TYPE) public @interface OreSpawnPlugin { - // the Mod this is for - will be used for - // generating the name of the json the config - // will get saved to and should also be the - // actual mod-id we can use for creating a - // resource location - String modid(); + // the Mod this is for - will be used for + // generating the name of the json the config + // will get saved to and should also be the + // actual mod-id we can use for creating a + // resource location + String modid(); - // resource location segment to look in - // for registered config files + // resource location segment to look in + // for registered config files - String resourcePath() default "orespawn"; + String resourcePath() default "orespawn"; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index fcd96e7e..8576c8c6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -31,134 +31,134 @@ public enum PluginLoader { - INSTANCE; - - private class PluginData { - - public final String modId; - public final String resourcePath; - public final IOreSpawnPlugin plugin; - - PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { - this.modId = modId; - this.resourcePath = resourcePath; - this.plugin = plugin; - } - } - - private static List dataStore = new ArrayList<>(); - - private String getAnnotationItem(final String item, final ASMData asmData) { - if (asmData.getAnnotationInfo().get(item) != null) { - return asmData.getAnnotationInfo().get(item).toString(); - } else { - return ""; - } - } - - public void load(final FMLPreInitializationEvent event) { - for (final ASMData asmDataItem : event.getAsmData() - .getAll(OreSpawnPlugin.class.getCanonicalName())) { - final String modId = getAnnotationItem("modid", asmDataItem); - final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); - final String clazz = asmDataItem.getClassName(); - IOreSpawnPlugin integration; - - try { - integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); - final PluginData pd = new PluginData(modId, resourceBase, integration); - dataStore.add(pd); - } catch (final Exception ex) { - OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); - } - } - } - - public void register() { - dataStore.forEach(pd -> { - scanResources(pd); - pd.plugin.register(OreSpawn.API); - }); - } - - public void scanResources(final PluginData pd) { - if (Config.getKnownMods().contains(pd.modId)) { - return; - } - - final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); - final URL resURL = getClass().getClassLoader().getResource(base); - - if (resURL == null) { - OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", - base); - return; - } - - URI uri; - - try { - uri = resURL.toURI(); - } catch (URISyntaxException ex) { - CrashReport report = CrashReport.makeCrashReport(ex, - String.format("Failed to get URI for %s", - (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - return; - } - - if (uri.getScheme().equals("jar")) { - try (FileSystem fileSystem = FileSystems.newFileSystem(uri, - Collections.emptyMap())) { - copyout(fileSystem.getPath(base), pd.modId); - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Failed in getting FileSystem handler set up for %s", uri.getPath())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } else { - copyout(Paths.get(uri), pd.modId); - } - - Config.addKnownMod(pd.modId); - } - - private void copyout(final Path myPath, final String modId) { - try (Stream walk = Files.walk(myPath, 1)) { - for (final Iterator it = walk.iterator(); it.hasNext();) { - final Path p = it.next(); - final String name = p.getFileName().toString(); - - if ("json".equals(FilenameUtils.getExtension(name))) { - InputStream reader = null; - Path target; - - if ("_features".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format("features-%s.json", modId)); - } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format("replacements-%s.json", modId)); - } else { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - String.format("%s.json", modId)); - } - - if (!target.toFile().exists()) { - reader = Files.newInputStream(p); - FileUtils.copyInputStreamToFile(reader, target.toFile()); - IOUtils.closeQuietly(reader); - } - } - } - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Faulted while iterating %s for config files or copying them out", myPath)); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.error(report.getCompleteReport()); - } - } + INSTANCE; + + private class PluginData { + + public final String modId; + public final String resourcePath; + public final IOreSpawnPlugin plugin; + + PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { + this.modId = modId; + this.resourcePath = resourcePath; + this.plugin = plugin; + } + } + + private static List dataStore = new ArrayList<>(); + + private String getAnnotationItem(final String item, final ASMData asmData) { + if (asmData.getAnnotationInfo().get(item) != null) { + return asmData.getAnnotationInfo().get(item).toString(); + } else { + return ""; + } + } + + public void load(final FMLPreInitializationEvent event) { + for (final ASMData asmDataItem : event.getAsmData() + .getAll(OreSpawnPlugin.class.getCanonicalName())) { + final String modId = getAnnotationItem("modid", asmDataItem); + final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); + final String clazz = asmDataItem.getClassName(); + IOreSpawnPlugin integration; + + try { + integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); + final PluginData pd = new PluginData(modId, resourceBase, integration); + dataStore.add(pd); + } catch (final Exception ex) { + OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); + } + } + } + + public void register() { + dataStore.forEach(pd -> { + scanResources(pd); + pd.plugin.register(OreSpawn.API); + }); + } + + public void scanResources(final PluginData pd) { + if (Config.getKnownMods().contains(pd.modId)) { + return; + } + + final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); + final URL resURL = getClass().getClassLoader().getResource(base); + + if (resURL == null) { + OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", + base); + return; + } + + URI uri; + + try { + uri = resURL.toURI(); + } catch (URISyntaxException ex) { + CrashReport report = CrashReport.makeCrashReport(ex, + String.format("Failed to get URI for %s", + (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + return; + } + + if (uri.getScheme().equals("jar")) { + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, + Collections.emptyMap())) { + copyout(fileSystem.getPath(base), pd.modId); + } catch (IOException exc) { + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Failed in getting FileSystem handler set up for %s", uri.getPath())); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } else { + copyout(Paths.get(uri), pd.modId); + } + + Config.addKnownMod(pd.modId); + } + + private void copyout(final Path myPath, final String modId) { + try (Stream walk = Files.walk(myPath, 1)) { + for (final Iterator it = walk.iterator(); it.hasNext();) { + final Path p = it.next(); + final String name = p.getFileName().toString(); + + if ("json".equals(FilenameUtils.getExtension(name))) { + InputStream reader = null; + Path target; + + if ("_features".equals(FilenameUtils.getBaseName(name))) { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("features-%s.json", modId)); + } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("replacements-%s.json", modId)); + } else { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + String.format("%s.json", modId)); + } + + if (!target.toFile().exists()) { + reader = Files.newInputStream(p); + FileUtils.copyInputStreamToFile(reader, target.toFile()); + IOUtils.closeQuietly(reader); + } + } + } + } catch (IOException exc) { + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Faulted while iterating %s for config files or copying them out", myPath)); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + OreSpawn.LOGGER.error(report.getCompleteReport()); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 8ec4a687..ae91f018 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -26,86 +26,86 @@ public class AddOreCommand extends CommandBase { - @Override - public String getName() { - return "addore"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/addore "; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { - throw new CommandException("Only players can use this command"); - } - - final EntityPlayer player = (EntityPlayer) sender; - final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); - - if (stack == null) { - throw new CommandException("You have no item in your main hand"); - } else if (!(stack.getItem() instanceof ItemBlock)) { - throw new CommandException("The item in your main hand isn't a block"); - } else if (args.length < 2) { - throw new CommandException(this.getUsage(sender)); - } - - final String file = args[0]; - @SuppressWarnings("deprecation") - final IBlockState state = Block.getBlockFromItem(stack.getItem()) - .getStateFromMeta(stack.getItemDamage()); - - final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); - final JsonParser p = new JsonParser(); - final JsonElement parsed = mergeDefaults(p.parse(rawData), state); - OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); - OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); - } - - private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { - final JsonObject work = parse.getAsJsonObject(); - final JsonObject emptyBlacklist = new JsonObject(); - emptyBlacklist.add("excludes", new JsonArray()); - - if (!work.has(ConfigNames.ENABLED)) { - work.addProperty(ConfigNames.ENABLED, true); - } - if (!work.has(ConfigNames.RETROGEN)) { - work.addProperty(ConfigNames.RETROGEN, false); - } - if (!work.has(ConfigNames.FEATURE)) { - work.addProperty(ConfigNames.FEATURE, "default"); - } - if (!work.has(ConfigNames.REPLACEMENT)) { - work.addProperty(ConfigNames.REPLACEMENT, "default"); - } - if (!work.has(ConfigNames.PARAMETERS)) { - work.add(ConfigNames.PARAMETERS, - OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) - .getDefaultParameters()); - } - if (!work.has(ConfigNames.DIMENSIONS)) { - work.add(ConfigNames.DIMENSIONS, emptyBlacklist); - } - if (!work.has(ConfigNames.BIOMES)) { - work.add(ConfigNames.BIOMES, emptyBlacklist); - } - - final JsonObject block = new JsonObject(); - block.addProperty(ConfigNames.CHANCE, 100); - block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); - block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); - work.add(ConfigNames.BLOCK, block); - - return work; - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + @Override + public String getName() { + return "addore"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/addore "; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + if (!(sender instanceof EntityPlayer)) { + throw new CommandException("Only players can use this command"); + } + + final EntityPlayer player = (EntityPlayer) sender; + final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); + + if (stack == null) { + throw new CommandException("You have no item in your main hand"); + } else if (!(stack.getItem() instanceof ItemBlock)) { + throw new CommandException("The item in your main hand isn't a block"); + } else if (args.length < 2) { + throw new CommandException(this.getUsage(sender)); + } + + final String file = args[0]; + @SuppressWarnings("deprecation") + final IBlockState state = Block.getBlockFromItem(stack.getItem()) + .getStateFromMeta(stack.getItemDamage()); + + final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); + final JsonParser p = new JsonParser(); + final JsonElement parsed = mergeDefaults(p.parse(rawData), state); + OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); + OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); + } + + private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { + final JsonObject work = parse.getAsJsonObject(); + final JsonObject emptyBlacklist = new JsonObject(); + emptyBlacklist.add("excludes", new JsonArray()); + + if (!work.has(ConfigNames.ENABLED)) { + work.addProperty(ConfigNames.ENABLED, true); + } + if (!work.has(ConfigNames.RETROGEN)) { + work.addProperty(ConfigNames.RETROGEN, false); + } + if (!work.has(ConfigNames.FEATURE)) { + work.addProperty(ConfigNames.FEATURE, "default"); + } + if (!work.has(ConfigNames.REPLACEMENT)) { + work.addProperty(ConfigNames.REPLACEMENT, "default"); + } + if (!work.has(ConfigNames.PARAMETERS)) { + work.add(ConfigNames.PARAMETERS, + OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) + .getDefaultParameters()); + } + if (!work.has(ConfigNames.DIMENSIONS)) { + work.add(ConfigNames.DIMENSIONS, emptyBlacklist); + } + if (!work.has(ConfigNames.BIOMES)) { + work.add(ConfigNames.BIOMES, emptyBlacklist); + } + + final JsonObject block = new JsonObject(); + block.addProperty(ConfigNames.CHANCE, 100); + block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); + block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); + work.add(ConfigNames.BLOCK, block); + + return work; + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 1db09255..31daf891 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -27,137 +27,137 @@ public class ClearChunkCommand extends CommandBase { - private static final String STONE_ID = "minecraft:stone"; - private static final List stoneVariants = Arrays.asList(STONE_ID, - "minecraft:diorite", "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", - "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); - private static final List baseStones = Arrays.asList(STONE_ID, - "minecraft:netherrack", "minecraft:end_stone", "minecraft:cobblestone", - "minecraft:obsidian", "minecraft:magma", "minecraft:soul_sand"); - - private static final List dirtVariants = Arrays.asList("minecraft:dirt", - "minecraft:grass"); - private static final List otherVariants = Arrays.asList("minecraft:gravel", - "minecraft:sand"); - - @Override - public String getName() { - return "clearchunk"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/clearchunk "; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { - throw new CommandException("Only players can use this command"); - } - - final EntityPlayer player = (EntityPlayer) sender; - final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); - final ChunkPos chunkPos = chunk.getPos(); - final List blocks; - - final boolean flagClassic = args.length > 0 - ? args[0].toLowerCase().equalsIgnoreCase("classic") - : false; - - final List blockNames = new LinkedList<>(); - getBlocks(args, blockNames); - - blocks = blockNames.stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(block -> block.getDefaultState()).collect(Collectors.toList()); - - blocks.addAll(OreSpawn.API - .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) - .stream().collect(Collectors.toList())); - final List overburden = Arrays - .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", - "minecraft:sandstone", "minecraft:red_sandstone") - .stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); - - clearBlocks(chunkPos, blocks, overburden, flagClassic, player); - - player.sendStatusMessage( - new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); - } - - private void clearBlocks(final ChunkPos chunkPos, final List blocks, - final List overburden, final boolean flagClassic, - final EntityPlayer player) { - for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { - for (int y = 256; y >= 0; y--) { - for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { - final BlockPos pos = new BlockPos(x, y, z); - final IBlockState block = player.getEntityWorld().getBlockState(pos); - removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); - removeIfFluid(pos, player); - } - } - } - } - - private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { - if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { - final IBlockState bs = player.getEntityWorld().getBlockState(pos); - - if (bs.getMaterial().isLiquid()) { - player.getEntityWorld().setBlockToAir(pos); - } - } - } - - private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, - final IBlockState block, final List blocks, - final List overburden, final boolean flagClassic) { - if (blocks.contains(block) - || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { - player.getEntityWorld().setBlockToAir(pos); - } - } - - private void getBlocks(final String[] args, final List blockNames) { - if (args.length > 0) { - switch (args[0].toLowerCase()) { - case "viewores": - blockNames.addAll(stoneVariants); - blockNames.addAll(dirtVariants); - blockNames.addAll(otherVariants); - break; - - case "dirtandgravel": - blockNames.add(STONE_ID); - blockNames.addAll(dirtVariants); - blockNames.addAll(otherVariants); - break; - - case "classic": - blockNames.add(Blocks.STONE.getRegistryName().toString()); - blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); - blockNames.add(Blocks.END_STONE.getRegistryName().toString()); - blockNames - .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) - .map(Block::getBlockFromItem).map(Block::getRegistryName) - .map(ResourceLocation::toString).collect(Collectors.toList())); - break; - - default: - blockNames.addAll(baseStones); - } - } else { - blockNames.addAll(baseStones); - } - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + private static final String STONE_ID = "minecraft:stone"; + private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", + "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", + "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); + private static final List baseStones = Arrays.asList(STONE_ID, + "minecraft:netherrack", "minecraft:end_stone", "minecraft:cobblestone", + "minecraft:obsidian", "minecraft:magma", "minecraft:soul_sand"); + + private static final List dirtVariants = Arrays.asList("minecraft:dirt", + "minecraft:grass"); + private static final List otherVariants = Arrays.asList("minecraft:gravel", + "minecraft:sand"); + + @Override + public String getName() { + return "clearchunk"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/clearchunk "; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + if (!(sender instanceof EntityPlayer)) { + throw new CommandException("Only players can use this command"); + } + + final EntityPlayer player = (EntityPlayer) sender; + final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); + final ChunkPos chunkPos = chunk.getPos(); + final List blocks; + + final boolean flagClassic = args.length > 0 + ? args[0].toLowerCase().equalsIgnoreCase("classic") + : false; + + final List blockNames = new LinkedList<>(); + getBlocks(args, blockNames); + + blocks = blockNames.stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(block -> block.getDefaultState()).collect(Collectors.toList()); + + blocks.addAll(OreSpawn.API + .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) + .stream().collect(Collectors.toList())); + final List overburden = Arrays + .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", + "minecraft:sandstone", "minecraft:red_sandstone") + .stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); + + clearBlocks(chunkPos, blocks, overburden, flagClassic, player); + + player.sendStatusMessage( + new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); + } + + private void clearBlocks(final ChunkPos chunkPos, final List blocks, + final List overburden, final boolean flagClassic, + final EntityPlayer player) { + for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { + for (int y = 256; y >= 0; y--) { + for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { + final BlockPos pos = new BlockPos(x, y, z); + final IBlockState block = player.getEntityWorld().getBlockState(pos); + removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); + removeIfFluid(pos, player); + } + } + } + } + + private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { + if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { + final IBlockState bs = player.getEntityWorld().getBlockState(pos); + + if (bs.getMaterial().isLiquid()) { + player.getEntityWorld().setBlockToAir(pos); + } + } + } + + private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, + final IBlockState block, final List blocks, + final List overburden, final boolean flagClassic) { + if (blocks.contains(block) + || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { + player.getEntityWorld().setBlockToAir(pos); + } + } + + private void getBlocks(final String[] args, final List blockNames) { + if (args.length > 0) { + switch (args[0].toLowerCase()) { + case "viewores": + blockNames.addAll(stoneVariants); + blockNames.addAll(dirtVariants); + blockNames.addAll(otherVariants); + break; + + case "dirtandgravel": + blockNames.add(STONE_ID); + blockNames.addAll(dirtVariants); + blockNames.addAll(otherVariants); + break; + + case "classic": + blockNames.add(Blocks.STONE.getRegistryName().toString()); + blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); + blockNames.add(Blocks.END_STONE.getRegistryName().toString()); + blockNames + .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) + .map(Block::getBlockFromItem).map(Block::getRegistryName) + .map(ResourceLocation::toString).collect(Collectors.toList())); + break; + + default: + blockNames.addAll(baseStones); + } + } else { + blockNames.addAll(baseStones); + } + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 74bf10a5..54d5f21c 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -23,40 +23,40 @@ public class DumpBiomesCommand extends CommandBase { - @Override - public String getName() { - return "dumpbiomes"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/dumpbiomes"; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - JsonArray array = new JsonArray(); - - for (final Biome biome : ForgeRegistries.BIOMES) { - array.add(new JsonPrimitive(biome.getRegistryName().toString())); - } - - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final String json = gson.toJson(array); - - try { - FileUtils.writeStringToFile(new File(".", "biome_dump.json"), - StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); - } catch (final IOException e) { - throw new CommandException("Failed to save the json file"); - } - - sender.sendMessage(new TextComponentString("Done")); - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + @Override + public String getName() { + return "dumpbiomes"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/dumpbiomes"; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + JsonArray array = new JsonArray(); + + for (final Biome biome : ForgeRegistries.BIOMES) { + array.add(new JsonPrimitive(biome.getRegistryName().toString())); + } + + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String json = gson.toJson(array); + + try { + FileUtils.writeStringToFile(new File(".", "biome_dump.json"), + StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); + } catch (final IOException e) { + throw new CommandException("Failed to save the json file"); + } + + sender.sendMessage(new TextComponentString("Done")); + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index 4d1dc064..661c28a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -10,22 +10,22 @@ public class WriteConfigsCommand extends CommandBase { - @Override - public String getName() { - return "osSaveConfigs"; - } + @Override + public String getName() { + return "osSaveConfigs"; + } - @Override - public String getUsage(final ICommandSender sender) { - return "/osSaveConfigs"; - } + @Override + public String getUsage(final ICommandSender sender) { + return "/osSaveConfigs"; + } - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - sender.sendMessage(new TextComponentString( - "Forcing configs as OreSpawn sees them to be written to disk")); - OreSpawnWriter.saveConfigs(); - } + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + sender.sendMessage(new TextComponentString( + "Forcing configs as OreSpawn sees them to be written to disk")); + OreSpawnWriter.saveConfigs(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 95ade634..dbe413f0 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -23,147 +23,147 @@ public class Config { - private static Configuration configuration; - - private Config() { - } - - public static void loadConfig() { - configuration = new Configuration(new File(Constants.CONFIG_FILE)); - - // Load our Boolean Values - boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, - Configuration.CATEGORY_GENERAL, false, - "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); - boolVals.put(Constants.FORCE_RETROGEN_KEY, - configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, - Configuration.CATEGORY_GENERAL, false, - "Force all chunks to retrogen regardless of anything else")); - boolVals.put(Constants.REPLACE_VANILLA_OREGEN, - configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, - Configuration.CATEGORY_GENERAL, false, - "Replace vanilla ore-generation entirely")); - boolVals.put(Constants.FLAT_BEDROCK, - configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, - false, "Flatten the bedrock during world generation")); - boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, - Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); - intVals.put(Constants.BEDROCK_LAYERS, - configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, - 4, "How thick should the shell of bedrock be?")); - knownKeys.add(Constants.RETROGEN_KEY); - knownKeys.add(Constants.FORCE_RETROGEN_KEY); - knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); - knownKeys.add(Constants.KNOWN_MODS); - knownKeys.add(Constants.FLAT_BEDROCK); - knownKeys.add(Constants.RETRO_BEDROCK); - knownKeys.add(Constants.BEDROCK_LAYERS); - - loadExtractedConfigs(); - } - - private static void loadExtractedConfigs() { - final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", - "known-configs.json"); - - if (!p.toFile().exists()) { - return; - } - - final File in = p.toFile(); - String rawData; - - try { - rawData = FileUtils.readFileToString(in, Charset.defaultCharset()); - } catch (IOException e) { - return; - } - - if (rawData.isEmpty()) { - return; - } - - final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); - data.forEach(item -> addKnownMod(item.getAsString())); - } - - public static List getKnownMods() { - return ImmutableList.copyOf(extractedConfigs); - } - - public static void addKnownMod(final String modId) { - extractedConfigs.add(modId); - } - - public static boolean getBoolean(final String keyname) { - if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { - return boolVals.get(keyname); - } - - return false; - } - - public static String getString(final String keyname) { - if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { - return stringVals.get(keyname); - } - - return ""; - } - - public static int getInt(final String keyname) { - if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { - return intVals.get(keyname); - } - - return 0; - } - - public static float getFloat(final String keyname) { - if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { - return floatVals.get(keyname); - } - - return 0.0f; - } - - public static void saveConfig() { - if (!extractedConfigs.isEmpty()) { - saveKnownConfigs(); - } - - configuration.save(); - } - - private static void saveKnownConfigs() { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", - "known-configs.json"); - - if (!p.toFile().getParentFile().exists()) { - p.toFile().mkdirs(); - } - - final File in = p.toFile(); - - final JsonArray data = new JsonArray(); - - extractedConfigs.forEach(data::add); - - try { - FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed saving list of already extracted mod configs"); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - private static final HashMap boolVals = new HashMap<>(); - private static final HashMap stringVals = new HashMap<>(); - private static final HashMap intVals = new HashMap<>(); - private static final HashMap floatVals = new HashMap<>(); - private static final List knownKeys = new ArrayList<>(); - private static final List extractedConfigs = new ArrayList<>(); + private static Configuration configuration; + + private Config() { + } + + public static void loadConfig() { + configuration = new Configuration(new File(Constants.CONFIG_FILE)); + + // Load our Boolean Values + boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); + boolVals.put(Constants.FORCE_RETROGEN_KEY, + configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Force all chunks to retrogen regardless of anything else")); + boolVals.put(Constants.REPLACE_VANILLA_OREGEN, + configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, + Configuration.CATEGORY_GENERAL, false, + "Replace vanilla ore-generation entirely")); + boolVals.put(Constants.FLAT_BEDROCK, + configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, + false, "Flatten the bedrock during world generation")); + boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, + Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); + intVals.put(Constants.BEDROCK_LAYERS, + configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, + 4, "How thick should the shell of bedrock be?")); + knownKeys.add(Constants.RETROGEN_KEY); + knownKeys.add(Constants.FORCE_RETROGEN_KEY); + knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); + knownKeys.add(Constants.KNOWN_MODS); + knownKeys.add(Constants.FLAT_BEDROCK); + knownKeys.add(Constants.RETRO_BEDROCK); + knownKeys.add(Constants.BEDROCK_LAYERS); + + loadExtractedConfigs(); + } + + private static void loadExtractedConfigs() { + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); + + if (!p.toFile().exists()) { + return; + } + + final File in = p.toFile(); + String rawData; + + try { + rawData = FileUtils.readFileToString(in, Charset.defaultCharset()); + } catch (IOException e) { + return; + } + + if (rawData.isEmpty()) { + return; + } + + final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); + data.forEach(item -> addKnownMod(item.getAsString())); + } + + public static List getKnownMods() { + return ImmutableList.copyOf(extractedConfigs); + } + + public static void addKnownMod(final String modId) { + extractedConfigs.add(modId); + } + + public static boolean getBoolean(final String keyname) { + if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { + return boolVals.get(keyname); + } + + return false; + } + + public static String getString(final String keyname) { + if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { + return stringVals.get(keyname); + } + + return ""; + } + + public static int getInt(final String keyname) { + if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { + return intVals.get(keyname); + } + + return 0; + } + + public static float getFloat(final String keyname) { + if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { + return floatVals.get(keyname); + } + + return 0.0f; + } + + public static void saveConfig() { + if (!extractedConfigs.isEmpty()) { + saveKnownConfigs(); + } + + configuration.save(); + } + + private static void saveKnownConfigs() { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); + + if (!p.toFile().getParentFile().exists()) { + p.toFile().mkdirs(); + } + + final File in = p.toFile(); + + final JsonArray data = new JsonArray(); + + extractedConfigs.forEach(data::add); + + try { + FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed saving list of already extracted mod configs"); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + private static final HashMap boolVals = new HashMap<>(); + private static final HashMap stringVals = new HashMap<>(); + private static final HashMap intVals = new HashMap<>(); + private static final HashMap floatVals = new HashMap<>(); + private static final List knownKeys = new ArrayList<>(); + private static final List extractedConfigs = new ArrayList<>(); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index cbe7543e..be3da0df 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -5,104 +5,104 @@ public class Constants { - public static final String MODID = "orespawn"; - public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.3.0"; - public static final String RETROGEN_KEY = "Retrogen"; - public static final String CONFIG_FILE = "config/orespawn.cfg"; - public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; - public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; - public static final String ORE_TAG = "ores"; - public static final String FEATURES_TAG = "features"; - public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; - public static final String OVERWORLD = "overworld"; - public static final String THE_OVERWORLD = "the overworld"; - public static final String NETHER = "nether"; - public static final String THE_NETHER = "the nether"; - public static final String END = "end"; - public static final String THE_END = "the end"; - public static final String DEFAULT_GEN = "default"; - public static final String VEIN_GEN = "vein"; - public static final String NORMAL_CLOUD = "normal-cloud"; - public static final String CLUSTERS = "clusters"; - public static final String CRASH_SECTION = "OreSpawn Version"; - public static final String KNOWN_MODS = "already-extracted"; - public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; - public static final String FLAT_BEDROCK = "Flatten Bedrock"; - public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; - public static final String BEDROCK_LAYERS = "Bedrock Thickness"; - public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; - public static final String PRECISION = "precision"; - public static final Path CONFDIR = Paths.get("config", "orespawn3"); - public static final Path SYSCONF = Paths.get("config", "orespawn3", - "sysconf"); + public static final String MODID = "orespawn"; + public static final String NAME = "MMD OreSpawn"; + public static final String VERSION = "3.3.0"; + public static final String RETROGEN_KEY = "Retrogen"; + public static final String CONFIG_FILE = "config/orespawn.cfg"; + public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; + public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; + public static final String ORE_TAG = "ores"; + public static final String FEATURES_TAG = "features"; + public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; + public static final String OVERWORLD = "overworld"; + public static final String THE_OVERWORLD = "the overworld"; + public static final String NETHER = "nether"; + public static final String THE_NETHER = "the nether"; + public static final String END = "end"; + public static final String THE_END = "the end"; + public static final String DEFAULT_GEN = "default"; + public static final String VEIN_GEN = "vein"; + public static final String NORMAL_CLOUD = "normal-cloud"; + public static final String CLUSTERS = "clusters"; + public static final String CRASH_SECTION = "OreSpawn Version"; + public static final String KNOWN_MODS = "already-extracted"; + public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; + public static final String FLAT_BEDROCK = "Flatten Bedrock"; + public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; + public static final String BEDROCK_LAYERS = "Bedrock Thickness"; + public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; + public static final String PRECISION = "precision"; + public static final Path CONFDIR = Paths.get("config", "orespawn3"); + public static final Path SYSCONF = Paths.get("config", "orespawn3", + "sysconf"); - public final class FormatBits { + public final class FormatBits { - private FormatBits() { - } + private FormatBits() { + } - public static final String MAX_SPREAD = "maxSpread"; - public static final String MEDIAN_SIZE = "medianSize"; - public static final String MIN_HEIGHT = "minHeight"; - public static final String MAX_HEIGHT = "maxHeight"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String NODE_SIZE = "size"; - public static final String ATTEMPTS = "attempts"; - public static final String LENGTH = "length"; - public static final String NODE_COUNT = "numObjects"; - public static final String ATTEMPTS_MIN = "minAttempts"; - public static final String ATTEMPTS_MAX = "maxAttempts"; - public static final String STARTINGFACE = "startFacing"; - } + public static final String MAX_SPREAD = "maxSpread"; + public static final String MEDIAN_SIZE = "medianSize"; + public static final String MIN_HEIGHT = "minHeight"; + public static final String MAX_HEIGHT = "maxHeight"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String NODE_SIZE = "size"; + public static final String ATTEMPTS = "attempts"; + public static final String LENGTH = "length"; + public static final String NODE_COUNT = "numObjects"; + public static final String ATTEMPTS_MIN = "minAttempts"; + public static final String ATTEMPTS_MAX = "maxAttempts"; + public static final String STARTINGFACE = "startFacing"; + } - public final class FileBits { + public final class FileBits { - private FileBits() { - } + private FileBits() { + } - public static final String CONFIG_DIR = "config"; - public static final String OS3 = "orespawn3"; - public static final String SYSCONF = "sysconf"; - public static final String PRESETS = "presets.json"; - } + public static final String CONFIG_DIR = "config"; + public static final String OS3 = "orespawn3"; + public static final String SYSCONF = "sysconf"; + public static final String PRESETS = "presets.json"; + } - public final class ConfigNames { + public final class ConfigNames { - private ConfigNames() { - } + private ConfigNames() { + } - public static final String DEFAULT = "default"; - public static final String STATE_NORMAL = "normal"; - public static final String DIMENSIONS = "dimensions"; - public static final String CHANCE = "chance"; - public static final String METADATA = "metaData"; - public static final String BIOMES = "biomes"; - public static final String STATE = "state"; - public static final String REPLACEMENT = "replaces"; - public static final String FEATURE = "feature"; - public static final String PARAMETERS = "parameters"; - public static final String FILE_VERSION = "version"; - public static final String BLOCK = "blocks"; - public static final String SPAWNS = "spawns"; - public static final String RETROGEN = "retrogen"; - public static final String ENABLED = "enabled"; - public static final String NAME = "name"; - public static final String WHITELIST = "includes"; - public static final String BLACKLIST = "excludes"; - public static final String PRESETS = "presets"; + public static final String DEFAULT = "default"; + public static final String STATE_NORMAL = "normal"; + public static final String DIMENSIONS = "dimensions"; + public static final String CHANCE = "chance"; + public static final String METADATA = "metaData"; + public static final String BIOMES = "biomes"; + public static final String STATE = "state"; + public static final String REPLACEMENT = "replaces"; + public static final String FEATURE = "feature"; + public static final String PARAMETERS = "parameters"; + public static final String FILE_VERSION = "version"; + public static final String BLOCK = "blocks"; + public static final String SPAWNS = "spawns"; + public static final String RETROGEN = "retrogen"; + public static final String ENABLED = "enabled"; + public static final String NAME = "name"; + public static final String WHITELIST = "includes"; + public static final String BLACKLIST = "excludes"; + public static final String PRESETS = "presets"; - public final class DefaultFeatureProperties { + public final class DefaultFeatureProperties { - private DefaultFeatureProperties() { - } + private DefaultFeatureProperties() { + } - public static final String SIZE = "size"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String MAXHEIGHT = "maxHeight"; - public static final String MINHEIGHT = "minHeight"; - } - } + public static final String SIZE = "size"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String MAXHEIGHT = "maxHeight"; + public static final String MINHEIGHT = "minHeight"; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 675f5842..a8490bb1 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -28,135 +28,135 @@ public class FeatureRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistry registry = new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) - .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO - .create(); - - public FeatureRegistry() { - // - } - - public Map getFeatures() { - final Map tempMap = new TreeMap<>(); - registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); - - return Collections.unmodifiableMap(tempMap); - } - - public String getFeatureName(final IFeature feature) { - return feature.getRegistryName().toString(); - } - - public IFeature getFeature(final String name) { - return getFeature(new ResourceLocation(name)); - } - - public IFeature getFeature(final ResourceLocation featureResourceLocation) { - final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); - if (registry.containsKey(featureResourceLocation)) { - return registry.getValue(featureResourceLocation); - } else { - return registry.getValue(defaultGen); - } - } - - public boolean hasFeature(final String name) { - return hasFeature(new ResourceLocation(name)); - } - - public boolean hasFeature(final ResourceLocation featureResourceLocation) { - return registry.containsKey(featureResourceLocation); - } - - public boolean hasFeature(final IFeature feature) { - return registry.containsKey(feature.getRegistryName()); - } - - public void addFeature(final String name, final IFeature feature) { - feature.setRegistryName(new ResourceLocation("orespawn", name)); - registry.register(feature); - } - - public void addFeature(final JsonObject entry) { - addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); - } - - public void addFeature(final String name, final String className) { - final IFeature feature = getInstance(className); - - if (feature != null && !hasFeature(name)) { - addFeature(name, feature); - } - } - - private static IFeature getInstance(final String className) { - Class featureClazz; - Constructor featureCons; - IFeature feature; - - try { - featureClazz = Class.forName(className); - featureCons = featureClazz.getConstructor(); - feature = (IFeature) featureCons.newInstance(); - } catch (final Exception e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed to load and instantiate an instance of the feature generator named " - + className + " that was specified as a feature generator"); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return null; - } - - return feature; - } - - public void loadFeaturesFile(final File file) { - final JsonParser parser = new JsonParser(); - String rawJson; - JsonArray elements; - - try { - rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); - } catch (final IOException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + file.getName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return; - } - - elements = parser.parse(rawJson).getAsJsonArray(); - - for (final JsonElement elem : elements) { - addFeature(elem.getAsJsonObject()); - } - } - - public void writeFeatures(final File file) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - final JsonArray root = new JsonArray(); - - registry.getEntries().stream().map(ent -> { - final JsonObject e = new JsonObject(); - e.addProperty("name", ent.getKey().getPath()); - e.addProperty("class", ent.getValue().getClass().getName()); - return e; - }).forEach(root::add); - - final String json = gson.toJson(root); - - try { - FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), - CharEncoding.UTF_8); - } catch (final IOException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed writing config " + file.getName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistry registry = new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) + .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO + .create(); + + public FeatureRegistry() { + // + } + + public Map getFeatures() { + final Map tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); + + return Collections.unmodifiableMap(tempMap); + } + + public String getFeatureName(final IFeature feature) { + return feature.getRegistryName().toString(); + } + + public IFeature getFeature(final String name) { + return getFeature(new ResourceLocation(name)); + } + + public IFeature getFeature(final ResourceLocation featureResourceLocation) { + final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); + if (registry.containsKey(featureResourceLocation)) { + return registry.getValue(featureResourceLocation); + } else { + return registry.getValue(defaultGen); + } + } + + public boolean hasFeature(final String name) { + return hasFeature(new ResourceLocation(name)); + } + + public boolean hasFeature(final ResourceLocation featureResourceLocation) { + return registry.containsKey(featureResourceLocation); + } + + public boolean hasFeature(final IFeature feature) { + return registry.containsKey(feature.getRegistryName()); + } + + public void addFeature(final String name, final IFeature feature) { + feature.setRegistryName(new ResourceLocation("orespawn", name)); + registry.register(feature); + } + + public void addFeature(final JsonObject entry) { + addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); + } + + public void addFeature(final String name, final String className) { + final IFeature feature = getInstance(className); + + if (feature != null && !hasFeature(name)) { + addFeature(name, feature); + } + } + + private static IFeature getInstance(final String className) { + Class featureClazz; + Constructor featureCons; + IFeature feature; + + try { + featureClazz = Class.forName(className); + featureCons = featureClazz.getConstructor(); + feature = (IFeature) featureCons.newInstance(); + } catch (final Exception e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed to load and instantiate an instance of the feature generator named " + + className + " that was specified as a feature generator"); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return null; + } + + return feature; + } + + public void loadFeaturesFile(final File file) { + final JsonParser parser = new JsonParser(); + String rawJson; + JsonArray elements; + + try { + rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return; + } + + elements = parser.parse(rawJson).getAsJsonArray(); + + for (final JsonElement elem : elements) { + addFeature(elem.getAsJsonObject()); + } + } + + public void writeFeatures(final File file) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + final JsonArray root = new JsonArray(); + + registry.getEntries().stream().map(ent -> { + final JsonObject e = new JsonObject(); + e.addProperty("name", ent.getKey().getPath()); + e.addProperty("class", ent.getValue().getClass().getName()); + return e; + }).forEach(root::add); + + final String json = gson.toJson(root); + + try { + FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), + CharEncoding.UTF_8); + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config " + file.getName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index 6b8c715f..ca310863 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -21,75 +21,75 @@ public class PresetsStorage { - private final Map> storage; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private final Map> storage; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public PresetsStorage() { - storage = new TreeMap<>(); - } + public PresetsStorage() { + storage = new TreeMap<>(); + } - public void setSymbolSection(final String sectionName, final String itemName, - final JsonElement value) { - final Map temp = storage.getOrDefault(sectionName, - new HashMap()); - temp.put(itemName, value); - storage.put(sectionName, temp); - } + public void setSymbolSection(final String sectionName, final String itemName, + final JsonElement value) { + final Map temp = storage.getOrDefault(sectionName, + new HashMap()); + temp.put(itemName, value); + storage.put(sectionName, temp); + } - public JsonElement getSymbolSection(final String sectionName, final String itemName) { - if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { - return storage.get(sectionName).get(itemName); - } else { - return new JsonPrimitive(itemName); - } - } + public JsonElement getSymbolSection(final String sectionName, final String itemName) { + if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { + return storage.get(sectionName).get(itemName); + } else { + return new JsonPrimitive(itemName); + } + } - public void copy(final PresetsStorage dest) { - storage.entrySet().stream().forEach(ensm -> { - final String section = ensm.getKey(); - ensm.getValue().entrySet().forEach( - ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); - }); - } + public void copy(final PresetsStorage dest) { + storage.entrySet().stream().forEach(ensm -> { + final String section = ensm.getKey(); + ensm.getValue().entrySet().forEach( + ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); + }); + } - public void clear() { - this.storage.clear(); - } + public void clear() { + this.storage.clear(); + } - public void load(final Path inputFile) { - final JsonParser p = new JsonParser(); - JsonElement parsed = null; + public void load(final Path inputFile) { + final JsonParser p = new JsonParser(); + JsonElement parsed = null; - try (BufferedReader r = Files.newBufferedReader(inputFile)) { - parsed = p.parse(r); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading presets from" + inputFile.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (final JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "JSON Parsing Error in " + inputFile.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } + try (BufferedReader r = Files.newBufferedReader(inputFile)) { + parsed = p.parse(r); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading presets from" + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch (final JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } - if (parsed != null) { - parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { - final String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream().forEach( - sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); - }); - } - } + if (parsed != null) { + parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { + final String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream().forEach( + sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); + }); + } + } - public JsonElement get(final String asString) { - final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); - final Matcher m = p.matcher(asString); - if (m.matches()) { - return this.getSymbolSection(m.group(1), m.group(2)); - } - return new JsonPrimitive("Unknown Variable " + asString); - } + public JsonElement get(final String asString) { + final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); + final Matcher m = p.matcher(asString); + if (m.matches()) { + return this.getSymbolSection(m.group(1), m.group(2)); + } + return new JsonPrimitive("Unknown Variable " + asString); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index a78868d7..14361973 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -41,198 +41,198 @@ public class ReplacementsRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() - .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... - .create(); - - public ReplacementsRegistry() { - // - } - - public Map getReplacements() { - return ImmutableMap.copyOf(registry.getEntries()); - } - - /** - * - * @param dimension - * @return - * @deprecated - */ - @Deprecated - public List getDimensionDefault(final int dimension) { - final String[] names = { - "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" - }; - final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() - .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) - .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) - .collect(Collectors.toList()); - final List baseRv = new ArrayList<>(); - baseRv.addAll(mineralogyOres); - - if (dimension < -1 || dimension > 1 || dimension == 0) { - for (final ItemStack iS : OreDictionary.getOres("stone")) { - baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); - } - - return baseRv; - } - - baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS - .getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); - return baseRv; - } - - public IReplacementEntry getReplacement(final String name) { - final ResourceLocation act = new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name)); - - if (registry.containsKey(act)) { - return registry.getValue(act); - } else { - return registry.getValue(new ResourceLocation("orespawn:default")); - } - } - - public void addBlock(final String name, final String blockName, final String blockState) { - final IBlockState b = StateUtil.deserializeState( - ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); - addBlock(name, b); - } - - public Map> getBlocks() { - final Map> tempMap = new TreeMap<>(); - registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); - - return Collections.unmodifiableMap(tempMap); - } - - public void addReplacement(final IReplacementEntry replacement) { - registry.register(replacement); - } - - public void addBlock(final String name, final IBlockState state) { - ResourceLocation regName = new ResourceLocation(name); - if (registry.containsKey(regName)) { - final IReplacementEntry old = registry.getValue(regName); - IReplacementEntry newRE; - List oldList = old.getEntries(); - oldList.add(state); - newRE = new ReplacementEntry(name, oldList); - registry.remove(regName); - newRE.setRegistryName(regName); - registry.register(newRE); - return; - } - - final IReplacementEntry r = new ReplacementEntry(name, state); - registry.register(r); - } - - @SuppressWarnings("deprecation") - public void loadFile(final Path file) { - final JsonParser parser = new JsonParser(); - JsonObject elements; - String rawJson; - - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); - - try { - rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + file.getFileName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return; - } - - elements = parser.parse(rawJson).getAsJsonObject(); - elements.entrySet().stream().forEach(elem -> { - final String entName = elem.getKey(); - final JsonArray entries = elem.getValue().getAsJsonArray(); - final List blocks = new LinkedList<>(); - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); - for (final JsonElement e : entries) { - final JsonObject asObj = e.getAsJsonObject(); - final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() - .toLowerCase(); - - // is this an OreDictionary entry ? - if (blockName.startsWith("ore:")) { - // yes, it is - final String oreDictName = blockName.split(":")[1]; - OreDictionary.getOres(oreDictName).forEach(iS -> { - if (iS.getMetadata() != 0) { - blocks.add(Block.getBlockFromItem(iS.getItem()) - .getStateFromMeta(iS.getMetadata())); - } else { - blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); - } - }); - } else { - String state = null; - final ResourceLocation blockRL = new ResourceLocation(blockName); - final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); - if (asObj.has(Constants.ConfigNames.METADATA)) { - // has metadata - final int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); - blocks.add(theBlock.getStateFromMeta(meta)); - } else if (asObj.has(Constants.ConfigNames.STATE)) { - // has a state - state = asObj.get(Constants.ConfigNames.STATE).getAsString(); - blocks.add(StateUtil.deserializeState(theBlock, state)); - } else { - // use the default state - blocks.add(theBlock.getDefaultState()); - } - } - } - - final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); - registry.register(replacer); - }); - } - - public void saveFile(final String modName) { - final JsonObject outs = new JsonObject(); - - registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) - .forEach(ent -> { - final JsonArray entry = new JsonArray(); - final IReplacementEntry workVal = ent.getValue(); - workVal.getEntries().stream().forEach(bs -> { - final JsonObject block = new JsonObject(); - block.addProperty(Constants.ConfigNames.BLOCK, - bs.getBlock().getRegistryName().toString()); - if (!bs.toString().matches("\\[normal\\]")) { - block.addProperty(Constants.ConfigNames.STATE, - bs.toString().replaceAll("[\\[\\]]", "")); - } - entry.add(block); - }); - outs.add(ent.getKey().toString(), entry); - }); - final Path p = Paths.get("config", "orespawn3", "sysconfig", - String.format("replacements-%s.json", modName)); - try (final BufferedWriter w = Files.newBufferedWriter(p)) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final String ov = gson.toJson(outs); - w.write(ov); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, String - .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - public boolean has(final ResourceLocation resourceLocation) { - return registry.containsKey(resourceLocation); - } + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() + .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... + .create(); + + public ReplacementsRegistry() { + // + } + + public Map getReplacements() { + return ImmutableMap.copyOf(registry.getEntries()); + } + + /** + * + * @param dimension + * @return + * @deprecated + */ + @Deprecated + public List getDimensionDefault(final int dimension) { + final String[] names = { + "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" + }; + final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() + .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) + .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) + .collect(Collectors.toList()); + final List baseRv = new ArrayList<>(); + baseRv.addAll(mineralogyOres); + + if (dimension < -1 || dimension > 1 || dimension == 0) { + for (final ItemStack iS : OreDictionary.getOres("stone")) { + baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); + } + + return baseRv; + } + + baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS + .getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); + return baseRv; + } + + public IReplacementEntry getReplacement(final String name) { + final ResourceLocation act = new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name)); + + if (registry.containsKey(act)) { + return registry.getValue(act); + } else { + return registry.getValue(new ResourceLocation("orespawn:default")); + } + } + + public void addBlock(final String name, final String blockName, final String blockState) { + final IBlockState b = StateUtil.deserializeState( + ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + addBlock(name, b); + } + + public Map> getBlocks() { + final Map> tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); + + return Collections.unmodifiableMap(tempMap); + } + + public void addReplacement(final IReplacementEntry replacement) { + registry.register(replacement); + } + + public void addBlock(final String name, final IBlockState state) { + ResourceLocation regName = new ResourceLocation(name); + if (registry.containsKey(regName)) { + final IReplacementEntry old = registry.getValue(regName); + IReplacementEntry newRE; + List oldList = old.getEntries(); + oldList.add(state); + newRE = new ReplacementEntry(name, oldList); + registry.remove(regName); + newRE.setRegistryName(regName); + registry.register(newRE); + return; + } + + final IReplacementEntry r = new ReplacementEntry(name, state); + registry.register(r); + } + + @SuppressWarnings("deprecation") + public void loadFile(final Path file) { + final JsonParser parser = new JsonParser(); + JsonObject elements; + String rawJson; + + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); + + try { + rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getFileName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return; + } + + elements = parser.parse(rawJson).getAsJsonObject(); + elements.entrySet().stream().forEach(elem -> { + final String entName = elem.getKey(); + final JsonArray entries = elem.getValue().getAsJsonArray(); + final List blocks = new LinkedList<>(); + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); + for (final JsonElement e : entries) { + final JsonObject asObj = e.getAsJsonObject(); + final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() + .toLowerCase(); + + // is this an OreDictionary entry ? + if (blockName.startsWith("ore:")) { + // yes, it is + final String oreDictName = blockName.split(":")[1]; + OreDictionary.getOres(oreDictName).forEach(iS -> { + if (iS.getMetadata() != 0) { + blocks.add(Block.getBlockFromItem(iS.getItem()) + .getStateFromMeta(iS.getMetadata())); + } else { + blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); + } + }); + } else { + String state = null; + final ResourceLocation blockRL = new ResourceLocation(blockName); + final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); + if (asObj.has(Constants.ConfigNames.METADATA)) { + // has metadata + final int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); + blocks.add(theBlock.getStateFromMeta(meta)); + } else if (asObj.has(Constants.ConfigNames.STATE)) { + // has a state + state = asObj.get(Constants.ConfigNames.STATE).getAsString(); + blocks.add(StateUtil.deserializeState(theBlock, state)); + } else { + // use the default state + blocks.add(theBlock.getDefaultState()); + } + } + } + + final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); + registry.register(replacer); + }); + } + + public void saveFile(final String modName) { + final JsonObject outs = new JsonObject(); + + registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) + .forEach(ent -> { + final JsonArray entry = new JsonArray(); + final IReplacementEntry workVal = ent.getValue(); + workVal.getEntries().stream().forEach(bs -> { + final JsonObject block = new JsonObject(); + block.addProperty(Constants.ConfigNames.BLOCK, + bs.getBlock().getRegistryName().toString()); + if (!bs.toString().matches("\\[normal\\]")) { + block.addProperty(Constants.ConfigNames.STATE, + bs.toString().replaceAll("[\\[\\]]", "")); + } + entry.add(block); + }); + outs.add(ent.getKey().toString(), entry); + }); + final Path p = Paths.get("config", "orespawn3", "sysconfig", + String.format("replacements-%s.json", modName)); + try (final BufferedWriter w = Files.newBufferedWriter(p)) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String ov = gson.toJson(outs); + w.write(ov); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, String + .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + public boolean has(final ResourceLocation resourceLocation) { + return registry.containsKey(resourceLocation); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java index e04934b2..b9f36c90 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java +++ b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java @@ -7,10 +7,10 @@ @OreSpawnPlugin(modid = "orespawn", resourcePath = "configs") public class VanillaOres implements IOreSpawnPlugin { - @Override - public void register(final OS3API apiInterface) { - // nothing for us to do - all of our ores are in the - // jar and the code handles that - } + @Override + public void register(final OS3API apiInterface) { + // nothing for us to do - all of our ores are in the + // jar and the code handles that + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index ce423979..588091f0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -19,177 +19,177 @@ public class ClusterGenerator extends FeatureBase implements IFeature { - private ClusterGenerator(final Random rand) { - super(rand); - } + private ClusterGenerator(final Random rand) { + super(rand); + } - public ClusterGenerator() { - this(new Random()); - } + public ClusterGenerator() { + this(new Random()); + } - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; - mergeDefaults(params, getDefaultParameters()); + mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, spawnData); + runCache(chunkX, chunkZ, world, spawnData); - // now to ore spawn + // now to ore spawn - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; - final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); - - int tries; + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); + + int tries; - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - while (tries > 0) { - if (this.random.nextInt(100) <= frequency) { - final int xRand = random.nextInt(16); - final int zRand = random.nextInt(16); - - final int x = blockX + xRand - (maxSpread / 2); - final int y = random.nextInt(maxHeight - minHeight) + minHeight; - final int z = blockZ + zRand - (maxSpread / 2); - - spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, - spawnData, world, new BlockPos(x, y, z)); - } - - tries--; - } - } - - private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, - final int maxSpread, final int minHeight, final int maxHeight, - final ISpawnEntry spawnData, final World world, final BlockPos pos) { - // spawn a cluster at the center, then a bunch around the outside... - int r = clusterSize - variance; - - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; - } - - spawnChunk(world, pos, spawnData, r); - - int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary - // inside that - - if (variance > 0) { - count += this.random.nextInt(2 * variance) - variance; - } - - while (count >= 0) { - r = clusterSize - variance; - - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; - } - - final int radius = maxSpread / 2; - - final int xp = getPoint(-radius, radius, 0); - final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - final int zp = getPoint(-radius, radius, 0); - - final BlockPos p = pos.add(xp, yp, zp); - spawnChunk(world, p, spawnData, r); - - count -= r; - } - } - - private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - final int dimension = world.provider.getDimension(); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - int z = 0; - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - - if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, - spawnData)) { - count++; - z++; - } else { - z = 0; - } - - if (z > 5) { - count--; - z = 0; - OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); - } - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, - final ISpawnEntry spawnData, final World world, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); - defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); - defParams.addProperty(Constants.FormatBits.VARIATION, 4); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); - return defParams; - } + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + while (tries > 0) { + if (this.random.nextInt(100) <= frequency) { + final int xRand = random.nextInt(16); + final int zRand = random.nextInt(16); + + final int x = blockX + xRand - (maxSpread / 2); + final int y = random.nextInt(maxHeight - minHeight) + minHeight; + final int z = blockZ + zRand - (maxSpread / 2); + + spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, + spawnData, world, new BlockPos(x, y, z)); + } + + tries--; + } + } + + private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, + final int maxSpread, final int minHeight, final int maxHeight, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { + // spawn a cluster at the center, then a bunch around the outside... + int r = clusterSize - variance; + + if (variance > 0) { + r += this.random.nextInt(2 * variance) - variance; + } + + spawnChunk(world, pos, spawnData, r); + + int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary + // inside that + + if (variance > 0) { + count += this.random.nextInt(2 * variance) - variance; + } + + while (count >= 0) { + r = clusterSize - variance; + + if (variance > 0) { + r += this.random.nextInt(2 * variance) - variance; + } + + final int radius = maxSpread / 2; + + final int xp = getPoint(-radius, radius, 0); + final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + final int zp = getPoint(-radius, radius, 0); + + final BlockPos p = pos.add(xp, yp, zp); + spawnChunk(world, p, spawnData, r); + + count -= r; + } + } + + private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + final int dimension = world.provider.getDimension(); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + int z = 0; + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData)) { + count++; + z++; + } else { + z = 0; + } + + if (z > 5) { + count--; + z = 0; + OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); + } + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); + defParams.addProperty(Constants.FormatBits.VARIATION, 4); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); + return defParams; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index fbc9d734..5f26bfb9 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -18,119 +18,119 @@ public class DefaultFeatureGenerator extends FeatureBase implements IFeature { - public DefaultFeatureGenerator() { - super(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // now to ore spawn - - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; - - final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); - final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - - if (freq >= 1) { - for (int i = 0; i < freq; i++) { - final int x = blockX + random.nextInt(16); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(16); - - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); - } - } else if (random.nextFloat() < freq) { - final int x = blockX + random.nextInt(8); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(8); - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); - } - - } - - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - final BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, - final ISpawnEntry spawnData, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); - defParams.addProperty(Constants.FormatBits.VARIATION, 16); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 0.5); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); - return defParams; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } + public DefaultFeatureGenerator() { + super(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); + final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + + if (freq >= 1) { + for (int i = 0; i < freq; i++) { + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); + + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); + } + } else if (random.nextFloat() < freq) { + final int x = blockX + random.nextInt(8); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(8); + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); + } + + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 0.5); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + return defParams; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 6d6d1cf1..6e0f6833 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -17,166 +17,166 @@ public class NormalCloudGenerator extends FeatureBase implements IFeature { - private NormalCloudGenerator(final Random rand) { - super(rand); - } - - public NormalCloudGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // now to ore spawn - - // lets not offset blind, - final int blockX = chunkX * 16; - final int blockZ = chunkZ * 16; - - final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); - final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - - // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get - // a size that will let us insert by the radius - final int offsetXZ = 32 - maxSpread; - - // you have the distance between minHeight and maxHeight - // this is the actual size of the space - final int sizeY = (maxHeight - minHeight); - final int offsetY = sizeY - maxSpread; - final int radiusXZ = offsetXZ / 2; - - // actual radius for placement is the size minus the spread to center it in the space and - // keep - // from overflowing - final int radiusY = offsetY / 2; - - // we center at the minimum plus the half the height - final int blockY = minHeight + (sizeY / 2); - - final int fSave = frequency; - int tryCount = 0; - - int tries; - - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - while (tries > 0) { - if (this.random.nextInt(100) <= frequency) { - frequency = fSave; - final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; - // this should, hopefully, keep us centered between minHeight and maxHeight with - // nothing going above/below those values - final int y = blockY + getPoint(0, offsetY, radiusY); - final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; - - int r = medianSize - variance; - - if (variance > 0) { - r += random.nextInt(2 * variance) - variance; - } - - final BlockPos p = new BlockPos(x, y, z); - - if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) - && tryCount < 5) { - // make another try! - tries++; - frequency = 100; - tryCount++; - } else { - tryCount = 0; - } - } - - tries--; - } - } - - private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, - final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, - final World world) { - // spawn one right at the center here, then generate for the cloud and do the math - - if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, - world.provider.getDimension(), true, spawnData)) { - return false; - } - - final int radius = maxSpread / 2; - boolean alreadySpewed = false; - int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); - - while (count > 0) { - int xp = getPoint(0, maxSpread, radius); - int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - int zp = getPoint(0, maxSpread, radius); - - BlockPos p = pos.add(xp, yp, zp); - - int z = 0; - - while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, - world.provider.getDimension(), true, spawnData)) { - xp = getPoint(0, maxSpread, radius); - yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - zp = getPoint(0, maxSpread, radius); - - p = pos.add(xp, yp, zp); - - z++; - } - - if (z >= 5 && !alreadySpewed) { - OreSpawn.LOGGER.info( - "unable to achieve requested cloud density for cloud centered at %s", pos); - alreadySpewed = true; - } - - count--; - } - - return true; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); - defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); - defParams.addProperty(Constants.FormatBits.VARIATION, 4); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); - return defParams; - } + private NormalCloudGenerator(final Random rand) { + super(rand); + } + + public NormalCloudGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + // lets not offset blind, + final int blockX = chunkX * 16; + final int blockZ = chunkZ * 16; + + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + + // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get + // a size that will let us insert by the radius + final int offsetXZ = 32 - maxSpread; + + // you have the distance between minHeight and maxHeight + // this is the actual size of the space + final int sizeY = (maxHeight - minHeight); + final int offsetY = sizeY - maxSpread; + final int radiusXZ = offsetXZ / 2; + + // actual radius for placement is the size minus the spread to center it in the space and + // keep + // from overflowing + final int radiusY = offsetY / 2; + + // we center at the minimum plus the half the height + final int blockY = minHeight + (sizeY / 2); + + final int fSave = frequency; + int tryCount = 0; + + int tries; + + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + while (tries > 0) { + if (this.random.nextInt(100) <= frequency) { + frequency = fSave; + final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + // this should, hopefully, keep us centered between minHeight and maxHeight with + // nothing going above/below those values + final int y = blockY + getPoint(0, offsetY, radiusY); + final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + + int r = medianSize - variance; + + if (variance > 0) { + r += random.nextInt(2 * variance) - variance; + } + + final BlockPos p = new BlockPos(x, y, z); + + if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) + && tryCount < 5) { + // make another try! + tries++; + frequency = 100; + tryCount++; + } else { + tryCount = 0; + } + } + + tries--; + } + } + + private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, + final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, + final World world) { + // spawn one right at the center here, then generate for the cloud and do the math + + if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, + world.provider.getDimension(), true, spawnData)) { + return false; + } + + final int radius = maxSpread / 2; + boolean alreadySpewed = false; + int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); + + while (count > 0) { + int xp = getPoint(0, maxSpread, radius); + int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + int zp = getPoint(0, maxSpread, radius); + + BlockPos p = pos.add(xp, yp, zp); + + int z = 0; + + while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, + world.provider.getDimension(), true, spawnData)) { + xp = getPoint(0, maxSpread, radius); + yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + zp = getPoint(0, maxSpread, radius); + + p = pos.add(xp, yp, zp); + + z++; + } + + if (z >= 5 && !alreadySpewed) { + OreSpawn.LOGGER.info( + "unable to achieve requested cloud density for cloud centered at %s", pos); + alreadySpewed = true; + } + + count--; + } + + return true; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); + defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); + defParams.addProperty(Constants.FormatBits.VARIATION, 4); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); + return defParams; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 50faca25..3e720f28 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -20,279 +20,279 @@ public class PrecisionGenerator extends FeatureBase implements IFeature { - private PrecisionGenerator(final Random rand) { - super(rand); - } - - public PrecisionGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // extract parameters - final int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); - final int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); - final int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); - final int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); - - int thisNode = nodeSize; - - // now to use them - for (int c = nodeCount; c > 0; c--) { - int sc; - final HeightRange hr = new HeightRange(minHeight, maxHeight); - final BlockPos spot = chooseSpot(chunkX, chunkZ, hr); - - sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); - - // bit of feedback - if we underproduce or overproduce a node, the next one gets a - // correction - if (sc != thisNode && sc != 0) { - thisNode += (nodeSize - sc); - } else if (sc == thisNode) { - // if we produced exact size, reset the size - thisNode = nodeSize; - } - - // if we hit a node of size zero or less, we've done something wrong - if (thisNode <= 0) { - thisNode = nodeSize; - } - } - } - - private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, - final ChunkPos pos, final ISpawnEntry spawnData, final World world) { - int spawned = 0; - int c; - - BlockPos act = spot; - int counter = nodeSize; - - while (counter > 0 && spawned < nodeSize) { - c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); - - if (c == 0) { - act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), - heightRange); - } - - counter -= (c + 1); - spawned += c; - } - - return spawned; - } - - private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, - final World world, final int nodeSize, final HeightRange heightRange) { - - int count = nodeSize; - final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((nodeSize < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (nodeSize < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - int nc = 0; - - for (; count > 0 && nc <= nodeSize; count--) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); - final Vec3i offset = offs[scrambledLUT[--count]]; - final BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); - final int dimension = world.provider.getDimension(); - - if (spawn(oreBlock, world, p, dimension, true, spawnData)) { - nc++; - } - } - - return nc; - } - - return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); - } - - private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, - final HeightRange heightRange, final ChunkPos pos) { - final BlockPos p = spot.add(offset); - final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); - final int xMax = x1z1.getXEnd(); - final int zMax = x1z1.getZEnd(); - final int xMin = pos.getXStart(); - final int zMin = pos.getZStart(); - - int xmod = offset.getX(); - int ymod = offset.getY(); - int zmod = offset.getZ(); - - // correct the points values to not cause the Y coordinate to go outside the permissable - // range - if (p.getY() < heightRange.getMin() || p.getY() > heightRange.getMax()) { - ymod = rescaleOffset(ymod, spot.getY(), heightRange.getMin(), heightRange.getMax()); - } - - if (p.getX() < xMin || p.getX() > xMax) { - xmod = rescaleOffset(xmod, spot.getX(), xMin, xMax); - } - - if (p.getZ() < zMin || p.getZ() > zMax) { - zmod = rescaleOffset(zmod, spot.getZ(), zMin, zMax); - } - - return spot.add(xmod, ymod, zmod); - } - - private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, - final int maximumIn) { - final int actual = centerIn + offsetIn; - int wrapDistance; - final int range = maximumIn - minimumIn; - int workingPoint; - - if (actual < minimumIn) { - wrapDistance = minimumIn - actual; - } else { - wrapDistance = actual - maximumIn; - } - - if (wrapDistance < 0) { - wrapDistance = ((-1) * wrapDistance) % range; - } else { - wrapDistance %= range; - } - - if (actual < minimumIn) { - workingPoint = maximumIn - wrapDistance; - } else { - workingPoint = minimumIn + wrapDistance; - } - - return workingPoint - centerIn; - } - - private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, - final BlockPos loc, final int nodeSize, final HeightRange heightRange) { - - final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) Math.ceil(radius * radius); - - if (this.random.nextBoolean()) { - return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, - nodeSize); - } else { - return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, - nodeSize); - } - } - - private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, - final BlockPos loc, final HeightRange heightRange, final boolean toPositive, - final double radius, final int rSqr, final int nodeSize) { - int quantity = nodeSize; - int nc = 0; - - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, - radius); dx = countItem(dx, toPositive)) { - for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, - radius); dz = countItem(dz, toPositive)) { - if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, - loc) >= 0) { - nc++; - quantity--; - - if (nc >= nodeSize || quantity <= 0) { - return nc; - } - } - } - } - } - - return nc; - } - - private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, - final HeightRange heightRange, final ISpawnEntry spawnData, final World world, - final ChunkPos pos, final BlockPos loc) { - if (getABC(dx, dy, dz) <= rSqr) { - final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); - final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); - return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; - } - - return -1; - } - - private int getPoint(final int lowerBound, final int upperBound) { - final List arr = new ArrayList<>(); - - for (int i = lowerBound; i <= upperBound; i++) { - arr.add(i); - } - - return arr.get(this.random.nextInt(arr.size())); - } - - private BlockPos chooseSpot(final int xPosition, final int zPosition, - final HeightRange heightRange) { - final int xRet = getPoint(0, 15) + (xPosition * 16); - final int zRet = getPoint(0, 15) + (zPosition * 16); - final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); - - return new BlockPos(xRet, yRet, zRet); - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defaults = new JsonObject(); - defaults.addProperty(FormatBits.NODE_COUNT, 4); - defaults.addProperty(FormatBits.MIN_HEIGHT, 16); - defaults.addProperty(FormatBits.MAX_HEIGHT, 80); - defaults.addProperty(FormatBits.NODE_SIZE, 8); - return defaults; - } - - private class HeightRange { - - private int min; - private int max; - - HeightRange(final int min, final int max) { - this.min = min; - this.max = max; - } - - int getMin() { - return this.min; - } - - int getMax() { - return this.max; - } - } + private PrecisionGenerator(final Random rand) { + super(rand); + } + + public PrecisionGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // extract parameters + final int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); + final int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); + final int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); + final int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); + + int thisNode = nodeSize; + + // now to use them + for (int c = nodeCount; c > 0; c--) { + int sc; + final HeightRange hr = new HeightRange(minHeight, maxHeight); + final BlockPos spot = chooseSpot(chunkX, chunkZ, hr); + + sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); + + // bit of feedback - if we underproduce or overproduce a node, the next one gets a + // correction + if (sc != thisNode && sc != 0) { + thisNode += (nodeSize - sc); + } else if (sc == thisNode) { + // if we produced exact size, reset the size + thisNode = nodeSize; + } + + // if we hit a node of size zero or less, we've done something wrong + if (thisNode <= 0) { + thisNode = nodeSize; + } + } + } + + private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, + final ChunkPos pos, final ISpawnEntry spawnData, final World world) { + int spawned = 0; + int c; + + BlockPos act = spot; + int counter = nodeSize; + + while (counter > 0 && spawned < nodeSize) { + c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); + + if (c == 0) { + act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), + heightRange); + } + + counter -= (c + 1); + spawned += c; + } + + return spawned; + } + + private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, + final World world, final int nodeSize, final HeightRange heightRange) { + + int count = nodeSize; + final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((nodeSize < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (nodeSize < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + int nc = 0; + + for (; count > 0 && nc <= nodeSize; count--) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); + final Vec3i offset = offs[scrambledLUT[--count]]; + final BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); + final int dimension = world.provider.getDimension(); + + if (spawn(oreBlock, world, p, dimension, true, spawnData)) { + nc++; + } + } + + return nc; + } + + return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); + } + + private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, + final HeightRange heightRange, final ChunkPos pos) { + final BlockPos p = spot.add(offset); + final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); + final int xMax = x1z1.getXEnd(); + final int zMax = x1z1.getZEnd(); + final int xMin = pos.getXStart(); + final int zMin = pos.getZStart(); + + int xmod = offset.getX(); + int ymod = offset.getY(); + int zmod = offset.getZ(); + + // correct the points values to not cause the Y coordinate to go outside the permissable + // range + if (p.getY() < heightRange.getMin() || p.getY() > heightRange.getMax()) { + ymod = rescaleOffset(ymod, spot.getY(), heightRange.getMin(), heightRange.getMax()); + } + + if (p.getX() < xMin || p.getX() > xMax) { + xmod = rescaleOffset(xmod, spot.getX(), xMin, xMax); + } + + if (p.getZ() < zMin || p.getZ() > zMax) { + zmod = rescaleOffset(zmod, spot.getZ(), zMin, zMax); + } + + return spot.add(xmod, ymod, zmod); + } + + private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, + final int maximumIn) { + final int actual = centerIn + offsetIn; + int wrapDistance; + final int range = maximumIn - minimumIn; + int workingPoint; + + if (actual < minimumIn) { + wrapDistance = minimumIn - actual; + } else { + wrapDistance = actual - maximumIn; + } + + if (wrapDistance < 0) { + wrapDistance = ((-1) * wrapDistance) % range; + } else { + wrapDistance %= range; + } + + if (actual < minimumIn) { + workingPoint = maximumIn - wrapDistance; + } else { + workingPoint = minimumIn + wrapDistance; + } + + return workingPoint - centerIn; + } + + private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final int nodeSize, final HeightRange heightRange) { + + final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) Math.ceil(radius * radius); + + if (this.random.nextBoolean()) { + return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, + nodeSize); + } else { + return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, + nodeSize); + } + } + + private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final HeightRange heightRange, final boolean toPositive, + final double radius, final int rSqr, final int nodeSize) { + int quantity = nodeSize; + int nc = 0; + + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, + radius); dx = countItem(dx, toPositive)) { + for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, + radius); dz = countItem(dz, toPositive)) { + if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, + loc) >= 0) { + nc++; + quantity--; + + if (nc >= nodeSize || quantity <= 0) { + return nc; + } + } + } + } + } + + return nc; + } + + private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, + final HeightRange heightRange, final ISpawnEntry spawnData, final World world, + final ChunkPos pos, final BlockPos loc) { + if (getABC(dx, dy, dz) <= rSqr) { + final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); + final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); + return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; + } + + return -1; + } + + private int getPoint(final int lowerBound, final int upperBound) { + final List arr = new ArrayList<>(); + + for (int i = lowerBound; i <= upperBound; i++) { + arr.add(i); + } + + return arr.get(this.random.nextInt(arr.size())); + } + + private BlockPos chooseSpot(final int xPosition, final int zPosition, + final HeightRange heightRange) { + final int xRet = getPoint(0, 15) + (xPosition * 16); + final int zRet = getPoint(0, 15) + (zPosition * 16); + final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); + + return new BlockPos(xRet, yRet, zRet); + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defaults = new JsonObject(); + defaults.addProperty(FormatBits.NODE_COUNT, 4); + defaults.addProperty(FormatBits.MIN_HEIGHT, 16); + defaults.addProperty(FormatBits.MAX_HEIGHT, 80); + defaults.addProperty(FormatBits.NODE_SIZE, 8); + return defaults; + } + + private class HeightRange { + + private int min; + private int max; + + HeightRange(final int min, final int max) { + this.min = min; + this.max = max; + } + + int getMin() { + return this.min; + } + + int getMax() { + return this.max; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index ec2a1292..d77e200a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -25,558 +25,558 @@ public class VeinGenerator extends FeatureBase implements IFeature { - private VeinGenerator(final Random rand) { - super(rand); - } - - public VeinGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - runCache(chunkX, chunkZ, world, spawnData); - mergeDefaults(params, getDefaultParameters()); - - // now to ore spawn - - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; - - final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - final EnumFacing startingFace = getFaceFromString( - params.get(Constants.FormatBits.STARTINGFACE).getAsString()); - final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - - int tries; - - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - // we have an offset into the chunk but actually need something more - while (tries > 0) { - if (this.random.nextInt(100) <= freq) { - final int x = blockX + random.nextInt(16); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(16); - - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, - world); - } - - tries--; - } - } - - private EnumFacing getFaceFromString(final String direction) { - final String work = direction.toLowerCase(); - switch (work) { - case "north": - return EnumFacing.NORTH; - case "south": - return EnumFacing.SOUTH; - case "east": - return EnumFacing.EAST; - case "west": - return EnumFacing.WEST; - case "down": - return EnumFacing.DOWN; - case "up": - return EnumFacing.UP; - case "random": - return EnumFacing.VALUES[this.random.nextInt(EnumFacing.VALUES.length)]; - case "vertical": - return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; - case "horizontal": - return EnumFacing.HORIZONTALS[this.random.nextInt(EnumFacing.HORIZONTALS.length)]; - default: - OreSpawn.LOGGER.error( - "Invalid value %s found in parameters for vein spawn, returning \"north\"", - direction); - return EnumFacing.NORTH; - } - } - - private enum EnumSquare { - TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), - RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); - - private int index; - - private EnumSquare(int index) { - this.index = index; - } - - final public int getIndex() { - return this.index; - } - } - - private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, - final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { - EnumFacing face = startingFace; - EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; - BlockPos workingPos = new BlockPos(blockPos); - - if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { - return; - } - - // build vein - final List points = Lists.newLinkedList(); - for (; points.size() < veinLength;) { - points.add(workingPos); - List nextFaces = getNextFaceSet(square, face); - - if (!nextFaces.isEmpty()) { - BlockPos temp = workingPos; - for (EnumFacing f : nextFaces) { - temp = temp.offset(f, 1); - } - nextFaces.clear(); - points.add(temp); - workingPos = temp; - } - - face = getNextStartingFace(square, face); - square = getNextSquare(); - } - - spawnOre(world, spawnData, blockPos, nodeSize); - for (final BlockPos pos : points) { - spawnOre(world, spawnData, pos, nodeSize); - } - } - - private class SquareWeight extends WeightedRandom.Item { - - public EnumSquare item; - - public SquareWeight(EnumSquare item, int weight) { - super(weight); - this.item = item; - } - } - - private EnumSquare getNextSquare() { - float[] weights = new float[] { - 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f - }; - List items = new ArrayList<>(); - - for (EnumSquare sq : EnumSquare.values()) { - items.add(new SquareWeight(sq, (int) (weights[sq.getIndex()] * 10000))); - } - - return ((SquareWeight) WeightedRandom.getRandomItem(this.random, items)).item; - } - - private static final EnumFacing[][][] congruentSquares = new EnumFacing[][][] { - // Index 0 - DOWN - new EnumFacing[][] { - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.NORTH, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 1 - UP - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.NORTH, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 2 - NORTH - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 3 - SOUTH - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.EAST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.EAST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.WEST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.WEST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 4 - WEST - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.SOUTH - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.SOUTH - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.NORTH - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.NORTH - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 5 - EAST - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.NORTH - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.NORTH - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.SOUTH - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.SOUTH - } // RIGHT_TOP - } - }; - - private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { - - if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { - return face; - } - - EnumFacing[] possibles = Arrays.asList(congruentSquares[face.getIndex()][square.getIndex()]) - .stream().filter(it -> it != null).toArray(EnumFacing[]::new); - - if (possibles.length > 1) { - return possibles[this.random.nextInt(possibles.length)]; - } - return possibles[0]; - } - - private List getNextFaceSet(EnumSquare square, EnumFacing face) { - List rv = new ArrayList<>(); - - rv.add(face); - - switch (square) { - case BOTTOM_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - case TOP_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case LEFT_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - break; - default: - break; - } - break; - case RIGHT_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - break; - case UP: - case DOWN: - rv.add(EnumFacing.WEST); - break; - default: - break; - } - break; - case FACE: - break; - case LEFT_TOP: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case LEFT_BOTTOM: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - case RIGHT_TOP: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case RIGHT_BOTTOM: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - default: - break; - } - - return rv; - } - - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - final BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, - final ISpawnEntry spawnData, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); - defParams.addProperty(Constants.FormatBits.VARIATION, 16); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 50); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.LENGTH, 16); - defParams.addProperty(Constants.FormatBits.STARTINGFACE, "north"); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3); - return defParams; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } + private VeinGenerator(final Random rand) { + super(rand); + } + + public VeinGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + runCache(chunkX, chunkZ, world, spawnData); + mergeDefaults(params, getDefaultParameters()); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); + final EnumFacing startingFace = getFaceFromString( + params.get(Constants.FormatBits.STARTINGFACE).getAsString()); + final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + + int tries; + + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + // we have an offset into the chunk but actually need something more + while (tries > 0) { + if (this.random.nextInt(100) <= freq) { + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); + + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, + world); + } + + tries--; + } + } + + private EnumFacing getFaceFromString(final String direction) { + final String work = direction.toLowerCase(); + switch (work) { + case "north": + return EnumFacing.NORTH; + case "south": + return EnumFacing.SOUTH; + case "east": + return EnumFacing.EAST; + case "west": + return EnumFacing.WEST; + case "down": + return EnumFacing.DOWN; + case "up": + return EnumFacing.UP; + case "random": + return EnumFacing.VALUES[this.random.nextInt(EnumFacing.VALUES.length)]; + case "vertical": + return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; + case "horizontal": + return EnumFacing.HORIZONTALS[this.random.nextInt(EnumFacing.HORIZONTALS.length)]; + default: + OreSpawn.LOGGER.error( + "Invalid value %s found in parameters for vein spawn, returning \"north\"", + direction); + return EnumFacing.NORTH; + } + } + + private enum EnumSquare { + TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), + RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); + + private int index; + + private EnumSquare(int index) { + this.index = index; + } + + final public int getIndex() { + return this.index; + } + } + + private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, + final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { + EnumFacing face = startingFace; + EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; + BlockPos workingPos = new BlockPos(blockPos); + + if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { + return; + } + + // build vein + final List points = Lists.newLinkedList(); + for (; points.size() < veinLength;) { + points.add(workingPos); + List nextFaces = getNextFaceSet(square, face); + + if (!nextFaces.isEmpty()) { + BlockPos temp = workingPos; + for (EnumFacing f : nextFaces) { + temp = temp.offset(f, 1); + } + nextFaces.clear(); + points.add(temp); + workingPos = temp; + } + + face = getNextStartingFace(square, face); + square = getNextSquare(); + } + + spawnOre(world, spawnData, blockPos, nodeSize); + for (final BlockPos pos : points) { + spawnOre(world, spawnData, pos, nodeSize); + } + } + + private class SquareWeight extends WeightedRandom.Item { + + public EnumSquare item; + + public SquareWeight(EnumSquare item, int weight) { + super(weight); + this.item = item; + } + } + + private EnumSquare getNextSquare() { + float[] weights = new float[] { + 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f + }; + List items = new ArrayList<>(); + + for (EnumSquare sq : EnumSquare.values()) { + items.add(new SquareWeight(sq, (int) (weights[sq.getIndex()] * 10000))); + } + + return ((SquareWeight) WeightedRandom.getRandomItem(this.random, items)).item; + } + + private static final EnumFacing[][][] congruentSquares = new EnumFacing[][][] { + // Index 0 - DOWN + new EnumFacing[][] { + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 1 - UP + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 2 - NORTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 3 - SOUTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 4 - WEST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 5 - EAST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + } // RIGHT_TOP + } + }; + + private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { + + if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { + return face; + } + + EnumFacing[] possibles = Arrays.asList(congruentSquares[face.getIndex()][square.getIndex()]) + .stream().filter(it -> it != null).toArray(EnumFacing[]::new); + + if (possibles.length > 1) { + return possibles[this.random.nextInt(possibles.length)]; + } + return possibles[0]; + } + + private List getNextFaceSet(EnumSquare square, EnumFacing face) { + List rv = new ArrayList<>(); + + rv.add(face); + + switch (square) { + case BOTTOM_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case TOP_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + break; + default: + break; + } + break; + case RIGHT_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.WEST); + break; + default: + break; + } + break; + case FACE: + break; + case LEFT_TOP: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_BOTTOM: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case RIGHT_TOP: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case RIGHT_BOTTOM: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + default: + break; + } + + return rv; + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 50); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.LENGTH, 16); + defParams.addProperty(Constants.FormatBits.STARTINGFACE, "north"); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3); + return defParams; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java index 057eacc0..7be8b101 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -10,16 +10,16 @@ public class BiomeLocationAcceptAny implements BiomeLocation { - @Override - public boolean matches(final Biome biome) { - return true; - } + @Override + public boolean matches(final Biome biome) { + return true; + } - @Override - public JsonElement serialize() { - final JsonObject rv = new JsonObject(); - rv.add(ConfigNames.BLACKLIST, new JsonArray()); - return rv; - } + @Override + public JsonElement serialize() { + final JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 4abce926..4dd291d6 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -14,73 +14,73 @@ public final class BiomeLocationComposition implements BiomeLocation { - private final BiomeLocation inclusions; - - private final BiomeLocation exclusions; - - private final int hash; - - public BiomeLocationComposition(final BiomeLocation inclusions, - final BiomeLocation exclusions) { - this.inclusions = inclusions; - this.exclusions = exclusions; - this.hash = Objects.hash(inclusions, exclusions); - } - - @Override - public boolean matches(final Biome biome) { - final boolean inWhite = this.inclusions.matches(biome); - final boolean inBlack = this.exclusions.matches(biome); - - return !inBlack && inWhite; - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - - if (obj instanceof BiomeLocationComposition) { - final BiomeLocationComposition other = (BiomeLocationComposition) obj; - return this.inclusions.equals(other.inclusions) - && this.exclusions.equals(other.exclusions); - } - - return false; - } - - @Override - public ImmutableList getBiomes() { - final List temp = new LinkedList<>(); - temp.addAll(this.inclusions.getBiomes()); - temp.addAll(this.exclusions.getBiomes()); - return ImmutableList.copyOf(temp); - } - - public BiomeLocation getInclusions() { - return this.inclusions; - } - - public BiomeLocation getExclusions() { - return this.exclusions; - } - - @Override - public JsonElement serialize() { - final JsonObject rv = new JsonObject(); - - rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); - if (!(this.inclusions instanceof BiomeLocationEmpty)) { - rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); - } - - return rv; - } + private final BiomeLocation inclusions; + + private final BiomeLocation exclusions; + + private final int hash; + + public BiomeLocationComposition(final BiomeLocation inclusions, + final BiomeLocation exclusions) { + this.inclusions = inclusions; + this.exclusions = exclusions; + this.hash = Objects.hash(inclusions, exclusions); + } + + @Override + public boolean matches(final Biome biome) { + final boolean inWhite = this.inclusions.matches(biome); + final boolean inBlack = this.exclusions.matches(biome); + + return !inBlack && inWhite; + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof BiomeLocationComposition) { + final BiomeLocationComposition other = (BiomeLocationComposition) obj; + return this.inclusions.equals(other.inclusions) + && this.exclusions.equals(other.exclusions); + } + + return false; + } + + @Override + public ImmutableList getBiomes() { + final List temp = new LinkedList<>(); + temp.addAll(this.inclusions.getBiomes()); + temp.addAll(this.exclusions.getBiomes()); + return ImmutableList.copyOf(temp); + } + + public BiomeLocation getInclusions() { + return this.inclusions; + } + + public BiomeLocation getExclusions() { + return this.exclusions; + } + + @Override + public JsonElement serialize() { + final JsonObject rv = new JsonObject(); + + rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); + if (!(this.inclusions instanceof BiomeLocationEmpty)) { + rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); + } + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java index d45d846e..f665118b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java @@ -10,42 +10,42 @@ public final class BiomeLocationDictionary implements BiomeLocation { - private final BiomeDictionary.Type type; - - private final int hash; - - public BiomeLocationDictionary(final BiomeDictionary.Type type) { - this.type = type; - this.hash = type.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return BiomeDictionary.hasType(biome, this.type); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationDictionary) - && this.type.equals(((BiomeLocationDictionary) obj).type)); - } - - public BiomeDictionary.Type getType() { - return this.type; - } - - @Override - public ImmutableList getBiomes() { - return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); - } - - @Override - public JsonElement serialize() { - return new JsonPrimitive(this.type.toString().toUpperCase()); - } + private final BiomeDictionary.Type type; + + private final int hash; + + public BiomeLocationDictionary(final BiomeDictionary.Type type) { + this.type = type; + this.hash = type.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return BiomeDictionary.hasType(biome, this.type); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationDictionary) + && this.type.equals(((BiomeLocationDictionary) obj).type)); + } + + public BiomeDictionary.Type getType() { + return this.type; + } + + @Override + public ImmutableList getBiomes() { + return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); + } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.type.toString().toUpperCase()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java index 44db55a7..fa2c3247 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -8,14 +8,14 @@ public class BiomeLocationEmpty implements BiomeLocation { - @Override - public boolean matches(final Biome biome) { - return false; - } + @Override + public boolean matches(final Biome biome) { + return false; + } - @Override - public JsonElement serialize() { - return new JsonArray(); - } + @Override + public JsonElement serialize() { + return new JsonArray(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index 56b34080..c8ccbc0c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -13,48 +13,48 @@ public final class BiomeLocationList implements BiomeLocation { - private final ImmutableSet locations; - - private final int hash; - - public BiomeLocationList(final ImmutableSet locations) { - this.locations = locations; - this.hash = locations.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return this.locations.stream().anyMatch(loc -> loc.matches(biome)); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationList) - && this.locations.equals(((BiomeLocationList) obj).locations)); - } - - @Override - public ImmutableList getBiomes() { - final List temp = new LinkedList<>(); - locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); - return ImmutableList.copyOf(temp); - } - - public ImmutableSet getLocations() { - return this.locations; - } - - @Override - public JsonElement serialize() { - final JsonArray rv = new JsonArray(); - this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) - .forEach(bl -> rv.add(bl.serialize())); - - return rv; - } + private final ImmutableSet locations; + + private final int hash; + + public BiomeLocationList(final ImmutableSet locations) { + this.locations = locations; + this.hash = locations.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return this.locations.stream().anyMatch(loc -> loc.matches(biome)); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationList) + && this.locations.equals(((BiomeLocationList) obj).locations)); + } + + @Override + public ImmutableList getBiomes() { + final List temp = new LinkedList<>(); + locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); + return ImmutableList.copyOf(temp); + } + + public ImmutableSet getLocations() { + return this.locations; + } + + @Override + public JsonElement serialize() { + final JsonArray rv = new JsonArray(); + this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) + .forEach(bl -> rv.add(bl.serialize())); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java index 0b862c70..6dfaa7ae 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java @@ -9,42 +9,42 @@ public final class BiomeLocationSingle implements BiomeLocation { - private final Biome biome; - - private final int hash; - - public BiomeLocationSingle(final Biome biome) { - this.biome = biome; - this.hash = biome.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return this.biome.equals(biome); - } - - @Override - public ImmutableList getBiomes() { - return ImmutableList.of(this.biome); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationSingle) - && this.biome.equals(((BiomeLocationSingle) obj).biome)); - } - - public Biome getBiome() { - return this.biome; - } - - @Override - public JsonElement serialize() { - return new JsonPrimitive(this.biome.getRegistryName().toString()); - } + private final Biome biome; + + private final int hash; + + public BiomeLocationSingle(final Biome biome) { + this.biome = biome; + this.hash = biome.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return this.biome.equals(biome); + } + + @Override + public ImmutableList getBiomes() { + return ImmutableList.of(this.biome); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationSingle) + && this.biome.equals(((BiomeLocationSingle) obj).biome)); + } + + public Biome getBiome() { + return this.biome; + } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.biome.getRegistryName().toString()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index b4db864f..91048e3e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -19,81 +19,81 @@ public class BiomeBuilder implements IBiomeBuilder { - private final List whitelist = new LinkedList<>(); - private final List blacklist = new LinkedList<>(); - - private boolean acceptAll = false; - - public BiomeBuilder() { - // - } - - @Override - public IBiomeBuilder addWhitelistEntry(final Biome biome) { - this.whitelist.add(biome); - return this; - } - - @Override - public IBiomeBuilder addWhitelistEntry(final String biomeName) { - return this.addWhitelistEntry(new ResourceLocation(biomeName)); - } - - @Override - public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { - return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); - } - - @Override - public IBiomeBuilder addBlacklistEntry(final Biome biome) { - this.blacklist.add(biome); - return this; - } - - @Override - public IBiomeBuilder addBlacklistEntry(final String biomeName) { - return this.addBlacklistEntry(new ResourceLocation(biomeName)); - } - - @Override - public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { - return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); - } - - @Override - public IBiomeBuilder setAcceptAll() { - this.acceptAll = true; - return this; - } - - @Override - public BiomeLocation create() { - if (this.acceptAll) { - return new BiomeLocationAcceptAny(); - } - - BiomeLocation whitelistI; - BiomeLocation blacklistI; - if (this.whitelist.isEmpty()) { - if (!this.blacklist.isEmpty()) { - whitelistI = new BiomeLocationAcceptAny(); - } else { - whitelistI = new BiomeLocationEmpty(); - } - } else { - whitelistI = new BiomeLocationList(ImmutableSet.copyOf( - this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) - .collect(Collectors.toList()))); - } - - if (this.blacklist.isEmpty()) { - blacklistI = new BiomeLocationEmpty(); - } else { - blacklistI = new BiomeLocationList(ImmutableSet.copyOf( - this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) - .collect(Collectors.toList()))); - } - - return new BiomeLocationComposition(whitelistI, blacklistI); - } + private final List whitelist = new LinkedList<>(); + private final List blacklist = new LinkedList<>(); + + private boolean acceptAll = false; + + public BiomeBuilder() { + // + } + + @Override + public IBiomeBuilder addWhitelistEntry(final Biome biome) { + this.whitelist.add(biome); + return this; + } + + @Override + public IBiomeBuilder addWhitelistEntry(final String biomeName) { + return this.addWhitelistEntry(new ResourceLocation(biomeName)); + } + + @Override + public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { + return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public IBiomeBuilder addBlacklistEntry(final Biome biome) { + this.blacklist.add(biome); + return this; + } + + @Override + public IBiomeBuilder addBlacklistEntry(final String biomeName) { + return this.addBlacklistEntry(new ResourceLocation(biomeName)); + } + + @Override + public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { + return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public IBiomeBuilder setAcceptAll() { + this.acceptAll = true; + return this; + } + + @Override + public BiomeLocation create() { + if (this.acceptAll) { + return new BiomeLocationAcceptAny(); + } + + BiomeLocation whitelistI; + BiomeLocation blacklistI; + if (this.whitelist.isEmpty()) { + if (!this.blacklist.isEmpty()) { + whitelistI = new BiomeLocationAcceptAny(); + } else { + whitelistI = new BiomeLocationEmpty(); + } + } else { + whitelistI = new BiomeLocationList(ImmutableSet.copyOf( + this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) + .collect(Collectors.toList()))); + } + + if (this.blacklist.isEmpty()) { + blacklistI = new BiomeLocationEmpty(); + } else { + blacklistI = new BiomeLocationList(ImmutableSet.copyOf( + this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) + .collect(Collectors.toList()))); + } + + return new BiomeLocationComposition(whitelistI, blacklistI); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index 9328c2e1..c1c76b47 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -11,162 +11,162 @@ public class BlockBuilder implements IBlockBuilder { - private IBlockState blockState; - private int chance; - private boolean isValid = true; - - public BlockBuilder() { - // nothing to do here - } - - @Override - public IBlockBuilder setFromBlockState(final IBlockState blockState) { - final ResourceLocation key = blockState.getBlock().getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockStateWithChance(blockState, 100); - } - - @Override - public IBlockBuilder setFromBlock(final Block block) { - final ResourceLocation key = block.getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockState(block.getDefaultState()); - } - - @Override - public IBlockBuilder setFromName(final String blockName) { - return this.setFromName(new ResourceLocation(blockName)); - } - - @Override - public IBlockBuilder setFromName(final String blockName, final String state) { - return this.setFromName(new ResourceLocation(blockName), state); - } - - @Override - public IBlockBuilder setFromName(final String blockName, final int metadata) { - return this.setFromName(new ResourceLocation(blockName), metadata); - } - - @Override - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); - } - - @Override - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final String state) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final int metadata) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); - } - - @Override - public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, - final int chance) { - final ResourceLocation key = blockState.getBlock().getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - this.blockState = blockState; - this.chance = chance; - return this; - } - - @Override - public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { - final ResourceLocation key = block.getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockStateWithChance(block.getDefaultState(), chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final String state, - final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, - final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), - chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final String state, final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), - chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int metadata, final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); - } - - @Override - public IBlockBuilder setChance(final int chance) { - this.chance = chance; - return this; - } - - @Override - public IBlockDefinition create() { - return new BlockDefinition(this.blockState, this.chance, this.isValid); - } + private IBlockState blockState; + private int chance; + private boolean isValid = true; + + public BlockBuilder() { + // nothing to do here + } + + @Override + public IBlockBuilder setFromBlockState(final IBlockState blockState) { + final ResourceLocation key = blockState.getBlock().getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockStateWithChance(blockState, 100); + } + + @Override + public IBlockBuilder setFromBlock(final Block block) { + final ResourceLocation key = block.getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockState(block.getDefaultState()); + } + + @Override + public IBlockBuilder setFromName(final String blockName) { + return this.setFromName(new ResourceLocation(blockName)); + } + + @Override + public IBlockBuilder setFromName(final String blockName, final String state) { + return this.setFromName(new ResourceLocation(blockName), state); + } + + @Override + public IBlockBuilder setFromName(final String blockName, final int metadata) { + return this.setFromName(new ResourceLocation(blockName), metadata); + } + + @Override + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); + } + + @Override + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final String state) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final int metadata) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); + } + + @Override + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, + final int chance) { + final ResourceLocation key = blockState.getBlock().getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + this.blockState = blockState; + this.chance = chance; + return this; + } + + @Override + public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { + final ResourceLocation key = block.getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockStateWithChance(block.getDefaultState(), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, + final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, + final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), + chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final String state, final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), + chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int metadata, final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); + } + + @Override + public IBlockBuilder setChance(final int chance) { + this.chance = chance; + return this; + } + + @Override + public IBlockDefinition create() { + return new BlockDefinition(this.blockState, this.chance, this.isValid); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java index 8a3d0574..85f92e11 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -6,28 +6,28 @@ public class BlockDefinition implements IBlockDefinition { - private final IBlockState blockState; - private final int blockChance; - private final boolean isValid; - - public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { - this.blockState = blockState; - this.blockChance = chance; - this.isValid = isValid; - } - - @Override - public IBlockState getBlock() { - return this.blockState; - } - - @Override - public int getChance() { - return this.blockChance; - } - - @Override - public boolean isValid() { - return this.isValid; - } + private final IBlockState blockState; + private final int blockChance; + private final boolean isValid; + + public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { + this.blockState = blockState; + this.blockChance = chance; + this.isValid = isValid; + } + + @Override + public IBlockState getBlock() { + return this.blockState; + } + + @Override + public int getChance() { + return this.blockChance; + } + + @Override + public boolean isValid() { + return this.isValid; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 7d880935..65384779 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -12,51 +12,51 @@ public class BlockList implements IBlockList { - private final List myBlocks; - private final List workingList; - - public BlockList() { - this.myBlocks = new LinkedList<>(); - this.workingList = new LinkedList<>(); - } - - @Override - public void addBlock(final IBlockDefinition block) { - this.myBlocks.add(block); - } - - @Override - public IBlockState getRandomBlock(final Random rand) { - if (this.workingList.isEmpty()) { - this.startNewSpawn(); - } - - final int spot = rand.nextInt(this.workingList.size()); - final IBlockState rv = this.workingList.get(spot); - this.workingList.remove(spot); - return rv; - } - - @Override - public void startNewSpawn() { - this.workingList.clear(); - - this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { - for (int i = 0; i < b.getChance(); i++) { - this.workingList.add(b.getBlock()); - } - }); - } - - @Override - public void dump() { - this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( - bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); - } - - @Override - public int count() { - return this.myBlocks.size(); - } + private final List myBlocks; + private final List workingList; + + public BlockList() { + this.myBlocks = new LinkedList<>(); + this.workingList = new LinkedList<>(); + } + + @Override + public void addBlock(final IBlockDefinition block) { + this.myBlocks.add(block); + } + + @Override + public IBlockState getRandomBlock(final Random rand) { + if (this.workingList.isEmpty()) { + this.startNewSpawn(); + } + + final int spot = rand.nextInt(this.workingList.size()); + final IBlockState rv = this.workingList.get(spot); + this.workingList.remove(spot); + return rv; + } + + @Override + public void startNewSpawn() { + this.workingList.clear(); + + this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { + for (int i = 0; i < b.getChance(); i++) { + this.workingList.add(b.getBlock()); + } + }); + } + + @Override + public void dump() { + this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( + bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); + } + + @Override + public int count() { + return this.myBlocks.size(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 4e2fd880..53971888 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -8,69 +8,69 @@ public class DimensionBuilder implements IDimensionBuilder { - private final List dimensionWhitelist = new LinkedList<>(); - private final List dimensionBlacklist = new LinkedList<>(); - private boolean acceptAll = false; - private boolean denyAll = false; - private boolean acceptAllOverworld = true; + private final List dimensionWhitelist = new LinkedList<>(); + private final List dimensionBlacklist = new LinkedList<>(); + private boolean acceptAll = false; + private boolean denyAll = false; + private boolean acceptAllOverworld = true; - public DimensionBuilder() { - // - } + public DimensionBuilder() { + // + } - @Override - public IDimensionBuilder addWhitelistEntry(final int dimensionID) { - this.acceptAllOverworld = false; - this.dimensionWhitelist.add(dimensionID); - return this; - } + @Override + public IDimensionBuilder addWhitelistEntry(final int dimensionID) { + this.acceptAllOverworld = false; + this.dimensionWhitelist.add(dimensionID); + return this; + } - @Override - public IDimensionBuilder addBlacklistEntry(final int dimensionID) { - this.acceptAllOverworld = false; - this.dimensionBlacklist.add(dimensionID); - return this; - } + @Override + public IDimensionBuilder addBlacklistEntry(final int dimensionID) { + this.acceptAllOverworld = false; + this.dimensionBlacklist.add(dimensionID); + return this; + } - @Override - public IDimensionBuilder setAcceptAll() { - if (this.denyAll) { - this.denyAll = false; - } - this.acceptAll = true; - return this; - } + @Override + public IDimensionBuilder setAcceptAll() { + if (this.denyAll) { + this.denyAll = false; + } + this.acceptAll = true; + return this; + } - @Override - public IDimensionBuilder setDenyAll() { - if (this.acceptAll) { - this.acceptAll = false; - } - this.denyAll = true; - return this; - } + @Override + public IDimensionBuilder setDenyAll() { + if (this.acceptAll) { + this.acceptAll = false; + } + this.denyAll = true; + return this; + } - @Override - public IDimensionList create() { - if (this.acceptAll - || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) - && !(this.acceptAllOverworld)) { - return new DimensionListAcceptAll(); - } else if (this.denyAll) { - return new DimensionListDenyAll(); - } else if (this.acceptAllOverworld) { - return new DimensionListAcceptAllOverworld(); - } else { - return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); - } - } + @Override + public IDimensionList create() { + if (this.acceptAll + || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) + && !(this.acceptAllOverworld)) { + return new DimensionListAcceptAll(); + } else if (this.denyAll) { + return new DimensionListDenyAll(); + } else if (this.acceptAllOverworld) { + return new DimensionListAcceptAllOverworld(); + } else { + return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); + } + } - @Override - public IDimensionBuilder setAcceptAllOverworld() { - this.acceptAll = false; - this.denyAll = false; - this.acceptAllOverworld = true; - return this; - } + @Override + public IDimensionBuilder setAcceptAllOverworld() { + this.acceptAll = false; + this.denyAll = false; + this.acceptAllOverworld = true; + return this; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 4997211e..8bd5219b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -9,51 +9,51 @@ public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { - private final List whitelist = new ArrayList<>(); - private final List blacklist = new ArrayList<>(); - - public DimensionList(final List whitelist, final List blacklist) { - this.whitelist.addAll(whitelist); - this.blacklist.addAll(blacklist); - } - - @Override - public boolean matches(final int dimensionID) { - if (this.whitelist.contains(Integer.valueOf(dimensionID))) { - return true; - } - if (this.blacklist.contains(Integer.valueOf(dimensionID))) { - return false; - } - if (!this.whitelist.isEmpty()) { - return false; - } - if (!this.blacklist.isEmpty()) { - return true; - } - - // if it gets here, the whitelist and blacklist are empty... - // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... - return true; - } - - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - if (!this.whitelist.isEmpty()) { - final JsonArray wl = new JsonArray(); - whitelist.stream().forEach(wl::add); - rv.add(Constants.ConfigNames.WHITELIST, wl); - } - - if (!this.blacklist.isEmpty()) { - final JsonArray bl = new JsonArray(); - blacklist.stream().forEach(bl::add); - rv.add(Constants.ConfigNames.WHITELIST, bl); - } else if (this.whitelist.isEmpty()) { - return new DimensionListAcceptAllOverworld().serialize(); - } - - return rv; - } + private final List whitelist = new ArrayList<>(); + private final List blacklist = new ArrayList<>(); + + public DimensionList(final List whitelist, final List blacklist) { + this.whitelist.addAll(whitelist); + this.blacklist.addAll(blacklist); + } + + @Override + public boolean matches(final int dimensionID) { + if (this.whitelist.contains(Integer.valueOf(dimensionID))) { + return true; + } + if (this.blacklist.contains(Integer.valueOf(dimensionID))) { + return false; + } + if (!this.whitelist.isEmpty()) { + return false; + } + if (!this.blacklist.isEmpty()) { + return true; + } + + // if it gets here, the whitelist and blacklist are empty... + // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... + return true; + } + + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + if (!this.whitelist.isEmpty()) { + final JsonArray wl = new JsonArray(); + whitelist.stream().forEach(wl::add); + rv.add(Constants.ConfigNames.WHITELIST, wl); + } + + if (!this.blacklist.isEmpty()) { + final JsonArray bl = new JsonArray(); + blacklist.stream().forEach(bl::add); + rv.add(Constants.ConfigNames.WHITELIST, bl); + } else if (this.whitelist.isEmpty()) { + return new DimensionListAcceptAllOverworld().serialize(); + } + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index 8f2b1ce0..bd871741 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -7,15 +7,15 @@ public class DimensionListAcceptAll implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return true; - } + @Override + public boolean matches(final int dimensionID) { + return true; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - rv.add(ConfigNames.BLACKLIST, new JsonArray()); - return rv; - } + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java index 263272ca..5727d875 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -7,19 +7,19 @@ public class DimensionListAcceptAllOverworld implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return dimensionID != -1 && dimensionID != 1; - } + @Override + public boolean matches(final int dimensionID) { + return dimensionID != -1 && dimensionID != 1; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - final JsonArray bl = new JsonArray(); - bl.add(-1); - bl.add(1); - rv.add(Constants.ConfigNames.BLACKLIST, bl); + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + final JsonArray bl = new JsonArray(); + bl.add(-1); + bl.add(1); + rv.add(Constants.ConfigNames.BLACKLIST, bl); - return rv; - } + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index 49eef5c0..54c527aa 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -7,16 +7,16 @@ public class DimensionListDenyAll implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return false; - } + @Override + public boolean matches(final int dimensionID) { + return false; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); - return rv; - } + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index d143163c..7ac4166b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -11,110 +11,110 @@ public class FeatureBuilder implements IFeatureBuilder { - private IFeature feature; - private JsonObject parameters; - private boolean useDefaults; - - public FeatureBuilder() { - this.useDefaults = false; - this.parameters = new JsonObject(); - } - - @Override - public IFeatureBuilder setFeature(final String featureName) { - String actName = featureName; - if (!actName.contains(":")) { - actName = String.format("orespawn:%s", featureName); - } - return this.setFeature(new ResourceLocation(actName)); - } - - @Override - public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { - if (!OreSpawn.API.featureExists(featureResourceLocation)) { - OreSpawn.LOGGER.warn( - "Feature %s is not known, feature for this will be set to the default feature", - featureResourceLocation.getPath()); - } - return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); - } - - @Override - public IFeatureBuilder setFeature(final IFeature feature) { - this.feature = feature; - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, - final JsonElement parameterValue) { - this.parameters.add(parameterName, parameterValue); - return this; - } - - private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, - final FeatureEntry feat) { - if (parameterValue.getAsJsonPrimitive().isBoolean()) { - feat.setParameter(parameterName, parameterValue.getAsBoolean()); - } else if (parameterValue.getAsJsonPrimitive().isString()) { - feat.setParameter(parameterName, parameterValue.getAsString()); - } else { - float paramAsFloat = parameterValue.getAsFloat(); - if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { - feat.setParameter(parameterName, parameterValue.getAsFloat()); - } else { - feat.setParameter(parameterName, parameterValue.getAsInt()); - } - } - } - - @Override - public IFeatureBuilder setUseFeatureDefaults() { - this.useDefaults = true; - return this; - } - - @Override - public IFeatureEntry create() { - final FeatureEntry res = new FeatureEntry(this.feature); - if (!this.useDefaults) { - // only copy in the parameters we need - this.feature.getDefaultParameters().entrySet().stream() - .filter(ent -> !this.parameters.has(ent.getKey())) - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); - } else { - // overwrite - they've said to just use the defaults - this.feature.getDefaultParameters().entrySet().stream() - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); - } - - this.parameters.entrySet().stream() - .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); - - return res; - } + private IFeature feature; + private JsonObject parameters; + private boolean useDefaults; + + public FeatureBuilder() { + this.useDefaults = false; + this.parameters = new JsonObject(); + } + + @Override + public IFeatureBuilder setFeature(final String featureName) { + String actName = featureName; + if (!actName.contains(":")) { + actName = String.format("orespawn:%s", featureName); + } + return this.setFeature(new ResourceLocation(actName)); + } + + @Override + public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { + if (!OreSpawn.API.featureExists(featureResourceLocation)) { + OreSpawn.LOGGER.warn( + "Feature %s is not known, feature for this will be set to the default feature", + featureResourceLocation.getPath()); + } + return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); + } + + @Override + public IFeatureBuilder setFeature(final IFeature feature) { + this.feature = feature; + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, + final JsonElement parameterValue) { + this.parameters.add(parameterName, parameterValue); + return this; + } + + private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, + final FeatureEntry feat) { + if (parameterValue.getAsJsonPrimitive().isBoolean()) { + feat.setParameter(parameterName, parameterValue.getAsBoolean()); + } else if (parameterValue.getAsJsonPrimitive().isString()) { + feat.setParameter(parameterName, parameterValue.getAsString()); + } else { + float paramAsFloat = parameterValue.getAsFloat(); + if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { + feat.setParameter(parameterName, parameterValue.getAsFloat()); + } else { + feat.setParameter(parameterName, parameterValue.getAsInt()); + } + } + } + + @Override + public IFeatureBuilder setUseFeatureDefaults() { + this.useDefaults = true; + return this; + } + + @Override + public IFeatureEntry create() { + final FeatureEntry res = new FeatureEntry(this.feature); + if (!this.useDefaults) { + // only copy in the parameters we need + this.feature.getDefaultParameters().entrySet().stream() + .filter(ent -> !this.parameters.has(ent.getKey())) + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } else { + // overwrite - they've said to just use the defaults + this.feature.getDefaultParameters().entrySet().stream() + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } + + this.parameters.entrySet().stream() + .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); + + return res; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 1a6905f8..45425250 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -6,48 +6,48 @@ public class FeatureEntry implements IFeatureEntry { - private final IFeature feature; - private final JsonObject parameters; - - public FeatureEntry(final IFeature feature) { - this.feature = feature; - this.parameters = new JsonObject(); - } - - @Override - public IFeature getFeature() { - return this.feature; - } - - @Override - public String getFeatureName() { - return this.feature.getRegistryName().getPath(); - } - - @Override - public JsonObject getFeatureParameters() { - final JsonObject defs = feature.getDefaultParameters(); - this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); - return defs; - } - - @Override - public void setParameter(final String parameterName, final String parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final int parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final boolean parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final float parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } + private final IFeature feature; + private final JsonObject parameters; + + public FeatureEntry(final IFeature feature) { + this.feature = feature; + this.parameters = new JsonObject(); + } + + @Override + public IFeature getFeature() { + return this.feature; + } + + @Override + public String getFeatureName() { + return this.feature.getRegistryName().getPath(); + } + + @Override + public JsonObject getFeatureParameters() { + final JsonObject defs = feature.getDefaultParameters(); + this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); + return defs; + } + + @Override + public void setParameter(final String parameterName, final String parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final int parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final boolean parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final float parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index ca00982e..0c7035f1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -44,224 +44,224 @@ public class OS3APIImpl implements OS3API { - private static final Map spawns; - private static final FeatureRegistry features; - private static final ReplacementsRegistry replacements; - private static final PresetsStorage presets; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final Map spawnsToSourceFiles = new TreeMap<>(); - - static { - spawns = new ConcurrentHashMap<>(); - features = new FeatureRegistry(); - replacements = new ReplacementsRegistry(); - presets = new PresetsStorage(); - } - - public OS3APIImpl() { - // - } - - public void loadConfigFiles() { - final String failedReadingConfigsFrom = "Failed reading configs from "; - PathMatcher featuresFiles = FileSystems.getDefault() - .getPathMatcher("glob:**/features-*.json"); - PathMatcher replacementsFiles = FileSystems.getDefault() - .getPathMatcher("glob:**/replacements-*.json"); - PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); - - try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(featuresFiles::matches).map(Path::toFile) - .forEach(features::loadFeaturesFile); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.SYSCONF.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - - // have to do this twice or we have issues - try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.SYSCONF.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - - if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { - presets.load(Constants.SYSCONF.resolve("presets-default.json")); - } - - try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { - stream.filter(jsonMatcher::matches).forEach(conf -> { - try { - OreSpawnReader.tryReadFile(conf, this); - } catch (final MissingVersionException | NotAProperConfigException - | OldVersionException | UnknownVersionException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - }); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.CONFDIR.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - @Override - public void addSpawn(final ISpawnEntry spawnEntry) { - if (spawnEntry != null) { - spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); - } - } - - @Override - public void addFeature(final String featureName, final IFeature feature) { - features.addFeature(featureName, feature); - } - - @Override - public void addReplacement(final IReplacementEntry replacementEntry) { - replacements.addReplacement(replacementEntry); - } - - @Override - public ISpawnBuilder getSpawnBuilder() { - return new SpawnBuilder(); - } - - @Override - public IDimensionBuilder getDimensionBuilder() { - return new DimensionBuilder(); - } - - @Override - public IFeatureBuilder getFeatureBuilder() { - return new FeatureBuilder(); - } - - @Override - public IBlockBuilder getBlockBuilder() { - return new BlockBuilder(); - } - - @Override - public IBiomeBuilder getBiomeBuilder() { - return new BiomeBuilder(); - } - - @Override - public IReplacementBuilder getReplacementBuilder() { - return new ReplacementBuilder(); - } - - @Override - public Map getReplacements() { - final Map temp = new HashMap<>(); - replacements.getReplacements().entrySet().stream() - .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); - return ImmutableMap.copyOf(temp); - } - - @Override - public IReplacementEntry getReplacement(final String replacementName) { - return replacements.getReplacement(replacementName); - } - - @Override - public List getSpawns(final int dimensionID) { - return ImmutableList.copyOf( - spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) - .map(e -> e.getValue()).collect(Collectors.toList())); - } - - @Override - public ISpawnEntry getSpawn(final String spawnName) { - return spawns.get(new ResourceLocation(spawnName)); - } - - @Override - public Map getAllSpawns() { - final Map sp = new HashMap<>(); - spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); - return ImmutableMap.copyOf(sp); - } - - @Override - public boolean featureExists(final String featureName) { - return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName - : String.format("orespawn:%s", featureName))); - } - - @Override - public boolean featureExists(final ResourceLocation featureName) { - return features.hasFeature(featureName); - } - - @Override - public IFeature getFeature(final String featureName) { - return this.getFeature(new ResourceLocation(featureName)); - } - - @Override - public IFeature getFeature(final ResourceLocation featureName) { - return features.getFeature(featureName); - } - - @Override - public PresetsStorage copyPresets() { - final PresetsStorage copy = new PresetsStorage(); - presets.copy(copy); - return copy; - } - - @Override - public List getDimensionDefaultReplacements(final int dimensionID) { - return replacements.getDimensionDefault(dimensionID); - } - - @Override - public boolean hasReplacement(final ResourceLocation resourceLocation) { - return replacements.has(resourceLocation); - } - - @Override - public boolean hasReplacement(final String name) { - return this.hasReplacement(new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name))); - } - - @Override - public void mapEntryToFile(final Path p, final String entryName) { - spawnsToSourceFiles.put(entryName, p); - } - - @Override - public List getSpawnsForFile(final String fileName) { - final Path p = Constants.CONFDIR.resolve(fileName); - final List values = spawnsToSourceFiles.entrySet().stream() - .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) - .collect(Collectors.toList()); - return ImmutableList.copyOf(values); - } - - @Override - public Map> getSpawnsByFile() { - final Map> temp = new HashMap<>(); - spawnsToSourceFiles.entrySet().stream().forEach(ent -> { - if (temp.containsKey(ent.getValue())) { - temp.get(ent.getValue()).add(ent.getKey()); - } else { - temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); - } - }); - - return ImmutableMap.copyOf(temp); - } + private static final Map spawns; + private static final FeatureRegistry features; + private static final ReplacementsRegistry replacements; + private static final PresetsStorage presets; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final Map spawnsToSourceFiles = new TreeMap<>(); + + static { + spawns = new ConcurrentHashMap<>(); + features = new FeatureRegistry(); + replacements = new ReplacementsRegistry(); + presets = new PresetsStorage(); + } + + public OS3APIImpl() { + // + } + + public void loadConfigFiles() { + final String failedReadingConfigsFrom = "Failed reading configs from "; + PathMatcher featuresFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/features-*.json"); + PathMatcher replacementsFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/replacements-*.json"); + PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); + + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { + stream.filter(featuresFiles::matches).map(Path::toFile) + .forEach(features::loadFeaturesFile); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + // have to do this twice or we have issues + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { + stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { + presets.load(Constants.SYSCONF.resolve("presets-default.json")); + } + + try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { + stream.filter(jsonMatcher::matches).forEach(conf -> { + try { + OreSpawnReader.tryReadFile(conf, this); + } catch (final MissingVersionException | NotAProperConfigException + | OldVersionException | UnknownVersionException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.CONFDIR.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + @Override + public void addSpawn(final ISpawnEntry spawnEntry) { + if (spawnEntry != null) { + spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); + } + } + + @Override + public void addFeature(final String featureName, final IFeature feature) { + features.addFeature(featureName, feature); + } + + @Override + public void addReplacement(final IReplacementEntry replacementEntry) { + replacements.addReplacement(replacementEntry); + } + + @Override + public ISpawnBuilder getSpawnBuilder() { + return new SpawnBuilder(); + } + + @Override + public IDimensionBuilder getDimensionBuilder() { + return new DimensionBuilder(); + } + + @Override + public IFeatureBuilder getFeatureBuilder() { + return new FeatureBuilder(); + } + + @Override + public IBlockBuilder getBlockBuilder() { + return new BlockBuilder(); + } + + @Override + public IBiomeBuilder getBiomeBuilder() { + return new BiomeBuilder(); + } + + @Override + public IReplacementBuilder getReplacementBuilder() { + return new ReplacementBuilder(); + } + + @Override + public Map getReplacements() { + final Map temp = new HashMap<>(); + replacements.getReplacements().entrySet().stream() + .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); + return ImmutableMap.copyOf(temp); + } + + @Override + public IReplacementEntry getReplacement(final String replacementName) { + return replacements.getReplacement(replacementName); + } + + @Override + public List getSpawns(final int dimensionID) { + return ImmutableList.copyOf( + spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) + .map(e -> e.getValue()).collect(Collectors.toList())); + } + + @Override + public ISpawnEntry getSpawn(final String spawnName) { + return spawns.get(new ResourceLocation(spawnName)); + } + + @Override + public Map getAllSpawns() { + final Map sp = new HashMap<>(); + spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); + return ImmutableMap.copyOf(sp); + } + + @Override + public boolean featureExists(final String featureName) { + return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName + : String.format("orespawn:%s", featureName))); + } + + @Override + public boolean featureExists(final ResourceLocation featureName) { + return features.hasFeature(featureName); + } + + @Override + public IFeature getFeature(final String featureName) { + return this.getFeature(new ResourceLocation(featureName)); + } + + @Override + public IFeature getFeature(final ResourceLocation featureName) { + return features.getFeature(featureName); + } + + @Override + public PresetsStorage copyPresets() { + final PresetsStorage copy = new PresetsStorage(); + presets.copy(copy); + return copy; + } + + @Override + public List getDimensionDefaultReplacements(final int dimensionID) { + return replacements.getDimensionDefault(dimensionID); + } + + @Override + public boolean hasReplacement(final ResourceLocation resourceLocation) { + return replacements.has(resourceLocation); + } + + @Override + public boolean hasReplacement(final String name) { + return this.hasReplacement(new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name))); + } + + @Override + public void mapEntryToFile(final Path p, final String entryName) { + spawnsToSourceFiles.put(entryName, p); + } + + @Override + public List getSpawnsForFile(final String fileName) { + final Path p = Constants.CONFDIR.resolve(fileName); + final List values = spawnsToSourceFiles.entrySet().stream() + .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) + .collect(Collectors.toList()); + return ImmutableList.copyOf(values); + } + + @Override + public Map> getSpawnsByFile() { + final Map> temp = new HashMap<>(); + spawnsToSourceFiles.entrySet().stream().forEach(ent -> { + if (temp.containsKey(ent.getValue())) { + temp.get(ent.getValue()).add(ent.getKey()); + } else { + temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); + } + }); + + return ImmutableMap.copyOf(temp); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 1a6aef44..b21fec9c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -16,89 +16,89 @@ public class ReplacementBuilder implements IReplacementBuilder { - private String replacementName = null; - private List entries; - - public ReplacementBuilder() { - this.entries = new LinkedList<>(); - } - - @Override - public IReplacementBuilder setFromName(final String entryName) { - this.replacementName = entryName; - this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); - return this; - } - - @Override - public IReplacementBuilder setName(final String name) { - this.replacementName = name; - return this; - } - - @Override - public IReplacementBuilder addEntry(final IBlockState blockState) { - this.entries.add(blockState); - return this; - } - - @Override - public IReplacementBuilder addEntry(final String blockName) { - return this.addEntry(new ResourceLocation(blockName)); - } - - @Override - public IReplacementBuilder addEntry(final String blockName, final String state) { - return this.addEntry(new ResourceLocation(blockName), state); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IReplacementBuilder addEntry(final String blockName, final int metadata) { - return this.addEntry(new ResourceLocation(blockName), metadata); - } - - @Override - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { - return this - .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); - } - - @Override - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final String state) { - return this.addEntry(StateUtil - .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final int metadata) { - return this.addEntry( - ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); - } - - @Override - public boolean hasEntries() { - return !this.entries.isEmpty(); - } - - @Override - public IReplacementEntry create() { - if (this.replacementName == null) { - this.replacementName = String.format("replacement_%s", - RandomStringUtils.randomAlphanumeric(8, 16)); - } - - return new ReplacementEntry(this.replacementName, this.entries); - } + private String replacementName = null; + private List entries; + + public ReplacementBuilder() { + this.entries = new LinkedList<>(); + } + + @Override + public IReplacementBuilder setFromName(final String entryName) { + this.replacementName = entryName; + this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); + return this; + } + + @Override + public IReplacementBuilder setName(final String name) { + this.replacementName = name; + return this; + } + + @Override + public IReplacementBuilder addEntry(final IBlockState blockState) { + this.entries.add(blockState); + return this; + } + + @Override + public IReplacementBuilder addEntry(final String blockName) { + return this.addEntry(new ResourceLocation(blockName)); + } + + @Override + public IReplacementBuilder addEntry(final String blockName, final String state) { + return this.addEntry(new ResourceLocation(blockName), state); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IReplacementBuilder addEntry(final String blockName, final int metadata) { + return this.addEntry(new ResourceLocation(blockName), metadata); + } + + @Override + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { + return this + .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); + } + + @Override + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final String state) { + return this.addEntry(StateUtil + .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final int metadata) { + return this.addEntry( + ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); + } + + @Override + public boolean hasEntries() { + return !this.entries.isEmpty(); + } + + @Override + public IReplacementEntry create() { + if (this.replacementName == null) { + this.replacementName = String.format("replacement_%s", + RandomStringUtils.randomAlphanumeric(8, 16)); + } + + return new ReplacementEntry(this.replacementName, this.entries); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index d5bb771a..34f487e1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -12,31 +12,31 @@ import net.minecraftforge.registries.IForgeRegistryEntry; public class ReplacementEntry extends IForgeRegistryEntry.Impl - implements IReplacementEntry { - - private final List matchVal; - private OreSpawnBlockMatcher matcher = null; - - public ReplacementEntry(final String name, final IBlockState... toMatch) { - super.setRegistryName(name); - this.matchVal = Arrays.asList(toMatch); - } - - public ReplacementEntry(final String name, final List toMatch) { - super.setRegistryName(name); - this.matchVal = new ArrayList<>(); - this.matchVal.addAll(toMatch); - } - - @Override - public OreSpawnBlockMatcher getMatcher() { - if (this.matcher == null) { - this.matcher = new OreSpawnBlockMatcher(this.matchVal); - } - return this.matcher; - } - - public List getEntries() { - return ImmutableList.copyOf(this.matchVal); - } + implements IReplacementEntry { + + private final List matchVal; + private OreSpawnBlockMatcher matcher = null; + + public ReplacementEntry(final String name, final IBlockState... toMatch) { + super.setRegistryName(name); + this.matchVal = Arrays.asList(toMatch); + } + + public ReplacementEntry(final String name, final List toMatch) { + super.setRegistryName(name); + this.matchVal = new ArrayList<>(); + this.matchVal.addAll(toMatch); + } + + @Override + public OreSpawnBlockMatcher getMatcher() { + if (this.matcher == null) { + this.matcher = new OreSpawnBlockMatcher(this.matchVal); + } + return this.matcher; + } + + public List getEntries() { + return ImmutableList.copyOf(this.matchVal); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 9f0e6c8e..1a902d97 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -16,199 +16,199 @@ public class SpawnBuilder implements ISpawnBuilder { - private String spawnName; - private boolean enabled; - private boolean retrogen; - private IBlockList blocks; - private IFeatureEntry feature; - private BiomeLocation biomes; - private IDimensionList dimensions; - private IReplacementEntry replacements; - - public SpawnBuilder() { - this.enabled = false; - this.retrogen = false; - this.blocks = new BlockList(); - } - - public SpawnBuilder(final String spawnName) { - this(); - this.spawnName = spawnName; - } - - @Override - public ISpawnBuilder setName(final String name) { - this.spawnName = name; - return this; - } - - @Override - public ISpawnBuilder setDimensions(final IDimensionList dimensions) { - this.dimensions = dimensions; - return this; - } - - @Override - public ISpawnBuilder setBiomes(final BiomeLocation biomes) { - this.biomes = biomes; - return this; - } - - @Override - public ISpawnBuilder setEnabled(final boolean enabled) { - this.enabled = enabled; - return this; - } - - @Override - public ISpawnBuilder setRetrogen(final boolean retrogen) { - this.retrogen = retrogen; - return this; - } - - @Override - public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { - this.replacements = replacements; - return this; - } - - @Override - public ISpawnBuilder setFeature(final IFeatureEntry feature) { - this.feature = feature; - return this; - } - - @Override - public ISpawnBuilder addBlock(final String blockName) { - return this.addBlock(new ResourceLocation(blockName)); - } - - @Override - public ISpawnBuilder addBlock(final String blockName, final String blockState) { - return this.addBlock(new ResourceLocation(blockName), blockState); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { - return this.addBlock(new ResourceLocation(blockName), blockMetadata); - } - - @Override - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { - return this.addBlockWithChance(blockResourceLocation, 100); - } - - @Override - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final String blockState) { - return this.addBlockWithChance(blockResourceLocation, blockState, 100); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final int blockMetadata) { - return this.addBlockWithChance(blockResourceLocation, 100); - } - - @Override - public ISpawnBuilder addBlock(final Block block) { - return this.addBlockWithChance(block, 100); - } - - @Override - public ISpawnBuilder addBlock(final IBlockState block) { - return this.addBlockWithChance(block, 100); - } - - @Override - public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { - return this.addBlockWithChance(new ResourceLocation(blockName), chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, - final int chance) { - return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, - final int chance) { - return this.addBlockWithChance(blockName, blockMetadata, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int chance) { - final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) - .getDefaultState(); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final String blockState, final int chance) { - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); - return this.addBlockWithChance(tempVar, chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int blockMetadata, final int chance) { - final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) - .getStateFromMeta(blockMetadata); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { - final IBlockState tempVar = block.getDefaultState(); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { - final BlockBuilder bb = new BlockBuilder(); - bb.setFromBlockStateWithChance(block, chance); - return this.addBlock(bb.create()); - } - - @Override - public ISpawnBuilder addBlock(final IBlockDefinition block) { - if (block.isValid()) { - this.blocks.addBlock(block); - } - return this; - } - - @Override - public SpawnEntry create() { - if (this.blocks.count() > 0) { - return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, - this.biomes, this.replacements, this.blocks, this.feature); - } else { - return null; - } - } + private String spawnName; + private boolean enabled; + private boolean retrogen; + private IBlockList blocks; + private IFeatureEntry feature; + private BiomeLocation biomes; + private IDimensionList dimensions; + private IReplacementEntry replacements; + + public SpawnBuilder() { + this.enabled = false; + this.retrogen = false; + this.blocks = new BlockList(); + } + + public SpawnBuilder(final String spawnName) { + this(); + this.spawnName = spawnName; + } + + @Override + public ISpawnBuilder setName(final String name) { + this.spawnName = name; + return this; + } + + @Override + public ISpawnBuilder setDimensions(final IDimensionList dimensions) { + this.dimensions = dimensions; + return this; + } + + @Override + public ISpawnBuilder setBiomes(final BiomeLocation biomes) { + this.biomes = biomes; + return this; + } + + @Override + public ISpawnBuilder setEnabled(final boolean enabled) { + this.enabled = enabled; + return this; + } + + @Override + public ISpawnBuilder setRetrogen(final boolean retrogen) { + this.retrogen = retrogen; + return this; + } + + @Override + public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { + this.replacements = replacements; + return this; + } + + @Override + public ISpawnBuilder setFeature(final IFeatureEntry feature) { + this.feature = feature; + return this; + } + + @Override + public ISpawnBuilder addBlock(final String blockName) { + return this.addBlock(new ResourceLocation(blockName)); + } + + @Override + public ISpawnBuilder addBlock(final String blockName, final String blockState) { + return this.addBlock(new ResourceLocation(blockName), blockState); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { + return this.addBlock(new ResourceLocation(blockName), blockMetadata); + } + + @Override + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final String blockState) { + return this.addBlockWithChance(blockResourceLocation, blockState, 100); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final int blockMetadata) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public ISpawnBuilder addBlock(final Block block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public ISpawnBuilder addBlock(final IBlockState block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { + return this.addBlockWithChance(new ResourceLocation(blockName), chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, + final int chance) { + return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, + final int chance) { + return this.addBlockWithChance(blockName, blockMetadata, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int chance) { + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final String blockState, final int chance) { + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); + return this.addBlockWithChance(tempVar, chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int blockMetadata, final int chance) { + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getStateFromMeta(blockMetadata); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { + final IBlockState tempVar = block.getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { + final BlockBuilder bb = new BlockBuilder(); + bb.setFromBlockStateWithChance(block, chance); + return this.addBlock(bb.create()); + } + + @Override + public ISpawnBuilder addBlock(final IBlockDefinition block) { + if (block.isValid()) { + this.blocks.addBlock(block); + } + return this; + } + + @Override + public SpawnEntry create() { + if (this.blocks.count() > 0) { + return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, + this.biomes, this.replacements, this.blocks, this.feature); + } else { + return null; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 8935e9fa..58ac7bfb 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -19,89 +19,89 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { - private final String spawnName; - private final IDimensionList dimensions; - private final IReplacementEntry replacements; - private final IBlockList blocks; - private final BiomeLocation biomes; - private final IFeatureEntry feature; - private final boolean enabled; - private final boolean retrogen; - - public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, - final IDimensionList dimensions, final BiomeLocation biomes, - final IReplacementEntry replacements, final IBlockList blocks, - final IFeatureEntry feature) { - this.spawnName = spawnName; - this.enabled = enabled; - this.retrogen = retrogen; - this.dimensions = dimensions; - this.biomes = biomes; - this.replacements = replacements; - this.blocks = blocks; - this.feature = feature; - } - - @Override - public boolean isRetrogen() { - return this.retrogen; - } - - @Override - public boolean isEnabled() { - return this.enabled; - } - - @Override - public String getSpawnName() { - return this.spawnName; - } - - @Override - public boolean dimensionAllowed(final int dimension) { - return this.dimensions.matches(dimension); - } - - @Override - public boolean biomeAllowed(final ResourceLocation biomeName) { - return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); - } - - @Override - public boolean biomeAllowed(final Biome biome) { - return this.biomes.matches(biome); - } - - @Override - public IFeatureEntry getFeature() { - return this.feature; - } - - @Override - public OreSpawnBlockMatcher getMatcher() { - return this.replacements.getMatcher(); - } - - @Override - public IBlockList getBlocks() { - return this.blocks; - } - - @Override - public void generate(final Random random, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ChunkPos pos) { - this.feature.getFeature().setRandom(random); - this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); - } - - @Override - public IDimensionList getDimensions() { - return this.dimensions; - } - - @Override - public BiomeLocation getBiomes() { - return this.biomes; - } + private final String spawnName; + private final IDimensionList dimensions; + private final IReplacementEntry replacements; + private final IBlockList blocks; + private final BiomeLocation biomes; + private final IFeatureEntry feature; + private final boolean enabled; + private final boolean retrogen; + + public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, + final IDimensionList dimensions, final BiomeLocation biomes, + final IReplacementEntry replacements, final IBlockList blocks, + final IFeatureEntry feature) { + this.spawnName = spawnName; + this.enabled = enabled; + this.retrogen = retrogen; + this.dimensions = dimensions; + this.biomes = biomes; + this.replacements = replacements; + this.blocks = blocks; + this.feature = feature; + } + + @Override + public boolean isRetrogen() { + return this.retrogen; + } + + @Override + public boolean isEnabled() { + return this.enabled; + } + + @Override + public String getSpawnName() { + return this.spawnName; + } + + @Override + public boolean dimensionAllowed(final int dimension) { + return this.dimensions.matches(dimension); + } + + @Override + public boolean biomeAllowed(final ResourceLocation biomeName) { + return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); + } + + @Override + public boolean biomeAllowed(final Biome biome) { + return this.biomes.matches(biome); + } + + @Override + public IFeatureEntry getFeature() { + return this.feature; + } + + @Override + public OreSpawnBlockMatcher getMatcher() { + return this.replacements.getMatcher(); + } + + @Override + public IBlockList getBlocks() { + return this.blocks; + } + + @Override + public void generate(final Random random, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ChunkPos pos) { + this.feature.getFeature().setRandom(random); + this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); + } + + @Override + public IDimensionList getDimensions() { + return this.dimensions; + } + + @Override + public BiomeLocation getBiomes() { + return this.biomes; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 989866e7..3010949d 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -46,363 +46,363 @@ public class OreSpawnReader { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) - throws MissingVersionException, NotAProperConfigException, OldVersionException, - UnknownVersionException { - final JsonParser parser = new JsonParser(); + public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) + throws MissingVersionException, NotAProperConfigException, OldVersionException, + UnknownVersionException { + final JsonParser parser = new JsonParser(); - try (BufferedReader data = Files.newBufferedReader(conf)) { - final JsonElement json = parser.parse(data); + try (BufferedReader data = Files.newBufferedReader(conf)) { + final JsonElement json = parser.parse(data); - if (!json.isJsonObject()) { - throw new NotAProperConfigException(); - } + if (!json.isJsonObject()) { + throw new NotAProperConfigException(); + } - final JsonObject root = json.getAsJsonObject(); - if (!root.has(Constants.ConfigNames.FILE_VERSION)) { - throw new MissingVersionException(); - } + final JsonObject root = json.getAsJsonObject(); + if (!root.has(Constants.ConfigNames.FILE_VERSION)) { + throw new MissingVersionException(); + } - final float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); - if (version < 2f) { - throw new OldVersionException(); - } else if (version != 2f) { - throw new UnknownVersionException(); - } + final float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); + if (version < 2f) { + throw new OldVersionException(); + } else if (version != 2f) { + throw new UnknownVersionException(); + } - if (!root.has(Constants.ConfigNames.SPAWNS)) { - throw new NotAProperConfigException(); - } + if (!root.has(Constants.ConfigNames.SPAWNS)) { + throw new NotAProperConfigException(); + } - final JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) - .getAsJsonObject(); - spawnData.entrySet().stream().forEach(e -> { - try { - OreSpawn.API.mapEntryToFile(conf, e.getKey()); - loadSingleEntry(e); - } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { - CrashReport report = CrashReport.makeCrashReport(e1, - "Error parsing an entry " + e.getKey() + " in " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - }); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config data " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (final JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "JSON Parsing Error in " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + final JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject(); + spawnData.entrySet().stream().forEach(e -> { + try { + OreSpawn.API.mapEntryToFile(conf, e.getKey()); + loadSingleEntry(e); + } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { + CrashReport report = CrashReport.makeCrashReport(e1, + "Error parsing an entry " + e.getKey() + " in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config data " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch (final JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } - private static JsonObject doHandlePresets(final JsonObject spawnData) { - final PresetsStorage configPresets = OreSpawn.API.copyPresets(); - if (spawnData.has(Constants.ConfigNames.PRESETS)) { - spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() - .forEach(entry -> { - String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream() - .forEach(sect -> configPresets.setSymbolSection(section, - sect.getKey(), sect.getValue())); - }); - } + private static JsonObject doHandlePresets(final JsonObject spawnData) { + final PresetsStorage configPresets = OreSpawn.API.copyPresets(); + if (spawnData.has(Constants.ConfigNames.PRESETS)) { + spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() + .forEach(entry -> { + String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream() + .forEach(sect -> configPresets.setSymbolSection(section, + sect.getKey(), sect.getValue())); + }); + } - final JsonObject spawnDataFixed = new JsonObject(); - for (final Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) - .getAsJsonObject().entrySet()) { - spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); - } - return spawnData; - } + final JsonObject spawnDataFixed = new JsonObject(); + for (final Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject().entrySet()) { + spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); + } + return spawnData; + } - private static JsonElement doPresetFix(final JsonElement value, - final PresetsStorage configPresets) { - if (value.isJsonObject()) { - return doPresetForObject(value.getAsJsonObject(), configPresets); - } else if (value.isJsonArray()) { - return doPresetForArray(value.getAsJsonArray(), configPresets); - } else if (value.isJsonPrimitive() && !value.isJsonNull()) { - if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { - return configPresets.get(value.getAsString()); - } else { - return value; - } - } else { - OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " - + value.toString()); - return value; - } - } + private static JsonElement doPresetFix(final JsonElement value, + final PresetsStorage configPresets) { + if (value.isJsonObject()) { + return doPresetForObject(value.getAsJsonObject(), configPresets); + } else if (value.isJsonArray()) { + return doPresetForArray(value.getAsJsonArray(), configPresets); + } else if (value.isJsonPrimitive() && !value.isJsonNull()) { + if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { + return configPresets.get(value.getAsString()); + } else { + return value; + } + } else { + OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " + + value.toString()); + return value; + } + } - private static JsonElement doPresetForArray(final JsonArray value, - final PresetsStorage configPresets) { - final JsonArray rv = new JsonArray(); - value.forEach(it -> rv.add(doPresetFix(it, configPresets))); - return rv; - } + private static JsonElement doPresetForArray(final JsonArray value, + final PresetsStorage configPresets) { + final JsonArray rv = new JsonArray(); + value.forEach(it -> rv.add(doPresetFix(it, configPresets))); + return rv; + } - private static JsonElement doPresetForObject(final JsonObject value, - final PresetsStorage configPresets) { - final JsonObject rv = new JsonObject(); + private static JsonElement doPresetForObject(final JsonObject value, + final PresetsStorage configPresets) { + final JsonObject rv = new JsonObject(); - value.entrySet().stream().forEach( - entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); - return rv; - } + value.entrySet().stream().forEach( + entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); + return rv; + } - public static void loadFromJson(final String name, final JsonElement json) { - final Entry t = new AbstractMap.SimpleEntry<>(name, json); - try { - loadSingleEntry(t); - } catch (UnknownFieldException | BadValueException | UnknownNameException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Error parsing an manual JSON read for " + name); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + public static void loadFromJson(final String name, final JsonElement json) { + final Entry t = new AbstractMap.SimpleEntry<>(name, json); + try { + loadSingleEntry(t); + } catch (UnknownFieldException | BadValueException | UnknownNameException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Error parsing an manual JSON read for " + name); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } - private static void loadSingleEntry(final Entry entry) - throws UnknownFieldException, BadValueException, UnknownNameException { - final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); - final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); - sb.setName(entry.getKey()); + private static void loadSingleEntry(final Entry entry) + throws UnknownFieldException, BadValueException, UnknownNameException { + final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); + final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); + sb.setName(entry.getKey()); - for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { - switch (ent.getKey()) { - case Constants.ConfigNames.RETROGEN: - sb.setRetrogen(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.ENABLED: - sb.setEnabled(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.DIMENSIONS: - final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); - if (ent.getValue().isJsonArray()) { - final JsonArray dims = ent.getValue().getAsJsonArray(); - if (dims.size() == 0) { - // blank list, accept all overworld - db.setAcceptAllOverworld(); - } else { - dims.forEach(item -> { - if (item.isJsonPrimitive() - && item.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(item.getAsInt()); - } - }); - } - } else if (ent.getValue().isJsonObject()) { - loadDimensions(db, ent.getValue().getAsJsonObject()); - } else { - throw new BadValueException(Constants.ConfigNames.DIMENSIONS, - ent.getValue().toString()); - } - sb.setDimensions(db.create()); - break; - case Constants.ConfigNames.BIOMES: - if (!ent.getValue().isJsonObject()) { - throw new BadValueException(Constants.ConfigNames.BIOMES, - ent.getValue().toString()); - } - final IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); - loadBiomes(bb, ent.getValue().getAsJsonObject()); - sb.setBiomes(bb.create()); - break; - case Constants.ConfigNames.FEATURE: - if (ent.getValue().isJsonPrimitive() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.FEATURE, - ent.getValue().toString()); - } - final String featureName = ent.getValue().getAsString(); - if (!OreSpawn.API.featureExists(featureName)) { - throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); - } - fb.setFeature(featureName); - break; - case Constants.ConfigNames.REPLACEMENT: - final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); - if (!ent.getValue().isJsonArray() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.REPLACEMENT, - ent.getValue().toString()); - } else if (ent.getValue().isJsonPrimitive() - && ent.getValue().getAsJsonPrimitive().isString()) { - if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { - rb.setFromName(ent.getValue().getAsString()); - } - } else { - for (final JsonElement e : ent.getValue().getAsJsonArray()) { - if (e.isJsonObject()) { - loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in replacements list as it is not the correct format", - e.toString()); - } - } - } + for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { + switch (ent.getKey()) { + case Constants.ConfigNames.RETROGEN: + sb.setRetrogen(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.ENABLED: + sb.setEnabled(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.DIMENSIONS: + final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + if (ent.getValue().isJsonArray()) { + final JsonArray dims = ent.getValue().getAsJsonArray(); + if (dims.size() == 0) { + // blank list, accept all overworld + db.setAcceptAllOverworld(); + } else { + dims.forEach(item -> { + if (item.isJsonPrimitive() + && item.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(item.getAsInt()); + } + }); + } + } else if (ent.getValue().isJsonObject()) { + loadDimensions(db, ent.getValue().getAsJsonObject()); + } else { + throw new BadValueException(Constants.ConfigNames.DIMENSIONS, + ent.getValue().toString()); + } + sb.setDimensions(db.create()); + break; + case Constants.ConfigNames.BIOMES: + if (!ent.getValue().isJsonObject()) { + throw new BadValueException(Constants.ConfigNames.BIOMES, + ent.getValue().toString()); + } + final IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); + loadBiomes(bb, ent.getValue().getAsJsonObject()); + sb.setBiomes(bb.create()); + break; + case Constants.ConfigNames.FEATURE: + if (ent.getValue().isJsonPrimitive() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.FEATURE, + ent.getValue().toString()); + } + final String featureName = ent.getValue().getAsString(); + if (!OreSpawn.API.featureExists(featureName)) { + throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); + } + fb.setFeature(featureName); + break; + case Constants.ConfigNames.REPLACEMENT: + final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + if (!ent.getValue().isJsonArray() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.REPLACEMENT, + ent.getValue().toString()); + } else if (ent.getValue().isJsonPrimitive() + && ent.getValue().getAsJsonPrimitive().isString()) { + if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { + rb.setFromName(ent.getValue().getAsString()); + } + } else { + for (final JsonElement e : ent.getValue().getAsJsonArray()) { + if (e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in replacements list as it is not the correct format", + e.toString()); + } + } + } - if (rb.hasEntries()) { - sb.setReplacement(rb.create()); - } - break; - case Constants.ConfigNames.BLOCK: - if (ent.getValue().isJsonArray()) { - for (final JsonElement elem : ent.getValue().getAsJsonArray()) { - final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); - if (elem.isJsonObject()) { - final JsonObject bl = elem.getAsJsonObject(); - if (bl.has(Constants.ConfigNames.STATE)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.STATE).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else if (bl.has(Constants.ConfigNames.METADATA)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.METADATA).getAsInt(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } - sb.addBlock(block.create()); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in blocks list as it is not the correct format", - elem.toString()); - } - } - } else { - throw new BadValueException(Constants.ConfigNames.BLOCK, - ent.getValue().toString()); - } - case Constants.ConfigNames.PARAMETERS: - if (ent.getValue().isJsonObject()) { - ent.getValue().getAsJsonObject().entrySet().stream() - .forEach(e -> fb.setParameter(e.getKey(), e.getValue())); - } - break; - default: - throw new UnknownFieldException(ent.getKey()); - } - } - sb.setFeature(fb.create()); - OreSpawn.API.addSpawn(sb.create()); - } + if (rb.hasEntries()) { + sb.setReplacement(rb.create()); + } + break; + case Constants.ConfigNames.BLOCK: + if (ent.getValue().isJsonArray()) { + for (final JsonElement elem : ent.getValue().getAsJsonArray()) { + final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + if (elem.isJsonObject()) { + final JsonObject bl = elem.getAsJsonObject(); + if (bl.has(Constants.ConfigNames.STATE)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.STATE).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else if (bl.has(Constants.ConfigNames.METADATA)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.METADATA).getAsInt(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } + sb.addBlock(block.create()); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in blocks list as it is not the correct format", + elem.toString()); + } + } + } else { + throw new BadValueException(Constants.ConfigNames.BLOCK, + ent.getValue().toString()); + } + case Constants.ConfigNames.PARAMETERS: + if (ent.getValue().isJsonObject()) { + ent.getValue().getAsJsonObject().entrySet().stream() + .forEach(e -> fb.setParameter(e.getKey(), e.getValue())); + } + break; + default: + throw new UnknownFieldException(ent.getKey()); + } + } + sb.setFeature(fb.create()); + OreSpawn.API.addSpawn(sb.create()); + } - private static List loadBlock(final JsonObject json) { - final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); - if (json.has(Constants.ConfigNames.STATE)) { - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(StateUtil.deserializeState(block, - json.get(Constants.ConfigNames.STATE).getAsString())); - } else if (json.has(Constants.ConfigNames.METADATA)) { - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList( - block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); - } + private static List loadBlock(final JsonObject json) { + final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); + if (json.has(Constants.ConfigNames.STATE)) { + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(StateUtil.deserializeState(block, + json.get(Constants.ConfigNames.STATE).getAsString())); + } else if (json.has(Constants.ConfigNames.METADATA)) { + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList( + block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); + } - if (blockName.startsWith("ore:")) { - final String entry = blockName.split(":")[1]; - return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { - final Block b = Block.getBlockFromItem(is.getItem()); - return b.getStateFromMeta(is.getMetadata()); - }).collect(Collectors.toList())); - } - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(block.getDefaultState()); - } + if (blockName.startsWith("ore:")) { + final String entry = blockName.split(":")[1]; + return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { + final Block b = Block.getBlockFromItem(is.getItem()); + return b.getStateFromMeta(is.getMetadata()); + }).collect(Collectors.toList())); + } + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(block.getDefaultState()); + } - private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { - boolean emptyWhitelist = false; + private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { + boolean emptyWhitelist = false; - if (biomeList.has(Constants.ConfigNames.WHITELIST) - && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addWhitelistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addWhitelistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else { - emptyWhitelist = true; - } + if (biomeList.has(Constants.ConfigNames.WHITELIST) + && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addWhitelistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addWhitelistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else { + emptyWhitelist = true; + } - if (biomeList.has(Constants.ConfigNames.BLACKLIST) - && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addBlacklistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addBlacklistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", - elem.getAsString()); - } - } - } else if (emptyWhitelist) { - // empty whitelist and blacklist - accept everything - bb.setAcceptAll(); - } - } + if (biomeList.has(Constants.ConfigNames.BLACKLIST) + && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addBlacklistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addBlacklistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", + elem.getAsString()); + } + } + } else if (emptyWhitelist) { + // empty whitelist and blacklist - accept everything + bb.setAcceptAll(); + } + } - private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { - boolean emptyWhitelist = false; + private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { + boolean emptyWhitelist = false; - if (dimensionList.has(Constants.ConfigNames.WHITELIST) - && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else { - emptyWhitelist = true; - } + if (dimensionList.has(Constants.ConfigNames.WHITELIST) + && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else { + emptyWhitelist = true; + } - if (dimensionList.has(Constants.ConfigNames.BLACKLIST) - && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addBlacklistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else if (emptyWhitelist) { - db.setAcceptAllOverworld(); - } - } + if (dimensionList.has(Constants.ConfigNames.BLACKLIST) + && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addBlacklistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else if (emptyWhitelist) { + db.setAcceptAllOverworld(); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index f8edba41..11a35b01 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -20,54 +20,54 @@ public class OreSpawnWriter { - /* - * Write out the configs as the system knows them to the 'forced-saves' directory - */ - public static void saveConfigs() { - final Map> configs = OreSpawn.API.getSpawnsByFile(); - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); - } + /* + * Write out the configs as the system knows them to the 'forced-saves' directory + */ + public static void saveConfigs() { + final Map> configs = OreSpawn.API.getSpawnsByFile(); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); + } - private static void saveSingle(final Path filePath, final Gson gson) { - final JsonObject root = new JsonObject(); - root.addProperty(ConfigNames.FILE_VERSION, "2.0"); - final JsonObject spawns = new JsonObject(); - final String k = filePath.getFileName().toString(); - final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); - final Path conf = saveDir.resolve(k); - if (!saveDir.toFile().exists()) { - saveDir.toFile().mkdirs(); - } - try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { - OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { - final JsonObject thisSpawn = new JsonObject(); - final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); - thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); - thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); - thisSpawn.addProperty(ConfigNames.FEATURE, - spawnEntry.getFeature().getFeatureName()); - thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); - thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); - thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); - thisSpawn.add(ConfigNames.PARAMETERS, - spawnEntry.getFeature().getFeatureParameters()); - spawns.add(spawnName, thisSpawn); - }); - root.add(ConfigNames.SPAWNS, spawns); - p.write(gson.toJson(root)); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed writing config data " + conf.toString()); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } + private static void saveSingle(final Path filePath, final Gson gson) { + final JsonObject root = new JsonObject(); + root.addProperty(ConfigNames.FILE_VERSION, "2.0"); + final JsonObject spawns = new JsonObject(); + final String k = filePath.getFileName().toString(); + final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); + final Path conf = saveDir.resolve(k); + if (!saveDir.toFile().exists()) { + saveDir.toFile().mkdirs(); + } + try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { + OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { + final JsonObject thisSpawn = new JsonObject(); + final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); + thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); + thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); + thisSpawn.addProperty(ConfigNames.FEATURE, + spawnEntry.getFeature().getFeatureName()); + thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); + thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); + thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); + thisSpawn.add(ConfigNames.PARAMETERS, + spawnEntry.getFeature().getFeatureParameters()); + spawns.add(spawnName, thisSpawn); + }); + root.add(ConfigNames.SPAWNS, spawns); + p.write(gson.toJson(root)); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config data " + conf.toString()); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } - } + } - public static void saveSingle(final String fileName) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - saveSingle(Constants.CONFDIR.resolve(fileName), gson); - } + public static void saveSingle(final String fileName) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + saveSingle(Constants.CONFDIR.resolve(fileName), gson); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java index bbe8ade9..469c3281 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java +++ b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java @@ -7,16 +7,16 @@ public final class Collectors2 { - private Collectors2() { - } + private Collectors2() { + } - public static Collector, ImmutableList> toImmutableList() { - return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, - (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); - } + public static Collector, ImmutableList> toImmutableList() { + return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); + } - public static Collector, ImmutableSet> toImmutableSet() { - return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, - (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); - } + public static Collector, ImmutableSet> toImmutableSet() { + return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 28f663e5..59044076 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -7,39 +7,39 @@ public class StateUtil { - private StateUtil() { - throw new InstantiationError("This class cannot be instantiated!"); - } - - public static String serializeState(final IBlockState state) { - String string = state.toString(); - string = string.substring(string.indexOf('[') + 1, - string.length() - (string.endsWith("]") ? 1 : 0)); - - if (string.equals(state.getBlock().getRegistryName().toString())) { - string = "normal"; - } - - OreSpawn.LOGGER.debug("State is %s (for block %s)", string, - state.getBlock().getRegistryName()); - return string; - } - - public static IBlockState deserializeState(final Block block, final String state) { - for (final IBlockState validState : block.getBlockState().getValidStates()) { - String string = validState.toString(); - string = string.substring(string.indexOf('[') + 1, - string.length() - (string.endsWith("]") ? 1 : 0)); - - if (string.equals(block.getRegistryName().toString())) { - string = ""; - } - - if (state.equals(string)) { - return validState; - } - } - - return null; - } + private StateUtil() { + throw new InstantiationError("This class cannot be instantiated!"); + } + + public static String serializeState(final IBlockState state) { + String string = state.toString(); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); + + if (string.equals(state.getBlock().getRegistryName().toString())) { + string = "normal"; + } + + OreSpawn.LOGGER.debug("State is %s (for block %s)", string, + state.getBlock().getRegistryName()); + return string; + } + + public static IBlockState deserializeState(final Block block, final String state) { + for (final IBlockState validState : block.getBlockState().getValidStates()) { + String string = validState.toString(); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); + + if (string.equals(block.getRegistryName().toString())) { + string = ""; + } + + if (state.equals(string)) { + return validState; + } + } + + return null; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index 497069e9..64fc38dd 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -17,71 +17,71 @@ public class FlatBedrock implements IWorldGenerator { - @Override - public void generate(final Random random, final int chunkX, final int chunkZ, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { - // no need to do flat-bedrock on a "FLAT" world - if (world.getWorldType() != WorldType.FLAT) { - if (world.provider.getDimension() == -1) { - genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); - } - } - } + @Override + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { + // no need to do flat-bedrock on a "FLAT" world + if (world.getWorldType() != WorldType.FLAT) { + if (world.provider.getDimension() == -1) { + genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); + } + } + } - public void retrogen(final World world, final int chunkX, final int chunkZ) { - if (world.getWorldType() != WorldType.FLAT) { - if (world.provider.getDimension() == -1) { - genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); - } - } - } + public void retrogen(final World world, final int chunkX, final int chunkZ) { + if (world.getWorldType() != WorldType.FLAT) { + if (world.provider.getDimension() == -1) { + genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); + } + } + } - private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); - for (int xP = 0; xP < 16; xP++) { - for (int zP = 0; zP < 16; zP++) { - for (int yP = 5; yP > 0; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, - chunkPos.z * 16 + zP); + for (int xP = 0; xP < 16; xP++) { + for (int zP = 0; zP < 16; zP++) { + for (int yP = 5; yP > 0; yP--) { + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); - if (yP < plateThickness - && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP >= plateThickness - && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, repBlock.getDefaultState(), 26); - } - } - } - } - } + if (yP < plateThickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); + } else if (yP >= plateThickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, repBlock.getDefaultState(), 26); + } + } + } + } + } - private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); - final int thickness = 127 - plateThickness; // layer where the flat for the top starts + private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + final int thickness = 127 - plateThickness; // layer where the flat for the top starts - for (int xP = 0; xP < 16; xP++) { - for (int zP = 0; zP < 16; zP++) { - for (int yP = 126; yP > 121; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, - chunkPos.z * 16 + zP); + for (int xP = 0; xP < 16; xP++) { + for (int zP = 0; zP < 16; zP++) { + for (int yP = 126; yP > 121; yP--) { + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); - if (yP > thickness - && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP <= thickness - && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, repBlock.getDefaultState(), 26); - } - } - } - } - } + if (yP > thickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); + } else if (yP <= thickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, repBlock.getDefaultState(), 26); + } + } + } + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index e0cb7025..34f23c35 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -14,16 +14,16 @@ public class OreSpawnWorldGen implements IWorldGenerator { - @Override - public void generate(final Random random, final int chunkX, final int chunkZ, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { + @Override + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { - final int thisDim = world.provider.getDimension(); + final int thisDim = world.provider.getDimension(); - OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) - .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) - || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, - new ChunkPos(chunkX, chunkZ))); - } + OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) + .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) + || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) + .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, + new ChunkPos(chunkX, chunkZ))); + } } From ed8748e04fedecefd8ebd40549b33e4a319521e0 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 28 Aug 2018 13:57:35 -0400 Subject: [PATCH 063/205] somehow "align fields in columns" snuck in from a different workspace (or maybe I only thought I'd changed workspaces for that project ?) Anyway... more brain-damage fixing --- .../com/mcmoddev/orespawn/EventHandlers.java | 370 +++--- .../java/com/mcmoddev/orespawn/OreSpawn.java | 127 +- .../mcmoddev/orespawn/api/BiomeLocation.java | 12 +- .../mcmoddev/orespawn/api/FeatureBase.java | 532 ++++---- .../com/mcmoddev/orespawn/api/IBlockList.java | 10 +- .../mcmoddev/orespawn/api/IDimensionList.java | 8 +- .../com/mcmoddev/orespawn/api/IFeature.java | 8 +- .../api/exceptions/BadValueException.java | 28 +- .../exceptions/MissingVersionException.java | 8 +- .../exceptions/NotAProperConfigException.java | 8 +- .../api/exceptions/OldVersionException.java | 8 +- .../api/exceptions/UnknownFieldException.java | 22 +- .../api/exceptions/UnknownNameException.java | 28 +- .../exceptions/UnknownVersionException.java | 8 +- .../orespawn/api/os3/IBiomeBuilder.java | 16 +- .../orespawn/api/os3/IBlockBuilder.java | 300 ++--- .../orespawn/api/os3/IBlockDefinition.java | 10 +- .../orespawn/api/os3/IDimensionBuilder.java | 12 +- .../orespawn/api/os3/IFeatureBuilder.java | 20 +- .../orespawn/api/os3/IFeatureEntry.java | 14 +- .../orespawn/api/os3/IReplacementBuilder.java | 128 +- .../orespawn/api/os3/IReplacementEntry.java | 4 +- .../orespawn/api/os3/ISpawnBuilder.java | 54 +- .../orespawn/api/os3/ISpawnEntry.java | 34 +- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 52 +- .../api/os3/OreSpawnBlockMatcher.java | 68 +- .../orespawn/api/plugin/IOreSpawnPlugin.java | 2 +- .../orespawn/api/plugin/OreSpawnPlugin.java | 18 +- .../orespawn/api/plugin/PluginLoader.java | 260 ++-- .../orespawn/commands/AddOreCommand.java | 164 +-- .../orespawn/commands/ClearChunkCommand.java | 266 ++-- .../orespawn/commands/DumpBiomesCommand.java | 72 +- .../commands/WriteConfigsCommand.java | 30 +- .../com/mcmoddev/orespawn/data/Config.java | 286 ++--- .../com/mcmoddev/orespawn/data/Constants.java | 175 ++- .../orespawn/data/FeatureRegistry.java | 262 ++-- .../orespawn/data/PresetsStorage.java | 122 +- .../orespawn/data/ReplacementsRegistry.java | 386 +++--- .../mcmoddev/orespawn/data/VanillaOres.java | 10 +- .../impl/features/ClusterGenerator.java | 328 ++--- .../features/DefaultFeatureGenerator.java | 230 ++-- .../impl/features/NormalCloudGenerator.java | 324 ++--- .../impl/features/PrecisionGenerator.java | 550 ++++---- .../orespawn/impl/features/VeinGenerator.java | 1108 ++++++++--------- .../impl/location/BiomeLocationAcceptAny.java | 20 +- .../location/BiomeLocationComposition.java | 136 +- .../location/BiomeLocationDictionary.java | 76 +- .../impl/location/BiomeLocationEmpty.java | 16 +- .../impl/location/BiomeLocationList.java | 88 +- .../impl/location/BiomeLocationSingle.java | 76 +- .../orespawn/impl/os3/BiomeBuilder.java | 154 +-- .../orespawn/impl/os3/BlockBuilder.java | 316 ++--- .../orespawn/impl/os3/BlockDefinition.java | 48 +- .../mcmoddev/orespawn/impl/os3/BlockList.java | 92 +- .../orespawn/impl/os3/DimensionBuilder.java | 114 +- .../orespawn/impl/os3/DimensionList.java | 94 +- .../impl/os3/DimensionListAcceptAll.java | 20 +- .../os3/DimensionListAcceptAllOverworld.java | 26 +- .../impl/os3/DimensionListDenyAll.java | 20 +- .../orespawn/impl/os3/FeatureBuilder.java | 212 ++-- .../orespawn/impl/os3/FeatureEntry.java | 88 +- .../orespawn/impl/os3/OS3APIImpl.java | 440 +++---- .../orespawn/impl/os3/ReplacementBuilder.java | 170 +-- .../orespawn/impl/os3/ReplacementEntry.java | 54 +- .../orespawn/impl/os3/SpawnBuilder.java | 390 +++--- .../orespawn/impl/os3/SpawnEntry.java | 170 +-- .../orespawn/json/OreSpawnReader.java | 668 +++++----- .../orespawn/json/OreSpawnWriter.java | 94 +- .../mcmoddev/orespawn/util/Collectors2.java | 20 +- .../com/mcmoddev/orespawn/util/StateUtil.java | 70 +- .../orespawn/worldgen/FlatBedrock.java | 120 +- .../orespawn/worldgen/OreSpawnWorldGen.java | 20 +- 72 files changed, 5146 insertions(+), 5148 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index e624b4bf..434f28a4 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -38,189 +38,189 @@ public class EventHandlers { - private final Deque retroChunks; - private final Deque>> chunks; - // private Map> chunks - - EventHandlers() { - retroChunks = new ConcurrentLinkedDeque<>(); - chunks = new ConcurrentLinkedDeque<>(); - } - - private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, - EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, - EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, - EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); - - @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) - public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { - if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - && vanillaEvents.contains(event.getType())) { - event.setResult(Event.Result.DENY); - } - } - - @SubscribeEvent - public void onChunkSave(final ChunkDataEvent.Save ev) { - final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final NBTTagCompound features = new NBTTagCompound(); - - // save a list of the spawns that were configured and available - in this dimension - when - // the chunk - // was first generated. - - // collect that data - final int thisDimension = ev.getWorld().provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) - .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features - .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - dataTag.setTag(Constants.FEATURES_TAG, features); - - ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); - } - - private boolean dequeContains(final ChunkPos cc) { - return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) - .contains(true); - } - - @SubscribeEvent - public void onChunkLoad(final ChunkDataEvent.Load ev) { - final World clWorld = ev.getWorld(); - final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); - - doBedrockRetrogen(chunkCoords); - - if (dequeContains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETROGEN_KEY)) { - final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final int thisDimension = clWorld.provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); - - if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) - || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.addLast(new Tuple<>(chunkCoords, - getDifferingTags(chunkTag, thisDimension, thisBiome))); - } - } - } - - private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - final List stuff = Lists.newLinkedList(); - stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) - .collect(Collectors.toList())); - stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) - .collect(Collectors.toList())); - return ImmutableList.copyOf(stuff); - } - - private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 - && diff.entriesOnlyOnRight().size() == 0; - } - - private void doBedrockRetrogen(final ChunkPos chunkCoords) { - if (retroChunks.contains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETRO_BEDROCK)) { - retroChunks.addLast(chunkCoords); - } - } - - private static World world; - private static ChunkProviderServer chunkProvider; - private static IChunkGenerator chunkGenerator; - private static Random random; - - private static void setupData(final World nw) { - if (world == null || !world.equals(nw)) { - world = nw; - } - - if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { - chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); - } - - if (chunkGenerator == null) { - chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, - chunkProvider, "field_186029_c", "chunkGenerator"); - } - - if (random == null) { - random = new Random(world.getSeed()); - } - - } - - private void runBits(final Tuple> tup) { - final ChunkPos p = tup.getFirst(); - final List spawns = tup.getSecond(); - - // re-seed with something totally new :P - random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) - ^ world.getSeed()); - spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, - chunkGenerator, chunkProvider, p)); - } - - @SubscribeEvent - public void worldTick(final WorldTickEvent ev) { - setupData(ev.world); - - if (ev.side != Side.SERVER) { - return; - } - - if (ev.phase == Phase.END) { - final Deque>> b = new LinkedList<>(); - for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { - b.push(chunks.pop()); - } - - b.forEach(this::runBits); - - for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { - final ChunkPos p = retroChunks.pop(); - OreSpawn.flatBedrock.retrogen(world, p.x, p.z); - } - } - } + private final Deque retroChunks; + private final Deque>> chunks; + // private Map> chunks + + EventHandlers() { + retroChunks = new ConcurrentLinkedDeque<>(); + chunks = new ConcurrentLinkedDeque<>(); + } + + private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, + EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, + EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, + EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); + + @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) + public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { + if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + && vanillaEvents.contains(event.getType())) { + event.setResult(Event.Result.DENY); + } + } + + @SubscribeEvent + public void onChunkSave(final ChunkDataEvent.Save ev) { + final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final NBTTagCompound features = new NBTTagCompound(); + + // save a list of the spawns that were configured and available - in this dimension - when + // the chunk + // was first generated. + + // collect that data + final int thisDimension = ev.getWorld().provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) + .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features + .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + dataTag.setTag(Constants.FEATURES_TAG, features); + + ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); + } + + private boolean dequeContains(final ChunkPos cc) { + return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) + .contains(true); + } + + @SubscribeEvent + public void onChunkLoad(final ChunkDataEvent.Load ev) { + final World clWorld = ev.getWorld(); + final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); + + doBedrockRetrogen(chunkCoords); + + if (dequeContains(chunkCoords)) { + return; + } + + if (Config.getBoolean(Constants.RETROGEN_KEY)) { + final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); + final int thisDimension = clWorld.provider.getDimension(); + final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); + final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); + + if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) + || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { + chunks.addLast(new Tuple<>(chunkCoords, + getDifferingTags(chunkTag, thisDimension, thisBiome))); + } + } + } + + private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + final MapDifference diff = Maps.difference(oldBits, currentBits); + + final List stuff = Lists.newLinkedList(); + stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); + stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) + .collect(Collectors.toList())); + return ImmutableList.copyOf(stuff); + } + + private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, + final Biome biome) { + final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); + final Map currentBits = new TreeMap<>(); + final Map oldBits = new TreeMap<>(); + + OreSpawn.API.getAllSpawns().entrySet().stream() + .filter(ent -> ent.getValue().dimensionAllowed(dim)) + .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits + .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); + + tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); + + final MapDifference diff = Maps.difference(oldBits, currentBits); + + return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 + && diff.entriesOnlyOnRight().size() == 0; + } + + private void doBedrockRetrogen(final ChunkPos chunkCoords) { + if (retroChunks.contains(chunkCoords)) { + return; + } + + if (Config.getBoolean(Constants.RETRO_BEDROCK)) { + retroChunks.addLast(chunkCoords); + } + } + + private static World world; + private static ChunkProviderServer chunkProvider; + private static IChunkGenerator chunkGenerator; + private static Random random; + + private static void setupData(final World nw) { + if (world == null || !world.equals(nw)) { + world = nw; + } + + if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { + chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); + } + + if (chunkGenerator == null) { + chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, + chunkProvider, "field_186029_c", "chunkGenerator"); + } + + if (random == null) { + random = new Random(world.getSeed()); + } + + } + + private void runBits(final Tuple> tup) { + final ChunkPos p = tup.getFirst(); + final List spawns = tup.getSecond(); + + // re-seed with something totally new :P + random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) + ^ world.getSeed()); + spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, + chunkGenerator, chunkProvider, p)); + } + + @SubscribeEvent + public void worldTick(final WorldTickEvent ev) { + setupData(ev.world); + + if (ev.side != Side.SERVER) { + return; + } + + if (ev.phase == Phase.END) { + final Deque>> b = new LinkedList<>(); + for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { + b.push(chunks.pop()); + } + + b.forEach(this::runBits); + + for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { + final ChunkPos p = retroChunks.pop(); + OreSpawn.flatBedrock.retrogen(world, p.x, p.z); + } + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 157278b9..8e85600f 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -39,71 +39,70 @@ */ @Mod(modid = Constants.MODID, - name = Constants.NAME, - version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,)", - certificateFingerprint = "@FINGERPRINT@") + name = Constants.NAME, + version = Constants.VERSION, + acceptedMinecraftVersions = "[1.12,)", + certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { - @Instance - public static OreSpawn instance; - - public static final Logger LOGGER = LogManager - .getFormatterLogger(Constants.MODID); - public static final OS3API API = new OS3APIImpl(); - static final EventHandlers eventHandlers = new EventHandlers(); - public static final FeatureRegistry FEATURES = new FeatureRegistry(); - protected static final Map> spawns = new HashMap<>(); - - static final FlatBedrock flatBedrock = new FlatBedrock(); - - public static Map> getSpawns() { - return spawns; - } - - @EventHandler - public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { - LOGGER.warn("Invalid fingerprint detected!"); - } - - @EventHandler - public void preInit(final FMLPreInitializationEvent ev) { - Config.loadConfig(); - - PluginLoader.INSTANCE.load(ev); - - if (Config.getBoolean(Constants.FLAT_BEDROCK)) { - GameRegistry.registerWorldGenerator(flatBedrock, 100); - } - - GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); - - if (Config.getBoolean(Constants.RETROGEN_KEY) - || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - || Config.getBoolean(Constants.RETRO_BEDROCK)) { - MinecraftForge.EVENT_BUS.register(eventHandlers); - MinecraftForge.ORE_GEN_BUS.register(eventHandlers); - } - } - - @EventHandler - public void init(final FMLInitializationEvent ev) { - PluginLoader.INSTANCE.register(); - - API.loadConfigFiles(); - } - - @EventHandler - public void postInit(final FMLPostInitializationEvent ev) { - Config.saveConfig(); - } - - @EventHandler - public void onServerStarting(final FMLServerStartingEvent ev) { - ev.registerServerCommand(new ClearChunkCommand()); - ev.registerServerCommand(new DumpBiomesCommand()); - ev.registerServerCommand(new AddOreCommand()); - ev.registerServerCommand(new WriteConfigsCommand()); - } + @Instance + public static OreSpawn instance; + + public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID); + public static final OS3API API = new OS3APIImpl(); + static final EventHandlers eventHandlers = new EventHandlers(); + public static final FeatureRegistry FEATURES = new FeatureRegistry(); + protected static final Map> spawns = new HashMap<>(); + + static final FlatBedrock flatBedrock = new FlatBedrock(); + + public static Map> getSpawns() { + return spawns; + } + + @EventHandler + public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { + LOGGER.warn("Invalid fingerprint detected!"); + } + + @EventHandler + public void preInit(final FMLPreInitializationEvent ev) { + Config.loadConfig(); + + PluginLoader.INSTANCE.load(ev); + + if (Config.getBoolean(Constants.FLAT_BEDROCK)) { + GameRegistry.registerWorldGenerator(flatBedrock, 100); + } + + GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); + + if (Config.getBoolean(Constants.RETROGEN_KEY) + || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) + || Config.getBoolean(Constants.RETRO_BEDROCK)) { + MinecraftForge.EVENT_BUS.register(eventHandlers); + MinecraftForge.ORE_GEN_BUS.register(eventHandlers); + } + } + + @EventHandler + public void init(final FMLInitializationEvent ev) { + PluginLoader.INSTANCE.register(); + + API.loadConfigFiles(); + } + + @EventHandler + public void postInit(final FMLPostInitializationEvent ev) { + Config.saveConfig(); + } + + @EventHandler + public void onServerStarting(final FMLServerStartingEvent ev) { + ev.registerServerCommand(new ClearChunkCommand()); + ev.registerServerCommand(new DumpBiomesCommand()); + ev.registerServerCommand(new AddOreCommand()); + ev.registerServerCommand(new WriteConfigsCommand()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java index 7dfb78dc..6870c78a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java @@ -9,12 +9,12 @@ public interface BiomeLocation { - boolean matches(Biome biome); + boolean matches(Biome biome); - JsonElement serialize(); + JsonElement serialize(); - default ImmutableList getBiomes() { - return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) - .collect(Collectors2.toImmutableList()); - } + default ImmutableList getBiomes() { + return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) + .collect(Collectors2.toImmutableList()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 0efe5dc6..0efa31fe 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -23,270 +23,270 @@ public class FeatureBase extends IForgeRegistryEntry.Impl { - private static final int MAX_CACHE_SIZE = 2048; - /** - * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk - * without triggering a chunk-load. - */ - private static final Map> overflowCache = new HashMap<>( - MAX_CACHE_SIZE); - private static final Deque cacheOrder = new LinkedList<>(); - protected Random random; - - public FeatureBase(final Random rand) { - this.random = rand; - } - - public boolean isValidBlock(final IBlockState oreBlock) { - return oreBlock.getBlock() != Blocks.AIR; - } - - protected void runCache(final int chunkX, final int chunkZ, final World world, - final ISpawnEntry spawnData) { - final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); - final Map cache = retrieveCache(chunkCoord); - - if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it - for (final Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), - world.provider.getDimension(), spawnData); - } - } - } - - protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); - return false; - } - - if (!isValidBlock(oreBlock)) { - return false; - } - - final Biome thisBiome = world.getBiome(coord); - - if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { - return false; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); - return false; - } - - return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, - spawnData); - } - - private BlockPos mungeFixYcoord(final BlockPos coord) { - if (coord.getY() < 0) { - final int newYCoord = coord.getY() * -1; - return new BlockPos(coord.getX(), newYCoord, coord.getZ()); - } else { - return new BlockPos(coord); - } - } - - private boolean spawnOrCache(final World world, final BlockPos coord, - final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, - final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { - if (world.isBlockLoaded(coord)) { - if (!isValidBlock(oreBlock)) { - return false; - } - - final IBlockState targetBlock = world.getBlockState(coord); - final Biome thisBiome = world.getBiome(coord); - - if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { - world.setBlockState(coord, oreBlock); - return true; - } else { - return false; - } - } else if (cacheOverflow) { - cacheOverflowBlock(oreBlock, coord, dimension); - return true; - } - - return false; - } - - private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); - return; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); - return; - } - - spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); - } - - private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, - final int dimension) { - final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); - - if (overflowCache.containsKey(chunkCoord)) { - cacheOrder.addLast(chunkCoord); - - if (cacheOrder.size() > MAX_CACHE_SIZE) { - final Vec3i drop = cacheOrder.removeFirst(); - overflowCache.get(drop).clear(); - overflowCache.remove(drop); - } - - overflowCache.put(chunkCoord, new HashMap<>()); - } - - final Map cache = overflowCache.getOrDefault(chunkCoord, - new HashMap<>()); - cache.put(coord, bs); - } - - private Map retrieveCache(final Vec3i chunkCoord) { - if (overflowCache.containsKey(chunkCoord)) { - final Map cache = overflowCache.get(chunkCoord); - cacheOrder.remove(chunkCoord); - overflowCache.remove(chunkCoord); - return cache; - } else { - return Collections.emptyMap(); - } - } - - protected void scramble(final int[] target, final Random prng) { - for (int i = target.length - 1; i > 0; i--) { - final int n = prng.nextInt(i); - final int temp = target[i]; - target[i] = target[n]; - target[n] = temp; - } - } - - protected static final Vec3i[] offsets_small = { - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), - - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) - }; - - protected static final Vec3i[] offsets = { - new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), - new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), - new Vec3i(1, 1, -1), - - new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), - new Vec3i(1, 1, 0), - - new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), - new Vec3i(1, 1, 1) - }; - - protected static final int[] offsetIndexRef = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26 - }; - protected static final int[] offsetIndexRef_small = { - 0, 1, 2, 3, 4, 5, 6, 7 - }; - - protected static void mergeDefaults(final JsonObject parameters, - final JsonObject defaultParameters) { - defaultParameters.entrySet().forEach(entry -> { - if (!parameters.has(entry.getKey())) { - parameters.add(entry.getKey(), entry.getValue()); - } - }); - } - - private double triangularDistribution(final double a, final double b, final double c) { - final double base = (c - a) / (b - a); - final double rand = this.random.nextDouble(); - - if (rand < base) { - return a + Math.sqrt(rand * (b - a) * (c - a)); - } else { - return b - Math.sqrt((1 - rand) * (b - a) * (b - c)); - } - } - - protected int getPoint(final int lowerBound, final int upperBound, final int median) { - final int t = (int) Math.round( - triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); - return t - median; - } - - protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { - for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } - if (quantity <= 0) { - return; - } - } - } - } - } - - protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dz = (int) (-1 * radius); dz < radius; dz++) { - for (int dx = (int) (-1 * radius); dx < radius; dx++) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } - if (quantity <= 0) { - return; - } - } - } - } - } - - protected int getABC(final int dx, final int dy, final int dz) { - return (dx * dx + dy * dy + dz * dz); - } - - protected int countItem(final int dx, final boolean toPositive) { - return toPositive ? dx + 1 : dx - 1; - } - - protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { - return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); - } - - protected int getStart(final boolean toPositive, final double radius) { - return ((int) (radius * (toPositive ? 1 : -1))); - } + private static final int MAX_CACHE_SIZE = 2048; + /** + * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk + * without triggering a chunk-load. + */ + private static final Map> overflowCache = new HashMap<>( + MAX_CACHE_SIZE); + private static final Deque cacheOrder = new LinkedList<>(); + protected Random random; + + public FeatureBase(final Random rand) { + this.random = rand; + } + + public boolean isValidBlock(final IBlockState oreBlock) { + return oreBlock.getBlock() != Blocks.AIR; + } + + protected void runCache(final int chunkX, final int chunkZ, final World world, + final ISpawnEntry spawnData) { + final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); + final Map cache = retrieveCache(chunkCoord); + + if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it + for (final Entry ent : cache.entrySet()) { + spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), + world.provider.getDimension(), spawnData); + } + } + } + + protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { + if (oreBlock == null) { + OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + return false; + } + + if (!isValidBlock(oreBlock)) { + return false; + } + + final Biome thisBiome = world.getBiome(coord); + + if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { + return false; + } + + final BlockPos np = mungeFixYcoord(coord); + + if (coord.getY() >= world.getHeight()) { + OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + return false; + } + + return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, + spawnData); + } + + private BlockPos mungeFixYcoord(final BlockPos coord) { + if (coord.getY() < 0) { + final int newYCoord = coord.getY() * -1; + return new BlockPos(coord.getX(), newYCoord, coord.getZ()); + } else { + return new BlockPos(coord); + } + } + + private boolean spawnOrCache(final World world, final BlockPos coord, + final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, + final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { + if (world.isBlockLoaded(coord)) { + if (!isValidBlock(oreBlock)) { + return false; + } + + final IBlockState targetBlock = world.getBlockState(coord); + final Biome thisBiome = world.getBiome(coord); + + if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { + world.setBlockState(coord, oreBlock); + return true; + } else { + return false; + } + } else if (cacheOverflow) { + cacheOverflowBlock(oreBlock, coord, dimension); + return true; + } + + return false; + } + + private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, + final int dimension, final ISpawnEntry spawnData) { + if (oreBlock == null) { + OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + return; + } + + final BlockPos np = mungeFixYcoord(coord); + + if (coord.getY() >= world.getHeight()) { + OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + return; + } + + spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); + } + + private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, + final int dimension) { + final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); + + if (overflowCache.containsKey(chunkCoord)) { + cacheOrder.addLast(chunkCoord); + + if (cacheOrder.size() > MAX_CACHE_SIZE) { + final Vec3i drop = cacheOrder.removeFirst(); + overflowCache.get(drop).clear(); + overflowCache.remove(drop); + } + + overflowCache.put(chunkCoord, new HashMap<>()); + } + + final Map cache = overflowCache.getOrDefault(chunkCoord, + new HashMap<>()); + cache.put(coord, bs); + } + + private Map retrieveCache(final Vec3i chunkCoord) { + if (overflowCache.containsKey(chunkCoord)) { + final Map cache = overflowCache.get(chunkCoord); + cacheOrder.remove(chunkCoord); + overflowCache.remove(chunkCoord); + return cache; + } else { + return Collections.emptyMap(); + } + } + + protected void scramble(final int[] target, final Random prng) { + for (int i = target.length - 1; i > 0; i--) { + final int n = prng.nextInt(i); + final int temp = target[i]; + target[i] = target[n]; + target[n] = temp; + } + } + + protected static final Vec3i[] offsets_small = { + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), + + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) + }; + + protected static final Vec3i[] offsets = { + new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), + new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), + new Vec3i(1, 1, -1), + + new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), + new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), + new Vec3i(1, 1, 0), + + new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), + new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), + new Vec3i(1, 1, 1) + }; + + protected static final int[] offsetIndexRef = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26 + }; + protected static final int[] offsetIndexRef_small = { + 0, 1, 2, 3, 4, 5, 6, 7 + }; + + protected static void mergeDefaults(final JsonObject parameters, + final JsonObject defaultParameters) { + defaultParameters.entrySet().forEach(entry -> { + if (!parameters.has(entry.getKey())) { + parameters.add(entry.getKey(), entry.getValue()); + } + }); + } + + private double triangularDistribution(final double a, final double b, final double c) { + final double base = (c - a) / (b - a); + final double rand = this.random.nextDouble(); + + if (rand < base) { + return a + Math.sqrt(rand * (b - a) * (c - a)); + } else { + return b - Math.sqrt((1 - rand) * (b - a) * (b - c)); + } + } + + protected int getPoint(final int lowerBound, final int upperBound, final int median) { + final int t = (int) Math.round( + triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); + return t - median; + } + + protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { + final Random prng = this.random; + int quantity = count; + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { + for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); + quantity--; + } + if (quantity <= 0) { + return; + } + } + } + } + } + + protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, + final double radius, final ISpawnEntry spawnData, final int count) { + final Random prng = this.random; + int quantity = count; + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dz = (int) (-1 * radius); dz < radius; dz++) { + for (int dx = (int) (-1 * radius); dx < radius; dx++) { + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); + quantity--; + } + if (quantity <= 0) { + return; + } + } + } + } + } + + protected int getABC(final int dx, final int dy, final int dz) { + return (dx * dx + dy * dy + dz * dz); + } + + protected int countItem(final int dx, final boolean toPositive) { + return toPositive ? dx + 1 : dx - 1; + } + + protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { + return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); + } + + protected int getStart(final boolean toPositive, final double radius) { + return ((int) (radius * (toPositive ? 1 : -1))); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java index 86b35071..26e12bb6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java @@ -8,13 +8,13 @@ public interface IBlockList { - void addBlock(IBlockDefinition block); + void addBlock(IBlockDefinition block); - IBlockState getRandomBlock(Random rand); + IBlockState getRandomBlock(Random rand); - void startNewSpawn(); + void startNewSpawn(); - void dump(); + void dump(); - int count(); + int count(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java index 034ecd46..11564819 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java @@ -4,9 +4,9 @@ public interface IDimensionList { - JsonObject serialize(); + JsonObject serialize(); - default boolean matches(int dimensionId) { - return false; - } + default boolean matches(int dimensionId) { + return false; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java index ac6bc4ec..82f04a60 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java @@ -13,10 +13,10 @@ public interface IFeature extends IForgeRegistryEntry { - void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawn, ChunkPos pos); + void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, + ISpawnEntry spawn, ChunkPos pos); - void setRandom(Random rand); + void setRandom(Random rand); - JsonObject getDefaultParameters(); + JsonObject getDefaultParameters(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index e864edcf..e45b98a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -2,20 +2,20 @@ public class BadValueException extends Exception { - private static final long serialVersionUID = 1143938140559149506L; - private final String keyName; - private final String keyValue; + private static final long serialVersionUID = 1143938140559149506L; + private final String keyName; + private final String keyValue; - public BadValueException(final String keyName, final String keyValue) { - super(); - this.keyName = keyName; - this.keyValue = keyValue; - } + public BadValueException(final String keyName, final String keyValue) { + super(); + this.keyName = keyName; + this.keyValue = keyValue; + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, - baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, + baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java index 70623e44..8c98fffa 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java @@ -2,9 +2,9 @@ public class MissingVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = -4306852267351590384L; + /** + * + */ + private static final long serialVersionUID = -4306852267351590384L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java index c959466f..2f31a433 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java @@ -2,9 +2,9 @@ public class NotAProperConfigException extends Exception { - /** - * - */ - private static final long serialVersionUID = -7748241590958198482L; + /** + * + */ + private static final long serialVersionUID = -7748241590958198482L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java index 39c8da6a..62b5fa71 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java @@ -2,9 +2,9 @@ public class OldVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = 3760017140789193369L; + /** + * + */ + private static final long serialVersionUID = 3760017140789193369L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 6aaa81cf..9cf2b4ad 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -2,17 +2,17 @@ public class UnknownFieldException extends Exception { - private static final long serialVersionUID = 1L; - private final String message; + private static final long serialVersionUID = 1L; + private final String message; - public UnknownFieldException(final String theField) { - super(); - this.message = String.format("Unkown field %s in config", theField); - } + public UnknownFieldException(final String theField) { + super(); + this.message = String.format("Unkown field %s in config", theField); + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("%s%n%s", this.message, baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("%s%n%s", this.message, baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 79973b0b..8e5b6049 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -2,20 +2,20 @@ public class UnknownNameException extends Exception { - private static final long serialVersionUID = -3426121906665390773L; - private final String fieldName; - private final String fieldValue; + private static final long serialVersionUID = -3426121906665390773L; + private final String fieldName; + private final String fieldValue; - public UnknownNameException(final String fieldName, final String fieldValue) { - super(); - this.fieldName = fieldName; - this.fieldValue = fieldValue; - } + public UnknownNameException(final String fieldName, final String fieldValue) { + super(); + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, - baseMessage); - } + @Override + public String getMessage() { + final String baseMessage = super.getMessage(); + return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, + baseMessage); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java index 53e9ac3a..fa369ca9 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java @@ -2,9 +2,9 @@ public class UnknownVersionException extends Exception { - /** - * - */ - private static final long serialVersionUID = 3817238409227005355L; + /** + * + */ + private static final long serialVersionUID = 3817238409227005355L; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java index f622e22e..1bda5db5 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java @@ -7,19 +7,19 @@ public interface IBiomeBuilder { - IBiomeBuilder addWhitelistEntry(Biome biome); + IBiomeBuilder addWhitelistEntry(Biome biome); - IBiomeBuilder addWhitelistEntry(String biomeName); + IBiomeBuilder addWhitelistEntry(String biomeName); - IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); + IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); - IBiomeBuilder addBlacklistEntry(Biome biome); + IBiomeBuilder addBlacklistEntry(Biome biome); - IBiomeBuilder addBlacklistEntry(String biomeName); + IBiomeBuilder addBlacklistEntry(String biomeName); - IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); + IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); - IBiomeBuilder setAcceptAll(); + IBiomeBuilder setAcceptAll(); - BiomeLocation create(); + BiomeLocation create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java index 226ea16c..54baec34 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java @@ -6,154 +6,154 @@ public interface IBlockBuilder { - /** - * - * @param blockState - * @return - */ - IBlockBuilder setFromBlockState(IBlockState blockState); - - /** - * - * @param block - * @return - */ - IBlockBuilder setFromBlock(Block block); - - /** - * - * @param blockName - * @return - */ - IBlockBuilder setFromName(String blockName); - - /** - * - * @param blockName - * @param state - * @return - */ - IBlockBuilder setFromName(String blockName, String state); - - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(String blockName, int metadata); - - /** - * - * @param blockResourceLocation - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation); - - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); - - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); - - /** - * - * @param blockState - * @param chance - * @return - */ - IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); - - /** - * - * @param block - * @param chance - * @return - */ - IBlockBuilder setFromBlockWithChance(Block block, int chance); - - /** - * - * @param blockName - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, int chance); - - /** - * - * @param blockName - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); - - /** - * - * @param blockName - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); - - /** - * - * @param blockResourceLocation - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); - - /** - * - * @param blockResourceLocation - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, - int chance); - - /** - * - * @param blockResourceLocation - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, - int chance); - - /** - * - * @param chance - * @return - */ - IBlockBuilder setChance(int chance); - - /** - * - * @return - */ - IBlockDefinition create(); + /** + * + * @param blockState + * @return + */ + IBlockBuilder setFromBlockState(IBlockState blockState); + + /** + * + * @param block + * @return + */ + IBlockBuilder setFromBlock(Block block); + + /** + * + * @param blockName + * @return + */ + IBlockBuilder setFromName(String blockName); + + /** + * + * @param blockName + * @param state + * @return + */ + IBlockBuilder setFromName(String blockName, String state); + + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromName(String blockName, int metadata); + + /** + * + * @param blockResourceLocation + * @return + */ + IBlockBuilder setFromName(ResourceLocation blockResourceLocation); + + /** + * + * @param blockResourceLocation + * @param state + * @return + */ + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); + + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); + + /** + * + * @param blockState + * @param chance + * @return + */ + IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); + + /** + * + * @param block + * @param chance + * @return + */ + IBlockBuilder setFromBlockWithChance(Block block, int chance); + + /** + * + * @param blockName + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(String blockName, int chance); + + /** + * + * @param blockName + * @param state + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); + + /** + * + * @param blockName + * @param metadata + * @param chance + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); + + /** + * + * @param blockResourceLocation + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); + + /** + * + * @param blockResourceLocation + * @param state + * @param chance + * @return + */ + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, + int chance); + + /** + * + * @param blockResourceLocation + * @param metadata + * @param chance + * @return + * @deprecated + */ + @Deprecated + IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, + int chance); + + /** + * + * @param chance + * @return + */ + IBlockBuilder setChance(int chance); + + /** + * + * @return + */ + IBlockDefinition create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java index 1cb48858..03bec55b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java @@ -4,11 +4,11 @@ public interface IBlockDefinition { - IBlockState getBlock(); + IBlockState getBlock(); - int getChance(); + int getChance(); - default boolean isValid() { - return true; - } + default boolean isValid() { + return true; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java index 9d178ecf..1fe97bb7 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java @@ -4,15 +4,15 @@ public interface IDimensionBuilder { - IDimensionBuilder addWhitelistEntry(int dimensionID); + IDimensionBuilder addWhitelistEntry(int dimensionID); - IDimensionBuilder addBlacklistEntry(int dimensionID); + IDimensionBuilder addBlacklistEntry(int dimensionID); - IDimensionBuilder setAcceptAll(); + IDimensionBuilder setAcceptAll(); - IDimensionBuilder setDenyAll(); + IDimensionBuilder setDenyAll(); - IDimensionBuilder setAcceptAllOverworld(); + IDimensionBuilder setAcceptAllOverworld(); - IDimensionList create(); + IDimensionList create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java index 111b7a1b..20fefa25 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java @@ -7,23 +7,23 @@ public interface IFeatureBuilder { - IFeatureBuilder setFeature(String featureName); + IFeatureBuilder setFeature(String featureName); - IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); + IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); - IFeatureBuilder setFeature(IFeature feature); + IFeatureBuilder setFeature(IFeature feature); - IFeatureBuilder setParameter(String parameterName, String parameterValue); + IFeatureBuilder setParameter(String parameterName, String parameterValue); - IFeatureBuilder setParameter(String parameterName, int parameterValue); + IFeatureBuilder setParameter(String parameterName, int parameterValue); - IFeatureBuilder setParameter(String parameterName, float parameterValue); + IFeatureBuilder setParameter(String parameterName, float parameterValue); - IFeatureBuilder setParameter(String parameterName, boolean parameterValue); + IFeatureBuilder setParameter(String parameterName, boolean parameterValue); - IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); + IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); - IFeatureBuilder setUseFeatureDefaults(); + IFeatureBuilder setUseFeatureDefaults(); - IFeatureEntry create(); + IFeatureEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java index ef9c1d94..6f5fb06b 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java @@ -5,17 +5,17 @@ public interface IFeatureEntry { - IFeature getFeature(); + IFeature getFeature(); - String getFeatureName(); + String getFeatureName(); - JsonObject getFeatureParameters(); + JsonObject getFeatureParameters(); - void setParameter(String parameterName, String parameterValue); + void setParameter(String parameterName, String parameterValue); - void setParameter(String parameterName, int parameterValue); + void setParameter(String parameterName, int parameterValue); - void setParameter(String parameterName, boolean parameterValue); + void setParameter(String parameterName, boolean parameterValue); - void setParameter(String parameterName, float parameterValue); + void setParameter(String parameterName, float parameterValue); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java index a1055ae5..ecf91e74 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java @@ -5,78 +5,78 @@ public interface IReplacementBuilder { - /** - * - * @param entryName - * @return - */ - IReplacementBuilder setFromName(String entryName); + /** + * + * @param entryName + * @return + */ + IReplacementBuilder setFromName(String entryName); - /** - * - * @param name - * @return - */ - IReplacementBuilder setName(String name); + /** + * + * @param name + * @return + */ + IReplacementBuilder setName(String name); - /** - * - * @param blockState - * @return - */ - IReplacementBuilder addEntry(IBlockState blockState); + /** + * + * @param blockState + * @return + */ + IReplacementBuilder addEntry(IBlockState blockState); - /** - * - * @param blockName - * @return - */ - IReplacementBuilder addEntry(String blockName); + /** + * + * @param blockName + * @return + */ + IReplacementBuilder addEntry(String blockName); - /** - * - * @param blockName - * @param state - * @return - */ - IReplacementBuilder addEntry(String blockName, String state); + /** + * + * @param blockName + * @param state + * @return + */ + IReplacementBuilder addEntry(String blockName, String state); - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(String blockName, int metadata); + /** + * + * @param blockName + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IReplacementBuilder addEntry(String blockName, int metadata); - /** - * - * @param blockResourceLocation - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); + /** + * + * @param blockResourceLocation + * @return + */ + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); + /** + * + * @param blockResourceLocation + * @param state + * @return + */ + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); + /** + * + * @param blockResourceLocation + * @param metadata + * @return + * @deprecated + */ + @Deprecated + IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); - boolean hasEntries(); + boolean hasEntries(); - IReplacementEntry create(); + IReplacementEntry create(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java index b58c5ed7..e9f03f91 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java @@ -7,7 +7,7 @@ public interface IReplacementEntry extends IForgeRegistryEntry { - OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - List getEntries(); + List getEntries(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java index c2772e1d..3808d61a 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java @@ -9,55 +9,55 @@ public interface ISpawnBuilder { - ISpawnBuilder setName(String name); + ISpawnBuilder setName(String name); - ISpawnBuilder setDimensions(IDimensionList dimensions); + ISpawnBuilder setDimensions(IDimensionList dimensions); - ISpawnBuilder setBiomes(BiomeLocation biomes); + ISpawnBuilder setBiomes(BiomeLocation biomes); - ISpawnBuilder setEnabled(boolean enabled); + ISpawnBuilder setEnabled(boolean enabled); - ISpawnBuilder setRetrogen(boolean retrogen); + ISpawnBuilder setRetrogen(boolean retrogen); - ISpawnBuilder setReplacement(IReplacementEntry replacements); + ISpawnBuilder setReplacement(IReplacementEntry replacements); - ISpawnBuilder setFeature(IFeatureEntry feature); + ISpawnBuilder setFeature(IFeatureEntry feature); - ISpawnBuilder addBlock(String blockName); + ISpawnBuilder addBlock(String blockName); - ISpawnBuilder addBlock(String blockName, String blockState); + ISpawnBuilder addBlock(String blockName, String blockState); - ISpawnBuilder addBlock(String blockName, int blockMetadata); + ISpawnBuilder addBlock(String blockName, int blockMetadata); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); + ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); - ISpawnBuilder addBlock(Block block); + ISpawnBuilder addBlock(Block block); - ISpawnBuilder addBlock(IBlockState block); + ISpawnBuilder addBlock(IBlockState block); - ISpawnBuilder addBlockWithChance(String blockName, int chance); + ISpawnBuilder addBlockWithChance(String blockName, int chance); - ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); + ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); - ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); + ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, - int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, + int chance); - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, - int chance); + ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, + int chance); - ISpawnBuilder addBlockWithChance(Block block, int chance); + ISpawnBuilder addBlockWithChance(Block block, int chance); - ISpawnBuilder addBlockWithChance(IBlockState block, int chance); + ISpawnBuilder addBlockWithChance(IBlockState block, int chance); - ISpawnEntry create(); + ISpawnEntry create(); - ISpawnBuilder addBlock(IBlockDefinition block); + ISpawnBuilder addBlock(IBlockDefinition block); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java index 9361b074..7fdaceb4 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java @@ -15,32 +15,32 @@ public interface ISpawnEntry { - default boolean isEnabled() { - return false; - } + default boolean isEnabled() { + return false; + } - default boolean isRetrogen() { - return false; - } + default boolean isRetrogen() { + return false; + } - String getSpawnName(); + String getSpawnName(); - boolean dimensionAllowed(int dimension); + boolean dimensionAllowed(int dimension); - boolean biomeAllowed(ResourceLocation biomeName); + boolean biomeAllowed(ResourceLocation biomeName); - boolean biomeAllowed(Biome biome); + boolean biomeAllowed(Biome biome); - IFeatureEntry getFeature(); + IFeatureEntry getFeature(); - OreSpawnBlockMatcher getMatcher(); + OreSpawnBlockMatcher getMatcher(); - IBlockList getBlocks(); + IBlockList getBlocks(); - void generate(Random random, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider, ChunkPos pos); + void generate(Random random, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider, ChunkPos pos); - IDimensionList getDimensions(); + IDimensionList getDimensions(); - BiomeLocation getBiomes(); + BiomeLocation getBiomes(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index 00fab9cd..aba87455 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -12,55 +12,55 @@ public interface OS3API { - void addSpawn(ISpawnEntry spawnEntry); + void addSpawn(ISpawnEntry spawnEntry); - void addFeature(String featureName, IFeature feature); + void addFeature(String featureName, IFeature feature); - void addReplacement(IReplacementEntry replacementEntry); + void addReplacement(IReplacementEntry replacementEntry); - Map getReplacements(); + Map getReplacements(); - IReplacementEntry getReplacement(String replacementName); + IReplacementEntry getReplacement(String replacementName); - List getSpawns(int dimensionID); + List getSpawns(int dimensionID); - ISpawnEntry getSpawn(String spawnName); + ISpawnEntry getSpawn(String spawnName); - Map getAllSpawns(); + Map getAllSpawns(); - List getDimensionDefaultReplacements(int dimensionID); + List getDimensionDefaultReplacements(int dimensionID); - ISpawnBuilder getSpawnBuilder(); + ISpawnBuilder getSpawnBuilder(); - IDimensionBuilder getDimensionBuilder(); + IDimensionBuilder getDimensionBuilder(); - IFeatureBuilder getFeatureBuilder(); + IFeatureBuilder getFeatureBuilder(); - IBlockBuilder getBlockBuilder(); + IBlockBuilder getBlockBuilder(); - IBiomeBuilder getBiomeBuilder(); + IBiomeBuilder getBiomeBuilder(); - IReplacementBuilder getReplacementBuilder(); + IReplacementBuilder getReplacementBuilder(); - boolean featureExists(String featureName); + boolean featureExists(String featureName); - boolean featureExists(ResourceLocation featureName); + boolean featureExists(ResourceLocation featureName); - IFeature getFeature(String featureName); + IFeature getFeature(String featureName); - IFeature getFeature(ResourceLocation featureName); + IFeature getFeature(ResourceLocation featureName); - PresetsStorage copyPresets(); + PresetsStorage copyPresets(); - void loadConfigFiles(); + void loadConfigFiles(); - boolean hasReplacement(ResourceLocation resourceLocation); + boolean hasReplacement(ResourceLocation resourceLocation); - boolean hasReplacement(String name); + boolean hasReplacement(String name); - void mapEntryToFile(Path p, String entryName); + void mapEntryToFile(Path p, String entryName); - List getSpawnsForFile(String fileName); + List getSpawnsForFile(String fileName); - Map> getSpawnsByFile(); + Map> getSpawnsByFile(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index ef5a5804..ffba56f6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -15,38 +15,38 @@ public class OreSpawnBlockMatcher implements Predicate { - private final List possibles; - - public OreSpawnBlockMatcher(final IBlockState... matches) { - this.possibles = Arrays.asList(matches); - } - - public OreSpawnBlockMatcher(final List matches) { - this.possibles = new ArrayList<>(); - this.possibles.addAll(matches); - } - - private boolean has(final IBlockState bs) { - return this.possibles.stream().filter(bs::equals).count() > 0; - } - - public boolean test(final IBlockState other) { - return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); - } - - public JsonArray serialize() { - final JsonArray rv = new JsonArray(); - - possibles.stream().forEach(bs -> { - final JsonObject t = new JsonObject(); - t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); - if (!bs.equals(bs.getBlock().getDefaultState())) { - final String state = StateUtil.serializeState(bs); - t.addProperty(Constants.ConfigNames.STATE, state); - } - rv.add(t); - }); - - return rv; - } + private final List possibles; + + public OreSpawnBlockMatcher(final IBlockState... matches) { + this.possibles = Arrays.asList(matches); + } + + public OreSpawnBlockMatcher(final List matches) { + this.possibles = new ArrayList<>(); + this.possibles.addAll(matches); + } + + private boolean has(final IBlockState bs) { + return this.possibles.stream().filter(bs::equals).count() > 0; + } + + public boolean test(final IBlockState other) { + return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); + } + + public JsonArray serialize() { + final JsonArray rv = new JsonArray(); + + possibles.stream().forEach(bs -> { + final JsonObject t = new JsonObject(); + t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); + if (!bs.equals(bs.getBlock().getDefaultState())) { + final String state = StateUtil.serializeState(bs); + t.addProperty(Constants.ConfigNames.STATE, state); + } + rv.add(t); + }); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java index 8ffefb38..d3b0bf7c 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java @@ -4,5 +4,5 @@ public interface IOreSpawnPlugin { - void register(OS3API apiInterface); + void register(OS3API apiInterface); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java index 700ce86e..7120c8be 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java @@ -10,15 +10,15 @@ @Target(TYPE) public @interface OreSpawnPlugin { - // the Mod this is for - will be used for - // generating the name of the json the config - // will get saved to and should also be the - // actual mod-id we can use for creating a - // resource location - String modid(); + // the Mod this is for - will be used for + // generating the name of the json the config + // will get saved to and should also be the + // actual mod-id we can use for creating a + // resource location + String modid(); - // resource location segment to look in - // for registered config files + // resource location segment to look in + // for registered config files - String resourcePath() default "orespawn"; + String resourcePath() default "orespawn"; } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index 8576c8c6..2d23b41f 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -31,134 +31,134 @@ public enum PluginLoader { - INSTANCE; - - private class PluginData { - - public final String modId; - public final String resourcePath; - public final IOreSpawnPlugin plugin; - - PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { - this.modId = modId; - this.resourcePath = resourcePath; - this.plugin = plugin; - } - } - - private static List dataStore = new ArrayList<>(); - - private String getAnnotationItem(final String item, final ASMData asmData) { - if (asmData.getAnnotationInfo().get(item) != null) { - return asmData.getAnnotationInfo().get(item).toString(); - } else { - return ""; - } - } - - public void load(final FMLPreInitializationEvent event) { - for (final ASMData asmDataItem : event.getAsmData() - .getAll(OreSpawnPlugin.class.getCanonicalName())) { - final String modId = getAnnotationItem("modid", asmDataItem); - final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); - final String clazz = asmDataItem.getClassName(); - IOreSpawnPlugin integration; - - try { - integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); - final PluginData pd = new PluginData(modId, resourceBase, integration); - dataStore.add(pd); - } catch (final Exception ex) { - OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); - } - } - } - - public void register() { - dataStore.forEach(pd -> { - scanResources(pd); - pd.plugin.register(OreSpawn.API); - }); - } - - public void scanResources(final PluginData pd) { - if (Config.getKnownMods().contains(pd.modId)) { - return; - } - - final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); - final URL resURL = getClass().getClassLoader().getResource(base); - - if (resURL == null) { - OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", - base); - return; - } - - URI uri; - - try { - uri = resURL.toURI(); - } catch (URISyntaxException ex) { - CrashReport report = CrashReport.makeCrashReport(ex, - String.format("Failed to get URI for %s", - (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - return; - } - - if (uri.getScheme().equals("jar")) { - try (FileSystem fileSystem = FileSystems.newFileSystem(uri, - Collections.emptyMap())) { - copyout(fileSystem.getPath(base), pd.modId); - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Failed in getting FileSystem handler set up for %s", uri.getPath())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } else { - copyout(Paths.get(uri), pd.modId); - } - - Config.addKnownMod(pd.modId); - } - - private void copyout(final Path myPath, final String modId) { - try (Stream walk = Files.walk(myPath, 1)) { - for (final Iterator it = walk.iterator(); it.hasNext();) { - final Path p = it.next(); - final String name = p.getFileName().toString(); - - if ("json".equals(FilenameUtils.getExtension(name))) { - InputStream reader = null; - Path target; - - if ("_features".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format("features-%s.json", modId)); - } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format("replacements-%s.json", modId)); - } else { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - String.format("%s.json", modId)); - } - - if (!target.toFile().exists()) { - reader = Files.newInputStream(p); - FileUtils.copyInputStreamToFile(reader, target.toFile()); - IOUtils.closeQuietly(reader); - } - } - } - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Faulted while iterating %s for config files or copying them out", myPath)); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.error(report.getCompleteReport()); - } - } + INSTANCE; + + private class PluginData { + + public final String modId; + public final String resourcePath; + public final IOreSpawnPlugin plugin; + + PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { + this.modId = modId; + this.resourcePath = resourcePath; + this.plugin = plugin; + } + } + + private static List dataStore = new ArrayList<>(); + + private String getAnnotationItem(final String item, final ASMData asmData) { + if (asmData.getAnnotationInfo().get(item) != null) { + return asmData.getAnnotationInfo().get(item).toString(); + } else { + return ""; + } + } + + public void load(final FMLPreInitializationEvent event) { + for (final ASMData asmDataItem : event.getAsmData() + .getAll(OreSpawnPlugin.class.getCanonicalName())) { + final String modId = getAnnotationItem("modid", asmDataItem); + final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); + final String clazz = asmDataItem.getClassName(); + IOreSpawnPlugin integration; + + try { + integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); + final PluginData pd = new PluginData(modId, resourceBase, integration); + dataStore.add(pd); + } catch (final Exception ex) { + OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); + } + } + } + + public void register() { + dataStore.forEach(pd -> { + scanResources(pd); + pd.plugin.register(OreSpawn.API); + }); + } + + public void scanResources(final PluginData pd) { + if (Config.getKnownMods().contains(pd.modId)) { + return; + } + + final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); + final URL resURL = getClass().getClassLoader().getResource(base); + + if (resURL == null) { + OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", + base); + return; + } + + URI uri; + + try { + uri = resURL.toURI(); + } catch (URISyntaxException ex) { + CrashReport report = CrashReport.makeCrashReport(ex, + String.format("Failed to get URI for %s", + (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + return; + } + + if (uri.getScheme().equals("jar")) { + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, + Collections.emptyMap())) { + copyout(fileSystem.getPath(base), pd.modId); + } catch (IOException exc) { + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Failed in getting FileSystem handler set up for %s", uri.getPath())); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } else { + copyout(Paths.get(uri), pd.modId); + } + + Config.addKnownMod(pd.modId); + } + + private void copyout(final Path myPath, final String modId) { + try (Stream walk = Files.walk(myPath, 1)) { + for (final Iterator it = walk.iterator(); it.hasNext();) { + final Path p = it.next(); + final String name = p.getFileName().toString(); + + if ("json".equals(FilenameUtils.getExtension(name))) { + InputStream reader = null; + Path target; + + if ("_features".equals(FilenameUtils.getBaseName(name))) { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("features-%s.json", modId)); + } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + Constants.FileBits.SYSCONF, + String.format("replacements-%s.json", modId)); + } else { + target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, + String.format("%s.json", modId)); + } + + if (!target.toFile().exists()) { + reader = Files.newInputStream(p); + FileUtils.copyInputStreamToFile(reader, target.toFile()); + IOUtils.closeQuietly(reader); + } + } + } + } catch (IOException exc) { + CrashReport report = CrashReport.makeCrashReport(exc, String.format( + "Faulted while iterating %s for config files or copying them out", myPath)); + report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); + OreSpawn.LOGGER.error(report.getCompleteReport()); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index ae91f018..8ec4a687 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -26,86 +26,86 @@ public class AddOreCommand extends CommandBase { - @Override - public String getName() { - return "addore"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/addore "; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { - throw new CommandException("Only players can use this command"); - } - - final EntityPlayer player = (EntityPlayer) sender; - final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); - - if (stack == null) { - throw new CommandException("You have no item in your main hand"); - } else if (!(stack.getItem() instanceof ItemBlock)) { - throw new CommandException("The item in your main hand isn't a block"); - } else if (args.length < 2) { - throw new CommandException(this.getUsage(sender)); - } - - final String file = args[0]; - @SuppressWarnings("deprecation") - final IBlockState state = Block.getBlockFromItem(stack.getItem()) - .getStateFromMeta(stack.getItemDamage()); - - final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); - final JsonParser p = new JsonParser(); - final JsonElement parsed = mergeDefaults(p.parse(rawData), state); - OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); - OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); - } - - private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { - final JsonObject work = parse.getAsJsonObject(); - final JsonObject emptyBlacklist = new JsonObject(); - emptyBlacklist.add("excludes", new JsonArray()); - - if (!work.has(ConfigNames.ENABLED)) { - work.addProperty(ConfigNames.ENABLED, true); - } - if (!work.has(ConfigNames.RETROGEN)) { - work.addProperty(ConfigNames.RETROGEN, false); - } - if (!work.has(ConfigNames.FEATURE)) { - work.addProperty(ConfigNames.FEATURE, "default"); - } - if (!work.has(ConfigNames.REPLACEMENT)) { - work.addProperty(ConfigNames.REPLACEMENT, "default"); - } - if (!work.has(ConfigNames.PARAMETERS)) { - work.add(ConfigNames.PARAMETERS, - OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) - .getDefaultParameters()); - } - if (!work.has(ConfigNames.DIMENSIONS)) { - work.add(ConfigNames.DIMENSIONS, emptyBlacklist); - } - if (!work.has(ConfigNames.BIOMES)) { - work.add(ConfigNames.BIOMES, emptyBlacklist); - } - - final JsonObject block = new JsonObject(); - block.addProperty(ConfigNames.CHANCE, 100); - block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); - block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); - work.add(ConfigNames.BLOCK, block); - - return work; - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + @Override + public String getName() { + return "addore"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/addore "; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + if (!(sender instanceof EntityPlayer)) { + throw new CommandException("Only players can use this command"); + } + + final EntityPlayer player = (EntityPlayer) sender; + final ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); + + if (stack == null) { + throw new CommandException("You have no item in your main hand"); + } else if (!(stack.getItem() instanceof ItemBlock)) { + throw new CommandException("The item in your main hand isn't a block"); + } else if (args.length < 2) { + throw new CommandException(this.getUsage(sender)); + } + + final String file = args[0]; + @SuppressWarnings("deprecation") + final IBlockState state = Block.getBlockFromItem(stack.getItem()) + .getStateFromMeta(stack.getItemDamage()); + + final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); + final JsonParser p = new JsonParser(); + final JsonElement parsed = mergeDefaults(p.parse(rawData), state); + OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); + OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); + } + + private JsonElement mergeDefaults(final JsonElement parse, final IBlockState state) { + final JsonObject work = parse.getAsJsonObject(); + final JsonObject emptyBlacklist = new JsonObject(); + emptyBlacklist.add("excludes", new JsonArray()); + + if (!work.has(ConfigNames.ENABLED)) { + work.addProperty(ConfigNames.ENABLED, true); + } + if (!work.has(ConfigNames.RETROGEN)) { + work.addProperty(ConfigNames.RETROGEN, false); + } + if (!work.has(ConfigNames.FEATURE)) { + work.addProperty(ConfigNames.FEATURE, "default"); + } + if (!work.has(ConfigNames.REPLACEMENT)) { + work.addProperty(ConfigNames.REPLACEMENT, "default"); + } + if (!work.has(ConfigNames.PARAMETERS)) { + work.add(ConfigNames.PARAMETERS, + OreSpawn.API.getFeature(work.get(ConfigNames.FEATURE).getAsString()) + .getDefaultParameters()); + } + if (!work.has(ConfigNames.DIMENSIONS)) { + work.add(ConfigNames.DIMENSIONS, emptyBlacklist); + } + if (!work.has(ConfigNames.BIOMES)) { + work.add(ConfigNames.BIOMES, emptyBlacklist); + } + + final JsonObject block = new JsonObject(); + block.addProperty(ConfigNames.CHANCE, 100); + block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); + block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); + work.add(ConfigNames.BLOCK, block); + + return work; + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 31daf891..79829133 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -27,137 +27,137 @@ public class ClearChunkCommand extends CommandBase { - private static final String STONE_ID = "minecraft:stone"; - private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", - "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", - "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); - private static final List baseStones = Arrays.asList(STONE_ID, - "minecraft:netherrack", "minecraft:end_stone", "minecraft:cobblestone", - "minecraft:obsidian", "minecraft:magma", "minecraft:soul_sand"); - - private static final List dirtVariants = Arrays.asList("minecraft:dirt", - "minecraft:grass"); - private static final List otherVariants = Arrays.asList("minecraft:gravel", - "minecraft:sand"); - - @Override - public String getName() { - return "clearchunk"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/clearchunk "; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - if (!(sender instanceof EntityPlayer)) { - throw new CommandException("Only players can use this command"); - } - - final EntityPlayer player = (EntityPlayer) sender; - final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); - final ChunkPos chunkPos = chunk.getPos(); - final List blocks; - - final boolean flagClassic = args.length > 0 - ? args[0].toLowerCase().equalsIgnoreCase("classic") - : false; - - final List blockNames = new LinkedList<>(); - getBlocks(args, blockNames); - - blocks = blockNames.stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(block -> block.getDefaultState()).collect(Collectors.toList()); - - blocks.addAll(OreSpawn.API - .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) - .stream().collect(Collectors.toList())); - final List overburden = Arrays - .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", - "minecraft:sandstone", "minecraft:red_sandstone") - .stream() - .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); - - clearBlocks(chunkPos, blocks, overburden, flagClassic, player); - - player.sendStatusMessage( - new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); - } - - private void clearBlocks(final ChunkPos chunkPos, final List blocks, - final List overburden, final boolean flagClassic, - final EntityPlayer player) { - for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { - for (int y = 256; y >= 0; y--) { - for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { - final BlockPos pos = new BlockPos(x, y, z); - final IBlockState block = player.getEntityWorld().getBlockState(pos); - removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); - removeIfFluid(pos, player); - } - } - } - } - - private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { - if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { - final IBlockState bs = player.getEntityWorld().getBlockState(pos); - - if (bs.getMaterial().isLiquid()) { - player.getEntityWorld().setBlockToAir(pos); - } - } - } - - private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, - final IBlockState block, final List blocks, - final List overburden, final boolean flagClassic) { - if (blocks.contains(block) - || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { - player.getEntityWorld().setBlockToAir(pos); - } - } - - private void getBlocks(final String[] args, final List blockNames) { - if (args.length > 0) { - switch (args[0].toLowerCase()) { - case "viewores": - blockNames.addAll(stoneVariants); - blockNames.addAll(dirtVariants); - blockNames.addAll(otherVariants); - break; - - case "dirtandgravel": - blockNames.add(STONE_ID); - blockNames.addAll(dirtVariants); - blockNames.addAll(otherVariants); - break; - - case "classic": - blockNames.add(Blocks.STONE.getRegistryName().toString()); - blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); - blockNames.add(Blocks.END_STONE.getRegistryName().toString()); - blockNames - .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) - .map(Block::getBlockFromItem).map(Block::getRegistryName) - .map(ResourceLocation::toString).collect(Collectors.toList())); - break; - - default: - blockNames.addAll(baseStones); - } - } else { - blockNames.addAll(baseStones); - } - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + private static final String STONE_ID = "minecraft:stone"; + private static final List stoneVariants = Arrays.asList(STONE_ID, "minecraft:diorite", + "minecraft:andesite", "minecraft:granite", "minecraft:sandstone", + "minecraft:red_sandstone", "minecraft:netherrack", "minecraft:end_stone"); + private static final List baseStones = Arrays.asList(STONE_ID, "minecraft:netherrack", + "minecraft:end_stone", "minecraft:cobblestone", "minecraft:obsidian", "minecraft:magma", + "minecraft:soul_sand"); + + private static final List dirtVariants = Arrays.asList("minecraft:dirt", + "minecraft:grass"); + private static final List otherVariants = Arrays.asList("minecraft:gravel", + "minecraft:sand"); + + @Override + public String getName() { + return "clearchunk"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/clearchunk "; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + if (!(sender instanceof EntityPlayer)) { + throw new CommandException("Only players can use this command"); + } + + final EntityPlayer player = (EntityPlayer) sender; + final Chunk chunk = player.getEntityWorld().getChunk(player.getPosition()); + final ChunkPos chunkPos = chunk.getPos(); + final List blocks; + + final boolean flagClassic = args.length > 0 + ? args[0].toLowerCase().equalsIgnoreCase("classic") + : false; + + final List blockNames = new LinkedList<>(); + getBlocks(args, blockNames); + + blocks = blockNames.stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(block -> block.getDefaultState()).collect(Collectors.toList()); + + blocks.addAll(OreSpawn.API + .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) + .stream().collect(Collectors.toList())); + final List overburden = Arrays + .asList("minecraft:dirt", "minecraft:sand", "minecraft:gravel", "minecraft:grass", + "minecraft:sandstone", "minecraft:red_sandstone") + .stream() + .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) + .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); + + clearBlocks(chunkPos, blocks, overburden, flagClassic, player); + + player.sendStatusMessage( + new TextComponentString("chunk " + chunkPos.toString() + " cleared"), true); + } + + private void clearBlocks(final ChunkPos chunkPos, final List blocks, + final List overburden, final boolean flagClassic, + final EntityPlayer player) { + for (int x = chunkPos.getXStart(); x <= chunkPos.getXEnd(); x++) { + for (int y = 256; y >= 0; y--) { + for (int z = chunkPos.getZStart(); z <= chunkPos.getZEnd(); z++) { + final BlockPos pos = new BlockPos(x, y, z); + final IBlockState block = player.getEntityWorld().getBlockState(pos); + removeIfBlocks(player, pos, block, blocks, overburden, !flagClassic); + removeIfFluid(pos, player); + } + } + } + } + + private void removeIfFluid(final BlockPos pos, final EntityPlayer player) { + if (player.getEntityWorld().getBlockState(pos).getMaterial().isLiquid()) { + final IBlockState bs = player.getEntityWorld().getBlockState(pos); + + if (bs.getMaterial().isLiquid()) { + player.getEntityWorld().setBlockToAir(pos); + } + } + } + + private void removeIfBlocks(final EntityPlayer player, final BlockPos pos, + final IBlockState block, final List blocks, + final List overburden, final boolean flagClassic) { + if (blocks.contains(block) + || ((pos.getY() >= 64 && overburden.contains(block)) && flagClassic)) { + player.getEntityWorld().setBlockToAir(pos); + } + } + + private void getBlocks(final String[] args, final List blockNames) { + if (args.length > 0) { + switch (args[0].toLowerCase()) { + case "viewores": + blockNames.addAll(stoneVariants); + blockNames.addAll(dirtVariants); + blockNames.addAll(otherVariants); + break; + + case "dirtandgravel": + blockNames.add(STONE_ID); + blockNames.addAll(dirtVariants); + blockNames.addAll(otherVariants); + break; + + case "classic": + blockNames.add(Blocks.STONE.getRegistryName().toString()); + blockNames.add(Blocks.NETHERRACK.getRegistryName().toString()); + blockNames.add(Blocks.END_STONE.getRegistryName().toString()); + blockNames + .addAll(OreDictionary.getOres("stone").stream().map(ItemStack::getItem) + .map(Block::getBlockFromItem).map(Block::getRegistryName) + .map(ResourceLocation::toString).collect(Collectors.toList())); + break; + + default: + blockNames.addAll(baseStones); + } + } else { + blockNames.addAll(baseStones); + } + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 54d5f21c..74bf10a5 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -23,40 +23,40 @@ public class DumpBiomesCommand extends CommandBase { - @Override - public String getName() { - return "dumpbiomes"; - } - - @Override - public String getUsage(final ICommandSender sender) { - return "/dumpbiomes"; - } - - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - JsonArray array = new JsonArray(); - - for (final Biome biome : ForgeRegistries.BIOMES) { - array.add(new JsonPrimitive(biome.getRegistryName().toString())); - } - - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final String json = gson.toJson(array); - - try { - FileUtils.writeStringToFile(new File(".", "biome_dump.json"), - StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); - } catch (final IOException e) { - throw new CommandException("Failed to save the json file"); - } - - sender.sendMessage(new TextComponentString("Done")); - } - - @Override - public int compareTo(final ICommand command) { - return this.getName().compareTo(command.getName()); - } + @Override + public String getName() { + return "dumpbiomes"; + } + + @Override + public String getUsage(final ICommandSender sender) { + return "/dumpbiomes"; + } + + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + JsonArray array = new JsonArray(); + + for (final Biome biome : ForgeRegistries.BIOMES) { + array.add(new JsonPrimitive(biome.getRegistryName().toString())); + } + + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String json = gson.toJson(array); + + try { + FileUtils.writeStringToFile(new File(".", "biome_dump.json"), + StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); + } catch (final IOException e) { + throw new CommandException("Failed to save the json file"); + } + + sender.sendMessage(new TextComponentString("Done")); + } + + @Override + public int compareTo(final ICommand command) { + return this.getName().compareTo(command.getName()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java index 661c28a7..4d1dc064 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java @@ -10,22 +10,22 @@ public class WriteConfigsCommand extends CommandBase { - @Override - public String getName() { - return "osSaveConfigs"; - } + @Override + public String getName() { + return "osSaveConfigs"; + } - @Override - public String getUsage(final ICommandSender sender) { - return "/osSaveConfigs"; - } + @Override + public String getUsage(final ICommandSender sender) { + return "/osSaveConfigs"; + } - @Override - public void execute(final MinecraftServer server, final ICommandSender sender, - final String[] args) throws CommandException { - sender.sendMessage(new TextComponentString( - "Forcing configs as OreSpawn sees them to be written to disk")); - OreSpawnWriter.saveConfigs(); - } + @Override + public void execute(final MinecraftServer server, final ICommandSender sender, + final String[] args) throws CommandException { + sender.sendMessage(new TextComponentString( + "Forcing configs as OreSpawn sees them to be written to disk")); + OreSpawnWriter.saveConfigs(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index dbe413f0..08ba58c7 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -23,147 +23,147 @@ public class Config { - private static Configuration configuration; - - private Config() { - } - - public static void loadConfig() { - configuration = new Configuration(new File(Constants.CONFIG_FILE)); - - // Load our Boolean Values - boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, - Configuration.CATEGORY_GENERAL, false, - "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); - boolVals.put(Constants.FORCE_RETROGEN_KEY, - configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, - Configuration.CATEGORY_GENERAL, false, - "Force all chunks to retrogen regardless of anything else")); - boolVals.put(Constants.REPLACE_VANILLA_OREGEN, - configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, - Configuration.CATEGORY_GENERAL, false, - "Replace vanilla ore-generation entirely")); - boolVals.put(Constants.FLAT_BEDROCK, - configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, - false, "Flatten the bedrock during world generation")); - boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, - Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); - intVals.put(Constants.BEDROCK_LAYERS, - configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, - 4, "How thick should the shell of bedrock be?")); - knownKeys.add(Constants.RETROGEN_KEY); - knownKeys.add(Constants.FORCE_RETROGEN_KEY); - knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); - knownKeys.add(Constants.KNOWN_MODS); - knownKeys.add(Constants.FLAT_BEDROCK); - knownKeys.add(Constants.RETRO_BEDROCK); - knownKeys.add(Constants.BEDROCK_LAYERS); - - loadExtractedConfigs(); - } - - private static void loadExtractedConfigs() { - final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", - "known-configs.json"); - - if (!p.toFile().exists()) { - return; - } - - final File in = p.toFile(); - String rawData; - - try { - rawData = FileUtils.readFileToString(in, Charset.defaultCharset()); - } catch (IOException e) { - return; - } - - if (rawData.isEmpty()) { - return; - } - - final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); - data.forEach(item -> addKnownMod(item.getAsString())); - } - - public static List getKnownMods() { - return ImmutableList.copyOf(extractedConfigs); - } - - public static void addKnownMod(final String modId) { - extractedConfigs.add(modId); - } - - public static boolean getBoolean(final String keyname) { - if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { - return boolVals.get(keyname); - } - - return false; - } - - public static String getString(final String keyname) { - if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { - return stringVals.get(keyname); - } - - return ""; - } - - public static int getInt(final String keyname) { - if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { - return intVals.get(keyname); - } - - return 0; - } - - public static float getFloat(final String keyname) { - if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { - return floatVals.get(keyname); - } - - return 0.0f; - } - - public static void saveConfig() { - if (!extractedConfigs.isEmpty()) { - saveKnownConfigs(); - } - - configuration.save(); - } - - private static void saveKnownConfigs() { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", - "known-configs.json"); - - if (!p.toFile().getParentFile().exists()) { - p.toFile().mkdirs(); - } - - final File in = p.toFile(); - - final JsonArray data = new JsonArray(); - - extractedConfigs.forEach(data::add); - - try { - FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed saving list of already extracted mod configs"); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - private static final HashMap boolVals = new HashMap<>(); - private static final HashMap stringVals = new HashMap<>(); - private static final HashMap intVals = new HashMap<>(); - private static final HashMap floatVals = new HashMap<>(); - private static final List knownKeys = new ArrayList<>(); - private static final List extractedConfigs = new ArrayList<>(); + private static Configuration configuration; + + private Config() { + } + + public static void loadConfig() { + configuration = new Configuration(new File(Constants.CONFIG_FILE)); + + // Load our Boolean Values + boolVals.put(Constants.RETROGEN_KEY, configuration.getBoolean(Constants.RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Do we have Retrogen active and generating anything different from the last run in already existing chunks ?")); + boolVals.put(Constants.FORCE_RETROGEN_KEY, + configuration.getBoolean(Constants.FORCE_RETROGEN_KEY, + Configuration.CATEGORY_GENERAL, false, + "Force all chunks to retrogen regardless of anything else")); + boolVals.put(Constants.REPLACE_VANILLA_OREGEN, + configuration.getBoolean(Constants.REPLACE_VANILLA_OREGEN, + Configuration.CATEGORY_GENERAL, false, + "Replace vanilla ore-generation entirely")); + boolVals.put(Constants.FLAT_BEDROCK, + configuration.getBoolean(Constants.FLAT_BEDROCK, Configuration.CATEGORY_GENERAL, + false, "Flatten the bedrock during world generation")); + boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, + Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); + intVals.put(Constants.BEDROCK_LAYERS, + configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, + 4, "How thick should the shell of bedrock be?")); + knownKeys.add(Constants.RETROGEN_KEY); + knownKeys.add(Constants.FORCE_RETROGEN_KEY); + knownKeys.add(Constants.REPLACE_VANILLA_OREGEN); + knownKeys.add(Constants.KNOWN_MODS); + knownKeys.add(Constants.FLAT_BEDROCK); + knownKeys.add(Constants.RETRO_BEDROCK); + knownKeys.add(Constants.BEDROCK_LAYERS); + + loadExtractedConfigs(); + } + + private static void loadExtractedConfigs() { + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); + + if (!p.toFile().exists()) { + return; + } + + final File in = p.toFile(); + String rawData; + + try { + rawData = FileUtils.readFileToString(in, Charset.defaultCharset()); + } catch (IOException e) { + return; + } + + if (rawData.isEmpty()) { + return; + } + + final JsonArray data = new JsonParser().parse(rawData).getAsJsonArray(); + data.forEach(item -> addKnownMod(item.getAsString())); + } + + public static List getKnownMods() { + return ImmutableList.copyOf(extractedConfigs); + } + + public static void addKnownMod(final String modId) { + extractedConfigs.add(modId); + } + + public static boolean getBoolean(final String keyname) { + if (knownKeys.contains(keyname) && boolVals.containsKey(keyname)) { + return boolVals.get(keyname); + } + + return false; + } + + public static String getString(final String keyname) { + if (knownKeys.contains(keyname) && stringVals.containsKey(keyname)) { + return stringVals.get(keyname); + } + + return ""; + } + + public static int getInt(final String keyname) { + if (knownKeys.contains(keyname) && intVals.containsKey(keyname)) { + return intVals.get(keyname); + } + + return 0; + } + + public static float getFloat(final String keyname) { + if (knownKeys.contains(keyname) && floatVals.containsKey(keyname)) { + return floatVals.get(keyname); + } + + return 0.0f; + } + + public static void saveConfig() { + if (!extractedConfigs.isEmpty()) { + saveKnownConfigs(); + } + + configuration.save(); + } + + private static void saveKnownConfigs() { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final Path p = FileSystems.getDefault().getPath("config", "orespawn3", "sysconf", + "known-configs.json"); + + if (!p.toFile().getParentFile().exists()) { + p.toFile().mkdirs(); + } + + final File in = p.toFile(); + + final JsonArray data = new JsonArray(); + + extractedConfigs.forEach(data::add); + + try { + FileUtils.writeStringToFile(in, gson.toJson(data), Charset.defaultCharset()); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed saving list of already extracted mod configs"); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + private static final HashMap boolVals = new HashMap<>(); + private static final HashMap stringVals = new HashMap<>(); + private static final HashMap intVals = new HashMap<>(); + private static final HashMap floatVals = new HashMap<>(); + private static final List knownKeys = new ArrayList<>(); + private static final List extractedConfigs = new ArrayList<>(); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index be3da0df..7c6ea724 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -5,104 +5,103 @@ public class Constants { - public static final String MODID = "orespawn"; - public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.3.0"; - public static final String RETROGEN_KEY = "Retrogen"; - public static final String CONFIG_FILE = "config/orespawn.cfg"; - public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; - public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; - public static final String ORE_TAG = "ores"; - public static final String FEATURES_TAG = "features"; - public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; - public static final String OVERWORLD = "overworld"; - public static final String THE_OVERWORLD = "the overworld"; - public static final String NETHER = "nether"; - public static final String THE_NETHER = "the nether"; - public static final String END = "end"; - public static final String THE_END = "the end"; - public static final String DEFAULT_GEN = "default"; - public static final String VEIN_GEN = "vein"; - public static final String NORMAL_CLOUD = "normal-cloud"; - public static final String CLUSTERS = "clusters"; - public static final String CRASH_SECTION = "OreSpawn Version"; - public static final String KNOWN_MODS = "already-extracted"; - public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; - public static final String FLAT_BEDROCK = "Flatten Bedrock"; - public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; - public static final String BEDROCK_LAYERS = "Bedrock Thickness"; - public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; - public static final String PRECISION = "precision"; - public static final Path CONFDIR = Paths.get("config", "orespawn3"); - public static final Path SYSCONF = Paths.get("config", "orespawn3", - "sysconf"); + public static final String MODID = "orespawn"; + public static final String NAME = "MMD OreSpawn"; + public static final String VERSION = "3.3.0"; + public static final String RETROGEN_KEY = "Retrogen"; + public static final String CONFIG_FILE = "config/orespawn.cfg"; + public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; + public static final String CHUNK_TAG_NAME = "MMD OreSpawn Data"; + public static final String ORE_TAG = "ores"; + public static final String FEATURES_TAG = "features"; + public static final String REPLACE_VANILLA_OREGEN = "Replace Vanilla Oregen"; + public static final String OVERWORLD = "overworld"; + public static final String THE_OVERWORLD = "the overworld"; + public static final String NETHER = "nether"; + public static final String THE_NETHER = "the nether"; + public static final String END = "end"; + public static final String THE_END = "the end"; + public static final String DEFAULT_GEN = "default"; + public static final String VEIN_GEN = "vein"; + public static final String NORMAL_CLOUD = "normal-cloud"; + public static final String CLUSTERS = "clusters"; + public static final String CRASH_SECTION = "OreSpawn Version"; + public static final String KNOWN_MODS = "already-extracted"; + public static final String RETRO_BEDROCK = "Retrogen Flat Bedrock"; + public static final String FLAT_BEDROCK = "Flatten Bedrock"; + public static final String RETRO_BEDROCK_TAG = "retro-bedrock"; + public static final String BEDROCK_LAYERS = "Bedrock Thickness"; + public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; + public static final String PRECISION = "precision"; + public static final Path CONFDIR = Paths.get("config", "orespawn3"); + public static final Path SYSCONF = Paths.get("config", "orespawn3", "sysconf"); - public final class FormatBits { + public final class FormatBits { - private FormatBits() { - } + private FormatBits() { + } - public static final String MAX_SPREAD = "maxSpread"; - public static final String MEDIAN_SIZE = "medianSize"; - public static final String MIN_HEIGHT = "minHeight"; - public static final String MAX_HEIGHT = "maxHeight"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String NODE_SIZE = "size"; - public static final String ATTEMPTS = "attempts"; - public static final String LENGTH = "length"; - public static final String NODE_COUNT = "numObjects"; - public static final String ATTEMPTS_MIN = "minAttempts"; - public static final String ATTEMPTS_MAX = "maxAttempts"; - public static final String STARTINGFACE = "startFacing"; - } + public static final String MAX_SPREAD = "maxSpread"; + public static final String MEDIAN_SIZE = "medianSize"; + public static final String MIN_HEIGHT = "minHeight"; + public static final String MAX_HEIGHT = "maxHeight"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String NODE_SIZE = "size"; + public static final String ATTEMPTS = "attempts"; + public static final String LENGTH = "length"; + public static final String NODE_COUNT = "numObjects"; + public static final String ATTEMPTS_MIN = "minAttempts"; + public static final String ATTEMPTS_MAX = "maxAttempts"; + public static final String STARTINGFACE = "startFacing"; + } - public final class FileBits { + public final class FileBits { - private FileBits() { - } + private FileBits() { + } - public static final String CONFIG_DIR = "config"; - public static final String OS3 = "orespawn3"; - public static final String SYSCONF = "sysconf"; - public static final String PRESETS = "presets.json"; - } + public static final String CONFIG_DIR = "config"; + public static final String OS3 = "orespawn3"; + public static final String SYSCONF = "sysconf"; + public static final String PRESETS = "presets.json"; + } - public final class ConfigNames { + public final class ConfigNames { - private ConfigNames() { - } + private ConfigNames() { + } - public static final String DEFAULT = "default"; - public static final String STATE_NORMAL = "normal"; - public static final String DIMENSIONS = "dimensions"; - public static final String CHANCE = "chance"; - public static final String METADATA = "metaData"; - public static final String BIOMES = "biomes"; - public static final String STATE = "state"; - public static final String REPLACEMENT = "replaces"; - public static final String FEATURE = "feature"; - public static final String PARAMETERS = "parameters"; - public static final String FILE_VERSION = "version"; - public static final String BLOCK = "blocks"; - public static final String SPAWNS = "spawns"; - public static final String RETROGEN = "retrogen"; - public static final String ENABLED = "enabled"; - public static final String NAME = "name"; - public static final String WHITELIST = "includes"; - public static final String BLACKLIST = "excludes"; - public static final String PRESETS = "presets"; + public static final String DEFAULT = "default"; + public static final String STATE_NORMAL = "normal"; + public static final String DIMENSIONS = "dimensions"; + public static final String CHANCE = "chance"; + public static final String METADATA = "metaData"; + public static final String BIOMES = "biomes"; + public static final String STATE = "state"; + public static final String REPLACEMENT = "replaces"; + public static final String FEATURE = "feature"; + public static final String PARAMETERS = "parameters"; + public static final String FILE_VERSION = "version"; + public static final String BLOCK = "blocks"; + public static final String SPAWNS = "spawns"; + public static final String RETROGEN = "retrogen"; + public static final String ENABLED = "enabled"; + public static final String NAME = "name"; + public static final String WHITELIST = "includes"; + public static final String BLACKLIST = "excludes"; + public static final String PRESETS = "presets"; - public final class DefaultFeatureProperties { + public final class DefaultFeatureProperties { - private DefaultFeatureProperties() { - } + private DefaultFeatureProperties() { + } - public static final String SIZE = "size"; - public static final String VARIATION = "variation"; - public static final String FREQUENCY = "frequency"; - public static final String MAXHEIGHT = "maxHeight"; - public static final String MINHEIGHT = "minHeight"; - } - } + public static final String SIZE = "size"; + public static final String VARIATION = "variation"; + public static final String FREQUENCY = "frequency"; + public static final String MAXHEIGHT = "maxHeight"; + public static final String MINHEIGHT = "minHeight"; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index a8490bb1..8042f745 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -28,135 +28,135 @@ public class FeatureRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistry registry = new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) - .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO - .create(); - - public FeatureRegistry() { - // - } - - public Map getFeatures() { - final Map tempMap = new TreeMap<>(); - registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); - - return Collections.unmodifiableMap(tempMap); - } - - public String getFeatureName(final IFeature feature) { - return feature.getRegistryName().toString(); - } - - public IFeature getFeature(final String name) { - return getFeature(new ResourceLocation(name)); - } - - public IFeature getFeature(final ResourceLocation featureResourceLocation) { - final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); - if (registry.containsKey(featureResourceLocation)) { - return registry.getValue(featureResourceLocation); - } else { - return registry.getValue(defaultGen); - } - } - - public boolean hasFeature(final String name) { - return hasFeature(new ResourceLocation(name)); - } - - public boolean hasFeature(final ResourceLocation featureResourceLocation) { - return registry.containsKey(featureResourceLocation); - } - - public boolean hasFeature(final IFeature feature) { - return registry.containsKey(feature.getRegistryName()); - } - - public void addFeature(final String name, final IFeature feature) { - feature.setRegistryName(new ResourceLocation("orespawn", name)); - registry.register(feature); - } - - public void addFeature(final JsonObject entry) { - addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); - } - - public void addFeature(final String name, final String className) { - final IFeature feature = getInstance(className); - - if (feature != null && !hasFeature(name)) { - addFeature(name, feature); - } - } - - private static IFeature getInstance(final String className) { - Class featureClazz; - Constructor featureCons; - IFeature feature; - - try { - featureClazz = Class.forName(className); - featureCons = featureClazz.getConstructor(); - feature = (IFeature) featureCons.newInstance(); - } catch (final Exception e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed to load and instantiate an instance of the feature generator named " - + className + " that was specified as a feature generator"); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return null; - } - - return feature; - } - - public void loadFeaturesFile(final File file) { - final JsonParser parser = new JsonParser(); - String rawJson; - JsonArray elements; - - try { - rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); - } catch (final IOException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + file.getName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return; - } - - elements = parser.parse(rawJson).getAsJsonArray(); - - for (final JsonElement elem : elements) { - addFeature(elem.getAsJsonObject()); - } - } - - public void writeFeatures(final File file) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - - final JsonArray root = new JsonArray(); - - registry.getEntries().stream().map(ent -> { - final JsonObject e = new JsonObject(); - e.addProperty("name", ent.getKey().getPath()); - e.addProperty("class", ent.getValue().getClass().getName()); - return e; - }).forEach(root::add); - - final String json = gson.toJson(root); - - try { - FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), - CharEncoding.UTF_8); - } catch (final IOException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Failed writing config " + file.getName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistry registry = new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "feature_registry")).setType(IFeature.class) + .setMaxID(4096) // 12 bits should be enough... hell, 8 bits would be, IMNSHO + .create(); + + public FeatureRegistry() { + // + } + + public Map getFeatures() { + final Map tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue())); + + return Collections.unmodifiableMap(tempMap); + } + + public String getFeatureName(final IFeature feature) { + return feature.getRegistryName().toString(); + } + + public IFeature getFeature(final String name) { + return getFeature(new ResourceLocation(name)); + } + + public IFeature getFeature(final ResourceLocation featureResourceLocation) { + final ResourceLocation defaultGen = new ResourceLocation(Constants.DEFAULT_GEN); + if (registry.containsKey(featureResourceLocation)) { + return registry.getValue(featureResourceLocation); + } else { + return registry.getValue(defaultGen); + } + } + + public boolean hasFeature(final String name) { + return hasFeature(new ResourceLocation(name)); + } + + public boolean hasFeature(final ResourceLocation featureResourceLocation) { + return registry.containsKey(featureResourceLocation); + } + + public boolean hasFeature(final IFeature feature) { + return registry.containsKey(feature.getRegistryName()); + } + + public void addFeature(final String name, final IFeature feature) { + feature.setRegistryName(new ResourceLocation("orespawn", name)); + registry.register(feature); + } + + public void addFeature(final JsonObject entry) { + addFeature(entry.get("name").getAsString(), entry.get("class").getAsString()); + } + + public void addFeature(final String name, final String className) { + final IFeature feature = getInstance(className); + + if (feature != null && !hasFeature(name)) { + addFeature(name, feature); + } + } + + private static IFeature getInstance(final String className) { + Class featureClazz; + Constructor featureCons; + IFeature feature; + + try { + featureClazz = Class.forName(className); + featureCons = featureClazz.getConstructor(); + feature = (IFeature) featureCons.newInstance(); + } catch (final Exception e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed to load and instantiate an instance of the feature generator named " + + className + " that was specified as a feature generator"); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return null; + } + + return feature; + } + + public void loadFeaturesFile(final File file) { + final JsonParser parser = new JsonParser(); + String rawJson; + JsonArray elements; + + try { + rawJson = FileUtils.readFileToString(file, Charset.defaultCharset()); + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return; + } + + elements = parser.parse(rawJson).getAsJsonArray(); + + for (final JsonElement elem : elements) { + addFeature(elem.getAsJsonObject()); + } + } + + public void writeFeatures(final File file) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + final JsonArray root = new JsonArray(); + + registry.getEntries().stream().map(ent -> { + final JsonObject e = new JsonObject(); + e.addProperty("name", ent.getKey().getPath()); + e.addProperty("class", ent.getValue().getClass().getName()); + return e; + }).forEach(root::add); + + final String json = gson.toJson(root); + + try { + FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), + CharEncoding.UTF_8); + } catch (final IOException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config " + file.getName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java index ca310863..d0d948c6 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java +++ b/src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java @@ -21,75 +21,75 @@ public class PresetsStorage { - private final Map> storage; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private final Map> storage; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public PresetsStorage() { - storage = new TreeMap<>(); - } + public PresetsStorage() { + storage = new TreeMap<>(); + } - public void setSymbolSection(final String sectionName, final String itemName, - final JsonElement value) { - final Map temp = storage.getOrDefault(sectionName, - new HashMap()); - temp.put(itemName, value); - storage.put(sectionName, temp); - } + public void setSymbolSection(final String sectionName, final String itemName, + final JsonElement value) { + final Map temp = storage.getOrDefault(sectionName, + new HashMap()); + temp.put(itemName, value); + storage.put(sectionName, temp); + } - public JsonElement getSymbolSection(final String sectionName, final String itemName) { - if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { - return storage.get(sectionName).get(itemName); - } else { - return new JsonPrimitive(itemName); - } - } + public JsonElement getSymbolSection(final String sectionName, final String itemName) { + if (storage.containsKey(sectionName) && storage.get(sectionName).containsKey(itemName)) { + return storage.get(sectionName).get(itemName); + } else { + return new JsonPrimitive(itemName); + } + } - public void copy(final PresetsStorage dest) { - storage.entrySet().stream().forEach(ensm -> { - final String section = ensm.getKey(); - ensm.getValue().entrySet().forEach( - ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); - }); - } + public void copy(final PresetsStorage dest) { + storage.entrySet().stream().forEach(ensm -> { + final String section = ensm.getKey(); + ensm.getValue().entrySet().forEach( + ensje -> dest.setSymbolSection(section, ensje.getKey(), ensje.getValue())); + }); + } - public void clear() { - this.storage.clear(); - } + public void clear() { + this.storage.clear(); + } - public void load(final Path inputFile) { - final JsonParser p = new JsonParser(); - JsonElement parsed = null; + public void load(final Path inputFile) { + final JsonParser p = new JsonParser(); + JsonElement parsed = null; - try (BufferedReader r = Files.newBufferedReader(inputFile)) { - parsed = p.parse(r); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading presets from" + inputFile.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (final JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "JSON Parsing Error in " + inputFile.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } + try (BufferedReader r = Files.newBufferedReader(inputFile)) { + parsed = p.parse(r); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading presets from" + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch (final JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + inputFile.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } - if (parsed != null) { - parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { - final String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream().forEach( - sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); - }); - } - } + if (parsed != null) { + parsed.getAsJsonObject().entrySet().stream().forEach(entry -> { + final String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream().forEach( + sect -> this.setSymbolSection(section, sect.getKey(), sect.getValue())); + }); + } + } - public JsonElement get(final String asString) { - final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); - final Matcher m = p.matcher(asString); - if (m.matches()) { - return this.getSymbolSection(m.group(1), m.group(2)); - } - return new JsonPrimitive("Unknown Variable " + asString); - } + public JsonElement get(final String asString) { + final Pattern p = Pattern.compile("\\$\\.(\\w+)\\.(\\w+)"); + final Matcher m = p.matcher(asString); + if (m.matches()) { + return this.getSymbolSection(m.group(1), m.group(2)); + } + return new JsonPrimitive("Unknown Variable " + asString); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 14361973..7addab86 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -41,198 +41,198 @@ public class ReplacementsRegistry { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() - .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() - .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... - .create(); - - public ReplacementsRegistry() { - // - } - - public Map getReplacements() { - return ImmutableMap.copyOf(registry.getEntries()); - } - - /** - * - * @param dimension - * @return - * @deprecated - */ - @Deprecated - public List getDimensionDefault(final int dimension) { - final String[] names = { - "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" - }; - final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() - .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) - .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) - .collect(Collectors.toList()); - final List baseRv = new ArrayList<>(); - baseRv.addAll(mineralogyOres); - - if (dimension < -1 || dimension > 1 || dimension == 0) { - for (final ItemStack iS : OreDictionary.getOres("stone")) { - baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); - } - - return baseRv; - } - - baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS - .getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); - return baseRv; - } - - public IReplacementEntry getReplacement(final String name) { - final ResourceLocation act = new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name)); - - if (registry.containsKey(act)) { - return registry.getValue(act); - } else { - return registry.getValue(new ResourceLocation("orespawn:default")); - } - } - - public void addBlock(final String name, final String blockName, final String blockState) { - final IBlockState b = StateUtil.deserializeState( - ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); - addBlock(name, b); - } - - public Map> getBlocks() { - final Map> tempMap = new TreeMap<>(); - registry.getEntries().stream() - .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); - - return Collections.unmodifiableMap(tempMap); - } - - public void addReplacement(final IReplacementEntry replacement) { - registry.register(replacement); - } - - public void addBlock(final String name, final IBlockState state) { - ResourceLocation regName = new ResourceLocation(name); - if (registry.containsKey(regName)) { - final IReplacementEntry old = registry.getValue(regName); - IReplacementEntry newRE; - List oldList = old.getEntries(); - oldList.add(state); - newRE = new ReplacementEntry(name, oldList); - registry.remove(regName); - newRE.setRegistryName(regName); - registry.register(newRE); - return; - } - - final IReplacementEntry r = new ReplacementEntry(name, state); - registry.register(r); - } - - @SuppressWarnings("deprecation") - public void loadFile(final Path file) { - final JsonParser parser = new JsonParser(); - JsonObject elements; - String rawJson; - - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); - - try { - rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); - } catch (IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + file.getFileName()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - return; - } - - elements = parser.parse(rawJson).getAsJsonObject(); - elements.entrySet().stream().forEach(elem -> { - final String entName = elem.getKey(); - final JsonArray entries = elem.getValue().getAsJsonArray(); - final List blocks = new LinkedList<>(); - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); - for (final JsonElement e : entries) { - final JsonObject asObj = e.getAsJsonObject(); - final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() - .toLowerCase(); - - // is this an OreDictionary entry ? - if (blockName.startsWith("ore:")) { - // yes, it is - final String oreDictName = blockName.split(":")[1]; - OreDictionary.getOres(oreDictName).forEach(iS -> { - if (iS.getMetadata() != 0) { - blocks.add(Block.getBlockFromItem(iS.getItem()) - .getStateFromMeta(iS.getMetadata())); - } else { - blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); - } - }); - } else { - String state = null; - final ResourceLocation blockRL = new ResourceLocation(blockName); - final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); - if (asObj.has(Constants.ConfigNames.METADATA)) { - // has metadata - final int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); - blocks.add(theBlock.getStateFromMeta(meta)); - } else if (asObj.has(Constants.ConfigNames.STATE)) { - // has a state - state = asObj.get(Constants.ConfigNames.STATE).getAsString(); - blocks.add(StateUtil.deserializeState(theBlock, state)); - } else { - // use the default state - blocks.add(theBlock.getDefaultState()); - } - } - } - - final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); - registry.register(replacer); - }); - } - - public void saveFile(final String modName) { - final JsonObject outs = new JsonObject(); - - registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) - .forEach(ent -> { - final JsonArray entry = new JsonArray(); - final IReplacementEntry workVal = ent.getValue(); - workVal.getEntries().stream().forEach(bs -> { - final JsonObject block = new JsonObject(); - block.addProperty(Constants.ConfigNames.BLOCK, - bs.getBlock().getRegistryName().toString()); - if (!bs.toString().matches("\\[normal\\]")) { - block.addProperty(Constants.ConfigNames.STATE, - bs.toString().replaceAll("[\\[\\]]", "")); - } - entry.add(block); - }); - outs.add(ent.getKey().toString(), entry); - }); - final Path p = Paths.get("config", "orespawn3", "sysconfig", - String.format("replacements-%s.json", modName)); - try (final BufferedWriter w = Files.newBufferedWriter(p)) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - final String ov = gson.toJson(outs); - w.write(ov); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, String - .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - public boolean has(final ResourceLocation resourceLocation) { - return registry.containsKey(resourceLocation); - } + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final IForgeRegistryModifiable registry = (IForgeRegistryModifiable) new RegistryBuilder() + .setName(new ResourceLocation("orespawn", "replacements_registry")).allowModification() + .setType(IReplacementEntry.class).setMaxID(65535) // 16 bits should be enough... + .create(); + + public ReplacementsRegistry() { + // + } + + public Map getReplacements() { + return ImmutableMap.copyOf(registry.getEntries()); + } + + /** + * + * @param dimension + * @return + * @deprecated + */ + @Deprecated + public List getDimensionDefault(final int dimension) { + final String[] names = { + "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" + }; + final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() + .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) + .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) + .collect(Collectors.toList()); + final List baseRv = new ArrayList<>(); + baseRv.addAll(mineralogyOres); + + if (dimension < -1 || dimension > 1 || dimension == 0) { + for (final ItemStack iS : OreDictionary.getOres("stone")) { + baseRv.add(Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())); + } + + return baseRv; + } + + baseRv.addAll(Arrays.asList(ForgeRegistries.BLOCKS + .getValue(new ResourceLocation(names[dimension + 1])).getDefaultState())); + return baseRv; + } + + public IReplacementEntry getReplacement(final String name) { + final ResourceLocation act = new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name)); + + if (registry.containsKey(act)) { + return registry.getValue(act); + } else { + return registry.getValue(new ResourceLocation("orespawn:default")); + } + } + + public void addBlock(final String name, final String blockName, final String blockState) { + final IBlockState b = StateUtil.deserializeState( + ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + addBlock(name, b); + } + + public Map> getBlocks() { + final Map> tempMap = new TreeMap<>(); + registry.getEntries().stream() + .forEach(e -> tempMap.put(e.getKey().toString(), e.getValue().getEntries())); + + return Collections.unmodifiableMap(tempMap); + } + + public void addReplacement(final IReplacementEntry replacement) { + registry.register(replacement); + } + + public void addBlock(final String name, final IBlockState state) { + ResourceLocation regName = new ResourceLocation(name); + if (registry.containsKey(regName)) { + final IReplacementEntry old = registry.getValue(regName); + IReplacementEntry newRE; + List oldList = old.getEntries(); + oldList.add(state); + newRE = new ReplacementEntry(name, oldList); + registry.remove(regName); + newRE.setRegistryName(regName); + registry.register(newRE); + return; + } + + final IReplacementEntry r = new ReplacementEntry(name, state); + registry.register(r); + } + + @SuppressWarnings("deprecation") + public void loadFile(final Path file) { + final JsonParser parser = new JsonParser(); + JsonObject elements; + String rawJson; + + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); + + try { + rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); + } catch (IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + file.getFileName()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + return; + } + + elements = parser.parse(rawJson).getAsJsonObject(); + elements.entrySet().stream().forEach(elem -> { + final String entName = elem.getKey(); + final JsonArray entries = elem.getValue().getAsJsonArray(); + final List blocks = new LinkedList<>(); + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); + for (final JsonElement e : entries) { + final JsonObject asObj = e.getAsJsonObject(); + final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() + .toLowerCase(); + + // is this an OreDictionary entry ? + if (blockName.startsWith("ore:")) { + // yes, it is + final String oreDictName = blockName.split(":")[1]; + OreDictionary.getOres(oreDictName).forEach(iS -> { + if (iS.getMetadata() != 0) { + blocks.add(Block.getBlockFromItem(iS.getItem()) + .getStateFromMeta(iS.getMetadata())); + } else { + blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); + } + }); + } else { + String state = null; + final ResourceLocation blockRL = new ResourceLocation(blockName); + final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); + if (asObj.has(Constants.ConfigNames.METADATA)) { + // has metadata + final int meta = asObj.get(Constants.ConfigNames.METADATA).getAsInt(); + blocks.add(theBlock.getStateFromMeta(meta)); + } else if (asObj.has(Constants.ConfigNames.STATE)) { + // has a state + state = asObj.get(Constants.ConfigNames.STATE).getAsString(); + blocks.add(StateUtil.deserializeState(theBlock, state)); + } else { + // use the default state + blocks.add(theBlock.getDefaultState()); + } + } + } + + final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); + registry.register(replacer); + }); + } + + public void saveFile(final String modName) { + final JsonObject outs = new JsonObject(); + + registry.getEntries().stream().filter(ent -> ent.getKey().getNamespace().equals(modName)) + .forEach(ent -> { + final JsonArray entry = new JsonArray(); + final IReplacementEntry workVal = ent.getValue(); + workVal.getEntries().stream().forEach(bs -> { + final JsonObject block = new JsonObject(); + block.addProperty(Constants.ConfigNames.BLOCK, + bs.getBlock().getRegistryName().toString()); + if (!bs.toString().matches("\\[normal\\]")) { + block.addProperty(Constants.ConfigNames.STATE, + bs.toString().replaceAll("[\\[\\]]", "")); + } + entry.add(block); + }); + outs.add(ent.getKey().toString(), entry); + }); + final Path p = Paths.get("config", "orespawn3", "sysconfig", + String.format("replacements-%s.json", modName)); + try (final BufferedWriter w = Files.newBufferedWriter(p)) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + final String ov = gson.toJson(outs); + w.write(ov); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, String + .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + public boolean has(final ResourceLocation resourceLocation) { + return registry.containsKey(resourceLocation); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java index b9f36c90..e04934b2 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java +++ b/src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java @@ -7,10 +7,10 @@ @OreSpawnPlugin(modid = "orespawn", resourcePath = "configs") public class VanillaOres implements IOreSpawnPlugin { - @Override - public void register(final OS3API apiInterface) { - // nothing for us to do - all of our ores are in the - // jar and the code handles that - } + @Override + public void register(final OS3API apiInterface) { + // nothing for us to do - all of our ores are in the + // jar and the code handles that + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 588091f0..ce423979 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -19,177 +19,177 @@ public class ClusterGenerator extends FeatureBase implements IFeature { - private ClusterGenerator(final Random rand) { - super(rand); - } + private ClusterGenerator(final Random rand) { + super(rand); + } - public ClusterGenerator() { - this(new Random()); - } + public ClusterGenerator() { + this(new Random()); + } - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; - mergeDefaults(params, getDefaultParameters()); + mergeDefaults(params, getDefaultParameters()); - runCache(chunkX, chunkZ, world, spawnData); + runCache(chunkX, chunkZ, world, spawnData); - // now to ore spawn + // now to ore spawn - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; - final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); - - int tries; + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int clusterSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int clusterCount = params.get(Constants.FormatBits.NODE_COUNT).getAsInt(); + + int tries; - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - while (tries > 0) { - if (this.random.nextInt(100) <= frequency) { - final int xRand = random.nextInt(16); - final int zRand = random.nextInt(16); - - final int x = blockX + xRand - (maxSpread / 2); - final int y = random.nextInt(maxHeight - minHeight) + minHeight; - final int z = blockZ + zRand - (maxSpread / 2); - - spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, - spawnData, world, new BlockPos(x, y, z)); - } - - tries--; - } - } - - private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, - final int maxSpread, final int minHeight, final int maxHeight, - final ISpawnEntry spawnData, final World world, final BlockPos pos) { - // spawn a cluster at the center, then a bunch around the outside... - int r = clusterSize - variance; - - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; - } - - spawnChunk(world, pos, spawnData, r); - - int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary - // inside that - - if (variance > 0) { - count += this.random.nextInt(2 * variance) - variance; - } - - while (count >= 0) { - r = clusterSize - variance; - - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; - } - - final int radius = maxSpread / 2; - - final int xp = getPoint(-radius, radius, 0); - final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - final int zp = getPoint(-radius, radius, 0); - - final BlockPos p = pos.add(xp, yp, zp); - spawnChunk(world, p, spawnData, r); - - count -= r; - } - } - - private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - final int dimension = world.provider.getDimension(); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - int z = 0; - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - - if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, - spawnData)) { - count++; - z++; - } else { - z = 0; - } - - if (z > 5) { - count--; - z = 0; - OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); - } - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, - final ISpawnEntry spawnData, final World world, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); - defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); - defParams.addProperty(Constants.FormatBits.VARIATION, 4); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); - return defParams; - } + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + while (tries > 0) { + if (this.random.nextInt(100) <= frequency) { + final int xRand = random.nextInt(16); + final int zRand = random.nextInt(16); + + final int x = blockX + xRand - (maxSpread / 2); + final int y = random.nextInt(maxHeight - minHeight) + minHeight; + final int z = blockZ + zRand - (maxSpread / 2); + + spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, + spawnData, world, new BlockPos(x, y, z)); + } + + tries--; + } + } + + private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, + final int maxSpread, final int minHeight, final int maxHeight, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { + // spawn a cluster at the center, then a bunch around the outside... + int r = clusterSize - variance; + + if (variance > 0) { + r += this.random.nextInt(2 * variance) - variance; + } + + spawnChunk(world, pos, spawnData, r); + + int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary + // inside that + + if (variance > 0) { + count += this.random.nextInt(2 * variance) - variance; + } + + while (count >= 0) { + r = clusterSize - variance; + + if (variance > 0) { + r += this.random.nextInt(2 * variance) - variance; + } + + final int radius = maxSpread / 2; + + final int xp = getPoint(-radius, radius, 0); + final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + final int zp = getPoint(-radius, radius, 0); + + final BlockPos p = pos.add(xp, yp, zp); + spawnChunk(world, p, spawnData, r); + + count -= r; + } + } + + private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry spawnData, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + final int dimension = world.provider.getDimension(); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + int z = 0; + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData)) { + count++; + z++; + } else { + z = 0; + } + + if (z > 5) { + count--; + z = 0; + OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); + } + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, + final ISpawnEntry spawnData, final World world, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + defParams.addProperty(Constants.FormatBits.NODE_COUNT, 8); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); + defParams.addProperty(Constants.FormatBits.VARIATION, 4); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); + return defParams; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 5f26bfb9..fbc9d734 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -18,119 +18,119 @@ public class DefaultFeatureGenerator extends FeatureBase implements IFeature { - public DefaultFeatureGenerator() { - super(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // now to ore spawn - - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; - - final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); - final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - - if (freq >= 1) { - for (int i = 0; i < freq; i++) { - final int x = blockX + random.nextInt(16); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(16); - - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); - } - } else if (random.nextFloat() < freq) { - final int x = blockX + random.nextInt(8); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(8); - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); - } - - } - - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - final BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, - final ISpawnEntry spawnData, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); - defParams.addProperty(Constants.FormatBits.VARIATION, 16); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 0.5); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); - return defParams; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } + public DefaultFeatureGenerator() { + super(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final float freq = params.get(Constants.FormatBits.FREQUENCY).getAsFloat(); + final int size = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + + if (freq >= 1) { + for (int i = 0; i < freq; i++) { + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); + + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); + } + } else if (random.nextFloat() < freq) { + final int x = blockX + random.nextInt(8); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(8); + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); + } + + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 0.5); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + return defParams; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 6e0f6833..6d6d1cf1 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -17,166 +17,166 @@ public class NormalCloudGenerator extends FeatureBase implements IFeature { - private NormalCloudGenerator(final Random rand) { - super(rand); - } - - public NormalCloudGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // now to ore spawn - - // lets not offset blind, - final int blockX = chunkX * 16; - final int blockZ = chunkZ * 16; - - final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); - final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); - final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - - // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get - // a size that will let us insert by the radius - final int offsetXZ = 32 - maxSpread; - - // you have the distance between minHeight and maxHeight - // this is the actual size of the space - final int sizeY = (maxHeight - minHeight); - final int offsetY = sizeY - maxSpread; - final int radiusXZ = offsetXZ / 2; - - // actual radius for placement is the size minus the spread to center it in the space and - // keep - // from overflowing - final int radiusY = offsetY / 2; - - // we center at the minimum plus the half the height - final int blockY = minHeight + (sizeY / 2); - - final int fSave = frequency; - int tryCount = 0; - - int tries; - - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - while (tries > 0) { - if (this.random.nextInt(100) <= frequency) { - frequency = fSave; - final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; - // this should, hopefully, keep us centered between minHeight and maxHeight with - // nothing going above/below those values - final int y = blockY + getPoint(0, offsetY, radiusY); - final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; - - int r = medianSize - variance; - - if (variance > 0) { - r += random.nextInt(2 * variance) - variance; - } - - final BlockPos p = new BlockPos(x, y, z); - - if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) - && tryCount < 5) { - // make another try! - tries++; - frequency = 100; - tryCount++; - } else { - tryCount = 0; - } - } - - tries--; - } - } - - private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, - final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, - final World world) { - // spawn one right at the center here, then generate for the cloud and do the math - - if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, - world.provider.getDimension(), true, spawnData)) { - return false; - } - - final int radius = maxSpread / 2; - boolean alreadySpewed = false; - int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); - - while (count > 0) { - int xp = getPoint(0, maxSpread, radius); - int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - int zp = getPoint(0, maxSpread, radius); - - BlockPos p = pos.add(xp, yp, zp); - - int z = 0; - - while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, - world.provider.getDimension(), true, spawnData)) { - xp = getPoint(0, maxSpread, radius); - yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); - zp = getPoint(0, maxSpread, radius); - - p = pos.add(xp, yp, zp); - - z++; - } - - if (z >= 5 && !alreadySpewed) { - OreSpawn.LOGGER.info( - "unable to achieve requested cloud density for cloud centered at %s", pos); - alreadySpewed = true; - } - - count--; - } - - return true; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); - defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); - defParams.addProperty(Constants.FormatBits.VARIATION, 4); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); - return defParams; - } + private NormalCloudGenerator(final Random rand) { + super(rand); + } + + public NormalCloudGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + // lets not offset blind, + final int blockX = chunkX * 16; + final int blockZ = chunkZ * 16; + + final int maxSpread = params.get(Constants.FormatBits.MAX_SPREAD).getAsInt(); + final int medianSize = params.get(Constants.FormatBits.MEDIAN_SIZE).getAsInt(); + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + int frequency = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + + // on the X and Z you have a possible 2-chunk range - 32 blocks - subtract the spread to get + // a size that will let us insert by the radius + final int offsetXZ = 32 - maxSpread; + + // you have the distance between minHeight and maxHeight + // this is the actual size of the space + final int sizeY = (maxHeight - minHeight); + final int offsetY = sizeY - maxSpread; + final int radiusXZ = offsetXZ / 2; + + // actual radius for placement is the size minus the spread to center it in the space and + // keep + // from overflowing + final int radiusY = offsetY / 2; + + // we center at the minimum plus the half the height + final int blockY = minHeight + (sizeY / 2); + + final int fSave = frequency; + int tryCount = 0; + + int tries; + + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + while (tries > 0) { + if (this.random.nextInt(100) <= frequency) { + frequency = fSave; + final int x = blockX + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + // this should, hopefully, keep us centered between minHeight and maxHeight with + // nothing going above/below those values + final int y = blockY + getPoint(0, offsetY, radiusY); + final int z = blockZ + getPoint(0, offsetXZ, radiusXZ) + radiusXZ; + + int r = medianSize - variance; + + if (variance > 0) { + r += random.nextInt(2 * variance) - variance; + } + + final BlockPos p = new BlockPos(x, y, z); + + if (!spawnCloud(r, maxSpread, minHeight, maxHeight, p, spawnData, world) + && tryCount < 5) { + // make another try! + tries++; + frequency = 100; + tryCount++; + } else { + tryCount = 0; + } + } + + tries--; + } + } + + private boolean spawnCloud(final int size, final int maxSpread, final int minHeight, + final int maxHeight, final BlockPos pos, final ISpawnEntry spawnData, + final World world) { + // spawn one right at the center here, then generate for the cloud and do the math + + if (!spawn(spawnData.getBlocks().getRandomBlock(random), world, pos, + world.provider.getDimension(), true, spawnData)) { + return false; + } + + final int radius = maxSpread / 2; + boolean alreadySpewed = false; + int count = Math.min(size, (int) Math.round(Math.PI * Math.pow(radius, 2))); + + while (count > 0) { + int xp = getPoint(0, maxSpread, radius); + int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + int zp = getPoint(0, maxSpread, radius); + + BlockPos p = pos.add(xp, yp, zp); + + int z = 0; + + while (z < 5 && !spawn(spawnData.getBlocks().getRandomBlock(random), world, p, + world.provider.getDimension(), true, spawnData)) { + xp = getPoint(0, maxSpread, radius); + yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + zp = getPoint(0, maxSpread, radius); + + p = pos.add(xp, yp, zp); + + z++; + } + + if (z >= 5 && !alreadySpewed) { + OreSpawn.LOGGER.info( + "unable to achieve requested cloud density for cloud centered at %s", pos); + alreadySpewed = true; + } + + count--; + } + + return true; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MAX_SPREAD, 16); + defParams.addProperty(Constants.FormatBits.MEDIAN_SIZE, 8); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 8); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 24); + defParams.addProperty(Constants.FormatBits.VARIATION, 4); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 25); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); + return defParams; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 3e720f28..ee3eaa52 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -20,279 +20,279 @@ public class PrecisionGenerator extends FeatureBase implements IFeature { - private PrecisionGenerator(final Random rand) { - super(rand); - } - - public PrecisionGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // extract parameters - final int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); - final int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); - final int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); - final int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); - - int thisNode = nodeSize; - - // now to use them - for (int c = nodeCount; c > 0; c--) { - int sc; - final HeightRange hr = new HeightRange(minHeight, maxHeight); - final BlockPos spot = chooseSpot(chunkX, chunkZ, hr); - - sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); - - // bit of feedback - if we underproduce or overproduce a node, the next one gets a - // correction - if (sc != thisNode && sc != 0) { - thisNode += (nodeSize - sc); - } else if (sc == thisNode) { - // if we produced exact size, reset the size - thisNode = nodeSize; - } - - // if we hit a node of size zero or less, we've done something wrong - if (thisNode <= 0) { - thisNode = nodeSize; - } - } - } - - private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, - final ChunkPos pos, final ISpawnEntry spawnData, final World world) { - int spawned = 0; - int c; - - BlockPos act = spot; - int counter = nodeSize; - - while (counter > 0 && spawned < nodeSize) { - c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); - - if (c == 0) { - act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), - heightRange); - } - - counter -= (c + 1); - spawned += c; - } - - return spawned; - } - - private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, - final World world, final int nodeSize, final HeightRange heightRange) { - - int count = nodeSize; - final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((nodeSize < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (nodeSize < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - int nc = 0; - - for (; count > 0 && nc <= nodeSize; count--) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); - final Vec3i offset = offs[scrambledLUT[--count]]; - final BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); - final int dimension = world.provider.getDimension(); - - if (spawn(oreBlock, world, p, dimension, true, spawnData)) { - nc++; - } - } - - return nc; - } - - return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); - } - - private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, - final HeightRange heightRange, final ChunkPos pos) { - final BlockPos p = spot.add(offset); - final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); - final int xMax = x1z1.getXEnd(); - final int zMax = x1z1.getZEnd(); - final int xMin = pos.getXStart(); - final int zMin = pos.getZStart(); - - int xmod = offset.getX(); - int ymod = offset.getY(); - int zmod = offset.getZ(); - - // correct the points values to not cause the Y coordinate to go outside the permissable - // range - if (p.getY() < heightRange.getMin() || p.getY() > heightRange.getMax()) { - ymod = rescaleOffset(ymod, spot.getY(), heightRange.getMin(), heightRange.getMax()); - } - - if (p.getX() < xMin || p.getX() > xMax) { - xmod = rescaleOffset(xmod, spot.getX(), xMin, xMax); - } - - if (p.getZ() < zMin || p.getZ() > zMax) { - zmod = rescaleOffset(zmod, spot.getZ(), zMin, zMax); - } - - return spot.add(xmod, ymod, zmod); - } - - private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, - final int maximumIn) { - final int actual = centerIn + offsetIn; - int wrapDistance; - final int range = maximumIn - minimumIn; - int workingPoint; - - if (actual < minimumIn) { - wrapDistance = minimumIn - actual; - } else { - wrapDistance = actual - maximumIn; - } - - if (wrapDistance < 0) { - wrapDistance = ((-1) * wrapDistance) % range; - } else { - wrapDistance %= range; - } - - if (actual < minimumIn) { - workingPoint = maximumIn - wrapDistance; - } else { - workingPoint = minimumIn + wrapDistance; - } - - return workingPoint - centerIn; - } - - private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, - final BlockPos loc, final int nodeSize, final HeightRange heightRange) { - - final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) Math.ceil(radius * radius); - - if (this.random.nextBoolean()) { - return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, - nodeSize); - } else { - return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, - nodeSize); - } - } - - private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, - final BlockPos loc, final HeightRange heightRange, final boolean toPositive, - final double radius, final int rSqr, final int nodeSize) { - int quantity = nodeSize; - int nc = 0; - - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, - radius); dx = countItem(dx, toPositive)) { - for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, - radius); dz = countItem(dz, toPositive)) { - if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, - loc) >= 0) { - nc++; - quantity--; - - if (nc >= nodeSize || quantity <= 0) { - return nc; - } - } - } - } - } - - return nc; - } - - private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, - final HeightRange heightRange, final ISpawnEntry spawnData, final World world, - final ChunkPos pos, final BlockPos loc) { - if (getABC(dx, dy, dz) <= rSqr) { - final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); - final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); - return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; - } - - return -1; - } - - private int getPoint(final int lowerBound, final int upperBound) { - final List arr = new ArrayList<>(); - - for (int i = lowerBound; i <= upperBound; i++) { - arr.add(i); - } - - return arr.get(this.random.nextInt(arr.size())); - } - - private BlockPos chooseSpot(final int xPosition, final int zPosition, - final HeightRange heightRange) { - final int xRet = getPoint(0, 15) + (xPosition * 16); - final int zRet = getPoint(0, 15) + (zPosition * 16); - final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); - - return new BlockPos(xRet, yRet, zRet); - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defaults = new JsonObject(); - defaults.addProperty(FormatBits.NODE_COUNT, 4); - defaults.addProperty(FormatBits.MIN_HEIGHT, 16); - defaults.addProperty(FormatBits.MAX_HEIGHT, 80); - defaults.addProperty(FormatBits.NODE_SIZE, 8); - return defaults; - } - - private class HeightRange { - - private int min; - private int max; - - HeightRange(final int min, final int max) { - this.min = min; - this.max = max; - } - - int getMin() { - return this.min; - } - - int getMax() { - return this.max; - } - } + private PrecisionGenerator(final Random rand) { + super(rand); + } + + public PrecisionGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // extract parameters + final int nodeCount = params.get(FormatBits.NODE_COUNT).getAsInt(); + final int maxHeight = params.get(FormatBits.MAX_HEIGHT).getAsInt(); + final int minHeight = params.get(FormatBits.MIN_HEIGHT).getAsInt(); + final int nodeSize = params.get(FormatBits.NODE_SIZE).getAsInt(); + + int thisNode = nodeSize; + + // now to use them + for (int c = nodeCount; c > 0; c--) { + int sc; + final HeightRange hr = new HeightRange(minHeight, maxHeight); + final BlockPos spot = chooseSpot(chunkX, chunkZ, hr); + + sc = spawnAtSpot(thisNode, hr, spot, new ChunkPos(chunkX, chunkZ), spawnData, world); + + // bit of feedback - if we underproduce or overproduce a node, the next one gets a + // correction + if (sc != thisNode && sc != 0) { + thisNode += (nodeSize - sc); + } else if (sc == thisNode) { + // if we produced exact size, reset the size + thisNode = nodeSize; + } + + // if we hit a node of size zero or less, we've done something wrong + if (thisNode <= 0) { + thisNode = nodeSize; + } + } + } + + private int spawnAtSpot(final int nodeSize, final HeightRange heightRange, final BlockPos spot, + final ChunkPos pos, final ISpawnEntry spawnData, final World world) { + int spawned = 0; + int c; + + BlockPos act = spot; + int counter = nodeSize; + + while (counter > 0 && spawned < nodeSize) { + c = spawnOreNode(act, pos, spawnData, world, nodeSize, heightRange); + + if (c == 0) { + act = chooseSpot(Math.floorDiv(spot.getX(), 16), Math.floorDiv(spot.getZ(), 16), + heightRange); + } + + counter -= (c + 1); + spawned += c; + } + + return spawned; + } + + private int spawnOreNode(final BlockPos loc, final ChunkPos pos, final ISpawnEntry spawnData, + final World world, final int nodeSize, final HeightRange heightRange) { + + int count = nodeSize; + final int lutType = (nodeSize < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (nodeSize < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((nodeSize < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (nodeSize < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + int nc = 0; + + for (; count > 0 && nc <= nodeSize; count--) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(this.random); + final Vec3i offset = offs[scrambledLUT[--count]]; + final BlockPos p = fixMungeOffset(offset, loc, heightRange, pos); + final int dimension = world.provider.getDimension(); + + if (spawn(oreBlock, world, p, dimension, true, spawnData)) { + nc++; + } + } + + return nc; + } + + return spawnFill(spawnData, world, pos, loc, nodeSize, heightRange); + } + + private BlockPos fixMungeOffset(final Vec3i offset, final BlockPos spot, + final HeightRange heightRange, final ChunkPos pos) { + final BlockPos p = spot.add(offset); + final ChunkPos x1z1 = new ChunkPos(pos.x + 1, pos.z + 1); + final int xMax = x1z1.getXEnd(); + final int zMax = x1z1.getZEnd(); + final int xMin = pos.getXStart(); + final int zMin = pos.getZStart(); + + int xmod = offset.getX(); + int ymod = offset.getY(); + int zmod = offset.getZ(); + + // correct the points values to not cause the Y coordinate to go outside the permissable + // range + if (p.getY() < heightRange.getMin() || p.getY() > heightRange.getMax()) { + ymod = rescaleOffset(ymod, spot.getY(), heightRange.getMin(), heightRange.getMax()); + } + + if (p.getX() < xMin || p.getX() > xMax) { + xmod = rescaleOffset(xmod, spot.getX(), xMin, xMax); + } + + if (p.getZ() < zMin || p.getZ() > zMax) { + zmod = rescaleOffset(zmod, spot.getZ(), zMin, zMax); + } + + return spot.add(xmod, ymod, zmod); + } + + private int rescaleOffset(final int offsetIn, final int centerIn, final int minimumIn, + final int maximumIn) { + final int actual = centerIn + offsetIn; + int wrapDistance; + final int range = maximumIn - minimumIn; + int workingPoint; + + if (actual < minimumIn) { + wrapDistance = minimumIn - actual; + } else { + wrapDistance = actual - maximumIn; + } + + if (wrapDistance < 0) { + wrapDistance = ((-1) * wrapDistance) % range; + } else { + wrapDistance %= range; + } + + if (actual < minimumIn) { + workingPoint = maximumIn - wrapDistance; + } else { + workingPoint = minimumIn + wrapDistance; + } + + return workingPoint - centerIn; + } + + private int spawnFill(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final int nodeSize, final HeightRange heightRange) { + + final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) Math.ceil(radius * radius); + + if (this.random.nextBoolean()) { + return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, + nodeSize); + } else { + return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, + nodeSize); + } + } + + private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, + final BlockPos loc, final HeightRange heightRange, final boolean toPositive, + final double radius, final int rSqr, final int nodeSize) { + int quantity = nodeSize; + int nc = 0; + + for (int dy = (int) (-1 * radius); dy < radius; dy++) { + for (int dx = getStart(toPositive, radius); endCheck(toPositive, dx, + radius); dx = countItem(dx, toPositive)) { + for (int dz = getStart(toPositive, radius); endCheck(toPositive, dz, + radius); dz = countItem(dz, toPositive)) { + if (doCheckSpawn(dx, dy, dz, rSqr, heightRange, spawnData, world, pos, + loc) >= 0) { + nc++; + quantity--; + + if (nc >= nodeSize || quantity <= 0) { + return nc; + } + } + } + } + } + + return nc; + } + + private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSqr, + final HeightRange heightRange, final ISpawnEntry spawnData, final World world, + final ChunkPos pos, final BlockPos loc) { + if (getABC(dx, dy, dz) <= rSqr) { + final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); + final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); + return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; + } + + return -1; + } + + private int getPoint(final int lowerBound, final int upperBound) { + final List arr = new ArrayList<>(); + + for (int i = lowerBound; i <= upperBound; i++) { + arr.add(i); + } + + return arr.get(this.random.nextInt(arr.size())); + } + + private BlockPos chooseSpot(final int xPosition, final int zPosition, + final HeightRange heightRange) { + final int xRet = getPoint(0, 15) + (xPosition * 16); + final int zRet = getPoint(0, 15) + (zPosition * 16); + final int yRet = getPoint(heightRange.getMin(), heightRange.getMax()); + + return new BlockPos(xRet, yRet, zRet); + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defaults = new JsonObject(); + defaults.addProperty(FormatBits.NODE_COUNT, 4); + defaults.addProperty(FormatBits.MIN_HEIGHT, 16); + defaults.addProperty(FormatBits.MAX_HEIGHT, 80); + defaults.addProperty(FormatBits.NODE_SIZE, 8); + return defaults; + } + + private class HeightRange { + + private int min; + private int max; + + HeightRange(final int min, final int max) { + this.min = min; + this.max = max; + } + + int getMin() { + return this.min; + } + + int getMax() { + return this.max; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index d77e200a..ec2a1292 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -25,558 +25,558 @@ public class VeinGenerator extends FeatureBase implements IFeature { - private VeinGenerator(final Random rand) { - super(rand); - } - - public VeinGenerator() { - this(new Random()); - } - - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - runCache(chunkX, chunkZ, world, spawnData); - mergeDefaults(params, getDefaultParameters()); - - // now to ore spawn - - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; - - final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); - final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); - final EnumFacing startingFace = getFaceFromString( - params.get(Constants.FormatBits.STARTINGFACE).getAsString()); - final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - - int tries; - - if (triesMax == triesMin) { - tries = triesMax; - } else { - tries = random.nextInt(triesMax - triesMin) + triesMin; - } - - // we have an offset into the chunk but actually need something more - while (tries > 0) { - if (this.random.nextInt(100) <= freq) { - final int x = blockX + random.nextInt(16); - final int y = random.nextInt(maxY - minY) + minY; - final int z = blockZ + random.nextInt(16); - - final int r; - - if (vari > 0) { - r = random.nextInt(2 * vari) - vari; - } else { - r = 0; - } - - spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, - world); - } - - tries--; - } - } - - private EnumFacing getFaceFromString(final String direction) { - final String work = direction.toLowerCase(); - switch (work) { - case "north": - return EnumFacing.NORTH; - case "south": - return EnumFacing.SOUTH; - case "east": - return EnumFacing.EAST; - case "west": - return EnumFacing.WEST; - case "down": - return EnumFacing.DOWN; - case "up": - return EnumFacing.UP; - case "random": - return EnumFacing.VALUES[this.random.nextInt(EnumFacing.VALUES.length)]; - case "vertical": - return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; - case "horizontal": - return EnumFacing.HORIZONTALS[this.random.nextInt(EnumFacing.HORIZONTALS.length)]; - default: - OreSpawn.LOGGER.error( - "Invalid value %s found in parameters for vein spawn, returning \"north\"", - direction); - return EnumFacing.NORTH; - } - } - - private enum EnumSquare { - TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), - RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); - - private int index; - - private EnumSquare(int index) { - this.index = index; - } - - final public int getIndex() { - return this.index; - } - } - - private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, - final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { - EnumFacing face = startingFace; - EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; - BlockPos workingPos = new BlockPos(blockPos); - - if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { - return; - } - - // build vein - final List points = Lists.newLinkedList(); - for (; points.size() < veinLength;) { - points.add(workingPos); - List nextFaces = getNextFaceSet(square, face); - - if (!nextFaces.isEmpty()) { - BlockPos temp = workingPos; - for (EnumFacing f : nextFaces) { - temp = temp.offset(f, 1); - } - nextFaces.clear(); - points.add(temp); - workingPos = temp; - } - - face = getNextStartingFace(square, face); - square = getNextSquare(); - } - - spawnOre(world, spawnData, blockPos, nodeSize); - for (final BlockPos pos : points) { - spawnOre(world, spawnData, pos, nodeSize); - } - } - - private class SquareWeight extends WeightedRandom.Item { - - public EnumSquare item; - - public SquareWeight(EnumSquare item, int weight) { - super(weight); - this.item = item; - } - } - - private EnumSquare getNextSquare() { - float[] weights = new float[] { - 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f - }; - List items = new ArrayList<>(); - - for (EnumSquare sq : EnumSquare.values()) { - items.add(new SquareWeight(sq, (int) (weights[sq.getIndex()] * 10000))); - } - - return ((SquareWeight) WeightedRandom.getRandomItem(this.random, items)).item; - } - - private static final EnumFacing[][][] congruentSquares = new EnumFacing[][][] { - // Index 0 - DOWN - new EnumFacing[][] { - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.NORTH, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 1 - UP - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.NORTH, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.SOUTH, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 2 - NORTH - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.WEST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.WEST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.EAST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.EAST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 3 - SOUTH - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.EAST, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.WEST, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.EAST - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.EAST - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.WEST - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.WEST - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 4 - WEST - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.SOUTH - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.SOUTH - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.NORTH - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.NORTH - } // RIGHT_TOP - }, new EnumFacing[][] { - // Index 5 - EAST - new EnumFacing[] { - EnumFacing.UP, null - }, // TOP_EDGE - new EnumFacing[] { - EnumFacing.NORTH, null - }, // LEFT_EDGE - new EnumFacing[] { - EnumFacing.DOWN, null - }, // BOTTOM_EDGE - new EnumFacing[] { - EnumFacing.SOUTH, null - }, // RIGHT_EDGE - new EnumFacing[] { - EnumFacing.UP, EnumFacing.NORTH - }, // LEFT_TOP - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.NORTH - }, // LEFT_BOTTOM - new EnumFacing[] { - EnumFacing.DOWN, EnumFacing.SOUTH - }, // RIGHT_BOTTOM - new EnumFacing[] { - EnumFacing.UP, EnumFacing.SOUTH - } // RIGHT_TOP - } - }; - - private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { - - if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { - return face; - } - - EnumFacing[] possibles = Arrays.asList(congruentSquares[face.getIndex()][square.getIndex()]) - .stream().filter(it -> it != null).toArray(EnumFacing[]::new); - - if (possibles.length > 1) { - return possibles[this.random.nextInt(possibles.length)]; - } - return possibles[0]; - } - - private List getNextFaceSet(EnumSquare square, EnumFacing face) { - List rv = new ArrayList<>(); - - rv.add(face); - - switch (square) { - case BOTTOM_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - case TOP_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case LEFT_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - break; - default: - break; - } - break; - case RIGHT_EDGE: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - break; - case UP: - case DOWN: - rv.add(EnumFacing.WEST); - break; - default: - break; - } - break; - case FACE: - break; - case LEFT_TOP: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case LEFT_BOTTOM: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateYCCW()); - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - case RIGHT_TOP: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - rv.add(EnumFacing.UP); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.SOUTH); - break; - default: - break; - } - break; - case RIGHT_BOTTOM: - switch (face) { - case EAST: - case WEST: - case NORTH: - case SOUTH: - rv.add(face.rotateY()); - rv.add(EnumFacing.DOWN); - break; - case UP: - case DOWN: - rv.add(EnumFacing.EAST); - rv.add(EnumFacing.NORTH); - break; - default: - break; - } - break; - default: - break; - } - - return rv; - } - - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - final BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, - final ISpawnEntry spawnData, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); - defParams.addProperty(Constants.FormatBits.VARIATION, 16); - defParams.addProperty(Constants.FormatBits.FREQUENCY, 50); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.LENGTH, 16); - defParams.addProperty(Constants.FormatBits.STARTINGFACE, "north"); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3); - return defParams; - } - - @Override - public void setRandom(final Random rand) { - this.random = rand; - } + private VeinGenerator(final Random rand) { + super(rand); + } + + public VeinGenerator() { + this(new Random()); + } + + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + runCache(chunkX, chunkZ, world, spawnData); + mergeDefaults(params, getDefaultParameters()); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + final int minY = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxY = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int vari = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int freq = params.get(Constants.FormatBits.FREQUENCY).getAsInt(); + final int length = params.get(Constants.FormatBits.LENGTH).getAsInt(); + final EnumFacing startingFace = getFaceFromString( + params.get(Constants.FormatBits.STARTINGFACE).getAsString()); + final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + + int tries; + + if (triesMax == triesMin) { + tries = triesMax; + } else { + tries = random.nextInt(triesMax - triesMin) + triesMin; + } + + // we have an offset into the chunk but actually need something more + while (tries > 0) { + if (this.random.nextInt(100) <= freq) { + final int x = blockX + random.nextInt(16); + final int y = random.nextInt(maxY - minY) + minY; + final int z = blockZ + random.nextInt(16); + + final int r; + + if (vari > 0) { + r = random.nextInt(2 * vari) - vari; + } else { + r = 0; + } + + spawnVein(length + r, nodeSize, startingFace, new BlockPos(x, y, z), spawnData, + world); + } + + tries--; + } + } + + private EnumFacing getFaceFromString(final String direction) { + final String work = direction.toLowerCase(); + switch (work) { + case "north": + return EnumFacing.NORTH; + case "south": + return EnumFacing.SOUTH; + case "east": + return EnumFacing.EAST; + case "west": + return EnumFacing.WEST; + case "down": + return EnumFacing.DOWN; + case "up": + return EnumFacing.UP; + case "random": + return EnumFacing.VALUES[this.random.nextInt(EnumFacing.VALUES.length)]; + case "vertical": + return this.random.nextBoolean() ? EnumFacing.UP : EnumFacing.DOWN; + case "horizontal": + return EnumFacing.HORIZONTALS[this.random.nextInt(EnumFacing.HORIZONTALS.length)]; + default: + OreSpawn.LOGGER.error( + "Invalid value %s found in parameters for vein spawn, returning \"north\"", + direction); + return EnumFacing.NORTH; + } + } + + private enum EnumSquare { + TOP_EDGE(0), LEFT_EDGE(1), BOTTOM_EDGE(2), RIGHT_EDGE(3), LEFT_TOP(4), LEFT_BOTTOM(5), + RIGHT_TOP(6), RIGHT_BOTTOM(7), FACE(8); + + private int index; + + private EnumSquare(int index) { + this.index = index; + } + + final public int getIndex() { + return this.index; + } + } + + private void spawnVein(final int veinLength, final int nodeSize, final EnumFacing startingFace, + final BlockPos blockPos, final ISpawnEntry spawnData, final World world) { + EnumFacing face = startingFace; + EnumSquare square = EnumSquare.values()[this.random.nextInt(EnumSquare.values().length)]; + BlockPos workingPos = new BlockPos(blockPos); + + if (!spawnData.getMatcher().test(world.getBlockState(blockPos))) { + return; + } + + // build vein + final List points = Lists.newLinkedList(); + for (; points.size() < veinLength;) { + points.add(workingPos); + List nextFaces = getNextFaceSet(square, face); + + if (!nextFaces.isEmpty()) { + BlockPos temp = workingPos; + for (EnumFacing f : nextFaces) { + temp = temp.offset(f, 1); + } + nextFaces.clear(); + points.add(temp); + workingPos = temp; + } + + face = getNextStartingFace(square, face); + square = getNextSquare(); + } + + spawnOre(world, spawnData, blockPos, nodeSize); + for (final BlockPos pos : points) { + spawnOre(world, spawnData, pos, nodeSize); + } + } + + private class SquareWeight extends WeightedRandom.Item { + + public EnumSquare item; + + public SquareWeight(EnumSquare item, int weight) { + super(weight); + this.item = item; + } + } + + private EnumSquare getNextSquare() { + float[] weights = new float[] { + 0.12f, 0.12f, 0.12f, 0.12f, 0.0475f, 0.0475f, 0.0475f, 0.0475f, 0.33f + }; + List items = new ArrayList<>(); + + for (EnumSquare sq : EnumSquare.values()) { + items.add(new SquareWeight(sq, (int) (weights[sq.getIndex()] * 10000))); + } + + return ((SquareWeight) WeightedRandom.getRandomItem(this.random, items)).item; + } + + private static final EnumFacing[][][] congruentSquares = new EnumFacing[][][] { + // Index 0 - DOWN + new EnumFacing[][] { + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 1 - UP + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.NORTH, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.SOUTH, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 2 - NORTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 3 - SOUTH + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.EAST, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.WEST, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.EAST + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.EAST + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.WEST + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.WEST + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 4 - WEST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + } // RIGHT_TOP + }, new EnumFacing[][] { + // Index 5 - EAST + new EnumFacing[] { + EnumFacing.UP, null + }, // TOP_EDGE + new EnumFacing[] { + EnumFacing.NORTH, null + }, // LEFT_EDGE + new EnumFacing[] { + EnumFacing.DOWN, null + }, // BOTTOM_EDGE + new EnumFacing[] { + EnumFacing.SOUTH, null + }, // RIGHT_EDGE + new EnumFacing[] { + EnumFacing.UP, EnumFacing.NORTH + }, // LEFT_TOP + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.NORTH + }, // LEFT_BOTTOM + new EnumFacing[] { + EnumFacing.DOWN, EnumFacing.SOUTH + }, // RIGHT_BOTTOM + new EnumFacing[] { + EnumFacing.UP, EnumFacing.SOUTH + } // RIGHT_TOP + } + }; + + private EnumFacing getNextStartingFace(EnumSquare square, EnumFacing face) { + + if ((this.random.nextBoolean()) || (square == EnumSquare.FACE)) { + return face; + } + + EnumFacing[] possibles = Arrays.asList(congruentSquares[face.getIndex()][square.getIndex()]) + .stream().filter(it -> it != null).toArray(EnumFacing[]::new); + + if (possibles.length > 1) { + return possibles[this.random.nextInt(possibles.length)]; + } + return possibles[0]; + } + + private List getNextFaceSet(EnumSquare square, EnumFacing face) { + List rv = new ArrayList<>(); + + rv.add(face); + + switch (square) { + case BOTTOM_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case TOP_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + break; + default: + break; + } + break; + case RIGHT_EDGE: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + break; + case UP: + case DOWN: + rv.add(EnumFacing.WEST); + break; + default: + break; + } + break; + case FACE: + break; + case LEFT_TOP: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case LEFT_BOTTOM: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateYCCW()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + case RIGHT_TOP: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.UP); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.SOUTH); + break; + default: + break; + } + break; + case RIGHT_BOTTOM: + switch (face) { + case EAST: + case WEST: + case NORTH: + case SOUTH: + rv.add(face.rotateY()); + rv.add(EnumFacing.DOWN); + break; + case UP: + case DOWN: + rv.add(EnumFacing.EAST); + rv.add(EnumFacing.NORTH); + break; + default: + break; + } + break; + default: + break; + } + + return rv; + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.FREQUENCY, 50); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 8); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.LENGTH, 16); + defParams.addProperty(Constants.FormatBits.STARTINGFACE, "north"); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 3); + return defParams; + } + + @Override + public void setRandom(final Random rand) { + this.random = rand; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java index 7be8b101..057eacc0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java @@ -10,16 +10,16 @@ public class BiomeLocationAcceptAny implements BiomeLocation { - @Override - public boolean matches(final Biome biome) { - return true; - } + @Override + public boolean matches(final Biome biome) { + return true; + } - @Override - public JsonElement serialize() { - final JsonObject rv = new JsonObject(); - rv.add(ConfigNames.BLACKLIST, new JsonArray()); - return rv; - } + @Override + public JsonElement serialize() { + final JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java index 4dd291d6..4abce926 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java @@ -14,73 +14,73 @@ public final class BiomeLocationComposition implements BiomeLocation { - private final BiomeLocation inclusions; - - private final BiomeLocation exclusions; - - private final int hash; - - public BiomeLocationComposition(final BiomeLocation inclusions, - final BiomeLocation exclusions) { - this.inclusions = inclusions; - this.exclusions = exclusions; - this.hash = Objects.hash(inclusions, exclusions); - } - - @Override - public boolean matches(final Biome biome) { - final boolean inWhite = this.inclusions.matches(biome); - final boolean inBlack = this.exclusions.matches(biome); - - return !inBlack && inWhite; - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - if (obj == this) { - return true; - } - - if (obj instanceof BiomeLocationComposition) { - final BiomeLocationComposition other = (BiomeLocationComposition) obj; - return this.inclusions.equals(other.inclusions) - && this.exclusions.equals(other.exclusions); - } - - return false; - } - - @Override - public ImmutableList getBiomes() { - final List temp = new LinkedList<>(); - temp.addAll(this.inclusions.getBiomes()); - temp.addAll(this.exclusions.getBiomes()); - return ImmutableList.copyOf(temp); - } - - public BiomeLocation getInclusions() { - return this.inclusions; - } - - public BiomeLocation getExclusions() { - return this.exclusions; - } - - @Override - public JsonElement serialize() { - final JsonObject rv = new JsonObject(); - - rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); - if (!(this.inclusions instanceof BiomeLocationEmpty)) { - rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); - } - - return rv; - } + private final BiomeLocation inclusions; + + private final BiomeLocation exclusions; + + private final int hash; + + public BiomeLocationComposition(final BiomeLocation inclusions, + final BiomeLocation exclusions) { + this.inclusions = inclusions; + this.exclusions = exclusions; + this.hash = Objects.hash(inclusions, exclusions); + } + + @Override + public boolean matches(final Biome biome) { + final boolean inWhite = this.inclusions.matches(biome); + final boolean inBlack = this.exclusions.matches(biome); + + return !inBlack && inWhite; + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + if (obj == this) { + return true; + } + + if (obj instanceof BiomeLocationComposition) { + final BiomeLocationComposition other = (BiomeLocationComposition) obj; + return this.inclusions.equals(other.inclusions) + && this.exclusions.equals(other.exclusions); + } + + return false; + } + + @Override + public ImmutableList getBiomes() { + final List temp = new LinkedList<>(); + temp.addAll(this.inclusions.getBiomes()); + temp.addAll(this.exclusions.getBiomes()); + return ImmutableList.copyOf(temp); + } + + public BiomeLocation getInclusions() { + return this.inclusions; + } + + public BiomeLocation getExclusions() { + return this.exclusions; + } + + @Override + public JsonElement serialize() { + final JsonObject rv = new JsonObject(); + + rv.add(Constants.ConfigNames.BLACKLIST, this.exclusions.serialize()); + if (!(this.inclusions instanceof BiomeLocationEmpty)) { + rv.add(Constants.ConfigNames.WHITELIST, this.inclusions.serialize()); + } + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java index f665118b..d45d846e 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java @@ -10,42 +10,42 @@ public final class BiomeLocationDictionary implements BiomeLocation { - private final BiomeDictionary.Type type; - - private final int hash; - - public BiomeLocationDictionary(final BiomeDictionary.Type type) { - this.type = type; - this.hash = type.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return BiomeDictionary.hasType(biome, this.type); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationDictionary) - && this.type.equals(((BiomeLocationDictionary) obj).type)); - } - - public BiomeDictionary.Type getType() { - return this.type; - } - - @Override - public ImmutableList getBiomes() { - return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); - } - - @Override - public JsonElement serialize() { - return new JsonPrimitive(this.type.toString().toUpperCase()); - } + private final BiomeDictionary.Type type; + + private final int hash; + + public BiomeLocationDictionary(final BiomeDictionary.Type type) { + this.type = type; + this.hash = type.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return BiomeDictionary.hasType(biome, this.type); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationDictionary) + && this.type.equals(((BiomeLocationDictionary) obj).type)); + } + + public BiomeDictionary.Type getType() { + return this.type; + } + + @Override + public ImmutableList getBiomes() { + return ImmutableList.copyOf(BiomeDictionary.getBiomes(this.type)); + } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.type.toString().toUpperCase()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java index fa2c3247..44db55a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java @@ -8,14 +8,14 @@ public class BiomeLocationEmpty implements BiomeLocation { - @Override - public boolean matches(final Biome biome) { - return false; - } + @Override + public boolean matches(final Biome biome) { + return false; + } - @Override - public JsonElement serialize() { - return new JsonArray(); - } + @Override + public JsonElement serialize() { + return new JsonArray(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java index c8ccbc0c..56b34080 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java @@ -13,48 +13,48 @@ public final class BiomeLocationList implements BiomeLocation { - private final ImmutableSet locations; - - private final int hash; - - public BiomeLocationList(final ImmutableSet locations) { - this.locations = locations; - this.hash = locations.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return this.locations.stream().anyMatch(loc -> loc.matches(biome)); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationList) - && this.locations.equals(((BiomeLocationList) obj).locations)); - } - - @Override - public ImmutableList getBiomes() { - final List temp = new LinkedList<>(); - locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); - return ImmutableList.copyOf(temp); - } - - public ImmutableSet getLocations() { - return this.locations; - } - - @Override - public JsonElement serialize() { - final JsonArray rv = new JsonArray(); - this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) - .forEach(bl -> rv.add(bl.serialize())); - - return rv; - } + private final ImmutableSet locations; + + private final int hash; + + public BiomeLocationList(final ImmutableSet locations) { + this.locations = locations; + this.hash = locations.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return this.locations.stream().anyMatch(loc -> loc.matches(biome)); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationList) + && this.locations.equals(((BiomeLocationList) obj).locations)); + } + + @Override + public ImmutableList getBiomes() { + final List temp = new LinkedList<>(); + locations.stream().forEach(bl -> temp.addAll(bl.getBiomes())); + return ImmutableList.copyOf(temp); + } + + public ImmutableSet getLocations() { + return this.locations; + } + + @Override + public JsonElement serialize() { + final JsonArray rv = new JsonArray(); + this.locations.stream().filter(bl -> (!(bl instanceof BiomeLocationEmpty))) + .forEach(bl -> rv.add(bl.serialize())); + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java index 6dfaa7ae..0b862c70 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java @@ -9,42 +9,42 @@ public final class BiomeLocationSingle implements BiomeLocation { - private final Biome biome; - - private final int hash; - - public BiomeLocationSingle(final Biome biome) { - this.biome = biome; - this.hash = biome.hashCode(); - } - - @Override - public boolean matches(final Biome biome) { - return this.biome.equals(biome); - } - - @Override - public ImmutableList getBiomes() { - return ImmutableList.of(this.biome); - } - - @Override - public int hashCode() { - return this.hash; - } - - @Override - public boolean equals(final Object obj) { - return (obj == this) || ((obj instanceof BiomeLocationSingle) - && this.biome.equals(((BiomeLocationSingle) obj).biome)); - } - - public Biome getBiome() { - return this.biome; - } - - @Override - public JsonElement serialize() { - return new JsonPrimitive(this.biome.getRegistryName().toString()); - } + private final Biome biome; + + private final int hash; + + public BiomeLocationSingle(final Biome biome) { + this.biome = biome; + this.hash = biome.hashCode(); + } + + @Override + public boolean matches(final Biome biome) { + return this.biome.equals(biome); + } + + @Override + public ImmutableList getBiomes() { + return ImmutableList.of(this.biome); + } + + @Override + public int hashCode() { + return this.hash; + } + + @Override + public boolean equals(final Object obj) { + return (obj == this) || ((obj instanceof BiomeLocationSingle) + && this.biome.equals(((BiomeLocationSingle) obj).biome)); + } + + public Biome getBiome() { + return this.biome; + } + + @Override + public JsonElement serialize() { + return new JsonPrimitive(this.biome.getRegistryName().toString()); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java index 91048e3e..a8a9bf51 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java @@ -19,81 +19,81 @@ public class BiomeBuilder implements IBiomeBuilder { - private final List whitelist = new LinkedList<>(); - private final List blacklist = new LinkedList<>(); - - private boolean acceptAll = false; - - public BiomeBuilder() { - // - } - - @Override - public IBiomeBuilder addWhitelistEntry(final Biome biome) { - this.whitelist.add(biome); - return this; - } - - @Override - public IBiomeBuilder addWhitelistEntry(final String biomeName) { - return this.addWhitelistEntry(new ResourceLocation(biomeName)); - } - - @Override - public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { - return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); - } - - @Override - public IBiomeBuilder addBlacklistEntry(final Biome biome) { - this.blacklist.add(biome); - return this; - } - - @Override - public IBiomeBuilder addBlacklistEntry(final String biomeName) { - return this.addBlacklistEntry(new ResourceLocation(biomeName)); - } - - @Override - public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { - return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); - } - - @Override - public IBiomeBuilder setAcceptAll() { - this.acceptAll = true; - return this; - } - - @Override - public BiomeLocation create() { - if (this.acceptAll) { - return new BiomeLocationAcceptAny(); - } - - BiomeLocation whitelistI; - BiomeLocation blacklistI; - if (this.whitelist.isEmpty()) { - if (!this.blacklist.isEmpty()) { - whitelistI = new BiomeLocationAcceptAny(); - } else { - whitelistI = new BiomeLocationEmpty(); - } - } else { - whitelistI = new BiomeLocationList(ImmutableSet.copyOf( - this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) - .collect(Collectors.toList()))); - } - - if (this.blacklist.isEmpty()) { - blacklistI = new BiomeLocationEmpty(); - } else { - blacklistI = new BiomeLocationList(ImmutableSet.copyOf( - this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) - .collect(Collectors.toList()))); - } - - return new BiomeLocationComposition(whitelistI, blacklistI); - } + private final List whitelist = new LinkedList<>(); + private final List blacklist = new LinkedList<>(); + + private boolean acceptAll = false; + + public BiomeBuilder() { + // + } + + @Override + public IBiomeBuilder addWhitelistEntry(final Biome biome) { + this.whitelist.add(biome); + return this; + } + + @Override + public IBiomeBuilder addWhitelistEntry(final String biomeName) { + return this.addWhitelistEntry(new ResourceLocation(biomeName)); + } + + @Override + public IBiomeBuilder addWhitelistEntry(final ResourceLocation biomeResourceLocation) { + return this.addWhitelistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public IBiomeBuilder addBlacklistEntry(final Biome biome) { + this.blacklist.add(biome); + return this; + } + + @Override + public IBiomeBuilder addBlacklistEntry(final String biomeName) { + return this.addBlacklistEntry(new ResourceLocation(biomeName)); + } + + @Override + public IBiomeBuilder addBlacklistEntry(final ResourceLocation biomeResourceLocation) { + return this.addBlacklistEntry(ForgeRegistries.BIOMES.getValue(biomeResourceLocation)); + } + + @Override + public IBiomeBuilder setAcceptAll() { + this.acceptAll = true; + return this; + } + + @Override + public BiomeLocation create() { + if (this.acceptAll) { + return new BiomeLocationAcceptAny(); + } + + BiomeLocation whitelistI; + BiomeLocation blacklistI; + if (this.whitelist.isEmpty()) { + if (!this.blacklist.isEmpty()) { + whitelistI = new BiomeLocationAcceptAny(); + } else { + whitelistI = new BiomeLocationEmpty(); + } + } else { + whitelistI = new BiomeLocationList(ImmutableSet.copyOf( + this.whitelist.stream().map(biome -> new BiomeLocationSingle(biome)) + .collect(Collectors.toList()))); + } + + if (this.blacklist.isEmpty()) { + blacklistI = new BiomeLocationEmpty(); + } else { + blacklistI = new BiomeLocationList(ImmutableSet.copyOf( + this.blacklist.stream().map(biome -> new BiomeLocationSingle(biome)) + .collect(Collectors.toList()))); + } + + return new BiomeLocationComposition(whitelistI, blacklistI); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index c1c76b47..c7c57eab 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -11,162 +11,162 @@ public class BlockBuilder implements IBlockBuilder { - private IBlockState blockState; - private int chance; - private boolean isValid = true; - - public BlockBuilder() { - // nothing to do here - } - - @Override - public IBlockBuilder setFromBlockState(final IBlockState blockState) { - final ResourceLocation key = blockState.getBlock().getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockStateWithChance(blockState, 100); - } - - @Override - public IBlockBuilder setFromBlock(final Block block) { - final ResourceLocation key = block.getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockState(block.getDefaultState()); - } - - @Override - public IBlockBuilder setFromName(final String blockName) { - return this.setFromName(new ResourceLocation(blockName)); - } - - @Override - public IBlockBuilder setFromName(final String blockName, final String state) { - return this.setFromName(new ResourceLocation(blockName), state); - } - - @Override - public IBlockBuilder setFromName(final String blockName, final int metadata) { - return this.setFromName(new ResourceLocation(blockName), metadata); - } - - @Override - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); - } - - @Override - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final String state) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, - final int metadata) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); - } - - @Override - public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, - final int chance) { - final ResourceLocation key = blockState.getBlock().getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - this.blockState = blockState; - this.chance = chance; - return this; - } - - @Override - public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { - final ResourceLocation key = block.getRegistryName(); - if (!ForgeRegistries.BLOCKS.containsKey(key)) { - this.isValid = false; - } - return this.setFromBlockStateWithChance(block.getDefaultState(), chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final String state, - final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, - final int chance) { - return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), - chance); - } - - @Override - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final String state, final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), - chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, - final int metadata, final int chance) { - if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { - this.isValid = false; - } - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); - } - - @Override - public IBlockBuilder setChance(final int chance) { - this.chance = chance; - return this; - } - - @Override - public IBlockDefinition create() { - return new BlockDefinition(this.blockState, this.chance, this.isValid); - } + private IBlockState blockState; + private int chance; + private boolean isValid = true; + + public BlockBuilder() { + // nothing to do here + } + + @Override + public IBlockBuilder setFromBlockState(final IBlockState blockState) { + final ResourceLocation key = blockState.getBlock().getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockStateWithChance(blockState, 100); + } + + @Override + public IBlockBuilder setFromBlock(final Block block) { + final ResourceLocation key = block.getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockState(block.getDefaultState()); + } + + @Override + public IBlockBuilder setFromName(final String blockName) { + return this.setFromName(new ResourceLocation(blockName)); + } + + @Override + public IBlockBuilder setFromName(final String blockName, final String state) { + return this.setFromName(new ResourceLocation(blockName), state); + } + + @Override + public IBlockBuilder setFromName(final String blockName, final int metadata) { + return this.setFromName(new ResourceLocation(blockName), metadata); + } + + @Override + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + return this.setFromBlock(ForgeRegistries.BLOCKS.getValue(blockResourceLocation)); + } + + @Override + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final String state) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, + final int metadata) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockState(tempBlock.getStateFromMeta(metadata)); + } + + @Override + public IBlockBuilder setFromBlockStateWithChance(final IBlockState blockState, + final int chance) { + final ResourceLocation key = blockState.getBlock().getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + this.blockState = blockState; + this.chance = chance; + return this; + } + + @Override + public IBlockBuilder setFromBlockWithChance(final Block block, final int chance) { + final ResourceLocation key = block.getRegistryName(); + if (!ForgeRegistries.BLOCKS.containsKey(key)) { + this.isValid = false; + } + return this.setFromBlockStateWithChance(block.getDefaultState(), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final String state, + final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), state, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final String blockName, final int metadata, + final int chance) { + return this.setFromNameWithChance(new ResourceLocation(blockName), metadata, chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + return this.setFromBlockWithChance(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), + chance); + } + + @Override + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final String state, final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), + chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceLocation, + final int metadata, final int chance) { + if (!ForgeRegistries.BLOCKS.containsKey(blockResourceLocation)) { + this.isValid = false; + } + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + return this.setFromBlockStateWithChance(tempBlock.getStateFromMeta(metadata), chance); + } + + @Override + public IBlockBuilder setChance(final int chance) { + this.chance = chance; + return this; + } + + @Override + public IBlockDefinition create() { + return new BlockDefinition(this.blockState, this.chance, this.isValid); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java index 85f92e11..f30af422 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java @@ -6,28 +6,28 @@ public class BlockDefinition implements IBlockDefinition { - private final IBlockState blockState; - private final int blockChance; - private final boolean isValid; - - public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { - this.blockState = blockState; - this.blockChance = chance; - this.isValid = isValid; - } - - @Override - public IBlockState getBlock() { - return this.blockState; - } - - @Override - public int getChance() { - return this.blockChance; - } - - @Override - public boolean isValid() { - return this.isValid; - } + private final IBlockState blockState; + private final int blockChance; + private final boolean isValid; + + public BlockDefinition(final IBlockState blockState, final int chance, final boolean isValid) { + this.blockState = blockState; + this.blockChance = chance; + this.isValid = isValid; + } + + @Override + public IBlockState getBlock() { + return this.blockState; + } + + @Override + public int getChance() { + return this.blockChance; + } + + @Override + public boolean isValid() { + return this.isValid; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 65384779..5b2b9871 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -12,51 +12,51 @@ public class BlockList implements IBlockList { - private final List myBlocks; - private final List workingList; - - public BlockList() { - this.myBlocks = new LinkedList<>(); - this.workingList = new LinkedList<>(); - } - - @Override - public void addBlock(final IBlockDefinition block) { - this.myBlocks.add(block); - } - - @Override - public IBlockState getRandomBlock(final Random rand) { - if (this.workingList.isEmpty()) { - this.startNewSpawn(); - } - - final int spot = rand.nextInt(this.workingList.size()); - final IBlockState rv = this.workingList.get(spot); - this.workingList.remove(spot); - return rv; - } - - @Override - public void startNewSpawn() { - this.workingList.clear(); - - this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { - for (int i = 0; i < b.getChance(); i++) { - this.workingList.add(b.getBlock()); - } - }); - } - - @Override - public void dump() { - this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( - bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); - } - - @Override - public int count() { - return this.myBlocks.size(); - } + private final List myBlocks; + private final List workingList; + + public BlockList() { + this.myBlocks = new LinkedList<>(); + this.workingList = new LinkedList<>(); + } + + @Override + public void addBlock(final IBlockDefinition block) { + this.myBlocks.add(block); + } + + @Override + public IBlockState getRandomBlock(final Random rand) { + if (this.workingList.isEmpty()) { + this.startNewSpawn(); + } + + final int spot = rand.nextInt(this.workingList.size()); + final IBlockState rv = this.workingList.get(spot); + this.workingList.remove(spot); + return rv; + } + + @Override + public void startNewSpawn() { + this.workingList.clear(); + + this.myBlocks.stream().filter(b -> b.isValid()).forEach(b -> { + for (int i = 0; i < b.getChance(); i++) { + this.workingList.add(b.getBlock()); + } + }); + } + + @Override + public void dump() { + this.myBlocks.stream().map(bd -> bd.getBlock()).forEach( + bs -> OreSpawn.LOGGER.debug("Block %s (with state: %s)", bs.getBlock(), bs)); + } + + @Override + public int count() { + return this.myBlocks.size(); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java index 53971888..9467beb7 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java @@ -8,69 +8,69 @@ public class DimensionBuilder implements IDimensionBuilder { - private final List dimensionWhitelist = new LinkedList<>(); - private final List dimensionBlacklist = new LinkedList<>(); - private boolean acceptAll = false; - private boolean denyAll = false; - private boolean acceptAllOverworld = true; + private final List dimensionWhitelist = new LinkedList<>(); + private final List dimensionBlacklist = new LinkedList<>(); + private boolean acceptAll = false; + private boolean denyAll = false; + private boolean acceptAllOverworld = true; - public DimensionBuilder() { - // - } + public DimensionBuilder() { + // + } - @Override - public IDimensionBuilder addWhitelistEntry(final int dimensionID) { - this.acceptAllOverworld = false; - this.dimensionWhitelist.add(dimensionID); - return this; - } + @Override + public IDimensionBuilder addWhitelistEntry(final int dimensionID) { + this.acceptAllOverworld = false; + this.dimensionWhitelist.add(dimensionID); + return this; + } - @Override - public IDimensionBuilder addBlacklistEntry(final int dimensionID) { - this.acceptAllOverworld = false; - this.dimensionBlacklist.add(dimensionID); - return this; - } + @Override + public IDimensionBuilder addBlacklistEntry(final int dimensionID) { + this.acceptAllOverworld = false; + this.dimensionBlacklist.add(dimensionID); + return this; + } - @Override - public IDimensionBuilder setAcceptAll() { - if (this.denyAll) { - this.denyAll = false; - } - this.acceptAll = true; - return this; - } + @Override + public IDimensionBuilder setAcceptAll() { + if (this.denyAll) { + this.denyAll = false; + } + this.acceptAll = true; + return this; + } - @Override - public IDimensionBuilder setDenyAll() { - if (this.acceptAll) { - this.acceptAll = false; - } - this.denyAll = true; - return this; - } + @Override + public IDimensionBuilder setDenyAll() { + if (this.acceptAll) { + this.acceptAll = false; + } + this.denyAll = true; + return this; + } - @Override - public IDimensionList create() { - if (this.acceptAll - || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) - && !(this.acceptAllOverworld)) { - return new DimensionListAcceptAll(); - } else if (this.denyAll) { - return new DimensionListDenyAll(); - } else if (this.acceptAllOverworld) { - return new DimensionListAcceptAllOverworld(); - } else { - return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); - } - } + @Override + public IDimensionList create() { + if (this.acceptAll + || ((this.dimensionWhitelist.isEmpty()) && (this.dimensionBlacklist.isEmpty())) + && !(this.acceptAllOverworld)) { + return new DimensionListAcceptAll(); + } else if (this.denyAll) { + return new DimensionListDenyAll(); + } else if (this.acceptAllOverworld) { + return new DimensionListAcceptAllOverworld(); + } else { + return new DimensionList(this.dimensionWhitelist, this.dimensionBlacklist); + } + } - @Override - public IDimensionBuilder setAcceptAllOverworld() { - this.acceptAll = false; - this.denyAll = false; - this.acceptAllOverworld = true; - return this; - } + @Override + public IDimensionBuilder setAcceptAllOverworld() { + this.acceptAll = false; + this.denyAll = false; + this.acceptAllOverworld = true; + return this; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java index 8bd5219b..61d9ebc2 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java @@ -9,51 +9,51 @@ public class DimensionList implements com.mcmoddev.orespawn.api.IDimensionList { - private final List whitelist = new ArrayList<>(); - private final List blacklist = new ArrayList<>(); - - public DimensionList(final List whitelist, final List blacklist) { - this.whitelist.addAll(whitelist); - this.blacklist.addAll(blacklist); - } - - @Override - public boolean matches(final int dimensionID) { - if (this.whitelist.contains(Integer.valueOf(dimensionID))) { - return true; - } - if (this.blacklist.contains(Integer.valueOf(dimensionID))) { - return false; - } - if (!this.whitelist.isEmpty()) { - return false; - } - if (!this.blacklist.isEmpty()) { - return true; - } - - // if it gets here, the whitelist and blacklist are empty... - // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... - return true; - } - - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - if (!this.whitelist.isEmpty()) { - final JsonArray wl = new JsonArray(); - whitelist.stream().forEach(wl::add); - rv.add(Constants.ConfigNames.WHITELIST, wl); - } - - if (!this.blacklist.isEmpty()) { - final JsonArray bl = new JsonArray(); - blacklist.stream().forEach(bl::add); - rv.add(Constants.ConfigNames.WHITELIST, bl); - } else if (this.whitelist.isEmpty()) { - return new DimensionListAcceptAllOverworld().serialize(); - } - - return rv; - } + private final List whitelist = new ArrayList<>(); + private final List blacklist = new ArrayList<>(); + + public DimensionList(final List whitelist, final List blacklist) { + this.whitelist.addAll(whitelist); + this.blacklist.addAll(blacklist); + } + + @Override + public boolean matches(final int dimensionID) { + if (this.whitelist.contains(Integer.valueOf(dimensionID))) { + return true; + } + if (this.blacklist.contains(Integer.valueOf(dimensionID))) { + return false; + } + if (!this.whitelist.isEmpty()) { + return false; + } + if (!this.blacklist.isEmpty()) { + return true; + } + + // if it gets here, the whitelist and blacklist are empty... + // ***THAT*** should have resulted in a DimensionListAcceptAll being created, but... + return true; + } + + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + if (!this.whitelist.isEmpty()) { + final JsonArray wl = new JsonArray(); + whitelist.stream().forEach(wl::add); + rv.add(Constants.ConfigNames.WHITELIST, wl); + } + + if (!this.blacklist.isEmpty()) { + final JsonArray bl = new JsonArray(); + blacklist.stream().forEach(bl::add); + rv.add(Constants.ConfigNames.WHITELIST, bl); + } else if (this.whitelist.isEmpty()) { + return new DimensionListAcceptAllOverworld().serialize(); + } + + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java index bd871741..8f2b1ce0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java @@ -7,15 +7,15 @@ public class DimensionListAcceptAll implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return true; - } + @Override + public boolean matches(final int dimensionID) { + return true; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - rv.add(ConfigNames.BLACKLIST, new JsonArray()); - return rv; - } + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + rv.add(ConfigNames.BLACKLIST, new JsonArray()); + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java index 5727d875..263272ca 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java @@ -7,19 +7,19 @@ public class DimensionListAcceptAllOverworld implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return dimensionID != -1 && dimensionID != 1; - } + @Override + public boolean matches(final int dimensionID) { + return dimensionID != -1 && dimensionID != 1; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - final JsonArray bl = new JsonArray(); - bl.add(-1); - bl.add(1); - rv.add(Constants.ConfigNames.BLACKLIST, bl); + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + final JsonArray bl = new JsonArray(); + bl.add(-1); + bl.add(1); + rv.add(Constants.ConfigNames.BLACKLIST, bl); - return rv; - } + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java index 54c527aa..49eef5c0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java @@ -7,16 +7,16 @@ public class DimensionListDenyAll implements IDimensionList { - @Override - public boolean matches(final int dimensionID) { - return false; - } + @Override + public boolean matches(final int dimensionID) { + return false; + } - @Override - public JsonObject serialize() { - final JsonObject rv = new JsonObject(); - rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); + @Override + public JsonObject serialize() { + final JsonObject rv = new JsonObject(); + rv.add(Constants.ConfigNames.WHITELIST, new JsonArray()); - return rv; - } + return rv; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 7ac4166b..63f61da3 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -11,110 +11,110 @@ public class FeatureBuilder implements IFeatureBuilder { - private IFeature feature; - private JsonObject parameters; - private boolean useDefaults; - - public FeatureBuilder() { - this.useDefaults = false; - this.parameters = new JsonObject(); - } - - @Override - public IFeatureBuilder setFeature(final String featureName) { - String actName = featureName; - if (!actName.contains(":")) { - actName = String.format("orespawn:%s", featureName); - } - return this.setFeature(new ResourceLocation(actName)); - } - - @Override - public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { - if (!OreSpawn.API.featureExists(featureResourceLocation)) { - OreSpawn.LOGGER.warn( - "Feature %s is not known, feature for this will be set to the default feature", - featureResourceLocation.getPath()); - } - return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); - } - - @Override - public IFeatureBuilder setFeature(final IFeature feature) { - this.feature = feature; - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - return this; - } - - @Override - public IFeatureBuilder setParameter(final String parameterName, - final JsonElement parameterValue) { - this.parameters.add(parameterName, parameterValue); - return this; - } - - private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, - final FeatureEntry feat) { - if (parameterValue.getAsJsonPrimitive().isBoolean()) { - feat.setParameter(parameterName, parameterValue.getAsBoolean()); - } else if (parameterValue.getAsJsonPrimitive().isString()) { - feat.setParameter(parameterName, parameterValue.getAsString()); - } else { - float paramAsFloat = parameterValue.getAsFloat(); - if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { - feat.setParameter(parameterName, parameterValue.getAsFloat()); - } else { - feat.setParameter(parameterName, parameterValue.getAsInt()); - } - } - } - - @Override - public IFeatureBuilder setUseFeatureDefaults() { - this.useDefaults = true; - return this; - } - - @Override - public IFeatureEntry create() { - final FeatureEntry res = new FeatureEntry(this.feature); - if (!this.useDefaults) { - // only copy in the parameters we need - this.feature.getDefaultParameters().entrySet().stream() - .filter(ent -> !this.parameters.has(ent.getKey())) - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); - } else { - // overwrite - they've said to just use the defaults - this.feature.getDefaultParameters().entrySet().stream() - .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); - } - - this.parameters.entrySet().stream() - .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); - - return res; - } + private IFeature feature; + private JsonObject parameters; + private boolean useDefaults; + + public FeatureBuilder() { + this.useDefaults = false; + this.parameters = new JsonObject(); + } + + @Override + public IFeatureBuilder setFeature(final String featureName) { + String actName = featureName; + if (!actName.contains(":")) { + actName = String.format("orespawn:%s", featureName); + } + return this.setFeature(new ResourceLocation(actName)); + } + + @Override + public IFeatureBuilder setFeature(final ResourceLocation featureResourceLocation) { + if (!OreSpawn.API.featureExists(featureResourceLocation)) { + OreSpawn.LOGGER.warn( + "Feature %s is not known, feature for this will be set to the default feature", + featureResourceLocation.getPath()); + } + return this.setFeature(OreSpawn.API.getFeature(featureResourceLocation)); + } + + @Override + public IFeatureBuilder setFeature(final IFeature feature) { + this.feature = feature; + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final String parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final int parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final float parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, final boolean parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + return this; + } + + @Override + public IFeatureBuilder setParameter(final String parameterName, + final JsonElement parameterValue) { + this.parameters.add(parameterName, parameterValue); + return this; + } + + private void setFeatureParameter(final String parameterName, final JsonElement parameterValue, + final FeatureEntry feat) { + if (parameterValue.getAsJsonPrimitive().isBoolean()) { + feat.setParameter(parameterName, parameterValue.getAsBoolean()); + } else if (parameterValue.getAsJsonPrimitive().isString()) { + feat.setParameter(parameterName, parameterValue.getAsString()); + } else { + float paramAsFloat = parameterValue.getAsFloat(); + if ((paramAsFloat - Math.floor(paramAsFloat)) > 0) { + feat.setParameter(parameterName, parameterValue.getAsFloat()); + } else { + feat.setParameter(parameterName, parameterValue.getAsInt()); + } + } + } + + @Override + public IFeatureBuilder setUseFeatureDefaults() { + this.useDefaults = true; + return this; + } + + @Override + public IFeatureEntry create() { + final FeatureEntry res = new FeatureEntry(this.feature); + if (!this.useDefaults) { + // only copy in the parameters we need + this.feature.getDefaultParameters().entrySet().stream() + .filter(ent -> !this.parameters.has(ent.getKey())) + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } else { + // overwrite - they've said to just use the defaults + this.feature.getDefaultParameters().entrySet().stream() + .forEach(ent -> this.parameters.add(ent.getKey(), ent.getValue())); + } + + this.parameters.entrySet().stream() + .forEach(ent -> this.setFeatureParameter(ent.getKey(), ent.getValue(), res)); + + return res; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java index 45425250..c5d7167d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java @@ -6,48 +6,48 @@ public class FeatureEntry implements IFeatureEntry { - private final IFeature feature; - private final JsonObject parameters; - - public FeatureEntry(final IFeature feature) { - this.feature = feature; - this.parameters = new JsonObject(); - } - - @Override - public IFeature getFeature() { - return this.feature; - } - - @Override - public String getFeatureName() { - return this.feature.getRegistryName().getPath(); - } - - @Override - public JsonObject getFeatureParameters() { - final JsonObject defs = feature.getDefaultParameters(); - this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); - return defs; - } - - @Override - public void setParameter(final String parameterName, final String parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final int parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final boolean parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } - - @Override - public void setParameter(final String parameterName, final float parameterValue) { - this.parameters.addProperty(parameterName, parameterValue); - } + private final IFeature feature; + private final JsonObject parameters; + + public FeatureEntry(final IFeature feature) { + this.feature = feature; + this.parameters = new JsonObject(); + } + + @Override + public IFeature getFeature() { + return this.feature; + } + + @Override + public String getFeatureName() { + return this.feature.getRegistryName().getPath(); + } + + @Override + public JsonObject getFeatureParameters() { + final JsonObject defs = feature.getDefaultParameters(); + this.parameters.entrySet().stream().forEach(ent -> defs.add(ent.getKey(), ent.getValue())); + return defs; + } + + @Override + public void setParameter(final String parameterName, final String parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final int parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final boolean parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } + + @Override + public void setParameter(final String parameterName, final float parameterValue) { + this.parameters.addProperty(parameterName, parameterValue); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 0c7035f1..1559f718 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -44,224 +44,224 @@ public class OS3APIImpl implements OS3API { - private static final Map spawns; - private static final FeatureRegistry features; - private static final ReplacementsRegistry replacements; - private static final PresetsStorage presets; - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - private static final Map spawnsToSourceFiles = new TreeMap<>(); - - static { - spawns = new ConcurrentHashMap<>(); - features = new FeatureRegistry(); - replacements = new ReplacementsRegistry(); - presets = new PresetsStorage(); - } - - public OS3APIImpl() { - // - } - - public void loadConfigFiles() { - final String failedReadingConfigsFrom = "Failed reading configs from "; - PathMatcher featuresFiles = FileSystems.getDefault() - .getPathMatcher("glob:**/features-*.json"); - PathMatcher replacementsFiles = FileSystems.getDefault() - .getPathMatcher("glob:**/replacements-*.json"); - PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); - - try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(featuresFiles::matches).map(Path::toFile) - .forEach(features::loadFeaturesFile); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.SYSCONF.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - - // have to do this twice or we have issues - try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { - stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.SYSCONF.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - - if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { - presets.load(Constants.SYSCONF.resolve("presets-default.json")); - } - - try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { - stream.filter(jsonMatcher::matches).forEach(conf -> { - try { - OreSpawnReader.tryReadFile(conf, this); - } catch (final MissingVersionException | NotAProperConfigException - | OldVersionException | UnknownVersionException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - }); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - failedReadingConfigsFrom + Constants.CONFDIR.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } - - @Override - public void addSpawn(final ISpawnEntry spawnEntry) { - if (spawnEntry != null) { - spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); - } - } - - @Override - public void addFeature(final String featureName, final IFeature feature) { - features.addFeature(featureName, feature); - } - - @Override - public void addReplacement(final IReplacementEntry replacementEntry) { - replacements.addReplacement(replacementEntry); - } - - @Override - public ISpawnBuilder getSpawnBuilder() { - return new SpawnBuilder(); - } - - @Override - public IDimensionBuilder getDimensionBuilder() { - return new DimensionBuilder(); - } - - @Override - public IFeatureBuilder getFeatureBuilder() { - return new FeatureBuilder(); - } - - @Override - public IBlockBuilder getBlockBuilder() { - return new BlockBuilder(); - } - - @Override - public IBiomeBuilder getBiomeBuilder() { - return new BiomeBuilder(); - } - - @Override - public IReplacementBuilder getReplacementBuilder() { - return new ReplacementBuilder(); - } - - @Override - public Map getReplacements() { - final Map temp = new HashMap<>(); - replacements.getReplacements().entrySet().stream() - .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); - return ImmutableMap.copyOf(temp); - } - - @Override - public IReplacementEntry getReplacement(final String replacementName) { - return replacements.getReplacement(replacementName); - } - - @Override - public List getSpawns(final int dimensionID) { - return ImmutableList.copyOf( - spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) - .map(e -> e.getValue()).collect(Collectors.toList())); - } - - @Override - public ISpawnEntry getSpawn(final String spawnName) { - return spawns.get(new ResourceLocation(spawnName)); - } - - @Override - public Map getAllSpawns() { - final Map sp = new HashMap<>(); - spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); - return ImmutableMap.copyOf(sp); - } - - @Override - public boolean featureExists(final String featureName) { - return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName - : String.format("orespawn:%s", featureName))); - } - - @Override - public boolean featureExists(final ResourceLocation featureName) { - return features.hasFeature(featureName); - } - - @Override - public IFeature getFeature(final String featureName) { - return this.getFeature(new ResourceLocation(featureName)); - } - - @Override - public IFeature getFeature(final ResourceLocation featureName) { - return features.getFeature(featureName); - } - - @Override - public PresetsStorage copyPresets() { - final PresetsStorage copy = new PresetsStorage(); - presets.copy(copy); - return copy; - } - - @Override - public List getDimensionDefaultReplacements(final int dimensionID) { - return replacements.getDimensionDefault(dimensionID); - } - - @Override - public boolean hasReplacement(final ResourceLocation resourceLocation) { - return replacements.has(resourceLocation); - } - - @Override - public boolean hasReplacement(final String name) { - return this.hasReplacement(new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name))); - } - - @Override - public void mapEntryToFile(final Path p, final String entryName) { - spawnsToSourceFiles.put(entryName, p); - } - - @Override - public List getSpawnsForFile(final String fileName) { - final Path p = Constants.CONFDIR.resolve(fileName); - final List values = spawnsToSourceFiles.entrySet().stream() - .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) - .collect(Collectors.toList()); - return ImmutableList.copyOf(values); - } - - @Override - public Map> getSpawnsByFile() { - final Map> temp = new HashMap<>(); - spawnsToSourceFiles.entrySet().stream().forEach(ent -> { - if (temp.containsKey(ent.getValue())) { - temp.get(ent.getValue()).add(ent.getKey()); - } else { - temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); - } - }); - - return ImmutableMap.copyOf(temp); - } + private static final Map spawns; + private static final FeatureRegistry features; + private static final ReplacementsRegistry replacements; + private static final PresetsStorage presets; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final Map spawnsToSourceFiles = new TreeMap<>(); + + static { + spawns = new ConcurrentHashMap<>(); + features = new FeatureRegistry(); + replacements = new ReplacementsRegistry(); + presets = new PresetsStorage(); + } + + public OS3APIImpl() { + // + } + + public void loadConfigFiles() { + final String failedReadingConfigsFrom = "Failed reading configs from "; + PathMatcher featuresFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/features-*.json"); + PathMatcher replacementsFiles = FileSystems.getDefault() + .getPathMatcher("glob:**/replacements-*.json"); + PathMatcher jsonMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.json"); + + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { + stream.filter(featuresFiles::matches).map(Path::toFile) + .forEach(features::loadFeaturesFile); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + // have to do this twice or we have issues + try (final Stream stream = Files.walk(Constants.SYSCONF, 1)) { + stream.filter(replacementsFiles::matches).forEach(replacements::loadFile); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.SYSCONF.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + + if (Constants.SYSCONF.resolve("presets-default.json").toFile().exists()) { + presets.load(Constants.SYSCONF.resolve("presets-default.json")); + } + + try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { + stream.filter(jsonMatcher::matches).forEach(conf -> { + try { + OreSpawnReader.tryReadFile(conf, this); + } catch (final MissingVersionException | NotAProperConfigException + | OldVersionException | UnknownVersionException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + failedReadingConfigsFrom + Constants.CONFDIR.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } + + @Override + public void addSpawn(final ISpawnEntry spawnEntry) { + if (spawnEntry != null) { + spawns.put(new ResourceLocation(spawnEntry.getSpawnName()), spawnEntry); + } + } + + @Override + public void addFeature(final String featureName, final IFeature feature) { + features.addFeature(featureName, feature); + } + + @Override + public void addReplacement(final IReplacementEntry replacementEntry) { + replacements.addReplacement(replacementEntry); + } + + @Override + public ISpawnBuilder getSpawnBuilder() { + return new SpawnBuilder(); + } + + @Override + public IDimensionBuilder getDimensionBuilder() { + return new DimensionBuilder(); + } + + @Override + public IFeatureBuilder getFeatureBuilder() { + return new FeatureBuilder(); + } + + @Override + public IBlockBuilder getBlockBuilder() { + return new BlockBuilder(); + } + + @Override + public IBiomeBuilder getBiomeBuilder() { + return new BiomeBuilder(); + } + + @Override + public IReplacementBuilder getReplacementBuilder() { + return new ReplacementBuilder(); + } + + @Override + public Map getReplacements() { + final Map temp = new HashMap<>(); + replacements.getReplacements().entrySet().stream() + .forEach(e -> temp.put(e.getKey().getPath(), e.getValue())); + return ImmutableMap.copyOf(temp); + } + + @Override + public IReplacementEntry getReplacement(final String replacementName) { + return replacements.getReplacement(replacementName); + } + + @Override + public List getSpawns(final int dimensionID) { + return ImmutableList.copyOf( + spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) + .map(e -> e.getValue()).collect(Collectors.toList())); + } + + @Override + public ISpawnEntry getSpawn(final String spawnName) { + return spawns.get(new ResourceLocation(spawnName)); + } + + @Override + public Map getAllSpawns() { + final Map sp = new HashMap<>(); + spawns.entrySet().forEach(ent -> sp.put(ent.getKey().getPath(), ent.getValue())); + return ImmutableMap.copyOf(sp); + } + + @Override + public boolean featureExists(final String featureName) { + return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName + : String.format("orespawn:%s", featureName))); + } + + @Override + public boolean featureExists(final ResourceLocation featureName) { + return features.hasFeature(featureName); + } + + @Override + public IFeature getFeature(final String featureName) { + return this.getFeature(new ResourceLocation(featureName)); + } + + @Override + public IFeature getFeature(final ResourceLocation featureName) { + return features.getFeature(featureName); + } + + @Override + public PresetsStorage copyPresets() { + final PresetsStorage copy = new PresetsStorage(); + presets.copy(copy); + return copy; + } + + @Override + public List getDimensionDefaultReplacements(final int dimensionID) { + return replacements.getDimensionDefault(dimensionID); + } + + @Override + public boolean hasReplacement(final ResourceLocation resourceLocation) { + return replacements.has(resourceLocation); + } + + @Override + public boolean hasReplacement(final String name) { + return this.hasReplacement(new ResourceLocation( + name.contains(":") ? name : String.format("orespawn:%s", name))); + } + + @Override + public void mapEntryToFile(final Path p, final String entryName) { + spawnsToSourceFiles.put(entryName, p); + } + + @Override + public List getSpawnsForFile(final String fileName) { + final Path p = Constants.CONFDIR.resolve(fileName); + final List values = spawnsToSourceFiles.entrySet().stream() + .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) + .collect(Collectors.toList()); + return ImmutableList.copyOf(values); + } + + @Override + public Map> getSpawnsByFile() { + final Map> temp = new HashMap<>(); + spawnsToSourceFiles.entrySet().stream().forEach(ent -> { + if (temp.containsKey(ent.getValue())) { + temp.get(ent.getValue()).add(ent.getKey()); + } else { + temp.put(ent.getValue(), Lists.newLinkedList(Arrays.asList(ent.getKey()))); + } + }); + + return ImmutableMap.copyOf(temp); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index b21fec9c..df6eb61a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -16,89 +16,89 @@ public class ReplacementBuilder implements IReplacementBuilder { - private String replacementName = null; - private List entries; - - public ReplacementBuilder() { - this.entries = new LinkedList<>(); - } - - @Override - public IReplacementBuilder setFromName(final String entryName) { - this.replacementName = entryName; - this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); - return this; - } - - @Override - public IReplacementBuilder setName(final String name) { - this.replacementName = name; - return this; - } - - @Override - public IReplacementBuilder addEntry(final IBlockState blockState) { - this.entries.add(blockState); - return this; - } - - @Override - public IReplacementBuilder addEntry(final String blockName) { - return this.addEntry(new ResourceLocation(blockName)); - } - - @Override - public IReplacementBuilder addEntry(final String blockName, final String state) { - return this.addEntry(new ResourceLocation(blockName), state); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IReplacementBuilder addEntry(final String blockName, final int metadata) { - return this.addEntry(new ResourceLocation(blockName), metadata); - } - - @Override - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { - return this - .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); - } - - @Override - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final String state) { - return this.addEntry(StateUtil - .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, - final int metadata) { - return this.addEntry( - ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); - } - - @Override - public boolean hasEntries() { - return !this.entries.isEmpty(); - } - - @Override - public IReplacementEntry create() { - if (this.replacementName == null) { - this.replacementName = String.format("replacement_%s", - RandomStringUtils.randomAlphanumeric(8, 16)); - } - - return new ReplacementEntry(this.replacementName, this.entries); - } + private String replacementName = null; + private List entries; + + public ReplacementBuilder() { + this.entries = new LinkedList<>(); + } + + @Override + public IReplacementBuilder setFromName(final String entryName) { + this.replacementName = entryName; + this.entries.addAll(OreSpawn.API.getReplacement(entryName).getEntries()); + return this; + } + + @Override + public IReplacementBuilder setName(final String name) { + this.replacementName = name; + return this; + } + + @Override + public IReplacementBuilder addEntry(final IBlockState blockState) { + this.entries.add(blockState); + return this; + } + + @Override + public IReplacementBuilder addEntry(final String blockName) { + return this.addEntry(new ResourceLocation(blockName)); + } + + @Override + public IReplacementBuilder addEntry(final String blockName, final String state) { + return this.addEntry(new ResourceLocation(blockName), state); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IReplacementBuilder addEntry(final String blockName, final int metadata) { + return this.addEntry(new ResourceLocation(blockName), metadata); + } + + @Override + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation) { + return this + .addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); + } + + @Override + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final String state) { + return this.addEntry(StateUtil + .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, + final int metadata) { + return this.addEntry( + ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getStateFromMeta(metadata)); + } + + @Override + public boolean hasEntries() { + return !this.entries.isEmpty(); + } + + @Override + public IReplacementEntry create() { + if (this.replacementName == null) { + this.replacementName = String.format("replacement_%s", + RandomStringUtils.randomAlphanumeric(8, 16)); + } + + return new ReplacementEntry(this.replacementName, this.entries); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java index 34f487e1..e2e21fce 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java @@ -12,31 +12,31 @@ import net.minecraftforge.registries.IForgeRegistryEntry; public class ReplacementEntry extends IForgeRegistryEntry.Impl - implements IReplacementEntry { - - private final List matchVal; - private OreSpawnBlockMatcher matcher = null; - - public ReplacementEntry(final String name, final IBlockState... toMatch) { - super.setRegistryName(name); - this.matchVal = Arrays.asList(toMatch); - } - - public ReplacementEntry(final String name, final List toMatch) { - super.setRegistryName(name); - this.matchVal = new ArrayList<>(); - this.matchVal.addAll(toMatch); - } - - @Override - public OreSpawnBlockMatcher getMatcher() { - if (this.matcher == null) { - this.matcher = new OreSpawnBlockMatcher(this.matchVal); - } - return this.matcher; - } - - public List getEntries() { - return ImmutableList.copyOf(this.matchVal); - } + implements IReplacementEntry { + + private final List matchVal; + private OreSpawnBlockMatcher matcher = null; + + public ReplacementEntry(final String name, final IBlockState... toMatch) { + super.setRegistryName(name); + this.matchVal = Arrays.asList(toMatch); + } + + public ReplacementEntry(final String name, final List toMatch) { + super.setRegistryName(name); + this.matchVal = new ArrayList<>(); + this.matchVal.addAll(toMatch); + } + + @Override + public OreSpawnBlockMatcher getMatcher() { + if (this.matcher == null) { + this.matcher = new OreSpawnBlockMatcher(this.matchVal); + } + return this.matcher; + } + + public List getEntries() { + return ImmutableList.copyOf(this.matchVal); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 1a902d97..1c95bb11 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -16,199 +16,199 @@ public class SpawnBuilder implements ISpawnBuilder { - private String spawnName; - private boolean enabled; - private boolean retrogen; - private IBlockList blocks; - private IFeatureEntry feature; - private BiomeLocation biomes; - private IDimensionList dimensions; - private IReplacementEntry replacements; - - public SpawnBuilder() { - this.enabled = false; - this.retrogen = false; - this.blocks = new BlockList(); - } - - public SpawnBuilder(final String spawnName) { - this(); - this.spawnName = spawnName; - } - - @Override - public ISpawnBuilder setName(final String name) { - this.spawnName = name; - return this; - } - - @Override - public ISpawnBuilder setDimensions(final IDimensionList dimensions) { - this.dimensions = dimensions; - return this; - } - - @Override - public ISpawnBuilder setBiomes(final BiomeLocation biomes) { - this.biomes = biomes; - return this; - } - - @Override - public ISpawnBuilder setEnabled(final boolean enabled) { - this.enabled = enabled; - return this; - } - - @Override - public ISpawnBuilder setRetrogen(final boolean retrogen) { - this.retrogen = retrogen; - return this; - } - - @Override - public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { - this.replacements = replacements; - return this; - } - - @Override - public ISpawnBuilder setFeature(final IFeatureEntry feature) { - this.feature = feature; - return this; - } - - @Override - public ISpawnBuilder addBlock(final String blockName) { - return this.addBlock(new ResourceLocation(blockName)); - } - - @Override - public ISpawnBuilder addBlock(final String blockName, final String blockState) { - return this.addBlock(new ResourceLocation(blockName), blockState); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { - return this.addBlock(new ResourceLocation(blockName), blockMetadata); - } - - @Override - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { - return this.addBlockWithChance(blockResourceLocation, 100); - } - - @Override - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final String blockState) { - return this.addBlockWithChance(blockResourceLocation, blockState, 100); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, - final int blockMetadata) { - return this.addBlockWithChance(blockResourceLocation, 100); - } - - @Override - public ISpawnBuilder addBlock(final Block block) { - return this.addBlockWithChance(block, 100); - } - - @Override - public ISpawnBuilder addBlock(final IBlockState block) { - return this.addBlockWithChance(block, 100); - } - - @Override - public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { - return this.addBlockWithChance(new ResourceLocation(blockName), chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, - final int chance) { - return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, - final int chance) { - return this.addBlockWithChance(blockName, blockMetadata, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int chance) { - final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) - .getDefaultState(); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final String blockState, final int chance) { - final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); - return this.addBlockWithChance(tempVar, chance); - } - - /** - * - * @deprecated - */ - @Override - @Deprecated - public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, - final int blockMetadata, final int chance) { - final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) - .getStateFromMeta(blockMetadata); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { - final IBlockState tempVar = block.getDefaultState(); - return this.addBlockWithChance(tempVar, chance); - } - - @Override - public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { - final BlockBuilder bb = new BlockBuilder(); - bb.setFromBlockStateWithChance(block, chance); - return this.addBlock(bb.create()); - } - - @Override - public ISpawnBuilder addBlock(final IBlockDefinition block) { - if (block.isValid()) { - this.blocks.addBlock(block); - } - return this; - } - - @Override - public SpawnEntry create() { - if (this.blocks.count() > 0) { - return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, - this.biomes, this.replacements, this.blocks, this.feature); - } else { - return null; - } - } + private String spawnName; + private boolean enabled; + private boolean retrogen; + private IBlockList blocks; + private IFeatureEntry feature; + private BiomeLocation biomes; + private IDimensionList dimensions; + private IReplacementEntry replacements; + + public SpawnBuilder() { + this.enabled = false; + this.retrogen = false; + this.blocks = new BlockList(); + } + + public SpawnBuilder(final String spawnName) { + this(); + this.spawnName = spawnName; + } + + @Override + public ISpawnBuilder setName(final String name) { + this.spawnName = name; + return this; + } + + @Override + public ISpawnBuilder setDimensions(final IDimensionList dimensions) { + this.dimensions = dimensions; + return this; + } + + @Override + public ISpawnBuilder setBiomes(final BiomeLocation biomes) { + this.biomes = biomes; + return this; + } + + @Override + public ISpawnBuilder setEnabled(final boolean enabled) { + this.enabled = enabled; + return this; + } + + @Override + public ISpawnBuilder setRetrogen(final boolean retrogen) { + this.retrogen = retrogen; + return this; + } + + @Override + public ISpawnBuilder setReplacement(final IReplacementEntry replacements) { + this.replacements = replacements; + return this; + } + + @Override + public ISpawnBuilder setFeature(final IFeatureEntry feature) { + this.feature = feature; + return this; + } + + @Override + public ISpawnBuilder addBlock(final String blockName) { + return this.addBlock(new ResourceLocation(blockName)); + } + + @Override + public ISpawnBuilder addBlock(final String blockName, final String blockState) { + return this.addBlock(new ResourceLocation(blockName), blockState); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlock(final String blockName, final int blockMetadata) { + return this.addBlock(new ResourceLocation(blockName), blockMetadata); + } + + @Override + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final String blockState) { + return this.addBlockWithChance(blockResourceLocation, blockState, 100); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlock(final ResourceLocation blockResourceLocation, + final int blockMetadata) { + return this.addBlockWithChance(blockResourceLocation, 100); + } + + @Override + public ISpawnBuilder addBlock(final Block block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public ISpawnBuilder addBlock(final IBlockState block) { + return this.addBlockWithChance(block, 100); + } + + @Override + public ISpawnBuilder addBlockWithChance(final String blockName, final int chance) { + return this.addBlockWithChance(new ResourceLocation(blockName), chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final String blockName, final String blockState, + final int chance) { + return this.addBlockWithChance(new ResourceLocation(blockName), blockState, chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlockWithChance(final String blockName, final int blockMetadata, + final int chance) { + return this.addBlockWithChance(blockName, blockMetadata, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int chance) { + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final String blockState, final int chance) { + final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); + final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); + return this.addBlockWithChance(tempVar, chance); + } + + /** + * + * @deprecated + */ + @Override + @Deprecated + public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, + final int blockMetadata, final int chance) { + final IBlockState tempVar = ForgeRegistries.BLOCKS.getValue(blockResourceLocation) + .getStateFromMeta(blockMetadata); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final Block block, final int chance) { + final IBlockState tempVar = block.getDefaultState(); + return this.addBlockWithChance(tempVar, chance); + } + + @Override + public ISpawnBuilder addBlockWithChance(final IBlockState block, final int chance) { + final BlockBuilder bb = new BlockBuilder(); + bb.setFromBlockStateWithChance(block, chance); + return this.addBlock(bb.create()); + } + + @Override + public ISpawnBuilder addBlock(final IBlockDefinition block) { + if (block.isValid()) { + this.blocks.addBlock(block); + } + return this; + } + + @Override + public SpawnEntry create() { + if (this.blocks.count() > 0) { + return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, + this.biomes, this.replacements, this.blocks, this.feature); + } else { + return null; + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java index 58ac7bfb..8aa72589 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java @@ -19,89 +19,89 @@ public class SpawnEntry implements com.mcmoddev.orespawn.api.os3.ISpawnEntry { - private final String spawnName; - private final IDimensionList dimensions; - private final IReplacementEntry replacements; - private final IBlockList blocks; - private final BiomeLocation biomes; - private final IFeatureEntry feature; - private final boolean enabled; - private final boolean retrogen; - - public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, - final IDimensionList dimensions, final BiomeLocation biomes, - final IReplacementEntry replacements, final IBlockList blocks, - final IFeatureEntry feature) { - this.spawnName = spawnName; - this.enabled = enabled; - this.retrogen = retrogen; - this.dimensions = dimensions; - this.biomes = biomes; - this.replacements = replacements; - this.blocks = blocks; - this.feature = feature; - } - - @Override - public boolean isRetrogen() { - return this.retrogen; - } - - @Override - public boolean isEnabled() { - return this.enabled; - } - - @Override - public String getSpawnName() { - return this.spawnName; - } - - @Override - public boolean dimensionAllowed(final int dimension) { - return this.dimensions.matches(dimension); - } - - @Override - public boolean biomeAllowed(final ResourceLocation biomeName) { - return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); - } - - @Override - public boolean biomeAllowed(final Biome biome) { - return this.biomes.matches(biome); - } - - @Override - public IFeatureEntry getFeature() { - return this.feature; - } - - @Override - public OreSpawnBlockMatcher getMatcher() { - return this.replacements.getMatcher(); - } - - @Override - public IBlockList getBlocks() { - return this.blocks; - } - - @Override - public void generate(final Random random, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, - final ChunkPos pos) { - this.feature.getFeature().setRandom(random); - this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); - } - - @Override - public IDimensionList getDimensions() { - return this.dimensions; - } - - @Override - public BiomeLocation getBiomes() { - return this.biomes; - } + private final String spawnName; + private final IDimensionList dimensions; + private final IReplacementEntry replacements; + private final IBlockList blocks; + private final BiomeLocation biomes; + private final IFeatureEntry feature; + private final boolean enabled; + private final boolean retrogen; + + public SpawnEntry(final String spawnName, final boolean enabled, final boolean retrogen, + final IDimensionList dimensions, final BiomeLocation biomes, + final IReplacementEntry replacements, final IBlockList blocks, + final IFeatureEntry feature) { + this.spawnName = spawnName; + this.enabled = enabled; + this.retrogen = retrogen; + this.dimensions = dimensions; + this.biomes = biomes; + this.replacements = replacements; + this.blocks = blocks; + this.feature = feature; + } + + @Override + public boolean isRetrogen() { + return this.retrogen; + } + + @Override + public boolean isEnabled() { + return this.enabled; + } + + @Override + public String getSpawnName() { + return this.spawnName; + } + + @Override + public boolean dimensionAllowed(final int dimension) { + return this.dimensions.matches(dimension); + } + + @Override + public boolean biomeAllowed(final ResourceLocation biomeName) { + return this.biomeAllowed(ForgeRegistries.BIOMES.getValue(biomeName)); + } + + @Override + public boolean biomeAllowed(final Biome biome) { + return this.biomes.matches(biome); + } + + @Override + public IFeatureEntry getFeature() { + return this.feature; + } + + @Override + public OreSpawnBlockMatcher getMatcher() { + return this.replacements.getMatcher(); + } + + @Override + public IBlockList getBlocks() { + return this.blocks; + } + + @Override + public void generate(final Random random, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider, + final ChunkPos pos) { + this.feature.getFeature().setRandom(random); + this.feature.getFeature().generate(world, chunkGenerator, chunkProvider, this, pos); + } + + @Override + public IDimensionList getDimensions() { + return this.dimensions; + } + + @Override + public BiomeLocation getBiomes() { + return this.biomes; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 3010949d..989866e7 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -46,363 +46,363 @@ public class OreSpawnReader { - private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; + private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) - throws MissingVersionException, NotAProperConfigException, OldVersionException, - UnknownVersionException { - final JsonParser parser = new JsonParser(); + public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) + throws MissingVersionException, NotAProperConfigException, OldVersionException, + UnknownVersionException { + final JsonParser parser = new JsonParser(); - try (BufferedReader data = Files.newBufferedReader(conf)) { - final JsonElement json = parser.parse(data); + try (BufferedReader data = Files.newBufferedReader(conf)) { + final JsonElement json = parser.parse(data); - if (!json.isJsonObject()) { - throw new NotAProperConfigException(); - } + if (!json.isJsonObject()) { + throw new NotAProperConfigException(); + } - final JsonObject root = json.getAsJsonObject(); - if (!root.has(Constants.ConfigNames.FILE_VERSION)) { - throw new MissingVersionException(); - } + final JsonObject root = json.getAsJsonObject(); + if (!root.has(Constants.ConfigNames.FILE_VERSION)) { + throw new MissingVersionException(); + } - final float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); - if (version < 2f) { - throw new OldVersionException(); - } else if (version != 2f) { - throw new UnknownVersionException(); - } + final float version = root.get(Constants.ConfigNames.FILE_VERSION).getAsFloat(); + if (version < 2f) { + throw new OldVersionException(); + } else if (version != 2f) { + throw new UnknownVersionException(); + } - if (!root.has(Constants.ConfigNames.SPAWNS)) { - throw new NotAProperConfigException(); - } + if (!root.has(Constants.ConfigNames.SPAWNS)) { + throw new NotAProperConfigException(); + } - final JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) - .getAsJsonObject(); - spawnData.entrySet().stream().forEach(e -> { - try { - OreSpawn.API.mapEntryToFile(conf, e.getKey()); - loadSingleEntry(e); - } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { - CrashReport report = CrashReport.makeCrashReport(e1, - "Error parsing an entry " + e.getKey() + " in " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - }); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed reading config data " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } catch (final JsonIOException | JsonSyntaxException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "JSON Parsing Error in " + conf.toString()); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + final JsonObject spawnData = doHandlePresets(root).get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject(); + spawnData.entrySet().stream().forEach(e -> { + try { + OreSpawn.API.mapEntryToFile(conf, e.getKey()); + loadSingleEntry(e); + } catch (UnknownFieldException | BadValueException | UnknownNameException e1) { + CrashReport report = CrashReport.makeCrashReport(e1, + "Error parsing an entry " + e.getKey() + " in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + }); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed reading config data " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } catch (final JsonIOException | JsonSyntaxException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "JSON Parsing Error in " + conf.toString()); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } - private static JsonObject doHandlePresets(final JsonObject spawnData) { - final PresetsStorage configPresets = OreSpawn.API.copyPresets(); - if (spawnData.has(Constants.ConfigNames.PRESETS)) { - spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() - .forEach(entry -> { - String section = entry.getKey(); - entry.getValue().getAsJsonObject().entrySet().stream() - .forEach(sect -> configPresets.setSymbolSection(section, - sect.getKey(), sect.getValue())); - }); - } + private static JsonObject doHandlePresets(final JsonObject spawnData) { + final PresetsStorage configPresets = OreSpawn.API.copyPresets(); + if (spawnData.has(Constants.ConfigNames.PRESETS)) { + spawnData.get(Constants.ConfigNames.PRESETS).getAsJsonObject().entrySet().stream() + .forEach(entry -> { + String section = entry.getKey(); + entry.getValue().getAsJsonObject().entrySet().stream() + .forEach(sect -> configPresets.setSymbolSection(section, + sect.getKey(), sect.getValue())); + }); + } - final JsonObject spawnDataFixed = new JsonObject(); - for (final Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) - .getAsJsonObject().entrySet()) { - spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); - } - return spawnData; - } + final JsonObject spawnDataFixed = new JsonObject(); + for (final Entry elem : spawnData.get(Constants.ConfigNames.SPAWNS) + .getAsJsonObject().entrySet()) { + spawnDataFixed.add(elem.getKey(), doPresetFix(elem.getValue(), configPresets)); + } + return spawnData; + } - private static JsonElement doPresetFix(final JsonElement value, - final PresetsStorage configPresets) { - if (value.isJsonObject()) { - return doPresetForObject(value.getAsJsonObject(), configPresets); - } else if (value.isJsonArray()) { - return doPresetForArray(value.getAsJsonArray(), configPresets); - } else if (value.isJsonPrimitive() && !value.isJsonNull()) { - if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { - return configPresets.get(value.getAsString()); - } else { - return value; - } - } else { - OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " - + value.toString()); - return value; - } - } + private static JsonElement doPresetFix(final JsonElement value, + final PresetsStorage configPresets) { + if (value.isJsonObject()) { + return doPresetForObject(value.getAsJsonObject(), configPresets); + } else if (value.isJsonArray()) { + return doPresetForArray(value.getAsJsonArray(), configPresets); + } else if (value.isJsonPrimitive() && !value.isJsonNull()) { + if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { + return configPresets.get(value.getAsString()); + } else { + return value; + } + } else { + OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " + + value.toString()); + return value; + } + } - private static JsonElement doPresetForArray(final JsonArray value, - final PresetsStorage configPresets) { - final JsonArray rv = new JsonArray(); - value.forEach(it -> rv.add(doPresetFix(it, configPresets))); - return rv; - } + private static JsonElement doPresetForArray(final JsonArray value, + final PresetsStorage configPresets) { + final JsonArray rv = new JsonArray(); + value.forEach(it -> rv.add(doPresetFix(it, configPresets))); + return rv; + } - private static JsonElement doPresetForObject(final JsonObject value, - final PresetsStorage configPresets) { - final JsonObject rv = new JsonObject(); + private static JsonElement doPresetForObject(final JsonObject value, + final PresetsStorage configPresets) { + final JsonObject rv = new JsonObject(); - value.entrySet().stream().forEach( - entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); - return rv; - } + value.entrySet().stream().forEach( + entry -> rv.add(entry.getKey(), doPresetFix(entry.getValue(), configPresets))); + return rv; + } - public static void loadFromJson(final String name, final JsonElement json) { - final Entry t = new AbstractMap.SimpleEntry<>(name, json); - try { - loadSingleEntry(t); - } catch (UnknownFieldException | BadValueException | UnknownNameException e) { - final CrashReport report = CrashReport.makeCrashReport(e, - "Error parsing an manual JSON read for " + name); - report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } + public static void loadFromJson(final String name, final JsonElement json) { + final Entry t = new AbstractMap.SimpleEntry<>(name, json); + try { + loadSingleEntry(t); + } catch (UnknownFieldException | BadValueException | UnknownNameException e) { + final CrashReport report = CrashReport.makeCrashReport(e, + "Error parsing an manual JSON read for " + name); + report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } + } - private static void loadSingleEntry(final Entry entry) - throws UnknownFieldException, BadValueException, UnknownNameException { - final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); - final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); - sb.setName(entry.getKey()); + private static void loadSingleEntry(final Entry entry) + throws UnknownFieldException, BadValueException, UnknownNameException { + final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); + final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); + sb.setName(entry.getKey()); - for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { - switch (ent.getKey()) { - case Constants.ConfigNames.RETROGEN: - sb.setRetrogen(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.ENABLED: - sb.setEnabled(ent.getValue().getAsBoolean()); - break; - case Constants.ConfigNames.DIMENSIONS: - final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); - if (ent.getValue().isJsonArray()) { - final JsonArray dims = ent.getValue().getAsJsonArray(); - if (dims.size() == 0) { - // blank list, accept all overworld - db.setAcceptAllOverworld(); - } else { - dims.forEach(item -> { - if (item.isJsonPrimitive() - && item.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(item.getAsInt()); - } - }); - } - } else if (ent.getValue().isJsonObject()) { - loadDimensions(db, ent.getValue().getAsJsonObject()); - } else { - throw new BadValueException(Constants.ConfigNames.DIMENSIONS, - ent.getValue().toString()); - } - sb.setDimensions(db.create()); - break; - case Constants.ConfigNames.BIOMES: - if (!ent.getValue().isJsonObject()) { - throw new BadValueException(Constants.ConfigNames.BIOMES, - ent.getValue().toString()); - } - final IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); - loadBiomes(bb, ent.getValue().getAsJsonObject()); - sb.setBiomes(bb.create()); - break; - case Constants.ConfigNames.FEATURE: - if (ent.getValue().isJsonPrimitive() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.FEATURE, - ent.getValue().toString()); - } - final String featureName = ent.getValue().getAsString(); - if (!OreSpawn.API.featureExists(featureName)) { - throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); - } - fb.setFeature(featureName); - break; - case Constants.ConfigNames.REPLACEMENT: - final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); - if (!ent.getValue().isJsonArray() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.REPLACEMENT, - ent.getValue().toString()); - } else if (ent.getValue().isJsonPrimitive() - && ent.getValue().getAsJsonPrimitive().isString()) { - if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { - rb.setFromName(ent.getValue().getAsString()); - } - } else { - for (final JsonElement e : ent.getValue().getAsJsonArray()) { - if (e.isJsonObject()) { - loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in replacements list as it is not the correct format", - e.toString()); - } - } - } + for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { + switch (ent.getKey()) { + case Constants.ConfigNames.RETROGEN: + sb.setRetrogen(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.ENABLED: + sb.setEnabled(ent.getValue().getAsBoolean()); + break; + case Constants.ConfigNames.DIMENSIONS: + final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); + if (ent.getValue().isJsonArray()) { + final JsonArray dims = ent.getValue().getAsJsonArray(); + if (dims.size() == 0) { + // blank list, accept all overworld + db.setAcceptAllOverworld(); + } else { + dims.forEach(item -> { + if (item.isJsonPrimitive() + && item.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(item.getAsInt()); + } + }); + } + } else if (ent.getValue().isJsonObject()) { + loadDimensions(db, ent.getValue().getAsJsonObject()); + } else { + throw new BadValueException(Constants.ConfigNames.DIMENSIONS, + ent.getValue().toString()); + } + sb.setDimensions(db.create()); + break; + case Constants.ConfigNames.BIOMES: + if (!ent.getValue().isJsonObject()) { + throw new BadValueException(Constants.ConfigNames.BIOMES, + ent.getValue().toString()); + } + final IBiomeBuilder bb = OreSpawn.API.getBiomeBuilder(); + loadBiomes(bb, ent.getValue().getAsJsonObject()); + sb.setBiomes(bb.create()); + break; + case Constants.ConfigNames.FEATURE: + if (ent.getValue().isJsonPrimitive() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.FEATURE, + ent.getValue().toString()); + } + final String featureName = ent.getValue().getAsString(); + if (!OreSpawn.API.featureExists(featureName)) { + throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); + } + fb.setFeature(featureName); + break; + case Constants.ConfigNames.REPLACEMENT: + final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); + if (!ent.getValue().isJsonArray() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.REPLACEMENT, + ent.getValue().toString()); + } else if (ent.getValue().isJsonPrimitive() + && ent.getValue().getAsJsonPrimitive().isString()) { + if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { + rb.setFromName(ent.getValue().getAsString()); + } + } else { + for (final JsonElement e : ent.getValue().getAsJsonArray()) { + if (e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in replacements list as it is not the correct format", + e.toString()); + } + } + } - if (rb.hasEntries()) { - sb.setReplacement(rb.create()); - } - break; - case Constants.ConfigNames.BLOCK: - if (ent.getValue().isJsonArray()) { - for (final JsonElement elem : ent.getValue().getAsJsonArray()) { - final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); - if (elem.isJsonObject()) { - final JsonObject bl = elem.getAsJsonObject(); - if (bl.has(Constants.ConfigNames.STATE)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.STATE).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else if (bl.has(Constants.ConfigNames.METADATA)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.METADATA).getAsInt(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } - sb.addBlock(block.create()); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in blocks list as it is not the correct format", - elem.toString()); - } - } - } else { - throw new BadValueException(Constants.ConfigNames.BLOCK, - ent.getValue().toString()); - } - case Constants.ConfigNames.PARAMETERS: - if (ent.getValue().isJsonObject()) { - ent.getValue().getAsJsonObject().entrySet().stream() - .forEach(e -> fb.setParameter(e.getKey(), e.getValue())); - } - break; - default: - throw new UnknownFieldException(ent.getKey()); - } - } - sb.setFeature(fb.create()); - OreSpawn.API.addSpawn(sb.create()); - } + if (rb.hasEntries()) { + sb.setReplacement(rb.create()); + } + break; + case Constants.ConfigNames.BLOCK: + if (ent.getValue().isJsonArray()) { + for (final JsonElement elem : ent.getValue().getAsJsonArray()) { + final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + if (elem.isJsonObject()) { + final JsonObject bl = elem.getAsJsonObject(); + if (bl.has(Constants.ConfigNames.STATE)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.STATE).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else if (bl.has(Constants.ConfigNames.METADATA)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.METADATA).getAsInt(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } + sb.addBlock(block.create()); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in blocks list as it is not the correct format", + elem.toString()); + } + } + } else { + throw new BadValueException(Constants.ConfigNames.BLOCK, + ent.getValue().toString()); + } + case Constants.ConfigNames.PARAMETERS: + if (ent.getValue().isJsonObject()) { + ent.getValue().getAsJsonObject().entrySet().stream() + .forEach(e -> fb.setParameter(e.getKey(), e.getValue())); + } + break; + default: + throw new UnknownFieldException(ent.getKey()); + } + } + sb.setFeature(fb.create()); + OreSpawn.API.addSpawn(sb.create()); + } - private static List loadBlock(final JsonObject json) { - final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); - if (json.has(Constants.ConfigNames.STATE)) { - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(StateUtil.deserializeState(block, - json.get(Constants.ConfigNames.STATE).getAsString())); - } else if (json.has(Constants.ConfigNames.METADATA)) { - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList( - block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); - } + private static List loadBlock(final JsonObject json) { + final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); + if (json.has(Constants.ConfigNames.STATE)) { + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(StateUtil.deserializeState(block, + json.get(Constants.ConfigNames.STATE).getAsString())); + } else if (json.has(Constants.ConfigNames.METADATA)) { + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList( + block.getStateFromMeta(json.get(Constants.ConfigNames.METADATA).getAsInt())); + } - if (blockName.startsWith("ore:")) { - final String entry = blockName.split(":")[1]; - return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { - final Block b = Block.getBlockFromItem(is.getItem()); - return b.getStateFromMeta(is.getMetadata()); - }).collect(Collectors.toList())); - } - final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(block.getDefaultState()); - } + if (blockName.startsWith("ore:")) { + final String entry = blockName.split(":")[1]; + return ImmutableList.copyOf(OreDictionary.getOres(entry, false).stream().map(is -> { + final Block b = Block.getBlockFromItem(is.getItem()); + return b.getStateFromMeta(is.getMetadata()); + }).collect(Collectors.toList())); + } + final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); + return Arrays.asList(block.getDefaultState()); + } - private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { - boolean emptyWhitelist = false; + private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { + boolean emptyWhitelist = false; - if (biomeList.has(Constants.ConfigNames.WHITELIST) - && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addWhitelistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addWhitelistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else { - emptyWhitelist = true; - } + if (biomeList.has(Constants.ConfigNames.WHITELIST) + && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addWhitelistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addWhitelistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else { + emptyWhitelist = true; + } - if (biomeList.has(Constants.ConfigNames.BLACKLIST) - && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addBlacklistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addBlacklistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", - elem.getAsString()); - } - } - } else if (emptyWhitelist) { - // empty whitelist and blacklist - accept everything - bb.setAcceptAll(); - } - } + if (biomeList.has(Constants.ConfigNames.BLACKLIST) + && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addBlacklistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addBlacklistEntry); + } + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", + elem.getAsString()); + } + } + } else if (emptyWhitelist) { + // empty whitelist and blacklist - accept everything + bb.setAcceptAll(); + } + } - private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { - boolean emptyWhitelist = false; + private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { + boolean emptyWhitelist = false; - if (dimensionList.has(Constants.ConfigNames.WHITELIST) - && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else { - emptyWhitelist = true; - } + if (dimensionList.has(Constants.ConfigNames.WHITELIST) + && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else { + emptyWhitelist = true; + } - if (dimensionList.has(Constants.ConfigNames.BLACKLIST) - && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addBlacklistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } - } else if (emptyWhitelist) { - db.setAcceptAllOverworld(); - } - } + if (dimensionList.has(Constants.ConfigNames.BLACKLIST) + && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { + for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) + .getAsJsonArray()) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addBlacklistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", + elem.getAsString()); + } + } + } else if (emptyWhitelist) { + db.setAcceptAllOverworld(); + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java index 11a35b01..f8edba41 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java @@ -20,54 +20,54 @@ public class OreSpawnWriter { - /* - * Write out the configs as the system knows them to the 'forced-saves' directory - */ - public static void saveConfigs() { - final Map> configs = OreSpawn.API.getSpawnsByFile(); - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); - } + /* + * Write out the configs as the system knows them to the 'forced-saves' directory + */ + public static void saveConfigs() { + final Map> configs = OreSpawn.API.getSpawnsByFile(); + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + configs.entrySet().stream().forEach(ent -> saveSingle(ent.getKey(), gson)); + } - private static void saveSingle(final Path filePath, final Gson gson) { - final JsonObject root = new JsonObject(); - root.addProperty(ConfigNames.FILE_VERSION, "2.0"); - final JsonObject spawns = new JsonObject(); - final String k = filePath.getFileName().toString(); - final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); - final Path conf = saveDir.resolve(k); - if (!saveDir.toFile().exists()) { - saveDir.toFile().mkdirs(); - } - try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { - OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { - final JsonObject thisSpawn = new JsonObject(); - final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); - thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); - thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); - thisSpawn.addProperty(ConfigNames.FEATURE, - spawnEntry.getFeature().getFeatureName()); - thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); - thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); - thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); - thisSpawn.add(ConfigNames.PARAMETERS, - spawnEntry.getFeature().getFeatureParameters()); - spawns.add(spawnName, thisSpawn); - }); - root.add(ConfigNames.SPAWNS, spawns); - p.write(gson.toJson(root)); - } catch (final IOException e) { - CrashReport report = CrashReport.makeCrashReport(e, - "Failed writing config data " + conf.toString()); - report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } + private static void saveSingle(final Path filePath, final Gson gson) { + final JsonObject root = new JsonObject(); + root.addProperty(ConfigNames.FILE_VERSION, "2.0"); + final JsonObject spawns = new JsonObject(); + final String k = filePath.getFileName().toString(); + final Path saveDir = Constants.CONFDIR.resolve("forced-saves"); + final Path conf = saveDir.resolve(k); + if (!saveDir.toFile().exists()) { + saveDir.toFile().mkdirs(); + } + try (final BufferedWriter p = Files.newBufferedWriter(conf, StandardOpenOption.CREATE, + StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE)) { + OreSpawn.API.getSpawnsForFile(k).stream().forEach(spawnName -> { + final JsonObject thisSpawn = new JsonObject(); + final ISpawnEntry spawnEntry = OreSpawn.API.getSpawn(spawnName); + thisSpawn.addProperty(ConfigNames.ENABLED, spawnEntry.isEnabled()); + thisSpawn.addProperty(ConfigNames.RETROGEN, spawnEntry.isRetrogen()); + thisSpawn.addProperty(ConfigNames.FEATURE, + spawnEntry.getFeature().getFeatureName()); + thisSpawn.add(ConfigNames.DIMENSIONS, spawnEntry.getDimensions().serialize()); + thisSpawn.add(ConfigNames.BIOMES, spawnEntry.getBiomes().serialize()); + thisSpawn.add(ConfigNames.REPLACEMENT, spawnEntry.getMatcher().serialize()); + thisSpawn.add(ConfigNames.PARAMETERS, + spawnEntry.getFeature().getFeatureParameters()); + spawns.add(spawnName, thisSpawn); + }); + root.add(ConfigNames.SPAWNS, spawns); + p.write(gson.toJson(root)); + } catch (final IOException e) { + CrashReport report = CrashReport.makeCrashReport(e, + "Failed writing config data " + conf.toString()); + report.getCategory().addCrashSection("OreSpawn Version", Constants.VERSION); + OreSpawn.LOGGER.info(report.getCompleteReport()); + } - } + } - public static void saveSingle(final String fileName) { - final Gson gson = new GsonBuilder().setPrettyPrinting().create(); - saveSingle(Constants.CONFDIR.resolve(fileName), gson); - } + public static void saveSingle(final String fileName) { + final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + saveSingle(Constants.CONFDIR.resolve(fileName), gson); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java index 469c3281..bbe8ade9 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java +++ b/src/main/java/com/mcmoddev/orespawn/util/Collectors2.java @@ -7,16 +7,16 @@ public final class Collectors2 { - private Collectors2() { - } + private Collectors2() { + } - public static Collector, ImmutableList> toImmutableList() { - return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, - (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); - } + public static Collector, ImmutableList> toImmutableList() { + return Collector.of(ImmutableList.Builder::new, ImmutableList.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableList.Builder::build); + } - public static Collector, ImmutableSet> toImmutableSet() { - return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, - (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); - } + public static Collector, ImmutableSet> toImmutableSet() { + return Collector.of(ImmutableSet.Builder::new, ImmutableSet.Builder::add, + (left, right) -> left.addAll(right.build()), ImmutableSet.Builder::build); + } } diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 59044076..28f663e5 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -7,39 +7,39 @@ public class StateUtil { - private StateUtil() { - throw new InstantiationError("This class cannot be instantiated!"); - } - - public static String serializeState(final IBlockState state) { - String string = state.toString(); - string = string.substring(string.indexOf('[') + 1, - string.length() - (string.endsWith("]") ? 1 : 0)); - - if (string.equals(state.getBlock().getRegistryName().toString())) { - string = "normal"; - } - - OreSpawn.LOGGER.debug("State is %s (for block %s)", string, - state.getBlock().getRegistryName()); - return string; - } - - public static IBlockState deserializeState(final Block block, final String state) { - for (final IBlockState validState : block.getBlockState().getValidStates()) { - String string = validState.toString(); - string = string.substring(string.indexOf('[') + 1, - string.length() - (string.endsWith("]") ? 1 : 0)); - - if (string.equals(block.getRegistryName().toString())) { - string = ""; - } - - if (state.equals(string)) { - return validState; - } - } - - return null; - } + private StateUtil() { + throw new InstantiationError("This class cannot be instantiated!"); + } + + public static String serializeState(final IBlockState state) { + String string = state.toString(); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); + + if (string.equals(state.getBlock().getRegistryName().toString())) { + string = "normal"; + } + + OreSpawn.LOGGER.debug("State is %s (for block %s)", string, + state.getBlock().getRegistryName()); + return string; + } + + public static IBlockState deserializeState(final Block block, final String state) { + for (final IBlockState validState : block.getBlockState().getValidStates()) { + String string = validState.toString(); + string = string.substring(string.indexOf('[') + 1, + string.length() - (string.endsWith("]") ? 1 : 0)); + + if (string.equals(block.getRegistryName().toString())) { + string = ""; + } + + if (state.equals(string)) { + return validState; + } + } + + return null; + } } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java index 64fc38dd..497069e9 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java @@ -17,71 +17,71 @@ public class FlatBedrock implements IWorldGenerator { - @Override - public void generate(final Random random, final int chunkX, final int chunkZ, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { - // no need to do flat-bedrock on a "FLAT" world - if (world.getWorldType() != WorldType.FLAT) { - if (world.provider.getDimension() == -1) { - genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); - } - } - } + @Override + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { + // no need to do flat-bedrock on a "FLAT" world + if (world.getWorldType() != WorldType.FLAT) { + if (world.provider.getDimension() == -1) { + genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); + } + } + } - public void retrogen(final World world, final int chunkX, final int chunkZ) { - if (world.getWorldType() != WorldType.FLAT) { - if (world.provider.getDimension() == -1) { - genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); - } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { - genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); - } - } - } + public void retrogen(final World world, final int chunkX, final int chunkZ) { + if (world.getWorldType() != WorldType.FLAT) { + if (world.provider.getDimension() == -1) { + genTopPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.NETHERRACK); + } else if (world.provider.getDimension() >= 0 && world.provider.getDimension() != 1) { + genBottomPlate(world, new ChunkPos(chunkX, chunkZ), Blocks.STONE); + } + } + } - private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + private void genBottomPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); - for (int xP = 0; xP < 16; xP++) { - for (int zP = 0; zP < 16; zP++) { - for (int yP = 5; yP > 0; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, - chunkPos.z * 16 + zP); + for (int xP = 0; xP < 16; xP++) { + for (int zP = 0; zP < 16; zP++) { + for (int yP = 5; yP > 0; yP--) { + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); - if (yP < plateThickness - && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP >= plateThickness - && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, repBlock.getDefaultState(), 26); - } - } - } - } - } + if (yP < plateThickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); + } else if (yP >= plateThickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, repBlock.getDefaultState(), 26); + } + } + } + } + } - private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { - final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); - final int thickness = 127 - plateThickness; // layer where the flat for the top starts + private void genTopPlate(final World world, final ChunkPos chunkPos, final Block repBlock) { + final int plateThickness = Config.getInt(Constants.BEDROCK_LAYERS); + final int thickness = 127 - plateThickness; // layer where the flat for the top starts - for (int xP = 0; xP < 16; xP++) { - for (int zP = 0; zP < 16; zP++) { - for (int yP = 126; yP > 121; yP--) { - final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, - chunkPos.z * 16 + zP); + for (int xP = 0; xP < 16; xP++) { + for (int zP = 0; zP < 16; zP++) { + for (int yP = 126; yP > 121; yP--) { + final BlockPos target = new BlockPos(chunkPos.x * 16 + xP, yP, + chunkPos.z * 16 + zP); - if (yP > thickness - && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); - } else if (yP <= thickness - && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { - world.setBlockState(target, repBlock.getDefaultState(), 26); - } - } - } - } - } + if (yP > thickness + && !world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, Blocks.BEDROCK.getDefaultState(), 26); + } else if (yP <= thickness + && world.getBlockState(target).getBlock().equals(Blocks.BEDROCK)) { + world.setBlockState(target, repBlock.getDefaultState(), 26); + } + } + } + } + } } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index 34f23c35..e0cb7025 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -14,16 +14,16 @@ public class OreSpawnWorldGen implements IWorldGenerator { - @Override - public void generate(final Random random, final int chunkX, final int chunkZ, final World world, - final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { + @Override + public void generate(final Random random, final int chunkX, final int chunkZ, final World world, + final IChunkGenerator chunkGenerator, final IChunkProvider chunkProvider) { - final int thisDim = world.provider.getDimension(); + final int thisDim = world.provider.getDimension(); - OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) - .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) - || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, - new ChunkPos(chunkX, chunkZ))); - } + OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) + .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) + || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) + .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, + new ChunkPos(chunkX, chunkZ))); + } } From c928f3ed3f85f43580f9c7922debba8f96685675 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 2 Sep 2018 04:44:46 -0400 Subject: [PATCH 064/205] Underfluid Generator coded, not yet tested --- .../com/mcmoddev/orespawn/data/Constants.java | 1 + .../orespawn/impl/features/UnderFluid.java | 185 ++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 7c6ea724..c50f8fae 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -54,6 +54,7 @@ private FormatBits() { public static final String ATTEMPTS_MIN = "minAttempts"; public static final String ATTEMPTS_MAX = "maxAttempts"; public static final String STARTINGFACE = "startFacing"; + public static final String FLUID = "fluid"; } public final class FileBits { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java new file mode 100644 index 00000000..2fb22cd3 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -0,0 +1,185 @@ +/** + * + */ +package com.mcmoddev.orespawn.impl.features; + +import java.util.Random; +import java.util.Set; +import java.util.stream.StreamSupport; + +import com.google.common.collect.Sets; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.api.FeatureBase; +import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.data.Constants; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidUtil; + + +/** + * @author Daniel Hazelton + * + */ +public class UnderFluid extends FeatureBase implements IFeature { + + /** + * @param rand + */ + public UnderFluid(Random rand) { + super(rand); + } + + /** + * Try to generate this feature to the specified parameters in the specified chunk. + * @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) + *

Theory: + *

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

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

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

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

At the fluids lower bound, generate the node. + * + * @param world {@link net.minecraft.world.World} World this chunk is in + * @param chunkGenerator {@link net.minecraft.world.gen.IChunkGenerator} Chunk generator for this chunk + * @param chunkProvider {@link net.minecraft.world.chunk.IChunkGenerator} Chunk provider for this chunk + * @param spawnData {@link com.mcmoddev.orespawn.api.os3.ISpawnEntry} Parameters and data on this spawn from the configuration file + * @param _pos {@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) + */ + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { + final ChunkPos pos = _pos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final Fluid fluid = FluidRegistry.getFluid(params.get(Constants.FormatBits.FLUID).getAsString()); + + int tries = this.random.nextInt(triesMax - triesMin + 1) + triesMin; + int surveySize = triesMax * 2; + int ySpan = maxHeight - minHeight; + BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); + Block fluidBlock = fluid.getBlock(); + + Set found = Sets.newHashSet(); + + for (int j = 0; j < surveySize; j++) { + BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); + BlockPos lowSide = sampleCenter.add(-2,-2,-2); + BlockPos highSide = sampleCenter.add(2,2,2); + StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) + .filter( bp -> world.getBlockState(bp).getMaterial().isLiquid() && + world.getBlockState(bp).getBlock().equals(fluidBlock) && + !found.contains(bp) && bp.getY() >= minHeight ) + .map(BlockPos.MutableBlockPos::toImmutable) + .forEach(found::add); + } + + for(int i = 0; i < tries; i++) { + BlockPos mp = found.toArray(new BlockPos[found.size()])[this.random.nextInt(found.size())]; + found.remove(mp); + while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { + mp = mp.add(0, -1, 0); + } + + // calculate actual size for this node + int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); + + // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... + // so... we copy vanilla spawn logic, to a degree, I think + spawnOre(world, spawnData, mp, size); + } + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + /* (non-Javadoc) + * @see com.mcmoddev.orespawn.api.IFeature#setRandom(java.util.Random) + */ + @Override + public void setRandom(Random rand) { + this.random = rand; + } + + /* (non-Javadoc) + * @see com.mcmoddev.orespawn.api.IFeature#getDefaultParameters() + */ + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + defParams.addProperty(Constants.FormatBits.FLUID, "water"); + return defParams; + } + +} From 61b9711d57257b43ed8b7eee0b98ca0e446b15f2 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 2 Sep 2018 19:39:18 -0400 Subject: [PATCH 065/205] plumb UnderFluid in and get its sampling to a somewhat better level --- .../orespawn/impl/features/UnderFluid.java | 57 +++++++++++-------- .../assets/orespawn/configs/_features.json | 4 ++ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java index 2fb22cd3..8f3b44d0 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -4,7 +4,8 @@ package com.mcmoddev.orespawn.impl.features; import java.util.Random; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import java.util.stream.StreamSupport; import com.google.common.collect.Sets; @@ -24,8 +25,6 @@ import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidUtil; - /** * @author Daniel Hazelton @@ -36,30 +35,32 @@ public class UnderFluid extends FeatureBase implements IFeature { /** * @param rand */ - public UnderFluid(Random rand) { - super(rand); + public UnderFluid() { + super(new Random()); } /** * Try to generate this feature to the specified parameters in the specified chunk. - * @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) + *

*

Theory: *

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

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

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

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

At the fluids lower bound, generate the node. + *

* * @param world {@link net.minecraft.world.World} World this chunk is in * @param chunkGenerator {@link net.minecraft.world.gen.IChunkGenerator} Chunk generator for this chunk * @param chunkProvider {@link net.minecraft.world.chunk.IChunkGenerator} Chunk provider for this chunk * @param spawnData {@link com.mcmoddev.orespawn.api.os3.ISpawnEntry} Parameters and data on this spawn from the configuration file - * @param _pos {@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) + * @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) + * @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) */ @Override public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { + final ChunkPos pos = chunkPos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -90,12 +91,12 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); Block fluidBlock = fluid.getBlock(); - Set found = Sets.newHashSet(); + List found = new ArrayList<>(); for (int j = 0; j < surveySize; j++) { BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); - BlockPos lowSide = sampleCenter.add(-2,-2,-2); - BlockPos highSide = sampleCenter.add(2,2,2); + BlockPos lowSide = sampleCenter.add(-3,-3,-3); + BlockPos highSide = sampleCenter.add(3,3,3); StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) .filter( bp -> world.getBlockState(bp).getMaterial().isLiquid() && world.getBlockState(bp).getBlock().equals(fluidBlock) && @@ -104,22 +105,28 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, .forEach(found::add); } - for(int i = 0; i < tries; i++) { - BlockPos mp = found.toArray(new BlockPos[found.size()])[this.random.nextInt(found.size())]; - found.remove(mp); - while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { - mp = mp.add(0, -1, 0); + int i = 0; + + if (!found.isEmpty()) { + while( i < tries && !found.isEmpty()) { + BlockPos mp = found.get(this.random.nextInt(found.size())); + found.remove(mp); + while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { + mp = mp.down(); + } + + if (mp.getY() < minHeight || mp.getY() > maxHeight) break; + + // calculate actual size for this node + int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); + // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... + // so... we copy vanilla spawn logic, to a degree, I think + spawnOre(world, spawnData, mp, size); + i++; } - - // calculate actual size for this node - int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); - - // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... - // so... we copy vanilla spawn logic, to a degree, I think - spawnOre(world, spawnData, mp, size); } } - + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; diff --git a/src/main/resources/assets/orespawn/configs/_features.json b/src/main/resources/assets/orespawn/configs/_features.json index 970456c7..09075a31 100644 --- a/src/main/resources/assets/orespawn/configs/_features.json +++ b/src/main/resources/assets/orespawn/configs/_features.json @@ -18,5 +18,9 @@ { "name": "clusters", "class": "com.mcmoddev.orespawn.impl.features.ClusterGenerator" + }, + { + "name": "underfluids", + "class": "com.mcmoddev.orespawn.impl.features.UnderFluid" } ] \ No newline at end of file From 90854e4e8536355cebecb60d84228e18a102cbaf Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 2 Sep 2018 19:39:49 -0400 Subject: [PATCH 066/205] minor cleanups and refactorings that replace some simple lambdas with method references --- src/main/java/com/mcmoddev/orespawn/EventHandlers.java | 4 ++-- .../com/mcmoddev/orespawn/commands/ClearChunkCommand.java | 4 ++-- src/main/java/com/mcmoddev/orespawn/data/Constants.java | 4 ++-- .../orespawn/impl/features/DefaultFeatureGenerator.java | 4 ++-- .../orespawn/impl/features/NormalCloudGenerator.java | 4 ++-- src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java | 4 ++-- .../com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java | 5 +++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 434f28a4..7f2deec9 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -129,9 +129,9 @@ private List getDifferingTags(final NBTTagCompound chunkTag, final int d final MapDifference diff = Maps.difference(oldBits, currentBits); final List stuff = Lists.newLinkedList(); - stuff.addAll(diff.entriesDiffering().entrySet().stream().map(ent -> ent.getKey()) + stuff.addAll(diff.entriesDiffering().entrySet().stream().map(Map.Entry::getKey) .collect(Collectors.toList())); - stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(ent -> ent.getKey()) + stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(Map.Entry::getKey) .collect(Collectors.toList())); return ImmutableList.copyOf(stuff); } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 79829133..377ec980 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -71,7 +71,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, blocks = blockNames.stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(block -> block.getDefaultState()).collect(Collectors.toList()); + .map(Block::getDefaultState).collect(Collectors.toList()); blocks.addAll(OreSpawn.API .getDimensionDefaultReplacements(player.getEntityWorld().provider.getDimension()) @@ -81,7 +81,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, "minecraft:sandstone", "minecraft:red_sandstone") .stream() .map(blockName -> ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName))) - .map(bl -> bl.getDefaultState()).collect(Collectors.toList()); + .map(Block::getDefaultState).collect(Collectors.toList()); clearBlocks(chunkPos, blocks, overburden, flagClassic, player); diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index c50f8fae..3c79155b 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -33,8 +33,8 @@ public class Constants { public static final String BEDROCK_LAYERS = "Bedrock Thickness"; public static final String ORESPAWN_VERSION_CRASH_MESSAGE = "OreSpawn Version"; public static final String PRECISION = "precision"; - public static final Path CONFDIR = Paths.get("config", "orespawn3"); - public static final Path SYSCONF = Paths.get("config", "orespawn3", "sysconf"); + public static final Path CONFDIR = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3); + public static final Path SYSCONF = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3, FileBits.SYSCONF); public final class FormatBits { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index fbc9d734..6b0b80ec 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -24,8 +24,8 @@ public DefaultFeatureGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { + final ChunkPos pos = chunkPos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java index 6d6d1cf1..bd18dd3d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java @@ -27,8 +27,8 @@ public NormalCloudGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { + final ChunkPos pos = chunkPos; final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 1559f718..6303c19f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -178,7 +178,7 @@ public IReplacementEntry getReplacement(final String replacementName) { public List getSpawns(final int dimensionID) { return ImmutableList.copyOf( spawns.entrySet().stream().filter(e -> e.getValue().dimensionAllowed(dimensionID)) - .map(e -> e.getValue()).collect(Collectors.toList())); + .map(Map.Entry::getValue).collect(Collectors.toList())); } @Override @@ -246,7 +246,7 @@ public void mapEntryToFile(final Path p, final String entryName) { public List getSpawnsForFile(final String fileName) { final Path p = Constants.CONFDIR.resolve(fileName); final List values = spawnsToSourceFiles.entrySet().stream() - .filter(ent -> ent.getValue().equals(p)).map(ent -> ent.getKey()) + .filter(ent -> ent.getValue().equals(p)).map(Map.Entry::getKey) .collect(Collectors.toList()); return ImmutableList.copyOf(values); } diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index e0cb7025..94d5e05c 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -3,6 +3,7 @@ import java.util.Random; import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; @@ -20,10 +21,10 @@ public void generate(final Random random, final int chunkX, final int chunkZ, fi final int thisDim = world.provider.getDimension(); - OreSpawn.API.getSpawns(thisDim).stream().filter(spawn -> spawn.isEnabled()) + OreSpawn.API.getSpawns(thisDim).stream().filter(ISpawnEntry::isEnabled) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, - new ChunkPos(chunkX, chunkZ))); + new ChunkPos(chunkX, chunkZ))); } } From f071f7f9792ffbf685cbfd73fc0d3ebdf060b8a8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 3 Sep 2018 14:41:42 -0400 Subject: [PATCH 067/205] sonar cleanups, mostly --- .../api/os3/OreSpawnBlockMatcher.java | 2 +- .../orespawn/commands/ClearChunkCommand.java | 4 +- .../orespawn/impl/features/UnderFluid.java | 1 - .../orespawn/impl/os3/OS3APIImpl.java | 2 +- .../orespawn/json/OreSpawnReader.java | 296 ++++++++++-------- 5 files changed, 166 insertions(+), 139 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java index ffba56f6..0c716413 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java @@ -31,7 +31,7 @@ private boolean has(final IBlockState bs) { } public boolean test(final IBlockState other) { - return (other != null) && (!other.getBlock().equals(Blocks.AIR)) && this.has(other); + return (!other.getBlock().equals(Blocks.AIR)) && this.has(other); } public JsonArray serialize() { diff --git a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java index 377ec980..f994de93 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java @@ -62,9 +62,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, final ChunkPos chunkPos = chunk.getPos(); final List blocks; - final boolean flagClassic = args.length > 0 - ? args[0].toLowerCase().equalsIgnoreCase("classic") - : false; + final boolean flagClassic = args.length > 0 && args[0].toLowerCase().equalsIgnoreCase("classic"); final List blockNames = new LinkedList<>(); getBlocks(args, blockNames); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java index 8f3b44d0..ca3d3a13 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.stream.StreamSupport; -import com.google.common.collect.Sets; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.FeatureBase; import com.mcmoddev.orespawn.api.IFeature; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 6303c19f..a283518f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -97,7 +97,7 @@ public void loadConfigFiles() { try (final Stream stream = Files.walk(Constants.CONFDIR, 1)) { stream.filter(jsonMatcher::matches).forEach(conf -> { try { - OreSpawnReader.tryReadFile(conf, this); + OreSpawnReader.tryReadFile(conf); } catch (final MissingVersionException | NotAProperConfigException | OldVersionException | UnknownVersionException e) { CrashReport report = CrashReport.makeCrashReport(e, diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index 989866e7..d289ec0b 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -33,7 +33,6 @@ import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.data.Constants; import com.mcmoddev.orespawn.data.PresetsStorage; -import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; import com.mcmoddev.orespawn.util.StateUtil; import net.minecraft.block.Block; @@ -48,7 +47,11 @@ public class OreSpawnReader { private static final String ORE_SPAWN_VERSION = "OreSpawn Version"; - public static void tryReadFile(final Path conf, final OS3APIImpl os3apiImpl) + private OreSpawnReader() { + // hiding the default one + } + + public static void tryReadFile(final Path conf) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { final JsonParser parser = new JsonParser(); @@ -185,25 +188,7 @@ private static void loadSingleEntry(final Entry entry) break; case Constants.ConfigNames.DIMENSIONS: final IDimensionBuilder db = OreSpawn.API.getDimensionBuilder(); - if (ent.getValue().isJsonArray()) { - final JsonArray dims = ent.getValue().getAsJsonArray(); - if (dims.size() == 0) { - // blank list, accept all overworld - db.setAcceptAllOverworld(); - } else { - dims.forEach(item -> { - if (item.isJsonPrimitive() - && item.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(item.getAsInt()); - } - }); - } - } else if (ent.getValue().isJsonObject()) { - loadDimensions(db, ent.getValue().getAsJsonObject()); - } else { - throw new BadValueException(Constants.ConfigNames.DIMENSIONS, - ent.getValue().toString()); - } + loadDimensionEntry(db, ent); sb.setDimensions(db.create()); break; case Constants.ConfigNames.BIOMES: @@ -216,76 +201,19 @@ private static void loadSingleEntry(final Entry entry) sb.setBiomes(bb.create()); break; case Constants.ConfigNames.FEATURE: - if (ent.getValue().isJsonPrimitive() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.FEATURE, - ent.getValue().toString()); - } - final String featureName = ent.getValue().getAsString(); - if (!OreSpawn.API.featureExists(featureName)) { - throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); - } - fb.setFeature(featureName); + fb.setFeature(loadFeatureEntry(ent)); break; case Constants.ConfigNames.REPLACEMENT: final IReplacementBuilder rb = OreSpawn.API.getReplacementBuilder(); - if (!ent.getValue().isJsonArray() - && !ent.getValue().getAsJsonPrimitive().isString()) { - throw new BadValueException(Constants.ConfigNames.REPLACEMENT, - ent.getValue().toString()); - } else if (ent.getValue().isJsonPrimitive() - && ent.getValue().getAsJsonPrimitive().isString()) { - if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { - rb.setFromName(ent.getValue().getAsString()); - } - } else { - for (final JsonElement e : ent.getValue().getAsJsonArray()) { - if (e.isJsonObject()) { - loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in replacements list as it is not the correct format", - e.toString()); - } - } - } + loadReplacements(rb, ent); if (rb.hasEntries()) { sb.setReplacement(rb.create()); } break; case Constants.ConfigNames.BLOCK: - if (ent.getValue().isJsonArray()) { - for (final JsonElement elem : ent.getValue().getAsJsonArray()) { - final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); - if (elem.isJsonObject()) { - final JsonObject bl = elem.getAsJsonObject(); - if (bl.has(Constants.ConfigNames.STATE)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.STATE).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else if (bl.has(Constants.ConfigNames.METADATA)) { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.METADATA).getAsInt(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } else { - block.setFromNameWithChance( - bl.get(Constants.ConfigNames.NAME).getAsString(), - bl.get(Constants.ConfigNames.CHANCE).getAsInt()); - } - sb.addBlock(block.create()); - } else { - OreSpawn.LOGGER.error( - "Skipping value %s in blocks list as it is not the correct format", - elem.toString()); - } - } - } else { - throw new BadValueException(Constants.ConfigNames.BLOCK, - ent.getValue().toString()); - } + loadBlocks(sb, ent); + break; case Constants.ConfigNames.PARAMETERS: if (ent.getValue().isJsonObject()) { ent.getValue().getAsJsonObject().entrySet().stream() @@ -300,6 +228,98 @@ private static void loadSingleEntry(final Entry entry) OreSpawn.API.addSpawn(sb.create()); } + private static String loadFeatureEntry(Entry ent) throws BadValueException, UnknownNameException { + if (ent.getValue().isJsonPrimitive() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.FEATURE, + ent.getValue().toString()); + } + final String featureName = ent.getValue().getAsString(); + if (!OreSpawn.API.featureExists(featureName)) { + throw new UnknownNameException(Constants.ConfigNames.FEATURE, featureName); + } + return featureName; + } + + private static void loadBlocks(ISpawnBuilder sb, Entry ent) throws BadValueException { + if (ent.getValue().isJsonArray()) { + for (final JsonElement elem : ent.getValue().getAsJsonArray()) { + final IBlockBuilder block = OreSpawn.API.getBlockBuilder(); + if (elem.isJsonObject()) { + final JsonObject bl = elem.getAsJsonObject(); + if (bl.has(Constants.ConfigNames.STATE)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.STATE).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else if (bl.has(Constants.ConfigNames.METADATA)) { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.METADATA).getAsInt(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } else { + block.setFromNameWithChance( + bl.get(Constants.ConfigNames.NAME).getAsString(), + bl.get(Constants.ConfigNames.CHANCE).getAsInt()); + } + sb.addBlock(block.create()); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in blocks list as it is not the correct format", + elem.toString()); + } + } + } else { + throw new BadValueException(Constants.ConfigNames.BLOCK, + ent.getValue().toString()); + } + } + + private static void loadReplacements(IReplacementBuilder rb, Entry ent) throws BadValueException { + if (!ent.getValue().isJsonArray() + && !ent.getValue().getAsJsonPrimitive().isString()) { + throw new BadValueException(Constants.ConfigNames.REPLACEMENT, + ent.getValue().toString()); + } else if (ent.getValue().isJsonPrimitive() + && ent.getValue().getAsJsonPrimitive().isString()) { + if (OreSpawn.API.hasReplacement(ent.getValue().getAsString())) { + rb.setFromName(ent.getValue().getAsString()); + } + } else { + for (final JsonElement e : ent.getValue().getAsJsonArray()) { + if (e.isJsonObject()) { + loadBlock(e.getAsJsonObject()).stream().forEach(rb::addEntry); + } else { + OreSpawn.LOGGER.error( + "Skipping value %s in replacements list as it is not the correct format", + e.toString()); + } + } + } + } + + private static void loadDimensionEntry(IDimensionBuilder db, Entry ent) throws BadValueException { + if (ent.getValue().isJsonArray()) { + final JsonArray dims = ent.getValue().getAsJsonArray(); + if (dims.size() == 0) { + // blank list, accept all overworld + db.setAcceptAllOverworld(); + } else { + dims.forEach(item -> { + if (item.isJsonPrimitive() + && item.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(item.getAsInt()); + } + }); + } + } else if (ent.getValue().isJsonObject()) { + loadDimensions(db, ent.getValue().getAsJsonObject()); + } else { + throw new BadValueException(Constants.ConfigNames.DIMENSIONS, + ent.getValue().toString()); + } + } + private static List loadBlock(final JsonObject json) { final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); if (json.has(Constants.ConfigNames.STATE)) { @@ -323,86 +343,96 @@ private static List loadBlock(final JsonObject json) { return Arrays.asList(block.getDefaultState()); } + private static final String WHITELIST_ERROR = "Skipping entry (%s) in whitelist, not a proper value"; + private static final String BLACKLIST_ERROR = "Skipping entry (%s) in blacklist, not a proper value"; private static void loadBiomes(final IBiomeBuilder bb, final JsonObject biomeList) { boolean emptyWhitelist = false; - + if (biomeList.has(Constants.ConfigNames.WHITELIST) && biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addWhitelistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addWhitelistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } + loadBiomeWhitelist(bb, biomeList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray()); } else { emptyWhitelist = true; } if (biomeList.has(Constants.ConfigNames.BLACKLIST) && biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : biomeList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { - final String xN = elem.getAsString(); - if (xN.contains(":")) { - // not a BiomeDictionary entry (we hope) - bb.addBlacklistEntry(xN); - } else { - BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() - .forEach(bb::addBlacklistEntry); - } - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in blacklist, not a proper value", - elem.getAsString()); - } - } + loadBiomeBlacklist(bb, biomeList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray()); } else if (emptyWhitelist) { // empty whitelist and blacklist - accept everything bb.setAcceptAll(); } } + private static void loadBiomeBlacklist(IBiomeBuilder bb, JsonArray blacklist) { + for (final JsonElement elem : blacklist) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addBlacklistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addBlacklistEntry); + } + } else { + OreSpawn.LOGGER.error(BLACKLIST_ERROR, elem.getAsString()); + } + } + } + + private static void loadBiomeWhitelist(IBiomeBuilder bb, JsonArray whitelist) { + for (final JsonElement elem : whitelist) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isString()) { + final String xN = elem.getAsString(); + if (xN.contains(":")) { + // not a BiomeDictionary entry (we hope) + bb.addWhitelistEntry(xN); + } else { + BiomeDictionary.getBiomes(BiomeDictionary.Type.getType(xN)).stream() + .forEach(bb::addWhitelistEntry); + } + } else { + OreSpawn.LOGGER.error(WHITELIST_ERROR, elem.getAsString()); + } + } + } + private static void loadDimensions(final IDimensionBuilder db, final JsonObject dimensionList) { boolean emptyWhitelist = false; if (dimensionList.has(Constants.ConfigNames.WHITELIST) && dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.WHITELIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addWhitelistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } + loadDimensionWhitelist(db, dimensionList.get(Constants.ConfigNames.WHITELIST).getAsJsonArray()); } else { emptyWhitelist = true; } if (dimensionList.has(Constants.ConfigNames.BLACKLIST) && dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray().size() > 0) { - for (final JsonElement elem : dimensionList.get(Constants.ConfigNames.BLACKLIST) - .getAsJsonArray()) { - if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { - db.addBlacklistEntry(elem.getAsInt()); - } else { - OreSpawn.LOGGER.error("Skipping entry (%s) in whitelist, not a proper value", - elem.getAsString()); - } - } + loadDimensionBlacklist(db, dimensionList.get(Constants.ConfigNames.BLACKLIST).getAsJsonArray()); } else if (emptyWhitelist) { db.setAcceptAllOverworld(); } } + + private static void loadDimensionBlacklist(IDimensionBuilder db, JsonArray blacklist) { + for (final JsonElement elem : blacklist) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addBlacklistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error(WHITELIST_ERROR, elem.getAsString()); + } + } + } + + private static void loadDimensionWhitelist(IDimensionBuilder db, JsonArray whitelist) { + for (final JsonElement elem : whitelist) { + if (elem.isJsonPrimitive() && elem.getAsJsonPrimitive().isNumber()) { + db.addWhitelistEntry(elem.getAsInt()); + } else { + OreSpawn.LOGGER.error(BLACKLIST_ERROR, elem.getAsString()); + } + } + } } From 7b3877cf97d781aad7d79829892d611f440b4bc6 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 4 Sep 2018 04:15:52 -0400 Subject: [PATCH 068/205] why the f*ck was this labelled as deprecated ? --- .../com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 7addab86..8a005d29 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -59,9 +59,11 @@ public Map getReplacements() { * * @param dimension * @return - * @deprecated */ - @Deprecated + /* + * @deprecated (no, it isn't - why was it flagged this to begin with ?) + */ + // @Deprecated public List getDimensionDefault(final int dimension) { final String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" From 3a65848a652c7d84d48c89f6e6d1bd0aefefa248 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 4 Sep 2018 04:17:22 -0400 Subject: [PATCH 069/205] cognitive complexity cleanup and a small performance improvement - brings a new issue that seems to be having stuff spawning where it shouldn't, possibly because of x/z or y wrapping. Lets see if adding a non-wrapping helper fixes things --- .../orespawn/impl/features/UnderFluid.java | 82 ++++++++++++------- 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java index ca3d3a13..adc66120 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -4,9 +4,11 @@ package com.mcmoddev.orespawn.impl.features; import java.util.Random; -import java.util.ArrayList; +import java.util.Set; +import java.util.HashSet; import java.util.List; import java.util.stream.StreamSupport; +import java.util.stream.Collectors; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.api.FeatureBase; @@ -20,6 +22,7 @@ import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.gen.IChunkGenerator; import net.minecraftforge.fluids.Fluid; @@ -85,47 +88,64 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, final Fluid fluid = FluidRegistry.getFluid(params.get(Constants.FormatBits.FLUID).getAsString()); int tries = this.random.nextInt(triesMax - triesMin + 1) + triesMin; - int surveySize = triesMax * 2; int ySpan = maxHeight - minHeight; + int surveySize = ((256 * (16 * ySpan)) / 4) / 125; BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); Block fluidBlock = fluid.getBlock(); - List found = new ArrayList<>(); + Set found = new HashSet<>(); - for (int j = 0; j < surveySize; j++) { - BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); - BlockPos lowSide = sampleCenter.add(-3,-3,-3); - BlockPos highSide = sampleCenter.add(3,3,3); - StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) - .filter( bp -> world.getBlockState(bp).getMaterial().isLiquid() && - world.getBlockState(bp).getBlock().equals(fluidBlock) && - !found.contains(bp) && bp.getY() >= minHeight ) - .map(BlockPos.MutableBlockPos::toImmutable) - .forEach(found::add); - } - - int i = 0; + int surveyCount = 0; + int spawnCount = 0; - if (!found.isEmpty()) { - while( i < tries && !found.isEmpty()) { - BlockPos mp = found.get(this.random.nextInt(found.size())); - found.remove(mp); - while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { - mp = mp.down(); + while(surveyCount < surveySize && spawnCount < tries) { + BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); + BlockPos lowSide = sampleCenter.add(-2,-2,-2); + BlockPos highSide = sampleCenter.add(2,2,2); + Chunk chunk = world.getChunk(sampleCenter); + + if(!found.contains(sampleCenter)) { + found.addAll(findPossibleTargets(chunk, lowSide, highSide, fluidBlock, minHeight)); + + if(!found.isEmpty()) { + BlockPos target = found.toArray(new BlockPos[0])[this.random.nextInt(found.size())]; + spawnCount += maybeSpawn(target, minHeight, maxHeight, nodeSize, variance, world, spawnData); } - - if (mp.getY() < minHeight || mp.getY() > maxHeight) break; - - // calculate actual size for this node - int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); - // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... - // so... we copy vanilla spawn logic, to a degree, I think - spawnOre(world, spawnData, mp, size); - i++; + surveyCount++; } } } + private int maybeSpawn(BlockPos target, int minHeight, int maxHeight, int nodeSize, + int variance, World world, ISpawnEntry spawnData) { + BlockPos mp = target; + while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { + mp = mp.down(); + } + + if (mp.getY() > minHeight && mp.getY() < maxHeight) { + // calculate actual size for this node + int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); + // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... + // so... we copy vanilla spawn logic, to a degree, I think + spawnOre(world, spawnData, mp, size); + return 1; + } + + + return 0; + } + + private List findPossibleTargets(Chunk chunk, BlockPos lowSide, BlockPos highSide, + Block fluidBlock, int minHeight) { + return StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) + .filter( bp -> chunk.getBlockState(bp).getMaterial().isLiquid() && + chunk.getBlockState(bp).getBlock().equals(fluidBlock) && + bp.getY() >= minHeight ) + .map(BlockPos.MutableBlockPos::toImmutable) + .collect(Collectors.toList()); + } + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, final int quantity) { int count = quantity; From 668222ab2b25d0f5fe0fd578c02b9c3b0fca7ca6 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Fri, 5 Oct 2018 13:30:04 -0400 Subject: [PATCH 070/205] quick fix to try and work-around the strange "workingList is null" bug @Fulcanelli#7288 on Discord (@Sunconure11 on Github) reported a crash (BaseMetals issue 373) while "toying around with a script for InControl" that caused an NPE in OreSpawn in the BlockList code. This adds an extra check to try and make sure that the BlockList's "working list" is not empty after initialization. --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 2 ++ .../com/mcmoddev/orespawn/impl/features/ClusterGenerator.java | 1 + .../orespawn/impl/features/DefaultFeatureGenerator.java | 1 + .../mcmoddev/orespawn/impl/features/PrecisionGenerator.java | 1 + .../java/com/mcmoddev/orespawn/impl/features/UnderFluid.java | 1 + .../com/mcmoddev/orespawn/impl/features/VeinGenerator.java | 1 + src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java | 3 +++ 7 files changed, 10 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 0efa31fe..22d45318 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -239,6 +239,7 @@ protected void spawnMungeSW(final World world, final BlockPos blockPos, final in for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { if ((dx * dx + dy * dy + dz * dz) <= rSqr) { final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; @@ -262,6 +263,7 @@ protected void spawnMungeNE(final World world, final BlockPos blockPos, final in for (int dx = (int) (-1 * radius); dx < radius; dx++) { if ((dx * dx + dy * dy + dz * dz) <= rSqr) { final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, world.provider.getDimension(), spawnData); quantity--; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index ce423979..98a7d594 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -139,6 +139,7 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry while (count > 0) { final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, spawnData)) { diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 6b0b80ec..9db89710 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -96,6 +96,7 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc while (count > 0) { final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; final BlockPos target = pos.add(offs[scrambledLUT[--count]]); spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index ee3eaa52..91d08106 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -237,6 +237,7 @@ private int doCheckSpawn(final int dx, final int dy, final int dz, final int rSq if (getABC(dx, dy, dz) <= rSqr) { final BlockPos p = fixMungeOffset(new Vec3i(dx, dy, dz), loc, heightRange, pos); final IBlockState bl = spawnData.getBlocks().getRandomBlock(this.random); + if (bl.getBlock().equals(net.minecraft.init.Blocks.AIR)) return -1; return spawn(bl, world, p, world.provider.getDimension(), true, spawnData) ? 1 : 0; } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java index adc66120..f1c4697c 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -162,6 +162,7 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc while (count > 0) { final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; final BlockPos target = pos.add(offs[scrambledLUT[--count]]); spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index ec2a1292..b68c4c96 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -538,6 +538,7 @@ private void spawnOre(final World world, final ISpawnEntry spawnData, final Bloc while (count > 0) { final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; final BlockPos target = pos.add(offs[scrambledLUT[--count]]); spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java index 5b2b9871..326ad77a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java @@ -29,6 +29,9 @@ public void addBlock(final IBlockDefinition block) { public IBlockState getRandomBlock(final Random rand) { if (this.workingList.isEmpty()) { this.startNewSpawn(); + if (this.workingList.isEmpty()) { + return net.minecraft.init.Blocks.AIR.getDefaultState(); + } } final int spot = rand.nextInt(this.workingList.size()); From 79c4cd6acdf8869e4cf3bab4c64ca3e3ce56cdee Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 9 Oct 2018 19:16:37 -0700 Subject: [PATCH 071/205] Update forge to latest RB --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 0ebd0008..1ac080db 100644 --- a/build.gradle +++ b/build.gradle @@ -68,7 +68,7 @@ if (secretFile.exists()) { } minecraft { - version = '1.12.2-14.23.4.2705' + version = '1.12.2-14.23.5.2768' runDir = 'run' mappings = 'stable_39' // coreMod = '' From be495ad802e2abfb31e22138d627cade80f2a06e Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Tue, 9 Oct 2018 19:17:28 -0700 Subject: [PATCH 072/205] Explicitly specify Locale when calling String.format Some of these might be better as Locale.ROOT, we shall see --- .../api/exceptions/BadValueException.java | 4 +++- .../api/exceptions/UnknownFieldException.java | 6 ++++-- .../api/exceptions/UnknownNameException.java | 4 +++- .../orespawn/api/plugin/PluginLoader.java | 15 ++++++++------- .../orespawn/data/ReplacementsRegistry.java | 7 ++++--- .../orespawn/impl/os3/FeatureBuilder.java | 4 +++- .../mcmoddev/orespawn/impl/os3/OS3APIImpl.java | 5 +++-- .../orespawn/impl/os3/ReplacementBuilder.java | 3 ++- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java index e45b98a1..a71123f9 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.api.exceptions; +import java.util.Locale; + public class BadValueException extends Exception { private static final long serialVersionUID = 1143938140559149506L; @@ -15,7 +17,7 @@ public BadValueException(final String keyName, final String keyValue) { @Override public String getMessage() { final String baseMessage = super.getMessage(); - return String.format("Unknown value %s for key %s%n%s", this.keyValue, this.keyName, + return String.format(Locale.ENGLISH, "Unknown value %s for key %s%n%s", this.keyValue, this.keyName, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java index 9cf2b4ad..e6008d1e 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.api.exceptions; +import java.util.Locale; + public class UnknownFieldException extends Exception { private static final long serialVersionUID = 1L; @@ -7,12 +9,12 @@ public class UnknownFieldException extends Exception { public UnknownFieldException(final String theField) { super(); - this.message = String.format("Unkown field %s in config", theField); + this.message = String.format(Locale.ENGLISH, "Unkown field %s in config", theField); } @Override public String getMessage() { final String baseMessage = super.getMessage(); - return String.format("%s%n%s", this.message, baseMessage); + return String.format(Locale.ENGLISH, "%s%n%s", this.message, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java index 8e5b6049..94bf09af 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.api.exceptions; +import java.util.Locale; + public class UnknownNameException extends Exception { private static final long serialVersionUID = -3426121906665390773L; @@ -15,7 +17,7 @@ public UnknownNameException(final String fieldName, final String fieldValue) { @Override public String getMessage() { final String baseMessage = super.getMessage(); - return String.format("Unknown %s name %s%n%s", this.fieldName, this.fieldValue, + return String.format(Locale.ENGLISH, "Unknown %s name %s%n%s", this.fieldName, this.fieldValue, baseMessage); } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index 2d23b41f..f18cb3b1 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -14,6 +14,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.stream.Stream; import org.apache.commons.io.FileUtils; @@ -86,7 +87,7 @@ public void scanResources(final PluginData pd) { return; } - final String base = String.format("assets/%s/%s", pd.modId, pd.resourcePath); + final String base = String.format(Locale.ENGLISH, "assets/%s/%s", pd.modId, pd.resourcePath); final URL resURL = getClass().getClassLoader().getResource(base); if (resURL == null) { @@ -101,7 +102,7 @@ public void scanResources(final PluginData pd) { uri = resURL.toURI(); } catch (URISyntaxException ex) { CrashReport report = CrashReport.makeCrashReport(ex, - String.format("Failed to get URI for %s", + String.format(Locale.ENGLISH, "Failed to get URI for %s", (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); return; @@ -113,7 +114,7 @@ public void scanResources(final PluginData pd) { copyout(fileSystem.getPath(base), pd.modId); } catch (IOException exc) { CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Failed in getting FileSystem handler set up for %s", uri.getPath())); + Locale.ENGLISH, "Failed in getting FileSystem handler set up for %s", uri.getPath())); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } @@ -137,14 +138,14 @@ private void copyout(final Path myPath, final String modId) { if ("_features".equals(FilenameUtils.getBaseName(name))) { target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF, - String.format("features-%s.json", modId)); + String.format(Locale.ENGLISH, "features-%s.json", modId)); } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, Constants.FileBits.SYSCONF, - String.format("replacements-%s.json", modId)); + String.format(Locale.ENGLISH, "replacements-%s.json", modId)); } else { target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - String.format("%s.json", modId)); + String.format(Locale.ENGLISH, "%s.json", modId)); } if (!target.toFile().exists()) { @@ -156,7 +157,7 @@ private void copyout(final Path myPath, final String modId) { } } catch (IOException exc) { CrashReport report = CrashReport.makeCrashReport(exc, String.format( - "Faulted while iterating %s for config files or copying them out", myPath)); + Locale.ENGLISH, "Faulted while iterating %s for config files or copying them out", myPath)); report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); OreSpawn.LOGGER.error(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 8a005d29..7dd310f7 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; @@ -90,7 +91,7 @@ public List getDimensionDefault(final int dimension) { public IReplacementEntry getReplacement(final String name) { final ResourceLocation act = new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name)); + name.contains(":") ? name : String.format(Locale.ENGLISH, "orespawn:%s", name)); if (registry.containsKey(act)) { return registry.getValue(act); @@ -220,14 +221,14 @@ public void saveFile(final String modName) { outs.add(ent.getKey().toString(), entry); }); final Path p = Paths.get("config", "orespawn3", "sysconfig", - String.format("replacements-%s.json", modName)); + String.format(Locale.ENGLISH, "replacements-%s.json", modName)); try (final BufferedWriter w = Files.newBufferedWriter(p)) { final Gson gson = new GsonBuilder().setPrettyPrinting().create(); final String ov = gson.toJson(outs); w.write(ov); } catch (final IOException e) { CrashReport report = CrashReport.makeCrashReport(e, String - .format("Failed writing replacements file %s", p.toAbsolutePath().toString())); + .format(Locale.ENGLISH, "Failed writing replacements file %s", p.toAbsolutePath().toString())); report.getCategory().addCrashSection(ORE_SPAWN_VERSION, Constants.VERSION); OreSpawn.LOGGER.info(report.getCompleteReport()); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java index 63f61da3..7bbaa8bd 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.impl.os3; +import java.util.Locale; + import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.mcmoddev.orespawn.OreSpawn; @@ -24,7 +26,7 @@ public FeatureBuilder() { public IFeatureBuilder setFeature(final String featureName) { String actName = featureName; if (!actName.contains(":")) { - actName = String.format("orespawn:%s", featureName); + actName = String.format(Locale.ENGLISH, "orespawn:%s", featureName); } return this.setFeature(new ResourceLocation(actName)); } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index a283518f..61516b72 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -8,6 +8,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; @@ -196,7 +197,7 @@ public Map getAllSpawns() { @Override public boolean featureExists(final String featureName) { return this.featureExists(new ResourceLocation(featureName.contains(":") ? featureName - : String.format("orespawn:%s", featureName))); + : String.format(Locale.ENGLISH, "orespawn:%s", featureName))); } @Override @@ -234,7 +235,7 @@ public boolean hasReplacement(final ResourceLocation resourceLocation) { @Override public boolean hasReplacement(final String name) { return this.hasReplacement(new ResourceLocation( - name.contains(":") ? name : String.format("orespawn:%s", name))); + name.contains(":") ? name : String.format(Locale.ENGLISH, "orespawn:%s", name))); } @Override diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index df6eb61a..2e78c747 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -2,6 +2,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.Locale; import org.apache.commons.lang3.RandomStringUtils; @@ -95,7 +96,7 @@ public boolean hasEntries() { @Override public IReplacementEntry create() { if (this.replacementName == null) { - this.replacementName = String.format("replacement_%s", + this.replacementName = String.format(Locale.ENGLISH, "replacement_%s", RandomStringUtils.randomAlphanumeric(8, 16)); } From 4f41a4b98b34f8e0e9d35188a28cc7f9237555eb Mon Sep 17 00:00:00 2001 From: "Daniel R. Hazelton" Date: Sat, 12 Jan 2019 11:11:45 -0500 Subject: [PATCH 073/205] don't let block updates go when placing a block - it causes issues. --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 22d45318..b23304af 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -103,7 +103,8 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final Biome thisBiome = world.getBiome(coord); if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { - world.setBlockState(coord, oreBlock); + // don't send block update, send to client, don't re-render, observers don't see the change + world.setBlockState(coord, oreBlock, 0x22); return true; } else { return false; From 59ec8cef78ae8ab8940cadd34f4e12be74809ba3 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sat, 9 Feb 2019 11:39:59 -0500 Subject: [PATCH 074/205] version bump in prep for push to CF to get a version with some fixes for remaining CWG bugs --- src/main/java/com/mcmoddev/orespawn/data/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 3c79155b..fd09c998 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -7,7 +7,7 @@ public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.3.0"; + public static final String VERSION = "3.3.1"; public static final String RETROGEN_KEY = "Retrogen"; public static final String CONFIG_FILE = "config/orespawn.cfg"; public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; From 473b62e0bb027c233759926e672347d49c1738e7 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 3 Mar 2019 19:47:12 -0500 Subject: [PATCH 075/205] fix the BlockState deserialization code - this should resolve the part of #145 by @MechanosG --- .../orespawn/commands/AddOreCommand.java | 19 ++++--- .../orespawn/data/ReplacementsRegistry.java | 22 ++++++-- .../orespawn/impl/os3/BlockBuilder.java | 18 +++++-- .../orespawn/impl/os3/ReplacementBuilder.java | 10 +++- .../orespawn/impl/os3/SpawnBuilder.java | 9 +++- .../orespawn/json/OreSpawnReader.java | 50 +++++++++++-------- .../com/mcmoddev/orespawn/util/StateUtil.java | 37 ++++++++------ 7 files changed, 115 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java index 8ec4a687..9219dbce 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java @@ -50,7 +50,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, throw new CommandException("You have no item in your main hand"); } else if (!(stack.getItem() instanceof ItemBlock)) { throw new CommandException("The item in your main hand isn't a block"); - } else if (args.length < 2) { + } else if (args.length < 1) { throw new CommandException(this.getUsage(sender)); } @@ -58,10 +58,15 @@ public void execute(final MinecraftServer server, final ICommandSender sender, @SuppressWarnings("deprecation") final IBlockState state = Block.getBlockFromItem(stack.getItem()) .getStateFromMeta(stack.getItemDamage()); - + final String rawData = getChatComponentFromNthArg(sender, args, 1).getUnformattedText(); final JsonParser p = new JsonParser(); - final JsonElement parsed = mergeDefaults(p.parse(rawData), state); + final JsonElement parsed; + if(rawData != null && rawData.length() > 0) { + parsed = mergeDefaults(p.parse(rawData), state); + } else { + parsed = mergeDefaults(p.parse("{}"), state); + } OreSpawnReader.loadFromJson(FilenameUtils.getBaseName(file), parsed); OreSpawnWriter.saveSingle(FilenameUtils.getBaseName(file)); } @@ -78,10 +83,10 @@ private JsonElement mergeDefaults(final JsonElement parse, final IBlockState sta work.addProperty(ConfigNames.RETROGEN, false); } if (!work.has(ConfigNames.FEATURE)) { - work.addProperty(ConfigNames.FEATURE, "default"); + work.addProperty(ConfigNames.FEATURE, "orespawn:default"); } if (!work.has(ConfigNames.REPLACEMENT)) { - work.addProperty(ConfigNames.REPLACEMENT, "default"); + work.addProperty(ConfigNames.REPLACEMENT, "orespawn:default"); } if (!work.has(ConfigNames.PARAMETERS)) { work.add(ConfigNames.PARAMETERS, @@ -99,7 +104,9 @@ private JsonElement mergeDefaults(final JsonElement parse, final IBlockState sta block.addProperty(ConfigNames.CHANCE, 100); block.addProperty(ConfigNames.NAME, state.getBlock().getRegistryName().toString()); block.addProperty(ConfigNames.STATE, StateUtil.serializeState(state)); - work.add(ConfigNames.BLOCK, block); + final JsonArray blocks = new JsonArray(); + blocks.add(block); + work.add(ConfigNames.BLOCK, blocks); return work; } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 7dd310f7..ab4f349b 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -65,6 +65,7 @@ public Map getReplacements() { * @deprecated (no, it isn't - why was it flagged this to begin with ?) */ // @Deprecated + @SuppressWarnings("deprecation") public List getDimensionDefault(final int dimension) { final String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" @@ -101,8 +102,15 @@ public IReplacementEntry getReplacement(final String name) { } public void addBlock(final String name, final String blockName, final String blockState) { - final IBlockState b = StateUtil.deserializeState( - ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + IBlockState b; + try { + b = StateUtil.deserializeState( + ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + b = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)).getDefaultState(); + } addBlock(name, b); } @@ -188,7 +196,15 @@ public void loadFile(final Path file) { } else if (asObj.has(Constants.ConfigNames.STATE)) { // has a state state = asObj.get(Constants.ConfigNames.STATE).getAsString(); - blocks.add(StateUtil.deserializeState(theBlock, state)); + IBlockState b; + try { + b = StateUtil.deserializeState(theBlock, state); + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + b = theBlock.getDefaultState(); + } + blocks.add(b); } else { // use the default state blocks.add(theBlock.getDefaultState()); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index c7c57eab..de2e18de 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -67,7 +67,13 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, this.isValid = false; } final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); + try { + return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return this; + } } /** @@ -140,8 +146,14 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL this.isValid = false; } final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), - chance); + try { + return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), + chance); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return this; + } } /** diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 2e78c747..8007f50f 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -72,8 +72,14 @@ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation @Override public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation, final String state) { - return this.addEntry(StateUtil - .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); + try { + return this.addEntry(StateUtil + .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); + } } /** diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 1c95bb11..280fd995 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -164,7 +164,14 @@ public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLoca public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLocation, final String blockState, final int chance) { final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); - final IBlockState tempVar = StateUtil.deserializeState(tempBlock, blockState); + IBlockState tempVar; + try { + tempVar = StateUtil.deserializeState(tempBlock, blockState); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + tempVar = tempBlock.getDefaultState(); + } return this.addBlockWithChance(tempVar, chance); } diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index d289ec0b..aeb1ee13 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -51,6 +51,25 @@ private OreSpawnReader() { // hiding the default one } + private static JsonElement doPresetFix(final JsonElement value, + final PresetsStorage configPresets) { + if (value.isJsonObject()) { + return doPresetForObject(value.getAsJsonObject(), configPresets); + } else if (value.isJsonArray()) { + return doPresetForArray(value.getAsJsonArray(), configPresets); + } else if (value.isJsonPrimitive() && !value.isJsonNull()) { + if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { + return configPresets.get(value.getAsString()); + } else { + return value; + } + } else { + OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " + + value.toString()); + return value; + } + } + public static void tryReadFile(final Path conf) throws MissingVersionException, NotAProperConfigException, OldVersionException, UnknownVersionException { @@ -125,25 +144,6 @@ private static JsonObject doHandlePresets(final JsonObject spawnData) { return spawnData; } - private static JsonElement doPresetFix(final JsonElement value, - final PresetsStorage configPresets) { - if (value.isJsonObject()) { - return doPresetForObject(value.getAsJsonObject(), configPresets); - } else if (value.isJsonArray()) { - return doPresetForArray(value.getAsJsonArray(), configPresets); - } else if (value.isJsonPrimitive() && !value.isJsonNull()) { - if (value.getAsJsonPrimitive().isString() && value.getAsString().matches("^\\$.*")) { - return configPresets.get(value.getAsString()); - } else { - return value; - } - } else { - OreSpawn.LOGGER.error("Error handling presets for config, unknown value type for item " - + value.toString()); - return value; - } - } - private static JsonElement doPresetForArray(final JsonArray value, final PresetsStorage configPresets) { final JsonArray rv = new JsonArray(); @@ -241,6 +241,7 @@ private static String loadFeatureEntry(Entry ent) throws Ba return featureName; } + @SuppressWarnings("deprecation") private static void loadBlocks(ISpawnBuilder sb, Entry ent) throws BadValueException { if (ent.getValue().isJsonArray()) { for (final JsonElement elem : ent.getValue().getAsJsonArray()) { @@ -320,12 +321,19 @@ private static void loadDimensionEntry(IDimensionBuilder db, Entry loadBlock(final JsonObject json) { final String blockName = json.get(Constants.ConfigNames.NAME).getAsString(); if (json.has(Constants.ConfigNames.STATE)) { final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); - return Arrays.asList(StateUtil.deserializeState(block, - json.get(Constants.ConfigNames.STATE).getAsString())); + try { + return Arrays.asList(StateUtil.deserializeState(block, + json.get(Constants.ConfigNames.STATE).getAsString())); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return Arrays.asList(block.getDefaultState()); + } } else if (json.has(Constants.ConfigNames.METADATA)) { final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)); return Arrays.asList( diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 28f663e5..2366cb0b 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -1,8 +1,10 @@ package com.mcmoddev.orespawn.util; +import com.google.common.base.Optional; import com.mcmoddev.orespawn.OreSpawn; import net.minecraft.block.Block; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; public class StateUtil { @@ -25,21 +27,28 @@ public static String serializeState(final IBlockState state) { return string; } - public static IBlockState deserializeState(final Block block, final String state) { - for (final IBlockState validState : block.getBlockState().getValidStates()) { - String string = validState.toString(); - string = string.substring(string.indexOf('[') + 1, - string.length() - (string.endsWith("]") ? 1 : 0)); - - if (string.equals(block.getRegistryName().toString())) { - string = ""; - } - - if (state.equals(string)) { - return validState; + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static IBlockState deserializeState(final Block block, final String state) throws Exception { + String bits[]; + if(state.contains(",")) bits = state.split(","); + else bits = new String[] { state }; + + IBlockState rv = block.getDefaultState(); + + for(String sv : bits) { + String kvp[] = sv.split("="); + IProperty prop = block.getBlockState().getProperty(kvp[0]); + if(prop != null) { + Optional propValue = prop.parseValue(kvp[1]); + if(propValue.isPresent()) + rv = rv.withProperty(prop, propValue.get()); + else + throw new Exception(String.format("%s is not a valid value for property %s", kvp[1], kvp[0])); + } else { + throw new Exception(String.format("%s is not a known property of %s", kvp[0], block.getRegistryName())); } } - - return null; + + return rv; } } From d81650b0ba81aa36a5f21b044530c29b4ced1550 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 3 Mar 2019 19:56:07 -0500 Subject: [PATCH 076/205] blargh - forgot that the code checkers, including Codacy, would trip on using default java.lang.Exception --- src/main/java/com/mcmoddev/orespawn/util/StateUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index 2366cb0b..bcf258f0 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -2,6 +2,7 @@ import com.google.common.base.Optional; import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; @@ -43,9 +44,9 @@ public static IBlockState deserializeState(final Block block, final String state if(propValue.isPresent()) rv = rv.withProperty(prop, propValue.get()); else - throw new Exception(String.format("%s is not a valid value for property %s", kvp[1], kvp[0])); + throw new BadStateValueException(String.format("%s is not a valid value for property %s", kvp[1], kvp[0])); } else { - throw new Exception(String.format("%s is not a known property of %s", kvp[0], block.getRegistryName())); + throw new BadStateValueException(String.format("%s is not a known property of %s", kvp[0], block.getRegistryName())); } } From 07ba78de9d6616acf582ddcc8a4fa2059d4be522 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 3 Mar 2019 19:58:55 -0500 Subject: [PATCH 077/205] ...how the fracking hell did I forget this? --- .../api/exceptions/BadStateValueException.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java new file mode 100755 index 00000000..01929897 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java @@ -0,0 +1,13 @@ +package com.mcmoddev.orespawn.api.exceptions; + +public class BadStateValueException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 3826628238012469423L; + + public BadStateValueException(String msg) { + super(msg); + } +} From f15844d30a63c4c0861a0d725555fdfc706bfba4 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 3 Mar 2019 20:22:12 -0500 Subject: [PATCH 078/205] add another round of checks to try and keep cascading chunk-gen from happening - this appears to have finally(\!) solved it --- .../com/mcmoddev/orespawn/api/FeatureBase.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index b23304af..3a03dcd6 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -95,6 +95,24 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { + int m_x = coord.getX() - 1; + int p_x = coord.getX() + 1; + int x = coord.getX(); + int m_z = coord.getZ() - 1; + int p_z = coord.getZ() + 1; + int z = coord.getZ(); + int min_x = (((int)(x/16))*16)+1; // convert to ChunkPos + int max_x = min_x+30; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int min_z = (((int)(z/16))*16)+1; // convert to ChunkPos + int max_z = min_z+30; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + if(m_x <= min_x || p_x >= max_x || m_z <= min_z || p_z >= max_z) { + if(cacheOverflow) { + cacheOverflowBlock(oreBlock, coord, dimension); + return true; + } else { + return false; + } + } if (!isValidBlock(oreBlock)) { return false; } From 6d4089689cf8d19050637fff70e7d1e26edc7db2 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 3 Mar 2019 20:51:49 -0500 Subject: [PATCH 079/205] SonarQube cleanups --- .../mcmoddev/orespawn/api/FeatureBase.java | 35 ++++++++++--------- .../orespawn/commands/DumpBiomesCommand.java | 4 +-- .../orespawn/data/ReplacementsRegistry.java | 10 +++--- .../orespawn/impl/features/VeinGenerator.java | 2 +- .../orespawn/impl/os3/BlockBuilder.java | 16 +++++---- .../orespawn/impl/os3/ReplacementBuilder.java | 8 +++-- .../orespawn/impl/os3/SpawnBuilder.java | 9 +++-- .../orespawn/json/OreSpawnReader.java | 8 +++-- .../com/mcmoddev/orespawn/util/StateUtil.java | 2 +- 9 files changed, 55 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 3a03dcd6..a94fcaf3 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -247,22 +247,31 @@ protected int getPoint(final int lowerBound, final int upperBound, final int med return t - median; } + protected void spawnMungeInner(final Random prng, final int rSqr, int quantity, + final Vec3i vals, final ISpawnEntry spawnData, final World world, final BlockPos blockPos) { + int dx = vals.getX(); + int dy = vals.getY(); + int dz = vals.getZ(); + final IBlockList possibleOres = spawnData.getBlocks(); + final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); + + if ((dx * dx + dy * dy + dz * dz) <= rSqr) { + final IBlockState oreBlock = possibleOres.getRandomBlock(prng); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; + spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, + world.provider.getDimension(), spawnData); + quantity--; + } + } + protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, final double radius, final ISpawnEntry spawnData, final int count) { final Random prng = this.random; int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for (int dy = (int) (-1 * radius); dy < radius; dy++) { for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } + spawnMungeInner(prng, rSqr, quantity, new Vec3i(dx,dy,dz), spawnData, world, blockPos); if (quantity <= 0) { return; } @@ -280,13 +289,7 @@ protected void spawnMungeNE(final World world, final BlockPos blockPos, final in for (int dy = (int) (-1 * radius); dy < radius; dy++) { for (int dz = (int) (-1 * radius); dz < radius; dz++) { for (int dx = (int) (-1 * radius); dx < radius; dx++) { - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } + spawnMungeInner(prng, rSqr, quantity, new Vec3i(dx,dy,dz), spawnData, world, blockPos); if (quantity <= 0) { return; } diff --git a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java index 74bf10a5..fa9f2ccf 100644 --- a/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java +++ b/src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java @@ -2,8 +2,8 @@ import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; -import org.apache.commons.codec.CharEncoding; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringEscapeUtils; @@ -47,7 +47,7 @@ public void execute(final MinecraftServer server, final ICommandSender sender, try { FileUtils.writeStringToFile(new File(".", "biome_dump.json"), - StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8); + StringEscapeUtils.unescapeJson(json), StandardCharsets.UTF_8); } catch (final IOException e) { throw new CommandException("Failed to save the json file"); } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index ab4f349b..dc0314c0 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -107,8 +107,9 @@ public void addBlock(final String name, final String blockName, final String blo b = StateUtil.deserializeState( ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)), blockState); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); b = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockName)).getDefaultState(); } addBlock(name, b); @@ -200,8 +201,9 @@ public void loadFile(final Path file) { try { b = StateUtil.deserializeState(theBlock, state); } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem1: e1.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem1.getClassName(), elem1.getMethodName(), elem1.getFileName(), elem1.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e1.getMessage(), p.toString())); b = theBlock.getDefaultState(); } blocks.add(b); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java index b68c4c96..dd3288c3 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java @@ -175,7 +175,7 @@ private void spawnVein(final int veinLength, final int nodeSize, final EnumFacin private class SquareWeight extends WeightedRandom.Item { - public EnumSquare item; + private EnumSquare item; public SquareWeight(EnumSquare item, int weight) { super(weight); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index de2e18de..6cf6fc58 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -1,5 +1,7 @@ package com.mcmoddev.orespawn.impl.os3; +import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; import com.mcmoddev.orespawn.api.os3.IBlockBuilder; import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.util.StateUtil; @@ -69,9 +71,10 @@ public IBlockBuilder setFromName(final ResourceLocation blockResourceLocation, final Block tempBlock = ForgeRegistries.BLOCKS.getValue(blockResourceLocation); try { return this.setFromBlockState(StateUtil.deserializeState(tempBlock, state)); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (BadStateValueException e) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); return this; } } @@ -149,9 +152,10 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL try { return this.setFromBlockStateWithChance(StateUtil.deserializeState(tempBlock, state), chance); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (BadStateValueException e) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); return this; } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java index 8007f50f..8071d4b6 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.RandomStringUtils; import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; import com.mcmoddev.orespawn.api.os3.IReplacementBuilder; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; @@ -75,9 +76,10 @@ public IReplacementBuilder addEntry(final ResourceLocation blockResourceLocation try { return this.addEntry(StateUtil .deserializeState(ForgeRegistries.BLOCKS.getValue(blockResourceLocation), state)); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (BadStateValueException e) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); return this.addEntry(ForgeRegistries.BLOCKS.getValue(blockResourceLocation).getDefaultState()); } } diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 280fd995..1d31dacb 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -1,8 +1,10 @@ package com.mcmoddev.orespawn.impl.os3; +import com.mcmoddev.orespawn.OreSpawn; import com.mcmoddev.orespawn.api.BiomeLocation; import com.mcmoddev.orespawn.api.IBlockList; import com.mcmoddev.orespawn.api.IDimensionList; +import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; import com.mcmoddev.orespawn.api.os3.IBlockDefinition; import com.mcmoddev.orespawn.api.os3.IFeatureEntry; import com.mcmoddev.orespawn.api.os3.IReplacementEntry; @@ -167,9 +169,10 @@ public ISpawnBuilder addBlockWithChance(final ResourceLocation blockResourceLoca IBlockState tempVar; try { tempVar = StateUtil.deserializeState(tempBlock, blockState); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (BadStateValueException e) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); tempVar = tempBlock.getDefaultState(); } return this.addBlockWithChance(tempVar, chance); diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index aeb1ee13..efc71710 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -18,6 +18,7 @@ import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.api.exceptions.BadStateValueException; import com.mcmoddev.orespawn.api.exceptions.BadValueException; import com.mcmoddev.orespawn.api.exceptions.MissingVersionException; import com.mcmoddev.orespawn.api.exceptions.NotAProperConfigException; @@ -329,9 +330,10 @@ private static List loadBlock(final JsonObject json) { try { return Arrays.asList(StateUtil.deserializeState(block, json.get(Constants.ConfigNames.STATE).getAsString())); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (BadStateValueException e) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); return Arrays.asList(block.getDefaultState()); } } else if (json.has(Constants.ConfigNames.METADATA)) { diff --git a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java index bcf258f0..1997daee 100644 --- a/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java +++ b/src/main/java/com/mcmoddev/orespawn/util/StateUtil.java @@ -29,7 +29,7 @@ public static String serializeState(final IBlockState state) { } @SuppressWarnings({ "unchecked", "rawtypes" }) - public static IBlockState deserializeState(final Block block, final String state) throws Exception { + public static IBlockState deserializeState(final Block block, final String state) throws BadStateValueException { String bits[]; if(state.contains(",")) bits = state.split(","); else bits = new String[] { state }; From 3cf3a3d1a1e79dd0cfa3d7354145b642ba6abf2c Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 4 Mar 2019 02:08:44 -0500 Subject: [PATCH 080/205] more SonarQube fixes --- src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index 8042f745..a05544a7 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Map; import java.util.TreeMap; @@ -151,7 +152,7 @@ public void writeFeatures(final File file) { try { FileUtils.writeStringToFile(file, StringEscapeUtils.unescapeJson(json), - CharEncoding.UTF_8); + StandardCharsets.UTF_8); } catch (final IOException e) { final CrashReport report = CrashReport.makeCrashReport(e, "Failed writing config " + file.getName()); From ceb699f99b95cb55006d215bdf52b58dc7040501 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 4 Mar 2019 10:01:23 -0500 Subject: [PATCH 081/205] and even more SonarQube --- .../orespawn/data/FeatureRegistry.java | 1 - .../orespawn/data/ReplacementsRegistry.java | 60 +++++++------ .../impl/features/ClusterGenerator.java | 86 ++++++++++++------- .../impl/features/PrecisionGenerator.java | 13 +-- 4 files changed, 93 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java index a05544a7..603ef370 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java @@ -9,7 +9,6 @@ import java.util.Map; import java.util.TreeMap; -import org.apache.commons.codec.CharEncoding; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringEscapeUtils; diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index dc0314c0..deaf42c1 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -22,7 +22,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mcmoddev.orespawn.OreSpawn; @@ -169,25 +168,16 @@ public void loadFile(final Path file) { final JsonArray entries = elem.getValue().getAsJsonArray(); final List blocks = new LinkedList<>(); com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); - for (final JsonElement e : entries) { +// for (final JsonElement e : entries) { + entries.forEach( e -> { final JsonObject asObj = e.getAsJsonObject(); final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() .toLowerCase(); // is this an OreDictionary entry ? if (blockName.startsWith("ore:")) { - // yes, it is - final String oreDictName = blockName.split(":")[1]; - OreDictionary.getOres(oreDictName).forEach(iS -> { - if (iS.getMetadata() != 0) { - blocks.add(Block.getBlockFromItem(iS.getItem()) - .getStateFromMeta(iS.getMetadata())); - } else { - blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); - } - }); + loadOreDict(blockName, blocks); } else { - String state = null; final ResourceLocation blockRL = new ResourceLocation(blockName); final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); if (asObj.has(Constants.ConfigNames.METADATA)) { @@ -196,29 +186,49 @@ public void loadFile(final Path file) { blocks.add(theBlock.getStateFromMeta(meta)); } else if (asObj.has(Constants.ConfigNames.STATE)) { // has a state - state = asObj.get(Constants.ConfigNames.STATE).getAsString(); - IBlockState b; - try { - b = StateUtil.deserializeState(theBlock, state); - } catch (Exception e1) { - StringBuilder p = new StringBuilder(); - for(StackTraceElement elem1: e1.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem1.getClassName(), elem1.getMethodName(), elem1.getFileName(), elem1.getLineNumber())); - OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e1.getMessage(), p.toString())); - b = theBlock.getDefaultState(); - } - blocks.add(b); + loadBlockState(blockName, asObj, blocks); } else { // use the default state blocks.add(theBlock.getDefaultState()); } } - } + }); final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); registry.register(replacer); }); } + private void loadBlockState(String blockName, JsonObject asObj, List blocks) { + final ResourceLocation blockRL = new ResourceLocation(blockName); + final Block theBlock = ForgeRegistries.BLOCKS.getValue(blockRL); + final String state = asObj.get(Constants.ConfigNames.STATE).getAsString(); + IBlockState b; + try { + b = StateUtil.deserializeState(theBlock, state); + } catch (Exception e1) { + StringBuilder p = new StringBuilder(); + for(StackTraceElement elem1: e1.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem1.getClassName(), elem1.getMethodName(), elem1.getFileName(), elem1.getLineNumber())); + OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e1.getMessage(), p.toString())); + b = theBlock.getDefaultState(); + } + blocks.add(b); + } + + @SuppressWarnings("deprecation") + private void loadOreDict(String blockName, List blocks) { + // yes, it is + final String oreDictName = blockName.split(":")[1]; + OreDictionary.getOres(oreDictName).forEach(iS -> { + if (iS.getMetadata() != 0) { + blocks.add(Block.getBlockFromItem(iS.getItem()) + .getStateFromMeta(iS.getMetadata())); + } else { + blocks.add(Block.getBlockFromItem(iS.getItem()).getDefaultState()); + } + }); + } + public void saveFile(final String modName) { final JsonObject outs = new JsonObject(); diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index 98a7d594..e16435f5 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -27,10 +27,28 @@ public ClusterGenerator() { this(new Random()); } + private class SpawnParameters { + public final int clusterSize; + public final int variance; + public final int clusterCount; + public final int maxSpread; + public final int minHeight; + public final int maxHeight; + + SpawnParameters(final int clusterSize, final int variance, final int clusterCount, + final int maxSpread, final int minHeight, final int maxHeight) { + this.clusterSize = clusterSize; + this.variance = variance; + this.clusterCount = clusterCount; + this.maxSpread = maxSpread; + this.minHeight = minHeight; + this.maxHeight = maxHeight; + } + } @Override public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos posIn) { + final ChunkPos pos = posIn; final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -73,7 +91,7 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, final int y = random.nextInt(maxHeight - minHeight) + minHeight; final int z = blockZ + zRand - (maxSpread / 2); - spawnCluster(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight, + spawnCluster(new SpawnParameters(clusterSize, variance, clusterCount, maxSpread, minHeight, maxHeight), spawnData, world, new BlockPos(x, y, z)); } @@ -81,36 +99,35 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, } } - private void spawnCluster(final int clusterSize, final int variance, final int clusterCount, - final int maxSpread, final int minHeight, final int maxHeight, + private void spawnCluster(final SpawnParameters params, final ISpawnEntry spawnData, final World world, final BlockPos pos) { // spawn a cluster at the center, then a bunch around the outside... - int r = clusterSize - variance; + int r = params.clusterSize - params.variance; - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; + if (params.variance > 0) { + r += this.random.nextInt(2 * params.variance) - params.variance; } spawnChunk(world, pos, spawnData, r); - int count = this.random.nextInt(clusterCount - 1); // always at least the first, but vary + int count = this.random.nextInt(params.clusterCount - 1); // always at least the first, but vary // inside that - if (variance > 0) { - count += this.random.nextInt(2 * variance) - variance; + if (params.variance > 0) { + count += this.random.nextInt(2 * params.variance) - params.variance; } while (count >= 0) { - r = clusterSize - variance; + r = params.clusterSize - params.variance; - if (variance > 0) { - r += this.random.nextInt(2 * variance) - variance; + if (params.variance > 0) { + r += this.random.nextInt(2 * params.variance) - params.variance; } - final int radius = maxSpread / 2; + final int radius = params.maxSpread / 2; final int xp = getPoint(-radius, radius, 0); - final int yp = getPoint(minHeight, maxHeight, (maxHeight - minHeight) / 2); + final int yp = getPoint(params.minHeight, params.maxHeight, (params.maxHeight - params.minHeight) / 2); final int zp = getPoint(-radius, radius, 0); final BlockPos p = pos.add(xp, yp, zp); @@ -138,22 +155,7 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry int z = 0; while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - - if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, - spawnData)) { - count++; - z++; - } else { - z = 0; - } - - if (z > 5) { - count--; - z = 0; - OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); - } + trySpawnInner(spawnData, world, pos, dimension, count, z, offs, scrambledLUT); } return; @@ -162,6 +164,26 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } + private void trySpawnInner(ISpawnEntry spawnData, World world, BlockPos pos, + int dimension, int count, int z, Vec3i[] offs, int[] scrambledLUT) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; + + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData)) { + count++; + z++; + } else { + z = 0; + } + + if (z > 5) { + count--; + z = 0; + OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); + } + } + private void doSpawnFill(final boolean nextBoolean, final int quantity, final ISpawnEntry spawnData, final World world, final BlockPos pos) { final int count = quantity; diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java index 91d08106..0a88c5cc 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java @@ -30,8 +30,8 @@ public PrecisionGenerator() { @Override public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos _pos) { - final ChunkPos pos = _pos; + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos posIn) { + final ChunkPos pos = posIn; final JsonObject params = spawnData.getFeature().getFeatureParameters(); // First, load cached blocks for neighboring chunk ore spawns @@ -195,13 +195,8 @@ private int spawnFill(final ISpawnEntry spawnData, final World world, final Chun final double radius = Math.pow(nodeSize, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; final int rSqr = (int) Math.ceil(radius * radius); - if (this.random.nextBoolean()) { - return spawnPrecise(spawnData, world, pos, loc, heightRange, false, radius, rSqr, - nodeSize); - } else { - return spawnPrecise(spawnData, world, pos, loc, heightRange, true, radius, rSqr, - nodeSize); - } + return spawnPrecise(spawnData, world, pos, loc, heightRange, !this.random.nextBoolean(), radius, rSqr, + nodeSize); } private int spawnPrecise(final ISpawnEntry spawnData, final World world, final ChunkPos pos, From 1af1f95c8dba1c2ffda673d654818a289712092b Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 18 Mar 2019 20:30:27 -0400 Subject: [PATCH 082/205] comment out some now unused code and fix the cascading gen lag caused by the work queue not doing enough work per tick --- src/main/java/com/mcmoddev/orespawn/EventHandlers.java | 2 +- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 7f2deec9..3510935d 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -211,7 +211,7 @@ public void worldTick(final WorldTickEvent ev) { if (ev.phase == Phase.END) { final Deque>> b = new LinkedList<>(); - for (int c = 0; c < 5 && !chunks.isEmpty(); c++) { + for (int c = 0; c < 25 && !chunks.isEmpty(); c++) { b.push(chunks.pop()); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index a94fcaf3..9fb97aaf 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -284,8 +284,8 @@ protected void spawnMungeNE(final World world, final BlockPos blockPos, final in final double radius, final ISpawnEntry spawnData, final int count) { final Random prng = this.random; int quantity = count; - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); +// final IBlockList possibleOres = spawnData.getBlocks(); +// final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); for (int dy = (int) (-1 * radius); dy < radius; dy++) { for (int dz = (int) (-1 * radius); dz < radius; dz++) { for (int dx = (int) (-1 * radius); dx < radius; dx++) { From e942a2d7167703a6b732b2102daeafcf012f3f2c Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 27 Mar 2019 20:54:01 -0400 Subject: [PATCH 083/205] remove a bunch of debug outs, fix the 'refuses to spawn in negative-x/negative-z chunks' issue and some minor cleanups --- build.gradle | 7 +++++ .../java/com/mcmoddev/orespawn/OreSpawn.java | 2 +- .../mcmoddev/orespawn/api/FeatureBase.java | 31 ++++++++++--------- .../orespawn/api/plugin/PluginLoader.java | 5 +-- .../orespawn/data/ReplacementsRegistry.java | 3 -- .../features/DefaultFeatureGenerator.java | 1 - .../orespawn/json/OreSpawnReader.java | 5 ++- .../orespawn/worldgen/OreSpawnWorldGen.java | 3 +- 8 files changed, 32 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index 1ac080db..404dcf7d 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,13 @@ def corePlugin = '' buildscript { repositories { jcenter() +// maven { +// url 'http://maven.aliyun.com/nexus/content/groups/public/' +// } + +// maven { +// url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' +// } maven { name = 'forge' url = 'http://files.minecraftforge.net/maven' diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 8e85600f..73a90312 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -49,7 +49,7 @@ public class OreSpawn { @Instance public static OreSpawn instance; - public static final Logger LOGGER = LogManager.getFormatterLogger(Constants.MODID); + public static final Logger LOGGER = LogManager.getLogger(Constants.MODID); public static final OS3API API = new OS3APIImpl(); static final EventHandlers eventHandlers = new EventHandlers(); public static final FeatureRegistry FEATURES = new FeatureRegistry(); diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 9fb97aaf..8712d89c 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -74,7 +74,7 @@ protected boolean spawn(final IBlockState oreBlock, final World world, final Blo final BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + OreSpawn.LOGGER.warn("Asked to spawn {} above build limit at {}", oreBlock, coord); return false; } @@ -95,17 +95,20 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { - int m_x = coord.getX() - 1; - int p_x = coord.getX() + 1; - int x = coord.getX(); - int m_z = coord.getZ() - 1; - int p_z = coord.getZ() + 1; - int z = coord.getZ(); - int min_x = (((int)(x/16))*16)+1; // convert to ChunkPos - int max_x = min_x+30; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks - int min_z = (((int)(z/16))*16)+1; // convert to ChunkPos - int max_z = min_z+30; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks - if(m_x <= min_x || p_x >= max_x || m_z <= min_z || p_z >= max_z) { + int m_x = coord.getX(); + int p_x = coord.getX(); + int m_z = coord.getZ(); + int p_z = coord.getZ(); + int min_x = world.getChunk(coord).getPos().getXStart()+1; // convert to ChunkPos + int max_x = world.getChunk(coord).getPos().getXEnd()+15; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int min_z = world.getChunk(coord).getPos().getZStart()+1; // convert to ChunkPos + int max_z = world.getChunk(coord).getPos().getZEnd()+15; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + boolean x_bad = false; + boolean z_bad = false; + if(m_x < min_x || p_x > max_x) x_bad = true; + if(m_z < min_z || p_z > max_z) z_bad = true; + + if(x_bad || z_bad) { if(cacheOverflow) { cacheOverflowBlock(oreBlock, coord, dimension); return true; @@ -145,7 +148,7 @@ private void spawnNoCheck(final IBlockState oreBlock, final World world, final B final BlockPos np = mungeFixYcoord(coord); if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn %s above build limit at %s", oreBlock, coord); + OreSpawn.LOGGER.warn("Asked to spawn {} above build limit at {}", oreBlock, coord); return; } @@ -154,7 +157,7 @@ private void spawnNoCheck(final IBlockState oreBlock, final World world, final B private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, final int dimension) { - final Vec3i chunkCoord = new Vec3i(coord.getX() >> 4, coord.getY() >> 4, dimension); + final Vec3i chunkCoord = new Vec3i(coord.getX() / 16, coord.getY() / 16, dimension); if (overflowCache.containsKey(chunkCoord)) { cacheOrder.addLast(chunkCoord); diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index f18cb3b1..7af04f40 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -68,6 +68,7 @@ public void load(final FMLPreInitializationEvent event) { try { integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); final PluginData pd = new PluginData(modId, resourceBase, integration); + OreSpawn.LOGGER.fatal("Loading Integration For {}", modId); dataStore.add(pd); } catch (final Exception ex) { OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); @@ -89,9 +90,9 @@ public void scanResources(final PluginData pd) { final String base = String.format(Locale.ENGLISH, "assets/%s/%s", pd.modId, pd.resourcePath); final URL resURL = getClass().getClassLoader().getResource(base); - + if (resURL == null) { - OreSpawn.LOGGER.warn("Unable to access file %s: got 'null' when trying to resolve it", + OreSpawn.LOGGER.warn("Unable to access file {}: got 'null' when trying to resolve it", base); return; } diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index deaf42c1..31dd1a08 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -150,7 +150,6 @@ public void loadFile(final Path file) { JsonObject elements; String rawJson; - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading file %s", file); try { rawJson = FileUtils.readFileToString(file.toFile(), Charset.defaultCharset()); @@ -167,8 +166,6 @@ public void loadFile(final Path file) { final String entName = elem.getKey(); final JsonArray entries = elem.getValue().getAsJsonArray(); final List blocks = new LinkedList<>(); - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Loading replacement entry %s", entName); -// for (final JsonElement e : entries) { entries.forEach( e -> { final JsonObject asObj = e.getAsJsonObject(); final String blockName = asObj.get(Constants.ConfigNames.NAME).getAsString() diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java index 9db89710..1447166a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java @@ -60,7 +60,6 @@ public void generate(final World world, final IChunkGenerator chunkGenerator, } else { r = 0; } - spawnOre(world, spawnData, new BlockPos(x, y, z), size + r); } } else if (random.nextFloat() < freq) { diff --git a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java index efc71710..8d30a8b0 100644 --- a/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java +++ b/src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java @@ -178,7 +178,6 @@ private static void loadSingleEntry(final Entry entry) final ISpawnBuilder sb = OreSpawn.API.getSpawnBuilder(); final IFeatureBuilder fb = OreSpawn.API.getFeatureBuilder(); sb.setName(entry.getKey()); - for (final Entry ent : entry.getValue().getAsJsonObject().entrySet()) { switch (ent.getKey()) { case Constants.ConfigNames.RETROGEN: @@ -267,7 +266,7 @@ private static void loadBlocks(ISpawnBuilder sb, Entry ent) sb.addBlock(block.create()); } else { OreSpawn.LOGGER.error( - "Skipping value %s in blocks list as it is not the correct format", + "Skipping value {} in blocks list as it is not the correct format", elem.toString()); } } @@ -293,7 +292,7 @@ private static void loadReplacements(IReplacementBuilder rb, Entry !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, + .forEach(spawn -> + spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); } } From 28293e0f916a2303cb0741cedcff3450b35d2be8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 27 Mar 2019 21:01:44 -0400 Subject: [PATCH 084/205] fix up the changelog --- CHANGELOG.txt | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 27993542..5bb9658a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,12 +1,8 @@ -Version 3.3.0 +Version 3.3.1 -* Rewrite the internal API to be a little more flexible -* Rewrite the loading and saving of the JSON configs - the current form is less flexible but will be easier to extend or replace in the future -* Fix the Dimension and Biome blacklist/whitelist code -* Fix the "zombie holes" issue that cropped up if a block was present in a config but not actually present in the game -* Change the default feature's (features-default.json in previous versions) to be defined in the _features.json in orespawn instead of programatically -* Change the default replacements (replacements-default.json in previous versions) to be defined in _replacements.json in orespawn instead of programatically -* Define the actual format of the replacements files -* fully define the format of the presets files (need to add, I believe, an _presets.json) -* remove any loading of any format of config other than those tagged as being version 2.0 (this capability will return at a later date) -* Fix the Dimension blacklist/whitelist code to make it actually work (there was a missing conditional in the DimensionBuilder create() method) +* Cascading World Gen Lag issues that were known have been resolved +* Vein generator has been fixed to work properly +* Underfluid generator has been stubbed out and is in testing +* Various minor bugs fixed +* Some small performance improvements +* Most Current Release (something like build 169 or 170) fixes a logic error that saw the system refusing to spawn in any chunk with a negative X or Y coordinate. From a721d98ee89fed051a2f4e6705b3aa2b35dd045b Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Fri, 19 Apr 2019 02:53:32 -0400 Subject: [PATCH 085/205] fix a possible source of a CME that has been crashing the test server - now getting some cascading gen lag, but seems to trigger on spawns next to lava and nothing is resolving this --- .../com/mcmoddev/orespawn/EventHandlers.java | 30 ++++++++++++------- .../mcmoddev/orespawn/api/FeatureBase.java | 8 ++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 3510935d..05d8356d 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -2,7 +2,6 @@ import java.util.Arrays; import java.util.Deque; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Random; @@ -190,10 +189,13 @@ private static void setupData(final World nw) { } - private void runBits(final Tuple> tup) { + private void runBits(final Tuple> tup, World world) { final ChunkPos p = tup.getFirst(); final List spawns = tup.getSecond(); - + if(!world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { + chunks.add(tup); + return; + } // re-seed with something totally new :P random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); @@ -210,16 +212,24 @@ public void worldTick(final WorldTickEvent ev) { } if (ev.phase == Phase.END) { - final Deque>> b = new LinkedList<>(); - for (int c = 0; c < 25 && !chunks.isEmpty(); c++) { - b.push(chunks.pop()); + for (int c = 0; c < 13 && !chunks.isEmpty(); c++) { + Tuple> pp = chunks.pop(); + if(ev.world.isBlockLoaded(new BlockPos(pp.getFirst().getXStart(), 128, pp.getFirst().getZStart()))) { + runBits(pp, ev.world); + } else { + chunks.add(pp); + c--; + } } - b.forEach(this::runBits); - - for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) { + for (int c = 0; c < 13 && !retroChunks.isEmpty(); c++) { final ChunkPos p = retroChunks.pop(); - OreSpawn.flatBedrock.retrogen(world, p.x, p.z); + if(ev.world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { + OreSpawn.flatBedrock.retrogen(world, p.x, p.z); + } else { + c--; + retroChunks.add(p); + } } } } diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 8712d89c..070acbaa 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -99,10 +99,10 @@ private boolean spawnOrCache(final World world, final BlockPos coord, int p_x = coord.getX(); int m_z = coord.getZ(); int p_z = coord.getZ(); - int min_x = world.getChunk(coord).getPos().getXStart()+1; // convert to ChunkPos - int max_x = world.getChunk(coord).getPos().getXEnd()+15; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks - int min_z = world.getChunk(coord).getPos().getZStart()+1; // convert to ChunkPos - int max_z = world.getChunk(coord).getPos().getZEnd()+15; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int min_x = world.getChunk(coord).getPos().getXStart()+8; // convert to ChunkPos + int max_x = world.getChunk(coord).getPos().getXEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int min_z = world.getChunk(coord).getPos().getZStart()+8; // convert to ChunkPos + int max_z = world.getChunk(coord).getPos().getZEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks boolean x_bad = false; boolean z_bad = false; if(m_x < min_x || p_x > max_x) x_bad = true; From 545a6b96fa7126a9c93b0adf5353f75a0ceacc5c Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Fri, 19 Apr 2019 10:19:40 -0400 Subject: [PATCH 086/205] changing the amount of work done per tick did not fix the issue and we shouldn't be calling world.getChunk() so often - and lets do it of smart thinking here... --- .../java/com/mcmoddev/orespawn/EventHandlers.java | 4 ++-- .../java/com/mcmoddev/orespawn/api/FeatureBase.java | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 05d8356d..16f5cb9c 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -212,7 +212,7 @@ public void worldTick(final WorldTickEvent ev) { } if (ev.phase == Phase.END) { - for (int c = 0; c < 13 && !chunks.isEmpty(); c++) { + for (int c = 0; c < 25 && !chunks.isEmpty(); c++) { Tuple> pp = chunks.pop(); if(ev.world.isBlockLoaded(new BlockPos(pp.getFirst().getXStart(), 128, pp.getFirst().getZStart()))) { runBits(pp, ev.world); @@ -222,7 +222,7 @@ public void worldTick(final WorldTickEvent ev) { } } - for (int c = 0; c < 13 && !retroChunks.isEmpty(); c++) { + for (int c = 0; c < 25 && !retroChunks.isEmpty(); c++) { final ChunkPos p = retroChunks.pop(); if(ev.world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { OreSpawn.flatBedrock.retrogen(world, p.x, p.z); diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 070acbaa..d3091713 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -16,6 +16,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3i; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; @@ -99,10 +100,12 @@ private boolean spawnOrCache(final World world, final BlockPos coord, int p_x = coord.getX(); int m_z = coord.getZ(); int p_z = coord.getZ(); - int min_x = world.getChunk(coord).getPos().getXStart()+8; // convert to ChunkPos - int max_x = world.getChunk(coord).getPos().getXEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks - int min_z = world.getChunk(coord).getPos().getZStart()+8; // convert to ChunkPos - int max_z = world.getChunk(coord).getPos().getZEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + ChunkPos chunkLoc = world.getChunk(coord).getPos(); + ChunkPos endLoc = new ChunkPos(chunkLoc.x+1, chunkLoc.z+1); + int min_x = chunkLoc.getXStart()+8; // convert to ChunkPos + int max_x = endLoc.getXStart()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int min_z = chunkLoc.getZStart()+8; // convert to ChunkPos + int max_z = endLoc.getXEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks boolean x_bad = false; boolean z_bad = false; if(m_x < min_x || p_x > max_x) x_bad = true; From 7e6d0db3627baf1efda2e662fa6d5c467332e91f Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Fri, 19 Apr 2019 12:13:17 -0400 Subject: [PATCH 087/205] forgot to hit 'save' before the last commit, dammit... --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index d3091713..4acb4626 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -105,7 +105,7 @@ private boolean spawnOrCache(final World world, final BlockPos coord, int min_x = chunkLoc.getXStart()+8; // convert to ChunkPos int max_x = endLoc.getXStart()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks int min_z = chunkLoc.getZStart()+8; // convert to ChunkPos - int max_z = endLoc.getXEnd()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks + int max_z = endLoc.getZStart()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks boolean x_bad = false; boolean z_bad = false; if(m_x < min_x || p_x > max_x) x_bad = true; From b2a741adbd8ef2e7840f584af0a5f8cc272c66c1 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 23 Apr 2019 02:58:14 -0400 Subject: [PATCH 088/205] fix the infinite loop issue caused by a dumbass programmer (me) assuming that Java did strict pass-by-reference and thus always had output parameters --- .../impl/features/ClusterGenerator.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java index e16435f5..e6b8d542 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java @@ -153,9 +153,25 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); scramble(scrambledLUT, this.random); int z = 0; - + while (count > 0) { - trySpawnInner(spawnData, world, pos, dimension, count, z, offs, scrambledLUT); + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; + + if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, + spawnData)) { + count++; + z++; + scramble(scrambledLUT, this.random); // rescramble the LUT + } else { + z = 0; + } + + if (z > 5) { + count--; + z = 0; + OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); + } } return; @@ -164,26 +180,6 @@ private void spawnChunk(final World world, final BlockPos pos, final ISpawnEntry doSpawnFill(this.random.nextBoolean(), count, spawnData, world, pos); } - private void trySpawnInner(ISpawnEntry spawnData, World world, BlockPos pos, - int dimension, int count, int z, Vec3i[] offs, int[] scrambledLUT) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - - if (!spawn(oreBlock, world, pos.add(offs[scrambledLUT[--count]]), dimension, true, - spawnData)) { - count++; - z++; - } else { - z = 0; - } - - if (z > 5) { - count--; - z = 0; - OreSpawn.LOGGER.warn("Unable to place block for chunk after 5 tries"); - } - } - private void doSpawnFill(final boolean nextBoolean, final int quantity, final ISpawnEntry spawnData, final World world, final BlockPos pos) { final int count = quantity; From 546ca1cfe7fca469a423bd2e9502a4acf49df33f Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Wed, 24 Apr 2019 23:25:42 -0400 Subject: [PATCH 089/205] Java doesn't have unsigned integers, dummy! Stop using %u where you actually mean to use %d --- src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java index 6cf6fc58..7bc3f62d 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java @@ -154,7 +154,7 @@ public IBlockBuilder setFromNameWithChance(final ResourceLocation blockResourceL chance); } catch (BadStateValueException e) { StringBuilder p = new StringBuilder(); - for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%u)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); + for(StackTraceElement elem: e.getStackTrace()) p.append(String.format("%s.%s (%s:%d)\n", elem.getClassName(), elem.getMethodName(), elem.getFileName(), elem.getLineNumber())); OreSpawn.LOGGER.error(String.format("Exception: %s\n%s", e.getMessage(), p.toString())); return this; } From 96f2f6a71e5e2ccbfbbc9559b31b1db12165145e Mon Sep 17 00:00:00 2001 From: Kilobyte22 Date: Tue, 18 Jun 2019 22:46:35 +0200 Subject: [PATCH 090/205] Fix Server Thread hanging with retrogen when less than 25 chunks need to be retrogenned, the tickHandler becomes effectively an infinite loop. This adds an additional check to catch that case --- src/main/java/com/mcmoddev/orespawn/EventHandlers.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 16f5cb9c..c2194dfb 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -212,6 +212,7 @@ public void worldTick(final WorldTickEvent ev) { } if (ev.phase == Phase.END) { + int chunkCount = chunks.size(); for (int c = 0; c < 25 && !chunks.isEmpty(); c++) { Tuple> pp = chunks.pop(); if(ev.world.isBlockLoaded(new BlockPos(pp.getFirst().getXStart(), 128, pp.getFirst().getZStart()))) { @@ -220,8 +221,13 @@ public void worldTick(final WorldTickEvent ev) { chunks.add(pp); c--; } + chunkCount--; + if (chunkCount <= 0) { + break; + } } + chunkCount = retroChunks.size(); for (int c = 0; c < 25 && !retroChunks.isEmpty(); c++) { final ChunkPos p = retroChunks.pop(); if(ev.world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { @@ -230,6 +236,10 @@ public void worldTick(final WorldTickEvent ev) { c--; retroChunks.add(p); } + chunkCount--; + if (chunkCount <= 0) { + break; + } } } } From e1b848156bda42fe0b1cd19d2163818e2f604806 Mon Sep 17 00:00:00 2001 From: proxyneko Date: Sat, 5 Oct 2019 02:18:23 +0100 Subject: [PATCH 091/205] Added some fancy shields. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 19ce6c43..9688f5dd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +[![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) +[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](http://minecraft.curseforge.com/projects/mmd-orespawn) +[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](http://minecraft.curseforge.com/projects/mmd-orespawn) +[![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) + # OreSpawn Minecraft library mod that provides better control over the spawning of ores in Minecraft. 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. From ff0380034599fa85f52fd6bf1c221e5450e57525 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Mon, 14 Oct 2019 15:13:28 -0700 Subject: [PATCH 092/205] Update .travis.yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4553e94c..342b0304 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +dist: trusty language: java sudo: false cache: From 73cc5f1df1a0c66609dcc8842cabeed60e37f0e0 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sat, 1 Feb 2020 21:46:25 -0500 Subject: [PATCH 093/205] fix a crash in an exception handler --- .../java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 4 ++-- .../orespawn/impl/features/DefaultFeatureGenerator.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 31dd1a08..3b37be96 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -205,8 +205,8 @@ private void loadBlockState(String blockName, JsonObject asObj, List 0) { final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; From 526aea6c0e9ca839bb721510c19bc1419f45e50a Mon Sep 17 00:00:00 2001 From: Bruno Miguel Faria Gaspar Date: Mon, 24 Feb 2020 08:21:24 +0000 Subject: [PATCH 094/205] Update CurseForge project links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9688f5dd..63a51fc0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) -[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](http://minecraft.curseforge.com/projects/mmd-orespawn) -[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](http://minecraft.curseforge.com/projects/mmd-orespawn) +[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) +[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) [![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) # OreSpawn From 60093093ba9e5a3c55750236407439e456a02420 Mon Sep 17 00:00:00 2001 From: Bruno Miguel Faria Gaspar Date: Mon, 24 Feb 2020 08:31:06 +0000 Subject: [PATCH 095/205] Update CurseForge Badges --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63a51fc0..26f6f44a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) -[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) -[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) +[![](https://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) +[![](https://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) [![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) # OreSpawn From 260b9b853d7fa5ac16f23ed7c3475a9d3a20fc40 Mon Sep 17 00:00:00 2001 From: Bruno Miguel Faria Gaspar Date: Mon, 24 Feb 2020 08:36:44 +0000 Subject: [PATCH 096/205] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 26f6f44a..63a51fc0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) -[![](https://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) -[![](https://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) +[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) +[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) [![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) # OreSpawn From 57be6fcf1e65c319e7f555acd0e92081b7f67f73 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Thu, 26 Mar 2020 16:59:27 -0400 Subject: [PATCH 097/205] minor style nit, totally pointless --- .../java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java index e80076e2..94d5e05c 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java @@ -24,8 +24,7 @@ public void generate(final Random random, final int chunkX, final int chunkZ, fi OreSpawn.API.getSpawns(thisDim).stream().filter(ISpawnEntry::isEnabled) .filter(sb -> !Config.getBoolean(Constants.RETROGEN_KEY) || (sb.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY))) - .forEach(spawn -> - spawn.generate(random, world, chunkGenerator, chunkProvider, + .forEach(spawn -> spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ))); } } From 61c95b9afbd2f43e11727de514d2eeac28bb9053 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 17 Apr 2020 10:25:43 -0700 Subject: [PATCH 098/205] Fix cascading worldgen bug Hopefully finally --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 4acb4626..a4004399 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -128,7 +128,7 @@ private boolean spawnOrCache(final World world, final BlockPos coord, if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { // don't send block update, send to client, don't re-render, observers don't see the change - world.setBlockState(coord, oreBlock, 0x22); + world.setBlockState(coord, oreBlock, 0x16); return true; } else { return false; From 8fea5eabc110d9b2a5a3ba9c4efb309f196bc94c Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Wed, 3 Jun 2020 18:40:25 -0700 Subject: [PATCH 099/205] Create .editorconfig --- .editorconfig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..7c2ae4c0 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.java] +charset = utf-8 +indent_style = tab +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false From 8f2003c38844a1ef1742fbf6e3ed6d908ba5f609 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Wed, 3 Jun 2020 18:42:29 -0700 Subject: [PATCH 100/205] Update build.gradle --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 404dcf7d..aa37f0ee 100644 --- a/build.gradle +++ b/build.gradle @@ -25,8 +25,8 @@ buildscript { } dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.0.11' - classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2' + classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0' + classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0' } } From 4234ca08155cae26495018d97e4cf0822c08fb79 Mon Sep 17 00:00:00 2001 From: SkyBlade1978 Date: Wed, 5 May 2021 10:09:35 +0200 Subject: [PATCH 101/205] removing hard coded mineralogy compatibility (which doesn't work anyway), mineralogy will provide it's own OS3 integration --- .../com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 3b37be96..62010ede 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -29,6 +29,7 @@ import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; +import akka.event.Logging.Debug; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.crash.CrashReport; @@ -69,12 +70,8 @@ public List getDimensionDefault(final int dimension) { final String[] names = { "minecraft:netherrack", "minecraft:stone", "minecraft:end_stone" }; - final List mineralogyOres = OreDictionary.getOres("cobblestone").stream() - .filter(iS -> iS.getItem().getRegistryName().getNamespace().equals("mineralogy")) - .map(iS -> Block.getBlockFromItem(iS.getItem()).getStateFromMeta(iS.getMetadata())) - .collect(Collectors.toList()); + final List baseRv = new ArrayList<>(); - baseRv.addAll(mineralogyOres); if (dimension < -1 || dimension > 1 || dimension == 0) { for (final ItemStack iS : OreDictionary.getOres("stone")) { From 1225a36dd5a7a03f1c0850494f88912c43c263dc Mon Sep 17 00:00:00 2001 From: SkyBlade1978 Date: Wed, 5 May 2021 10:12:48 +0200 Subject: [PATCH 102/205] removed unused imports --- .../java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 62010ede..78e25a55 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -14,8 +14,6 @@ import java.util.Locale; import java.util.Map; import java.util.TreeMap; -import java.util.stream.Collectors; - import org.apache.commons.io.FileUtils; import com.google.common.collect.ImmutableMap; @@ -29,7 +27,6 @@ import com.mcmoddev.orespawn.impl.os3.ReplacementEntry; import com.mcmoddev.orespawn.util.StateUtil; -import akka.event.Logging.Debug; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.crash.CrashReport; From f8beffe2f79d7c18484d33fa3c207e3858a61471 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 11 May 2021 14:11:18 -0400 Subject: [PATCH 103/205] make it so that it merges entries instead of replacing them --- .../com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 78e25a55..09af60a1 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -185,7 +185,12 @@ public void loadFile(final Path file) { } }); - final IReplacementEntry replacer = new ReplacementEntry("orespawn:" + entName, blocks); + ResourceLocation checkName= new ResourceLocation("orespawn", entName); + if (registry.containsKey(checkName)) { + List existingReps = getReplacement(checkName.toString()).getEntries(); + blocks.addAll(existingReps); + } + final IReplacementEntry replacer = new ReplacementEntry(checkName.toString(), blocks); registry.register(replacer); }); } From 3f5f7c2cd7dd81ee4e7ea36ee673ff02a8270e0f Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 11 May 2021 14:33:30 -0400 Subject: [PATCH 104/205] add a couple finals to fix style issues --- .../java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java index 09af60a1..657ae613 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java +++ b/src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java @@ -185,9 +185,9 @@ public void loadFile(final Path file) { } }); - ResourceLocation checkName= new ResourceLocation("orespawn", entName); + final ResourceLocation checkName= new ResourceLocation("orespawn", entName); if (registry.containsKey(checkName)) { - List existingReps = getReplacement(checkName.toString()).getEntries(); + final List existingReps = getReplacement(checkName.toString()).getEntries(); blocks.addAll(existingReps); } final IReplacementEntry replacer = new ReplacementEntry(checkName.toString(), blocks); From 91901c77036bf1de55334648dae11be2f1e8be5c Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 11 May 2021 17:27:17 -0400 Subject: [PATCH 105/205] Refactor to split out to individual spawn generator calls. Preparation for the 1.16 port - this splits things so there is no longer a single "mega generator", instead we have a separate generator per spawn entry. Next step will be fixing some bits of the generators to get them hitting the chunk boundaries, as the last changes to halt cascading chunk gen caused a "gridding" of generation rather than a nice, clean generation. --- .../com/mcmoddev/orespawn/EventHandlers.java | 14 ++++++++++++-- .../java/com/mcmoddev/orespawn/OreSpawn.java | 19 +++++-------------- .../com/mcmoddev/orespawn/api/os3/OS3API.java | 5 +++++ .../orespawn/api/os3/OS3FeatureGenerator.java | 6 ++++++ .../orespawn/impl/os3/OS3APIImpl.java | 14 ++++++++++++++ 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index c2194dfb..7aa25df2 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -15,6 +15,7 @@ import com.google.common.collect.Maps; import com.mcmoddev.orespawn.data.Config; import com.mcmoddev.orespawn.data.Constants; +import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Tuple; @@ -189,6 +190,13 @@ private static void setupData(final World nw) { } + private OreSpawnFeatureGenerator findSpawn(final String spawnName) { + for (OreSpawnFeatureGenerator ofg : OreSpawn.API.getGenerators()) { + if (ofg.getSpawnName().matches(spawnName)) return ofg; + } + return null; + } + private void runBits(final Tuple> tup, World world) { final ChunkPos p = tup.getFirst(); final List spawns = tup.getSecond(); @@ -199,8 +207,10 @@ private void runBits(final Tuple> tup, World world) { // re-seed with something totally new :P random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed()); - spawns.stream().forEach(s -> OreSpawn.API.getSpawn(s).generate(random, world, - chunkGenerator, chunkProvider, p)); + spawns.stream().forEach(s -> { + OreSpawnFeatureGenerator feature = findSpawn(s); + if (feature != null) feature.generate(random, p.x, p.z, world, chunkGenerator, chunkProvider); + }); } @SubscribeEvent diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 73a90312..63dedea0 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -1,13 +1,8 @@ package com.mcmoddev.orespawn; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.mcmoddev.orespawn.api.os3.ISpawnBuilder; import com.mcmoddev.orespawn.api.os3.OS3API; import com.mcmoddev.orespawn.api.plugin.PluginLoader; import com.mcmoddev.orespawn.commands.AddOreCommand; @@ -19,7 +14,7 @@ import com.mcmoddev.orespawn.data.FeatureRegistry; import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; import com.mcmoddev.orespawn.worldgen.FlatBedrock; -import com.mcmoddev.orespawn.worldgen.OreSpawnWorldGen; +import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; @@ -53,14 +48,9 @@ public class OreSpawn { public static final OS3API API = new OS3APIImpl(); static final EventHandlers eventHandlers = new EventHandlers(); public static final FeatureRegistry FEATURES = new FeatureRegistry(); - protected static final Map> spawns = new HashMap<>(); static final FlatBedrock flatBedrock = new FlatBedrock(); - - public static Map> getSpawns() { - return spawns; - } - + @EventHandler public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { LOGGER.warn("Invalid fingerprint detected!"); @@ -76,8 +66,9 @@ public void preInit(final FMLPreInitializationEvent ev) { GameRegistry.registerWorldGenerator(flatBedrock, 100); } - GameRegistry.registerWorldGenerator(new OreSpawnWorldGen(), 100); - + API.getAllSpawns().entrySet().parallelStream() + .forEach(ent -> GameRegistry.registerWorldGenerator(new OreSpawnFeatureGenerator(ent.getValue(), ent.getKey()), 100)); + if (Config.getBoolean(Constants.RETROGEN_KEY) || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) || Config.getBoolean(Constants.RETRO_BEDROCK)) { diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java index aba87455..cc421f86 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java @@ -6,6 +6,7 @@ import com.mcmoddev.orespawn.api.IFeature; import com.mcmoddev.orespawn.data.PresetsStorage; +import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; import net.minecraft.block.state.IBlockState; import net.minecraft.util.ResourceLocation; @@ -63,4 +64,8 @@ public interface OS3API { List getSpawnsForFile(String fileName); Map> getSpawnsByFile(); + + void addGenerator(final OreSpawnFeatureGenerator generator); + + List getGenerators(); } diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java new file mode 100644 index 00000000..d803f9de --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java @@ -0,0 +1,6 @@ +package com.mcmoddev.orespawn.api.os3; + +public interface OS3FeatureGenerator { + public ISpawnEntry getSpawnData(); + public String getSpawnName(); +} diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java index 61516b72..83664879 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java @@ -7,6 +7,7 @@ import java.nio.file.PathMatcher; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -38,6 +39,7 @@ import com.mcmoddev.orespawn.data.PresetsStorage; import com.mcmoddev.orespawn.data.ReplacementsRegistry; import com.mcmoddev.orespawn.json.OreSpawnReader; +import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; import net.minecraft.block.state.IBlockState; import net.minecraft.crash.CrashReport; @@ -46,6 +48,7 @@ public class OS3APIImpl implements OS3API { private static final Map spawns; + private static final List generators; private static final FeatureRegistry features; private static final ReplacementsRegistry replacements; private static final PresetsStorage presets; @@ -57,6 +60,7 @@ public class OS3APIImpl implements OS3API { features = new FeatureRegistry(); replacements = new ReplacementsRegistry(); presets = new PresetsStorage(); + generators = new LinkedList<>(); } public OS3APIImpl() { @@ -115,6 +119,16 @@ public void loadConfigFiles() { } } + @Override + public void addGenerator(final OreSpawnFeatureGenerator generator) { + generators.add(generator); + } + + @Override + public List getGenerators() { + return new LinkedList(generators); + } + @Override public void addSpawn(final ISpawnEntry spawnEntry) { if (spawnEntry != null) { From 269008fc26919ba9744c8ff2d63af6f5d6fbe244 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 11 May 2021 17:49:57 -0400 Subject: [PATCH 106/205] f*cking bullshit, I know I added this originally. --- .../worldgen/OreSpawnFeatureGenerator.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java new file mode 100644 index 00000000..7cd4f313 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java @@ -0,0 +1,46 @@ +package com.mcmoddev.orespawn.worldgen; + +import java.util.Random; + +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.api.os3.OS3FeatureGenerator; +import com.mcmoddev.orespawn.data.Config; +import com.mcmoddev.orespawn.data.Constants; + +import net.minecraft.world.World; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; +import net.minecraftforge.fml.common.IWorldGenerator; +import net.minecraft.util.math.ChunkPos; + +public class OreSpawnFeatureGenerator implements IWorldGenerator, OS3FeatureGenerator { + private final ISpawnEntry spawn; + private final String name; + + public OreSpawnFeatureGenerator( final ISpawnEntry spawn, final String name ) { + this.spawn = spawn; + this.name = name; + } + + @Override + public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, + IChunkProvider chunkProvider) { + final int thisDim = world.provider.getDimension(); + + if (((!Config.getBoolean(Constants.RETROGEN_KEY) && + (this.spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)))) && + this.spawn.isEnabled() && this.spawn.dimensionAllowed(thisDim)) { + this.spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); + } + } + + @Override + public ISpawnEntry getSpawnData() { + return this.spawn; + } + + @Override + public String getSpawnName() { + return this.name; + } +} From 4d6afcc6d1a94da3a28998a99b40a6d205360d20 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Tue, 11 May 2021 19:43:17 -0400 Subject: [PATCH 107/205] undo the idiocy of the last, really horrid attempt at fixing CWG --- .../com/mcmoddev/orespawn/api/FeatureBase.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index a4004399..5b067d60 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -96,20 +96,12 @@ private boolean spawnOrCache(final World world, final BlockPos coord, final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { if (world.isBlockLoaded(coord)) { - int m_x = coord.getX(); - int p_x = coord.getX(); - int m_z = coord.getZ(); - int p_z = coord.getZ(); - ChunkPos chunkLoc = world.getChunk(coord).getPos(); - ChunkPos endLoc = new ChunkPos(chunkLoc.x+1, chunkLoc.z+1); - int min_x = chunkLoc.getXStart()+8; // convert to ChunkPos - int max_x = endLoc.getXStart()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks - int min_z = chunkLoc.getZStart()+8; // convert to ChunkPos - int max_z = endLoc.getZStart()+8; // two chunks plus is 32 blocks, we are starting 1 block in and running to 1 block shy, thats 30 blocks boolean x_bad = false; boolean z_bad = false; - if(m_x < min_x || p_x > max_x) x_bad = true; - if(m_z < min_z || p_z > max_z) z_bad = true; + ChunkPos start = world.getChunk(coord).getPos(); + ChunkPos end = new ChunkPos(start.x+1, start.z+1); + if (coord.getX() < start.getXStart() || coord.getX() > end.getXEnd()) x_bad = true; + if (coord.getZ() < start.getZStart() || coord.getZ() > end.getZEnd()) z_bad = true; if(x_bad || z_bad) { if(cacheOverflow) { From ea49f9454c30afb86f21654472f7bc6310ff2567 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Mon, 31 May 2021 20:07:50 -0400 Subject: [PATCH 108/205] Fix the "nothing generates" issue caused by the wolf making two idiotic mistakes: 1) Trying to register the generators with Minecraft before the configurations were loaded 2) Messing up the conditional guard checking if the spawn was allowed to generate --- src/main/java/com/mcmoddev/orespawn/OreSpawn.java | 7 ++++--- .../orespawn/worldgen/OreSpawnFeatureGenerator.java | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 63dedea0..f0c6bad2 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -65,9 +65,6 @@ public void preInit(final FMLPreInitializationEvent ev) { if (Config.getBoolean(Constants.FLAT_BEDROCK)) { GameRegistry.registerWorldGenerator(flatBedrock, 100); } - - API.getAllSpawns().entrySet().parallelStream() - .forEach(ent -> GameRegistry.registerWorldGenerator(new OreSpawnFeatureGenerator(ent.getValue(), ent.getKey()), 100)); if (Config.getBoolean(Constants.RETROGEN_KEY) || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) @@ -87,6 +84,10 @@ public void init(final FMLInitializationEvent ev) { @EventHandler public void postInit(final FMLPostInitializationEvent ev) { Config.saveConfig(); + API.getAllSpawns().entrySet().stream() + .forEach(ent -> { + GameRegistry.registerWorldGenerator(new OreSpawnFeatureGenerator(ent.getValue(), ent.getKey()), 100); + }); } @EventHandler diff --git a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java index 7cd4f313..a650109b 100644 --- a/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java +++ b/src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java @@ -27,9 +27,9 @@ public void generate(Random random, int chunkX, int chunkZ, World world, IChunkG IChunkProvider chunkProvider) { final int thisDim = world.provider.getDimension(); - if (((!Config.getBoolean(Constants.RETROGEN_KEY) && - (this.spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)))) && - this.spawn.isEnabled() && this.spawn.dimensionAllowed(thisDim)) { + if ((Config.getBoolean(Constants.RETROGEN_KEY) && + ((this.spawn.isRetrogen() || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)))) || + (this.spawn.isEnabled() && this.spawn.dimensionAllowed(thisDim))) { this.spawn.generate(random, world, chunkGenerator, chunkProvider, new ChunkPos(chunkX, chunkZ)); } } From c4334ecfaa6f888be01a7da45cc0266f990a499f Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sat, 5 Jun 2021 21:05:33 -0400 Subject: [PATCH 109/205] Add a feature where we try to override ***ALL*** ore spawns - local test shows it will still allow itself. --- src/main/java/com/mcmoddev/orespawn/data/Config.java | 1 + src/main/java/com/mcmoddev/orespawn/data/Constants.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/data/Config.java b/src/main/java/com/mcmoddev/orespawn/data/Config.java index 08ba58c7..7f4f2c5d 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Config.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Config.java @@ -48,6 +48,7 @@ public static void loadConfig() { false, "Flatten the bedrock during world generation")); boolVals.put(Constants.RETRO_BEDROCK, configuration.getBoolean(Constants.RETRO_BEDROCK, Configuration.CATEGORY_GENERAL, false, "Retroactively flatten bedrock")); + boolVals.put(Constants.REPLACE_ALL, configuration.getBoolean(Constants.REPLACE_ALL, Configuration.CATEGORY_GENERAL, false, "Replace all ore generation")); intVals.put(Constants.BEDROCK_LAYERS, configuration.getInt(Constants.BEDROCK_LAYERS, Configuration.CATEGORY_GENERAL, 1, 1, 4, "How thick should the shell of bedrock be?")); diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index fd09c998..5509dde3 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -35,6 +35,7 @@ public class Constants { public static final String PRECISION = "precision"; public static final Path CONFDIR = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3); public static final Path SYSCONF = Paths.get(FileBits.CONFIG_DIR, FileBits.OS3, FileBits.SYSCONF); + public static final String REPLACE_ALL = "Replace All Generation"; public final class FormatBits { From ddd062ace25cf59842e57680ece77c8b5069d4e8 Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sat, 5 Jun 2021 21:13:11 -0400 Subject: [PATCH 110/205] %^&*$^&%$&^ Eclipse didn't save when I hit the button. Save the file and get the option implemented. It does work. --- src/main/java/com/mcmoddev/orespawn/EventHandlers.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java index 7aa25df2..bcaaadfd 100644 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java @@ -28,6 +28,7 @@ import net.minecraftforge.event.terraingen.OreGenEvent; import net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType; import net.minecraftforge.event.world.ChunkDataEvent; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.eventhandler.EventPriority; @@ -57,6 +58,8 @@ public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) && vanillaEvents.contains(event.getType())) { event.setResult(Event.Result.DENY); + } else if(Config.getBoolean(Constants.REPLACE_ALL) && !Loader.instance().activeModContainer().getModId().equals("orespawn")) { + event.setResult(Event.Result.DENY); } } From d2e6d74cd3f2198d0a38f9dc2902c4ced519d8ec Mon Sep 17 00:00:00 2001 From: Daniel Hazelton Date: Sun, 20 Jun 2021 12:47:20 -0400 Subject: [PATCH 111/205] update the SpawnBuilder to be a bit more intelligent --- .../java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 1d31dacb..2d9dac8a 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -215,6 +215,13 @@ public ISpawnBuilder addBlock(final IBlockDefinition block) { @Override public SpawnEntry create() { if (this.blocks.count() > 0) { + if (this.dimensions == null) this.dimensions = new DimensionBuilder().setAcceptAll().create(); + if (this.biomes == null) this.biomes = new BiomeBuilder().setAcceptAll().create(); + if (this.replacements == null) this.replacements = com.mcmoddev.orespawn.OreSpawn.API.getReplacement("default"); + if (this.feature == null) { + com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Spawn entry {} does not have a stated feature, ignoring.", this.spawnName); + return null; + } return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, this.biomes, this.replacements, this.blocks, this.feature); } else { From cbfa6127cbe3f0bb19985072c2c8ccf7b7c94791 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:16:44 -0400 Subject: [PATCH 112/205] Lock max supported mcversion to 1.12.2 --- src/main/java/com/mcmoddev/orespawn/OreSpawn.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index f0c6bad2..2f7061f1 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -36,7 +36,7 @@ @Mod(modid = Constants.MODID, name = Constants.NAME, version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,)", + acceptedMinecraftVersions = "[1.12,1.12.2]", certificateFingerprint = "@FINGERPRINT@") public class OreSpawn { From 682b8cd8096ad97557a91b79d4f42d311bc8da82 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:17:03 -0400 Subject: [PATCH 113/205] 1.12.x is pack format 3, not 2. --- src/main/resources/pack.mcmeta | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta index 6065f6d1..3b0a6228 100644 --- a/src/main/resources/pack.mcmeta +++ b/src/main/resources/pack.mcmeta @@ -1,6 +1,6 @@ { "pack":{ - "pack_format":2, - "description":"Ore Spawn" + "pack_format":3, + "description":"MMD OreSpawn" } } From afc1ca81b59b8e188bc65f65c0428c5639a0e562 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:17:15 -0400 Subject: [PATCH 114/205] Clarify mod name --- src/main/resources/mcmod.info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index c9bf0536..27d72329 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,7 +1,7 @@ [ { "modid": "orespawn", - "name": "OreSpawn", + "name": "MMD OreSpawn", "description": "A customizable ore-spawning system that uses JSON files to specify custom ore generation", "version": "${version}", "authorList": [ From 3c4388daae452908ab72bce6b3cc3ebb1eaa0454 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:17:41 -0400 Subject: [PATCH 115/205] Update version to 3.4.0 in preperation for release --- src/main/java/com/mcmoddev/orespawn/data/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/data/Constants.java b/src/main/java/com/mcmoddev/orespawn/data/Constants.java index 5509dde3..69cc5ff3 100644 --- a/src/main/java/com/mcmoddev/orespawn/data/Constants.java +++ b/src/main/java/com/mcmoddev/orespawn/data/Constants.java @@ -7,7 +7,7 @@ public class Constants { public static final String MODID = "orespawn"; public static final String NAME = "MMD OreSpawn"; - public static final String VERSION = "3.3.1"; + public static final String VERSION = "3.4.0"; public static final String RETROGEN_KEY = "Retrogen"; public static final String CONFIG_FILE = "config/orespawn.cfg"; public static final String FORCE_RETROGEN_KEY = "Force Retrogen"; From 7bf34c3eeaa9d1ebbc564c772e5b17ec8fd2955c Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:17:52 -0400 Subject: [PATCH 116/205] Update changelog --- CHANGELOG.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5bb9658a..f72e9673 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,8 +1,4 @@ Version 3.3.1 -* Cascading World Gen Lag issues that were known have been resolved -* Vein generator has been fixed to work properly -* Underfluid generator has been stubbed out and is in testing -* Various minor bugs fixed -* Some small performance improvements -* Most Current Release (something like build 169 or 170) fixes a logic error that saw the system refusing to spawn in any chunk with a negative X or Y coordinate. +* Fix several bugs +* Add ability to completely replace oregeneration (By popular request) From 0399381c3c4a5e8c5d352ada40c77623ae3743e8 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:18:15 -0400 Subject: [PATCH 117/205] Update forge maven location --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index aa37f0ee..3820a603 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { // } maven { name = 'forge' - url = 'http://files.minecraftforge.net/maven' + url = 'https://maven.minecraftforge.net' } maven { name = 'gradle' From 0a6cfab93befbae31328ce25addaf37ec8725716 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:18:34 -0400 Subject: [PATCH 118/205] Update sonarqube --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 3820a603..f85d89ef 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ buildscript { dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0' - classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0' + classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3' } } From 1437c02601a76a5be447f760282c6131a1698b28 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:19:05 -0400 Subject: [PATCH 119/205] Move mcmoddev maven to top of list --- build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index f85d89ef..a6a6ff15 100644 --- a/build.gradle +++ b/build.gradle @@ -85,6 +85,10 @@ minecraft { } repositories { + maven { + name 'MMD' + url 'https://maven.mcmoddev.com/' + } maven { // Mantle, TCon, JEI name 'DVS1 Maven FS' url 'http://dvs1.progwml6.com/files/maven' @@ -97,10 +101,6 @@ repositories { name 'tterrag' url 'http://maven.tterrag.com/' } - maven { - name 'MMD' - url 'https://maven.mcmoddev.com/' - } maven { // MCMultipart name 'amadornes' url 'http://maven.amadornes.com/' From 94c5665b721ba7a40ca779d2b5505ac3632f6c1e Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:19:29 -0400 Subject: [PATCH 120/205] Jcenter is dead, long live mavenCentral --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a6a6ff15..b90f12f5 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ def corePlugin = '' buildscript { repositories { - jcenter() + mavenCentral() // maven { // url 'http://maven.aliyun.com/nexus/content/groups/public/' // } @@ -85,6 +85,7 @@ minecraft { } repositories { + mavenCentral() maven { name 'MMD' url 'https://maven.mcmoddev.com/' From 0dee0d9ffeb29175388501422ec808450a0db8ce Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 22:19:57 -0400 Subject: [PATCH 121/205] Update forge to last FG2 compatible version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b90f12f5..06c57cde 100644 --- a/build.gradle +++ b/build.gradle @@ -75,7 +75,7 @@ if (secretFile.exists()) { } minecraft { - version = '1.12.2-14.23.5.2768' + version = '1.12.2-14.23.5.2847' runDir = 'run' mappings = 'stable_39' // coreMod = '' From 44e6d82ba859dc3ef787cee39c48021b75eee57b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 23:44:15 -0400 Subject: [PATCH 122/205] Update .travis.yml --- .travis.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 342b0304..dd5385bb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,29 @@ -dist: trusty language: java -sudo: false +os: linux +dist: trusty +addons: + apt: + update: true + packages: +# - oracle-java8-installer +git: + quiet: true +arch: amd64 +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ cache: directories: - - $HOME/.gradle + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ notifications: email: false jdk: - oraclejdk8 -before_install: +before_install: skip +install: skip +before_script: - chmod a+x gradlew -install: ./gradlew setupCIWorkspace -S -script: ./gradlew clean build -S +script: + - ./gradlew setupCIWorkspace -S + - ./gradlew clean build -S From 4595eeb5647903870560549b8d1c444065b8933b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 23:50:04 -0400 Subject: [PATCH 123/205] Add circleCI support --- .circleci/config.yml | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..237217aa --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,58 @@ +# Java Gradle CircleCI 2.0 Configuration file. +version: 2 +jobs: + build: + docker: + - image: circleci/openjdk:8-jdk + + working_directory: ~/repo + + environment: + JVM_OPTS: -Xmx3200m + TERM: dumb + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "build.gradle" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: Grant access to ./gradlew. + command: | + chmod +x gradlew + + - run: + name: Show the Gradle version in use with other details. + command: | + ./gradlew --version + + - run: + name: Set up the workspace for ci build + command: | + ./gradlew setupCiWorkspace + + - run: + name: Clean the workspace ready for a fresh build. + command: | + ./gradlew clean + + - run: + name: Attempt to build the mod. + command: | + ./gradlew build + + - store_artifacts: + path: ./build/libs + + - save_cache: + paths: + - ~/.gradle + key: v1-dependencies-{{ checksum "build.gradle" }} + + # run tests! + - run: ./gradlew test From 376e3a7987f39272fbb86b87aa7521633cefffeb Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Thu, 24 Jun 2021 23:50:19 -0400 Subject: [PATCH 124/205] Github actions --- .github/workflows/ci.yml | 24 +++++++ .github/workflows/codeql-analysis.yml | 73 +++++++++++++++++++++ .github/workflows/sonarqube.yml | 30 +++++++++ .github/workflows/validate-gradle-build.yml | 11 ++++ 4 files changed, 138 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/sonarqube.yml create mode 100644 .github/workflows/validate-gradle-build.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..72fbb317 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: CI + +on: [push, pull_request] +#on: +# push: +# branches: [ master-1.12 ] +# pull_request: +# # The branches below must be a subset of the branches above +# branches: [ master-1.12 ] +# types: [opened, synchronize, reopened] + +jobs: + build: + runs-on: ubuntu-latest + name: Build + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 8 + - run: chmod a+x gradlew + - run: ./gradlew --version --no-daemon + - run: ./gradlew setupCIWorkspace + - run: ./gradlew clean build diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..2b083168 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,73 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: [push, pull_request] +#on: +# push: +# branches: [ master-1.12 ] +# pull_request: +# # The branches below must be a subset of the branches above +# branches: [ master-1.12 ] +# types: [opened, synchronize, reopened] + schedule: + - cron: '43 7 * * 4' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # 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 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # â„¹ï¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœï¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml new file mode 100644 index 00000000..c9c52a54 --- /dev/null +++ b/.github/workflows/sonarqube.yml @@ -0,0 +1,30 @@ +on: [push, pull_request] +#on: +# push: +# branches: +# - master-1.12 +# pull_request: +# types: [opened, synchronize, reopened] +# +name: SonarCloud +jobs: + sonarcloud: + name: SonarCloud Scan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} +# SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + - name: SonarCloud Quality Gate check + uses: SonarSource/sonarqube-quality-gate-action@master + # Force to fail step after specific time + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/validate-gradle-build.yml b/.github/workflows/validate-gradle-build.yml new file mode 100644 index 00000000..528f4b5a --- /dev/null +++ b/.github/workflows/validate-gradle-build.yml @@ -0,0 +1,11 @@ +name: Validate Gradle Wrapper + +on: [push, pull_request] + +jobs: + validation: + name: "Validation" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: gradle/wrapper-validation-action@v1 From 728df12a5286a47ca115e87b26f292e966a9b20a Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:18:38 -0400 Subject: [PATCH 125/205] Add Jenkinsfile --- Jenkinsfile | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..859a0e31 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,128 @@ +pipeline { + agent any + environment { + GRADLE_OPTS = '-Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dorg.gradle.warning.mode=all' +// JAVA_OPTS = '' + } + options { + ansiColor('xterm') + } + tools { +// git 'Git' + gradle 'Gradle 4.9' + jdk 'oraclejdk8' + } + stages { + stage('prebuild') { + steps { + sh 'rm -rf build/libs' + sh 'chmod +x gradlew' + sh 'java -version' + sh 'gradle -version' + sh './gradlew -version' + sh 'export' + } + } + stage('CIWorkspace') { + steps { + withGradle { + sh './gradlew clean setupCiWorkspace' + } + } + } + stage('build') { + steps { + withGradle { + sh './gradlew build' + } + } + } + stage('test') { + steps { + withGradle { + sh './gradlew test' + } + } + } + stage('publish') { + steps { + withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { + withGradle { + sh './gradlew publish' + } + } + } + } + stage('CurseForge') { + steps { + withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { + withGradle { + sh './gradlew -x publish curseforge' + } + } + } + } + stage('SonarQube') { + tools { + jdk "oraclejdk11" + } + environment { + scannerHome = tool 'SonarQube' + } + steps { +// withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { +// withGradle { +// sh './gradlew sonarqube' +// } +// } + withSonarQubeEnv(installationName: 'SonarCloud', , envOnly: false) { + sh "${scannerHome}/bin/sonar-scanner -Dsonar.java.jdkHome=${JAVA_HOME}" + } + } + } + stage('postbuild') { + steps { + archiveArtifacts artifacts: 'build/libs/*.jar', followSymlinks: false + javadoc javadocDir: 'build/docs/javadoc', keepAll: false + fingerprint 'build/libs/*.zip' + junit allowEmptyResults: true, testResults: '**/build/test-results/junit-platform/*.xml' + jacoco classPattern: '**/build/classes/java', execPattern: '**/build/jacoco/**.exec', sourceInclusionPattern: '**/*.java', sourcePattern: '**/src/main/java' + findBuildScans() + recordIssues(tools: [java()]) + recordIssues(tools: [javaDoc()]) +// if (fileExists('')) { +// recordIssues(tools: [errorProne(pattern: 'ReportFilePattern', reportEncoding: 'UTF-8')]) +// } else { +// echo 'No ErrorProne report available' +// } + if (fileExists('**/build/reports/checkstyle/*.xml')) { + recordIssues(tools: [checkStyle(pattern: '**/build/reports/checkstyle/*.xml')]) + } else { + echo 'No CheckStyle report available' + } + if (fileExists('**/build/reports/pmd/*.xml')) { + recordIssues(tools: [pmdParser(pattern: '**/build/reports/pmd/*.xml')]) + } else { + echo 'No PMD report available' + } + if (fileExists('*/build/reports/findbugs/*.xml')) { + recordIssues(tools: [findBugs(pattern: '*/build/reports/findbugs/*.xml', useRankAsPriority: true)]) + } else { + echo 'No FindBugs report available' + } + } + when { expression { fileExists('**/build/reports/spotbugs/*.xml') } } + steps { + recordIssues(tools: [spotBugs(pattern: '**/build/reports/spotbugs/*.xml', useRankAsPriority: true)]) + } + when { expression { fileExists('**/build/test-results/junit-platform/*.xml') } } + steps { + recordIssues(tools: [junitParser(pattern: '**/build/test-results/junit-platform/*.xml')]) + } + when { expression { fileExists('**/sonar-report.json') } } + steps { + recordIssues(tools: [sonarQube(pattern: '**/sonar-report.json')]) + } + } + } +} From bb84372c55a545364458d381c60c151ae69da7bc Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:18:48 -0400 Subject: [PATCH 126/205] Update settings.gradle --- settings.gradle | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 0e64f4a2..f74c120a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,33 @@ +// Workaround to make the JUnit Platform Gradle Plugin available using the `plugins` DSL +// See https://github.com/junit-team/junit5/issues/768 +if (!(GradleVersion.current() <= GradleVersion.version('2.14.1'))) { +pluginManagement { + repositories { + gradlePluginPortal() + maven { url = ArtifactRepositoryContainer.MAVEN_CENTRAL_URL } + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == 'org.junit.platform.gradle.plugin') { + useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") +// } else if (requested.id.id == 'org.junit.platform.gradle.plugin') { +// useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") + } + } + } +} +} + rootProject.name = archivesBaseName -enableFeaturePreview('STABLE_PUBLISHING') +import org.gradle.util.GradleVersion +if ((GradleVersion.current() >= GradleVersion.version('4.8')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { + enableFeaturePreview('STABLE_PUBLISHING') // 4.10.3 +} + +// TODO: Things which likely don't work with FG yet, but I've not checked. +/* +if ((GradleVersion.current() >= GradleVersion.version('4.6')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { + enableFeaturePreview('IMPROVED_POM_SUPPORT') // Previously -Dorg.gradle.advancedpomsupport=true + enableFeaturePreview('GRADLE_METADATA') // Previously -Dorg.gradle.gradlemetadata=true +} +*/ From 4a4fe5741300e3a2ac57c6590a14022409109771 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:18:57 -0400 Subject: [PATCH 127/205] Create checkstyle.xml --- config/checkstyle.xml | 96 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 config/checkstyle.xml diff --git a/config/checkstyle.xml b/config/checkstyle.xml new file mode 100644 index 00000000..67eb300a --- /dev/null +++ b/config/checkstyle.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 156588efe773b8a201df28453d051a50a1b8c63e Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:19:02 -0400 Subject: [PATCH 128/205] Create changelog.mustache --- changelog.mustache | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 changelog.mustache diff --git a/changelog.mustache b/changelog.mustache new file mode 100644 index 00000000..076ba598 --- /dev/null +++ b/changelog.mustache @@ -0,0 +1,10 @@ +{{#tags}} + {{#issues}} + {{#commits}} +**{{{messageTitle}}}** +{{#messageBodyItems}} + * {{.}} +{{/messageBodyItems}} + {{/commits}} + {{/issues}} +{{/tags}} From 8d1d0ede894bb415475031b42b8fc5242ddf5af1 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:19:07 -0400 Subject: [PATCH 129/205] Update .gitignore --- .gitignore | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitignore b/.gitignore index 4fd03c87..a143318e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,17 @@ build # other eclipse run +classes +*.hprof /README.txt /forge-*-changelog.txt + +secret.json +libs/* +!/libs/README.txt + .DS_Store .DS_Store/* +.okhttpcache/* OS3 API Redesign Notes.txt From c6e8ec5d1a4fbbcdb6c6992ef207eac5873a0ffa Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:19:13 -0400 Subject: [PATCH 130/205] Create .gitattributes --- .gitattributes | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..84a0494e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,75 @@ +* text=auto + +*.bat text eol=crlf +#*.bat text eol=lf +*.gradle text diff=java +mcmod.info text +*.java text +*.json text +*.lang text +*.mcmeta text +*.md text +*.properties text +gradlew text eol=lf +*.sh text eol=lf +*.txt text +*.xml text +*.yml text +*.yaml text +*.toml text + +# Documents +*.pdf binary + +# Graphics +*.eps binary +*.gif binary +*.ico binary +*.jpg binary +*.jpeg binary +*.png binary +*.psd binary +# SVG treated as an asset (binary) by default. If you want to treat it as text, +# comment-out the following line and uncomment the line after. +*.svg binary +#*.svg text +*.tif binary +*.tiff binary +*.webp binary +*.xcf binary + +# Other +*.exe binary +*.jar binary + +############################### +# Git Large File System (LFS) # +############################### + +# Archives +#*.7z filter=lfs diff=lfs merge=lfs -text +#*.br filter=lfs diff=lfs merge=lfs -text +#*.bz2 filter=lfs diff=lfs merge=lfs -text +#*.gz filter=lfs diff=lfs merge=lfs -text +#*.tar filter=lfs diff=lfs merge=lfs -text +#*.zip filter=lfs diff=lfs merge=lfs -text + +# Documents +#*.pdf filter=lfs diff=lfs merge=lfs -text + +# Graphics +#*.eps filter=lfs diff=lfs merge=lfs -text +#*.gif filter=lfs diff=lfs merge=lfs -text +#*.ico filter=lfs diff=lfs merge=lfs -text +#*.jpg filter=lfs diff=lfs merge=lfs -text +#*.jpeg filter=lfs diff=lfs merge=lfs -text +#*.png filter=lfs diff=lfs merge=lfs -text +#*.psd filter=lfs diff=lfs merge=lfs -text +#*.tif filter=lfs diff=lfs merge=lfs -text +#*.tiff filter=lfs diff=lfs merge=lfs -text +#*.webp filter=lfs diff=lfs merge=lfs -text +#*.xcf filter=lfs diff=lfs merge=lfs -text + +# Other +#*.exe filter=lfs diff=lfs merge=lfs -text +#*.jar filter=lfs diff=lfs merge=lfs -text From 819a9e018b587d3a8f42abeeb1d4f17da929c89b Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:22:14 -0400 Subject: [PATCH 131/205] Update buildscript --- build.gradle | 1336 ++++++++++++++++++++++++++++++++++----------- gradle.properties | 146 ++++- 2 files changed, 1138 insertions(+), 344 deletions(-) diff --git a/build.gradle b/build.gradle index 06c57cde..3791a395 100644 --- a/build.gradle +++ b/build.gradle @@ -1,323 +1,1013 @@ -def corePlugin = '' - -buildscript { - repositories { - mavenCentral() -// maven { -// url 'http://maven.aliyun.com/nexus/content/groups/public/' -// } - -// maven { -// url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' -// } - maven { - name = 'forge' - url = 'https://maven.minecraftforge.net' - } - maven { - name = 'gradle' - url 'https://plugins.gradle.org/m2/' - } - maven { - name = 'sonatype' - url = 'https://oss.sonatype.org/content/groups/public' - } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0' - classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3' - } -} - -apply plugin: 'net.minecraftforge.gradle.forge' -apply plugin: 'com.matthewprenger.cursegradle' -apply plugin: 'maven-publish' -apply plugin: 'org.sonarqube' - -javadoc { - failOnError = false -} - -description = 'OreSpawn' -def mod_file = getModFile() -def mc_version = "1.12" -def short_version = getVersion("VERSION", mod_file) -version = mc_version + "-" + short_version -if (System.getenv().BUILD_NUMBER) { - version += '.' + System.getenv().BUILD_NUMBER -} -group = "com.mcmoddev" -sourceCompatibility = targetCompatibility = "1.8" - -class Secrets { - def data = null - - def getProperty(String key) { - return data ? data[key] : '' - } -} - -import groovy.json.JsonSlurper - -def secretFile -if (System.getenv().SECRET_FILE) { - secretFile = file System.getenv().SECRET_FILE -} else { - secretFile = file 'secret.json' -} - -project.ext.secret = new Secrets() -if (secretFile.exists()) { - secretFile.withReader { - project.ext.secret.data = new JsonSlurper().parse it - } -} - -minecraft { - version = '1.12.2-14.23.5.2847' - runDir = 'run' - mappings = 'stable_39' -// coreMod = '' - makeObfSourceJar = false - - replace '@FINGERPRINT@', project.findProperty('signSHA1') -} - -repositories { - mavenCentral() - maven { - name 'MMD' - url 'https://maven.mcmoddev.com/' - } - maven { // Mantle, TCon, JEI - name 'DVS1 Maven FS' - url 'http://dvs1.progwml6.com/files/maven' - } - maven { // CCL, CCC, NEI - name 'Chickenbones Repo' - url 'http://chickenbones.net/maven/' - } - maven { // The One Probe - name 'tterrag' - url 'http://maven.tterrag.com/' - } - maven { // MCMultipart - name 'amadornes' - url 'http://maven.amadornes.com/' - } - maven { // Tesla - name 'epoxide' - url 'http://maven.epoxide.org' - } - maven { // CraftTweaker, ZenScript - name 'jared maven' - url 'http://blamejared.com/maven' - } - maven { // IC2 - name 'industrialcraft' - url 'http://maven.ic2.player.to' - } - maven { // WAILA/HWYLA - name 'tehnut' - url 'http://tehnut.info/maven' - } - maven { // CoFH - name 'Covers Maven' - url 'http://maven.covers1624.net' - } - maven { - name = 'CurseForge' - url = 'https://minecraft.curseforge.com/api/maven/' - } - maven { - name 'opencomputers' - url 'http://maven.cil.li/' - } - maven { // Mekanism, TAIGA - name 'jitpack' - url 'https://jitpack.io' - } -} - -dependencies { - // None -} - -processResources { - inputs.property 'version', project.version - inputs.property 'mcversion', project.minecraft.version - - from (sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - expand 'version': short_version, 'mcversion': project.minecraft.version - } - - from (sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} - -jar { - manifest { -// attributes 'FMLCorePluginContainsFMLMod': 'true' -// attributes 'FMLCorePlugin': corePlugin -// attributes 'FMLAT' : '' - } -} - -task apiJar(type: Jar, dependsOn: classes) { - classifier = 'api' - from sourceSets.main.allSource - exclude('com/mcmoddev/orespawn/impl/**') - exclude('com/mcmoddev/orespawn/impl/features/**') - exclude('com/mcmoddev/orespawn/json/**') - exclude('com/mcmoddev/orespawn/world/**') - exclude('com/mcmoddev/orespawn/commands/**') - exclude('com/mcmoddev/orespawn/data/**') - exclude('com/mcmoddev/orespawn/*.java') -} - -task devJar(type: Jar) { - classifier = 'dev' - from sourceSets.main.output -} - -task deobfJar(type: Jar) { - classifier = 'deobf' - from sourceSets.main.output -} - -task signJar(type: SignJar, dependsOn: reobfJar) { - - // Skips if the keyStore property is missing. - onlyIf { - project.hasProperty('keyStore') - } - - // findProperty allows us to reference the property without it existing. - // Using project.propName would cause the script to fail validation if - // the property did not exist. - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - inputFile = jar.archivePath - outputFile = jar.archivePath -} - -build.dependsOn signJar - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.getDestinationDir() -} - -artifacts { - archives apiJar - archives devJar - archives deobfJar - archives sourceJar - archives javadocJar -} - -publishing { - publications { - mavenJava(MavenPublication) { - groupId project.group - artifactId project.archivesBaseName - version project.version - from components.java - artifact sourceJar { - classifier 'sources' - } - artifact apiJar { - classifier 'api' - } - artifact devJar { - classifier 'dev' - } - artifact deobfJar { - classifier 'deobf' - } - artifact javadocJar { - classifier 'javadoc' - } - } - } - repositories { - maven { - credentials { - username secret.username - password secret.password - } - url secret.url - } - } -} - -curseforge { - apiKey = secret.curseforgeAPIKey - project { - id = "245586" - changelog = file("CHANGELOG.txt") - releaseType = "release" - def projName = "OreSpawn" - def displayVersion = getVersion("VERSION", mod_file) - if (System.getenv().BUILD_NUMBER) { - displayVersion += '.' + System.getenv().BUILD_NUMBER - } - mainArtifact(jar) { - displayName = "$project.description $displayVersion" -// relations { -// } - } - addArtifact(apiJar) { - displayName = "$project.description $displayVersion API" - } - addArtifact(sourceJar) { - displayName = "$project.description $displayVersion Sources" - } - addArtifact(deobfJar) { - displayName = "$project.description $displayVersion Development" - } - addArtifact(javadocJar) { - displayName = "$project.description $displayVersion Javadoc" - } - } -} - -sonarqube { - properties { - property 'sonar.host.url', secret.sonarHost - property 'sonar.organization', secret.sonarOrganization - property 'sonar.login', secret.sonarToken - property 'sonar.projectName', project.archivesBaseName - property 'sonar.projectKey', "$project.group:$project.archivesBaseName" - } -} - -String getModFile() { - String path = 'src/main/java/com/mcmoddev/orespawn/data/Constants.java' - return path -} - -String getVersion(String type, String mod_file) { - String major = '0' - String revision = '0' - String patch = '0' - String prefix = "public static final String $type = \"" - File file = file(mod_file) - file.eachLine { String s -> - s = s.trim() - if (s.startsWith(prefix)) { - s = s.substring(prefix.length(), s.length() - 2) - String[] pts = s.split("\\.") - - major = pts[0] - revision = pts[1] - patch = pts[2] - } - } - return "$major.$revision.$patch" -} +buildscript { + repositories { + mavenLocal() + jcenter() + mavenCentral() + removeIf { it instanceof MavenArtifactRepository && it.url.host == 'files.minecraftforge.net' } + maven { + name = 'forge' + url = 'https://maven.minecraftforge.net/' + } + maven { + name = 'gradle' + url 'https://plugins.gradle.org/m2/' + } + maven { + name = 'sonatype' + url = 'https://oss.sonatype.org/content/groups/public' + } + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: project.fg_version + if (GradleVersion.current() <= GradleVersion.version('3.3')) { +// classpath group: 'com.jaredsburrows', name: 'gradle-checker-framework-plugin', version: '0.2.1' + } + } +} + +plugins { + id 'com.gradle.build-scan' version '1.16' +// id 'com.jaredsburrows.checkerframework' version '0.2.2'// 3.4/4.0 or later + id 'com.github.spotbugs' version '1.6.9' // 4.0 or later + id 'com.matthewprenger.cursegradle' version '1.4.0' + id 'org.sonarqube' version '3.3' + id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.66' +//id 'org.junit.platform.gradle.plugin' version '1.2.0' // 3.5 through 4.5 + id 'maven-publish' + id 'jacoco' + id 'checkstyle' // 2.7 or later +} + +if (isFG1()) { + apply plugin: 'forge' +}else if (isFG2()) { + apply plugin: 'net.minecraftforge.gradle.forge' +} else { + apply plugin: 'net.minecraftforge.gradle' +} +if (gradleOlderThan('3.4')) { +// apply plugin: 'com.jaredsburrows.checkerframework' +} +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'maven-publish' +apply plugin: 'pmd' +import org.gradle.util.GradleVersion +if (gradleOlderThan('4.0')) { + apply plugin: 'findbugs' +} + +buildScan { + if (System.getenv('CI')) { + publishAlways() + } +//publishAlwaysIf(System.getenv("CI")) + licenseAgreementUrl = 'https://gradle.com/terms-of-service'; + licenseAgree = 'yes' +} + +project.afterEvaluate { + //final def junitPlatformTestTask = project.tasks.getByName('junitPlatformTest') + + // configure jacoco to analyze the junitPlatformTest task + jacoco { + // this tool version is compatible with + toolVersion = '0.8.3' // 0.8.3 uses ASM 7.0.4, 0.8.4 uses ASM 7.1, 0.8.6 uses ASM 8.0.1, 0.8.7 uses ASM 9.1 + // Not needed with new way + //if (gradleOlderThan('4.6')) { + //applyTo junitPlatformTestTask + //}} + } + + // create junit platform jacoco task + project.task(type: JacocoReport, 'junitPlatformJacocoReport', + { + if (gradleNewerThan('5.0')) { + getSourceDirectories().from(files('./src/main')) + getClassDirectories().from(files("${project.buildDir}/classes/main")) + } else { + sourceDirectories = files('./src/main') + classDirectories = files("${project.buildDir}/classes/main") + } + // Not needed with new way + //if (gradleOlderThan('4.6')) { + // executionData junitPlatformTestTask + //} + }) +} + +// Only works with JUnit Platform Launcher 1.2.0 and earlier +/* +if (gradleOlderThan('4.6')) { + junitPlatform { + // platformVersion '1.2.0' + // logManager 'org.apache.logging.log4j.jul.LogManager' + reportsDir file("${project.buildDir}/test-results/junit-platform") + // enableStandardTestTask true + // selectors (optional) + // filters (optional) + } +} +*/ + +if (gradleNewerThan('4.0')) { + spotbugs { + ignoreFailures = true + toolVersion = '3.1.7' // 3.1.7 uses ASM 6.2, 3.1.8 uses ASM 6.2.1 + effort = 'max' + reportLevel = 'low' + //includeFilter = file("$rootProject.projectDir/config/spotbugs-filter.xml") + } + + tasks.withType(com.github.spotbugs.SpotBugsTask) { + reports { + if (isCi()) { + xml.enabled = true + html.enabled = false + } else { + xml.enabled = false + html.enabled = true + } + } + } +} else { + findbugs { + toolVersion = "3.0.1" // Required for Java 8 +// toolVersion = "2.0.3" // Required for Java ? +// toolVersion = "1.3.9" // Required for Java ? + } +} + +if (GradleVersion.current() >= GradleVersion.version('2.7')) { + checkstyle { + ignoreFailures = true + if (gradleNewerThan('2.7')) { + toolVersion = '8.23' // 8.42 + } else { + toolVersion = '6.7' + } + showViolations = false + } +} + +pmd { + if (gradleNewerThan('2.1')) { + consoleOutput = false + } + ignoreFailures = true + sourceSets = [sourceSets.main] + reportsDir = file("$project.buildDir/reports/pmd") + if (gradleNewerThan('2.8')) { + rulePriority = 5 + } + ruleSets = [ + 'java-android', + 'java-basic', + 'java-braces', + 'java-clone', + 'java-codesize', + 'java-comments', + 'java-controversial', + 'java-coupling', + 'java-design', + 'java-empty', + 'java-finalizers', + 'java-imports', + 'java-j2ee', + 'java-javabeans', + 'java-junit', + 'java-logging-jakarta-commons', + 'java-logging-java', +// 'java-metrics', // Upsets 5.8.1 + 'java-migrating', + 'java-migrating_to_junit4', + 'java-naming', + 'java-optimizations', +// 'java-quickstart', // 6.x + 'java-strictexception', + 'java-strings', + 'java-sunsecure', + 'java-typeresolution', + 'java-unnecessary', + 'java-unusedcode' + ] + if (gradleNewerThan('2.3')) { + toolVersion = '5.8.1'; // 6.0.1, 6.34.0 + } else { + toolVersion = '5.1.3'; + } + if (gradleNewerThan('5.6')) { +// incrementalAnalysis = true // Requires PMD 6.0.0 or newer + } +} + +tasks.withType(JavaCompile) { + options.encoding = 'UTF-8' + options.compilerArgs = [ + '-Xlint:deprecation', // deprecation, rawtypes, cast, unchecked, all + //'-Xdiags:verbose', + //'-Werror' + ] + compileJava.options.compilerArgs += '-proc:none' +} + +tasks.withType(Test) { + compileTestJava.options.compilerArgs += '-proc:none' +} + +javadoc { + failOnError = false +} + +test { + if (gradleNewerThan('4.6')) { + useJUnitPlatform() + /* + useJUnitPlatform { + includeTags 'fast', 'smoke & feature-a' + //excludeTags 'slow', 'ci' + includeEngines 'junit-jupiter' + //excludeEngines 'junit-vintage' + } + */ + } +} + +//project.ext.short_version = '1.0.0' +project.ext.short_version = getModVersion('VERSION', 'src/main/java/com/mcmoddev/orespawn/data/Constants.java') +//project.ext.short_version = getModVersion('VERSION') +version = (project.hasProperty('mc_version') ? project.mc_version : project.forge_mc_version) + '-' + short_version +project.ext.display_version = short_version + +if ((System.getenv('BUILD_NUMBER')) || (System.getenv('TRAVIS_BUILD_NUMBER')) || (System.getenv('CIRCLE_BUILD_NUM'))) { + version += '.' + buildNumber + display_version += '.' + buildNumber +} + +static String getBuildNumber() { + return System.getenv('BUILD_NUMBER') ?: System.getenv('TRAVIS_BUILD_NUMBER') ?: System.getenv('CIRCLE_BUILD_NUM') ?: '0' +} + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 +compileJava.sourceCompatibility = JavaVersion.VERSION_1_8 +compileJava.targetCompatibility = JavaVersion.VERSION_1_8 + +eclipse.project { + buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder' + natures 'org.eclipse.buildship.core.gradleprojectnature' +} + +idea.module { + downloadJavadoc = true + //inheritOutputDirs = true +} + +class Secrets { + Map m_data = null + + final String getProperty(final String key) { + return (m_data && (m_data[key] != null)) ? m_data[key] : '' + } +} + +final def secretFile +if (System.getenv('SECRET_FILE')) { + secretFile = file System.getenv().SECRET_FILE +} else { + secretFile = file 'secret.json' +} + +import groovy.json.JsonSlurper +project.ext.secret = new Secrets() +if (secretFile.exists()) { + secretFile.withReader { + project.secret.m_data = new JsonSlurper().parse it + } +} else { + project.secret.m_data = new JsonSlurper().parseText( + '{ "username" : "' + (System.getenv('userMaven') ?: '') + '",' + + '"password" : "' + (System.getenv('authMaven') ?: '') + '",' + + '"url" : "' + (System.getenv('urlMaven') ?: '') + '",' + + '"curseforgeAPIKey" : "' + (System.getenv('curse_auth') ?: '00000000-0000-0000-0000-000000000000') + '",' + + '"sonarHost" : "' + (System.getenv('SONAR_HOST_URL') ?: 'https://sonarcloud.io') + '",' + + '"sonarOrganization" : "' + (System.getenv('SONAR_ORGANIZATION') ?: '') + '",' + + '"sonarToken" : "' + (System.getenv('SONAR_TOKEN') ?: 0) + '"}' + ) +} + +minecraft { + version = project.forge_mc_version + '-' + project.forge_version + if ((project.forge_mc_version != "1.6.4") && (project.forge_mc_version != "1.7.2")) { + mappings = project.mcp_mappings_version + } + + if ((project.fg_version != '1.0-SNAPSHOT') && (project.fg_version != '1.1-SNAPSHOT')) { + if (project.hasProperty('runDir')) { + runDir = project.runDir + } else if (file('../run').exists()) { + runDir = '../run' + } else { + runDir = 'run' + } + } else { + if (project.hasProperty('runDir')) { + assetDir = project.runDir + } else if (file('../assets').exists()) { + assetDir = '../assets' + } else { + assetDir = 'eclipse/assets' + } + } + + replace '@MOD_VERSION@', project.short_version + + if (project.hasProperty('signSHA1') && getBooleanProperty('do_sign_jar') && isFG2()) { + replace '@FINGERPRINT@', project.findProperty('signSHA1') + } else { + replace '@FINGERPRINT@', '' + } + + if (project.hasProperty('core_plugin')) { + clientJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}" + serverJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}" + } + + if (project.hasProperty('mc_username')) { + clientRunArgs += ['--username', project.mc_username] + if (project.hasProperty('mc_password')) { + clientRunArgs += ['--password', project.mc_password] + } + } + if (project.hasProperty('mc_uuid')) { + clientRunArgs += ['--uuid', project.mc_uuid] + } + + if (getBooleanProperty('mc_server_nogui')) { + serverRunArgs += 'nogui' + } + + if (getBooleanProperty('forge_do_not_backup')) { + serverJvmArgs += '-Dfml.doNotBackup=true' + clientJvmArgs += '-Dfml.doNotBackup=true' + } + + if (getBooleanProperty('forge_query_result_confirm')) { + serverJvmArgs += '-Dfml.queryResult=confirm' + } + + if (getBooleanProperty('log4j_skip_jansi')) { + serverJvmArgs += '-Dlog4j.skipJansi=true' + clientJvmArgs += '-Dlog4j.skipJansi=true' + } + + if (project.hasProperty('mc_resolution')) { + final def res = [ + '480p': [640, 480], + '576p': [640, 576], + '720p': [1280, 720], + '1080p': [1920, 1080], + 'custom': [project.findProperty('mc_custom_resolution_width'), project.findProperty('mc_custom_resolution_height')]] + final def choice = res?.get(project.mc_resolution) + if (choice != null) { + clientRunArgs += ['--width', choice[0]] + clientRunArgs += ['--height', choice[1]] + } + } + + if (project.hasProperty('client_jvm_args')) { + clientJvmArgs += project.client_jvm_args + } + if (project.hasProperty('server_jvm_args')) { + serverJvmArgs += project.server_jvm_args + } + + if (project.hasProperty('client_game_args')) { + clientRunArgs += project.client_game_args + } + if (project.hasProperty('server_game_args')) { + serverRunArgs += project.server_game_args + } + + if (isFG2()) { + makeObfSourceJar = getBooleanProperty('create_source_jar') + + useDepAts = getBooleanProperty('dep_has_ats') + } +} + +repositories { + mavenLocal() + jcenter() + mavenCentral() + + maven { + name 'MMD' + url 'https://maven.mcmoddev.com/' + } +} + +dependencies { + testCompile('org.junit.platform:junit-platform-launcher:1.7.+') + testCompile('org.junit.jupiter:junit-jupiter-api:5.7.+') // testImplementation + testRuntime('org.junit.jupiter:junit-jupiter-engine:5.7.+') //testRuntimeOnly + if (gradleNewerThan('2.13')) { + testCompileOnly 'junit:junit:4.13.2' + } + testRuntime 'org.junit.vintage:junit-vintage-engine:5.7.+' //testRuntimeOnly + testCompile('org.mockito:mockito-core:2.+') + testCompile('org.mockito:mockito-junit-jupiter:2.+') { + exclude group: 'org.junit.jupiter', module: 'junit-jupiter-engine' + } + if (gradleNewerThan('4.6')) { + annotationProcessor group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0' + } +} + +processResources { + inputs.property 'version', project.short_version + inputs.property 'mcversion', project.minecraft.version + + from (sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version': project.short_version, 'mcversion': project.minecraft.version + } + + from (sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + + rename '(.+_at.cfg)', 'META-INF/$1' +} + +jar { + //from sourceSets.api.output + //from sourceSets.main.output + + manifest { + mainAttributes( + 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}", + 'Timestamp': System.currentTimeMillis(), + 'Specification-Title': project.modid, + 'Specification-Vendor': project.vendor, + 'Specification-Version': '1', + 'Implementation-Title': project.archivesBaseName, + 'Implementation-Version': project.version, + 'Implementation-Vendor' : project.vendor, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Built-On': "${project.forge_mc_version}-${project.forge_version}" + ) + if (project.hasProperty('core_plugin')) { + attributes 'FMLCorePluginContainsFMLMod': 'true' + attributes 'FMLCorePlugin': project.core_plugin + } + if (project.hasProperty('mod_at_file')) { + attributes 'FMLAT': project.mod_at_file + } + if (project.hasProperty('mod_contained_deps')) { + attributes 'ContainedDeps': project.mod_contained_deps + } + } +} + +task apiJar(type: Jar) { + onlyIf { + getBooleanProperty('create_api_jar') + } + + description = 'Creates a JAR containing the API Classes.' + classifier = 'api' + //from apiClasses + // from sourceSets.api.output + from sourceSets.main.allSource + exclude('com/mcmoddev/orespawn/impl/**') + exclude('com/mcmoddev/orespawn/impl/features/**') + exclude('com/mcmoddev/orespawn/json/**') + exclude('com/mcmoddev/orespawn/world/**') + exclude('com/mcmoddev/orespawn/commands/**') + exclude('com/mcmoddev/orespawn/data/**') + exclude('com/mcmoddev/orespawn/*.java') + manifest { + mainAttributes( + 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:api", + 'Timestamp': System.currentTimeMillis(), + 'Specification-Title': project.modid, + 'Specification-Vendor': project.vendor, + 'Specification-Version': '1', + 'Implementation-Title': project.archivesBaseName + '-api', + 'Implementation-Version': project.version, + 'Implementation-Vendor' : project.vendor, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Built-On': "${project.forge_mc_version}-${project.forge_version}" + ) + } +} + +task devJar(type: Jar) { + classifier = 'dev' + from sourceSets.main.output +} + +task deobfJar(type: Jar) { + onlyIf { + getBooleanProperty('create_deobf_jar') + } + + description = 'Creates a JAR containing the non-obfuscated compiled code.' + classifier = 'deobf' + from sourceSets.main.output + manifest { + mainAttributes( + 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:deobf", + 'Timestamp': System.currentTimeMillis(), + 'Specification-Title': project.modid, + 'Specification-Vendor': project.vendor, + 'Specification-Version': '1', + 'Implementation-Title': project.archivesBaseName + '-deobf', + 'Implementation-Version': project.version, + 'Implementation-Vendor' : project.vendor, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Built-On': "${project.forge_mc_version}-${project.forge_version}" + ) + if (project.hasProperty('mod_at_file')) { + attributes 'FMLAT': project.mod_at_file + } + if (project.hasProperty('core_plugin')) { + attributes 'FMLCorePlugin': project.core_plugin + } + } +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + onlyIf { + getBooleanProperty('create_javadoc_jar') + } + + description = 'Creates a JAR containing the JavaDocs.' + classifier = 'javadoc' + from javadoc.getDestinationDir() + manifest.mainAttributes( + 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:javadoc", + 'Timestamp': System.currentTimeMillis(), + 'Specification-Title': project.modid, + 'Specification-Vendor': project.vendor, + 'Specification-Version': '1', + 'Implementation-Title': project.archivesBaseName + '-javadoc', + 'Implementation-Version': project.version, + 'Implementation-Vendor' : project.vendor, + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", + 'Built-On': "${project.forge_mc_version}-${project.forge_version}" + ) +} + +if (isFG1()) { +// def signType = Jar +} else if (isFG2()) { +// def signType = SignJar + + task signJar(type: SignJar, dependsOn: reobfJar) { + onlyIf { + getBooleanProperty('do_sign_jar') && + project.hasProperty('keyStore') + } + + description = 'Sign the Main JAR' + inputFile = jar.archivePath + outputFile = jar.archivePath + + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + } + + task signApiJar(type: SignJar) { + onlyIf { + getBooleanProperty('create_api_jar') && + getBooleanProperty('do_sign_jar') && + project.hasProperty('keyStore') + } + + description = 'Sign the API JAR' + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + + inputFile = apiJar.archivePath + outputFile = apiJar.archivePath + } + + task signDeobfJar(type: SignJar) { + onlyIf { + getBooleanProperty('create_deobf_jar') && + getBooleanProperty('do_sign_jar') && + project.hasProperty('keyStore') + } + + description = 'Sign the deobf JAR' + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + + inputFile = deobfJar.archivePath + outputFile = deobfJar.archivePath + } + + task signSourceJar(type: SignJar) { + onlyIf { + getBooleanProperty('create_source_jar') && + getBooleanProperty('do_sign_jar') && + project.hasProperty('keyStore') + } + + description = 'Sign the Sources JAR' + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + + inputFile = sourceJar.archivePath + outputFile = sourceJar.archivePath + } + + task signJavadocJar(type: SignJar) { + onlyIf { + getBooleanProperty('create_javadoc_jar') && + getBooleanProperty('do_sign_jar') && + project.hasProperty('keyStore') + } + + keyStore = project.findProperty('keyStore') + alias = project.findProperty('keyStoreAlias') + storePass = project.findProperty('keyStorePass') + keyPass = project.findProperty('keyStoreKeyPass') + + inputFile = javadocJar.archivePath + outputFile = javadocJar.archivePath + } +} + +if (getBooleanProperty('do_sign_jar') && (!isFG1())) { + build.dependsOn signJar + if (getBooleanProperty('create_api_jar')) { + build.dependsOn signApiJar + } + if (getBooleanProperty('create_deobf_jar')) { + build.dependsOn signDeobfJar + } + if (getBooleanProperty('create_source_jar')) { + build.dependsOn signSourceJar + } + if (getBooleanProperty('create_javadoc_jar')) { + build.dependsOn signJavadocJar + } +} + +tasks.publish.dependsOn build +tasks.curseforge.dependsOn publish + +artifacts { + if (getBooleanProperty('create_api_jar')) { + archives apiJar + } + if (getBooleanProperty('create_deobf_jar')) { + archives devJar + archives deobfJar + } + if (getBooleanProperty('create_source_jar')) { + archives sourceJar + } + if (getBooleanProperty('create_javadoc_jar')) { + archives javadocJar + } +} + +publishing { + publications { + mavenJava(MavenPublication) { + groupId project.group + artifactId project.archivesBaseName + version project.version + from components.java + if (getBooleanProperty('create_source_jar')) { + artifact sourceJar { + classifier 'sources' + } + } + if (getBooleanProperty('create_api_jar')) { + artifact apiJar { + classifier 'api' + } + } + if (getBooleanProperty('create_deobf_jar')) { + artifact devJar { + classifier 'dev' + } + artifact deobfJar { + classifier 'deobf' + } + } + if (getBooleanProperty('create_javadoc_jar')) { + artifact javadocJar { + classifier 'javadoc' + } + } + if (getBooleanProperty(pom_information)) { + pom { + name = project.name + description = project.description + url = project.pom_url + packaging = 'jar' + //inceptionYear = '' + if (getBooleanProperty(pom_license_information)) { + licenses { + license { + name = project.pom_license_name + url = project.pom_license_url + distribution = 'repo' + comments = project.pom_comments + } + } + } + if (getBooleanProperty(pom_scm_information)) { + scm { + connection = project.pom_scm_connection + developerConnection = project.pom_scm_developer_connection + // tag + url = project.pom_scm_url + } + } + if (getBooleanProperty(pom_issue_information)) { + issueManagement { + system = project.pom_issue_system + url = project.pom_issue_url + } + } + if (getBooleanProperty(pom_ci_information)) { + ciManagement { + system = project.pom_ci_system + url = project.pom_ci_url + } + } + if (getBooleanProperty(pom_organisation_information)) { + organization { + name = project.pom_organization_name + url = project.pom_organization_url + } + } + // contributors, developers, distributionManagement + } + } + } + } + repositories { + maven { + if ((secret.username != '') && (secret.password != '')) { + credentials { + username secret.username + password secret.password + } + } + if (secret.url != '') { + url secret.url + } else { + url "file:///${project.buildDir}/repo" + } + } + } +} + +curseforge { + if (project.hasProperty('curseforge_project_id') && getBooleanProperty('curseforge_do_upload')) { + apiKey = secret.curseforgeAPIKey + project { + id = project.curseforge_project_id + if (project.hasProperty('curseforge_changelog_filename')) { + changelog = file(project.curseforge_changelog_filename) + } else { + changelog = '' + } + if (project.hasProperty('curseforge_changelog_type')) { + changelogType = project.curseforge_changelog_type + } + if ((project.hasProperty('curseforge_release_type')) && ((project.curseforge_release_type == 'alpha') || (project.curseforge_release_type == 'beta') || (project.curseforge_release_type == 'release'))) { + releaseType = project.curseforge_release_type + } else { + releaseType = 'alpha' + } + if (project.hasProperty('curseforge_versions')) { + final def versions = "${project.curseforge_versions}".split(', ') + versions.each { + addGameVersion "${it}" + } + } + mainArtifact(jar) { + if (getBooleanProperty('curseforge_use_custom_display_name')) { + displayName = "${project.name} ${project.display_version}" + } + if (project.hasProperty('curseforge_requirements') || project.hasProperty('curseforge_optionals') || project.hasProperty('curseforge_embeddeds') || project.hasProperty('curseforge_tools') || project.hasProperty('curseforge_incompatibles') || project.hasProperty('curseforge_includes')) { + relations { + if (project.hasProperty('curseforge_requirements')) { + final def requirements = "${project.curseforge_requirements}".split(', ') + requirements.each { + requiredDependency "${it}" + } + } + if (project.hasProperty('curseforge_optionals')) { + final def optionals = "${project.curseforge_optionals}".split(', ') + optionals.each { + optionalDependency "${it}" + } + } + if (project.hasProperty('curseforge_embeddeds')) { + final def embeddeds = "${project.curseforge_embeddeds}".split(', ') + embeddeds.each { + embeddedLibrary "${it}" + } + } + if (project.hasProperty('curseforge_tools')) { + final def tools = "${project.curseforge_tools}".split(', ') + tools.each { + tool "${it}" + } + } + if (project.hasProperty('curseforge_incompatibles')) { + final def incompatibles = "${project.curseforge_incompatibles}".split(', ') + incompatibles.each { + incompatible "${it}" + } + } + if (project.hasProperty('curseforge_includes')) { + final def includes = "${project.curseforge_includes}".split(', ') + includes.each { + include "${it}" + } + } + } + } + } + if (getBooleanProperty('create_api_jar')) { + addArtifact(apiJar) { + if (getBooleanProperty('curseforge_use_custom_display_name')) { + displayName = "${project.name} ${project.display_version} API" + } + } + } + if (getBooleanProperty('create_source_jar')) { + addArtifact(sourceJar) { + if (getBooleanProperty('curseforge_use_custom_display_name')) { + displayName = "${project.name} ${project.display_version} Sources" + } + } + } + if (getBooleanProperty('create_deobf_jar')) { + addArtifact(deobfJar) { + if (getBooleanProperty('curseforge_use_custom_display_name')) { + displayName = "${project.name} ${project.display_version} Development" + } + } + } + if (getBooleanProperty('create_javadoc_jar')) { + addArtifact(javadocJar) { + if (getBooleanProperty('curseforge_use_custom_display_name')) { + displayName = "${project.name} ${project.display_version} Javadoc" + } + } + } + } + } +} + +sonarqube { + properties { + if (project.hasProperty('sonar_host_url')) { + property 'sonar.host.url', project.sonar_host_url + } else if (secret.sonarHost != '') { + property 'sonar.host.url', secret.sonarHost + } else { + property 'sonar.host.url', 'https://sonarcloud.io' + } + + if (secret.sonarToken != '') { + property 'sonar.login', secret.sonarToken + } + + if (project.hasProperty('sonar_organisation')) { + property 'sonar.organization', project.sonar_organisation + } else if (secret.sonarOrganisation != '') { + property 'sonar.organization', secret.sonarOrganization + } else { + property 'sonar.organization', 'unset' + } + + if (project.hasProperty('sonar_project_key')) { + property 'sonar.projectKey', project.sonar_project_key + } + + if (project.hasProperty('sonar_project_name')) { + property 'sonar.projectName', project.sonar_project_name + } + + if (project.hasProperty('sonar_project_description')) { + property 'sonar.projectDescription', project.sonar_project_description + } + + if (project.hasProperty('sonar_project_version')) { + property 'sonar.projectVersion', project.sonar_project_version + } + + if (project.hasProperty('sonar_branch_name')) { + property 'sonar.branch.name', project.sonar_branch_name + } + + if (project.hasProperty('sonar_branch_target')) { + property 'sonar.branch.target', project.sonar_branch_target + } + + property 'sonar.junit.reportPaths', "${project.buildDir}/test-results/junit-platform/*.xml" + property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/junitPlatformTest.exec" + //property 'sonar.groovy.jacoco.reportPath', "" + } +} + +String getModFile() { + String path = '' + final FileTree tree = fileTree(dir: 'src/main/java') + tree.include '**/*.java' + tree.visit { final element -> + if (element.file.isFile()) { + element.file.eachLine { final String s -> + final String sTrim = s.trim() + if (sTrim.startsWith('@Mod(')) { + path = "src/main/java/${element.relativePath}" + } + } + } + } + return path +} + +String getModVersion(final String type) { + return getModVersion(type, modFile) +} + +import java.util.regex.Matcher +String getModVersion(final String type, final String modFile) { + if ((modFile != null) && (modFile != '')) { + final File file = file(modFile) + final def prefix = ~/^(?:\s*)(?:(?public|protected|private) )?(?:(?static) )?(?:(?final) )?String $type = "(?:(?\d*)\.)?(?:(?\d*)\.)?(?:(?[^."]*)\.?)(?[^"]*)";$/ + for (final String s in file.readLines()) { + final Matcher matcher = (s.trim() =~ prefix) + if (matcher.matches()) { + return "${matcher.group('major') ?: '0'}.${matcher.group('minor') ?: '0'}.${matcher.group('patch')}" + } + } + } + return '0.0.0' +} + +boolean isFG1() { + return (project.fg_version == '1.0-SNAPSHOT') || (project.fg_version == '1.1-SNAPSHOT') || (project.fg_version == '1.2-SNAPSHOT') +} + +boolean isFG2() { + return (project.fg_version == '2.0-SNAPSHOT') || (project.fg_version == '2.1-SNAPSHOT') || (project.fg_version == '2.2-SNAPSHOT') || (project.fg_version == '2.3-SNAPSHOT') +} + +boolean gradleOlderThan(final String version) { + return GradleVersion.current() < GradleVersion.version(version) +} + +boolean gradleNewerThan(final String version) { + return GradleVersion.current() >= GradleVersion.version(version) +} + +boolean isCi() { + return System.getenv('CI') +} + +boolean getBooleanProperty(final String property) { + if (project.hasProperty(property)) { + return ((String) project.findProperty(property)).toBoolean() + } else { + return false + } +} + +if (gradleNewerThan('2.1')) { + task gitChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) { + file = new File('CHANGELOG.md') + gitHubIssuePattern = "nonada123" + templateContent = file('changelog.mustache').getText('UTF-8') + } +} + +Object findProperty(final String propertyName) { + return hasProperty(propertyName) ? property(propertyName) : null; +} diff --git a/gradle.properties b/gradle.properties index 3fb922ea..31c10144 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,24 +1,128 @@ +org.gradle.daemon = false + +group = com.mcmoddev archivesBaseName = OreSpawn +modid = orespawn +vendor = mcmoddev +name = MMD OreSpawn +description = MMD OreSpawn +#Minumum Minecraft Version Mod will be built with mc_version=1.12 -top_mc_version=1.11 -ccl_version=2.4.3.165 -ccc_version=2.3.5.93 -nei_version=2.1.2.175 -//jei_version=3.10.0.268 -//jei_version=3.12.8.328 -//jei_version=3.13.6.389 -jei_version=+ -mantle_version=1.1.3.199 -tconstruct_version=2.6.1.464 -mcmp_version=1.2.1 -//mcmp_version=1.3.0 -mcmp_experimental_version=2.0.0_88 -top_version=1.3.3-46 -orespawn_version=3.1.0+ -tesla_version=1.2.1.50 -bme_version=2.5.0-beta1 -mme_version=0.11.0 -fme_version=0.11.0 -bmi_version=0.11.0 -pa_version=2.3.0 \ No newline at end of file + +#ForgeGradle version to use (Required) +fg_version = 2.3-SNAPSHOT +#version of Minecraft Forge is built against (Required) +forge_mc_version = 1.12.2 +#Forge version to use (Required) +forge_version = 14.23.5.2847 +#Mappings version to use (Required) +mcp_mappings_version = stable_39 + +# The following will currently only be set when using Gradle 4.8 or later +pom_information = false +pom_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' + +pom_license_information = true +pom_license_name = 'GNU Lesser General Public License v2.1' +pom_license_url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' +pom_comments = '' + +pom_scm_information = true +pom_scm_connection = 'scm:git:git://github.com/MinecraftModDevelopmentMods/OreSpawn.git' +pom_scm_developer_connection = 'scm:git:git@github.com:MinecraftModDevelopmentMods/OreSpawn.git' +pom_scm_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' + +pom_issue_information = true +pom_issue_system = 'github' +pom_issue_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn/issues' + +pom_ci_information = true +pom_ci_system = 'jenkins' +pom_ci_url = 'https://ci.mcmoddev.com/' + +pom_organisation_information = true +pom_organization_name = 'Minecraft Mod Development' +pom_organization_url = 'https://mcmoddev.com/' + +curseforge_do_upload=false +#curseforge_debug=false +#Cursforge Project ID (Required) +curseforge_project_id = 245586 +#Type of Release, can be one of 'alpha', 'beta' or 'release' (Defaults to 'alpha' if not set) +curseforge_release_type = release +#When using a ChangeLog file specifies filename +curseforge_changelog_filename = CHANGELOG.txt +#Changelog type, can be one of 'text', 'html' or 'markdown' (Defaults to 'text' if not set) +curseforge_changelog_type = text +#Version(s) of Minecraft this mod will work on (comma separated list) +curseforge_versions = 1.12, 1.12.1, 1.12.2 +#Whether to use a custom display name on artifacts +curseforge_use_custom_display_name = true +#List of required dependencies (comma separated list) +#curseforge_requirements = +#List of optional dependencies (comma separated list) +#curseforge_optionals = +#List of embedded dependencies (comma separated list) +#curseforge_embeddeds = +#List of compatible tools (comma separated list) +#curseforge_tools = +#List of incompatible dependencies (comma separated list) +#curseforge_incompatibles = +#List of included dependencies (comma separated list) +#curseforge_includes = + +#String reference to Core Plugin this mod contains, if any +#core_plugin = +#Whether or not to use Access Transformers from depended mods +dep_has_ats = false +#File name of this mod's Access Transformers (If any) +#mod_at_file = _at.cfg + +#Whether the artifacts should be signed +do_sign_jar = true + +#Create a source jar? +create_source_jar = true +#Create an API jar? +create_api_jar = true +#Create a deobf jar? +create_deobf_jar = true +#Create a javadoc jar? +create_javadoc_jar = true + +#The following four options are optional and do not affect your build in any way +#They are only for convenience when using the 'runClient' and 'runServer' tasks +#Whether to Disable server gui +#mc_server_nogui = true +#Whether to Skip the screen to confirm that you want to load a world with missing registry entries +#forge_do_not_backup = true +#Whether to skip having to confirm on server +#forge_query_result_confirm = true +#Whether to Skip jansi warnings in the log +#log4j_skip_jansi = true + +# Optional convenience setter for game resolution one of '480p', '576p', '720p', '1080p' or 'custom' +#mc_resolution = 1080p +#the following two will only be used when mc_resolution = custom +#mc_custom_resolution_width = 1920 +#mc_custom_resolution_height = 1080 +#mc_fullscreen = true + +#Additional arguments to pass to minecraft.clientJvmArgs +#client_jvm_args = +#Additional arguments to pass to minecraft.serverJvmArgs +#client_game_args = +#Additional arguments to pass to minecraft.clientRunArgs +#server_jvm_args = +#Additional arguments to pass to minecraft.serverRunArgs +#server_game_args = + +##The following three options should *NEVER* be set in this file, it's a security risk, Be safe, keep your account information private. +##These properties here are for reference only and explanation of what they do +##Your Minecraft account username (Consistent player name for singleplayer worlds) +##mc_username = +##Your Minecraft account password (Allows online play while present with associated username) +##mc_password = +##Your Minecraft account uuid (Allows using your skin while testing, This can be with or without hyphens) +##mc_uuid = From 219406b674f5fd854b74a008d08440dc6742d17a Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:28:44 -0400 Subject: [PATCH 132/205] Update checkstyle.xml --- config/checkstyle.xml | 148 +++++++++++++++++++++++++++++++++--------- 1 file changed, 119 insertions(+), 29 deletions(-) diff --git a/config/checkstyle.xml b/config/checkstyle.xml index 67eb300a..038f8213 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle.xml @@ -1,22 +1,99 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -26,42 +103,60 @@ Checkstyle configuration that checks the sun coding conventions. + + + - + - - - - + + + + + + - - + + - - + + + + + + + + - + + + + @@ -69,28 +164,23 @@ Checkstyle configuration that checks the sun coding conventions. + + + + + + + - + - - - - - - - - - - - - From ee47dd44d0ba7df238b066c078c7de54ef3768f7 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:29:00 -0400 Subject: [PATCH 133/205] Fix CodeQL --- .github/workflows/codeql-analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2b083168..d5a02752 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,8 +19,8 @@ on: [push, pull_request] # # The branches below must be a subset of the branches above # branches: [ master-1.12 ] # types: [opened, synchronize, reopened] - schedule: - - cron: '43 7 * * 4' +# schedule: +# - cron: '43 7 * * 4' jobs: analyze: From b932291d141d8c07b33fc47cc74b7f3f572e5d97 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 00:34:31 -0400 Subject: [PATCH 134/205] Try again --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72fbb317..e4806ccc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,4 +21,4 @@ jobs: - run: chmod a+x gradlew - run: ./gradlew --version --no-daemon - run: ./gradlew setupCIWorkspace - - run: ./gradlew clean build + - run: ./gradlew clean build -x test From dc60c243c2b1e8344f349fad8d9695aa1b9edeff Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:06:54 -0400 Subject: [PATCH 135/205] Try fixing again --- .github/workflows/ci.yml | 2 +- config/checkstyle.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4806ccc..72fbb317 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,4 +21,4 @@ jobs: - run: chmod a+x gradlew - run: ./gradlew --version --no-daemon - run: ./gradlew setupCIWorkspace - - run: ./gradlew clean build -x test + - run: ./gradlew clean build diff --git a/config/checkstyle.xml b/config/checkstyle.xml index 038f8213..aafbfb36 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle.xml @@ -51,12 +51,12 @@ - + ---- + --> From 3194669d90d1ef6353d811a74a750d91b54217ca Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:12:46 -0400 Subject: [PATCH 136/205] Well, that was embarrassing.... --- config/{ => checkstyle}/checkstyle.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename config/{ => checkstyle}/checkstyle.xml (99%) diff --git a/config/checkstyle.xml b/config/checkstyle/checkstyle.xml similarity index 99% rename from config/checkstyle.xml rename to config/checkstyle/checkstyle.xml index aafbfb36..038f8213 100644 --- a/config/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -51,12 +51,12 @@ - ---- + - --> From e754c106247cb88352084472b2ae6b77b7225a07 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:26:26 -0400 Subject: [PATCH 137/205] Fix silly mistake --- .../orespawn/impl/features/UnderFluid.java | 421 +++++++++--------- 1 file changed, 209 insertions(+), 212 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java index f1c4697c..d4ea1707 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java @@ -1,212 +1,209 @@ -/** - * - */ -package com.mcmoddev.orespawn.impl.features; - -import java.util.Random; -import java.util.Set; -import java.util.HashSet; -import java.util.List; -import java.util.stream.StreamSupport; -import java.util.stream.Collectors; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.FeatureBase; -import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.data.Constants; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; - -/** - * @author Daniel Hazelton - * - */ -public class UnderFluid extends FeatureBase implements IFeature { - - /** - * @param rand - */ - public UnderFluid() { - super(new Random()); - } - - /** - * Try to generate this feature to the specified parameters in the specified chunk. - *
- *

Theory: - *

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

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

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

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

At the fluids lower bound, generate the node. - *

- * - * @param world {@link net.minecraft.world.World} World this chunk is in - * @param chunkGenerator {@link net.minecraft.world.gen.IChunkGenerator} Chunk generator for this chunk - * @param chunkProvider {@link net.minecraft.world.chunk.IChunkGenerator} Chunk provider for this chunk - * @param spawnData {@link com.mcmoddev.orespawn.api.os3.ISpawnEntry} Parameters and data on this spawn from the configuration file - * @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) - * @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) - */ - @Override - public void generate(final World world, final IChunkGenerator chunkGenerator, - final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { - final ChunkPos pos = chunkPos; - final JsonObject params = spawnData.getFeature().getFeatureParameters(); - - // First, load cached blocks for neighboring chunk ore spawns - final int chunkX = pos.x; - final int chunkZ = pos.z; - - mergeDefaults(params, getDefaultParameters()); - - runCache(chunkX, chunkZ, world, spawnData); - - // now to ore spawn - - final int blockX = chunkX * 16 + 8; - final int blockZ = chunkZ * 16 + 8; - - - final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); - final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); - final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); - final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); - final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); - final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); - final Fluid fluid = FluidRegistry.getFluid(params.get(Constants.FormatBits.FLUID).getAsString()); - - int tries = this.random.nextInt(triesMax - triesMin + 1) + triesMin; - int ySpan = maxHeight - minHeight; - int surveySize = ((256 * (16 * ySpan)) / 4) / 125; - BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); - Block fluidBlock = fluid.getBlock(); - - Set found = new HashSet<>(); - - int surveyCount = 0; - int spawnCount = 0; - - while(surveyCount < surveySize && spawnCount < tries) { - BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); - BlockPos lowSide = sampleCenter.add(-2,-2,-2); - BlockPos highSide = sampleCenter.add(2,2,2); - Chunk chunk = world.getChunk(sampleCenter); - - if(!found.contains(sampleCenter)) { - found.addAll(findPossibleTargets(chunk, lowSide, highSide, fluidBlock, minHeight)); - - if(!found.isEmpty()) { - BlockPos target = found.toArray(new BlockPos[0])[this.random.nextInt(found.size())]; - spawnCount += maybeSpawn(target, minHeight, maxHeight, nodeSize, variance, world, spawnData); - } - surveyCount++; - } - } - } - - private int maybeSpawn(BlockPos target, int minHeight, int maxHeight, int nodeSize, - int variance, World world, ISpawnEntry spawnData) { - BlockPos mp = target; - while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { - mp = mp.down(); - } - - if (mp.getY() > minHeight && mp.getY() < maxHeight) { - // calculate actual size for this node - int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); - // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... - // so... we copy vanilla spawn logic, to a degree, I think - spawnOre(world, spawnData, mp, size); - return 1; - } - - - return 0; - } - - private List findPossibleTargets(Chunk chunk, BlockPos lowSide, BlockPos highSide, - Block fluidBlock, int minHeight) { - return StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) - .filter( bp -> chunk.getBlockState(bp).getMaterial().isLiquid() && - chunk.getBlockState(bp).getBlock().equals(fluidBlock) && - bp.getY() >= minHeight ) - .map(BlockPos.MutableBlockPos::toImmutable) - .collect(Collectors.toList()); - } - - private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, - final int quantity) { - int count = quantity; - final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; - final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; - final Vec3i[] offs = new Vec3i[lutType]; - - System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); - - if (quantity < 27) { - final int[] scrambledLUT = new int[lutType]; - System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); - scramble(scrambledLUT, this.random); - - while (count > 0) { - final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - final BlockPos target = pos.add(offs[scrambledLUT[--count]]); - spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); - } - - return; - } - - doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); - } - - private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, - final ISpawnEntry spawnData, final BlockPos pos) { - final int count = quantity; - final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; - final int rSqr = (int) (radius * radius); - if (nextBoolean) { - spawnMungeNE(world, pos, rSqr, radius, spawnData, count); - } else { - spawnMungeSW(world, pos, rSqr, radius, spawnData, count); - } - } - - /* (non-Javadoc) - * @see com.mcmoddev.orespawn.api.IFeature#setRandom(java.util.Random) - */ - @Override - public void setRandom(Random rand) { - this.random = rand; - } - - /* (non-Javadoc) - * @see com.mcmoddev.orespawn.api.IFeature#getDefaultParameters() - */ - @Override - public JsonObject getDefaultParameters() { - final JsonObject defParams = new JsonObject(); - defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); - defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); - defParams.addProperty(Constants.FormatBits.VARIATION, 16); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); - defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); - defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); - defParams.addProperty(Constants.FormatBits.FLUID, "water"); - return defParams; - } - -} +/** + * + */ +package com.mcmoddev.orespawn.impl.features; + +import java.util.Random; +import java.util.Set; +import java.util.HashSet; +import java.util.List; +import java.util.stream.StreamSupport; +import java.util.stream.Collectors; + +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.api.FeatureBase; +import com.mcmoddev.orespawn.api.IFeature; +import com.mcmoddev.orespawn.api.os3.ISpawnEntry; +import com.mcmoddev.orespawn.data.Constants; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.IChunkGenerator; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; + +/** + * @author Daniel Hazelton + * + */ +public class UnderFluid extends FeatureBase implements IFeature { + + public UnderFluid() { + super(new Random()); + } + + /** + * Try to generate this feature to the specified parameters in the specified chunk. + *
+ *

Theory: + *

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

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

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

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

At the fluids lower bound, generate the node. + *

+ * + * @param world {@link net.minecraft.world.World} World this chunk is in + * @param chunkGenerator {@link net.minecraft.world.gen.IChunkGenerator} Chunk generator for this chunk + * @param chunkProvider {@link net.minecraft.world.chunk.IChunkProvider} Chunk provider for this chunk + * @param spawnData {@link com.mcmoddev.orespawn.api.os3.ISpawnEntry} Parameters and data on this spawn from the configuration file + * @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) + * @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) + */ + @Override + public void generate(final World world, final IChunkGenerator chunkGenerator, + final IChunkProvider chunkProvider, final ISpawnEntry spawnData, final ChunkPos chunkPos) { + final ChunkPos pos = chunkPos; + final JsonObject params = spawnData.getFeature().getFeatureParameters(); + + // First, load cached blocks for neighboring chunk ore spawns + final int chunkX = pos.x; + final int chunkZ = pos.z; + + mergeDefaults(params, getDefaultParameters()); + + runCache(chunkX, chunkZ, world, spawnData); + + // now to ore spawn + + final int blockX = chunkX * 16 + 8; + final int blockZ = chunkZ * 16 + 8; + + + final int minHeight = params.get(Constants.FormatBits.MIN_HEIGHT).getAsInt(); + final int maxHeight = params.get(Constants.FormatBits.MAX_HEIGHT).getAsInt(); + final int variance = params.get(Constants.FormatBits.VARIATION).getAsInt(); + final int triesMin = params.get(Constants.FormatBits.ATTEMPTS_MIN).getAsInt(); + final int triesMax = params.get(Constants.FormatBits.ATTEMPTS_MAX).getAsInt(); + final int nodeSize = params.get(Constants.FormatBits.NODE_SIZE).getAsInt(); + final Fluid fluid = FluidRegistry.getFluid(params.get(Constants.FormatBits.FLUID).getAsString()); + + int tries = this.random.nextInt(triesMax - triesMin + 1) + triesMin; + int ySpan = maxHeight - minHeight; + int surveySize = ((256 * (16 * ySpan)) / 4) / 125; + BlockPos refBlock = new BlockPos(blockX, minHeight, blockZ); + Block fluidBlock = fluid.getBlock(); + + Set found = new HashSet<>(); + + int surveyCount = 0; + int spawnCount = 0; + + while(surveyCount < surveySize && spawnCount < tries) { + BlockPos sampleCenter = refBlock.add(this.random.nextInt(16), this.random.nextInt(ySpan), this.random.nextInt(16)); + BlockPos lowSide = sampleCenter.add(-2,-2,-2); + BlockPos highSide = sampleCenter.add(2,2,2); + Chunk chunk = world.getChunk(sampleCenter); + + if(!found.contains(sampleCenter)) { + found.addAll(findPossibleTargets(chunk, lowSide, highSide, fluidBlock, minHeight)); + + if(!found.isEmpty()) { + BlockPos target = found.toArray(new BlockPos[0])[this.random.nextInt(found.size())]; + spawnCount += maybeSpawn(target, minHeight, maxHeight, nodeSize, variance, world, spawnData); + } + surveyCount++; + } + } + } + + private int maybeSpawn(BlockPos target, int minHeight, int maxHeight, int nodeSize, + int variance, World world, ISpawnEntry spawnData) { + BlockPos mp = target; + while(world.getBlockState(mp).getMaterial().isLiquid() && mp.getY() >= minHeight) { + mp = mp.down(); + } + + if (mp.getY() > minHeight && mp.getY() < maxHeight) { + // calculate actual size for this node + int size = this.random.nextInt(nodeSize - variance + 1) + this.random.nextInt(variance); + // try to spawn now, as we do ***NOT*** want the node to wrap, we have to do this different... + // so... we copy vanilla spawn logic, to a degree, I think + spawnOre(world, spawnData, mp, size); + return 1; + } + + + return 0; + } + + private List findPossibleTargets(Chunk chunk, BlockPos lowSide, BlockPos highSide, + Block fluidBlock, int minHeight) { + return StreamSupport.stream(BlockPos.getAllInBoxMutable(lowSide, highSide).spliterator(), false) + .filter( bp -> chunk.getBlockState(bp).getMaterial().isLiquid() && + chunk.getBlockState(bp).getBlock().equals(fluidBlock) && + bp.getY() >= minHeight ) + .map(BlockPos.MutableBlockPos::toImmutable) + .collect(Collectors.toList()); + } + + private void spawnOre(final World world, final ISpawnEntry spawnData, final BlockPos pos, + final int quantity) { + int count = quantity; + final int lutType = (quantity < 8) ? offsetIndexRef_small.length : offsetIndexRef.length; + final int[] lut = (quantity < 8) ? offsetIndexRef_small : offsetIndexRef; + final Vec3i[] offs = new Vec3i[lutType]; + + System.arraycopy((quantity < 8) ? offsets_small : offsets, 0, offs, 0, lutType); + + if (quantity < 27) { + final int[] scrambledLUT = new int[lutType]; + System.arraycopy(lut, 0, scrambledLUT, 0, scrambledLUT.length); + scramble(scrambledLUT, this.random); + + while (count > 0) { + final IBlockState oreBlock = spawnData.getBlocks().getRandomBlock(random); + if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; + final BlockPos target = pos.add(offs[scrambledLUT[--count]]); + spawn(oreBlock, world, target, world.provider.getDimension(), true, spawnData); + } + + return; + } + + doSpawnFill(this.random.nextBoolean(), count, world, spawnData, pos); + } + + private void doSpawnFill(final boolean nextBoolean, final int quantity, final World world, + final ISpawnEntry spawnData, final BlockPos pos) { + final int count = quantity; + final double radius = Math.pow(quantity, 1.0 / 3.0) * (3.0 / 4.0 / Math.PI) + 2; + final int rSqr = (int) (radius * radius); + if (nextBoolean) { + spawnMungeNE(world, pos, rSqr, radius, spawnData, count); + } else { + spawnMungeSW(world, pos, rSqr, radius, spawnData, count); + } + } + + /* (non-Javadoc) + * @see com.mcmoddev.orespawn.api.IFeature#setRandom(java.util.Random) + */ + @Override + public void setRandom(Random rand) { + this.random = rand; + } + + /* (non-Javadoc) + * @see com.mcmoddev.orespawn.api.IFeature#getDefaultParameters() + */ + @Override + public JsonObject getDefaultParameters() { + final JsonObject defParams = new JsonObject(); + defParams.addProperty(Constants.FormatBits.MIN_HEIGHT, 0); + defParams.addProperty(Constants.FormatBits.MAX_HEIGHT, 256); + defParams.addProperty(Constants.FormatBits.VARIATION, 16); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MIN, 4); + defParams.addProperty(Constants.FormatBits.ATTEMPTS_MAX, 4); + defParams.addProperty(Constants.FormatBits.NODE_SIZE, 8); + defParams.addProperty(Constants.FormatBits.FLUID, "water"); + return defParams; + } + +} From ff57706fed51930daecee00a51b35ae058987141 Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:29:04 -0400 Subject: [PATCH 138/205] Update checkstyle.xml --- config/checkstyle/checkstyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 038f8213..833508da 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -53,7 +53,7 @@ have been changes/updates that we have not updated to. - Proxy --> - + From e0835865f8091dc9041913c1025842c5c5135eba Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:32:34 -0400 Subject: [PATCH 139/205] Update checkstyle.xml --- config/checkstyle/checkstyle.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 833508da..0a477167 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -51,12 +51,12 @@ - + < ---- > - + < ---- > + --> From 94fdb8c3ea097037d16892870490e5e46fc4278a Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:36:22 -0400 Subject: [PATCH 140/205] fix dumb --- config/checkstyle/checkstyle.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index 0a477167..7a3a620a 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -52,9 +52,9 @@ IDEA really dislikes it being in the checkstyle config at all, there may have been changes/updates that we have not updated to. - Proxy - < ---- > + < - -- - > - < ---- > + < - -- - > --> From 9924dbdf6cbd96b3301b803ed839b38f481cb8df Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Fri, 25 Jun 2021 01:36:40 -0400 Subject: [PATCH 141/205] Enable full stacktrace for github and jenkins --- .github/workflows/ci.yml | 4 ++-- Jenkinsfile | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72fbb317..7fc461d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,5 +20,5 @@ jobs: java-version: 8 - run: chmod a+x gradlew - run: ./gradlew --version --no-daemon - - run: ./gradlew setupCIWorkspace - - run: ./gradlew clean build + - run: ./gradlew setupCIWorkspace -S + - run: ./gradlew clean build -S diff --git a/Jenkinsfile b/Jenkinsfile index 859a0e31..a3081bfe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,21 +26,21 @@ pipeline { stage('CIWorkspace') { steps { withGradle { - sh './gradlew clean setupCiWorkspace' + sh './gradlew clean setupCiWorkspace -S' } } } stage('build') { steps { withGradle { - sh './gradlew build' + sh './gradlew build -S' } } } stage('test') { steps { withGradle { - sh './gradlew test' + sh './gradlew test -S' } } } @@ -48,7 +48,7 @@ pipeline { steps { withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { withGradle { - sh './gradlew publish' + sh './gradlew publish -S' } } } @@ -57,7 +57,7 @@ pipeline { steps { withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { withGradle { - sh './gradlew -x publish curseforge' + sh './gradlew -x publish curseforge -S' } } } @@ -72,7 +72,7 @@ pipeline { steps { // withCredentials([file(credentialsId: 'secret.json', variable: 'SECRET_FILE')]) { // withGradle { -// sh './gradlew sonarqube' +// sh './gradlew sonarqube -S' // } // } withSonarQubeEnv(installationName: 'SonarCloud', , envOnly: false) { From 5de732c0d65138c09ea9b8530efc6e332f6d3157 Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Fri, 6 Aug 2021 15:58:29 +0530 Subject: [PATCH 142/205] Update PluginLoader.java I don't believe the "loading integration" message should be fatal? --- .../java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java index 7af04f40..74a4c118 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java @@ -68,7 +68,7 @@ public void load(final FMLPreInitializationEvent event) { try { integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); final PluginData pd = new PluginData(modId, resourceBase, integration); - OreSpawn.LOGGER.fatal("Loading Integration For {}", modId); + OreSpawn.LOGGER.info("Loading Integration For {}", modId); dataStore.add(pd); } catch (final Exception ex) { OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); From e2517e19dc9d2f9a8fba2e5994fb194c3a510d43 Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Sat, 7 Aug 2021 10:53:03 +0530 Subject: [PATCH 143/205] Update FeatureBase.java fixes more accidental LOGGER.fatal()s also replaces (is block pos above build limit) with (is block pos valid) --- src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java index 5b067d60..b1eb04fb 100644 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java @@ -58,7 +58,7 @@ protected void runCache(final int chunkX, final int chunkZ, final World world, protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + OreSpawn.LOGGER.error("FeatureBase.spawn() called with a null ore!"); return false; } @@ -74,8 +74,8 @@ protected boolean spawn(final IBlockState oreBlock, final World world, final Blo final BlockPos np = mungeFixYcoord(coord); - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn {} above build limit at {}", oreBlock, coord); + if (world.isValid(coord)) { + OreSpawn.LOGGER.warn("Asked to spawn {} outside of world at {}", oreBlock, coord); return false; } @@ -136,7 +136,7 @@ private boolean spawnOrCache(final World world, final BlockPos coord, private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, final int dimension, final ISpawnEntry spawnData) { if (oreBlock == null) { - OreSpawn.LOGGER.fatal("FeatureBase.spawn() called with a null ore!"); + OreSpawn.LOGGER.error("FeatureBase.spawnNoCheck() called with a null ore!"); return; } From 5417f4a5ac6fd658c92c8664546380b54bfc98ff Mon Sep 17 00:00:00 2001 From: BalaM314 <71201189+BalaM314@users.noreply.github.com> Date: Sat, 7 Aug 2021 10:53:20 +0530 Subject: [PATCH 144/205] Update SpawnBuilder.java replaces a fatal() with an error() --- src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java index 2d9dac8a..25b6a18b 100644 --- a/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java +++ b/src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java @@ -219,7 +219,7 @@ public SpawnEntry create() { if (this.biomes == null) this.biomes = new BiomeBuilder().setAcceptAll().create(); if (this.replacements == null) this.replacements = com.mcmoddev.orespawn.OreSpawn.API.getReplacement("default"); if (this.feature == null) { - com.mcmoddev.orespawn.OreSpawn.LOGGER.fatal("Spawn entry {} does not have a stated feature, ignoring.", this.spawnName); + com.mcmoddev.orespawn.OreSpawn.LOGGER.error("Spawn entry {} does not have a stated feature, ignoring.", this.spawnName); return null; } return new SpawnEntry(this.spawnName, this.enabled, this.retrogen, this.dimensions, From d2d8c29a44250f86b13195459306967e2afecc9b Mon Sep 17 00:00:00 2001 From: JohnBraham Date: Sun, 19 Jul 2026 20:15:20 +0100 Subject: [PATCH 145/205] Port OreSpawn worldgen engine to Minecraft 1.18.2 --- .gitignore | 15 +- README.md | 180 +- build.gradle | 1264 +++---------- docs/AGENTS.md | 55 + docs/API.md | 79 + docs/CONFIGURATION.md | 40 + docs/DIMENSIONS.md | 31 + docs/FEATURES.md | 49 + docs/MIGRATION.md | 29 + docs/PROVIDERS.md | 46 + docs/README.md | 18 + docs/TEMPLATES.md | 17 + docs/TROUBLESHOOTING.md | 45 + docs/examples/examplemod-orespawn.json | 110 ++ docs/examples/orespawn-global.json | 59 + docs/examples/orespawn-world.json | 97 + docs/schemas/orespawn-global.schema.json | 12 + docs/schemas/orespawn-provider.schema.json | 56 + docs/schemas/orespawn-world.schema.json | 12 + docs/schemas/profile-common.schema.json | 218 +++ gradle.properties | 187 +- gradle/wrapper/gradle-wrapper.jar | Bin 54413 -> 60756 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 286 +-- gradlew.bat | 175 +- settings.gradle | 36 +- .../com/mcmoddev/orespawn/EventHandlers.java | 259 --- .../java/com/mcmoddev/orespawn/OreSpawn.java | 227 ++- .../com/mcmoddev/orespawn/OreSpawnConfig.java | 145 ++ .../mcmoddev/orespawn/api/BiomeLocation.java | 20 - .../orespawn/api/CompiledOrePattern.java | 11 + .../mcmoddev/orespawn/api/FeatureBase.java | 314 --- .../orespawn/api/FormationPreset.java | 21 + .../orespawn/api/GeologyAlgorithm.java | 17 + .../mcmoddev/orespawn/api/GeologyColumn.java | 18 + .../mcmoddev/orespawn/api/GeologyFamily.java | 19 + .../orespawn/api/GeologyProfileView.java | 71 + .../mcmoddev/orespawn/api/GeologySampler.java | 10 + .../com/mcmoddev/orespawn/api/IBlockList.java | 20 - .../mcmoddev/orespawn/api/IDimensionList.java | 12 - .../com/mcmoddev/orespawn/api/IFeature.java | 22 - .../orespawn/api/OreHeightDistribution.java | 17 + .../com/mcmoddev/orespawn/api/OrePattern.java | 28 + .../mcmoddev/orespawn/api/OrePatternType.java | 53 + .../orespawn/api/OrePlacementContext.java | 24 + .../mcmoddev/orespawn/api/OreSpawnApi.java | 56 + .../orespawn/api/OreSpawnGeologySampler.java | 136 ++ .../orespawn/api/OreSpawnOreIntegration.java | 51 + .../orespawn/api/OreSpawnPatternRegistry.java | 25 + .../mcmoddev/orespawn/api/ProviderStatus.java | 8 + .../orespawn/api/StandardPatternSettings.java | 39 + .../orespawn/api/WorldgenProvider.java | 1006 ++++++++++ .../exceptions/BadStateValueException.java | 13 - .../api/exceptions/BadValueException.java | 23 - .../exceptions/MissingVersionException.java | 10 - .../exceptions/NotAProperConfigException.java | 10 - .../api/exceptions/OldVersionException.java | 10 - .../api/exceptions/UnknownFieldException.java | 20 - .../api/exceptions/UnknownNameException.java | 23 - .../exceptions/UnknownVersionException.java | 10 - .../orespawn/api/os3/IBiomeBuilder.java | 25 - .../orespawn/api/os3/IBlockBuilder.java | 159 -- .../orespawn/api/os3/IBlockDefinition.java | 14 - .../orespawn/api/os3/IDimensionBuilder.java | 18 - .../orespawn/api/os3/IFeatureBuilder.java | 29 - .../orespawn/api/os3/IFeatureEntry.java | 21 - .../orespawn/api/os3/IReplacementBuilder.java | 82 - .../orespawn/api/os3/IReplacementEntry.java | 13 - .../orespawn/api/os3/ISpawnBuilder.java | 63 - .../orespawn/api/os3/ISpawnEntry.java | 46 - .../com/mcmoddev/orespawn/api/os3/OS3API.java | 71 - .../orespawn/api/os3/OS3FeatureGenerator.java | 6 - .../api/os3/OreSpawnBlockMatcher.java | 52 - .../orespawn/api/os3/package-info.java | 2 - .../mcmoddev/orespawn/api/package-info.java | 7 + .../orespawn/api/plugin/IOreSpawnPlugin.java | 8 - .../orespawn/api/plugin/OreSpawnPlugin.java | 24 - .../orespawn/api/plugin/PluginLoader.java | 166 -- .../client/AdvancedGeologySettingsScreen.java | 53 + .../client/BlockAssignmentScreen.java | 70 + .../orespawn/client/BlockPickerScreen.java | 129 ++ .../mcmoddev/orespawn/client/ClientSetup.java | 18 + .../orespawn/client/DimensionDiscovery.java | 92 + .../orespawn/client/GeologyEditorSession.java | 705 +++++++ .../client/GeologyMaterialsScreen.java | 161 ++ .../orespawn/client/GeomeBiomeScreen.java | 138 ++ .../orespawn/client/GeomeEntryScreen.java | 137 ++ .../orespawn/client/NumericConfigScreen.java | 180 ++ .../orespawn/client/OreDimensionScreen.java | 414 ++++ .../orespawn/client/OreEntryScreen.java | 206 ++ .../orespawn/client/OreRichnessPreset.java | 34 + .../orespawn/client/OreSpawnGuideScreen.java | 98 + .../orespawn/client/OreSpawnScreenLayout.java | 28 + .../client/OreSpawnWorldSettingsScreen.java | 314 +++ .../orespawn/client/RockEntryScreen.java | 183 ++ .../orespawn/client/WeightMapScreen.java | 123 ++ .../client/WorldCreationScreenHandler.java | 46 + .../orespawn/commands/AddOreCommand.java | 118 -- .../orespawn/commands/ClearChunkCommand.java | 161 -- .../orespawn/commands/DumpBiomesCommand.java | 62 - .../orespawn/commands/OreSpawnCommands.java | 85 + .../commands/WriteConfigsCommand.java | 31 - .../com/mcmoddev/orespawn/data/Config.java | 170 -- .../com/mcmoddev/orespawn/data/Constants.java | 109 -- .../orespawn/data/FeatureRegistry.java | 162 -- .../orespawn/data/PresetsStorage.java | 95 - .../orespawn/data/ReplacementsRegistry.java | 265 --- .../mcmoddev/orespawn/data/VanillaOres.java | 16 - .../impl/features/ClusterGenerator.java | 214 --- .../features/DefaultFeatureGenerator.java | 136 -- .../impl/features/NormalCloudGenerator.java | 182 -- .../impl/features/PrecisionGenerator.java | 294 --- .../orespawn/impl/features/UnderFluid.java | 209 -- .../orespawn/impl/features/VeinGenerator.java | 583 ------ .../impl/location/BiomeLocationAcceptAny.java | 25 - .../location/BiomeLocationComposition.java | 86 - .../location/BiomeLocationDictionary.java | 51 - .../impl/location/BiomeLocationEmpty.java | 21 - .../impl/location/BiomeLocationList.java | 60 - .../impl/location/BiomeLocationSingle.java | 50 - .../orespawn/impl/os3/BiomeBuilder.java | 99 - .../orespawn/impl/os3/BlockBuilder.java | 188 -- .../orespawn/impl/os3/BlockDefinition.java | 33 - .../mcmoddev/orespawn/impl/os3/BlockList.java | 65 - .../orespawn/impl/os3/DimensionBuilder.java | 76 - .../orespawn/impl/os3/DimensionList.java | 59 - .../impl/os3/DimensionListAcceptAll.java | 21 - .../os3/DimensionListAcceptAllOverworld.java | 25 - .../impl/os3/DimensionListDenyAll.java | 22 - .../orespawn/impl/os3/FeatureBuilder.java | 122 -- .../orespawn/impl/os3/FeatureEntry.java | 53 - .../orespawn/impl/os3/OS3APIImpl.java | 282 --- .../orespawn/impl/os3/ReplacementBuilder.java | 113 -- .../orespawn/impl/os3/ReplacementEntry.java | 42 - .../orespawn/impl/os3/SpawnBuilder.java | 231 --- .../orespawn/impl/os3/SpawnEntry.java | 107 -- .../com/mcmoddev/orespawn/init/Features.java | 29 + .../orespawn/init/OreSpawnPatterns.java | 249 +++ .../WorldgenIntegrationManager.java | 753 ++++++++ .../orespawn/json/OreSpawnReader.java | 447 ----- .../orespawn/json/OreSpawnWriter.java | 73 - .../mcmoddev/orespawn/util/Collectors2.java | 22 - .../com/mcmoddev/orespawn/util/StateUtil.java | 55 - .../orespawn/worldgen/BakedGeomeConfig.java | 684 +++++++ .../worldgen/BakedTerrainDimension.java | 52 + .../orespawn/worldgen/FlatBedrock.java | 87 - .../orespawn/worldgen/FlatBedrockFeature.java | 199 ++ .../orespawn/worldgen/FormationSettings.java | 116 ++ .../mcmoddev/orespawn/worldgen/Geology.java | 134 ++ .../worldgen/GeologyBlockAliases.java | 66 + .../orespawn/worldgen/GeomeConfig.java | 1681 +++++++++++++++++ .../worldgen/GeomeDistributionSampler.java | 580 ++++++ .../orespawn/worldgen/GeomeGeology.java | 326 ++++ .../worldgen/LegacyConfigMigrator.java | 367 ++++ .../orespawn/worldgen/OilDepositFeature.java | 295 +++ .../worldgen/OreHeightDistribution.java | 25 + .../orespawn/worldgen/OrePattern.java | 45 + .../orespawn/worldgen/OreRetrogenManager.java | 151 ++ .../worldgen/OreSpawnFeatureGenerator.java | 46 - .../worldgen/OreSpawnOreGeneration.java | 924 +++++++++ .../orespawn/worldgen/OreSpawnWorldGen.java | 30 - .../orespawn/worldgen/RockFamily.java | 24 + .../orespawn/worldgen/StoneReplacer.java | 163 ++ .../worldgen/VanillaOreFeatureGate.java | 262 +++ .../worldgen/WorldGeologyProfile.java | 374 ++++ .../worldgen/WorldGeologyProfileManager.java | 257 +++ .../orespawn/worldgen/WorldgenBenchmark.java | 116 ++ .../worldgen/math/CubicInterpolator.java | 214 +++ .../orespawn/worldgen/math/NoiseLayer2D.java | 67 + .../orespawn/worldgen/math/PerlinNoise2D.java | 81 + src/main/resources/META-INF/mods.toml | 64 + .../assets/orespawn/configs/_features.json | 26 - .../orespawn/configs/_replacements.json | 8 - .../assets/orespawn/configs/orespawn.json | 332 ---- .../resources/assets/orespawn/lang/de_au.json | 168 ++ .../resources/assets/orespawn/lang/de_de.json | 168 ++ .../resources/assets/orespawn/lang/en_ca.json | 168 ++ .../resources/assets/orespawn/lang/en_en.json | 168 ++ .../resources/assets/orespawn/lang/en_gb.json | 168 ++ .../resources/assets/orespawn/lang/en_pt.json | 168 ++ .../resources/assets/orespawn/lang/en_us.json | 168 ++ .../resources/assets/orespawn/lang/es_es.json | 168 ++ .../resources/assets/orespawn/lang/es_mx.json | 168 ++ .../resources/assets/orespawn/lang/fr_ca.json | 168 ++ .../resources/assets/orespawn/lang/fr_fr.json | 168 ++ .../resources/assets/orespawn/lang/ja_jp.json | 168 ++ .../resources/assets/orespawn/lang/ko_kr.json | 168 ++ .../resources/assets/orespawn/lang/pt_br.json | 168 ++ .../resources/assets/orespawn/lang/ru_ru.json | 168 ++ .../resources/assets/orespawn/lang/zh_cn.json | 168 ++ src/main/resources/mcmod.info | 15 - src/main/resources/pack.mcmeta | 10 +- .../orespawn/DocumentationJsonTest.java | 200 ++ .../orespawn/LocalizationParityTest.java | 69 + .../orespawn/api/WorldgenProviderTest.java | 144 ++ .../client/DimensionDiscoveryTest.java | 20 + .../client/GeologyEditorSessionTest.java | 31 + .../client/OreRichnessPresetTest.java | 28 + .../client/OreSpawnScreenLayoutTest.java | 23 + .../worldgen/BakedTerrainDimensionTest.java | 21 + .../orespawn/worldgen/BiomeDefaultsTest.java | 63 + .../worldgen/StableLayerTraversalTest.java | 28 + .../worldgen/WorldGeologyProfileTest.java | 242 +++ 203 files changed, 18653 insertions(+), 8877 deletions(-) create mode 100644 docs/AGENTS.md create mode 100644 docs/API.md create mode 100644 docs/CONFIGURATION.md create mode 100644 docs/DIMENSIONS.md create mode 100644 docs/FEATURES.md create mode 100644 docs/MIGRATION.md create mode 100644 docs/PROVIDERS.md create mode 100644 docs/README.md create mode 100644 docs/TEMPLATES.md create mode 100644 docs/TROUBLESHOOTING.md create mode 100644 docs/examples/examplemod-orespawn.json create mode 100644 docs/examples/orespawn-global.json create mode 100644 docs/examples/orespawn-world.json create mode 100644 docs/schemas/orespawn-global.schema.json create mode 100644 docs/schemas/orespawn-provider.schema.json create mode 100644 docs/schemas/orespawn-world.schema.json create mode 100644 docs/schemas/profile-common.schema.json delete mode 100644 src/main/java/com/mcmoddev/orespawn/EventHandlers.java create mode 100644 src/main/java/com/mcmoddev/orespawn/OreSpawnConfig.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/CompiledOrePattern.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/FormationPreset.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeologyAlgorithm.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeologyColumn.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeologyFamily.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeologyProfileView.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/GeologySampler.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/IBlockList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/IFeature.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OreHeightDistribution.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OrePattern.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OrePatternType.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OrePlacementContext.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OreSpawnApi.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OreSpawnGeologySampler.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OreSpawnOreIntegration.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/OreSpawnPatternRegistry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/ProviderStatus.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/StandardPatternSettings.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/WorldgenProvider.java delete mode 100755 src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java create mode 100644 src/main/java/com/mcmoddev/orespawn/api/package-info.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/AdvancedGeologySettingsScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/BlockAssignmentScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/BlockPickerScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/ClientSetup.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/DimensionDiscovery.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/GeologyEditorSession.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/GeologyMaterialsScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/GeomeBiomeScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/GeomeEntryScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/NumericConfigScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreDimensionScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreEntryScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreRichnessPreset.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreSpawnGuideScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreSpawnScreenLayout.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/OreSpawnWorldSettingsScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/RockEntryScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/WeightMapScreen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/client/WorldCreationScreenHandler.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/commands/AddOreCommand.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/commands/ClearChunkCommand.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/commands/DumpBiomesCommand.java create mode 100644 src/main/java/com/mcmoddev/orespawn/commands/OreSpawnCommands.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/commands/WriteConfigsCommand.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/Config.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/Constants.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/FeatureRegistry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/PresetsStorage.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/ReplacementsRegistry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/data/VanillaOres.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/ClusterGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/DefaultFeatureGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/NormalCloudGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/PrecisionGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/UnderFluid.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/features/VeinGenerator.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationAcceptAny.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationComposition.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationDictionary.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationEmpty.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/location/BiomeLocationSingle.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BiomeBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockDefinition.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/BlockList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionList.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAll.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListAcceptAllOverworld.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/DimensionListDenyAll.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/FeatureEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/OS3APIImpl.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/ReplacementEntry.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnBuilder.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/impl/os3/SpawnEntry.java create mode 100644 src/main/java/com/mcmoddev/orespawn/init/Features.java create mode 100644 src/main/java/com/mcmoddev/orespawn/init/OreSpawnPatterns.java create mode 100644 src/main/java/com/mcmoddev/orespawn/integration/WorldgenIntegrationManager.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/OreSpawnReader.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/json/OreSpawnWriter.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/util/Collectors2.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/util/StateUtil.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/BakedGeomeConfig.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/BakedTerrainDimension.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrock.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/FlatBedrockFeature.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/FormationSettings.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/Geology.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/GeologyBlockAliases.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/GeomeConfig.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/GeomeDistributionSampler.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/GeomeGeology.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/LegacyConfigMigrator.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OilDepositFeature.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreHeightDistribution.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OrePattern.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreRetrogenManager.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnFeatureGenerator.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnOreGeneration.java delete mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/OreSpawnWorldGen.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/RockFamily.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/StoneReplacer.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/VanillaOreFeatureGate.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/WorldGeologyProfile.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/WorldGeologyProfileManager.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/WorldgenBenchmark.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/math/CubicInterpolator.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/math/NoiseLayer2D.java create mode 100644 src/main/java/com/mcmoddev/orespawn/worldgen/math/PerlinNoise2D.java create mode 100644 src/main/resources/META-INF/mods.toml delete mode 100644 src/main/resources/assets/orespawn/configs/_features.json delete mode 100644 src/main/resources/assets/orespawn/configs/_replacements.json delete mode 100755 src/main/resources/assets/orespawn/configs/orespawn.json create mode 100644 src/main/resources/assets/orespawn/lang/de_au.json create mode 100644 src/main/resources/assets/orespawn/lang/de_de.json create mode 100644 src/main/resources/assets/orespawn/lang/en_ca.json create mode 100644 src/main/resources/assets/orespawn/lang/en_en.json create mode 100644 src/main/resources/assets/orespawn/lang/en_gb.json create mode 100644 src/main/resources/assets/orespawn/lang/en_pt.json create mode 100644 src/main/resources/assets/orespawn/lang/en_us.json create mode 100644 src/main/resources/assets/orespawn/lang/es_es.json create mode 100644 src/main/resources/assets/orespawn/lang/es_mx.json create mode 100644 src/main/resources/assets/orespawn/lang/fr_ca.json create mode 100644 src/main/resources/assets/orespawn/lang/fr_fr.json create mode 100644 src/main/resources/assets/orespawn/lang/ja_jp.json create mode 100644 src/main/resources/assets/orespawn/lang/ko_kr.json create mode 100644 src/main/resources/assets/orespawn/lang/pt_br.json create mode 100644 src/main/resources/assets/orespawn/lang/ru_ru.json create mode 100644 src/main/resources/assets/orespawn/lang/zh_cn.json delete mode 100644 src/main/resources/mcmod.info create mode 100644 src/test/java/com/mcmoddev/orespawn/DocumentationJsonTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/LocalizationParityTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/api/WorldgenProviderTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/client/DimensionDiscoveryTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/client/GeologyEditorSessionTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/client/OreRichnessPresetTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/client/OreSpawnScreenLayoutTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/worldgen/BakedTerrainDimensionTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/worldgen/BiomeDefaultsTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/worldgen/StableLayerTraversalTest.java create mode 100644 src/test/java/com/mcmoddev/orespawn/worldgen/WorldGeologyProfileTest.java diff --git a/.gitignore b/.gitignore index a143318e..691b6184 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ bin *.launch .settings +.settings/* .metadata .classpath .project @@ -20,17 +21,21 @@ build # other eclipse run +/run.* +/*.log classes -*.hprof +logs + +# local agent context +/AGENTS.md +/agent-notes/ +/.codex/ +/CLAUDE.md /README.txt /forge-*-changelog.txt secret.json libs/* -!/libs/README.txt .DS_Store -.DS_Store/* -.okhttpcache/* -OS3 API Redesign Notes.txt diff --git a/README.md b/README.md index 63a51fc0..c19ee454 100644 --- a/README.md +++ b/README.md @@ -1,152 +1,38 @@ -[![](https://img.shields.io/badge/Discord-MMD-green.svg?style=flat&logo=Discord)](https://discord.mcmoddev.com) -[![](http://cf.way2muchnoise.eu/full_mmd-orespawn_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) -[![](http://cf.way2muchnoise.eu/versions/Minecraft_mmd-orespawn_all.svg)](https://www.curseforge.com/minecraft/mc-mods/mmd-orespawn) -[![Build Status](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/badge/icon)](https://ci.mcmoddev.com/job/OreSpawn/job/OreSpawn%201.12/) +# MMD OreSpawn -# OreSpawn -Minecraft library mod that provides better control over the spawning of ores in Minecraft. -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. +OreSpawn 4 is a provider-driven Minecraft 1.18.2 world-generation engine. It +can place ores using six built-in patterns, build configurable geological +strata and geomes, flatten bedrock, and perform bounded ore retrogen. Installed +mods provide blocks and declarative rules; OreSpawn keeps registry and config +work out of chunk-generation loops. -## How it works -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: +This is not the unrelated mod that adds mobs and dimensions under the same +name. -```json -[ - { - "dimension": -1, - "ores": [ - { - "block": "minecraft:quartz_ore", - "size": 15, - "variation": 4, - "frequency": 7, - "min_height": 0, - "max_height": 128 - } - ] - }, - { - "ores": [ - { - "block": "minecraft:coal_ore", - "size": 25, - "variation": 12, - "frequency": 20, - "min_height": 0, - "max_height": 128 - }, - { - "block": "minecraft:iron_ore", - "size": 8, - "variation": 4, - "frequency": 20, - "min_height": 0, - "max_height": 64 - }, - { - "block": "minecraft:gold_ore", - "size": 8, - "variation": 2, - "frequency": 2, - "min_height": 0, - "max_height": 32 - }, - { - "block": "minecraft:diamond_ore", - "size": 6, - "variation": 3, - "frequency": 8, - "min_height": 0, - "max_height": 16 - }, - { - "block": "minecraft:lapis_ore", - "size": 5, - "variation": 2, - "frequency": 1, - "min_height": 0, - "max_height": 32 - }, - { - "block": "minecraft:emerald_ore", - "size": 1, - "variation": 0, - "frequency": 8, - "min_height": 4, - "max_height": 32, - "biomes": [ - "minecraft:extreme_hills", - "minecraft:smaller_extreme_hills" - ] - }, - { - "block": "minecraft:dirt", - "size": 112, - "variation": 50, - "frequency": 10, - "min_height": 0, - "max_height": 255 - }, - { - "block": "minecraft:gravel", - "size": 112, - "variation": 50, - "frequency": 8, - "min_height": 0, - "max_height": 255 - }, - { - "block": "minecraft:stone", - "state": "variant=granite", - "size": 112, - "variation": 50, - "frequency": 10, - "min_height": 0, - "max_height": 255 - }, - { - "block": "minecraft:stone", - "state": "variant=diorite", - "size": 112, - "variation": 50, - "frequency": 10, - "min_height": 0, - "max_height": 255 - }, - { - "block": "minecraft:stone", - "state": "variant=andesite", - "size": 112, - "variation": 50, - "frequency": 10, - "min_height": 0, - "max_height": 255 - } - ] - } -] -``` +OreSpawn is intentionally passive when installed alone. Terrain replacement, +ore suppression, retrogen, and flat bedrock are opt-in. Mineralogy 6 is the +first full provider and supplies its rocks, ores, oil, geomes, and defaults in +`data/mineralogy/orespawn/provider.json`. + +## Integration + +- Global pack profile: `config/orespawn-worldgen.json` +- Per-world snapshot: `/serverconfig/orespawn-worldgen.json` +- Pack provider override: `config/-orespawn.json` +- Packaged provider: `data//orespawn/provider.json` +- Supported Java API: `com.mcmoddev.orespawn.api`, API major `1` + +Documentation, schemas, and examples are in [`docs`](docs/README.md). The same +material is packaged under `META-INF/orespawn/docs` in the normal jar, with an +agent-oriented entry point at jar-root `AGENTS.md`. -### dimension -The number ID of a dimension. Don't specify any dimension to target all dimensions *that are not already specified*. -### ores -Array of JSON objects specifying ore generators for this dimension -### block -Text ID of a block (the same you would use in the /give command) -### state -The state of a block (typically used for colored blocks) -### size -The number of blocks to spawn. Unlike the default Minecraft world settings JSON, this is the actually number of blocks that will spawn. -### variation -How much to randomly vary the number of blocks spawned (I recommend making this value 50% of the *size* value) -### frequency -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. -### min_height -The lowest Y-coordinate that the ore is allowed to spawn at -### max_height -The highest Y-coordinate that the ore is allowed to spawn at -### biomes -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. +## Building + +Use Java 17 and run from this checkout: + +```powershell +.\gradlew.bat test build --no-daemon +.\gradlew.bat genEclipseRuns eclipse --no-daemon +``` -# API -Adding OreSpawn support to your mod is not hard. Look at `VanillaOreSpawn.java` for an example. +OreSpawn is licensed under LGPL-2.1. diff --git a/build.gradle b/build.gradle index 3791a395..7f4ea7d5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,1013 +1,377 @@ -buildscript { - repositories { - mavenLocal() - jcenter() - mavenCentral() - removeIf { it instanceof MavenArtifactRepository && it.url.host == 'files.minecraftforge.net' } - maven { - name = 'forge' - url = 'https://maven.minecraftforge.net/' - } - maven { - name = 'gradle' - url 'https://plugins.gradle.org/m2/' - } - maven { - name = 'sonatype' - url = 'https://oss.sonatype.org/content/groups/public' - } - } - dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: project.fg_version - if (GradleVersion.current() <= GradleVersion.version('3.3')) { -// classpath group: 'com.jaredsburrows', name: 'gradle-checker-framework-plugin', version: '0.2.1' - } - } -} - plugins { - id 'com.gradle.build-scan' version '1.16' -// id 'com.jaredsburrows.checkerframework' version '0.2.2'// 3.4/4.0 or later - id 'com.github.spotbugs' version '1.6.9' // 4.0 or later - id 'com.matthewprenger.cursegradle' version '1.4.0' - id 'org.sonarqube' version '3.3' - id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.66' -//id 'org.junit.platform.gradle.plugin' version '1.2.0' // 3.5 through 4.5 - id 'maven-publish' - id 'jacoco' - id 'checkstyle' // 2.7 or later -} - -if (isFG1()) { - apply plugin: 'forge' -}else if (isFG2()) { - apply plugin: 'net.minecraftforge.gradle.forge' -} else { - apply plugin: 'net.minecraftforge.gradle' -} -if (gradleOlderThan('3.4')) { -// apply plugin: 'com.jaredsburrows.checkerframework' -} -apply plugin: 'eclipse' -apply plugin: 'idea' -apply plugin: 'maven-publish' -apply plugin: 'pmd' -import org.gradle.util.GradleVersion -if (gradleOlderThan('4.0')) { - apply plugin: 'findbugs' + id 'eclipse' + id 'idea' + id 'maven-publish' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' } -buildScan { - if (System.getenv('CI')) { - publishAlways() - } -//publishAlwaysIf(System.getenv("CI")) - licenseAgreementUrl = 'https://gradle.com/terms-of-service'; - licenseAgree = 'yes' -} +version = mod_version +group = mod_group_id -project.afterEvaluate { - //final def junitPlatformTestTask = project.tasks.getByName('junitPlatformTest') - - // configure jacoco to analyze the junitPlatformTest task - jacoco { - // this tool version is compatible with - toolVersion = '0.8.3' // 0.8.3 uses ASM 7.0.4, 0.8.4 uses ASM 7.1, 0.8.6 uses ASM 8.0.1, 0.8.7 uses ASM 9.1 - // Not needed with new way - //if (gradleOlderThan('4.6')) { - //applyTo junitPlatformTestTask - //}} - } - - // create junit platform jacoco task - project.task(type: JacocoReport, 'junitPlatformJacocoReport', - { - if (gradleNewerThan('5.0')) { - getSourceDirectories().from(files('./src/main')) - getClassDirectories().from(files("${project.buildDir}/classes/main")) - } else { - sourceDirectories = files('./src/main') - classDirectories = files("${project.buildDir}/classes/main") - } - // Not needed with new way - //if (gradleOlderThan('4.6')) { - // executionData junitPlatformTestTask - //} - }) +base { + archivesName = "OreSpawn-${minecraft_version}" } -// Only works with JUnit Platform Launcher 1.2.0 and earlier -/* -if (gradleOlderThan('4.6')) { - junitPlatform { - // platformVersion '1.2.0' - // logManager 'org.apache.logging.log4j.jul.LogManager' - reportsDir file("${project.buildDir}/test-results/junit-platform") - // enableStandardTestTask true - // selectors (optional) - // filters (optional) - } -} -*/ - -if (gradleNewerThan('4.0')) { - spotbugs { - ignoreFailures = true - toolVersion = '3.1.7' // 3.1.7 uses ASM 6.2, 3.1.8 uses ASM 6.2.1 - effort = 'max' - reportLevel = 'low' - //includeFilter = file("$rootProject.projectDir/config/spotbugs-filter.xml") - } - - tasks.withType(com.github.spotbugs.SpotBugsTask) { - reports { - if (isCi()) { - xml.enabled = true - html.enabled = false - } else { - xml.enabled = false - html.enabled = true - } - } - } -} else { - findbugs { - toolVersion = "3.0.1" // Required for Java 8 -// toolVersion = "2.0.3" // Required for Java ? -// toolVersion = "1.3.9" // Required for Java ? - } +// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. +java { + toolchain.languageVersion = JavaLanguageVersion.of(17) + withSourcesJar() + withJavadocJar() } -if (GradleVersion.current() >= GradleVersion.version('2.7')) { - checkstyle { - ignoreFailures = true - if (gradleNewerThan('2.7')) { - toolVersion = '8.23' // 8.42 - } else { - toolVersion = '6.7' - } - showViolations = false - } -} +println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" +minecraft { + // The mappings can be changed at any time and must be in the following format. + // Channel: Version: + // official MCVersion Official field/method names from Mojang mapping files + // parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official + // + // You must be aware of the Mojang license when using the 'official' or 'parchment' mappings. + // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md + // + // Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge + // Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started + // + // Use non-default mappings at your own risk. They may not always work. + // Simply re-run your setup task after changing the mappings to update your workspace. + mappings channel: mapping_channel, version: mapping_version + + // When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game. + // In most cases, it is not necessary to enable. + // enableEclipsePrepareRuns = true + // enableIdeaPrepareRuns = true + + // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. + // It is REQUIRED to be set to true for this template to function. + // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html + copyIdeResources = true + + // When true, this property will add the folder name of all declared run configurations to generated IDE run configurations. + // The folder name can be set on a run configuration using the "folderName" property. + // By default, the folder name of a run configuration is the name of the Gradle project containing it. + // generateRunFolders = true + + // This property enables access transformers for use in development. + // They will be applied to the Minecraft artifact. + // The access transformer file can be anywhere in the project. + // However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge. + // This default location is a best practice to automatically put the file in the right place in the final jar. + // See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information. + // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + + // Default run configurations. + // These can be tweaked, removed, or duplicated as needed. + runs { + // applies to all the run configs below + configureEach { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + // The markers can be added/remove as needed separated by commas. + // "SCAN": For mods scan. + // "REGISTRIES": For firing of registry events. + // "REGISTRYDUMP": For getting the contents of all registries. + property 'forge.logging.markers', 'REGISTRIES' + + // Recommended logging level for the console + // You can set various levels here. + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels + property 'forge.logging.console.level', 'debug' + + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. + property 'forge.enabledGameTestNamespaces', mod_id + + mods { + orespawn { + source sourceSets.main + } + } + } -pmd { - if (gradleNewerThan('2.1')) { - consoleOutput = false - } - ignoreFailures = true - sourceSets = [sourceSets.main] - reportsDir = file("$project.buildDir/reports/pmd") - if (gradleNewerThan('2.8')) { - rulePriority = 5 - } - ruleSets = [ - 'java-android', - 'java-basic', - 'java-braces', - 'java-clone', - 'java-codesize', - 'java-comments', - 'java-controversial', - 'java-coupling', - 'java-design', - 'java-empty', - 'java-finalizers', - 'java-imports', - 'java-j2ee', - 'java-javabeans', - 'java-junit', - 'java-logging-jakarta-commons', - 'java-logging-java', -// 'java-metrics', // Upsets 5.8.1 - 'java-migrating', - 'java-migrating_to_junit4', - 'java-naming', - 'java-optimizations', -// 'java-quickstart', // 6.x - 'java-strictexception', - 'java-strings', - 'java-sunsecure', - 'java-typeresolution', - 'java-unnecessary', - 'java-unusedcode' - ] - if (gradleNewerThan('2.3')) { - toolVersion = '5.8.1'; // 6.0.1, 6.34.0 - } else { - toolVersion = '5.1.3'; - } - if (gradleNewerThan('5.6')) { -// incrementalAnalysis = true // Requires PMD 6.0.0 or newer - } -} + client { + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. + property 'forge.enabledGameTestNamespaces', mod_id + } -tasks.withType(JavaCompile) { - options.encoding = 'UTF-8' - options.compilerArgs = [ - '-Xlint:deprecation', // deprecation, rawtypes, cast, unchecked, all - //'-Xdiags:verbose', - //'-Werror' - ] - compileJava.options.compilerArgs += '-proc:none' -} + server { + property 'forge.enabledGameTestNamespaces', mod_id + args '--nogui' + } -tasks.withType(Test) { - compileTestJava.options.compilerArgs += '-proc:none' -} + // This run config launches GameTestServer and runs all registered gametests, then exits. + // By default, the server will crash when no gametests are provided. + // The gametest system is also enabled by default for other run configs under the /test command. + gameTestServer { + property 'forge.enabledGameTestNamespaces', mod_id + if (providers.gradleProperty('orespawnBenchmarkMode').isPresent()) { + property 'orespawn.worldgenBenchmarkMode', providers.gradleProperty('orespawnBenchmarkMode').get() + property 'orespawn.worldgenBenchmarkRadius', + providers.gradleProperty('orespawnBenchmarkRadius').getOrElse('4') + property 'orespawn.worldgenBenchmarkRepetitions', + providers.gradleProperty('orespawnBenchmarkRepetitions').getOrElse('3') + property 'orespawn.worldgenBenchmarkVanillaOres', + providers.gradleProperty('orespawnBenchmarkVanillaOres').getOrElse('false') + } + } -javadoc { - failOnError = false -} + data { + // example of overriding the workingDirectory set in configureEach above + workingDirectory project.file('run-data') -test { - if (gradleNewerThan('4.6')) { - useJUnitPlatform() - /* - useJUnitPlatform { - includeTags 'fast', 'smoke & feature-a' - //excludeTags 'slow', 'ci' - includeEngines 'junit-jupiter' - //excludeEngines 'junit-vintage' + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. + args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + } } - */ - } -} - -//project.ext.short_version = '1.0.0' -project.ext.short_version = getModVersion('VERSION', 'src/main/java/com/mcmoddev/orespawn/data/Constants.java') -//project.ext.short_version = getModVersion('VERSION') -version = (project.hasProperty('mc_version') ? project.mc_version : project.forge_mc_version) + '-' + short_version -project.ext.display_version = short_version - -if ((System.getenv('BUILD_NUMBER')) || (System.getenv('TRAVIS_BUILD_NUMBER')) || (System.getenv('CIRCLE_BUILD_NUM'))) { - version += '.' + buildNumber - display_version += '.' + buildNumber } -static String getBuildNumber() { - return System.getenv('BUILD_NUMBER') ?: System.getenv('TRAVIS_BUILD_NUMBER') ?: System.getenv('CIRCLE_BUILD_NUM') ?: '0' -} +// Include resources generated by data generators. +sourceSets.main.resources { srcDir 'src/generated/resources' } -sourceCompatibility = JavaVersion.VERSION_1_8 -targetCompatibility = JavaVersion.VERSION_1_8 -compileJava.sourceCompatibility = JavaVersion.VERSION_1_8 -compileJava.targetCompatibility = JavaVersion.VERSION_1_8 +repositories { + // Put repositories for dependencies here + // ForgeGradle automatically adds the Forge maven and Maven Central for you -eclipse.project { - buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder' - natures 'org.eclipse.buildship.core.gradleprojectnature' + // If you have mod jar dependencies in ./libs, you can declare them as a repository like so: + // flatDir { + // dir 'libs' + // } } -idea.module { - downloadJavadoc = true - //inheritOutputDirs = true -} +dependencies { + // Specify the version of Minecraft to use. + // Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact. + // The "userdev" classifier will be requested and setup by ForgeGradle. + // If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"], + // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. + minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" -class Secrets { - Map m_data = null + testImplementation platform('org.junit:junit-bom:5.10.2') + testImplementation 'org.junit.jupiter:junit-jupiter' - final String getProperty(final String key) { - return (m_data && (m_data[key] != null)) ? m_data[key] : '' - } -} + // Real mod deobf dependency examples - these get remapped to your current mappings + // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency + // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency + // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency -final def secretFile -if (System.getenv('SECRET_FILE')) { - secretFile = file System.getenv().SECRET_FILE -} else { - secretFile = file 'secret.json' -} + // Example mod dependency using a mod jar from ./libs with a flat dir repository + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar + // The group id is ignored when searching -- in this case, it is "blank" + // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}") -import groovy.json.JsonSlurper -project.ext.secret = new Secrets() -if (secretFile.exists()) { - secretFile.withReader { - project.secret.m_data = new JsonSlurper().parse it - } -} else { - project.secret.m_data = new JsonSlurper().parseText( - '{ "username" : "' + (System.getenv('userMaven') ?: '') + '",' - + '"password" : "' + (System.getenv('authMaven') ?: '') + '",' - + '"url" : "' + (System.getenv('urlMaven') ?: '') + '",' - + '"curseforgeAPIKey" : "' + (System.getenv('curse_auth') ?: '00000000-0000-0000-0000-000000000000') + '",' - + '"sonarHost" : "' + (System.getenv('SONAR_HOST_URL') ?: 'https://sonarcloud.io') + '",' - + '"sonarOrganization" : "' + (System.getenv('SONAR_ORGANIZATION') ?: '') + '",' - + '"sonarToken" : "' + (System.getenv('SONAR_TOKEN') ?: 0) + '"}' - ) + // For more info: + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html } -minecraft { - version = project.forge_mc_version + '-' + project.forge_version - if ((project.forge_mc_version != "1.6.4") && (project.forge_mc_version != "1.7.2")) { - mappings = project.mcp_mappings_version - } - - if ((project.fg_version != '1.0-SNAPSHOT') && (project.fg_version != '1.1-SNAPSHOT')) { - if (project.hasProperty('runDir')) { - runDir = project.runDir - } else if (file('../run').exists()) { - runDir = '../run' - } else { - runDir = 'run' - } - } else { - if (project.hasProperty('runDir')) { - assetDir = project.runDir - } else if (file('../assets').exists()) { - assetDir = '../assets' - } else { - assetDir = 'eclipse/assets' +// Example for how to get properties into the manifest for reading at runtime. +tasks.named('jar', Jar).configure { + manifest { + attributes([ + 'Specification-Title' : 'OreSpawn', + 'Specification-Vendor' : 'SkyBlade1978', + 'Specification-Version' : '1', // We are version 1 of ourselves + 'Implementation-Title' : project.name, + 'Implementation-Version' : project.jar.archiveVersion, + 'Implementation-Vendor' : 'SkyBlade1978', + 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), + 'OreSpawn-API-Version' : '1' + ]) } - } - replace '@MOD_VERSION@', project.short_version - - if (project.hasProperty('signSHA1') && getBooleanProperty('do_sign_jar') && isFG2()) { - replace '@FINGERPRINT@', project.findProperty('signSHA1') - } else { - replace '@FINGERPRINT@', '' - } - - if (project.hasProperty('core_plugin')) { - clientJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}" - serverJvmArgs += "-Dfml.coreMods.load=${project.core_plugin}" - } - - if (project.hasProperty('mc_username')) { - clientRunArgs += ['--username', project.mc_username] - if (project.hasProperty('mc_password')) { - clientRunArgs += ['--password', project.mc_password] + from('docs/AGENTS.md') { + into '' + rename { 'AGENTS.md' } } - } - if (project.hasProperty('mc_uuid')) { - clientRunArgs += ['--uuid', project.mc_uuid] - } - - if (getBooleanProperty('mc_server_nogui')) { - serverRunArgs += 'nogui' - } - - if (getBooleanProperty('forge_do_not_backup')) { - serverJvmArgs += '-Dfml.doNotBackup=true' - clientJvmArgs += '-Dfml.doNotBackup=true' - } - - if (getBooleanProperty('forge_query_result_confirm')) { - serverJvmArgs += '-Dfml.queryResult=confirm' - } - - if (getBooleanProperty('log4j_skip_jansi')) { - serverJvmArgs += '-Dlog4j.skipJansi=true' - clientJvmArgs += '-Dlog4j.skipJansi=true' - } - - if (project.hasProperty('mc_resolution')) { - final def res = [ - '480p': [640, 480], - '576p': [640, 576], - '720p': [1280, 720], - '1080p': [1920, 1080], - 'custom': [project.findProperty('mc_custom_resolution_width'), project.findProperty('mc_custom_resolution_height')]] - final def choice = res?.get(project.mc_resolution) - if (choice != null) { - clientRunArgs += ['--width', choice[0]] - clientRunArgs += ['--height', choice[1]] + from('docs') { + into 'META-INF/orespawn/docs' } - } - - if (project.hasProperty('client_jvm_args')) { - clientJvmArgs += project.client_jvm_args - } - if (project.hasProperty('server_jvm_args')) { - serverJvmArgs += project.server_jvm_args - } - - if (project.hasProperty('client_game_args')) { - clientRunArgs += project.client_game_args - } - if (project.hasProperty('server_game_args')) { - serverRunArgs += project.server_game_args - } - - if (isFG2()) { - makeObfSourceJar = getBooleanProperty('create_source_jar') - - useDepAts = getBooleanProperty('dep_has_ats') - } -} -repositories { - mavenLocal() - jcenter() - mavenCentral() - - maven { - name 'MMD' - url 'https://maven.mcmoddev.com/' - } + // This is the preferred method to reobfuscate your jar file + finalizedBy 'reobfJar' } -dependencies { - testCompile('org.junit.platform:junit-platform-launcher:1.7.+') - testCompile('org.junit.jupiter:junit-jupiter-api:5.7.+') // testImplementation - testRuntime('org.junit.jupiter:junit-jupiter-engine:5.7.+') //testRuntimeOnly - if (gradleNewerThan('2.13')) { - testCompileOnly 'junit:junit:4.13.2' - } - testRuntime 'org.junit.vintage:junit-vintage-engine:5.7.+' //testRuntimeOnly - testCompile('org.mockito:mockito-core:2.+') - testCompile('org.mockito:mockito-junit-jupiter:2.+') { - exclude group: 'org.junit.jupiter', module: 'junit-jupiter-engine' - } - if (gradleNewerThan('4.6')) { - annotationProcessor group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0' - } -} - -processResources { - inputs.property 'version', project.short_version - inputs.property 'mcversion', project.minecraft.version - - from (sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - expand 'version': project.short_version, 'mcversion': project.minecraft.version - } +// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing: +// tasks.named('publish').configure { +// dependsOn 'reobfJar' +// } - from (sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } - - rename '(.+_at.cfg)', 'META-INF/$1' -} - -jar { - //from sourceSets.api.output - //from sourceSets.main.output - - manifest { - mainAttributes( - 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}", - 'Timestamp': System.currentTimeMillis(), - 'Specification-Title': project.modid, - 'Specification-Vendor': project.vendor, - 'Specification-Version': '1', - 'Implementation-Title': project.archivesBaseName, - 'Implementation-Version': project.version, - 'Implementation-Vendor' : project.vendor, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Built-On': "${project.forge_mc_version}-${project.forge_version}" - ) - if (project.hasProperty('core_plugin')) { - attributes 'FMLCorePluginContainsFMLMod': 'true' - attributes 'FMLCorePlugin': project.core_plugin - } - if (project.hasProperty('mod_at_file')) { - attributes 'FMLAT': project.mod_at_file +publishing { + publications { + register('mavenJava', MavenPublication) { + artifact jar + artifact sourcesJar + artifact javadocJar + } } - if (project.hasProperty('mod_contained_deps')) { - attributes 'ContainedDeps': project.mod_contained_deps + repositories { + maven { + url "file://${project.projectDir}/mcmodsrepo" + } } - } -} - -task apiJar(type: Jar) { - onlyIf { - getBooleanProperty('create_api_jar') - } - - description = 'Creates a JAR containing the API Classes.' - classifier = 'api' - //from apiClasses - // from sourceSets.api.output - from sourceSets.main.allSource - exclude('com/mcmoddev/orespawn/impl/**') - exclude('com/mcmoddev/orespawn/impl/features/**') - exclude('com/mcmoddev/orespawn/json/**') - exclude('com/mcmoddev/orespawn/world/**') - exclude('com/mcmoddev/orespawn/commands/**') - exclude('com/mcmoddev/orespawn/data/**') - exclude('com/mcmoddev/orespawn/*.java') - manifest { - mainAttributes( - 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:api", - 'Timestamp': System.currentTimeMillis(), - 'Specification-Title': project.modid, - 'Specification-Vendor': project.vendor, - 'Specification-Version': '1', - 'Implementation-Title': project.archivesBaseName + '-api', - 'Implementation-Version': project.version, - 'Implementation-Vendor' : project.vendor, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Built-On': "${project.forge_mc_version}-${project.forge_version}" - ) - } } -task devJar(type: Jar) { - classifier = 'dev' - from sourceSets.main.output -} - -task deobfJar(type: Jar) { - onlyIf { - getBooleanProperty('create_deobf_jar') - } - - description = 'Creates a JAR containing the non-obfuscated compiled code.' - classifier = 'deobf' - from sourceSets.main.output - manifest { - mainAttributes( - 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:deobf", - 'Timestamp': System.currentTimeMillis(), - 'Specification-Title': project.modid, - 'Specification-Vendor': project.vendor, - 'Specification-Version': '1', - 'Implementation-Title': project.archivesBaseName + '-deobf', - 'Implementation-Version': project.version, - 'Implementation-Vendor' : project.vendor, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Built-On': "${project.forge_mc_version}-${project.forge_version}" - ) - if (project.hasProperty('mod_at_file')) { - attributes 'FMLAT': project.mod_at_file - } - if (project.hasProperty('core_plugin')) { - attributes 'FMLCorePlugin': project.core_plugin - } - } +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation } -task javadocJar(type: Jar, dependsOn: javadoc) { - onlyIf { - getBooleanProperty('create_javadoc_jar') - } - - description = 'Creates a JAR containing the JavaDocs.' - classifier = 'javadoc' - from javadoc.getDestinationDir() - manifest.mainAttributes( - 'Maven-Artifact': "${project.group}:${project.archivesBaseName}:${project.version}:javadoc", - 'Timestamp': System.currentTimeMillis(), - 'Specification-Title': project.modid, - 'Specification-Vendor': project.vendor, - 'Specification-Version': '1', - 'Implementation-Title': project.archivesBaseName + '-javadoc', - 'Implementation-Version': project.version, - 'Implementation-Vendor' : project.vendor, - 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'Built-On-Java': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})", - 'Built-On': "${project.forge_mc_version}-${project.forge_version}" - ) +tasks.named('javadoc', Javadoc).configure { + options.encoding = 'UTF-8' + options.addStringOption('Xdoclint:none', '-quiet') } -if (isFG1()) { -// def signType = Jar -} else if (isFG2()) { -// def signType = SignJar - - task signJar(type: SignJar, dependsOn: reobfJar) { - onlyIf { - getBooleanProperty('do_sign_jar') && - project.hasProperty('keyStore') - } - - description = 'Sign the Main JAR' - inputFile = jar.archivePath - outputFile = jar.archivePath - - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - } - - task signApiJar(type: SignJar) { - onlyIf { - getBooleanProperty('create_api_jar') && - getBooleanProperty('do_sign_jar') && - project.hasProperty('keyStore') - } - - description = 'Sign the API JAR' - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - - inputFile = apiJar.archivePath - outputFile = apiJar.archivePath - } - - task signDeobfJar(type: SignJar) { - onlyIf { - getBooleanProperty('create_deobf_jar') && - getBooleanProperty('do_sign_jar') && - project.hasProperty('keyStore') - } - - description = 'Sign the deobf JAR' - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - - inputFile = deobfJar.archivePath - outputFile = deobfJar.archivePath - } - - task signSourceJar(type: SignJar) { - onlyIf { - getBooleanProperty('create_source_jar') && - getBooleanProperty('do_sign_jar') && - project.hasProperty('keyStore') - } - - description = 'Sign the Sources JAR' - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - - inputFile = sourceJar.archivePath - outputFile = sourceJar.archivePath - } - - task signJavadocJar(type: SignJar) { - onlyIf { - getBooleanProperty('create_javadoc_jar') && - getBooleanProperty('do_sign_jar') && - project.hasProperty('keyStore') - } - - keyStore = project.findProperty('keyStore') - alias = project.findProperty('keyStoreAlias') - storePass = project.findProperty('keyStorePass') - keyPass = project.findProperty('keyStoreKeyPass') - - inputFile = javadocJar.archivePath - outputFile = javadocJar.archivePath - } -} - -if (getBooleanProperty('do_sign_jar') && (!isFG1())) { - build.dependsOn signJar - if (getBooleanProperty('create_api_jar')) { - build.dependsOn signApiJar - } - if (getBooleanProperty('create_deobf_jar')) { - build.dependsOn signDeobfJar - } - if (getBooleanProperty('create_source_jar')) { - build.dependsOn signSourceJar - } - if (getBooleanProperty('create_javadoc_jar')) { - build.dependsOn signJavadocJar - } +tasks.named('test', Test).configure { + useJUnitPlatform() } -tasks.publish.dependsOn build -tasks.curseforge.dependsOn publish - -artifacts { - if (getBooleanProperty('create_api_jar')) { - archives apiJar - } - if (getBooleanProperty('create_deobf_jar')) { - archives devJar - archives deobfJar - } - if (getBooleanProperty('create_source_jar')) { - archives sourceJar - } - if (getBooleanProperty('create_javadoc_jar')) { - archives javadocJar - } -} +// Eclipse and command-line verification use different Gradle homes in this workspace. Keep every +// Eclipse runtime input on Buildship's cache while Forge remains free to rewrite build/classpath. +def syncEclipseRunClasspaths = tasks.register('syncEclipseRunClasspaths') { + group = 'IDE' + description = 'Aligns Eclipse project and Forge run classpaths with Buildship\'s Gradle home.' -publishing { - publications { - mavenJava(MavenPublication) { - groupId project.group - artifactId project.archivesBaseName - version project.version - from components.java - if (getBooleanProperty('create_source_jar')) { - artifact sourceJar { - classifier 'sources' + doLast { + File classpathDir = layout.buildDirectory.dir('classpath').get().asFile + Set classpathFiles = fileTree(classpathDir) { + include '*_minecraftClasspath.txt' + }.files + if (classpathFiles.isEmpty()) { + throw new GradleException('Missing Forge run classpaths. Run genEclipseRuns before launching from Eclipse.') } - } - if (getBooleanProperty('create_api_jar')) { - artifact apiJar { - classifier 'api' - } - } - if (getBooleanProperty('create_deobf_jar')) { - artifact devJar { - classifier 'dev' - } - artifact deobfJar { - classifier 'deobf' - } - } - if (getBooleanProperty('create_javadoc_jar')) { - artifact javadocJar { - classifier 'javadoc' + + File buildshipPreferences = file('.settings/org.eclipse.buildship.core.prefs') + Properties buildship = new Properties() + if (buildshipPreferences.isFile()) { + buildshipPreferences.withInputStream { buildship.load(it) } } - } - if (getBooleanProperty(pom_information)) { - pom { - name = project.name - description = project.description - url = project.pom_url - packaging = 'jar' - //inceptionYear = '' - if (getBooleanProperty(pom_license_information)) { - licenses { - license { - name = project.pom_license_name - url = project.pom_license_url - distribution = 'repo' - comments = project.pom_comments - } - } - } - if (getBooleanProperty(pom_scm_information)) { - scm { - connection = project.pom_scm_connection - developerConnection = project.pom_scm_developer_connection - // tag - url = project.pom_scm_url + String configuredGradleHome = buildship.getProperty('connection.gradle.user.home', '').trim() + File eclipseGradleHome = configuredGradleHome + ? file(configuredGradleHome).canonicalFile + : gradle.gradleUserHomeDir.canonicalFile + File eclipseCache = new File(eclipseGradleHome, 'caches').canonicalFile + File eclipseClasspathDir = file('.settings/orespawn-run-classpaths') + eclipseClasspathDir.mkdirs() + + Closure mapCacheReferences = { String value -> + value.replaceAll(/(?i)[A-Z]:[\\\/]\S*?[\\\/]caches(?=[\\\/])/) { String cacheRoot -> + cacheRoot.contains('/') + ? eclipseCache.absolutePath.replace('\\', '/') + : eclipseCache.absolutePath } - } - if (getBooleanProperty(pom_issue_information)) { - issueManagement { - system = project.pom_issue_system - url = project.pom_issue_url - } - } - if (getBooleanProperty(pom_ci_information)) { - ciManagement { - system = project.pom_ci_system - url = project.pom_ci_url - } - } - if (getBooleanProperty(pom_organisation_information)) { - organization { - name = project.pom_organization_name - url = project.pom_organization_url - } - } - // contributors, developers, distributionManagement } - } - } - } - repositories { - maven { - if ((secret.username != '') && (secret.password != '')) { - credentials { - username secret.username - password secret.password - } - } - if (secret.url != '') { - url secret.url - } else { - url "file:///${project.buildDir}/repo" - } - } - } -} -curseforge { - if (project.hasProperty('curseforge_project_id') && getBooleanProperty('curseforge_do_upload')) { - apiKey = secret.curseforgeAPIKey - project { - id = project.curseforge_project_id - if (project.hasProperty('curseforge_changelog_filename')) { - changelog = file(project.curseforge_changelog_filename) - } else { - changelog = '' - } - if (project.hasProperty('curseforge_changelog_type')) { - changelogType = project.curseforge_changelog_type - } - if ((project.hasProperty('curseforge_release_type')) && ((project.curseforge_release_type == 'alpha') || (project.curseforge_release_type == 'beta') || (project.curseforge_release_type == 'release'))) { - releaseType = project.curseforge_release_type - } else { - releaseType = 'alpha' - } - if (project.hasProperty('curseforge_versions')) { - final def versions = "${project.curseforge_versions}".split(', ') - versions.each { - addGameVersion "${it}" - } - } - mainArtifact(jar) { - if (getBooleanProperty('curseforge_use_custom_display_name')) { - displayName = "${project.name} ${project.display_version}" - } - if (project.hasProperty('curseforge_requirements') || project.hasProperty('curseforge_optionals') || project.hasProperty('curseforge_embeddeds') || project.hasProperty('curseforge_tools') || project.hasProperty('curseforge_incompatibles') || project.hasProperty('curseforge_includes')) { - relations { - if (project.hasProperty('curseforge_requirements')) { - final def requirements = "${project.curseforge_requirements}".split(', ') - requirements.each { - requiredDependency "${it}" - } + Map stableClasspaths = [:] + classpathFiles.each { File classpathFile -> + List original = classpathFile.readLines('UTF-8') + List synced = original.collect { String entry -> + String mapped = mapCacheReferences(entry) + String portable = mapped.replace('\\', '/') + int marker = portable.indexOf('/caches/') + if (marker < 0) { + return mapped + } + + File target = file(mapped).canonicalFile + if (!target.isFile()) { + throw new GradleException("Missing Eclipse run dependency in configured Gradle cache: ${target}") + } + return target.absolutePath } - if (project.hasProperty('curseforge_optionals')) { - final def optionals = "${project.curseforge_optionals}".split(', ') - optionals.each { - optionalDependency "${it}" - } - } - if (project.hasProperty('curseforge_embeddeds')) { - final def embeddeds = "${project.curseforge_embeddeds}".split(', ') - embeddeds.each { - embeddedLibrary "${it}" - } + + File stableClasspath = new File(eclipseClasspathDir, classpathFile.name) + stableClasspath.setText(synced.join(System.lineSeparator()) + System.lineSeparator(), 'UTF-8') + stableClasspaths.put(classpathFile.canonicalFile, stableClasspath.canonicalFile) + } + + File eclipseProjectClasspath = file('.classpath') + int changedProjectClasspath = 0 + int changedResourceExclusions = 0 + if (eclipseProjectClasspath.isFile()) { + String original = eclipseProjectClasspath.getText('UTF-8') + def parsedClasspath = new XmlParser(false, false).parseText(original) + parsedClasspath.classpathentry.each { entry -> + ['path', 'sourcepath'].each { String attribute -> + String value = entry.attribute(attribute) + if (!value) { + return + } + String mapped = mapCacheReferences(value) + if (mapped == value) { + return + } + File mappedTarget = file(mapped).canonicalFile + if (mappedTarget.exists()) { + entry.attributes().put(attribute, mappedTarget.absolutePath) + changedProjectClasspath = 1 + } else { + // Test-only libraries may have been resolved by command-line Gradle + // but not yet by Buildship. They are not part of the Forge launch + // module path, so retaining the existing valid path is safe. + File existingTarget = file(value).canonicalFile + if (!existingTarget.exists()) { + throw new GradleException("Missing Eclipse project dependency in both Gradle caches: ${mappedTarget}") + } + } + } } - if (project.hasProperty('curseforge_tools')) { - final def tools = "${project.curseforge_tools}".split(', ') - tools.each { - tool "${it}" - } + parsedClasspath.classpathentry.findAll { entry -> + entry.attribute('kind') == 'src' && entry.attribute('path') == 'src/main/resources' + }.each { entry -> + List exclusions = (entry.attribute('excluding') ?: '') + .split(/\|/) + .findAll { !it.isEmpty() } + ['META-INF/mods.toml', 'pack.mcmeta'].each { String metadataFile -> + if (exclusions.remove(metadataFile)) { + changedResourceExclusions = 1 + } + } + if (exclusions.isEmpty()) { + entry.attributes().remove('excluding') + } else { + entry.attributes().put('excluding', exclusions.join('|')) + } } - if (project.hasProperty('curseforge_incompatibles')) { - final def incompatibles = "${project.curseforge_incompatibles}".split(', ') - incompatibles.each { - incompatible "${it}" - } + if (changedProjectClasspath || changedResourceExclusions) { + eclipseProjectClasspath.setText(groovy.xml.XmlUtil.serialize(parsedClasspath), 'UTF-8') } - if (project.hasProperty('curseforge_includes')) { - final def includes = "${project.curseforge_includes}".split(', ') - includes.each { - include "${it}" - } + + parsedClasspath.classpathentry.each { entry -> + ['path', 'sourcepath'].each { String attribute -> + String value = entry.attribute(attribute) + if (value && value.replace('\\', '/').contains('/caches/')) { + File target = file(value).canonicalFile + if (!target.exists()) { + throw new GradleException("Missing Eclipse project dependency in configured Gradle cache: ${target}") + } + } + } } - } - } - } - if (getBooleanProperty('create_api_jar')) { - addArtifact(apiJar) { - if (getBooleanProperty('curseforge_use_custom_display_name')) { - displayName = "${project.name} ${project.display_version} API" - } - } - } - if (getBooleanProperty('create_source_jar')) { - addArtifact(sourceJar) { - if (getBooleanProperty('curseforge_use_custom_display_name')) { - displayName = "${project.name} ${project.display_version} Sources" - } - } - } - if (getBooleanProperty('create_deobf_jar')) { - addArtifact(deobfJar) { - if (getBooleanProperty('curseforge_use_custom_display_name')) { - displayName = "${project.name} ${project.display_version} Development" - } } - } - if (getBooleanProperty('create_javadoc_jar')) { - addArtifact(javadocJar) { - if (getBooleanProperty('curseforge_use_custom_display_name')) { - displayName = "${project.name} ${project.display_version} Javadoc" - } - } - } - } - } -} -sonarqube { - properties { - if (project.hasProperty('sonar_host_url')) { - property 'sonar.host.url', project.sonar_host_url - } else if (secret.sonarHost != '') { - property 'sonar.host.url', secret.sonarHost - } else { - property 'sonar.host.url', 'https://sonarcloud.io' - } - - if (secret.sonarToken != '') { - property 'sonar.login', secret.sonarToken - } - - if (project.hasProperty('sonar_organisation')) { - property 'sonar.organization', project.sonar_organisation - } else if (secret.sonarOrganisation != '') { - property 'sonar.organization', secret.sonarOrganization - } else { - property 'sonar.organization', 'unset' - } - - if (project.hasProperty('sonar_project_key')) { - property 'sonar.projectKey', project.sonar_project_key - } - - if (project.hasProperty('sonar_project_name')) { - property 'sonar.projectName', project.sonar_project_name - } - - if (project.hasProperty('sonar_project_description')) { - property 'sonar.projectDescription', project.sonar_project_description - } - - if (project.hasProperty('sonar_project_version')) { - property 'sonar.projectVersion', project.sonar_project_version - } - - if (project.hasProperty('sonar_branch_name')) { - property 'sonar.branch.name', project.sonar_branch_name - } - - if (project.hasProperty('sonar_branch_target')) { - property 'sonar.branch.target', project.sonar_branch_target - } - - property 'sonar.junit.reportPaths', "${project.buildDir}/test-results/junit-platform/*.xml" - property 'sonar.jacoco.reportPaths', "${project.buildDir}/jacoco/junitPlatformTest.exec" - //property 'sonar.groovy.jacoco.reportPath', "" - } -} - -String getModFile() { - String path = '' - final FileTree tree = fileTree(dir: 'src/main/java') - tree.include '**/*.java' - tree.visit { final element -> - if (element.file.isFile()) { - element.file.eachLine { final String s -> - final String sTrim = s.trim() - if (sTrim.startsWith('@Mod(')) { - path = "src/main/java/${element.relativePath}" + File eclipseLaunchDir = file('.eclipse/configurations') + int changedLaunches = 0 + if (eclipseLaunchDir.isDirectory()) { + fileTree(eclipseLaunchDir) { + include '*Slim.launch' + }.files.each { File launchFile -> + String original = launchFile.getText('UTF-8') + String synced = mapCacheReferences(original) + stableClasspaths.each { File generated, File stable -> + synced = synced + .replace(generated.absolutePath, stable.absolutePath) + .replace(generated.absolutePath.replace('\\', '/'), stable.absolutePath.replace('\\', '/')) + } + if (original != synced) { + launchFile.setText(synced, 'UTF-8') + changedLaunches++ + } + } } - } + logger.lifecycle("Eclipse runtime paths aligned with ${eclipseCache} (${stableClasspaths.size()} Forge classpaths, ${changedProjectClasspath} project classpath, ${changedResourceExclusions} metadata exclusion, ${changedLaunches} launches updated)") } - } - return path -} - -String getModVersion(final String type) { - return getModVersion(type, modFile) } -import java.util.regex.Matcher -String getModVersion(final String type, final String modFile) { - if ((modFile != null) && (modFile != '')) { - final File file = file(modFile) - final def prefix = ~/^(?:\s*)(?:(?public|protected|private) )?(?:(?static) )?(?:(?final) )?String $type = "(?:(?\d*)\.)?(?:(?\d*)\.)?(?:(?[^."]*)\.?)(?[^"]*)";$/ - for (final String s in file.readLines()) { - final Matcher matcher = (s.trim() =~ prefix) - if (matcher.matches()) { - return "${matcher.group('major') ?: '0'}.${matcher.group('minor') ?: '0'}.${matcher.group('patch')}" - } +tasks.configureEach { + if (name in ['copyEclipseResources', 'genEclipseRuns', 'eclipse']) { + finalizedBy syncEclipseRunClasspaths } - } - return '0.0.0' -} - -boolean isFG1() { - return (project.fg_version == '1.0-SNAPSHOT') || (project.fg_version == '1.1-SNAPSHOT') || (project.fg_version == '1.2-SNAPSHOT') -} - -boolean isFG2() { - return (project.fg_version == '2.0-SNAPSHOT') || (project.fg_version == '2.1-SNAPSHOT') || (project.fg_version == '2.2-SNAPSHOT') || (project.fg_version == '2.3-SNAPSHOT') -} - -boolean gradleOlderThan(final String version) { - return GradleVersion.current() < GradleVersion.version(version) -} - -boolean gradleNewerThan(final String version) { - return GradleVersion.current() >= GradleVersion.version(version) -} - -boolean isCi() { - return System.getenv('CI') -} - -boolean getBooleanProperty(final String property) { - if (project.hasProperty(property)) { - return ((String) project.findProperty(property)).toBoolean() - } else { - return false - } -} - -if (gradleNewerThan('2.1')) { - task gitChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) { - file = new File('CHANGELOG.md') - gitHubIssuePattern = "nonada123" - templateContent = file('changelog.mustache').getText('UTF-8') - } -} - -Object findProperty(final String propertyName) { - return hasProperty(propertyName) ? property(propertyName) : null; } diff --git a/docs/AGENTS.md b/docs/AGENTS.md new file mode 100644 index 00000000..45f282e7 --- /dev/null +++ b/docs/AGENTS.md @@ -0,0 +1,55 @@ +# OreSpawn Integration Notes For Humans And Agents + +OreSpawn 4.0 is a required Forge mod and declarative world-generation engine. +Public API major version 1 consists only of `com.mcmoddev.orespawn.api`. Treat +every other Java package as internal and unstable. + +Integration entry points: + +- Java declarations: `OreSpawnApi.enqueue(WorldgenProvider)` during + `InterModEnqueueEvent`. +- Packaged declarations: `data//orespawn/provider.json`. +- Pack overrides: `config/-orespawn.json`. +- Active queries: `getActiveProfile(MinecraftServer)` and + `createSampler(ServerLevel)`. +- Native-ore takeover: disable only when `isOreTakeoverActive(modid)` is true. + +Configuration contracts: + +- Global `config/orespawn-worldgen.json`: schema 4. +- World `serverconfig/orespawn-worldgen.json`: schema 3. +- Provider files: schema 2; legacy ore-only schema 1 remains accepted. +- JSON Schemas and examples are under `META-INF/orespawn/docs/` in the jar. + +Lifecycle and ownership: + +- Forge setup is parallel. Never mutate OreSpawn internals directly. +- A pack override file is authoritative over packaged and API definitions for + the same provider. A malformed override fails closed. +- Provider rule IDs use the provider namespace. A rule's `block` or weighted + output may reference any installed block. +- Definitions freeze at load completion and change only after restart or an + operator `/orespawn reload`. + +Performance constraints: + +- Do not request callbacks in block-generation loops. +- Registry IDs remain `ResourceLocation` values until setup-time baking. +- Dimension, tag, alias, biome, geome, family, pattern, and block-state + resolution occurs before generation. +- The chunk hot path must contain no config reads, registry access, strings, + logging, reflection, or per-block allocation. +- Ore and flat-bedrock retrogen are bounded and marker-based. Terrain strata + are never retrogened. + +Compatibility defaults: + +- Standalone OreSpawn is passive: no rocks, terrain dimensions, oil, ore + suppression, retrogen, or flat bedrock are enabled by default. +- The Overworld is the conventional geology target, but a provider must opt it + in. Nether and End terrain remain untouched unless explicitly configured. +- Mineralogy 6 is a provider, not a public-API compatibility facade. Do not use + removed `com.mcmoddev.mineralogy.api` classes. + +Common tasks are documented in `API.md`, `PROVIDERS.md`, `FEATURES.md`, +`TEMPLATES.md`, and `DIMENSIONS.md`. diff --git a/docs/API.md b/docs/API.md new file mode 100644 index 00000000..6976b35a --- /dev/null +++ b/docs/API.md @@ -0,0 +1,79 @@ +# Java API + +Only `com.mcmoddev.orespawn.api` is supported API. Every other package is an +implementation detail. API major version is available as +`OreSpawnApi.API_VERSION` and in the jar manifest as +`OreSpawn-API-Version`. + +Provider mods must depend on the full OreSpawn mod at compile time and +runtime. In `mods.toml` use a mandatory dependency, for example: + +```toml +[[dependencies.examplemod]] +modId="orespawn" +mandatory=true +versionRange="[4.0.0,5.0.0)" +ordering="AFTER" +side="BOTH" +``` + +Submit declarations during `InterModEnqueueEvent`: + +```java +WorldgenProvider provider = WorldgenProvider.builder("examplemod", 1) + .rock(new ResourceLocation("examplemod", "slate"), GeologyFamily.METAMORPHIC, rock -> rock + .depth(12, 36) + .weight(1.2) + .oreReplaceable(true)) + .build(); +OreSpawnApi.enqueue(provider); +``` + +Definitions are immutable after `build()`. Registry references remain +`ResourceLocation` values until OreSpawn validates and bakes them. Provider +messages are processed through Forge IMC and frozen at load completion; direct +cross-mod mutation during parallel setup is unsupported. + +The builder emits provider schema 2. Legacy provider schema 1 is intentionally +limited to ore-only JSON files. + +Formation and oil settings use the same declarative style when building a +template: + +```java +FormationDefinition formations = FormationDefinition.builder() + .horizontalSize(FormationPreset.HUGE) + .waviness(FormationPreset.LARGE) + .build(); +OilDefinition oil = OilDefinition.builder() + .yRange(-48, 32) + .minSolidCover(2) + .build(); +``` + +Query the active profile and sample exact production geology on the server: + +```java +OreSpawnApi.getActiveProfile(server).ifPresent(profile -> + LOGGER.info("Configured rocks: {}", profile.rockIds().size())); + +OreSpawnApi.createSampler(server.overworld()).ifPresent(sampler -> { + GeologyColumn column = sampler.sampleColumn(120, -40, 92); + LOGGER.info("{} / {} / {}", column.biome(), column.geome(), column.rockAt(20)); +}); +``` + +`sampleColumn` performs one biome/geome classification and reuses it for every +Y query. Sampling is read-only and is intended for gameplay decisions, +diagnostics, and compatible generation outside OreSpawn's block loops. +Callbacks inside OreSpawn generation loops are intentionally unsupported. + +Custom pattern mods create a Forge `DeferredRegister` using +`OreSpawnPatternRegistry.REGISTRY_NAME`. An `OrePatternType` contains a codec +and a compiler from decoded settings to `CompiledOrePattern`. Reference it from +an ore dimension with `pattern(patternId, settingsJson)`. OreSpawn decodes and +compiles once while baking the profile; only the compiled placement function +runs during generation. + +`OreSpawnOreIntegration` remains as a deprecated facade for early ore-provider +integrations. New code should use `OreSpawnApi`. diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md new file mode 100644 index 00000000..8cd51c4c --- /dev/null +++ b/docs/CONFIGURATION.md @@ -0,0 +1,40 @@ +# Configuration + +OreSpawn uses three JSON contracts: + +| File | Schema | Purpose | +|---|---:|---| +| `config/orespawn-worldgen.json` | 4 | Installed-pack defaults | +| `/serverconfig/orespawn-worldgen.json` | 3 | Self-contained world snapshot | +| `config/-orespawn.json` | 2 | Optional provider override | + +A provider can also package the same schema at +`data//orespawn/provider.json`. The effective profile for a new world is +assembled in this order: passive OreSpawn factory defaults, packaged or API +provider additions, provider override files, global pack configuration, the +selected template, then edits made in Create World. The result is saved into +the world. + +The global and world files configure formations, rocks, geomes, biome rules, +terrain dimensions, ores, oil, aliases, vanilla suppression, retrogen, and +flat bedrock. Registry references use full IDs such as `minecraft:calcite`. + +Important top-level controls: + +- `manage_vanilla_ores`: suppress only vanilla ore features claimed by active + configured rules. +- `suppress_all_ore_features`: wrap and suppress all standard Forge ore + features while OreSpawn rules run. Use this only for deliberately complete + packs. +- `retrogen.enabled`: generate rules with `retrogen:true` in loaded chunks + whose revision marker differs. `chunks_per_tick` is clamped to 1-16. +- `flat_bedrock.enabled`: flatten 1-5 bottom layers in listed dimensions and + the Nether ceiling. `flat_bedrock.retrogen` uses the same bounded queue. + +Copying the world profile into the same `serverconfig` location in a dedicated +server world reproduces the settings when all referenced mods and blocks are +installed. Restart after manual edits. Normal profile changes affect newly +generated chunks; enabled ore/bedrock retrogen is the only explicit exception. + +See `schemas/orespawn-global.schema.json`, +`schemas/orespawn-world.schema.json`, and `examples/`. diff --git a/docs/DIMENSIONS.md b/docs/DIMENSIONS.md new file mode 100644 index 00000000..8047c0da --- /dev/null +++ b/docs/DIMENSIONS.md @@ -0,0 +1,31 @@ +# Terrain Dimensions + +Standalone OreSpawn has no enabled terrain-replacement dimension. The +Overworld is the conventional geology target used by full providers such as +Mineralogy. Nether and End remain untouched unless a global/world profile +explicitly enables them. Providers may automatically opt in only dimensions +in their own namespace. + +Each `terrain_dimensions` entry supplies replacement host blocks or tags and +may restrict generation to explicit biome IDs or biome namespaces. With no +biome restriction, all biomes in that dimension are eligible. + +Rock entries may include a `dimensions` array. For backward compatibility, an +entry without this field belongs only to `minecraft:overworld`. A custom +dimension is disabled during baking if no valid eligible rocks resolve. + +Example: + +```json +"examplemod:crystal_caverns": { + "enabled": true, + "biome_namespaces": ["examplemod"], + "biome_ids": [], + "host_blocks": ["examplemod:base_rock"], + "host_tags": [] +} +``` + +OreSpawn resolves dimensions, hosts, tags, rocks, and biome filters before +chunk generation. An unconfigured dimension performs one table lookup and +immediately skips. diff --git a/docs/FEATURES.md b/docs/FEATURES.md new file mode 100644 index 00000000..eeb2d033 --- /dev/null +++ b/docs/FEATURES.md @@ -0,0 +1,49 @@ +# Ore Patterns And Runtime Features + +Every ore dimension selects one pattern. Legacy string values remain accepted; +the namespaced form is preferred. + +| Pattern | ID | Shape | +|---|---|---| +| Compact | `orespawn:default` | Dense rounded deposit | +| Vein | `orespawn:vein` | Wandering connected vein | +| Normal cloud | `orespawn:normal_cloud` | Diffuse bounded cloud | +| Precision | `orespawn:precision` | Deterministic compact fill | +| Clusters | `orespawn:clusters` | Multiple nearby nodes | +| Under fluids | `orespawn:underfluids` | Deposit beneath configured fluid | + +Built-in settings are `spread` (0-64), `vertical_spread` (0-64), `node_size` +(1-32), `length` (1-64), and a fluid registry ID. The legacy flat fields and +the codec object below are equivalent: + +```json +"pattern": { + "type": "orespawn:clusters", + "settings": { + "spread": 12, + "vertical_spread": 5, + "node_size": 3, + "length": 20, + "fluid": "minecraft:water" + } +} +``` + +Other mods may register `OrePatternType` values in the Forge registry named by +`OreSpawnPatternRegistry.REGISTRY_NAME`. Each type supplies a Mojang `Codec` +and compiles decoded settings into a `CompiledOrePattern`. Compilation occurs +during profile baking. The generation loop invokes only the compiled object. +Third-party codec settings are preserved and shown read-only in OreSpawn's UI. + +Height selection supports `uniform` and `triangle`. `frequency` is expected +attempts per chunk: the integer part is guaranteed and the fractional part is +the chance of one additional attempt. `quantity` is the placement budget for +each attempt. + +Retrogen records a deterministic profile revision in chunk NBT under +`OreSpawn`. Only ore rules with `retrogen:true` participate. Processing is +bounded by `chunks_per_tick`; no terrain strata retrogen exists. + +Flat bedrock is disabled by default. When enabled it flattens the configured +number of bottom layers and, in the Nether, the ceiling. It uses normal Forge +features and chunk events, with no reflection. diff --git a/docs/MIGRATION.md b/docs/MIGRATION.md new file mode 100644 index 00000000..40aa3136 --- /dev/null +++ b/docs/MIGRATION.md @@ -0,0 +1,29 @@ +# Migration + +Migration is non-destructive. OreSpawn writes `config/orespawn-worldgen.json` +only when that target does not already exist and retains every source file. + +When `config/mineralogy-geomes.json` exists, OreSpawn imports the Mineralogy 6 +profile directly, updates its schema marker, and records `migrated_from`. + +Otherwise it scans `config/orespawn3/*.json` and `config/orespawn/*.json` for +legacy OreSpawn `version: "2.0"` spawn files. It converts: + +- default, vein, normal cloud, precision, cluster, and under-fluid patterns; +- weighted output blocks and replacement blocks; +- numeric Overworld, Nether, and End dimensions; +- biome ID and biome-dictionary include/exclude rules; +- frequency, size, height, spread, node, fluid, and retrogen settings. + +Compatible flags are also read from `config/orespawn.cfg`: vanilla/all ore +replacement, retrogen, forced retrogen, flat bedrock, and bedrock thickness. +Unknown numeric dimensions and obsolete block states are reported instead of +guessed. Review `config/orespawn-migration/migration-report.txt` after import. + +Global schemas 1-3 and world schemas 1-2 are upgraded in memory and persisted +where safe. A schema-1 world held only mode/oil/formation choices and is +overlaid on the effective installed-pack profile. A schema-2 world is already +a full snapshot and preserves its geology. Existing terrain is not rewritten. + +Unqualified built-in geome names remain accepted and normalize to +`orespawn:` internally. diff --git a/docs/PROVIDERS.md b/docs/PROVIDERS.md new file mode 100644 index 00000000..309caf1b --- /dev/null +++ b/docs/PROVIDERS.md @@ -0,0 +1,46 @@ +# Worldgen Providers + +Provider mods may contribute through Forge IMC, a packaged resource at +`data//orespawn/provider.json`, or a pack override at +`config/-orespawn.json`. A valid override is authoritative. A +present malformed override leaves that provider inactive instead of silently +falling back. + +Provider schema 2 supports `profile_defaults`, `rocks`, `ores`, `geomes`, +`biome_rules`, `terrain_dimensions`, and `templates`. Each file requires a +matching `provider_modid`, a positive `provider_revision`, and at least one +contribution. Legacy schema 1 remains accepted for ore-only providers. + +Rule IDs in `rocks` and `ores` must use the provider namespace. They are stable +ownership keys, not necessarily block IDs. Set `block` for one output or +`outputs` for a weighted list: + +```json +"examplemod:ore/tin": { + "block": "examplemod:tin_ore", + "outputs": [ + { "block": "examplemod:tin_ore", "weight": 90 }, + { "block": "examplemod:rich_tin_ore", "weight": 10 } + ], + "enabled": true, + "dimensions": {} +} +``` + +An enabled ore dimension requires a Y range, expected attempts per chunk in +`frequency`, a block budget in `quantity`, and at least one host family, host +block, or host tag. Host arrays accept either registry-ID strings or weighted +objects such as `{ "block": "minecraft:stone", "weight": 1.0 }` and +`{ "tag": "forge:stone", "weight": 0.5 }`. Biome include/exclude IDs and +Forge biome-dictionary names may further restrict a rule. + +Only suppress a provider mod's native ore generation when +`OreSpawnApi.isOreTakeoverActive(modid)` returns true. `PENDING` means discovery +has not frozen. `INACTIVE` is the fail-safe and native generation must remain. + +Existing worlds merge newly introduced provider rule IDs but do not overwrite +world edits. Disabled and unassigned rules remain tombstones; removed provider +rules remain in the self-contained snapshot. + +See `examples/examplemod-orespawn.json` for rocks, weighted ore output, a +custom dimension, and a selectable template. diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..cd6232cc --- /dev/null +++ b/docs/README.md @@ -0,0 +1,18 @@ +# OreSpawn 4.0 Integration Documentation + +OreSpawn 4.0 exposes public API major version 1. The normal OreSpawn jar is +both the compile-time and runtime dependency; there is no shaded or embeddable +engine artifact. + +- [Configuration](CONFIGURATION.md) +- [Provider files](PROVIDERS.md) +- [Java API and custom patterns](API.md) +- [Ore patterns and runtime tools](FEATURES.md) +- [Templates](TEMPLATES.md) +- [Dimensions](DIMENSIONS.md) +- [Migration](MIGRATION.md) +- [Troubleshooting](TROUBLESHOOTING.md) +- [Agent integration notes](AGENTS.md) + +Machine-readable schemas and validated examples are in `schemas/` and +`examples/`. diff --git a/docs/TEMPLATES.md b/docs/TEMPLATES.md new file mode 100644 index 00000000..46e0f0be --- /dev/null +++ b/docs/TEMPLATES.md @@ -0,0 +1,17 @@ +# Geology Templates + +Templates are named profile overlays supplied by providers. They may set +formation presets, rocks, geomes, biome rules, ores, oil, suppression, +retrogen, flat bedrock, and terrain dimensions. A template may reference any +installed registry ID and list `required_mods`. + +Templates never activate merely because a provider is installed. Players +select one in OreSpawn's Create World screen. Dedicated servers may set +`default_template` in `config/orespawn-worldgen.json`. + +Template application happens after the global pack configuration and before +world-creation edits. The selected result is copied into the world profile. +Provider template changes never rewrite an existing world. + +Use namespaced template IDs such as `examplemod:ancient_sea`. Translation keys +for the selector belong to the provider resource pack. diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md new file mode 100644 index 00000000..3abe8cd4 --- /dev/null +++ b/docs/TROUBLESHOOTING.md @@ -0,0 +1,45 @@ +# Troubleshooting + +## Provider remains inactive + +Check that the provider mod is loaded, file name and `provider_modid` match, +`provider_revision` is positive, provider rule IDs use its namespace, all +output blocks resolve, all pattern codecs decode, and every enabled ore or +terrain dimension has hosts. A malformed override deliberately prevents +fallback to packaged or API declarations. + +## OreSpawn installed alone does nothing + +That is the intended passive default. Install a provider such as Mineralogy, +add a provider file, or explicitly configure rocks/ores and terrain dimensions. + +## Custom terrain does not appear + +Confirm the dimension is enabled in `terrain_dimensions`, its hosts resolve, +at least one enabled rock includes that dimension, and biome restrictions +match. OreSpawn does not replace Nether or End terrain by default. + +## Changes do not affect terrain + +Restart after editing JSON or changing provider/API declarations. Travel to +new chunks. Ore retrogen and flat-bedrock retrogen must be explicitly enabled; +geological strata are never retrogened. + +## Server differs from a client test world + +Copy `/serverconfig/orespawn-worldgen.json`, not merely the global +client config. Install the same provider mods and blocks on the server. + +## Native ores duplicate + +Provider mods suppress native generation only after +`OreSpawnApi.isOreTakeoverActive(modid)` is true. Keep native generation for +`PENDING` and `INACTIVE`. For pack-wide vanilla or modded suppression, review +`manage_vanilla_ores` and `suppress_all_ore_features` carefully. + +## Operator diagnostics + +- `/orespawn status` shows active mode, rule/provider counts, and retrogen queue. +- `/orespawn reload` reloads providers and the active world profile. +- `/orespawn retrogen [radius]` queues currently loaded chunks only. +- `/orespawn dump-biomes` writes `config/orespawn-biomes.txt`. diff --git a/docs/examples/examplemod-orespawn.json b/docs/examples/examplemod-orespawn.json new file mode 100644 index 00000000..27885a1f --- /dev/null +++ b/docs/examples/examplemod-orespawn.json @@ -0,0 +1,110 @@ +{ + "schema_version": 2, + "provider_modid": "examplemod", + "provider_revision": 1, + "rocks": { + "examplemod:rock/slate": { + "block": "examplemod:slate", + "enabled": true, + "family": "metamorphic", + "depth_peak": 20, + "depth_spread": 36, + "min_y": -64, + "max_y": 319, + "weight": 1.2, + "ore_replaceable": true, + "dimensions": ["minecraft:overworld"], + "geomes": { "orespawn:mountain_belt": 2.5 } + }, + "examplemod:rock/crystal_rock": { + "block": "examplemod:crystal_rock", + "enabled": true, + "family": "igneous_intrusive", + "depth_peak": 32, + "depth_spread": 64, + "min_y": -64, + "max_y": 319, + "weight": 1.0, + "ore_replaceable": true, + "dimensions": ["examplemod:crystal_caverns"] + } + }, + "ores": { + "examplemod:ore/tin": { + "block": "examplemod:tin_ore", + "outputs": [ + { "block": "examplemod:tin_ore", "weight": 90 }, + { "block": "examplemod:rich_tin_ore", "weight": 10, "min_y": -64, "max_y": 24 } + ], + "enabled": true, + "source_mod": "examplemod", + "dimensions": { + "minecraft:overworld": { + "enabled": true, + "min_y": -16, + "max_y": 96, + "frequency": 6.0, + "quantity": 8, + "pattern": { + "type": "orespawn:clusters", + "settings": { + "spread": 8, + "vertical_spread": 4, + "node_size": 4, + "length": 16, + "fluid": "minecraft:water" + } + }, + "height_distribution": "triangle", + "spread": 8, + "vertical_spread": 4, + "node_size": 4, + "host_families": ["sedimentary", "metamorphic", "igneous_intrusive"], + "host_blocks": [ + { "block": "minecraft:deepslate", "weight": 0.75 } + ] + } + } + } + }, + "geomes": { + "examplemod:crystal_province": { + "base": 0.5, + "families": { + "sedimentary": 0.2, + "metamorphic": 1.0, + "igneous_intrusive": 3.0, + "igneous_volcanic": 0.5 + } + } + }, + "biome_rules": { + "minecraft:jagged_peaks": { + "examplemod:crystal_province": 2.5, + "orespawn:mountain_belt": 2.0 + } + }, + "terrain_dimensions": { + "examplemod:crystal_caverns": { + "enabled": true, + "biome_ids": [], + "biome_namespaces": ["examplemod"], + "host_blocks": ["examplemod:base_rock"], + "host_tags": [] + } + }, + "templates": { + "examplemod:crystal_world": { + "name_key": "template.examplemod.crystal_world", + "description_key": "template.examplemod.crystal_world.description", + "required_mods": ["examplemod"], + "profile": { + "formations": { + "horizontal_size": "large", + "formation_continuity": "large" + }, + "manage_vanilla_ores": true + } + } + } +} diff --git a/docs/examples/orespawn-global.json b/docs/examples/orespawn-global.json new file mode 100644 index 00000000..8c67e2e3 --- /dev/null +++ b/docs/examples/orespawn-global.json @@ -0,0 +1,59 @@ +{ + "schema_version": 4, + "geology_mode": "geome", + "place_crude_oil": false, + "manage_vanilla_ores": false, + "suppress_all_ore_features": false, + "default_template": "", + "formations": { + "algorithm": "stable_layers", + "horizontal_size": "average", + "vertical_thickness": "average", + "waviness": "average", + "edge_irregularity": "average", + "formation_continuity": "average", + "custom": {} + }, + "geomes": { + "stable_craton": { + "base": 1.0, + "families": { + "sedimentary": 1.0, + "metamorphic": 1.0, + "igneous_intrusive": 1.4, + "igneous_volcanic": 0.25 + } + } + }, + "biomes": {}, + "biome_dictionary": {}, + "rocks": {}, + "terrain_dimensions": {}, + "ores": {}, + "oil": { + "min_y": -48, + "max_y": 32, + "frequency": 0.08, + "min_radius": 8, + "max_radius": 18, + "min_vertical_radius": 3, + "max_vertical_radius": 8, + "max_lobes": 5, + "min_solid_cover": 2 + }, + "retrogen": { + "enabled": false, + "force": false, + "revision": 0, + "chunks_per_tick": 1 + }, + "flat_bedrock": { + "enabled": false, + "retrogen": false, + "layers": 1, + "dimensions": ["minecraft:overworld", "minecraft:the_nether"] + }, + "worldgen_aliases": {}, + "providers": {}, + "ore_providers": {} +} diff --git a/docs/examples/orespawn-world.json b/docs/examples/orespawn-world.json new file mode 100644 index 00000000..0f802eba --- /dev/null +++ b/docs/examples/orespawn-world.json @@ -0,0 +1,97 @@ +{ + "schema_version": 3, + "geology_mode": "geome", + "place_crude_oil": false, + "manage_vanilla_ores": false, + "suppress_all_ore_features": false, + "formations": { + "algorithm": "stable_layers", + "horizontal_size": "large", + "vertical_thickness": "average", + "waviness": "average", + "edge_irregularity": "average", + "formation_continuity": "large", + "custom": {} + }, + "geomes": { + "stable_craton": { + "base": 1.0, + "families": { + "sedimentary": 1.0, + "metamorphic": 1.0, + "igneous_intrusive": 1.4, + "igneous_volcanic": 0.25 + } + } + }, + "biomes": {}, + "biome_dictionary": {}, + "rocks": { + "minecraft:sandstone": { + "enabled": true, + "family": "sedimentary", + "depth_peak": 64, + "depth_spread": 40, + "min_y": -64, + "max_y": 319, + "weight": 1.0, + "ore_replaceable": true + }, + "minecraft:calcite": { + "enabled": true, + "family": "metamorphic", + "depth_peak": 20, + "depth_spread": 36, + "min_y": -64, + "max_y": 319, + "weight": 1.0, + "ore_replaceable": true + }, + "minecraft:granite": { + "enabled": true, + "family": "igneous_intrusive", + "depth_peak": 12, + "depth_spread": 44, + "min_y": -64, + "max_y": 319, + "weight": 1.0, + "ore_replaceable": true + } + }, + "terrain_dimensions": { + "minecraft:overworld": { + "enabled": true, + "biome_ids": [], + "biome_namespaces": [], + "host_blocks": ["minecraft:stone", "minecraft:deepslate"], + "host_tags": [] + } + }, + "ores": {}, + "oil": { + "min_y": -48, + "max_y": 32, + "frequency": 0.08, + "min_radius": 8, + "max_radius": 18, + "min_vertical_radius": 3, + "max_vertical_radius": 8, + "max_lobes": 5, + "min_solid_cover": 2 + }, + "retrogen": { + "enabled": false, + "force": false, + "revision": 0, + "chunks_per_tick": 1 + }, + "flat_bedrock": { + "enabled": false, + "retrogen": false, + "layers": 1, + "dimensions": ["minecraft:overworld", "minecraft:the_nether"] + }, + "worldgen_aliases": {}, + "providers": {}, + "ore_providers": {} +} diff --git a/docs/schemas/orespawn-global.schema.json b/docs/schemas/orespawn-global.schema.json new file mode 100644 index 00000000..2e2ff31a --- /dev/null +++ b/docs/schemas/orespawn-global.schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mcmoddev.com/orespawn/schemas/orespawn-global.schema.json", + "allOf": [ + { "$ref": "profile-common.schema.json" }, + { + "type": "object", + "required": ["schema_version"], + "properties": { "schema_version": { "const": 4 } } + } + ] +} diff --git a/docs/schemas/orespawn-provider.schema.json b/docs/schemas/orespawn-provider.schema.json new file mode 100644 index 00000000..e59631f1 --- /dev/null +++ b/docs/schemas/orespawn-provider.schema.json @@ -0,0 +1,56 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mcmoddev.com/orespawn/schemas/orespawn-provider.schema.json", + "type": "object", + "required": ["schema_version", "provider_modid", "provider_revision"], + "properties": { + "schema_version": { "enum": [1, 2] }, + "provider_modid": { "type": "string", "pattern": "^[a-z][a-z0-9_.-]+$" }, + "provider_revision": { "type": "integer", "minimum": 1 }, + "rocks": { "type": "object", "additionalProperties": { "$ref": "profile-common.schema.json#/$defs/rock" } }, + "ores": { "type": "object", "additionalProperties": { "$ref": "profile-common.schema.json#/$defs/ore" } }, + "geomes": { "type": "object", "additionalProperties": { "$ref": "profile-common.schema.json#/$defs/geome" } }, + "biome_rules": { "type": "object", "additionalProperties": { "$ref": "profile-common.schema.json#/$defs/weights" } }, + "terrain_dimensions": { "type": "object", "additionalProperties": { "$ref": "profile-common.schema.json#/$defs/terrainDimension" } }, + "profile_defaults": { "type": "object" }, + "templates": { + "type": "object", + "additionalProperties": { + "type": "object", + "required": ["profile"], + "properties": { + "name_key": { "type": "string" }, + "description_key": { "type": "string" }, + "required_mods": { "type": "array", "uniqueItems": true, "items": { "type": "string" } }, + "profile": { "type": "object" } + } + } + } + }, + "allOf": [ + { + "if": { "properties": { "schema_version": { "const": 1 } } }, + "then": { + "required": ["ores"], + "properties": { + "ores": { "minProperties": 1 }, + "rocks": false, + "geomes": false, + "biome_rules": false, + "terrain_dimensions": false, + "templates": false, + "profile_defaults": false + } + } + } + ], + "anyOf": [ + { "required": ["rocks"], "properties": { "rocks": { "minProperties": 1 } } }, + { "required": ["ores"], "properties": { "ores": { "minProperties": 1 } } }, + { "required": ["geomes"], "properties": { "geomes": { "minProperties": 1 } } }, + { "required": ["biome_rules"], "properties": { "biome_rules": { "minProperties": 1 } } }, + { "required": ["terrain_dimensions"], "properties": { "terrain_dimensions": { "minProperties": 1 } } }, + { "required": ["templates"], "properties": { "templates": { "minProperties": 1 } } } + ], + "additionalProperties": false +} diff --git a/docs/schemas/orespawn-world.schema.json b/docs/schemas/orespawn-world.schema.json new file mode 100644 index 00000000..9bcec549 --- /dev/null +++ b/docs/schemas/orespawn-world.schema.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mcmoddev.com/orespawn/schemas/orespawn-world.schema.json", + "allOf": [ + { "$ref": "profile-common.schema.json" }, + { + "type": "object", + "required": ["schema_version"], + "properties": { "schema_version": { "const": 3 } } + } + ] +} diff --git a/docs/schemas/profile-common.schema.json b/docs/schemas/profile-common.schema.json new file mode 100644 index 00000000..e0205016 --- /dev/null +++ b/docs/schemas/profile-common.schema.json @@ -0,0 +1,218 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://mcmoddev.com/orespawn/schemas/profile-common.schema.json", + "type": "object", + "required": ["formations", "rocks", "geomes", "biomes", "terrain_dimensions", "ores", "oil"], + "properties": { + "geology_mode": { "enum": ["geome", "legacy"] }, + "place_crude_oil": { "type": "boolean" }, + "manage_vanilla_ores": { "type": "boolean" }, + "suppress_all_ore_features": { "type": "boolean" }, + "default_template": { "$ref": "#/$defs/optionalRegistryId" }, + "selected_template": { "$ref": "#/$defs/registryId" }, + "formations": { "$ref": "#/$defs/formations" }, + "rocks": { "type": "object", "additionalProperties": { "$ref": "#/$defs/rock" } }, + "geomes": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/geome" } }, + "biomes": { "type": "object", "additionalProperties": { "$ref": "#/$defs/weights" } }, + "biome_dictionary": { "type": "object", "additionalProperties": { "$ref": "#/$defs/weights" } }, + "terrain_dimensions": { "type": "object", "additionalProperties": { "$ref": "#/$defs/terrainDimension" } }, + "ores": { "type": "object", "additionalProperties": { "$ref": "#/$defs/ore" } }, + "oil": { "$ref": "#/$defs/oil" }, + "worldgen_aliases": { "type": "object", "additionalProperties": { "$ref": "#/$defs/registryId" } }, + "providers": { "type": "object" }, + "ore_providers": { "type": "object" } + ,"retrogen": { "$ref": "#/$defs/retrogen" } + ,"flat_bedrock": { "$ref": "#/$defs/flatBedrock" } + }, + "additionalProperties": true, + "$defs": { + "registryId": { "type": "string", "pattern": "^[a-z0-9_.-]+:[a-z0-9_./-]+$" }, + "optionalRegistryId": { "type": "string", "pattern": "^(|[a-z0-9_.-]+:[a-z0-9_./-]+)$" }, + "registryIds": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/registryId" } }, + "family": { "enum": ["sedimentary", "metamorphic", "igneous_intrusive", "igneous_volcanic"] }, + "preset": { "enum": ["tiny", "small", "average", "large", "huge", "custom"] }, + "weights": { "type": "object", "additionalProperties": { "type": "number", "minimum": 0 } }, + "weightedBlock": { + "type": "object", + "required": ["block"], + "properties": { + "block": { "$ref": "#/$defs/registryId" }, + "weight": { "type": "number", "minimum": 0, "maximum": 1 } + } + }, + "weightedTag": { + "type": "object", + "required": ["tag"], + "properties": { + "tag": { "$ref": "#/$defs/registryId" }, + "weight": { "type": "number", "minimum": 0, "maximum": 1 } + } + }, + "hostBlocks": { + "type": "array", + "items": { "anyOf": [ + { "$ref": "#/$defs/registryId" }, + { "$ref": "#/$defs/weightedBlock" } + ] } + }, + "hostTags": { + "type": "array", + "items": { "anyOf": [ + { "$ref": "#/$defs/registryId" }, + { "$ref": "#/$defs/weightedTag" } + ] } + }, + "formations": { + "type": "object", + "required": ["algorithm", "horizontal_size", "vertical_thickness", "waviness", "edge_irregularity", "formation_continuity", "custom"], + "properties": { + "algorithm": { "enum": ["stable_layers", "sky_v1"] }, + "horizontal_size": { "$ref": "#/$defs/preset" }, + "vertical_thickness": { "$ref": "#/$defs/preset" }, + "waviness": { "$ref": "#/$defs/preset" }, + "edge_irregularity": { "$ref": "#/$defs/preset" }, + "formation_continuity": { "$ref": "#/$defs/preset" }, + "custom": { "type": "object", "additionalProperties": { "type": "number" } } + } + }, + "rock": { + "type": "object", + "required": ["enabled", "family", "depth_peak", "depth_spread", "min_y", "max_y", "weight", "ore_replaceable"], + "properties": { + "block": { "$ref": "#/$defs/registryId" }, + "enabled": { "type": "boolean" }, + "family": { "$ref": "#/$defs/family" }, + "depth_peak": { "type": "integer", "minimum": -2048, "maximum": 2048 }, + "depth_spread": { "type": "integer", "minimum": 1 }, + "min_y": { "type": "integer", "minimum": -2048, "maximum": 2048 }, + "max_y": { "type": "integer", "minimum": -2048, "maximum": 2048 }, + "weight": { "type": "number", "minimum": 0 }, + "ore_replaceable": { "type": "boolean" }, + "geomes": { "$ref": "#/$defs/weights" }, + "dimensions": { "$ref": "#/$defs/registryIds" } + }, + "additionalProperties": true + }, + "geome": { + "type": "object", + "required": ["base", "families"], + "properties": { + "base": { "type": "number", "minimum": 0 }, + "families": { "type": "object", "additionalProperties": { "type": "number", "minimum": 0 } } + }, + "additionalProperties": true + }, + "terrainDimension": { + "type": "object", + "required": ["enabled", "host_blocks", "host_tags"], + "properties": { + "enabled": { "type": "boolean" }, + "biome_ids": { "$ref": "#/$defs/registryIds" }, + "biome_namespaces": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^[a-z][a-z0-9_.-]+$" } }, + "host_blocks": { "$ref": "#/$defs/hostBlocks" }, + "host_tags": { "$ref": "#/$defs/hostTags" } + } + }, + "oreDimension": { + "type": "object", + "required": ["enabled", "min_y", "max_y", "frequency", "quantity"], + "properties": { + "enabled": { "type": "boolean" }, + "min_y": { "type": "integer", "minimum": -2048, "maximum": 2048 }, + "max_y": { "type": "integer", "minimum": -2048, "maximum": 2048 }, + "frequency": { "type": "number", "minimum": 0, "maximum": 64 }, + "quantity": { "type": "integer", "minimum": 1, "maximum": 64 }, + "pattern": { "anyOf": [ + { "enum": ["default", "vein", "normal_cloud", "precision", "clusters", "underfluids", "cluster", "cloud"] }, + { + "type": "object", + "required": ["type", "settings"], + "properties": { + "type": { "$ref": "#/$defs/registryId" }, + "settings": { "type": "object" } + } + } + ] }, + "height_distribution": { "enum": ["uniform", "triangle"] }, + "spread": { "type": "integer", "minimum": 0, "maximum": 64 }, + "vertical_spread": { "type": "integer", "minimum": 0, "maximum": 64 }, + "node_size": { "type": "integer", "minimum": 1, "maximum": 32 }, + "length": { "type": "integer", "minimum": 1, "maximum": 64 }, + "fluid": { "$ref": "#/$defs/registryId" }, + "host_families": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/family" } }, + "host_blocks": { "$ref": "#/$defs/hostBlocks" }, + "host_tags": { "$ref": "#/$defs/hostTags" }, + "geomes": { "$ref": "#/$defs/weights" }, + "biome_ids": { "$ref": "#/$defs/registryIds" }, + "excluded_biome_ids": { "$ref": "#/$defs/registryIds" }, + "biome_dictionary": { "type": "array", "items": { "type": "string" } }, + "excluded_biome_dictionary": { "type": "array", "items": { "type": "string" } } + }, + "anyOf": [ + { "required": ["host_families"] }, + { "required": ["host_blocks"] }, + { "required": ["host_tags"] } + ], + "additionalProperties": true + }, + "ore": { + "type": "object", + "required": ["enabled", "dimensions"], + "properties": { + "block": { "$ref": "#/$defs/registryId" }, + "enabled": { "type": "boolean" }, + "source_mod": { "type": "string" }, + "native_generation": { "type": "boolean" }, + "suppress_vanilla": { "type": "boolean" }, + "retrogen": { "type": "boolean" }, + "outputs": { + "type": "array", + "items": { + "type": "object", + "required": ["block", "weight"], + "properties": { + "block": { "$ref": "#/$defs/registryId" }, + "weight": { "type": "number", "minimum": 0 }, + "min_y": { "type": "integer" }, + "max_y": { "type": "integer" } + } + } + }, + "deep_output": { "$ref": "#/$defs/registryId" }, + "deep_output_max_y": { "type": "integer" }, + "dimensions": { "type": "object", "minProperties": 1, "additionalProperties": { "$ref": "#/$defs/oreDimension" } } + }, + "additionalProperties": true + }, + "oil": { + "type": "object", + "required": ["min_y", "max_y", "frequency", "min_radius", "max_radius", "min_vertical_radius", "max_vertical_radius", "max_lobes", "min_solid_cover"], + "properties": { + "block": { "$ref": "#/$defs/registryId" }, + "min_y": { "type": "integer" }, "max_y": { "type": "integer" }, + "frequency": { "type": "number", "minimum": 0 }, + "min_radius": { "type": "integer", "minimum": 1 }, "max_radius": { "type": "integer", "minimum": 1 }, + "min_vertical_radius": { "type": "integer", "minimum": 1 }, "max_vertical_radius": { "type": "integer", "minimum": 1 }, + "max_lobes": { "type": "integer", "minimum": 1 }, "min_solid_cover": { "type": "integer", "minimum": 0 } + } + }, + "retrogen": { + "type": "object", + "properties": { + "enabled": { "type": "boolean" }, + "force": { "type": "boolean" }, + "revision": { "type": "integer", "minimum": 0 }, + "chunks_per_tick": { "type": "integer", "minimum": 1, "maximum": 16 } + } + }, + "flatBedrock": { + "type": "object", + "properties": { + "enabled": { "type": "boolean" }, + "retrogen": { "type": "boolean" }, + "layers": { "type": "integer", "minimum": 1, "maximum": 5 }, + "dimensions": { "$ref": "#/$defs/registryIds" } + } + } + } +} diff --git a/gradle.properties b/gradle.properties index 31c10144..d4700ba6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,128 +1,59 @@ -org.gradle.daemon = false - -group = com.mcmoddev -archivesBaseName = OreSpawn -modid = orespawn -vendor = mcmoddev -name = MMD OreSpawn -description = MMD OreSpawn - -#Minumum Minecraft Version Mod will be built with -mc_version=1.12 - -#ForgeGradle version to use (Required) -fg_version = 2.3-SNAPSHOT -#version of Minecraft Forge is built against (Required) -forge_mc_version = 1.12.2 -#Forge version to use (Required) -forge_version = 14.23.5.2847 -#Mappings version to use (Required) -mcp_mappings_version = stable_39 - -# The following will currently only be set when using Gradle 4.8 or later -pom_information = false -pom_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' - -pom_license_information = true -pom_license_name = 'GNU Lesser General Public License v2.1' -pom_license_url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt' -pom_comments = '' - -pom_scm_information = true -pom_scm_connection = 'scm:git:git://github.com/MinecraftModDevelopmentMods/OreSpawn.git' -pom_scm_developer_connection = 'scm:git:git@github.com:MinecraftModDevelopmentMods/OreSpawn.git' -pom_scm_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn' - -pom_issue_information = true -pom_issue_system = 'github' -pom_issue_url = 'https://github.com/MinecraftModDevelopmentMods/OreSpawn/issues' - -pom_ci_information = true -pom_ci_system = 'jenkins' -pom_ci_url = 'https://ci.mcmoddev.com/' - -pom_organisation_information = true -pom_organization_name = 'Minecraft Mod Development' -pom_organization_url = 'https://mcmoddev.com/' - -curseforge_do_upload=false -#curseforge_debug=false -#Cursforge Project ID (Required) -curseforge_project_id = 245586 -#Type of Release, can be one of 'alpha', 'beta' or 'release' (Defaults to 'alpha' if not set) -curseforge_release_type = release -#When using a ChangeLog file specifies filename -curseforge_changelog_filename = CHANGELOG.txt -#Changelog type, can be one of 'text', 'html' or 'markdown' (Defaults to 'text' if not set) -curseforge_changelog_type = text -#Version(s) of Minecraft this mod will work on (comma separated list) -curseforge_versions = 1.12, 1.12.1, 1.12.2 -#Whether to use a custom display name on artifacts -curseforge_use_custom_display_name = true -#List of required dependencies (comma separated list) -#curseforge_requirements = -#List of optional dependencies (comma separated list) -#curseforge_optionals = -#List of embedded dependencies (comma separated list) -#curseforge_embeddeds = -#List of compatible tools (comma separated list) -#curseforge_tools = -#List of incompatible dependencies (comma separated list) -#curseforge_incompatibles = -#List of included dependencies (comma separated list) -#curseforge_includes = - -#String reference to Core Plugin this mod contains, if any -#core_plugin = -#Whether or not to use Access Transformers from depended mods -dep_has_ats = false -#File name of this mod's Access Transformers (If any) -#mod_at_file = _at.cfg - -#Whether the artifacts should be signed -do_sign_jar = true - -#Create a source jar? -create_source_jar = true -#Create an API jar? -create_api_jar = true -#Create a deobf jar? -create_deobf_jar = true -#Create a javadoc jar? -create_javadoc_jar = true - -#The following four options are optional and do not affect your build in any way -#They are only for convenience when using the 'runClient' and 'runServer' tasks -#Whether to Disable server gui -#mc_server_nogui = true -#Whether to Skip the screen to confirm that you want to load a world with missing registry entries -#forge_do_not_backup = true -#Whether to skip having to confirm on server -#forge_query_result_confirm = true -#Whether to Skip jansi warnings in the log -#log4j_skip_jansi = true - -# Optional convenience setter for game resolution one of '480p', '576p', '720p', '1080p' or 'custom' -#mc_resolution = 1080p -#the following two will only be used when mc_resolution = custom -#mc_custom_resolution_width = 1920 -#mc_custom_resolution_height = 1080 -#mc_fullscreen = true - -#Additional arguments to pass to minecraft.clientJvmArgs -#client_jvm_args = -#Additional arguments to pass to minecraft.serverJvmArgs -#client_game_args = -#Additional arguments to pass to minecraft.clientRunArgs -#server_jvm_args = -#Additional arguments to pass to minecraft.serverRunArgs -#server_game_args = - -##The following three options should *NEVER* be set in this file, it's a security risk, Be safe, keep your account information private. -##These properties here are for reference only and explanation of what they do -##Your Minecraft account username (Consistent player name for singleplayer worlds) -##mc_username = -##Your Minecraft account password (Allows online play while present with associated username) -##mc_password = -##Your Minecraft account uuid (Allows using your skin while testing, This can be with or without hyphens) -##mc_uuid = +# Sets default memory used for gradle commands. Can be overridden by user or command line properties. +# This is required to provide enough memory for the Minecraft decompilation process. +org.gradle.jvmargs=-Xmx3G +org.gradle.daemon=false + + +## Environment Properties + +# The Minecraft version must agree with the Forge version to get a valid artifact +minecraft_version=1.18.2 +# The Minecraft version range can use any release version of Minecraft as bounds. +# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly +# as they do not follow standard versioning conventions. +minecraft_version_range=[1.18.2,1.19) +# The Forge version must agree with the Minecraft version to get a valid artifact +forge_version=40.3.0 +# The Forge version range can use any version of Forge as bounds or match the loader version range +forge_version_range=[40,) +# The loader version range can only use the major version of Forge/FML as bounds +loader_version_range=[40,) +# The mapping channel to use for mappings. +# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. +# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin. +# +# | Channel | Version | | +# |-----------|----------------------|--------------------------------------------------------------------------------| +# | official | MCVersion | Official field/method names from Mojang mapping files | +# | parchment | YYYY.MM.DD-MCVersion | Open community-sourced parameter names and javadocs layered on top of official | +# +# You must be aware of the Mojang license when using the 'official' or 'parchment' mappings. +# See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md +# +# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge. +# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started +mapping_channel=official +# The mapping version to query from the mapping channel. +# This must match the format required by the mapping channel. +mapping_version=1.18.2 + + +## Mod Properties + +# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} +# Must match the String constant located in the main mod class annotated with @Mod. +mod_id=orespawn +# The human-readable display name for the mod. +mod_name=MMD OreSpawn +# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. +mod_license=LGPL-2.1 +# The mod version. See https://semver.org/ +mod_version=4.0.0 +# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. +# This should match the base package used for the mod sources. +# See https://maven.apache.org/guides/mini/guide-naming-conventions.html +mod_group_id=com.mcmoddev +# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. +mod_authors=SkyBlade1978, dshadowwolf, the MMD Team +# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. +mod_description=Configurable, provider-driven terrain, ore, and deposit generation. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0d4a9516871afd710a9d84d89e31ba77745607bd..249e5832f090a2944b7473328c07c9755baa3196 100644 GIT binary patch literal 60756 zcmb5WV{~QRw(p$^Dz@00IL3?^hro$gg*4VI_WAaTyVM5Foj~O|-84 z$;06hMwt*rV;^8iB z1~&0XWpYJmG?Ts^K9PC62H*`G}xom%S%yq|xvG~FIfP=9*f zZoDRJBm*Y0aId=qJ?7dyb)6)JGWGwe)MHeNSzhi)Ko6J<-m@v=a%NsP537lHe0R* z`If4$aaBA#S=w!2z&m>{lpTy^Lm^mg*3?M&7HFv}7K6x*cukLIGX;bQG|QWdn{%_6 zHnwBKr84#B7Z+AnBXa16a?or^R?+>$4`}{*a_>IhbjvyTtWkHw)|ay)ahWUd-qq$~ zMbh6roVsj;_qnC-R{G+Cy6bApVOinSU-;(DxUEl!i2)1EeQ9`hrfqj(nKI7?Z>Xur zoJz-a`PxkYit1HEbv|jy%~DO^13J-ut986EEG=66S}D3!L}Efp;Bez~7tNq{QsUMm zh9~(HYg1pA*=37C0}n4g&bFbQ+?-h-W}onYeE{q;cIy%eZK9wZjSwGvT+&Cgv z?~{9p(;bY_1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-ksV;G;Xe`lh76T#Htuia+(UrIXrf9?

Classes outside this package are implementation details and may change + * between releases without an API-version change.

+ */ +package com.mcmoddev.orespawn.api; diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java deleted file mode 100644 index d3b0bf7c..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/IOreSpawnPlugin.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.mcmoddev.orespawn.api.plugin; - -import com.mcmoddev.orespawn.api.os3.OS3API; - -public interface IOreSpawnPlugin { - - void register(OS3API apiInterface); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java deleted file mode 100644 index 7120c8be..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/OreSpawnPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.mcmoddev.orespawn.api.plugin; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -@Retention(RUNTIME) -@Target(TYPE) -public @interface OreSpawnPlugin { - - // the Mod this is for - will be used for - // generating the name of the json the config - // will get saved to and should also be the - // actual mod-id we can use for creating a - // resource location - String modid(); - - // resource location segment to look in - // for registered config files - - String resourcePath() default "orespawn"; -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java b/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java deleted file mode 100644 index 74a4c118..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/plugin/PluginLoader.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.mcmoddev.orespawn.api.plugin; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.FileSystem; -import java.nio.file.FileSystems; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.stream.Stream; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; - -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.data.Config; -import com.mcmoddev.orespawn.data.Constants; - -import net.minecraft.crash.CrashReport; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public enum PluginLoader { - - INSTANCE; - - private class PluginData { - - public final String modId; - public final String resourcePath; - public final IOreSpawnPlugin plugin; - - PluginData(final String modId, final String resourcePath, final IOreSpawnPlugin plugin) { - this.modId = modId; - this.resourcePath = resourcePath; - this.plugin = plugin; - } - } - - private static List dataStore = new ArrayList<>(); - - private String getAnnotationItem(final String item, final ASMData asmData) { - if (asmData.getAnnotationInfo().get(item) != null) { - return asmData.getAnnotationInfo().get(item).toString(); - } else { - return ""; - } - } - - public void load(final FMLPreInitializationEvent event) { - for (final ASMData asmDataItem : event.getAsmData() - .getAll(OreSpawnPlugin.class.getCanonicalName())) { - final String modId = getAnnotationItem("modid", asmDataItem); - final String resourceBase = getAnnotationItem("resourcePath", asmDataItem); - final String clazz = asmDataItem.getClassName(); - IOreSpawnPlugin integration; - - try { - integration = Class.forName(clazz).asSubclass(IOreSpawnPlugin.class).newInstance(); - final PluginData pd = new PluginData(modId, resourceBase, integration); - OreSpawn.LOGGER.info("Loading Integration For {}", modId); - dataStore.add(pd); - } catch (final Exception ex) { - OreSpawn.LOGGER.error("Couldn't load integrations for " + modId, ex); - } - } - } - - public void register() { - dataStore.forEach(pd -> { - scanResources(pd); - pd.plugin.register(OreSpawn.API); - }); - } - - public void scanResources(final PluginData pd) { - if (Config.getKnownMods().contains(pd.modId)) { - return; - } - - final String base = String.format(Locale.ENGLISH, "assets/%s/%s", pd.modId, pd.resourcePath); - final URL resURL = getClass().getClassLoader().getResource(base); - - if (resURL == null) { - OreSpawn.LOGGER.warn("Unable to access file {}: got 'null' when trying to resolve it", - base); - return; - } - - URI uri; - - try { - uri = resURL.toURI(); - } catch (URISyntaxException ex) { - CrashReport report = CrashReport.makeCrashReport(ex, - String.format(Locale.ENGLISH, "Failed to get URI for %s", - (new ResourceLocation(pd.modId, pd.resourcePath)).toString())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - return; - } - - if (uri.getScheme().equals("jar")) { - try (FileSystem fileSystem = FileSystems.newFileSystem(uri, - Collections.emptyMap())) { - copyout(fileSystem.getPath(base), pd.modId); - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - Locale.ENGLISH, "Failed in getting FileSystem handler set up for %s", uri.getPath())); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.info(report.getCompleteReport()); - } - } else { - copyout(Paths.get(uri), pd.modId); - } - - Config.addKnownMod(pd.modId); - } - - private void copyout(final Path myPath, final String modId) { - try (Stream walk = Files.walk(myPath, 1)) { - for (final Iterator it = walk.iterator(); it.hasNext();) { - final Path p = it.next(); - final String name = p.getFileName().toString(); - - if ("json".equals(FilenameUtils.getExtension(name))) { - InputStream reader = null; - Path target; - - if ("_features".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format(Locale.ENGLISH, "features-%s.json", modId)); - } else if ("_replacements".equals(FilenameUtils.getBaseName(name))) { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - Constants.FileBits.SYSCONF, - String.format(Locale.ENGLISH, "replacements-%s.json", modId)); - } else { - target = Paths.get(Constants.FileBits.CONFIG_DIR, Constants.FileBits.OS3, - String.format(Locale.ENGLISH, "%s.json", modId)); - } - - if (!target.toFile().exists()) { - reader = Files.newInputStream(p); - FileUtils.copyInputStreamToFile(reader, target.toFile()); - IOUtils.closeQuietly(reader); - } - } - } - } catch (IOException exc) { - CrashReport report = CrashReport.makeCrashReport(exc, String.format( - Locale.ENGLISH, "Faulted while iterating %s for config files or copying them out", myPath)); - report.getCategory().addCrashSection(Constants.CRASH_SECTION, Constants.VERSION); - OreSpawn.LOGGER.error(report.getCompleteReport()); - } - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/client/AdvancedGeologySettingsScreen.java b/src/main/java/com/mcmoddev/orespawn/client/AdvancedGeologySettingsScreen.java new file mode 100644 index 00000000..6e02cca0 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/AdvancedGeologySettingsScreen.java @@ -0,0 +1,53 @@ +package com.mcmoddev.orespawn.client; + +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.TranslatableComponent; + +/** Less commonly changed numeric controls, kept off the world settings overview. */ +final class AdvancedGeologySettingsScreen extends Screen { + private final Screen parent; + private final GeologyEditorSession session; + + AdvancedGeologySettingsScreen(Screen parent, GeologyEditorSession session) { + super(new TranslatableComponent("screen.orespawn.advanced")); + this.parent = parent; + this.session = session; + } + + @Override + protected void init() { + int left = width / 2 - 155; + int top = 54; + addRenderableWidget(new Button(left, top, 310, 20, + new TranslatableComponent("button.orespawn.formation_details"), + button -> openNumeric("formations.custom", NumericConfigScreen.FORMATION_FIELDS))); + addRenderableWidget(new Button(left, top + 28, 310, 20, + new TranslatableComponent("button.orespawn.oil_details"), + button -> openNumeric("oil", NumericConfigScreen.OIL_FIELDS))); + addRenderableWidget(new Button(left, top + 56, 310, 20, + new TranslatableComponent("button.orespawn.cyano_details"), + button -> openNumeric("cyano", NumericConfigScreen.CYANO_FIELDS))); + addRenderableWidget(new Button(width / 2 - 75, OreSpawnScreenLayout.footerY(height), 150, 20, + CommonComponents.GUI_DONE, button -> onClose())); + } + + private void openNumeric(String path, NumericConfigScreen.Field[] fields) { + minecraft.setScreen(new NumericConfigScreen(this, session, path, fields)); + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 20, 0xFFFFFF); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/BlockAssignmentScreen.java b/src/main/java/com/mcmoddev/orespawn/client/BlockAssignmentScreen.java new file mode 100644 index 00000000..f2c58e6a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/BlockAssignmentScreen.java @@ -0,0 +1,70 @@ +package com.mcmoddev.orespawn.client; + +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; + +final class BlockAssignmentScreen extends Screen { + private final Screen parent; + private final GeologyEditorSession session; + private final String blockId; + private Component error; + + BlockAssignmentScreen(Screen parent, GeologyEditorSession session, String blockId) { + super(new TranslatableComponent("screen.orespawn.assign_block")); + this.parent = parent; + this.session = session; + String canonicalId = session.canonicalBlockId(blockId); + this.blockId = canonicalId == null ? blockId : canonicalId; + } + + @Override + protected void init() { + int left = width / 2 - 155; + int right = width / 2 + 5; + addRenderableWidget(new Button(left, 70, 150, 20, new TranslatableComponent("tab.orespawn.sedimentary"), + button -> assignRock(RockFamily.SEDIMENTARY))); + addRenderableWidget(new Button(right, 70, 150, 20, new TranslatableComponent("tab.orespawn.metamorphic"), + button -> assignRock(RockFamily.METAMORPHIC))); + addRenderableWidget(new Button(left, 98, 150, 20, new TranslatableComponent("value.orespawn.intrusive"), + button -> assignRock(RockFamily.IGNEOUS_INTRUSIVE))); + addRenderableWidget(new Button(right, 98, 150, 20, new TranslatableComponent("value.orespawn.volcanic"), + button -> assignRock(RockFamily.IGNEOUS_VOLCANIC))); + addRenderableWidget(new Button(left, 126, 310, 20, new TranslatableComponent("tab.orespawn.ores"), + button -> assignOre())); + addRenderableWidget(new Button(width / 2 - 75, height - 28, 150, 20, CommonComponents.GUI_CANCEL, + button -> onClose())); + } + + private void assignRock(RockFamily family) { + session.assignRock(blockId, family); + if (session.section("rocks").has(blockId)) minecraft.setScreen(parent); + else error = new TextComponent("Unknown or unsuitable block: " + blockId); + } + + private void assignOre() { + session.assignOre(blockId); + if (session.section("ores").has(blockId)) minecraft.setScreen(parent); + else error = new TextComponent("Unknown or unsuitable block: " + blockId); + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 18, 0xFFFFFF); + drawCenteredString(poseStack, font, new TextComponent(blockId), width / 2, 42, 0xDDDDDD); + if (error != null) drawCenteredString(poseStack, font, error, width / 2, 155, 0xFF5555); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/BlockPickerScreen.java b/src/main/java/com/mcmoddev/orespawn/client/BlockPickerScreen.java new file mode 100644 index 00000000..d956473e --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/BlockPickerScreen.java @@ -0,0 +1,129 @@ +package com.mcmoddev.orespawn.client; + +import java.util.List; + +import com.mcmoddev.orespawn.client.GeologyEditorSession.MaterialTab; +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.CycleButton; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; + +/** Registry-backed picker; text narrows installed blocks but never creates an ID. */ +final class BlockPickerScreen extends Screen { + private final GeologyMaterialsScreen parent; + private final GeologyEditorSession session; + private final MaterialTab target; + private String searchText = ""; + private String namespace = ""; + private boolean showAll; + private int page; + private EditBox search; + + BlockPickerScreen(GeologyMaterialsScreen parent, GeologyEditorSession session, MaterialTab target) { + super(new TranslatableComponent("screen.orespawn.choose_block")); + this.parent = parent; + this.session = session; + this.target = target; + } + + @Override + protected void init() { + int left = width / 2 - 155; + search = addRenderableWidget(new EditBox(font, left, 34, 230, 20, + new TranslatableComponent("option.orespawn.search"))); + search.setMaxLength(128); + search.setValue(searchText); + addRenderableWidget(new Button(left + 235, 34, 75, 20, + new TranslatableComponent("button.orespawn.search"), button -> { + searchText = search.getValue(); + page = 0; + rebuildWidgets(); + })); + + List namespaces = session.installedBlockNamespaces(); + if (!namespaces.contains(namespace)) namespace = ""; + addRenderableWidget(CycleButton.builder(this::namespaceName) + .withValues(namespaces).withInitialValue(namespace) + .create(left, 58, 150, 20, new TranslatableComponent("option.orespawn.mod_filter"), + (button, value) -> { namespace = value; page = 0; rebuildWidgets(); })); + addRenderableWidget(new Button(left + 160, 58, 150, 20, + new TranslatableComponent(showAll ? "button.orespawn.safe_only" : "button.orespawn.show_all"), + button -> { showAll = !showAll; page = 0; rebuildWidgets(); })); + + List ids = session.availableBlockIds(searchText, namespace, showAll); + int listTop = 84; + int controlsY = height - 52; + int pageSize = Math.max(1, (controlsY - listTop) / 24); + int pageCount = Math.max(1, (ids.size() + pageSize - 1) / pageSize); + page = Math.max(0, Math.min(page, pageCount - 1)); + int start = page * pageSize; + for (int i = 0; i < pageSize && start + i < ids.size(); i++) { + String id = ids.get(start + i); + addRenderableWidget(new Button(left, listTop + (i * 24), 310, 20, + new TextComponent(id), button -> select(id))); + } + Button previous = addRenderableWidget(new Button(left, controlsY, 45, 20, + new TextComponent("<"), button -> { page--; rebuildWidgets(); })); + Button next = addRenderableWidget(new Button(left + 50, controlsY, 45, 20, + new TextComponent(">"), button -> { page++; rebuildWidgets(); })); + previous.active = page > 0; + next.active = page + 1 < pageCount; + addRenderableWidget(new Button(width / 2 - 75, height - 28, 150, 20, + CommonComponents.GUI_CANCEL, button -> onClose())); + } + + private void select(String id) { + switch (target) { + case SEDIMENTARY: + session.assignRock(id, RockFamily.SEDIMENTARY); + minecraft.setScreen(new RockEntryScreen(parent, session, id)); + break; + case METAMORPHIC: + session.assignRock(id, RockFamily.METAMORPHIC); + minecraft.setScreen(new RockEntryScreen(parent, session, id)); + break; + case IGNEOUS: + session.assignRock(id, RockFamily.IGNEOUS_INTRUSIVE); + minecraft.setScreen(new RockEntryScreen(parent, session, id)); + break; + case ORES: + session.assignOre(id); + minecraft.setScreen(new OreEntryScreen(parent, session, id)); + break; + default: + minecraft.setScreen(new BlockAssignmentScreen(parent, session, id)); + } + } + + private Component namespaceName(String value) { + return value.isEmpty() ? new TranslatableComponent("value.orespawn.all_mods") : new TextComponent(value); + } + + private void rebuildWidgets() { + clearWidgets(); + init(); + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 8, 0xFFFFFF); + drawCenteredString(poseStack, font, + new TranslatableComponent("label.orespawn.adding_to", + new TranslatableComponent("tab.orespawn." + target.key)), + width / 2, 20, 0xCCCCCC); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/ClientSetup.java b/src/main/java/com/mcmoddev/orespawn/client/ClientSetup.java new file mode 100644 index 00000000..cd85135a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/ClientSetup.java @@ -0,0 +1,18 @@ +package com.mcmoddev.orespawn.client; + +import com.mcmoddev.orespawn.OreSpawn; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; + +@Mod.EventBusSubscriber(modid = OreSpawn.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) +public final class ClientSetup { + private ClientSetup() { + } + + @SubscribeEvent + public static void clientSetup(FMLClientSetupEvent event) { + // The world-creation editor registers through its Forge screen events. + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/DimensionDiscovery.java b/src/main/java/com/mcmoddev/orespawn/client/DimensionDiscovery.java new file mode 100644 index 00000000..e1e00090 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/DimensionDiscovery.java @@ -0,0 +1,92 @@ +package com.mcmoddev.orespawn.client; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Stream; + +import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen; +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.forgespi.locating.IModFile; + +final class DimensionDiscovery { + private static final String OVERWORLD = "minecraft:overworld"; + private static final String NETHER = "minecraft:the_nether"; + private static final String END = "minecraft:the_end"; + + private DimensionDiscovery() { + } + + static List availableDimensionIds(CreateWorldScreen screen) { + Set result = new TreeSet<>(); + result.add(OVERWORLD); + result.add(NETHER); + result.add(END); + + try { + screen.worldGenSettingsComponent.makeSettings(screen.hardCore).dimensions().keySet() + .forEach(id -> result.add(id.toString())); + } catch (RuntimeException ignored) { + // The vanilla dimensions above keep the picker usable if a custom preset is incomplete. + } + + ModList modList = ModList.get(); + if (modList != null) { + modList.forEachModFile(file -> collectModDimensions(file, result)); + } + return vanillaFirst(result); + } + + private static List vanillaFirst(Set ids) { + List result = new ArrayList<>(); + result.add(OVERWORLD); + result.add(NETHER); + result.add(END); + ids.remove(OVERWORLD); + ids.remove(NETHER); + ids.remove(END); + result.addAll(ids); + return result; + } + + private static void collectModDimensions(IModFile modFile, Set result) { + try { + Path dataRoot = modFile.findResource("data"); + if (!Files.isDirectory(dataRoot)) return; + try (Stream namespaces = Files.list(dataRoot)) { + namespaces.filter(Files::isDirectory) + .forEach(namespace -> collectNamespaceDimensions(namespace, result)); + } + } catch (IOException | RuntimeException ignored) { + // A broken optional resource path must not prevent opening the world editor. + } + } + + private static void collectNamespaceDimensions(Path namespaceRoot, Set result) { + Path dimensionRoot = namespaceRoot.resolve("dimension"); + if (!Files.isDirectory(dimensionRoot)) return; + String namespace = namespaceRoot.getFileName().toString(); + try (Stream files = Files.walk(dimensionRoot)) { + files.filter(Files::isRegularFile).forEach(file -> { + String relative = dimensionRoot.relativize(file).toString().replace('\\', '/'); + if (!relative.endsWith(".json")) return; + addDimensionId(result, namespace, relative.substring(0, relative.length() - 5)); + }); + } catch (IOException | RuntimeException ignored) { + // Continue with dimensions discovered from other mods and the active preset. + } + } + + static void addDimensionId(Set target, String namespace, String path) { + try { + target.add(new ResourceLocation(namespace, path).toString()); + } catch (RuntimeException ignored) { + // Ignore malformed resource paths from third-party jars. + } + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/GeologyEditorSession.java b/src/main/java/com/mcmoddev/orespawn/client/GeologyEditorSession.java new file mode 100644 index 00000000..97a61518 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/GeologyEditorSession.java @@ -0,0 +1,705 @@ +package com.mcmoddev.orespawn.client; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Map.Entry; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.worldgen.OreHeightDistribution; +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mcmoddev.orespawn.init.OreSpawnPatterns; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfile; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.EmptyBlockGetter; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.world.item.Items; +import net.minecraftforge.registries.ForgeRegistries; + +/** Mutable client-side copy used until the Create World settings are accepted. */ +final class GeologyEditorSession { + enum MaterialTab { + SEDIMENTARY("sedimentary"), + METAMORPHIC("metamorphic"), + IGNEOUS("igneous"), + ORES("ores"), + UNASSIGNED("unassigned"); + + final String key; + + MaterialTab(String key) { + this.key = key; + } + } + + static final Set BUILT_IN_GEOMES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + "stable_craton", "mountain_belt", "volcanic_arc", "sedimentary_basin", + "coastal_shelf", "arid_basin", "wetland_basin", "glacial_highland"))); + + private final WorldGeologyProfile originalProfile; + private final JsonObject original; + private final JsonObject root; + private final Set availableDimensionIds = new TreeSet<>(); + + GeologyEditorSession(WorldGeologyProfile profile) { + this(profile, Collections.emptyList()); + } + + GeologyEditorSession(WorldGeologyProfile profile, Iterable dimensions) { + originalProfile = profile; + original = profile.rootCopy(); + root = profile.rootCopy(); + normalizeRegistrySections(original); + normalizeRegistrySections(root); + rememberDimension("minecraft:overworld"); + rememberDimension("minecraft:the_nether"); + rememberDimension("minecraft:the_end"); + for (String dimension : dimensions) rememberDimension(dimension); + } + + JsonObject root() { + return root; + } + + WorldGeologyProfile profile() { + return originalProfile.withRoot(root); + } + + void applyProfile(WorldGeologyProfile profile) { + root.entrySet().clear(); + for (Entry entry : profile.rootCopy().entrySet()) { + root.add(entry.getKey(), entry.getValue().deepCopy()); + } + normalizeRegistrySections(root); + } + + JsonObject section(String key) { + return object(root, key); + } + + double oreFrequencyBaseline(String oreId, String dimensionId) { + if (!original.has("ores") || !original.get("ores").isJsonObject()) return 1.0D; + JsonObject ores = original.getAsJsonObject("ores"); + if (!ores.has(oreId) || !ores.get(oreId).isJsonObject()) return 1.0D; + JsonObject ore = ores.getAsJsonObject(oreId); + if (!ore.has("dimensions") || !ore.get("dimensions").isJsonObject()) return 1.0D; + JsonObject dimensions = ore.getAsJsonObject("dimensions"); + if (!dimensions.has(dimensionId) || !dimensions.get(dimensionId).isJsonObject()) return 1.0D; + double value = decimal(dimensions.getAsJsonObject(dimensionId), "frequency", 1.0D); + return Double.isFinite(value) && value >= 0.0D && value <= OreRichnessPreset.MAX_FREQUENCY + ? value : 1.0D; + } + + List availableDimensionIds() { + Set result = new TreeSet<>(availableDimensionIds); + for (Entry oreEntry : section("ores").entrySet()) { + JsonElement oreElement = oreEntry.getValue(); + if (!oreElement.isJsonObject()) continue; + JsonObject ore = oreElement.getAsJsonObject(); + if (!ore.has("dimensions") || !ore.get("dimensions").isJsonObject()) continue; + for (String id : ore.getAsJsonObject("dimensions").keySet()) { + if (validResource(id)) result.add(new ResourceLocation(id).toString()); + } + } + List ordered = new ArrayList<>(); + for (String vanilla : Arrays.asList("minecraft:overworld", "minecraft:the_nether", "minecraft:the_end")) { + ordered.add(vanilla); + result.remove(vanilla); + } + ordered.addAll(result); + return ordered; + } + + private void rememberDimension(String id) { + if (validResource(id)) availableDimensionIds.add(new ResourceLocation(id).toString()); + } + + List materialIds(MaterialTab tab, String search, boolean showAll) { + String query = search == null ? "" : search.trim().toLowerCase(Locale.ROOT); + List result = new ArrayList<>(); + if (tab == MaterialTab.ORES) { + result.addAll(section("ores").keySet()); + } else if (tab == MaterialTab.UNASSIGNED) { + return availableBlockIds(query, "", showAll); + } else { + for (Entry entry : section("rocks").entrySet()) { + if (!entry.getValue().isJsonObject()) { + continue; + } + String family = string(entry.getValue().getAsJsonObject(), "family", ""); + if ((tab == MaterialTab.SEDIMENTARY && "sedimentary".equals(family)) + || (tab == MaterialTab.METAMORPHIC && "metamorphic".equals(family)) + || (tab == MaterialTab.IGNEOUS && family.startsWith("igneous_"))) { + result.add(entry.getKey()); + } + } + } + result.removeIf(id -> !query.isEmpty() + && !id.toLowerCase(Locale.ROOT).contains(query) + && !materialBlockId(tab, id).toLowerCase(Locale.ROOT).contains(query)); + Collections.sort(result); + return result; + } + + List availableBlockIds(String search, String namespace, boolean showAll) { + String query = search == null ? "" : search.trim().toLowerCase(Locale.ROOT); + String mod = namespace == null ? "" : namespace.trim().toLowerCase(Locale.ROOT); + Set assigned = assignedBlockIds(); + List result = new ArrayList<>(); + for (Block block : ForgeRegistries.BLOCKS.getValues()) { + ResourceLocation id = ForgeRegistries.BLOCKS.getKey(block); + if (id == null || assigned.contains(id.toString()) || isWorldgenAliasSource(id.toString()) + || (!mod.isEmpty() && !mod.equals(id.getNamespace())) + || (!query.isEmpty() && !id.toString().toLowerCase(Locale.ROOT).contains(query)) + || !isSelectable(block, showAll)) { + continue; + } + result.add(id.toString()); + } + Collections.sort(result); + return result; + } + + String materialBlockId(MaterialTab tab, String entryId) { + if (tab == MaterialTab.UNASSIGNED) return entryId; + JsonObject section = section(tab == MaterialTab.ORES ? "ores" : "rocks"); + if (!section.has(entryId) || !section.get(entryId).isJsonObject()) return entryId; + return string(section.getAsJsonObject(entryId), "block", entryId); + } + + private Set assignedBlockIds() { + Set result = new HashSet<>(); + for (String sectionName : new String[] { "rocks", "ores" }) { + for (Entry entry : section(sectionName).entrySet()) { + if (entry.getValue().isJsonObject()) { + result.add(string(entry.getValue().getAsJsonObject(), "block", entry.getKey())); + } + } + } + return result; + } + + List installedBlockNamespaces() { + TreeSet namespaces = new TreeSet<>(); + for (Block block : ForgeRegistries.BLOCKS.getValues()) { + ResourceLocation id = ForgeRegistries.BLOCKS.getKey(block); + if (id != null && block != Blocks.AIR && block.asItem() != Items.AIR) { + namespaces.add(id.getNamespace()); + } + } + List result = new ArrayList<>(); + result.add(""); + result.addAll(namespaces); + return result; + } + + void assignRock(String id, RockFamily family) { + String canonicalId = canonicalBlockId(id); + if (canonicalId == null) { + return; + } + JsonObject rock = new JsonObject(); + rock.addProperty("enabled", true); + rock.addProperty("family", family.configName); + rock.addProperty("depth_peak", defaultPeak(family)); + rock.addProperty("depth_spread", 40); + rock.addProperty("min_y", -64); + rock.addProperty("max_y", 319); + rock.addProperty("weight", 1.0D); + rock.addProperty("ore_replaceable", true); + rock.add("geomes", new JsonObject()); + section("rocks").add(canonicalId, rock); + disableOrRemoveOre(canonicalId); + } + + void assignOre(String id) { + String canonicalId = canonicalBlockId(id); + if (canonicalId == null) { + return; + } + section("rocks").remove(canonicalId); + JsonObject ore = new JsonObject(); + ore.addProperty("enabled", true); + ResourceLocation blockId = new ResourceLocation(canonicalId); + ore.addProperty("source_mod", blockId.getNamespace()); + JsonObject dimensions = new JsonObject(); + JsonObject overworld = defaultOreDimension(); + dimensions.add("minecraft:overworld", overworld); + ore.add("dimensions", dimensions); + section("ores").add(canonicalId, ore); + } + + void removeRock(String id) { + section("rocks").remove(id); + } + + void disableOrRemoveOre(String id) { + JsonObject ores = section("ores"); + if (!ores.has(id) || !ores.get(id).isJsonObject()) { + return; + } + JsonObject ore = ores.getAsJsonObject(id); + if (ore.has("source_provider")) { + ore.addProperty("enabled", false); + ore.addProperty("unassigned", true); + } else { + ores.remove(id); + } + } + + void resetEntry(String section, String id) { + JsonObject originalSection = object(original, section); + if (originalSection.has(id)) { + section(section).add(id, originalSection.get(id).deepCopy()); + } + } + + JsonObject rock(String id) { + return objectEntry(section("rocks"), id); + } + + JsonObject ore(String id) { + return objectEntry(section("ores"), id); + } + + List geomeIds() { + List ids = new ArrayList<>(section("geomes").keySet()); + Collections.sort(ids); + return ids; + } + + List configuredBiomeIds() { + TreeSet ids = new TreeSet<>(section("biomes").keySet()); + for (net.minecraft.world.level.biome.Biome biome : ForgeRegistries.BIOMES.getValues()) { + ResourceLocation id = ForgeRegistries.BIOMES.getKey(biome); + if (id != null) { + ids.add(id.toString()); + } + } + return new ArrayList<>(ids); + } + + List dictionaryIds() { + List ids = new ArrayList<>(section("biome_dictionary").keySet()); + Collections.sort(ids); + return ids; + } + + JsonObject weightMap(String section, String id) { + JsonObject parent = section(section); + return objectEntry(parent, id); + } + + void addGeome(String id) { + String normalized = id.trim().toLowerCase(Locale.ROOT); + if (!normalized.matches("[a-z0-9_.-]+") || section("geomes").has(normalized)) { + return; + } + JsonObject geome = new JsonObject(); + geome.addProperty("base", 1.0D); + JsonObject families = new JsonObject(); + for (RockFamily family : RockFamily.values()) { + families.addProperty(family.configName, 1.0D); + } + geome.add("families", families); + section("geomes").add(normalized, geome); + } + + void removeGeome(String id) { + if (BUILT_IN_GEOMES.contains(id)) { + return; + } + section("geomes").remove(id); + removeWeightKey(section("biomes"), id); + removeWeightKey(section("biome_dictionary"), id); + for (Entry rock : section("rocks").entrySet()) { + if (rock.getValue().isJsonObject() && rock.getValue().getAsJsonObject().has("geomes")) { + rock.getValue().getAsJsonObject().getAsJsonObject("geomes").remove(id); + } + } + for (Entry ore : section("ores").entrySet()) { + if (!ore.getValue().isJsonObject()) continue; + JsonObject oreObject = ore.getValue().getAsJsonObject(); + if (!oreObject.has("dimensions") || !oreObject.get("dimensions").isJsonObject()) continue; + for (Entry dimension : oreObject.getAsJsonObject("dimensions").entrySet()) { + if (dimension.getValue().isJsonObject() && dimension.getValue().getAsJsonObject().has("geomes")) { + dimension.getValue().getAsJsonObject().getAsJsonObject("geomes").remove(id); + } + } + } + } + + List validate() { + List errors = new ArrayList<>(); + JsonObject geomes = section("geomes"); + if (geomes.entrySet().isEmpty()) { + errors.add("At least one geome is required."); + } + for (Entry entry : geomes.entrySet()) { + if (!entry.getKey().matches("[a-z0-9_.-]+") || !entry.getValue().isJsonObject()) { + errors.add("Invalid geome: " + entry.getKey()); + continue; + } + JsonObject definition = entry.getValue().getAsJsonObject(); + JsonObject families = definition.has("families") && definition.get("families").isJsonObject() + ? definition.getAsJsonObject("families") : new JsonObject(); + double total = 0.0D; + for (RockFamily family : RockFamily.values()) { + double value = decimal(families, family.configName, 0.0D); + if (value < 0.0D || !Double.isFinite(value)) errors.add("Invalid family weight in " + entry.getKey()); + total += Math.max(0.0D, value); + } + if (total <= 0.0D) errors.add("Geome has no available rock families: " + entry.getKey()); + } + int sedimentary = 0; + int metamorphic = 0; + int igneous = 0; + for (Entry entry : section("rocks").entrySet()) { + if (!entry.getValue().isJsonObject()) { + errors.add("Invalid rock block: " + entry.getKey()); + continue; + } + JsonObject rock = entry.getValue().getAsJsonObject(); + if (!validBlock(string(rock, "block", entry.getKey()))) { + errors.add("Invalid rock block: " + string(rock, "block", entry.getKey())); + continue; + } + if (!bool(rock, "enabled", true) || decimal(rock, "weight", 1.0D) <= 0.0D) { + continue; + } + String family = string(rock, "family", ""); + try { + RockFamily.fromConfigName(family); + } catch (RuntimeException e) { + errors.add("Invalid family for " + entry.getKey()); + continue; + } + if (integer(rock, "min_y", -64) > integer(rock, "max_y", 319)) { + errors.add("Minimum Y is above maximum Y for " + entry.getKey()); + } + if (rock.has("dimensions") && !validIdArray(rock.get("dimensions"))) { + errors.add("Invalid or empty terrain dimension list for " + entry.getKey()); + } + validateGeomeWeights(errors, entry.getKey(), rock.get("geomes"), geomes); + if ("sedimentary".equals(family)) sedimentary++; + else if ("metamorphic".equals(family)) metamorphic++; + else igneous++; + } + if (sedimentary == 0) errors.add("At least one enabled sedimentary rock is required."); + if (metamorphic == 0) errors.add("At least one enabled metamorphic rock is required."); + if (igneous == 0) errors.add("At least one enabled igneous rock is required."); + + for (Entry entry : section("ores").entrySet()) { + if (!entry.getValue().isJsonObject()) { + errors.add("Invalid ore block: " + entry.getKey()); + continue; + } + JsonObject ore = entry.getValue().getAsJsonObject(); + if (!validBlock(string(ore, "block", entry.getKey()))) { + errors.add("Invalid ore block: " + string(ore, "block", entry.getKey())); + continue; + } + if (!bool(ore, "enabled", true)) { + continue; + } + if (ore.has("deep_output") && !validBlock(string(ore, "deep_output", ""))) { + errors.add("Invalid deep ore block: " + string(ore, "deep_output", "")); + } + if (!ore.has("dimensions") || !ore.get("dimensions").isJsonObject() + || ore.getAsJsonObject("dimensions").entrySet().isEmpty()) { + errors.add("Ore has no dimension rules: " + entry.getKey()); + continue; + } + for (Entry dimension : ore.getAsJsonObject("dimensions").entrySet()) { + if (!validResource(dimension.getKey()) || !dimension.getValue().isJsonObject()) { + errors.add("Invalid dimension for " + entry.getKey()); + continue; + } + JsonObject rule = dimension.getValue().getAsJsonObject(); + if (integer(rule, "min_y", -64) > integer(rule, "max_y", 320) + || decimal(rule, "frequency", 0.0D) < 0.0D + || decimal(rule, "frequency", 0.0D) > 64.0D + || integer(rule, "quantity", 0) < 1 || integer(rule, "quantity", 0) > 64 + || integer(rule, "spread", 8) < 0 || integer(rule, "spread", 8) > 64 + || integer(rule, "vertical_spread", 4) < 0 + || integer(rule, "vertical_spread", 4) > 64 + || integer(rule, "node_size", 4) < 1 || integer(rule, "node_size", 4) > 32) { + errors.add("Invalid placement values for " + entry.getKey() + " in " + dimension.getKey()); + } + try { + OreSpawnPatterns.decode(rule); + OreHeightDistribution.fromConfigName(string(rule, "height_distribution", "uniform")); + } catch (RuntimeException e) { + errors.add("Invalid ore pattern for " + entry.getKey() + " in " + dimension.getKey()); + } + if (bool(rule, "enabled", true)) { + boolean hosts = validBlockArray(rule.get("host_blocks"), errors, entry.getKey()) + || validIdArray(rule.get("host_tags")); + if (rule.has("host_families") && rule.get("host_families").isJsonArray()) { + for (JsonElement family : rule.getAsJsonArray("host_families")) { + try { RockFamily.fromConfigName(family.getAsString()); hosts = true; } + catch (RuntimeException e) { errors.add("Invalid host family for " + entry.getKey()); } + } + } + if (!hosts) errors.add("Enabled ore has no hosts: " + entry.getKey()); + } + validateGeomeWeights(errors, entry.getKey(), rule.get("geomes"), geomes); + } + } + validateRuleGeomes(errors, section("biomes"), geomes, "biome"); + validateRuleGeomes(errors, section("biome_dictionary"), geomes, "biome type"); + for (Entry entry : section("terrain_dimensions").entrySet()) { + if (!validResource(entry.getKey()) || !entry.getValue().isJsonObject()) { + errors.add("Invalid terrain dimension: " + entry.getKey()); + continue; + } + JsonObject dimension = entry.getValue().getAsJsonObject(); + if (!bool(dimension, "enabled", true)) continue; + boolean hosts = validBlockArray(dimension.get("host_blocks"), errors, entry.getKey()) + || validIdArray(dimension.get("host_tags")); + if (!hosts) errors.add("Enabled terrain dimension has no valid hosts: " + entry.getKey()); + if (dimension.has("biome_ids")) { + JsonElement biomeIds = dimension.get("biome_ids"); + if (!biomeIds.isJsonArray() + || (biomeIds.getAsJsonArray().size() > 0 && !validIdArray(biomeIds))) { + errors.add("Invalid biome IDs for terrain dimension " + entry.getKey()); + } + } + } + return errors; + } + + private static void validateRuleGeomes(List errors, JsonObject rules, JsonObject geomes, String label) { + for (Entry entry : rules.entrySet()) { + validateGeomeWeights(errors, label + " " + entry.getKey(), entry.getValue(), geomes); + } + } + + private static void validateGeomeWeights(List errors, String owner, JsonElement element, + JsonObject geomes) { + if (element == null) return; + if (!element.isJsonObject()) { + errors.add("Invalid geome weights for " + owner); + return; + } + for (Entry weight : element.getAsJsonObject().entrySet()) { + if (!geomes.has(weight.getKey())) { + errors.add("Unknown geome '" + weight.getKey() + "' in " + owner); + continue; + } + try { + double value = weight.getValue().getAsDouble(); + if (!Double.isFinite(value) || value < 0.0D) throw new NumberFormatException(); + } catch (RuntimeException e) { + errors.add("Invalid geome weight in " + owner); + } + } + } + + private static boolean validIdArray(JsonElement element) { + if (element == null || !element.isJsonArray() || element.getAsJsonArray().size() == 0) return false; + boolean found = false; + for (JsonElement value : element.getAsJsonArray()) { + String id; + try { + id = value.isJsonObject() ? string(value.getAsJsonObject(), "tag", "") : value.getAsString(); + } catch (RuntimeException e) { + return false; + } + if (!validResource(id)) return false; + found = true; + } + return found; + } + + private static boolean validBlockArray(JsonElement element, List errors, String oreId) { + if (element == null || !element.isJsonArray() || element.getAsJsonArray().size() == 0) return false; + boolean found = false; + for (JsonElement value : element.getAsJsonArray()) { + String id; + try { + id = value.isJsonObject() ? string(value.getAsJsonObject(), "block", "") : value.getAsString(); + } catch (RuntimeException e) { + errors.add("Invalid host block for " + oreId); + continue; + } + if (!validBlock(id)) { + errors.add("Unknown host block '" + id + "' for " + oreId); + continue; + } + found = true; + } + return found; + } + + static JsonObject defaultOreDimension() { + JsonObject dimension = new JsonObject(); + dimension.addProperty("enabled", true); + dimension.addProperty("min_y", -64); + dimension.addProperty("max_y", 64); + dimension.addProperty("frequency", 1.0D); + dimension.addProperty("quantity", 8); + dimension.addProperty("pattern", "vein"); + dimension.addProperty("height_distribution", "uniform"); + dimension.addProperty("spread", 8); + dimension.addProperty("vertical_spread", 4); + dimension.addProperty("node_size", 4); + JsonArray families = new JsonArray(); + for (RockFamily family : RockFamily.values()) { + families.add(family.configName); + } + dimension.add("host_families", families); + JsonArray tags = new JsonArray(); + tags.add("minecraft:stone_ore_replaceables"); + tags.add("minecraft:deepslate_ore_replaceables"); + dimension.add("host_tags", tags); + return dimension; + } + + private static boolean isSelectable(Block block, boolean showAll) { + if (block == Blocks.AIR || block.asItem() == Items.AIR || block instanceof LiquidBlock) { + return false; + } + if (showAll) { + return true; + } + return !(block instanceof EntityBlock) + && block.defaultBlockState().getMaterial().blocksMotion() + && Block.isShapeFullBlock(block.defaultBlockState().getCollisionShape( + EmptyBlockGetter.INSTANCE, BlockPos.ZERO)); + } + + String canonicalBlockId(String id) { + try { + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(id)); + ResourceLocation canonical = block == null ? null : ForgeRegistries.BLOCKS.getKey(block); + return block == Blocks.AIR || canonical == null ? null : canonical.toString(); + } catch (RuntimeException e) { + return null; + } + } + + private void normalizeRegistrySections(JsonObject profileRoot) { + normalizeRegistrySection(profileRoot, "rocks", true); + normalizeRegistrySection(profileRoot, "ores", false); + } + + private void normalizeRegistrySection(JsonObject profileRoot, String sectionName, boolean applyAliases) { + JsonObject source = object(profileRoot, sectionName); + Map normalized = new LinkedHashMap<>(); + JsonObject aliases = profileRoot.has("worldgen_aliases") + && profileRoot.get("worldgen_aliases").isJsonObject() + ? profileRoot.getAsJsonObject("worldgen_aliases") : new JsonObject(); + for (Entry entry : source.entrySet()) { + String id = canonicalBlockId(entry.getKey()); + if (id == null) id = entry.getKey(); + if (applyAliases && aliases.has(id)) { + try { + String target = canonicalBlockId(aliases.get(id).getAsString()); + if (target != null) id = target; + } catch (RuntimeException ignored) { } + } + normalized.putIfAbsent(id, entry.getValue().deepCopy()); + } + JsonObject replacement = new JsonObject(); + for (Entry entry : normalized.entrySet()) { + replacement.add(entry.getKey(), entry.getValue()); + } + profileRoot.add(sectionName, replacement); + } + + private boolean isWorldgenAliasSource(String id) { + JsonObject aliases = section("worldgen_aliases"); + if (!aliases.has(id)) return false; + try { + return !id.equals(new ResourceLocation(aliases.get(id).getAsString()).toString()); + } catch (RuntimeException e) { + return false; + } + } + + private static int defaultPeak(RockFamily family) { + switch (family) { + case SEDIMENTARY: return 60; + case METAMORPHIC: return 28; + case IGNEOUS_INTRUSIVE: return 24; + case IGNEOUS_VOLCANIC: return 72; + default: return 48; + } + } + + private static void removeWeightKey(JsonObject rules, String geome) { + for (Entry rule : rules.entrySet()) { + if (rule.getValue().isJsonObject()) { + rule.getValue().getAsJsonObject().remove(geome); + } + } + } + + private static JsonObject object(JsonObject parent, String key) { + if (!parent.has(key) || !parent.get(key).isJsonObject()) { + JsonObject result = new JsonObject(); + parent.add(key, result); + return result; + } + return parent.getAsJsonObject(key); + } + + private static JsonObject objectEntry(JsonObject parent, String key) { + if (!parent.has(key) || !parent.get(key).isJsonObject()) { + JsonObject result = new JsonObject(); + parent.add(key, result); + return result; + } + return parent.getAsJsonObject(key); + } + + private static boolean validBlock(String id) { + if (!validResource(id)) return false; + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(id)); + return block != null && block != Blocks.AIR; + } + + private static boolean validResource(String id) { + try { + new ResourceLocation(id); + return true; + } catch (RuntimeException e) { + return false; + } + } + + static String string(JsonObject json, String key, String fallback) { + try { return json.has(key) ? json.get(key).getAsString() : fallback; } + catch (RuntimeException e) { return fallback; } + } + + static boolean bool(JsonObject json, String key, boolean fallback) { + try { return json.has(key) ? json.get(key).getAsBoolean() : fallback; } + catch (RuntimeException e) { return fallback; } + } + + static int integer(JsonObject json, String key, int fallback) { + try { return json.has(key) ? json.get(key).getAsInt() : fallback; } + catch (RuntimeException e) { return fallback; } + } + + static double decimal(JsonObject json, String key, double fallback) { + try { return json.has(key) ? json.get(key).getAsDouble() : fallback; } + catch (RuntimeException e) { return fallback; } + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/GeologyMaterialsScreen.java b/src/main/java/com/mcmoddev/orespawn/client/GeologyMaterialsScreen.java new file mode 100644 index 00000000..f94bc0de --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/GeologyMaterialsScreen.java @@ -0,0 +1,161 @@ +package com.mcmoddev.orespawn.client; + +import java.util.List; + +import com.mcmoddev.orespawn.client.GeologyEditorSession.MaterialTab; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; + +final class GeologyMaterialsScreen extends Screen { + private final Screen parent; + private final GeologyEditorSession session; + private MaterialTab tab = MaterialTab.SEDIMENTARY; + private EditBox search; + private boolean showAll; + private int page; + private String searchText = ""; + + GeologyMaterialsScreen(Screen parent, GeologyEditorSession session) { + super(new TranslatableComponent("screen.orespawn.materials")); + this.parent = parent; + this.session = session; + } + + @Override + protected void init() { + int contentWidth = Math.min(390, Math.max(240, width - 24)); + int contentLeft = (width - contentWidth) / 2; + int tabGap = 4; + int tabsPerRow = width < 390 ? 3 : MaterialTab.values().length; + int tabWidth = (contentWidth - (tabGap * (tabsPerRow - 1))) / tabsPerRow; + for (int i = 0; i < MaterialTab.values().length; i++) { + MaterialTab value = MaterialTab.values()[i]; + int tabRow = i / tabsPerRow; + int tabsInRow = Math.min(tabsPerRow, MaterialTab.values().length - (tabRow * tabsPerRow)); + int rowWidth = (tabsInRow * tabWidth) + ((tabsInRow - 1) * tabGap); + int tabX = (width - rowWidth) / 2 + ((i % tabsPerRow) * (tabWidth + tabGap)); + Button button = addRenderableWidget(new Button(tabX, 26 + (tabRow * 24), tabWidth, 20, + new TranslatableComponent("tab.orespawn." + value.key), selected -> changeTab(value))); + button.active = value != tab; + } + + int tabRows = (MaterialTab.values().length + tabsPerRow - 1) / tabsPerRow; + int searchY = 28 + (tabRows * 24); + int searchButtonWidth = 60; + int advancedWidth = tab == MaterialTab.UNASSIGNED ? 85 : 0; + int searchWidth = contentWidth - searchButtonWidth - advancedWidth - (advancedWidth > 0 ? 10 : 5); + search = addRenderableWidget(new EditBox(font, contentLeft, searchY, searchWidth, 20, + new TranslatableComponent("option.orespawn.search"))); + search.setValue(searchText); + int searchButtonX = contentLeft + searchWidth + 5; + addRenderableWidget(new Button(searchButtonX, searchY, searchButtonWidth, 20, + new TranslatableComponent("button.orespawn.search"), button -> { + searchText = search.getValue(); page = 0; rebuildWidgets(); + })); + Button advanced = addRenderableWidget(new Button(searchButtonX + searchButtonWidth + 5, searchY, 85, 20, + new TranslatableComponent(showAll ? "button.orespawn.safe_only" : "button.orespawn.show_all"), + button -> { showAll = !showAll; page = 0; rebuildWidgets(); })); + advanced.visible = tab == MaterialTab.UNASSIGNED; + + List ids = currentIds(); + int listTop = searchY + 28; + int controlsY = height - 52; + int pageSize = Math.max(1, (controlsY - listTop) / 24); + int pageCount = Math.max(1, (ids.size() + pageSize - 1) / pageSize); + page = Math.max(0, Math.min(page, pageCount - 1)); + int start = page * pageSize; + int removeWidth = 78; + int rowGap = 4; + for (int i = 0; i < pageSize && start + i < ids.size(); i++) { + String id = ids.get(start + i); + int y = listTop + (i * 24); + int entryWidth = tab == MaterialTab.UNASSIGNED + ? contentWidth : contentWidth - removeWidth - rowGap; + addRenderableWidget(new Button(contentLeft, y, entryWidth, 20, + new TextComponent(rowLabel(id)), button -> openEntry(id))); + if (tab != MaterialTab.UNASSIGNED) { + addRenderableWidget(new Button(contentLeft + entryWidth + rowGap, y, removeWidth, 20, + new TranslatableComponent("button.orespawn.remove"), button -> removeEntry(id))); + } + } + + Button previous = addRenderableWidget(new Button(contentLeft, controlsY, 45, 20, + new TextComponent("<"), button -> { page--; rebuildWidgets(); })); + Button next = addRenderableWidget(new Button(contentLeft + 50, controlsY, 45, 20, + new TextComponent(">"), button -> { page++; rebuildWidgets(); })); + previous.active = page > 0; + next.active = page + 1 < pageCount; + + int addWidth = Math.min(150, contentWidth - 105); + Button add = addRenderableWidget(new Button(contentLeft + contentWidth - addWidth, controlsY, addWidth, 20, + new TranslatableComponent("button.orespawn.add_block"), button -> openBlockPicker())); + add.visible = tab != MaterialTab.UNASSIGNED; + int doneWidth = Math.min(150, contentWidth); + addRenderableWidget(new Button((width - doneWidth) / 2, height - 28, doneWidth, 20, + CommonComponents.GUI_DONE, button -> onClose())); + } + + private void changeTab(MaterialTab value) { + tab = value; + page = 0; + rebuildWidgets(); + } + + private void rebuildWidgets() { + clearWidgets(); + init(); + } + + private List currentIds() { + return session.materialIds(tab, searchText, showAll); + } + + private String rowLabel(String id) { + String block = session.materialBlockId(tab, id); + String label = block.equals(id) ? id : block + " {" + id + "}"; + if (tab == MaterialTab.ORES) { + String source = GeologyEditorSession.string(session.ore(id), "source_provider", + GeologyEditorSession.string(session.ore(id), "source_mod", "")); + return source.isEmpty() ? label : label + " [" + source + "]"; + } + return label; + } + + private void openEntry(String id) { + if (tab == MaterialTab.ORES) { + minecraft.setScreen(new OreEntryScreen(this, session, id)); + } else if (tab == MaterialTab.UNASSIGNED) { + minecraft.setScreen(new BlockAssignmentScreen(this, session, id)); + } else { + minecraft.setScreen(new RockEntryScreen(this, session, id)); + } + } + + private void openBlockPicker() { + minecraft.setScreen(new BlockPickerScreen(this, session, tab)); + } + + private void removeEntry(String id) { + if (tab == MaterialTab.ORES) session.disableOrRemoveOre(id); + else session.removeRock(id); + rebuildWidgets(); + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 10, 0xFFFFFF); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/GeomeBiomeScreen.java b/src/main/java/com/mcmoddev/orespawn/client/GeomeBiomeScreen.java new file mode 100644 index 00000000..319021ff --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/GeomeBiomeScreen.java @@ -0,0 +1,138 @@ +package com.mcmoddev.orespawn.client; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import com.google.gson.JsonObject; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; + +final class GeomeBiomeScreen extends Screen { + private enum Tab { GEOMES, BIOMES, DICTIONARY } + private final Screen parent; + private final GeologyEditorSession session; + private Tab tab = Tab.GEOMES; + private int page; + private String searchText = ""; + private EditBox search; + private EditBox newId; + + GeomeBiomeScreen(Screen parent, GeologyEditorSession session) { + super(new TranslatableComponent("screen.orespawn.geomes")); + this.parent = parent; + this.session = session; + } + + @Override + protected void init() { + int left = width / 2 - 155; + for (int i = 0; i < Tab.values().length; i++) { + Tab value = Tab.values()[i]; + Button button = addRenderableWidget(new Button(left + (i * 105), 26, 100, 20, + new TranslatableComponent("tab.orespawn." + value.name().toLowerCase(Locale.ROOT)), + selected -> { tab = value; page = 0; rebuildWidgets(); })); + button.active = value != tab; + } + search = addRenderableWidget(new EditBox(font, left, 52, 230, 20, + new TranslatableComponent("option.orespawn.search"))); + search.setValue(searchText); + addRenderableWidget(new Button(left + 235, 52, 75, 20, + new TranslatableComponent("button.orespawn.search"), button -> { + searchText = search.getValue(); page = 0; rebuildWidgets(); + })); + + List ids = ids(); + int listTop = 80; + int controlsY = height - 52; + int pageSize = Math.max(1, (controlsY - listTop) / 24); + int pageCount = Math.max(1, (ids.size() + pageSize - 1) / pageSize); + page = Math.max(0, Math.min(page, pageCount - 1)); + int start = page * pageSize; + for (int i = 0; i < pageSize && start + i < ids.size(); i++) { + String id = ids.get(start + i); + addRenderableWidget(new Button(left, listTop + (i * 24), 310, 20, + new TextComponent(label(id)), button -> open(id))); + } + Button previous = addRenderableWidget(new Button(left, controlsY, 45, 20, + new TextComponent("<"), button -> { page--; rebuildWidgets(); })); + Button next = addRenderableWidget(new Button(left + 50, controlsY, 45, 20, + new TextComponent(">"), button -> { page++; rebuildWidgets(); })); + previous.active = page > 0; + next.active = page + 1 < pageCount; + newId = addRenderableWidget(new EditBox(font, left + 100, controlsY, 150, 20, + new TranslatableComponent("option.orespawn.registry_id"))); + newId.setMaxLength(128); + addRenderableWidget(new Button(left + 255, controlsY, 55, 20, + new TranslatableComponent("button.orespawn.add"), button -> add())); + addRenderableWidget(new Button(width / 2 - 75, height - 28, 150, 20, + CommonComponents.GUI_DONE, button -> onClose())); + } + + private List ids() { + List source; + if (tab == Tab.GEOMES) source = session.geomeIds(); + else if (tab == Tab.BIOMES) source = session.configuredBiomeIds(); + else source = session.dictionaryIds(); + if (searchText.isEmpty()) return source; + List filtered = new ArrayList<>(); + String query = searchText.toLowerCase(Locale.ROOT); + for (String id : source) if (id.toLowerCase(Locale.ROOT).contains(query)) filtered.add(id); + return filtered; + } + + private void rebuildWidgets() { + clearWidgets(); + init(); + } + + private String label(String id) { + if (tab == Tab.BIOMES && !session.section("biomes").has(id)) return id + " [installed]"; + return id; + } + + private void open(String id) { + if (tab == Tab.GEOMES) { + minecraft.setScreen(new GeomeEntryScreen(this, session, id)); + return; + } + String section = tab == Tab.BIOMES ? "biomes" : "biome_dictionary"; + JsonObject weights = session.weightMap(section, id); + minecraft.setScreen(new WeightMapScreen(this, new TextComponent(id), weights, + session.geomeIds(), 0.0D, () -> session.section(section).remove(id))); + } + + private void add() { + String id = newId.getValue().trim(); + if (id.isEmpty()) return; + if (tab == Tab.GEOMES) { + session.addGeome(id); + minecraft.setScreen(new GeomeEntryScreen(this, session, id.toLowerCase(Locale.ROOT))); + } else { + if (tab == Tab.BIOMES) { + try { new ResourceLocation(id); } + catch (RuntimeException e) { return; } + } + open(id); + } + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 10, 0xFFFFFF); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/GeomeEntryScreen.java b/src/main/java/com/mcmoddev/orespawn/client/GeomeEntryScreen.java new file mode 100644 index 00000000..24f490cd --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/GeomeEntryScreen.java @@ -0,0 +1,137 @@ +package com.mcmoddev.orespawn.client; + +import java.util.EnumMap; +import java.util.Map; + +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; + +final class GeomeEntryScreen extends Screen { + private final Screen parent; + private final GeologyEditorSession session; + private final String geomeId; + private final Map familyWeights = new EnumMap<>(RockFamily.class); + private EditBox baseWeight; + private Component error; + + GeomeEntryScreen(Screen parent, GeologyEditorSession session, String geomeId) { + super(new TranslatableComponent("screen.orespawn.geome_entry")); + this.parent = parent; + this.session = session; + this.geomeId = geomeId; + } + + @Override + protected void init() { + familyWeights.clear(); + JsonObject geome = session.weightMap("geomes", geomeId); + JsonObject families = object(geome, "families"); + int left = width / 2 - 155; + int right = width / 2 + 5; + baseWeight = addField(right, 52, "base", text(geome, "base", 1.0D)); + int index = 0; + for (RockFamily family : RockFamily.values()) { + EditBox field = addField(right, 82 + (index * 25), family.configName, + text(families, family.configName, 1.0D)); + familyWeights.put(family, field); + index++; + } + addRenderableWidget(new Button(left, 190, 150, 20, + new TranslatableComponent("button.orespawn.reset"), button -> reset())); + Button remove = addRenderableWidget(new Button(right, 190, 150, 20, + new TranslatableComponent("button.orespawn.remove"), button -> remove())); + remove.active = !GeologyEditorSession.BUILT_IN_GEOMES.contains(geomeId); + int bottom = height - 28; + addRenderableWidget(new Button(left, bottom, 150, 20, CommonComponents.GUI_DONE, + button -> saveAndClose())); + addRenderableWidget(new Button(right, bottom, 150, 20, CommonComponents.GUI_CANCEL, + button -> onClose())); + } + + private EditBox addField(int x, int y, String key, String value) { + EditBox field = new EditBox(font, x, y, 150, 20, new TextComponent(key)); + field.setMaxLength(32); + field.setValue(value); + return addRenderableWidget(field); + } + + private void saveAndClose() { + try { + JsonObject geome = session.weightMap("geomes", geomeId); + geome.addProperty("base", weight(baseWeight)); + JsonObject families = object(geome, "families"); + for (RockFamily family : RockFamily.values()) { + families.addProperty(family.configName, weight(familyWeights.get(family))); + } + error = null; + minecraft.setScreen(parent); + } catch (NumberFormatException e) { + error = new TextComponent("Weights must be between 0 and 1000."); + } + } + + private double weight(EditBox field) { + double value = Double.parseDouble(field.getValue().trim()); + if (!Double.isFinite(value) || value < 0.0D || value > 1000.0D) throw new NumberFormatException(); + return value; + } + + private void reset() { + session.resetEntry("geomes", geomeId); + rebuildWidgets(); + } + + private void rebuildWidgets() { + clearWidgets(); + init(); + } + + private void remove() { + session.removeGeome(geomeId); + minecraft.setScreen(parent); + } + + private static JsonObject object(JsonObject parent, String key) { + if (!parent.has(key) || !parent.get(key).isJsonObject()) { + JsonObject result = new JsonObject(); + parent.add(key, result); + return result; + } + return parent.getAsJsonObject(key); + } + + private static String text(JsonObject json, String key, Number fallback) { + return json.has(key) ? json.get(key).getAsString() : fallback.toString(); + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 12, 0xFFFFFF); + drawCenteredString(poseStack, font, new TextComponent(geomeId), width / 2, 30, 0xDDDDDD); + drawString(poseStack, font, new TranslatableComponent("option.orespawn.base_weight"), + width / 2 - 155, 58, 0xDDDDDD); + int index = 0; + for (RockFamily family : RockFamily.values()) { + drawString(poseStack, font, new TranslatableComponent("value.orespawn.family." + family.configName), + width / 2 - 155, 88 + (index * 25), 0xDDDDDD); + index++; + } + if (error != null) drawCenteredString(poseStack, font, error, width / 2, height - 42, 0xFF5555); + super.render(poseStack, mouseX, mouseY, partialTick); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/NumericConfigScreen.java b/src/main/java/com/mcmoddev/orespawn/client/NumericConfigScreen.java new file mode 100644 index 00000000..03cc1ca2 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/NumericConfigScreen.java @@ -0,0 +1,180 @@ +package com.mcmoddev.orespawn.client; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; + +final class NumericConfigScreen extends Screen { + static final Field[] FORMATION_FIELDS = { + new Field("stratum_wavelength", 16, 8192, false), + new Field("family_region_wavelength", 16, 8192, false), + new Field("vertical_thickness", 1, 192, true), + new Field("waviness_wavelength", 32, 2048, false), + new Field("waviness_amplitude", 0, 512, false), + new Field("edge_wavelength", 8, 512, false), + new Field("edge_amplitude", 0, 256, false), + new Field("edge_octaves", 1, 8, true), + new Field("continuity", 0, 1, false) + }; + static final Field[] OIL_FIELDS = { + new Field("min_y", -64, 320, true), new Field("max_y", -64, 320, true), + new Field("frequency", 0, 16, false), new Field("min_radius", 1, 24, true), + new Field("max_radius", 1, 32, true), new Field("min_vertical_radius", 1, 16, true), + new Field("max_vertical_radius", 1, 24, true), new Field("max_lobes", 1, 8, true), + new Field("min_solid_cover", 1, 16, true) + }; + static final Field[] CYANO_FIELDS = { + new Field("geome_size", 4, Short.MAX_VALUE, true), + new Field("rock_layer_noise", 1, Short.MAX_VALUE, false), + new Field("rock_layer_thickness", 1, 255, true) + }; + + private static final int PAGE_SIZE = 6; + private final Screen parent; + private final GeologyEditorSession session; + private final String path; + private final Field[] fields; + private final List editors = new ArrayList<>(); + private int page; + private Component error; + + NumericConfigScreen(Screen parent, GeologyEditorSession session, String path, Field[] fields) { + super(new TranslatableComponent("screen.orespawn.numeric_settings")); + this.parent = parent; + this.session = session; + this.path = path; + this.fields = fields; + } + + @Override + protected void init() { + editors.clear(); + JsonObject section = resolveSection(); + int start = page * PAGE_SIZE; + int end = Math.min(fields.length, start + PAGE_SIZE); + int left = width / 2 + 5; + for (int i = start; i < end; i++) { + Field field = fields[i]; + EditBox editor = new EditBox(font, left, 44 + ((i - start) * 25), 145, 20, + new TextComponent(field.key)); + editor.setMaxLength(32); + JsonElement value = section.get(field.key); + editor.setValue(value == null ? "0" : value.getAsString()); + editors.add(addRenderableWidget(editor)); + } + + int bottom = height - 28; + addRenderableWidget(new Button(width / 2 - 155, bottom, 100, 20, CommonComponents.GUI_DONE, + button -> saveAndClose())); + addRenderableWidget(new Button(width / 2 + 55, bottom, 100, 20, CommonComponents.GUI_CANCEL, + button -> onClose())); + Button previous = addRenderableWidget(new Button(width / 2 - 50, bottom, 45, 20, + new TextComponent("<"), button -> changePage(-1))); + Button next = addRenderableWidget(new Button(width / 2 + 5, bottom, 45, 20, + new TextComponent(">"), button -> changePage(1))); + previous.active = page > 0; + next.active = (page + 1) * PAGE_SIZE < fields.length; + } + + private void changePage(int offset) { + if (savePage()) { + page += offset; + rebuildWidgets(); + } + } + + private void rebuildWidgets() { + clearWidgets(); + init(); + } + + private void saveAndClose() { + if (savePage()) { + minecraft.setScreen(parent); + } + } + + private boolean savePage() { + JsonObject section = resolveSection(); + int start = page * PAGE_SIZE; + for (int i = 0; i < editors.size(); i++) { + Field field = fields[start + i]; + try { + double value = Double.parseDouble(editors.get(i).getValue().trim()); + if (value < field.min || value > field.max || (field.integer && value != Math.rint(value))) { + throw new NumberFormatException(); + } + if (field.integer) section.addProperty(field.key, (int) value); + else section.addProperty(field.key, value); + } catch (NumberFormatException e) { + error = new TextComponent("Invalid value for " + field.key); + return false; + } + } + error = null; + return true; + } + + private JsonObject resolveSection() { + JsonObject current = session.root(); + for (String segment : path.split("\\.")) { + if (!current.has(segment) || !current.get(segment).isJsonObject()) { + JsonObject child = new JsonObject(); + current.add(segment, child); + current = child; + } else { + current = current.getAsJsonObject(segment); + } + } + return current; + } + + @Override + public void onClose() { + minecraft.setScreen(parent); + } + + @Override + public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTick) { + renderBackground(poseStack); + drawCenteredString(poseStack, font, title, width / 2, 16, 0xFFFFFF); + int start = page * PAGE_SIZE; + for (int i = 0; i < editors.size(); i++) { + drawString(poseStack, font, label(fields[start + i].key), width / 2 - 155, + 50 + (i * 25), 0xDDDDDD); + } + if (error != null) { + drawCenteredString(poseStack, font, error, width / 2, height - 42, 0xFF5555); + } + super.render(poseStack, mouseX, mouseY, partialTick); + } + + private Component label(String key) { + return new TranslatableComponent("option.orespawn." + key); + } + + static final class Field { + final String key; + final double min; + final double max; + final boolean integer; + + Field(String key, double min, double max, boolean integer) { + this.key = key; + this.min = min; + this.max = max; + this.integer = integer; + } + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/client/OreDimensionScreen.java b/src/main/java/com/mcmoddev/orespawn/client/OreDimensionScreen.java new file mode 100644 index 00000000..ea67e16b --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/client/OreDimensionScreen.java @@ -0,0 +1,414 @@ +package com.mcmoddev.orespawn.client; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.EnumSet; +import java.util.List; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.worldgen.OreHeightDistribution; +import com.mcmoddev.orespawn.worldgen.OrePattern; +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.CycleButton; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.FormattedCharSequence; + +final class OreDimensionScreen extends Screen { + private enum Page { PLACEMENT, PATTERN, HOSTS } + + private final Screen parent; + private final GeologyEditorSession session; + private final String oreId; + private final String dimensionId; + private final double baselineFrequency; + private final EnumSet families = EnumSet.noneOf(RockFamily.class); + private boolean enabled; + private EditBox minY; + private EditBox maxY; + private EditBox frequency; + private EditBox quantity; + private CycleButton richness; + private EditBox spread; + private EditBox verticalSpread; + private EditBox nodeSize; + private EditBox hostBlocks; + private EditBox hostTags; + private OrePattern pattern; + private boolean externalPattern; + private String externalPatternId = ""; + private String originalHostBlocksText = ""; + private String originalHostTagsText = ""; + private OreHeightDistribution heightDistribution; + private Component error; + private Page page = Page.PLACEMENT; + private final List

L(tZ$0BqX1>24?V$S+&kLZ`AodQ4_)P#Q3*4xg8}lMV-FLwC*cN$< zt65Rf%7z41u^i=P*qO8>JqXPrinQFapR7qHAtp~&RZ85$>ob|Js;GS^y;S{XnGiBc zGa4IGvDl?x%gY`vNhv8wgZnP#UYI-w*^4YCZnxkF85@ldepk$&$#3EAhrJY0U)lR{F6sM3SONV^+$;Zx8BD&Eku3K z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jZUOxOX zU&-^smw$iwKPe;r`&{rP{L35^&+wk6f2-Sn;D2Ww@sjAJj{Gwbp4H!o{#5_}qALFq z{-q%LGklZvKf%A4D!+t%sRRBDi(>mvuz&V4yu^GdD*KFy?fg%ef5ZU%w=d&M`POGt zNSEJ0{qJI~FRTAjlJc1-+x>Tm{%D?m3sk-&cq#w)OpxI98wCF#2KbWcrAXK_(}M4B zF#VQf*h|irx=+uXZUMi+`A;fPFR5M%Wjs^Wh5rWCKgedhWO^w|@XS;b^&3oom;>K0 zB??|ry^IBarYem6Z7RU`#rDs-ZZAn*hSollv?csD$sh0QpTtI9vb>Dpd}e7*`fZj! zM|8d{~YM@vfW-r0z8vJ z<^6B6Ur(}L?ms_c9@hO0^Iy&J_uc51^?d33e#Y!-``?)VG)BGjCq5$&0G8A*r!2qk zUHscGc;VxE=1KqbH=dW%&Ogl({>L!>((m$2W8M9KQ@a1=h51jN|KoG{v(x0K&*iy% e1c3cF4~(n?C}6GmGu)3JNC)6=LGAhZ*Z%`+-T+_# diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a95009c3..0d184210 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d5..a69d9cb6 100755 --- a/gradlew +++ b/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -89,84 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..f127cfd4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,91 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index f74c120a..0077fa74 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,33 +1,13 @@ -// Workaround to make the JUnit Platform Gradle Plugin available using the `plugins` DSL -// See https://github.com/junit-team/junit5/issues/768 -if (!(GradleVersion.current() <= GradleVersion.version('2.14.1'))) { pluginManagement { - repositories { - gradlePluginPortal() - maven { url = ArtifactRepositoryContainer.MAVEN_CENTRAL_URL } - } - resolutionStrategy { - eachPlugin { - if (requested.id.id == 'org.junit.platform.gradle.plugin') { - useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") -// } else if (requested.id.id == 'org.junit.platform.gradle.plugin') { -// useModule("org.junit.platform:junit-platform-gradle-plugin:${requested.version}") - } + repositories { + gradlePluginPortal() + maven { + name = 'MinecraftForge' + url = 'https://maven.minecraftforge.net/' + } } - } -} -} - -rootProject.name = archivesBaseName -import org.gradle.util.GradleVersion -if ((GradleVersion.current() >= GradleVersion.version('4.8')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { - enableFeaturePreview('STABLE_PUBLISHING') // 4.10.3 } -// TODO: Things which likely don't work with FG yet, but I've not checked. -/* -if ((GradleVersion.current() >= GradleVersion.version('4.6')) && (GradleVersion.current() <= GradleVersion.version('4.10.3'))) { - enableFeaturePreview('IMPROVED_POM_SUPPORT') // Previously -Dorg.gradle.advancedpomsupport=true - enableFeaturePreview('GRADLE_METADATA') // Previously -Dorg.gradle.gradlemetadata=true +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' } -*/ diff --git a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java b/src/main/java/com/mcmoddev/orespawn/EventHandlers.java deleted file mode 100644 index bcaaadfd..00000000 --- a/src/main/java/com/mcmoddev/orespawn/EventHandlers.java +++ /dev/null @@ -1,259 +0,0 @@ -package com.mcmoddev.orespawn; - -import java.util.Arrays; -import java.util.Deque; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.TreeMap; -import java.util.concurrent.ConcurrentLinkedDeque; -import java.util.stream.Collectors; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.MapDifference; -import com.google.common.collect.Maps; -import com.mcmoddev.orespawn.data.Config; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.Tuple; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.gen.ChunkProviderServer; -import net.minecraft.world.gen.IChunkGenerator; -import net.minecraftforge.event.terraingen.OreGenEvent; -import net.minecraftforge.event.terraingen.OreGenEvent.GenerateMinable.EventType; -import net.minecraftforge.event.world.ChunkDataEvent; -import net.minecraftforge.fml.common.Loader; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; -import net.minecraftforge.fml.common.eventhandler.Event; -import net.minecraftforge.fml.common.eventhandler.EventPriority; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; -import net.minecraftforge.fml.common.gameevent.TickEvent.WorldTickEvent; -import net.minecraftforge.fml.relauncher.Side; - -public class EventHandlers { - - private final Deque retroChunks; - private final Deque>> chunks; - // private Map> chunks - - EventHandlers() { - retroChunks = new ConcurrentLinkedDeque<>(); - chunks = new ConcurrentLinkedDeque<>(); - } - - private final List vanillaEvents = Arrays.asList(EventType.ANDESITE, EventType.COAL, - EventType.DIAMOND, EventType.DIORITE, EventType.DIRT, EventType.EMERALD, EventType.GOLD, - EventType.GRANITE, EventType.GRAVEL, EventType.IRON, EventType.LAPIS, - EventType.REDSTONE, EventType.QUARTZ, EventType.SILVERFISH); - - @SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true) - public void onGenerateMinable(final OreGenEvent.GenerateMinable event) { - if (Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - && vanillaEvents.contains(event.getType())) { - event.setResult(Event.Result.DENY); - } else if(Config.getBoolean(Constants.REPLACE_ALL) && !Loader.instance().activeModContainer().getModId().equals("orespawn")) { - event.setResult(Event.Result.DENY); - } - } - - @SubscribeEvent - public void onChunkSave(final ChunkDataEvent.Save ev) { - final NBTTagCompound dataTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final NBTTagCompound features = new NBTTagCompound(); - - // save a list of the spawns that were configured and available - in this dimension - when - // the chunk - // was first generated. - - // collect that data - final int thisDimension = ev.getWorld().provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, ev.getWorld().getBiomeProvider()); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(thisDimension)) - .filter(ent -> ent.getValue().biomeAllowed(thisBiome)).forEach(ent -> features - .setString(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - dataTag.setTag(Constants.FEATURES_TAG, features); - - ev.getData().setTag(Constants.CHUNK_TAG_NAME, dataTag); - } - - private boolean dequeContains(final ChunkPos cc) { - return chunks.stream().map(tup -> tup.getFirst().equals(cc)).collect(Collectors.toList()) - .contains(true); - } - - @SubscribeEvent - public void onChunkLoad(final ChunkDataEvent.Load ev) { - final World clWorld = ev.getWorld(); - final ChunkPos chunkCoords = new ChunkPos(ev.getChunk().x, ev.getChunk().z); - - doBedrockRetrogen(chunkCoords); - - if (dequeContains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETROGEN_KEY)) { - final NBTTagCompound chunkTag = ev.getData().getCompoundTag(Constants.CHUNK_TAG_NAME); - final int thisDimension = clWorld.provider.getDimension(); - final BlockPos thisPos = new BlockPos(ev.getChunk().x + 8, 128, ev.getChunk().z + 8); - final Biome thisBiome = ev.getChunk().getBiome(thisPos, clWorld.getBiomeProvider()); - - if (featuresAreDifferent(chunkTag, thisDimension, thisBiome) - || Config.getBoolean(Constants.FORCE_RETROGEN_KEY)) { - chunks.addLast(new Tuple<>(chunkCoords, - getDifferingTags(chunkTag, thisDimension, thisBiome))); - } - } - } - - private List getDifferingTags(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - final List stuff = Lists.newLinkedList(); - stuff.addAll(diff.entriesDiffering().entrySet().stream().map(Map.Entry::getKey) - .collect(Collectors.toList())); - stuff.addAll(diff.entriesOnlyOnRight().entrySet().stream().map(Map.Entry::getKey) - .collect(Collectors.toList())); - return ImmutableList.copyOf(stuff); - } - - private boolean featuresAreDifferent(final NBTTagCompound chunkTag, final int dim, - final Biome biome) { - final NBTTagCompound tagList = chunkTag.getCompoundTag(Constants.FEATURES_TAG); - final Map currentBits = new TreeMap<>(); - final Map oldBits = new TreeMap<>(); - - OreSpawn.API.getAllSpawns().entrySet().stream() - .filter(ent -> ent.getValue().dimensionAllowed(dim)) - .filter(ent -> ent.getValue().biomeAllowed(biome)).forEach(ent -> currentBits - .put(ent.getKey(), ent.getValue().getFeature().getFeatureName())); - - tagList.getKeySet().stream().forEach(tag -> oldBits.put(tag, tagList.getString(tag))); - - final MapDifference diff = Maps.difference(oldBits, currentBits); - - return diff.entriesDiffering().size() == 0 && diff.entriesOnlyOnLeft().size() == 0 - && diff.entriesOnlyOnRight().size() == 0; - } - - private void doBedrockRetrogen(final ChunkPos chunkCoords) { - if (retroChunks.contains(chunkCoords)) { - return; - } - - if (Config.getBoolean(Constants.RETRO_BEDROCK)) { - retroChunks.addLast(chunkCoords); - } - } - - private static World world; - private static ChunkProviderServer chunkProvider; - private static IChunkGenerator chunkGenerator; - private static Random random; - - private static void setupData(final World nw) { - if (world == null || !world.equals(nw)) { - world = nw; - } - - if (chunkProvider == null || !chunkProvider.equals(nw.getChunkProvider())) { - chunkProvider = (ChunkProviderServer) nw.getChunkProvider(); - } - - if (chunkGenerator == null) { - chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, - chunkProvider, "field_186029_c", "chunkGenerator"); - } - - if (random == null) { - random = new Random(world.getSeed()); - } - - } - - private OreSpawnFeatureGenerator findSpawn(final String spawnName) { - for (OreSpawnFeatureGenerator ofg : OreSpawn.API.getGenerators()) { - if (ofg.getSpawnName().matches(spawnName)) return ofg; - } - return null; - } - - private void runBits(final Tuple> tup, World world) { - final ChunkPos p = tup.getFirst(); - final List spawns = tup.getSecond(); - if(!world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { - chunks.add(tup); - return; - } - // re-seed with something totally new :P - random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) - ^ world.getSeed()); - spawns.stream().forEach(s -> { - OreSpawnFeatureGenerator feature = findSpawn(s); - if (feature != null) feature.generate(random, p.x, p.z, world, chunkGenerator, chunkProvider); - }); - } - - @SubscribeEvent - public void worldTick(final WorldTickEvent ev) { - setupData(ev.world); - - if (ev.side != Side.SERVER) { - return; - } - - if (ev.phase == Phase.END) { - int chunkCount = chunks.size(); - for (int c = 0; c < 25 && !chunks.isEmpty(); c++) { - Tuple> pp = chunks.pop(); - if(ev.world.isBlockLoaded(new BlockPos(pp.getFirst().getXStart(), 128, pp.getFirst().getZStart()))) { - runBits(pp, ev.world); - } else { - chunks.add(pp); - c--; - } - chunkCount--; - if (chunkCount <= 0) { - break; - } - } - - chunkCount = retroChunks.size(); - for (int c = 0; c < 25 && !retroChunks.isEmpty(); c++) { - final ChunkPos p = retroChunks.pop(); - if(ev.world.isBlockLoaded(new BlockPos(p.getXStart(), 128, p.getZStart()))) { - OreSpawn.flatBedrock.retrogen(world, p.x, p.z); - } else { - c--; - retroChunks.add(p); - } - chunkCount--; - if (chunkCount <= 0) { - break; - } - } - } - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java index 2f7061f1..e5854d96 100644 --- a/src/main/java/com/mcmoddev/orespawn/OreSpawn.java +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawn.java @@ -1,100 +1,173 @@ package com.mcmoddev.orespawn; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import com.mcmoddev.orespawn.api.os3.OS3API; -import com.mcmoddev.orespawn.api.plugin.PluginLoader; -import com.mcmoddev.orespawn.commands.AddOreCommand; -import com.mcmoddev.orespawn.commands.ClearChunkCommand; -import com.mcmoddev.orespawn.commands.DumpBiomesCommand; -import com.mcmoddev.orespawn.commands.WriteConfigsCommand; -import com.mcmoddev.orespawn.data.Config; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.data.FeatureRegistry; -import com.mcmoddev.orespawn.impl.os3.OS3APIImpl; -import com.mcmoddev.orespawn.worldgen.FlatBedrock; -import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; +import com.mcmoddev.orespawn.integration.WorldgenIntegrationManager; +import com.mcmoddev.orespawn.init.OreSpawnPatterns; +import com.mcmoddev.orespawn.worldgen.OreSpawnOreGeneration; +import com.mcmoddev.orespawn.worldgen.GeomeConfig; +import com.mcmoddev.orespawn.worldgen.GeomeDistributionSampler; +import com.mcmoddev.orespawn.worldgen.OilDepositFeature; +import com.mcmoddev.orespawn.worldgen.StoneReplacer; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfileManager; +import com.mcmoddev.orespawn.worldgen.FormationSettings.Preset; +import com.mcmoddev.orespawn.OreSpawnConfig.GeologyMode; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfile; +import com.mcmoddev.orespawn.worldgen.WorldgenBenchmark; +import com.mcmoddev.orespawn.worldgen.FlatBedrockFeature; +import com.mcmoddev.orespawn.worldgen.OreRetrogenManager; +import com.mcmoddev.orespawn.commands.OreSpawnCommands; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.Mod.Instance; -import net.minecraftforge.fml.common.event.FMLFingerprintViolationEvent; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.event.FMLServerStartingEvent; -import net.minecraftforge.fml.common.registry.GameRegistry; - -/** - * Main entry point for the mod, everything runs through this. - * - * @author DShadowWolf <dshadowwolf@gmail.com> - */ - -@Mod(modid = Constants.MODID, - name = Constants.NAME, - version = Constants.VERSION, - acceptedMinecraftVersions = "[1.12,1.12.2]", - certificateFingerprint = "@FINGERPRINT@") +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent; +import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; +import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.ForgeRegistries; -public class OreSpawn { +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; - @Instance +@Mod(OreSpawn.MODID) +public class OreSpawn { public static OreSpawn instance; - public static final Logger LOGGER = LogManager.getLogger(Constants.MODID); - public static final OS3API API = new OS3APIImpl(); - static final EventHandlers eventHandlers = new EventHandlers(); - public static final FeatureRegistry FEATURES = new FeatureRegistry(); + public static final String MODID = "orespawn"; + public static final String NAME = "OreSpawn"; + public static final String VERSION = getVersion(); + + private static final Logger LOGGER = LogManager.getLogger(); - static final FlatBedrock flatBedrock = new FlatBedrock(); - - @EventHandler - public void onFingerprintViolation(final FMLFingerprintViolationEvent event) { - LOGGER.warn("Invalid fingerprint detected!"); + private static String getVersion() { + Package metadata = OreSpawn.class.getPackage(); + String version = metadata == null ? null : metadata.getImplementationVersion(); + return version == null ? "DEV" : version; } - @EventHandler - public void preInit(final FMLPreInitializationEvent ev) { - Config.loadConfig(); + public OreSpawn() { + instance = this; + OreSpawnConfig.register(); + OreSpawnPatterns.register(FMLJavaModLoadingContext.get().getModEventBus()); + + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueInterMod); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processInterMod); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::loadComplete); + MinecraftForge.EVENT_BUS.addListener(StoneReplacer::onBiomeLoading); + MinecraftForge.EVENT_BUS.addListener(OreSpawnOreGeneration::onBiomeLoading); + MinecraftForge.EVENT_BUS.addListener(OilDepositFeature::onBiomeLoading); + MinecraftForge.EVENT_BUS.addListener(FlatBedrockFeature::onBiomeLoading); + MinecraftForge.EVENT_BUS.addListener(WorldGeologyProfileManager::onServerAboutToStart); + MinecraftForge.EVENT_BUS.addListener(WorldGeologyProfileManager::onServerStopped); + MinecraftForge.EVENT_BUS.addListener(OreRetrogenManager::onChunkLoad); + MinecraftForge.EVENT_BUS.addListener(OreRetrogenManager::onChunkSave); + MinecraftForge.EVENT_BUS.addListener(OreRetrogenManager::onServerTick); + MinecraftForge.EVENT_BUS.addListener(OreSpawnCommands::register); + WorldgenBenchmark.register(); + } - PluginLoader.INSTANCE.load(ev); + private void loadComplete(final FMLLoadCompleteEvent event) { + event.enqueueWork(() -> { + WorldgenIntegrationManager.freeze(); + GeomeConfig.bake(); + OreSpawnOreGeneration.refreshWorldConfig(); + FlatBedrockFeature.refreshWorldConfig(); + OreRetrogenManager.refreshWorldConfig(); + WorldgenIntegrationManager.markFeatureReady(); + }); + } - if (Config.getBoolean(Constants.FLAT_BEDROCK)) { - GameRegistry.registerWorldGenerator(flatBedrock, 100); - } - - if (Config.getBoolean(Constants.RETROGEN_KEY) - || Config.getBoolean(Constants.REPLACE_VANILLA_OREGEN) - || Config.getBoolean(Constants.RETRO_BEDROCK)) { - MinecraftForge.EVENT_BUS.register(eventHandlers); - MinecraftForge.ORE_GEN_BUS.register(eventHandlers); - } + private void enqueueInterMod(final InterModEnqueueEvent event) { + // Provider mods submit WorldgenProvider values from their own enqueue event. } - @EventHandler - public void init(final FMLInitializationEvent ev) { - PluginLoader.INSTANCE.register(); + private void processInterMod(final InterModProcessEvent event) { + // Files are authoritative, so scan them before accepting API submissions. + WorldgenIntegrationManager.initialize(); + WorldgenIntegrationManager.processImcMessages(); + GeomeConfig.bake(); + OreSpawnOreGeneration.refreshWorldConfig(); + FlatBedrockFeature.refreshWorldConfig(); + OreRetrogenManager.refreshWorldConfig(); + } - API.loadConfigFiles(); + private void setup(final FMLCommonSetupEvent event) { + OreSpawnConfig.bake(); + WorldgenIntegrationManager.initialize(); + GeomeConfig.bake(); + logGeomeSampler(); + event.enqueueWork(() -> { + StoneReplacer.registerConfiguredFeature(); + OreSpawnOreGeneration.registerConfiguredFeatures(); + OilDepositFeature.registerConfiguredFeature(); + FlatBedrockFeature.registerConfiguredFeature(); + }); } - @EventHandler - public void postInit(final FMLPostInitializationEvent ev) { - Config.saveConfig(); - API.getAllSpawns().entrySet().stream() - .forEach(ent -> { - GameRegistry.registerWorldGenerator(new OreSpawnFeatureGenerator(ent.getValue(), ent.getKey()), 100); - }); + private static void logGeomeSampler() { + if (!Boolean.getBoolean("orespawn.geomeSampler")) { + return; + } + + WorldGeologyProfile original = GeomeConfig.globalProfile(); + String defaultSeed = Long.toString(Long.getLong("orespawn.geomeSamplerSeed", 19780401L)); + String[] samplerSeeds = System.getProperty("orespawn.geomeSamplerSeeds", defaultSeed).split(","); + String profileFilter = System.getProperty("orespawn.geomeSamplerProfiles", "all"); + boolean includeBiomeAudit = Boolean.parseBoolean( + System.getProperty("orespawn.geomeSamplerBiomeAudit", "true")); + try { + for (String seedText : samplerSeeds) { + long samplerSeed = Long.parseLong(seedText.trim()); + for (Preset preset : new Preset[] { + Preset.TINY, Preset.SMALL, Preset.AVERAGE, Preset.LARGE, Preset.HUGE }) { + if (!samplerProfileEnabled(profileFilter, preset.configName())) { + continue; + } + WorldGeologyProfile profile = original + .withSelection(GeologyMode.GEOME, preset, preset, preset, preset, preset, + original.placeCrudeOil()); + logSamplerProfile("Sky " + preset.configName(), samplerSeed, profile, includeBiomeAudit); + } + if (samplerProfileEnabled(profileFilter, "mixed_huge")) { + WorldGeologyProfile mixedHuge = original + .withSelection(GeologyMode.GEOME, Preset.AVERAGE, Preset.HUGE, Preset.HUGE, + Preset.HUGE, Preset.HUGE, original.placeCrudeOil()); + logSamplerProfile("Sky mixed-huge", samplerSeed, mixedHuge, includeBiomeAudit); + } + } + } finally { + GeomeConfig.applyWorldProfile(original); + } } - @EventHandler - public void onServerStarting(final FMLServerStartingEvent ev) { - ev.registerServerCommand(new ClearChunkCommand()); - ev.registerServerCommand(new DumpBiomesCommand()); - ev.registerServerCommand(new AddOreCommand()); - ev.registerServerCommand(new WriteConfigsCommand()); + private static boolean samplerProfileEnabled(String filter, String profile) { + if ("all".equalsIgnoreCase(filter.trim())) { + return true; + } + for (String configured : filter.split(",")) { + if (profile.equalsIgnoreCase(configured.trim())) { + return true; + } + } + return false; } + + private static void logSamplerProfile(String label, long seed, WorldGeologyProfile profile, + boolean includeBiomeAudit) { + GeomeConfig.applyWorldProfile(profile); + String terrainSample = System.getProperty("orespawn.geomeSamplerTerrain"); + if (terrainSample == null || terrainSample.trim().isEmpty()) { + LOGGER.info("\n{} sampler\n{}", label, + GeomeDistributionSampler.sample(seed, ForgeRegistries.BIOMES.getValues(), 8, 8, + includeBiomeAudit)); + return; + } + try { + LOGGER.info("\n{} sampler\n{}", label, + GeomeDistributionSampler.sampleTerrain(seed, java.nio.file.Paths.get(terrainSample))); + } catch (java.io.IOException e) { + LOGGER.error("Could not replay OreSpawn terrain sample '{}'", terrainSample, e); + } + } + } diff --git a/src/main/java/com/mcmoddev/orespawn/OreSpawnConfig.java b/src/main/java/com/mcmoddev/orespawn/OreSpawnConfig.java new file mode 100644 index 00000000..4c45ea4b --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/OreSpawnConfig.java @@ -0,0 +1,145 @@ +package com.mcmoddev.orespawn; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.config.ModConfig; + +/** Small bootstrap fallback; the JSON profile is the authoritative worldgen configuration. */ +public final class OreSpawnConfig { + private static final Common COMMON; + private static final ForgeConfigSpec SPEC; + + private static volatile boolean placeTerrain = true; + private static volatile GeologyMode geologyMode = GeologyMode.GEOME; + private static volatile int geomeSize = 256; + private static volatile double rockLayerNoise = 32.0D; + private static volatile int layerThickness = 8; + private static volatile boolean placeCrudeOil; + private static volatile OilGenerationSettings crudeOil = + new OilGenerationSettings(-48, 48, 0.08D, 5, 12, 2, 5, 4, 2); + + static { + Pair pair = new ForgeConfigSpec.Builder().configure(Common::new); + COMMON = pair.getLeft(); + SPEC = pair.getRight(); + } + + private OreSpawnConfig() { + } + + public static void register() { + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPEC, "orespawn-common.toml"); + } + + public static void bake() { + placeTerrain = COMMON.placeTerrain.get(); + geologyMode = COMMON.geologyMode.get(); + geomeSize = COMMON.geomeSize.get(); + rockLayerNoise = COMMON.rockLayerNoise.get(); + layerThickness = COMMON.layerThickness.get(); + placeCrudeOil = COMMON.placeCrudeOil.get(); + crudeOil = new OilGenerationSettings(COMMON.oilMinY.get(), COMMON.oilMaxY.get(), + COMMON.oilFrequency.get(), COMMON.oilMinRadius.get(), COMMON.oilMaxRadius.get(), + COMMON.oilMinVerticalRadius.get(), COMMON.oilMaxVerticalRadius.get(), + COMMON.oilMaxLobes.get(), COMMON.oilSolidCover.get()); + } + + public static boolean placeOreSpawnRock() { return placeTerrain; } + public static GeologyMode geologyMode() { return geologyMode; } + public static int geomeSize() { return geomeSize; } + public static double rockLayerNoise() { return rockLayerNoise; } + public static int geomLayerThickness() { return layerThickness; } + public static boolean placeCrudeOil() { return placeCrudeOil; } + public static OilGenerationSettings crudeOil() { return crudeOil; } + + private static final class Common { + final ForgeConfigSpec.BooleanValue placeTerrain; + final ForgeConfigSpec.EnumValue geologyMode; + final ForgeConfigSpec.IntValue geomeSize; + final ForgeConfigSpec.DoubleValue rockLayerNoise; + final ForgeConfigSpec.IntValue layerThickness; + final ForgeConfigSpec.BooleanValue placeCrudeOil; + final ForgeConfigSpec.IntValue oilMinY; + final ForgeConfigSpec.IntValue oilMaxY; + final ForgeConfigSpec.DoubleValue oilFrequency; + final ForgeConfigSpec.IntValue oilMinRadius; + final ForgeConfigSpec.IntValue oilMaxRadius; + final ForgeConfigSpec.IntValue oilMinVerticalRadius; + final ForgeConfigSpec.IntValue oilMaxVerticalRadius; + final ForgeConfigSpec.IntValue oilMaxLobes; + final ForgeConfigSpec.IntValue oilSolidCover; + + Common(ForgeConfigSpec.Builder builder) { + builder.comment("Bootstrap fallbacks. Detailed settings live in orespawn-worldgen.json.") + .push("worldgen"); + placeTerrain = builder.comment("Master switch for configured terrain replacement.") + .define("place_terrain", true); + geologyMode = builder.defineEnum("fallback_geology_mode", GeologyMode.GEOME); + geomeSize = builder.defineInRange("cyano_region_size", 256, 4, Short.MAX_VALUE); + rockLayerNoise = builder.defineInRange("cyano_layer_reach", 32.0D, 1.0D, Short.MAX_VALUE); + layerThickness = builder.defineInRange("cyano_layer_thickness", 8, 1, 255); + placeCrudeOil = builder.define("fallback_place_crude_oil", false); + builder.push("oil_fallback"); + oilMinY = builder.defineInRange("min_y", -48, -2048, 2048); + oilMaxY = builder.defineInRange("max_y", 48, -2048, 2048); + oilFrequency = builder.defineInRange("frequency", 0.08D, 0.0D, 64.0D); + oilMinRadius = builder.defineInRange("min_radius", 5, 1, 64); + oilMaxRadius = builder.defineInRange("max_radius", 12, 1, 64); + oilMinVerticalRadius = builder.defineInRange("min_vertical_radius", 2, 1, 32); + oilMaxVerticalRadius = builder.defineInRange("max_vertical_radius", 5, 1, 32); + oilMaxLobes = builder.defineInRange("max_lobes", 4, 1, 16); + oilSolidCover = builder.defineInRange("min_solid_cover", 2, 1, 64); + builder.pop(2); + } + } + + public static final class OreGenerationSettings { + private final int minY; + private final int maxY; + private final double frequency; + private final int quantity; + public OreGenerationSettings(int minY, int maxY, double frequency, int quantity) { + this.minY = minY; this.maxY = maxY; this.frequency = frequency; this.quantity = quantity; + } + public int minY() { return minY; } + public int maxY() { return maxY; } + public double frequency() { return frequency; } + public int quantity() { return quantity; } + } + + public static final class OilGenerationSettings { + private final int minY; + private final int maxY; + private final double frequency; + private final int minRadius; + private final int maxRadius; + private final int minVerticalRadius; + private final int maxVerticalRadius; + private final int maxLobes; + private final int minSolidCover; + public OilGenerationSettings(int minY, int maxY, double frequency, int minRadius, int maxRadius, + int minVerticalRadius, int maxVerticalRadius, int maxLobes, int minSolidCover) { + this.minY = minY; this.maxY = maxY; this.frequency = frequency; + this.minRadius = Math.min(minRadius, maxRadius); this.maxRadius = Math.max(minRadius, maxRadius); + this.minVerticalRadius = Math.min(minVerticalRadius, maxVerticalRadius); + this.maxVerticalRadius = Math.max(minVerticalRadius, maxVerticalRadius); + this.maxLobes = maxLobes; this.minSolidCover = minSolidCover; + } + public int minY() { return minY; } + public int maxY() { return maxY; } + public double frequency() { return frequency; } + public int minRadius() { return minRadius; } + public int maxRadius() { return maxRadius; } + public int minVerticalRadius() { return minVerticalRadius; } + public int maxVerticalRadius() { return maxVerticalRadius; } + public int maxLobes() { return maxLobes; } + public int minSolidCover() { return minSolidCover; } + } + + public enum GeologyMode { + GEOME, + LEGACY + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java b/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java deleted file mode 100644 index 6870c78a..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/BiomeLocation.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import com.google.common.collect.ImmutableList; -import com.google.gson.JsonElement; -import com.mcmoddev.orespawn.util.Collectors2; - -import net.minecraft.world.biome.Biome; -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -public interface BiomeLocation { - - boolean matches(Biome biome); - - JsonElement serialize(); - - default ImmutableList getBiomes() { - return ForgeRegistries.BIOMES.getValuesCollection().stream().filter(this::matches) - .collect(Collectors2.toImmutableList()); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/CompiledOrePattern.java b/src/main/java/com/mcmoddev/orespawn/api/CompiledOrePattern.java new file mode 100644 index 00000000..45d392ab --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/CompiledOrePattern.java @@ -0,0 +1,11 @@ +package com.mcmoddev.orespawn.api; + +/** + * Immutable, pre-decoded ore pattern used during chunk generation. + * Implementations must be thread-safe and must not allocate or access registries, + * configuration files, tags, or logging from {@link #place(OrePlacementContext)}. + */ +@FunctionalInterface +public interface CompiledOrePattern { + boolean place(OrePlacementContext context); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java b/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java deleted file mode 100644 index b1eb04fb..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/FeatureBase.java +++ /dev/null @@ -1,314 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import java.util.Collections; -import java.util.Deque; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Random; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.OreSpawn; -import com.mcmoddev.orespawn.api.os3.ISpawnEntry; -import com.mcmoddev.orespawn.api.os3.OreSpawnBlockMatcher; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; -import net.minecraftforge.registries.IForgeRegistryEntry; - -public class FeatureBase extends IForgeRegistryEntry.Impl { - - private static final int MAX_CACHE_SIZE = 2048; - /** - * overflow cache so that ores that spawn at edge of chunk can appear in the neighboring chunk - * without triggering a chunk-load. - */ - private static final Map> overflowCache = new HashMap<>( - MAX_CACHE_SIZE); - private static final Deque cacheOrder = new LinkedList<>(); - protected Random random; - - public FeatureBase(final Random rand) { - this.random = rand; - } - - public boolean isValidBlock(final IBlockState oreBlock) { - return oreBlock.getBlock() != Blocks.AIR; - } - - protected void runCache(final int chunkX, final int chunkZ, final World world, - final ISpawnEntry spawnData) { - final Vec3i chunkCoord = new Vec3i(chunkX, chunkZ, world.provider.getDimension()); - final Map cache = retrieveCache(chunkCoord); - - if (!cache.isEmpty()) { // if there is something in the cache, try to spawn it - for (final Entry ent : cache.entrySet()) { - spawnNoCheck(cache.get(ent.getKey()), world, ent.getKey(), - world.provider.getDimension(), spawnData); - } - } - } - - protected boolean spawn(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final boolean cacheOverflow, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.error("FeatureBase.spawn() called with a null ore!"); - return false; - } - - if (!isValidBlock(oreBlock)) { - return false; - } - - final Biome thisBiome = world.getBiome(coord); - - if (!spawnData.biomeAllowed(thisBiome.getRegistryName())) { - return false; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (world.isValid(coord)) { - OreSpawn.LOGGER.warn("Asked to spawn {} outside of world at {}", oreBlock, coord); - return false; - } - - return spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, cacheOverflow, dimension, - spawnData); - } - - private BlockPos mungeFixYcoord(final BlockPos coord) { - if (coord.getY() < 0) { - final int newYCoord = coord.getY() * -1; - return new BlockPos(coord.getX(), newYCoord, coord.getZ()); - } else { - return new BlockPos(coord); - } - } - - private boolean spawnOrCache(final World world, final BlockPos coord, - final OreSpawnBlockMatcher replacer, final IBlockState oreBlock, - final boolean cacheOverflow, final int dimension, final ISpawnEntry spawnData) { - if (world.isBlockLoaded(coord)) { - boolean x_bad = false; - boolean z_bad = false; - ChunkPos start = world.getChunk(coord).getPos(); - ChunkPos end = new ChunkPos(start.x+1, start.z+1); - if (coord.getX() < start.getXStart() || coord.getX() > end.getXEnd()) x_bad = true; - if (coord.getZ() < start.getZStart() || coord.getZ() > end.getZEnd()) z_bad = true; - - if(x_bad || z_bad) { - if(cacheOverflow) { - cacheOverflowBlock(oreBlock, coord, dimension); - return true; - } else { - return false; - } - } - if (!isValidBlock(oreBlock)) { - return false; - } - - final IBlockState targetBlock = world.getBlockState(coord); - final Biome thisBiome = world.getBiome(coord); - - if (replacer.test(targetBlock) && spawnData.biomeAllowed(thisBiome.getRegistryName())) { - // don't send block update, send to client, don't re-render, observers don't see the change - world.setBlockState(coord, oreBlock, 0x16); - return true; - } else { - return false; - } - } else if (cacheOverflow) { - cacheOverflowBlock(oreBlock, coord, dimension); - return true; - } - - return false; - } - - private void spawnNoCheck(final IBlockState oreBlock, final World world, final BlockPos coord, - final int dimension, final ISpawnEntry spawnData) { - if (oreBlock == null) { - OreSpawn.LOGGER.error("FeatureBase.spawnNoCheck() called with a null ore!"); - return; - } - - final BlockPos np = mungeFixYcoord(coord); - - if (coord.getY() >= world.getHeight()) { - OreSpawn.LOGGER.warn("Asked to spawn {} above build limit at {}", oreBlock, coord); - return; - } - - spawnOrCache(world, np, spawnData.getMatcher(), oreBlock, false, dimension, spawnData); - } - - private void cacheOverflowBlock(final IBlockState bs, final BlockPos coord, - final int dimension) { - final Vec3i chunkCoord = new Vec3i(coord.getX() / 16, coord.getY() / 16, dimension); - - if (overflowCache.containsKey(chunkCoord)) { - cacheOrder.addLast(chunkCoord); - - if (cacheOrder.size() > MAX_CACHE_SIZE) { - final Vec3i drop = cacheOrder.removeFirst(); - overflowCache.get(drop).clear(); - overflowCache.remove(drop); - } - - overflowCache.put(chunkCoord, new HashMap<>()); - } - - final Map cache = overflowCache.getOrDefault(chunkCoord, - new HashMap<>()); - cache.put(coord, bs); - } - - private Map retrieveCache(final Vec3i chunkCoord) { - if (overflowCache.containsKey(chunkCoord)) { - final Map cache = overflowCache.get(chunkCoord); - cacheOrder.remove(chunkCoord); - overflowCache.remove(chunkCoord); - return cache; - } else { - return Collections.emptyMap(); - } - } - - protected void scramble(final int[] target, final Random prng) { - for (int i = target.length - 1; i > 0; i--) { - final int n = prng.nextInt(i); - final int temp = target[i]; - target[i] = target[n]; - target[n] = temp; - } - } - - protected static final Vec3i[] offsets_small = { - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(0, 1, 0), new Vec3i(1, 1, 0), - - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(0, 1, 1), new Vec3i(1, 1, 1) - }; - - protected static final Vec3i[] offsets = { - new Vec3i(-1, -1, -1), new Vec3i(0, -1, -1), new Vec3i(1, -1, -1), new Vec3i(-1, 0, -1), - new Vec3i(0, 0, -1), new Vec3i(1, 0, -1), new Vec3i(-1, 1, -1), new Vec3i(0, 1, -1), - new Vec3i(1, 1, -1), - - new Vec3i(-1, -1, 0), new Vec3i(0, -1, 0), new Vec3i(1, -1, 0), new Vec3i(-1, 0, 0), - new Vec3i(0, 0, 0), new Vec3i(1, 0, 0), new Vec3i(-1, 1, 0), new Vec3i(0, 1, 0), - new Vec3i(1, 1, 0), - - new Vec3i(-1, -1, 1), new Vec3i(0, -1, 1), new Vec3i(1, -1, 1), new Vec3i(-1, 0, 1), - new Vec3i(0, 0, 1), new Vec3i(1, 0, 1), new Vec3i(-1, 1, 1), new Vec3i(0, 1, 1), - new Vec3i(1, 1, 1) - }; - - protected static final int[] offsetIndexRef = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - 24, 25, 26 - }; - protected static final int[] offsetIndexRef_small = { - 0, 1, 2, 3, 4, 5, 6, 7 - }; - - protected static void mergeDefaults(final JsonObject parameters, - final JsonObject defaultParameters) { - defaultParameters.entrySet().forEach(entry -> { - if (!parameters.has(entry.getKey())) { - parameters.add(entry.getKey(), entry.getValue()); - } - }); - } - - private double triangularDistribution(final double a, final double b, final double c) { - final double base = (c - a) / (b - a); - final double rand = this.random.nextDouble(); - - if (rand < base) { - return a + Math.sqrt(rand * (b - a) * (c - a)); - } else { - return b - Math.sqrt((1 - rand) * (b - a) * (b - c)); - } - } - - protected int getPoint(final int lowerBound, final int upperBound, final int median) { - final int t = (int) Math.round( - triangularDistribution((float) lowerBound, (float) upperBound, (float) median)); - return t - median; - } - - protected void spawnMungeInner(final Random prng, final int rSqr, int quantity, - final Vec3i vals, final ISpawnEntry spawnData, final World world, final BlockPos blockPos) { - int dx = vals.getX(); - int dy = vals.getY(); - int dz = vals.getZ(); - final IBlockList possibleOres = spawnData.getBlocks(); - final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - - if ((dx * dx + dy * dy + dz * dz) <= rSqr) { - final IBlockState oreBlock = possibleOres.getRandomBlock(prng); - if (oreBlock.getBlock().equals(net.minecraft.init.Blocks.AIR)) return; - spawnOrCache(world, blockPos.add(dx, dy, dz), replacer, oreBlock, true, - world.provider.getDimension(), spawnData); - quantity--; - } - } - - protected void spawnMungeSW(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dx = (int) (radius); dx >= (int) (-1 * radius); dx--) { - for (int dz = (int) (radius); dz >= (int) (-1 * radius); dz--) { - spawnMungeInner(prng, rSqr, quantity, new Vec3i(dx,dy,dz), spawnData, world, blockPos); - if (quantity <= 0) { - return; - } - } - } - } - } - - protected void spawnMungeNE(final World world, final BlockPos blockPos, final int rSqr, - final double radius, final ISpawnEntry spawnData, final int count) { - final Random prng = this.random; - int quantity = count; -// final IBlockList possibleOres = spawnData.getBlocks(); -// final OreSpawnBlockMatcher replacer = spawnData.getMatcher(); - for (int dy = (int) (-1 * radius); dy < radius; dy++) { - for (int dz = (int) (-1 * radius); dz < radius; dz++) { - for (int dx = (int) (-1 * radius); dx < radius; dx++) { - spawnMungeInner(prng, rSqr, quantity, new Vec3i(dx,dy,dz), spawnData, world, blockPos); - if (quantity <= 0) { - return; - } - } - } - } - } - - protected int getABC(final int dx, final int dy, final int dz) { - return (dx * dx + dy * dy + dz * dz); - } - - protected int countItem(final int dx, final boolean toPositive) { - return toPositive ? dx + 1 : dx - 1; - } - - protected boolean endCheck(final boolean toPositive, final int dx, final double radius) { - return toPositive ? (dx >= getStart(toPositive, radius)) : (dx < radius); - } - - protected int getStart(final boolean toPositive, final double radius) { - return ((int) (radius * (toPositive ? 1 : -1))); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/FormationPreset.java b/src/main/java/com/mcmoddev/orespawn/api/FormationPreset.java new file mode 100644 index 00000000..39435a3a --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/FormationPreset.java @@ -0,0 +1,21 @@ +package com.mcmoddev.orespawn.api; + +/** Named formation scales accepted by the world profile. */ +public enum FormationPreset { + TINY("tiny"), + SMALL("small"), + AVERAGE("average"), + LARGE("large"), + HUGE("huge"), + CUSTOM("custom"); + + private final String configName; + + FormationPreset(String configName) { + this.configName = configName; + } + + public String configName() { + return configName; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeologyAlgorithm.java b/src/main/java/com/mcmoddev/orespawn/api/GeologyAlgorithm.java new file mode 100644 index 00000000..3b47aadc --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/GeologyAlgorithm.java @@ -0,0 +1,17 @@ +package com.mcmoddev.orespawn.api; + +/** Supported terrain formation algorithms. */ +public enum GeologyAlgorithm { + STABLE_LAYERS("stable_layers"), + SKY_V1("sky_v1"); + + private final String configName; + + GeologyAlgorithm(String configName) { + this.configName = configName; + } + + public String configName() { + return configName; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeologyColumn.java b/src/main/java/com/mcmoddev/orespawn/api/GeologyColumn.java new file mode 100644 index 00000000..9d31fbd8 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/GeologyColumn.java @@ -0,0 +1,18 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Optional; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; + +/** A single classified geology column returned by {@link GeologySampler}. */ +public interface GeologyColumn { + ResourceLocation dimension(); + ResourceLocation biome(); + ResourceLocation geome(); + int blockX(); + int blockZ(); + int surfaceY(); + BlockState rockAt(int y); + Optional familyAt(int y); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeologyFamily.java b/src/main/java/com/mcmoddev/orespawn/api/GeologyFamily.java new file mode 100644 index 00000000..7019e3a7 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/GeologyFamily.java @@ -0,0 +1,19 @@ +package com.mcmoddev.orespawn.api; + +/** Geological families understood by OreSpawn's declarative engines. */ +public enum GeologyFamily { + SEDIMENTARY("sedimentary"), + METAMORPHIC("metamorphic"), + IGNEOUS_INTRUSIVE("igneous_intrusive"), + IGNEOUS_VOLCANIC("igneous_volcanic"); + + private final String configName; + + GeologyFamily(String configName) { + this.configName = configName; + } + + public String configName() { + return configName; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeologyProfileView.java b/src/main/java/com/mcmoddev/orespawn/api/GeologyProfileView.java new file mode 100644 index 00000000..bc3d80c0 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/GeologyProfileView.java @@ -0,0 +1,71 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Optional; +import java.util.Set; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import net.minecraft.resources.ResourceLocation; + +/** Immutable view of the effective geology profile for the active server. */ +public final class GeologyProfileView { + private final JsonObject root; + + GeologyProfileView(JsonObject root) { + this.root = root.deepCopy(); + } + + public int schemaVersion() { + return root.has("schema_version") ? root.get("schema_version").getAsInt() : 0; + } + + public String geologyMode() { + return root.has("geology_mode") ? root.get("geology_mode").getAsString() : "geome"; + } + + public Optional selectedTemplate() { + if (!root.has("selected_template")) { + return Optional.empty(); + } + try { + return Optional.of(new ResourceLocation(root.get("selected_template").getAsString())); + } catch (RuntimeException ignored) { + return Optional.empty(); + } + } + + public Set rockIds() { + return keys("rocks"); + } + + public Set oreIds() { + return keys("ores"); + } + + public Set terrainDimensions() { + return keys("terrain_dimensions"); + } + + /** Returns a defensive copy suitable for diagnostics or tooling. */ + public JsonObject toJson() { + return root.deepCopy(); + } + + private Set keys(String section) { + if (!root.has(section) || !root.get(section).isJsonObject()) { + return Collections.emptySet(); + } + Set values = new LinkedHashSet<>(); + for (String value : root.getAsJsonObject(section).keySet()) { + try { + values.add(new ResourceLocation(value)); + } catch (RuntimeException ignored) { + // Invalid user data is omitted from the typed view. + } + } + return Collections.unmodifiableSet(values); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/GeologySampler.java b/src/main/java/com/mcmoddev/orespawn/api/GeologySampler.java new file mode 100644 index 00000000..0fac0de1 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/GeologySampler.java @@ -0,0 +1,10 @@ +package com.mcmoddev.orespawn.api; + +/** Reusable, read-only sampler for the active world's baked geology. */ +public interface GeologySampler { + /** + * Classifies one column. The returned column reuses that biome/geome + * classification for all subsequent Y queries. + */ + GeologyColumn sampleColumn(int blockX, int blockZ, int surfaceY); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java b/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java deleted file mode 100644 index 26e12bb6..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/IBlockList.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import java.util.Random; - -import com.mcmoddev.orespawn.api.os3.IBlockDefinition; - -import net.minecraft.block.state.IBlockState; - -public interface IBlockList { - - void addBlock(IBlockDefinition block); - - IBlockState getRandomBlock(Random rand); - - void startNewSpawn(); - - void dump(); - - int count(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java b/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java deleted file mode 100644 index 11564819..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/IDimensionList.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import com.google.gson.JsonObject; - -public interface IDimensionList { - - JsonObject serialize(); - - default boolean matches(int dimensionId) { - return false; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java b/src/main/java/com/mcmoddev/orespawn/api/IFeature.java deleted file mode 100644 index 82f04a60..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/IFeature.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mcmoddev.orespawn.api; - -import java.util.Random; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.os3.ISpawnEntry; - -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; -import net.minecraftforge.registries.IForgeRegistryEntry; - -public interface IFeature extends IForgeRegistryEntry { - - void generate(World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider, - ISpawnEntry spawn, ChunkPos pos); - - void setRandom(Random rand); - - JsonObject getDefaultParameters(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OreHeightDistribution.java b/src/main/java/com/mcmoddev/orespawn/api/OreHeightDistribution.java new file mode 100644 index 00000000..919c72e2 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OreHeightDistribution.java @@ -0,0 +1,17 @@ +package com.mcmoddev.orespawn.api; + +/** Vertical distributions supported by OreSpawn-managed ores. */ +public enum OreHeightDistribution { + UNIFORM("uniform"), + TRIANGLE("triangle"); + + private final String configName; + + OreHeightDistribution(String configName) { + this.configName = configName; + } + + public String configName() { + return configName; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OrePattern.java b/src/main/java/com/mcmoddev/orespawn/api/OrePattern.java new file mode 100644 index 00000000..e9a225bb --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OrePattern.java @@ -0,0 +1,28 @@ +package com.mcmoddev.orespawn.api; + +/** Shapes supported by OreSpawn's bounded ore generator. */ +public enum OrePattern { + DEFAULT("default"), + VEIN("vein"), + NORMAL_CLOUD("normal_cloud"), + PRECISION("precision"), + CLUSTERS("clusters"), + UNDERFLUIDS("underfluids"); + + /** @deprecated Use {@link #CLUSTERS}. */ + @Deprecated + public static final OrePattern CLUSTER = CLUSTERS; + /** @deprecated Use {@link #NORMAL_CLOUD}. */ + @Deprecated + public static final OrePattern CLOUD = NORMAL_CLOUD; + + private final String configName; + + OrePattern(String configName) { + this.configName = configName; + } + + public String configName() { + return configName; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OrePatternType.java b/src/main/java/com/mcmoddev/orespawn/api/OrePatternType.java new file mode 100644 index 00000000..543324d8 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OrePatternType.java @@ -0,0 +1,53 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Objects; +import java.util.function.Function; + +import com.google.gson.JsonElement; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; + +import net.minecraftforge.registries.ForgeRegistryEntry; + +/** + * Forge-registered ore pattern type. Its codec is evaluated once while a + * geology profile is baked; only the resulting compiled pattern reaches the + * generation loop. + */ +public final class OrePatternType extends ForgeRegistryEntry { + private final Codec codec; + private final Function compiler; + + private OrePatternType(Codec codec, Function compiler) { + this.codec = Objects.requireNonNull(codec, "codec"); + Objects.requireNonNull(compiler, "compiler"); + this.compiler = value -> compiler.apply(cast(value)); + } + + public static OrePatternType create(Codec codec, + Function compiler) { + return new OrePatternType(codec, compiler); + } + + public Codec codec() { + return codec; + } + + public CompiledOrePattern decode(JsonElement configuration) { + DataResult result = codec.parse(JsonOps.INSTANCE, configuration); + Object value = result.result().orElseThrow(() -> new IllegalArgumentException( + "Invalid settings for ore pattern " + getRegistryName() + ": " + + result.error().map(Object::toString).orElse("unknown codec error"))); + return compile(value); + } + + private CompiledOrePattern compile(Object configuration) { + return Objects.requireNonNull(compiler.apply(configuration), "compiled pattern"); + } + + @SuppressWarnings("unchecked") + private static C cast(Object value) { + return (C) value; + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OrePlacementContext.java b/src/main/java/com/mcmoddev/orespawn/api/OrePlacementContext.java new file mode 100644 index 00000000..d22b44da --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OrePlacementContext.java @@ -0,0 +1,24 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Random; + +import net.minecraft.world.level.material.Fluid; + +/** Allocation-free view supplied to a compiled ore pattern for one attempt. */ +public interface OrePlacementContext { + Random random(); + + int originX(); + int originY(); + int originZ(); + int minY(); + int maxY(); + int quantity(); + int spread(); + int verticalSpread(); + int nodeSize(); + + boolean inside(int x, int y, int z); + boolean isFluid(int x, int y, int z, Fluid fluid); + boolean tryPlace(int x, int y, int z); +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OreSpawnApi.java b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnApi.java new file mode 100644 index 00000000..60f68a90 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnApi.java @@ -0,0 +1,56 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Optional; + +import com.mcmoddev.orespawn.OreSpawn; +import com.mcmoddev.orespawn.integration.WorldgenIntegrationManager; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfileManager; +import com.mcmoddev.orespawn.worldgen.GeomeConfig; + +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerLevel; +import net.minecraftforge.fml.InterModComms; + +/** Entry point for OreSpawn API version 1. */ +public final class OreSpawnApi { + public static final int API_VERSION = 1; + public static final String IMC_WORLDGEN_PROVIDER = "worldgen_provider_v1"; + + private OreSpawnApi() { + } + + /** + * Enqueues a provider through Forge IMC. Call this during + * {@code InterModEnqueueEvent}. + */ + public static boolean enqueue(WorldgenProvider provider) { + if (provider == null) { + throw new IllegalArgumentException("provider cannot be null"); + } + return InterModComms.sendTo(provider.modId(), OreSpawn.MODID, + IMC_WORLDGEN_PROVIDER, () -> provider); + } + + public static ProviderStatus getProviderStatus(String providerModId) { + return WorldgenIntegrationManager.getProviderStatus(providerModId); + } + + public static boolean isOreTakeoverActive(String providerModId) { + return WorldgenIntegrationManager.isOreTakeoverActive(providerModId); + } + + public static Optional getActiveProfile(MinecraftServer server) { + if (server == null || WorldGeologyProfileManager.activeServer() != server) { + return Optional.empty(); + } + return Optional.of(new GeologyProfileView(WorldGeologyProfileManager.activeProfile().toJson())); + } + + public static Optional createSampler(ServerLevel level) { + if (level == null || WorldGeologyProfileManager.activeServer() != level.getServer() + || GeomeConfig.baked(level.dimension()) == null) { + return Optional.empty(); + } + return Optional.of(OreSpawnGeologySampler.create(level)); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OreSpawnGeologySampler.java b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnGeologySampler.java new file mode 100644 index 00000000..359044b2 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnGeologySampler.java @@ -0,0 +1,136 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Locale; +import java.util.Optional; + +import com.mcmoddev.orespawn.OreSpawnConfig.GeologyMode; +import com.mcmoddev.orespawn.worldgen.BakedGeomeConfig; +import com.mcmoddev.orespawn.worldgen.Geology; +import com.mcmoddev.orespawn.worldgen.GeomeConfig; +import com.mcmoddev.orespawn.worldgen.GeomeGeology; +import com.mcmoddev.orespawn.worldgen.RockFamily; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfile; +import com.mcmoddev.orespawn.worldgen.WorldGeologyProfileManager; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.server.level.ServerLevel; + +final class OreSpawnGeologySampler implements GeologySampler { + private static final ResourceLocation CYANO_GEOME = new ResourceLocation("orespawn", "cyano"); + + private final ServerLevel level; + private final ResourceLocation dimension; + private final BakedGeomeConfig config; + private final GeologyMode mode; + private final GeomeGeology sky; + private final Geology cyano; + + private OreSpawnGeologySampler(ServerLevel level) { + this.level = level; + dimension = level.dimension().location(); + config = GeomeConfig.baked(level.dimension()); + WorldGeologyProfile profile = WorldGeologyProfileManager.activeProfile(); + mode = profile.geologyMode(); + if (mode == GeologyMode.LEGACY) { + cyano = new Geology(level.getSeed(), profile.cyanoGeomeSize(), profile.cyanoRockLayerNoise(), + profile.cyanoLayerThickness(), config); + sky = null; + } else { + sky = new GeomeGeology(level.getSeed(), config); + cyano = null; + } + } + + static GeologySampler create(ServerLevel level) { + if (level == null || WorldGeologyProfileManager.activeServer() != level.getServer()) { + throw new IllegalStateException("The level is not part of OreSpawn's active server"); + } + return new OreSpawnGeologySampler(level); + } + + @Override + public GeologyColumn sampleColumn(int blockX, int blockZ, int surfaceY) { + BlockPos position = new BlockPos(blockX, surfaceY, blockZ); + Holder holder = level.getBiome(position); + ResourceLocation biomeId = holder.unwrapKey().map(ResourceKey::location) + .orElse(new ResourceLocation("orespawn", "unregistered_biome")); + if (mode == GeologyMode.LEGACY) { + return new CyanoColumn(biomeId, blockX, blockZ, surfaceY); + } + GeomeGeology.ColumnSample sample = sky.sampleColumn(holder.value(), biomeId, blockX, blockZ); + return new SkyColumn(biomeId, blockX, blockZ, surfaceY, sample); + } + + private abstract class BaseColumn implements GeologyColumn { + private final ResourceLocation biome; + private final int x; + private final int z; + private final int surfaceY; + + BaseColumn(ResourceLocation biome, int x, int z, int surfaceY) { + this.biome = biome; + this.x = x; + this.z = z; + this.surfaceY = surfaceY; + } + + @Override public ResourceLocation dimension() { return dimension; } + @Override public ResourceLocation biome() { return biome; } + @Override public int blockX() { return x; } + @Override public int blockZ() { return z; } + @Override public int surfaceY() { return surfaceY; } + } + + private final class SkyColumn extends BaseColumn { + private final GeomeGeology.ColumnSample sample; + + SkyColumn(ResourceLocation biome, int x, int z, int surfaceY, GeomeGeology.ColumnSample sample) { + super(biome, x, z, surfaceY); + this.sample = sample; + } + + @Override public ResourceLocation geome() { return geomeId(sample.geomeName()); } + @Override public BlockState rockAt(int y) { return sample.rockAt(y); } + @Override public Optional familyAt(int y) { return family(sample.familyAt(y)); } + } + + private final class CyanoColumn extends BaseColumn { + CyanoColumn(ResourceLocation biome, int x, int z, int surfaceY) { + super(biome, x, z, surfaceY); + } + + @Override public ResourceLocation geome() { return CYANO_GEOME; } + @Override public BlockState rockAt(int y) { return cyano.getStoneAt(blockX(), y, blockZ()).defaultBlockState(); } + @Override public Optional familyAt(int y) { + Block block = rockAt(y).getBlock(); + for (RockFamily candidate : RockFamily.values()) { + for (BlockState state : config.statesForFamily(candidate)) { + if (state.getBlock() == block) { + return family(candidate); + } + } + } + return Optional.empty(); + } + } + + private static Optional family(RockFamily family) { + return family == null ? Optional.empty() + : Optional.of(GeologyFamily.valueOf(family.name())); + } + + private static ResourceLocation geomeId(String name) { + try { + return name.indexOf(':') >= 0 ? new ResourceLocation(name) + : new ResourceLocation("orespawn", name.toLowerCase(Locale.ROOT)); + } catch (RuntimeException ignored) { + return new ResourceLocation("orespawn", "unknown"); + } + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OreSpawnOreIntegration.java b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnOreIntegration.java new file mode 100644 index 00000000..ee2c93d6 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnOreIntegration.java @@ -0,0 +1,51 @@ +package com.mcmoddev.orespawn.api; + +import java.util.Set; + +import com.google.gson.JsonObject; +import com.mcmoddev.orespawn.integration.WorldgenIntegrationManager; + +/** + * Compatibility facade for the initial ore-provider status API. + * + * @deprecated Use {@link OreSpawnApi}. This class remains available so + * existing provider mods do not need an immediate source change. + */ +@Deprecated +public final class OreSpawnOreIntegration { + /** @deprecated Use {@link ProviderStatus}. */ + @Deprecated + public enum ProviderStatus { + PENDING, + ACTIVE, + INACTIVE + } + + private OreSpawnOreIntegration() { + } + + public static void initialize() { + WorldgenIntegrationManager.initialize(); + } + + public static ProviderStatus getProviderStatus(String providerModId) { + return ProviderStatus.valueOf(OreSpawnApi.getProviderStatus(providerModId).name()); + } + + public static boolean isProviderActive(String providerModId) { + return OreSpawnApi.isOreTakeoverActive(providerModId); + } + + public static void markFeatureReady() { + WorldgenIntegrationManager.markFeatureReady(); + } + + /** Merge all provider contributions while retaining the historical method name. */ + public static boolean mergeProviderOres(JsonObject target) { + return WorldgenIntegrationManager.mergeProviderDefinitions(target); + } + + public static Set activeProviderIds() { + return WorldgenIntegrationManager.activeProviderIds(); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/OreSpawnPatternRegistry.java b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnPatternRegistry.java new file mode 100644 index 00000000..c4c70634 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/OreSpawnPatternRegistry.java @@ -0,0 +1,25 @@ +package com.mcmoddev.orespawn.api; + +import java.util.function.Supplier; + +import com.mcmoddev.orespawn.OreSpawn; + +import net.minecraft.resources.ResourceLocation; +import net.minecraftforge.registries.IForgeRegistry; + +/** Stable entry point for mods that register codec-backed ore patterns. */ +public final class OreSpawnPatternRegistry { + public static final ResourceLocation REGISTRY_NAME = + new ResourceLocation(OreSpawn.MODID, "ore_pattern_types"); + + private OreSpawnPatternRegistry() { + } + + public static IForgeRegistry registry() { + return com.mcmoddev.orespawn.init.OreSpawnPatterns.registry(); + } + + public static Supplier> registrySupplier() { + return com.mcmoddev.orespawn.init.OreSpawnPatterns.registrySupplier(); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/ProviderStatus.java b/src/main/java/com/mcmoddev/orespawn/api/ProviderStatus.java new file mode 100644 index 00000000..108058aa --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/ProviderStatus.java @@ -0,0 +1,8 @@ +package com.mcmoddev.orespawn.api; + +/** Lifecycle state of a OreSpawn world-generation provider. */ +public enum ProviderStatus { + PENDING, + ACTIVE, + INACTIVE +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/StandardPatternSettings.java b/src/main/java/com/mcmoddev/orespawn/api/StandardPatternSettings.java new file mode 100644 index 00000000..6551520b --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/StandardPatternSettings.java @@ -0,0 +1,39 @@ +package com.mcmoddev.orespawn.api; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +/** Shared bounded settings understood by OreSpawn's six built-in patterns. */ +public final class StandardPatternSettings { + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.INT.optionalFieldOf("spread", 8).forGetter(StandardPatternSettings::spread), + Codec.INT.optionalFieldOf("vertical_spread", 4).forGetter(StandardPatternSettings::verticalSpread), + Codec.INT.optionalFieldOf("node_size", 4).forGetter(StandardPatternSettings::nodeSize), + Codec.INT.optionalFieldOf("length", 16).forGetter(StandardPatternSettings::length), + Codec.STRING.optionalFieldOf("fluid", "minecraft:water").forGetter(StandardPatternSettings::fluid)) + .apply(instance, StandardPatternSettings::new)); + + private final int spread; + private final int verticalSpread; + private final int nodeSize; + private final int length; + private final String fluid; + + public StandardPatternSettings(int spread, int verticalSpread, int nodeSize, int length, String fluid) { + this.spread = bounded(spread, 0, 64); + this.verticalSpread = bounded(verticalSpread, 0, 64); + this.nodeSize = bounded(nodeSize, 1, 32); + this.length = bounded(length, 1, 64); + this.fluid = fluid; + } + + public int spread() { return spread; } + public int verticalSpread() { return verticalSpread; } + public int nodeSize() { return nodeSize; } + public int length() { return length; } + public String fluid() { return fluid; } + + private static int bounded(int value, int min, int max) { + return Math.max(min, Math.min(max, value)); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/WorldgenProvider.java b/src/main/java/com/mcmoddev/orespawn/api/WorldgenProvider.java new file mode 100644 index 00000000..615c1ec7 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/WorldgenProvider.java @@ -0,0 +1,1006 @@ +package com.mcmoddev.orespawn.api; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.Consumer; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; + +import net.minecraft.resources.ResourceLocation; + +/** + * Immutable declarative world-generation contribution submitted to OreSpawn. + * All registry objects are represented by IDs and resolved only when OreSpawn + * freezes and bakes the active provider set. + */ +public final class WorldgenProvider { + private final String modId; + private final int revision; + private final JsonObject definition; + + private WorldgenProvider(String modId, int revision, JsonObject definition) { + this.modId = modId; + this.revision = revision; + this.definition = definition.deepCopy(); + } + + public static Builder builder(String modId, int revision) { + return new Builder(modId, revision); + } + + public String modId() { + return modId; + } + + public int revision() { + return revision; + } + + /** Returns a defensive JSON representation matching provider schema 2. */ + public JsonObject toJson() { + return definition.deepCopy(); + } + + public static final class Builder { + private final String modId; + private final int revision; + private final LinkedHashMap rocks = new LinkedHashMap<>(); + private final LinkedHashMap ores = new LinkedHashMap<>(); + private final LinkedHashMap geomes = new LinkedHashMap<>(); + private final LinkedHashMap biomeRules = new LinkedHashMap<>(); + private final LinkedHashMap terrainDimensions = + new LinkedHashMap<>(); + private final LinkedHashMap templates = new LinkedHashMap<>(); + + private Builder(String modId, int revision) { + this.modId = requireModId(modId); + if (revision < 1) { + throw new IllegalArgumentException("Provider revision must be at least 1"); + } + this.revision = revision; + } + + public Builder rock(RockDefinition rock) { + putUnique(rocks, rock.id(), rock, "rock"); + return this; + } + + public Builder rock(ResourceLocation block, GeologyFamily family, Consumer edit) { + RockDefinition.Builder builder = RockDefinition.builder(ownedId("rock", block), block, family); + edit.accept(builder); + return rock(builder.build()); + } + + public Builder rock(ResourceLocation id, ResourceLocation block, GeologyFamily family, + Consumer edit) { + RockDefinition.Builder builder = RockDefinition.builder(id, block, family); + edit.accept(builder); + return rock(builder.build()); + } + + public Builder ore(OreDefinition ore) { + putUnique(ores, ore.id(), ore, "ore"); + return this; + } + + public Builder ore(ResourceLocation block, Consumer edit) { + OreDefinition.Builder builder = OreDefinition.builder(ownedId("ore", block), block); + edit.accept(builder); + return ore(builder.build()); + } + + public Builder ore(ResourceLocation id, ResourceLocation block, + Consumer edit) { + OreDefinition.Builder builder = OreDefinition.builder(id, block); + edit.accept(builder); + return ore(builder.build()); + } + + public Builder geome(GeomeDefinition geome) { + putUnique(geomes, geome.id(), geome, "geome"); + return this; + } + + public Builder geome(ResourceLocation id, Consumer edit) { + GeomeDefinition.Builder builder = GeomeDefinition.builder(id); + edit.accept(builder); + return geome(builder.build()); + } + + public Builder biome(BiomeRule biome) { + putUnique(biomeRules, biome.biome(), biome, "biome rule"); + return this; + } + + public Builder biome(ResourceLocation biome, Map geomeWeights) { + return biome(new BiomeRule(biome, geomeWeights)); + } + + public Builder terrainDimension(TerrainDimensionDefinition dimension) { + putUnique(terrainDimensions, dimension.dimension(), dimension, "terrain dimension"); + return this; + } + + public Builder terrainDimension(ResourceLocation dimension, + Consumer edit) { + TerrainDimensionDefinition.Builder builder = TerrainDimensionDefinition.builder(dimension); + edit.accept(builder); + return terrainDimension(builder.build()); + } + + public Builder template(GeologyTemplate template) { + putUnique(templates, template.id(), template, "template"); + return this; + } + + public Builder template(ResourceLocation id, Consumer edit) { + GeologyTemplate.Builder builder = GeologyTemplate.builder(id); + edit.accept(builder); + return template(builder.build()); + } + + public WorldgenProvider build() { + if (rocks.isEmpty() && ores.isEmpty() && geomes.isEmpty() && biomeRules.isEmpty() + && terrainDimensions.isEmpty() && templates.isEmpty()) { + throw new IllegalStateException("A provider must declare at least one contribution"); + } + requireOwned(rocks.keySet(), "rock"); + requireOwned(ores.keySet(), "ore"); + requireOwned(geomes.keySet(), "geome"); + requireOwned(terrainDimensions.keySet(), "terrain dimension"); + requireOwned(templates.keySet(), "template"); + JsonObject root = new JsonObject(); + root.addProperty("schema_version", 2); + root.addProperty("provider_modid", modId); + root.addProperty("provider_revision", revision); + root.add("rocks", object(rocks)); + root.add("ores", object(ores)); + root.add("geomes", object(geomes)); + root.add("biome_rules", object(biomeRules)); + root.add("terrain_dimensions", object(terrainDimensions)); + root.add("templates", object(templates)); + return new WorldgenProvider(modId, revision, root); + } + + private void requireOwned(Collection ids, String type) { + for (ResourceLocation id : ids) { + if (!modId.equals(id.getNamespace())) { + throw new IllegalStateException("Provider " + modId + " does not own " + type + " " + id); + } + } + } + + private ResourceLocation ownedId(String kind, ResourceLocation output) { + return new ResourceLocation(modId, kind + "/" + output.getNamespace() + "/" + output.getPath()); + } + } + + public static final class RockDefinition implements JsonDefinition { + private final ResourceLocation id; + private final ResourceLocation block; + private final boolean enabled; + private final GeologyFamily family; + private final int depthPeak; + private final int depthSpread; + private final int minY; + private final int maxY; + private final double weight; + private final boolean oreReplaceable; + private final Map geomes; + private final Set dimensions; + + private RockDefinition(Builder builder) { + id = builder.id; + block = builder.block; + enabled = builder.enabled; + family = builder.family; + depthPeak = builder.depthPeak; + depthSpread = builder.depthSpread; + minY = builder.minY; + maxY = builder.maxY; + weight = builder.weight; + oreReplaceable = builder.oreReplaceable; + geomes = immutableMap(builder.geomes); + dimensions = immutableSet(builder.dimensions); + } + + public static Builder builder(ResourceLocation block, GeologyFamily family) { + return new Builder(block, block, family); + } + + public static Builder builder(ResourceLocation id, ResourceLocation block, GeologyFamily family) { + return new Builder(id, block, family); + } + + public ResourceLocation id() { return id; } + public ResourceLocation block() { return block; } + public boolean enabled() { return enabled; } + public GeologyFamily family() { return family; } + public int depthPeak() { return depthPeak; } + public int depthSpread() { return depthSpread; } + public int minY() { return minY; } + public int maxY() { return maxY; } + public double weight() { return weight; } + public boolean oreReplaceable() { return oreReplaceable; } + public Map geomes() { return geomes; } + public Set dimensions() { return dimensions; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("block", block.toString()); + json.addProperty("enabled", enabled); + json.addProperty("family", family.configName()); + json.addProperty("depth_peak", depthPeak); + json.addProperty("depth_spread", depthSpread); + json.addProperty("min_y", minY); + json.addProperty("max_y", maxY); + json.addProperty("weight", weight); + json.addProperty("ore_replaceable", oreReplaceable); + json.add("geomes", weights(geomes)); + json.add("dimensions", ids(dimensions)); + return json; + } + + public static final class Builder { + private final ResourceLocation id; + private final ResourceLocation block; + private final GeologyFamily family; + private boolean enabled = true; + private int depthPeak = 48; + private int depthSpread = 40; + private int minY = -64; + private int maxY = 319; + private double weight = 1.0D; + private boolean oreReplaceable = true; + private final Map geomes = new LinkedHashMap<>(); + private final Set dimensions = new LinkedHashSet<>(); + + private Builder(ResourceLocation id, ResourceLocation block, GeologyFamily family) { + this.id = Objects.requireNonNull(id, "id"); + this.block = Objects.requireNonNull(block, "block"); + this.family = Objects.requireNonNull(family, "family"); + dimensions.add(new ResourceLocation("minecraft", "overworld")); + } + + public Builder enabled(boolean value) { enabled = value; return this; } + public Builder depth(int peak, int spread) { depthPeak = peak; depthSpread = spread; return this; } + public Builder yRange(int min, int max) { minY = min; maxY = max; return this; } + public Builder weight(double value) { weight = value; return this; } + public Builder oreReplaceable(boolean value) { oreReplaceable = value; return this; } + public Builder geomeWeight(ResourceLocation geome, double value) { geomes.put(geome, value); return this; } + public Builder dimensions(Collection values) { dimensions.clear(); dimensions.addAll(values); return this; } + public Builder dimension(ResourceLocation value) { dimensions.add(value); return this; } + + public RockDefinition build() { + requireRange(minY, maxY, "rock Y range"); + if (depthSpread < 1 || weight < 0.0D || !Double.isFinite(weight) || dimensions.isEmpty()) { + throw new IllegalStateException("Invalid rock depth, weight, or dimensions for " + block); + } + return new RockDefinition(this); + } + } + } + + public static final class OreDefinition implements JsonDefinition { + private final ResourceLocation id; + private final ResourceLocation block; + private final boolean enabled; + private final boolean nativeGeneration; + private final ResourceLocation deepOutput; + private final int deepOutputMaxY; + private final List outputs; + private final boolean suppressVanilla; + private final boolean retrogen; + private final Map dimensions; + + private OreDefinition(Builder builder) { + id = builder.id; + block = builder.block; + enabled = builder.enabled; + nativeGeneration = builder.nativeGeneration; + deepOutput = builder.deepOutput; + deepOutputMaxY = builder.deepOutputMaxY; + outputs = Collections.unmodifiableList(new ArrayList<>(builder.outputs)); + suppressVanilla = builder.suppressVanilla; + retrogen = builder.retrogen; + dimensions = Collections.unmodifiableMap(new LinkedHashMap<>(builder.dimensions)); + } + + public static Builder builder(ResourceLocation block) { return new Builder(block, block); } + public static Builder builder(ResourceLocation id, ResourceLocation block) { return new Builder(id, block); } + public ResourceLocation id() { return id; } + public ResourceLocation block() { return block; } + public boolean enabled() { return enabled; } + public List outputs() { return outputs; } + public boolean suppressVanilla() { return suppressVanilla; } + public boolean retrogen() { return retrogen; } + public Map dimensions() { return dimensions; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("block", block.toString()); + json.addProperty("enabled", enabled); + json.addProperty("native_generation", nativeGeneration); + json.addProperty("suppress_vanilla", suppressVanilla); + json.addProperty("retrogen", retrogen); + if (!outputs.isEmpty()) { + JsonArray values = new JsonArray(); + for (OreOutputDefinition output : outputs) values.add(output.toJson()); + json.add("outputs", values); + } + if (deepOutput != null) { + json.addProperty("deep_output", deepOutput.toString()); + json.addProperty("deep_output_max_y", deepOutputMaxY); + } + json.add("dimensions", object(dimensions)); + return json; + } + + public static final class Builder { + private final ResourceLocation id; + private final ResourceLocation block; + private boolean enabled = true; + private boolean nativeGeneration; + private ResourceLocation deepOutput; + private int deepOutputMaxY = -1; + private final List outputs = new ArrayList<>(); + private boolean suppressVanilla; + private boolean retrogen = true; + private final LinkedHashMap dimensions = new LinkedHashMap<>(); + + private Builder(ResourceLocation id, ResourceLocation block) { + this.id = Objects.requireNonNull(id, "id"); + this.block = Objects.requireNonNull(block, "block"); + } + public Builder enabled(boolean value) { enabled = value; return this; } + public Builder nativeGeneration(boolean value) { nativeGeneration = value; return this; } + public Builder suppressVanilla(boolean value) { suppressVanilla = value; return this; } + public Builder retrogen(boolean value) { retrogen = value; return this; } + public Builder deepOutput(ResourceLocation value, int maxY) { deepOutput = value; deepOutputMaxY = maxY; return this; } + public Builder output(ResourceLocation value, double weight) { + return output(value, weight, -2048, 2048); + } + public Builder output(ResourceLocation value, double weight, int minY, int maxY) { + outputs.add(new OreOutputDefinition(value, weight, minY, maxY)); + return this; + } + public Builder dimension(OreDimensionDefinition value) { + putUnique(dimensions, value.dimension(), value, "ore dimension"); + return this; + } + public Builder dimension(ResourceLocation id, Consumer edit) { + OreDimensionDefinition.Builder builder = OreDimensionDefinition.builder(id); + edit.accept(builder); + return dimension(builder.build()); + } + + public OreDefinition build() { + if (dimensions.isEmpty()) { + throw new IllegalStateException("Ore has no dimensions: " + block); + } + return new OreDefinition(this); + } + } + } + + /** One weighted output choice for an ore rule, optionally restricted by Y. */ + public static final class OreOutputDefinition implements JsonDefinition { + private final ResourceLocation block; + private final double weight; + private final int minY; + private final int maxY; + + private OreOutputDefinition(ResourceLocation block, double weight, int minY, int maxY) { + this.block = Objects.requireNonNull(block, "block"); + if (!Double.isFinite(weight) || weight <= 0.0D) { + throw new IllegalArgumentException("Output weight must be positive for " + block); + } + requireRange(minY, maxY, "output Y range"); + this.weight = weight; + this.minY = minY; + this.maxY = maxY; + } + + public ResourceLocation block() { return block; } + public double weight() { return weight; } + public int minY() { return minY; } + public int maxY() { return maxY; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("block", block.toString()); + json.addProperty("weight", weight); + json.addProperty("min_y", minY); + json.addProperty("max_y", maxY); + return json; + } + } + + public static final class OreDimensionDefinition implements JsonDefinition { + private final ResourceLocation dimension; + private final boolean enabled; + private final int minY; + private final int maxY; + private final double frequency; + private final int quantity; + private final OrePattern pattern; + private final ResourceLocation patternType; + private final JsonObject patternSettings; + private final OreHeightDistribution heightDistribution; + private final int spread; + private final int verticalSpread; + private final int nodeSize; + private final Set hostFamilies; + private final Map geomes; + private final Set hostBlocks; + private final Set hostTags; + private final Map hostBlockWeights; + private final Map hostTagWeights; + + private OreDimensionDefinition(Builder builder) { + dimension = builder.dimension; + enabled = builder.enabled; + minY = builder.minY; + maxY = builder.maxY; + frequency = builder.frequency; + quantity = builder.quantity; + pattern = builder.pattern; + patternType = builder.patternType; + patternSettings = builder.patternSettings.deepCopy(); + heightDistribution = builder.heightDistribution; + spread = builder.spread; + verticalSpread = builder.verticalSpread; + nodeSize = builder.nodeSize; + hostFamilies = Collections.unmodifiableSet(new LinkedHashSet<>(builder.hostFamilies)); + geomes = immutableMap(builder.geomes); + hostBlocks = immutableSet(builder.hostBlocks); + hostTags = immutableSet(builder.hostTags); + hostBlockWeights = immutableMap(builder.hostBlockWeights); + hostTagWeights = immutableMap(builder.hostTagWeights); + } + + public static Builder builder(ResourceLocation dimension) { return new Builder(dimension); } + public ResourceLocation dimension() { return dimension; } + public boolean enabled() { return enabled; } + public int minY() { return minY; } + public int maxY() { return maxY; } + public double attempts() { return frequency; } + public int quantity() { return quantity; } + public OrePattern pattern() { return pattern; } + public ResourceLocation patternType() { return patternType; } + public JsonObject patternSettings() { return patternSettings.deepCopy(); } + public OreHeightDistribution heightDistribution() { return heightDistribution; } + public int spread() { return spread; } + public int verticalSpread() { return verticalSpread; } + public int nodeSize() { return nodeSize; } + public Set hostFamilies() { return hostFamilies; } + public Map geomes() { return geomes; } + public Set hostBlocks() { return hostBlocks; } + public Set hostTags() { return hostTags; } + public Map hostBlockWeights() { return hostBlockWeights; } + public Map hostTagWeights() { return hostTagWeights; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("enabled", enabled); + json.addProperty("min_y", minY); + json.addProperty("max_y", maxY); + json.addProperty("frequency", frequency); + json.addProperty("quantity", quantity); + if (patternType == null) { + json.addProperty("pattern", pattern.configName()); + } else { + JsonObject configuredPattern = new JsonObject(); + configuredPattern.addProperty("type", patternType.toString()); + configuredPattern.add("settings", patternSettings.deepCopy()); + json.add("pattern", configuredPattern); + } + json.addProperty("height_distribution", heightDistribution.configName()); + json.addProperty("spread", spread); + json.addProperty("vertical_spread", verticalSpread); + json.addProperty("node_size", nodeSize); + JsonArray families = new JsonArray(); + for (GeologyFamily family : hostFamilies) { families.add(family.configName()); } + json.add("host_families", families); + json.add("geomes", weights(geomes)); + json.add("host_blocks", weightedIds(hostBlocks, hostBlockWeights, "block")); + json.add("host_tags", weightedIds(hostTags, hostTagWeights, "tag")); + return json; + } + + public static final class Builder { + private final ResourceLocation dimension; + private boolean enabled = true; + private int minY = -64; + private int maxY = 319; + private double frequency = 1.0D; + private int quantity = 8; + private OrePattern pattern = OrePattern.VEIN; + private ResourceLocation patternType; + private JsonObject patternSettings = new JsonObject(); + private OreHeightDistribution heightDistribution = OreHeightDistribution.UNIFORM; + private int spread = 8; + private int verticalSpread = 4; + private int nodeSize = 4; + private final Set hostFamilies = new LinkedHashSet<>(); + private final Map geomes = new LinkedHashMap<>(); + private final Set hostBlocks = new LinkedHashSet<>(); + private final Set hostTags = new LinkedHashSet<>(); + private final Map hostBlockWeights = new LinkedHashMap<>(); + private final Map hostTagWeights = new LinkedHashMap<>(); + + private Builder(ResourceLocation dimension) { this.dimension = Objects.requireNonNull(dimension, "dimension"); } + public Builder enabled(boolean value) { enabled = value; return this; } + public Builder yRange(int min, int max) { minY = min; maxY = max; return this; } + public Builder attempts(double value) { frequency = value; return this; } + public Builder quantity(int value) { quantity = value; return this; } + public Builder pattern(OrePattern value) { + pattern = Objects.requireNonNull(value); + patternType = null; + patternSettings = new JsonObject(); + return this; + } + /** Uses a codec-backed pattern registered through {@link OreSpawnPatternRegistry}. */ + public Builder pattern(ResourceLocation type, JsonObject settings) { + patternType = Objects.requireNonNull(type, "type"); + patternSettings = Objects.requireNonNull(settings, "settings").deepCopy(); + return this; + } + public Builder heightDistribution(OreHeightDistribution value) { heightDistribution = Objects.requireNonNull(value); return this; } + public Builder spread(int horizontal, int vertical) { spread = horizontal; verticalSpread = vertical; return this; } + public Builder nodeSize(int value) { nodeSize = value; return this; } + public Builder hostFamily(GeologyFamily value) { hostFamilies.add(value); return this; } + public Builder geomeWeight(ResourceLocation geome, double value) { geomes.put(geome, value); return this; } + public Builder hostBlock(ResourceLocation value) { hostBlocks.add(value); return this; } + public Builder hostTag(ResourceLocation value) { hostTags.add(value); return this; } + public Builder hostBlock(ResourceLocation value, double weight) { + hostBlocks.add(value); + hostBlockWeights.put(value, replacementWeight(weight)); + return this; + } + public Builder hostTag(ResourceLocation value, double weight) { + hostTags.add(value); + hostTagWeights.put(value, replacementWeight(weight)); + return this; + } + + public OreDimensionDefinition build() { + requireRange(minY, maxY, "ore Y range"); + if (frequency < 0.0D || frequency > 64.0D || quantity < 1 || quantity > 64 + || spread < 0 || spread > 64 || verticalSpread < 0 || verticalSpread > 64 + || nodeSize < 1 || nodeSize > 32) { + throw new IllegalStateException("Invalid ore placement values for " + dimension); + } + if (enabled && hostFamilies.isEmpty() && hostBlocks.isEmpty() && hostTags.isEmpty()) { + throw new IllegalStateException("Enabled ore dimension has no hosts: " + dimension); + } + return new OreDimensionDefinition(this); + } + } + } + + public static final class GeomeDefinition implements JsonDefinition { + private final ResourceLocation id; + private final double baseWeight; + private final Map familyWeights; + + private GeomeDefinition(Builder builder) { + id = builder.id; + baseWeight = builder.baseWeight; + familyWeights = Collections.unmodifiableMap(new LinkedHashMap<>(builder.familyWeights)); + } + + public static Builder builder(ResourceLocation id) { return new Builder(id); } + public ResourceLocation id() { return id; } + public double baseWeight() { return baseWeight; } + public Map familyWeights() { return familyWeights; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("base", baseWeight); + for (GeologyFamily family : GeologyFamily.values()) { + json.addProperty(family.configName(), familyWeights.getOrDefault(family, 1.0D)); + } + return json; + } + + public static final class Builder { + private final ResourceLocation id; + private double baseWeight = 1.0D; + private final Map familyWeights = new LinkedHashMap<>(); + private Builder(ResourceLocation id) { this.id = Objects.requireNonNull(id, "id"); } + public Builder baseWeight(double value) { baseWeight = value; return this; } + public Builder familyWeight(GeologyFamily family, double value) { familyWeights.put(family, value); return this; } + public GeomeDefinition build() { + if (!Double.isFinite(baseWeight) || baseWeight < 0.0D) { + throw new IllegalStateException("Invalid geome base weight for " + id); + } + return new GeomeDefinition(this); + } + } + } + + public static final class BiomeRule implements JsonDefinition { + private final ResourceLocation biome; + private final Map geomeWeights; + public BiomeRule(ResourceLocation biome, Map geomeWeights) { + this.biome = Objects.requireNonNull(biome, "biome"); + this.geomeWeights = immutableMap(geomeWeights); + } + public ResourceLocation biome() { return biome; } + public Map geomeWeights() { return geomeWeights; } + @Override public JsonObject toJson() { return weights(geomeWeights); } + } + + public static final class TerrainDimensionDefinition implements JsonDefinition { + private final ResourceLocation dimension; + private final boolean enabled; + private final Set biomeIds; + private final Set biomeNamespaces; + private final Set hostBlocks; + private final Set hostTags; + + private TerrainDimensionDefinition(Builder builder) { + dimension = builder.dimension; + enabled = builder.enabled; + biomeIds = immutableSet(builder.biomeIds); + biomeNamespaces = Collections.unmodifiableSet(new LinkedHashSet<>(builder.biomeNamespaces)); + hostBlocks = immutableSet(builder.hostBlocks); + hostTags = immutableSet(builder.hostTags); + } + + public static Builder builder(ResourceLocation id) { return new Builder(id); } + public ResourceLocation dimension() { return dimension; } + public boolean enabled() { return enabled; } + public Set biomeIds() { return biomeIds; } + public Set biomeNamespaces() { return biomeNamespaces; } + public Set hostBlocks() { return hostBlocks; } + public Set hostTags() { return hostTags; } + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("enabled", enabled); + json.add("biome_ids", ids(biomeIds)); + JsonArray namespaces = new JsonArray(); + for (String namespace : biomeNamespaces) { namespaces.add(namespace); } + json.add("biome_namespaces", namespaces); + json.add("host_blocks", ids(hostBlocks)); + json.add("host_tags", ids(hostTags)); + return json; + } + + public static final class Builder { + private final ResourceLocation dimension; + private boolean enabled = true; + private final Set biomeIds = new LinkedHashSet<>(); + private final Set biomeNamespaces = new LinkedHashSet<>(); + private final Set hostBlocks = new LinkedHashSet<>(); + private final Set hostTags = new LinkedHashSet<>(); + private Builder(ResourceLocation id) { dimension = Objects.requireNonNull(id, "dimension"); } + public Builder enabled(boolean value) { enabled = value; return this; } + public Builder biome(ResourceLocation value) { biomeIds.add(value); return this; } + public Builder biomeNamespace(String value) { biomeNamespaces.add(requireModId(value)); return this; } + public Builder hostBlock(ResourceLocation value) { hostBlocks.add(value); return this; } + public Builder hostTag(ResourceLocation value) { hostTags.add(value); return this; } + public TerrainDimensionDefinition build() { + if (enabled && hostBlocks.isEmpty() && hostTags.isEmpty()) { + throw new IllegalStateException("Enabled terrain dimension has no replacement hosts: " + dimension); + } + return new TerrainDimensionDefinition(this); + } + } + } + + public static final class FormationDefinition implements JsonDefinition { + private final GeologyAlgorithm algorithm; + private final FormationPreset horizontal; + private final FormationPreset thickness; + private final FormationPreset waviness; + private final FormationPreset edge; + private final FormationPreset continuity; + private final JsonObject custom; + + public FormationDefinition(GeologyAlgorithm algorithm, FormationPreset horizontal, + FormationPreset thickness, FormationPreset waviness, FormationPreset edge, + FormationPreset continuity, JsonObject custom) { + this.algorithm = Objects.requireNonNull(algorithm); + this.horizontal = Objects.requireNonNull(horizontal); + this.thickness = Objects.requireNonNull(thickness); + this.waviness = Objects.requireNonNull(waviness); + this.edge = Objects.requireNonNull(edge); + this.continuity = Objects.requireNonNull(continuity); + this.custom = custom == null ? new JsonObject() : custom.deepCopy(); + } + + public static Builder builder() { return new Builder(); } + + public GeologyAlgorithm algorithm() { return algorithm; } + public FormationPreset horizontalSize() { return horizontal; } + public FormationPreset verticalThickness() { return thickness; } + public FormationPreset waviness() { return waviness; } + public FormationPreset edgeIrregularity() { return edge; } + public FormationPreset continuity() { return continuity; } + public JsonObject customValues() { return custom.deepCopy(); } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("algorithm", algorithm.configName()); + json.addProperty("horizontal_size", horizontal.configName()); + json.addProperty("vertical_thickness", thickness.configName()); + json.addProperty("waviness", waviness.configName()); + json.addProperty("edge_irregularity", edge.configName()); + json.addProperty("formation_continuity", continuity.configName()); + json.add("custom", custom.deepCopy()); + return json; + } + + public static final class Builder { + private GeologyAlgorithm algorithm = GeologyAlgorithm.STABLE_LAYERS; + private FormationPreset horizontal = FormationPreset.AVERAGE; + private FormationPreset thickness = FormationPreset.AVERAGE; + private FormationPreset waviness = FormationPreset.AVERAGE; + private FormationPreset edge = FormationPreset.AVERAGE; + private FormationPreset continuity = FormationPreset.AVERAGE; + private final JsonObject custom = new JsonObject(); + + private Builder() { } + public Builder algorithm(GeologyAlgorithm value) { algorithm = Objects.requireNonNull(value); return this; } + public Builder horizontalSize(FormationPreset value) { horizontal = Objects.requireNonNull(value); return this; } + public Builder verticalThickness(FormationPreset value) { thickness = Objects.requireNonNull(value); return this; } + public Builder waviness(FormationPreset value) { waviness = Objects.requireNonNull(value); return this; } + public Builder edgeIrregularity(FormationPreset value) { edge = Objects.requireNonNull(value); return this; } + public Builder continuity(FormationPreset value) { continuity = Objects.requireNonNull(value); return this; } + public Builder customValue(String key, double value) { + if (key == null || key.trim().isEmpty() || !Double.isFinite(value)) { + throw new IllegalArgumentException("Invalid custom formation value"); + } + custom.addProperty(key, value); + return this; + } + public Builder customValues(JsonObject values) { + custom.entrySet().clear(); + if (values != null) { + values.entrySet().forEach(entry -> custom.add(entry.getKey(), entry.getValue().deepCopy())); + } + return this; + } + public FormationDefinition build() { + return new FormationDefinition(algorithm, horizontal, thickness, waviness, edge, continuity, custom); + } + } + } + + public static final class OilDefinition implements JsonDefinition { + private final int minY; + private final int maxY; + private final double frequency; + private final int minRadius; + private final int maxRadius; + private final int minVerticalRadius; + private final int maxVerticalRadius; + private final int maxLobes; + private final int minSolidCover; + + public OilDefinition(int minY, int maxY, double frequency, int minRadius, int maxRadius, + int minVerticalRadius, int maxVerticalRadius, int maxLobes, int minSolidCover) { + requireRange(minY, maxY, "oil Y range"); + if (!Double.isFinite(frequency) || frequency < 0.0D || frequency > 64.0D + || minRadius < 1 || minRadius > maxRadius + || minVerticalRadius < 1 || minVerticalRadius > maxVerticalRadius + || maxLobes < 1 || minSolidCover < 0) { + throw new IllegalArgumentException("Invalid oil placement values"); + } + this.minY = minY; + this.maxY = maxY; + this.frequency = frequency; + this.minRadius = minRadius; + this.maxRadius = maxRadius; + this.minVerticalRadius = minVerticalRadius; + this.maxVerticalRadius = maxVerticalRadius; + this.maxLobes = maxLobes; + this.minSolidCover = minSolidCover; + } + + public static Builder builder() { return new Builder(); } + + public int minY() { return minY; } + public int maxY() { return maxY; } + public double frequency() { return frequency; } + public int minRadius() { return minRadius; } + public int maxRadius() { return maxRadius; } + public int minVerticalRadius() { return minVerticalRadius; } + public int maxVerticalRadius() { return maxVerticalRadius; } + public int maxLobes() { return maxLobes; } + public int minSolidCover() { return minSolidCover; } + + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("min_y", minY); + json.addProperty("max_y", maxY); + json.addProperty("frequency", frequency); + json.addProperty("min_radius", minRadius); + json.addProperty("max_radius", maxRadius); + json.addProperty("min_vertical_radius", minVerticalRadius); + json.addProperty("max_vertical_radius", maxVerticalRadius); + json.addProperty("max_lobes", maxLobes); + json.addProperty("min_solid_cover", minSolidCover); + return json; + } + + public static final class Builder { + private int minY = -48; + private int maxY = 40; + private double frequency = 0.035D; + private int minRadius = 8; + private int maxRadius = 16; + private int minVerticalRadius = 3; + private int maxVerticalRadius = 7; + private int maxLobes = 4; + private int minSolidCover = 2; + + private Builder() { } + public Builder yRange(int min, int max) { minY = min; maxY = max; return this; } + public Builder attempts(double value) { frequency = value; return this; } + public Builder radius(int min, int max) { minRadius = min; maxRadius = max; return this; } + public Builder verticalRadius(int min, int max) { minVerticalRadius = min; maxVerticalRadius = max; return this; } + public Builder maxLobes(int value) { maxLobes = value; return this; } + public Builder minSolidCover(int value) { minSolidCover = value; return this; } + public OilDefinition build() { + return new OilDefinition(minY, maxY, frequency, minRadius, maxRadius, + minVerticalRadius, maxVerticalRadius, maxLobes, minSolidCover); + } + } + } + + public static final class GeologyTemplate implements JsonDefinition { + private final ResourceLocation id; + private final String nameKey; + private final String descriptionKey; + private final Set requiredMods; + private final JsonObject profile; + + private GeologyTemplate(Builder builder) { + id = builder.id; + nameKey = builder.nameKey; + descriptionKey = builder.descriptionKey; + requiredMods = Collections.unmodifiableSet(new LinkedHashSet<>(builder.requiredMods)); + profile = builder.profile.deepCopy(); + } + + public static Builder builder(ResourceLocation id) { return new Builder(id); } + public ResourceLocation id() { return id; } + public String nameKey() { return nameKey; } + public String descriptionKey() { return descriptionKey; } + public Set requiredMods() { return requiredMods; } + public JsonObject profile() { return profile.deepCopy(); } + @Override + public JsonObject toJson() { + JsonObject json = new JsonObject(); + json.addProperty("name_key", nameKey); + json.addProperty("description_key", descriptionKey); + JsonArray mods = new JsonArray(); + for (String mod : requiredMods) { mods.add(mod); } + json.add("required_mods", mods); + json.add("profile", profile.deepCopy()); + return json; + } + + public static final class Builder { + private final ResourceLocation id; + private String nameKey; + private String descriptionKey; + private final Set requiredMods = new LinkedHashSet<>(); + private final JsonObject profile = new JsonObject(); + private Builder(ResourceLocation id) { + this.id = Objects.requireNonNull(id, "id"); + nameKey = "orespawn.template." + id.getNamespace() + "." + id.getPath(); + descriptionKey = nameKey + ".description"; + } + public Builder translationKeys(String name, String description) { nameKey = name; descriptionKey = description; return this; } + public Builder requiresMod(String value) { requiredMods.add(requireModId(value)); return this; } + public Builder profile(JsonObject value) { profile.entrySet().clear(); value.entrySet().forEach(e -> profile.add(e.getKey(), e.getValue().deepCopy())); return this; } + public Builder formations(FormationDefinition value) { profile.add("formations", value.toJson()); return this; } + public Builder oil(OilDefinition value) { profile.add("oil", value.toJson()); profile.addProperty("place_crude_oil", true); return this; } + public Builder geologyMode(String value) { profile.addProperty("geology_mode", value); return this; } + public Builder manageVanillaOres(boolean value) { profile.addProperty("manage_vanilla_ores", value); return this; } + public GeologyTemplate build() { + if (profile.entrySet().isEmpty()) { throw new IllegalStateException("Template profile is empty: " + id); } + return new GeologyTemplate(this); + } + } + } + + private interface JsonDefinition { + JsonObject toJson(); + } + + private static JsonObject object(Map values) { + JsonObject json = new JsonObject(); + for (Map.Entry entry : values.entrySet()) { + json.add(entry.getKey().toString(), entry.getValue().toJson()); + } + return json; + } + + private static JsonObject weights(Map values) { + JsonObject json = new JsonObject(); + for (Map.Entry entry : values.entrySet()) { + json.addProperty(entry.getKey().toString(), entry.getValue()); + } + return json; + } + + private static JsonArray ids(Collection values) { + JsonArray json = new JsonArray(); + for (ResourceLocation value : values) { json.add(value.toString()); } + return json; + } + + private static JsonArray weightedIds(Collection values, + Map weights, String idKey) { + JsonArray json = new JsonArray(); + for (ResourceLocation value : values) { + Double weight = weights.get(value); + if (weight == null || weight.doubleValue() == 1.0D) { + json.add(value.toString()); + } else { + JsonObject entry = new JsonObject(); + entry.addProperty(idKey, value.toString()); + entry.addProperty("weight", weight); + json.add(entry); + } + } + return json; + } + + private static double replacementWeight(double value) { + if (!Double.isFinite(value) || value < 0.0D || value > 1.0D) { + throw new IllegalArgumentException("Replacement weight must be between 0 and 1: " + value); + } + return value; + } + + private static void putUnique(Map values, K key, V value, String type) { + if (values.putIfAbsent(key, value) != null) { + throw new IllegalArgumentException("Duplicate " + type + ": " + key); + } + } + + private static String requireModId(String value) { + Objects.requireNonNull(value, "modId"); + ResourceLocation probe = new ResourceLocation(value, "provider"); + if (!probe.getNamespace().equals(value)) { + throw new IllegalArgumentException("Invalid mod ID: " + value); + } + return value; + } + + private static void requireRange(int min, int max, String name) { + if (min < -2048 || max > 2048 || min > max) { + throw new IllegalArgumentException("Invalid " + name + ": " + min + ".." + max); + } + } + + private static Map immutableMap(Map values) { + return Collections.unmodifiableMap(new LinkedHashMap<>(values)); + } + + private static Set immutableSet(Set values) { + return Collections.unmodifiableSet(new LinkedHashSet<>(values)); + } +} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java deleted file mode 100755 index 01929897..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadStateValueException.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -public class BadStateValueException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 3826628238012469423L; - - public BadStateValueException(String msg) { - super(msg); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java deleted file mode 100644 index a71123f9..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/BadValueException.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -import java.util.Locale; - -public class BadValueException extends Exception { - - private static final long serialVersionUID = 1143938140559149506L; - private final String keyName; - private final String keyValue; - - public BadValueException(final String keyName, final String keyValue) { - super(); - this.keyName = keyName; - this.keyValue = keyValue; - } - - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format(Locale.ENGLISH, "Unknown value %s for key %s%n%s", this.keyValue, this.keyName, - baseMessage); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java deleted file mode 100644 index 8c98fffa..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/MissingVersionException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -public class MissingVersionException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -4306852267351590384L; - -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java deleted file mode 100644 index 2f31a433..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/NotAProperConfigException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -public class NotAProperConfigException extends Exception { - - /** - * - */ - private static final long serialVersionUID = -7748241590958198482L; - -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java deleted file mode 100644 index 62b5fa71..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/OldVersionException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -public class OldVersionException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 3760017140789193369L; - -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java deleted file mode 100644 index e6008d1e..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownFieldException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -import java.util.Locale; - -public class UnknownFieldException extends Exception { - - private static final long serialVersionUID = 1L; - private final String message; - - public UnknownFieldException(final String theField) { - super(); - this.message = String.format(Locale.ENGLISH, "Unkown field %s in config", theField); - } - - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format(Locale.ENGLISH, "%s%n%s", this.message, baseMessage); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java deleted file mode 100644 index 94bf09af..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownNameException.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -import java.util.Locale; - -public class UnknownNameException extends Exception { - - private static final long serialVersionUID = -3426121906665390773L; - private final String fieldName; - private final String fieldValue; - - public UnknownNameException(final String fieldName, final String fieldValue) { - super(); - this.fieldName = fieldName; - this.fieldValue = fieldValue; - } - - @Override - public String getMessage() { - final String baseMessage = super.getMessage(); - return String.format(Locale.ENGLISH, "Unknown %s name %s%n%s", this.fieldName, this.fieldValue, - baseMessage); - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java b/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java deleted file mode 100644 index fa369ca9..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/exceptions/UnknownVersionException.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.mcmoddev.orespawn.api.exceptions; - -public class UnknownVersionException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 3817238409227005355L; - -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java deleted file mode 100644 index 1bda5db5..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBiomeBuilder.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.mcmoddev.orespawn.api.BiomeLocation; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.biome.Biome; - -public interface IBiomeBuilder { - - IBiomeBuilder addWhitelistEntry(Biome biome); - - IBiomeBuilder addWhitelistEntry(String biomeName); - - IBiomeBuilder addWhitelistEntry(ResourceLocation biomeResourceLocation); - - IBiomeBuilder addBlacklistEntry(Biome biome); - - IBiomeBuilder addBlacklistEntry(String biomeName); - - IBiomeBuilder addBlacklistEntry(ResourceLocation biomeResourceLocation); - - IBiomeBuilder setAcceptAll(); - - BiomeLocation create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java deleted file mode 100644 index 54baec34..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockBuilder.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.ResourceLocation; - -public interface IBlockBuilder { - - /** - * - * @param blockState - * @return - */ - IBlockBuilder setFromBlockState(IBlockState blockState); - - /** - * - * @param block - * @return - */ - IBlockBuilder setFromBlock(Block block); - - /** - * - * @param blockName - * @return - */ - IBlockBuilder setFromName(String blockName); - - /** - * - * @param blockName - * @param state - * @return - */ - IBlockBuilder setFromName(String blockName, String state); - - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(String blockName, int metadata); - - /** - * - * @param blockResourceLocation - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation); - - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, String state); - - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromName(ResourceLocation blockResourceLocation, int metadata); - - /** - * - * @param blockState - * @param chance - * @return - */ - IBlockBuilder setFromBlockStateWithChance(IBlockState blockState, int chance); - - /** - * - * @param block - * @param chance - * @return - */ - IBlockBuilder setFromBlockWithChance(Block block, int chance); - - /** - * - * @param blockName - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, int chance); - - /** - * - * @param blockName - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(String blockName, String state, int chance); - - /** - * - * @param blockName - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(String blockName, int metadata, int chance); - - /** - * - * @param blockResourceLocation - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int chance); - - /** - * - * @param blockResourceLocation - * @param state - * @param chance - * @return - */ - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, String state, - int chance); - - /** - * - * @param blockResourceLocation - * @param metadata - * @param chance - * @return - * @deprecated - */ - @Deprecated - IBlockBuilder setFromNameWithChance(ResourceLocation blockResourceLocation, int metadata, - int chance); - - /** - * - * @param chance - * @return - */ - IBlockBuilder setChance(int chance); - - /** - * - * @return - */ - IBlockDefinition create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java deleted file mode 100644 index 03bec55b..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IBlockDefinition.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import net.minecraft.block.state.IBlockState; - -public interface IBlockDefinition { - - IBlockState getBlock(); - - int getChance(); - - default boolean isValid() { - return true; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java deleted file mode 100644 index 1fe97bb7..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IDimensionBuilder.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.mcmoddev.orespawn.api.IDimensionList; - -public interface IDimensionBuilder { - - IDimensionBuilder addWhitelistEntry(int dimensionID); - - IDimensionBuilder addBlacklistEntry(int dimensionID); - - IDimensionBuilder setAcceptAll(); - - IDimensionBuilder setDenyAll(); - - IDimensionBuilder setAcceptAllOverworld(); - - IDimensionList create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java deleted file mode 100644 index 20fefa25..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.google.gson.JsonElement; -import com.mcmoddev.orespawn.api.IFeature; - -import net.minecraft.util.ResourceLocation; - -public interface IFeatureBuilder { - - IFeatureBuilder setFeature(String featureName); - - IFeatureBuilder setFeature(ResourceLocation featureResourceLocation); - - IFeatureBuilder setFeature(IFeature feature); - - IFeatureBuilder setParameter(String parameterName, String parameterValue); - - IFeatureBuilder setParameter(String parameterName, int parameterValue); - - IFeatureBuilder setParameter(String parameterName, float parameterValue); - - IFeatureBuilder setParameter(String parameterName, boolean parameterValue); - - IFeatureBuilder setParameter(String parameterName, JsonElement parameterValue); - - IFeatureBuilder setUseFeatureDefaults(); - - IFeatureEntry create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java deleted file mode 100644 index 6f5fb06b..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IFeatureEntry.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.api.IFeature; - -public interface IFeatureEntry { - - IFeature getFeature(); - - String getFeatureName(); - - JsonObject getFeatureParameters(); - - void setParameter(String parameterName, String parameterValue); - - void setParameter(String parameterName, int parameterValue); - - void setParameter(String parameterName, boolean parameterValue); - - void setParameter(String parameterName, float parameterValue); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java deleted file mode 100644 index ecf91e74..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementBuilder.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.ResourceLocation; - -public interface IReplacementBuilder { - - /** - * - * @param entryName - * @return - */ - IReplacementBuilder setFromName(String entryName); - - /** - * - * @param name - * @return - */ - IReplacementBuilder setName(String name); - - /** - * - * @param blockState - * @return - */ - IReplacementBuilder addEntry(IBlockState blockState); - - /** - * - * @param blockName - * @return - */ - IReplacementBuilder addEntry(String blockName); - - /** - * - * @param blockName - * @param state - * @return - */ - IReplacementBuilder addEntry(String blockName, String state); - - /** - * - * @param blockName - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(String blockName, int metadata); - - /** - * - * @param blockResourceLocation - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation); - - /** - * - * @param blockResourceLocation - * @param state - * @return - */ - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, String state); - - /** - * - * @param blockResourceLocation - * @param metadata - * @return - * @deprecated - */ - @Deprecated - IReplacementBuilder addEntry(ResourceLocation blockResourceLocation, int metadata); - - boolean hasEntries(); - - IReplacementEntry create(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java deleted file mode 100644 index e9f03f91..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/IReplacementEntry.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import java.util.List; - -import net.minecraft.block.state.IBlockState; -import net.minecraftforge.registries.IForgeRegistryEntry; - -public interface IReplacementEntry extends IForgeRegistryEntry { - - OreSpawnBlockMatcher getMatcher(); - - List getEntries(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java deleted file mode 100644 index 3808d61a..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.IDimensionList; - -import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.ResourceLocation; - -public interface ISpawnBuilder { - - ISpawnBuilder setName(String name); - - ISpawnBuilder setDimensions(IDimensionList dimensions); - - ISpawnBuilder setBiomes(BiomeLocation biomes); - - ISpawnBuilder setEnabled(boolean enabled); - - ISpawnBuilder setRetrogen(boolean retrogen); - - ISpawnBuilder setReplacement(IReplacementEntry replacements); - - ISpawnBuilder setFeature(IFeatureEntry feature); - - ISpawnBuilder addBlock(String blockName); - - ISpawnBuilder addBlock(String blockName, String blockState); - - ISpawnBuilder addBlock(String blockName, int blockMetadata); - - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation); - - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, String blockState); - - ISpawnBuilder addBlock(ResourceLocation blockResourceLocation, int blockMetadata); - - ISpawnBuilder addBlock(Block block); - - ISpawnBuilder addBlock(IBlockState block); - - ISpawnBuilder addBlockWithChance(String blockName, int chance); - - ISpawnBuilder addBlockWithChance(String blockName, String blockState, int chance); - - ISpawnBuilder addBlockWithChance(String blockName, int blockMetadata, int chance); - - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int chance); - - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, String blockState, - int chance); - - ISpawnBuilder addBlockWithChance(ResourceLocation blockResourceLocation, int blockMetadata, - int chance); - - ISpawnBuilder addBlockWithChance(Block block, int chance); - - ISpawnBuilder addBlockWithChance(IBlockState block, int chance); - - ISpawnEntry create(); - - ISpawnBuilder addBlock(IBlockDefinition block); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java b/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java deleted file mode 100644 index 7fdaceb4..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/ISpawnEntry.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import java.util.Random; - -import com.mcmoddev.orespawn.api.BiomeLocation; -import com.mcmoddev.orespawn.api.IBlockList; -import com.mcmoddev.orespawn.api.IDimensionList; - -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; -import net.minecraft.world.chunk.IChunkProvider; -import net.minecraft.world.gen.IChunkGenerator; - -public interface ISpawnEntry { - - default boolean isEnabled() { - return false; - } - - default boolean isRetrogen() { - return false; - } - - String getSpawnName(); - - boolean dimensionAllowed(int dimension); - - boolean biomeAllowed(ResourceLocation biomeName); - - boolean biomeAllowed(Biome biome); - - IFeatureEntry getFeature(); - - OreSpawnBlockMatcher getMatcher(); - - IBlockList getBlocks(); - - void generate(Random random, World world, IChunkGenerator chunkGenerator, - IChunkProvider chunkProvider, ChunkPos pos); - - IDimensionList getDimensions(); - - BiomeLocation getBiomes(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java deleted file mode 100644 index cc421f86..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3API.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import java.nio.file.Path; -import java.util.List; -import java.util.Map; - -import com.mcmoddev.orespawn.api.IFeature; -import com.mcmoddev.orespawn.data.PresetsStorage; -import com.mcmoddev.orespawn.worldgen.OreSpawnFeatureGenerator; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.util.ResourceLocation; - -public interface OS3API { - - void addSpawn(ISpawnEntry spawnEntry); - - void addFeature(String featureName, IFeature feature); - - void addReplacement(IReplacementEntry replacementEntry); - - Map getReplacements(); - - IReplacementEntry getReplacement(String replacementName); - - List getSpawns(int dimensionID); - - ISpawnEntry getSpawn(String spawnName); - - Map getAllSpawns(); - - List getDimensionDefaultReplacements(int dimensionID); - - ISpawnBuilder getSpawnBuilder(); - - IDimensionBuilder getDimensionBuilder(); - - IFeatureBuilder getFeatureBuilder(); - - IBlockBuilder getBlockBuilder(); - - IBiomeBuilder getBiomeBuilder(); - - IReplacementBuilder getReplacementBuilder(); - - boolean featureExists(String featureName); - - boolean featureExists(ResourceLocation featureName); - - IFeature getFeature(String featureName); - - IFeature getFeature(ResourceLocation featureName); - - PresetsStorage copyPresets(); - - void loadConfigFiles(); - - boolean hasReplacement(ResourceLocation resourceLocation); - - boolean hasReplacement(String name); - - void mapEntryToFile(Path p, String entryName); - - List getSpawnsForFile(String fileName); - - Map> getSpawnsByFile(); - - void addGenerator(final OreSpawnFeatureGenerator generator); - - List getGenerators(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java deleted file mode 100644 index d803f9de..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OS3FeatureGenerator.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -public interface OS3FeatureGenerator { - public ISpawnEntry getSpawnData(); - public String getSpawnName(); -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java b/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java deleted file mode 100644 index 0c716413..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/OreSpawnBlockMatcher.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.mcmoddev.orespawn.api.os3; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.function.Predicate; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.mcmoddev.orespawn.data.Constants; -import com.mcmoddev.orespawn.util.StateUtil; - -import net.minecraft.block.state.IBlockState; -import net.minecraft.init.Blocks; - -public class OreSpawnBlockMatcher implements Predicate { - - private final List possibles; - - public OreSpawnBlockMatcher(final IBlockState... matches) { - this.possibles = Arrays.asList(matches); - } - - public OreSpawnBlockMatcher(final List matches) { - this.possibles = new ArrayList<>(); - this.possibles.addAll(matches); - } - - private boolean has(final IBlockState bs) { - return this.possibles.stream().filter(bs::equals).count() > 0; - } - - public boolean test(final IBlockState other) { - return (!other.getBlock().equals(Blocks.AIR)) && this.has(other); - } - - public JsonArray serialize() { - final JsonArray rv = new JsonArray(); - - possibles.stream().forEach(bs -> { - final JsonObject t = new JsonObject(); - t.addProperty(Constants.ConfigNames.NAME, bs.getBlock().getRegistryName().toString()); - if (!bs.equals(bs.getBlock().getDefaultState())) { - final String state = StateUtil.serializeState(bs); - t.addProperty(Constants.ConfigNames.STATE, state); - } - rv.add(t); - }); - - return rv; - } -} diff --git a/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java b/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java deleted file mode 100644 index 3db5c1b9..00000000 --- a/src/main/java/com/mcmoddev/orespawn/api/os3/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -@javax.annotation.ParametersAreNonnullByDefault -package com.mcmoddev.orespawn.api.os3; diff --git a/src/main/java/com/mcmoddev/orespawn/api/package-info.java b/src/main/java/com/mcmoddev/orespawn/api/package-info.java new file mode 100644 index 00000000..a20e9ad9 --- /dev/null +++ b/src/main/java/com/mcmoddev/orespawn/api/package-info.java @@ -0,0 +1,7 @@ +/** + * OreSpawn's supported, versioned integration API. + * + *