[Mirror] A minecraft mod to make the world more alive and dynamic
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Refactor config code to kotlin

+159 -125
+7 -3
build.gradle
··· 1 1 plugins { 2 2 id 'fabric-loom' version "${loom_version}" 3 3 id 'maven-publish' 4 + id 'org.jetbrains.kotlin.jvm' 4 5 } 5 6 6 7 version = project.mod_version ··· 11 12 } 12 13 13 14 repositories { 14 - // Add repositories to retrieve artifacts from in here. 15 + mavenCentral() 16 + // Add repositories to retrieve artifacts from in here. 15 17 // You should only use this when depending on other mods because 16 18 // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. 17 19 // See https://docs.gradle.org/current/userguide/declaring_repositories.html ··· 37 39 modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" 38 40 // Fabric API. This is technically optional, but you probably want it anyway. 39 41 modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" 42 + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" 40 43 } 41 44 42 45 processResources { ··· 57 60 // If you remove this line, sources will not be generated. 58 61 withSourcesJar() 59 62 60 - sourceCompatibility = JavaVersion.VERSION_21 61 - targetCompatibility = JavaVersion.VERSION_21 62 63 } 63 64 64 65 jar { ··· 85 86 // The repositories here will be used for publishing your artifact, not for 86 87 // retrieving dependencies. 87 88 } 89 + } 90 + kotlin { 91 + jvmToolchain(21) 88 92 }
+6
settings.gradle
··· 7 7 mavenCentral() 8 8 gradlePluginPortal() 9 9 } 10 + plugins { 11 + id 'org.jetbrains.kotlin.jvm' version '2.2.0' 12 + } 13 + } 14 + plugins { 15 + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0' 10 16 }
+8 -8
src/main/java/xyz/sillyjune/ecological/Ecological.java
··· 81 81 public void onInitialize() { 82 82 83 83 PUDDLE_CONFIG = PuddleConfig.get_config(); 84 - PUDDLE_GROW_RANGE = PUDDLE_CONFIG.puddle_grow_range(); 85 - PROBABILITY_PUDDLE_GROW = PUDDLE_CONFIG.probability_puddle_grow(); 86 - PROBABILITY_PUDDLE_NEW_LAYER = PUDDLE_CONFIG.probability_puddle_new_layer(); 87 - PROBABILITY_PUDDLE_EVAPORATE = PUDDLE_CONFIG.probability_puddle_evaporate(); 88 - PROBABILITY_PUDDLE_SPAWN = PUDDLE_CONFIG.probability_puddle_spawn(); 84 + PUDDLE_GROW_RANGE = PUDDLE_CONFIG.puddle_grow_range; 85 + PROBABILITY_PUDDLE_GROW = PUDDLE_CONFIG.probability_puddle_grow; 86 + PROBABILITY_PUDDLE_NEW_LAYER = PUDDLE_CONFIG.probability_puddle_new_layer; 87 + PROBABILITY_PUDDLE_EVAPORATE = PUDDLE_CONFIG.probability_puddle_evaporate; 88 + PROBABILITY_PUDDLE_SPAWN = PUDDLE_CONFIG.probability_puddle_spawn; 89 89 90 90 CROP_CONFIG = CropConfig.get_config(); 91 - PROBABILITY_MIXED_SEEDS_GRASS = CROP_CONFIG.probability_mixed_seeds_grass(); 92 - PROBABILITY_WILD_CROP_SPREAD = CROP_CONFIG.probability_wild_crop_spread(); 93 - WILD_CROP_SPREAD_DISTANCE = CROP_CONFIG.wild_crop_spread_distance(); 91 + PROBABILITY_MIXED_SEEDS_GRASS = CROP_CONFIG.probability_mixed_seeds_grass; 92 + PROBABILITY_WILD_CROP_SPREAD = CROP_CONFIG.probability_wild_crop_spread; 93 + WILD_CROP_SPREAD_DISTANCE = CROP_CONFIG.wild_crop_spread_distance; 94 94 95 95 Blocks.registerBlocks(); 96 96 Items.registerItems();
+65 -55
src/main/java/xyz/sillyjune/ecological/config/CropConfig.kt
··· 1 - package xyz.sillyjune.ecological.config; 2 - 3 - import com.google.gson.Gson; 1 + package xyz.sillyjune.ecological.config 4 2 5 - import java.io.File; 6 - import java.io.FileNotFoundException; 7 - import java.io.FileWriter; 8 - import java.io.IOException; 9 - import java.nio.file.Files; 10 - import java.nio.file.Path; 11 - import java.util.Scanner; 12 - 13 - import static xyz.sillyjune.ecological.Ecological.LOGGER; 3 + import com.google.gson.Gson 4 + import xyz.sillyjune.ecological.Ecological 5 + import java.io.File 6 + import java.io.FileNotFoundException 7 + import java.io.FileWriter 8 + import java.io.IOException 9 + import java.nio.file.Files 10 + import java.nio.file.Path 11 + import java.util.* 14 12 15 - public record CropConfig(int probability_mixed_seeds_grass, int probability_wild_crop_spread, int wild_crop_spread_distance) { 16 - public int probability_mixed_seeds_grass() { 17 - return probability_mixed_seeds_grass; 13 + @JvmRecord 14 + data class CropConfig( 15 + @JvmField val probability_mixed_seeds_grass: Int, 16 + @JvmField val probability_wild_crop_spread: Int, 17 + @JvmField val wild_crop_spread_distance: Int 18 + ) { 19 + fun probability_mixed_seeds_grass(): Int { 20 + return probability_mixed_seeds_grass 18 21 } 19 - public int probability_wild_crop_spread() { 20 - return probability_wild_crop_spread; 22 + 23 + fun probability_wild_crop_spread(): Int { 24 + return probability_wild_crop_spread 21 25 } 22 - public int wild_crop_spread_distance() { 23 - return wild_crop_spread_distance; 26 + 27 + fun wild_crop_spread_distance(): Int { 28 + return wild_crop_spread_distance 24 29 } 25 30 26 31 27 - public static CropConfig get_config() { 28 - String config = CropConfig.read_config(); // Read config 29 - CropConfig cfg = CropConfig.default_config(); 30 - if (config != null) { // If the config file exists, set it to whatever json was inside 31 - cfg = new Gson().fromJson(config, CropConfig.class); 32 - } else { // If the config file doesn't exist, get the string version of the defaults we set cfg to 33 - String json = new Gson().toJson(cfg); 34 - try { // Write the defaults to config/Ecological/puddles.json 35 - FileWriter writer = new FileWriter("config/Ecological/crops.json"); 36 - writer.write(json); 37 - writer.close(); 38 - } catch (IOException e) { 39 - LOGGER.warn("Failed to create config file!"); 32 + companion object { 33 + @JvmStatic 34 + fun get_config(): CropConfig? { 35 + val config: String? = read_config() // Read config 36 + var cfg: CropConfig? = default_config() 37 + if (config != null) { // If the config file exists, set it to whatever json was inside 38 + cfg = Gson().fromJson<CropConfig?>(config, CropConfig::class.java) 39 + } else { // If the config file doesn't exist, get the string version of the defaults we set cfg to 40 + val json = Gson().toJson(cfg) 41 + try { // Write the defaults to config/Ecological/puddles.json 42 + val writer = FileWriter("config/Ecological/crops.json") 43 + writer.write(json) 44 + writer.close() 45 + } catch (e: IOException) { 46 + Ecological.LOGGER.warn("Failed to create config file!") 47 + } 40 48 } 49 + return cfg 41 50 } 42 - return cfg; 43 - } 44 51 45 - static String read_config() { 46 - try { 47 - Path configDir = Path.of("config/Ecological"); // Check that config/Ecological actually exists, so we can write a config file to it 48 - if (!Files.exists(configDir)) { 49 - Files.createDirectories(configDir); 50 - } 51 - File config = new File("config/Ecological/crops.json"); 52 - Scanner reader = new Scanner(config); 53 - StringBuilder d = new StringBuilder(); 54 - while (reader.hasNextLine()) { 55 - String data = reader.nextLine(); 56 - d.append(data); 52 + fun read_config(): String? { 53 + try { 54 + val configDir = 55 + Path.of("config/Ecological") // Check that config/Ecological actually exists, so we can write a config file to it 56 + if (!Files.exists(configDir)) { 57 + Files.createDirectories(configDir) 58 + } 59 + val config = File("config/Ecological/crops.json") 60 + val reader = Scanner(config) 61 + val d = StringBuilder() 62 + while (reader.hasNextLine()) { 63 + val data = reader.nextLine() 64 + d.append(data) 65 + } 66 + reader.close() 67 + return d.toString() 68 + } catch (e: FileNotFoundException) { 69 + return null 70 + } catch (e: IOException) { 71 + throw RuntimeException(e) 57 72 } 58 - reader.close(); 59 - return d.toString(); 60 - } catch (FileNotFoundException e) { 61 - return null; 62 - } catch (IOException e) { 63 - throw new RuntimeException(e); 73 + } 74 + 75 + fun default_config(): CropConfig { 76 + return CropConfig(3, 8, 3) 64 77 } 65 - } 66 - static CropConfig default_config() { 67 - return new CropConfig(3, 8, 3); 68 78 } 69 79 }
+73 -59
src/main/java/xyz/sillyjune/ecological/config/PuddleConfig.kt
··· 1 - package xyz.sillyjune.ecological.config; 1 + package xyz.sillyjune.ecological.config 2 2 3 - import com.google.gson.Gson; 3 + import com.google.gson.Gson 4 + import xyz.sillyjune.ecological.Ecological 5 + import java.io.File 6 + import java.io.FileNotFoundException 7 + import java.io.FileWriter 8 + import java.io.IOException 9 + import java.nio.file.Files 10 + import java.nio.file.Path 11 + import java.util.* 4 12 5 - import java.io.File; 6 - import java.io.FileNotFoundException; 7 - import java.io.FileWriter; 8 - import java.io.IOException; 9 - import java.nio.file.Files; 10 - import java.nio.file.Path; 11 - import java.util.Scanner; 12 - 13 - import static xyz.sillyjune.ecological.Ecological.LOGGER; 14 - 15 - public record PuddleConfig(int puddle_grow_range, int probability_puddle_grow, int probability_puddle_new_layer, int probability_puddle_evaporate, int probability_puddle_spawn) { 16 - public int puddle_grow_range() { 17 - return puddle_grow_range; 13 + @JvmRecord 14 + data class PuddleConfig( 15 + @JvmField val puddle_grow_range: Int, 16 + @JvmField val probability_puddle_grow: Int, 17 + @JvmField val probability_puddle_new_layer: Int, 18 + @JvmField val probability_puddle_evaporate: Int, 19 + @JvmField val probability_puddle_spawn: Int 20 + ) { 21 + fun puddle_grow_range(): Int { 22 + return puddle_grow_range 18 23 } 19 - public int probability_puddle_grow() { 20 - return probability_puddle_grow; 24 + 25 + fun probability_puddle_grow(): Int { 26 + return probability_puddle_grow 21 27 } 22 - public int probability_puddle_new_layer() { 23 - return probability_puddle_new_layer; 28 + 29 + fun probability_puddle_new_layer(): Int { 30 + return probability_puddle_new_layer 24 31 } 25 - public int probability_puddle_evaporate() { 26 - return probability_puddle_evaporate; 32 + 33 + fun probability_puddle_evaporate(): Int { 34 + return probability_puddle_evaporate 27 35 } 28 - public int probability_puddle_spawn() { 29 - return probability_puddle_spawn; 36 + 37 + fun probability_puddle_spawn(): Int { 38 + return probability_puddle_spawn 30 39 } 31 40 32 - public static PuddleConfig get_config() { 33 - String config = PuddleConfig.read_config(); // Read config 34 - PuddleConfig cfg = PuddleConfig.default_config(); 35 - if (config != null) { // If the config file exists, set it to whatever json was inside 36 - cfg = new Gson().fromJson(config, PuddleConfig.class); 37 - } else { // If the config file doesn't exist, get the string version of the defaults we set cfg to 38 - String json = new Gson().toJson(cfg); 39 - try { // Write the defaults to config/Ecological/puddles.json 40 - FileWriter writer = new FileWriter("config/Ecological/puddles.json"); 41 - writer.write(json); 42 - writer.close(); 43 - } catch (IOException e) { 44 - LOGGER.warn("Failed to create config file!"); 41 + companion object { 42 + @JvmStatic 43 + fun get_config(): PuddleConfig? { 44 + val config: String? = read_config() // Read config 45 + var cfg: PuddleConfig? = default_config() 46 + if (config != null) { // If the config file exists, set it to whatever json was inside 47 + cfg = Gson().fromJson<PuddleConfig?>(config, PuddleConfig::class.java) 48 + } else { // If the config file doesn't exist, get the string version of the defaults we set cfg to 49 + val json = Gson().toJson(cfg) 50 + try { // Write the defaults to config/Ecological/puddles.json 51 + val writer = FileWriter("config/Ecological/puddles.json") 52 + writer.write(json) 53 + writer.close() 54 + } catch (e: IOException) { 55 + Ecological.LOGGER.warn("Failed to create config file!") 56 + } 45 57 } 58 + return cfg 46 59 } 47 - return cfg; 48 - } 49 60 50 - static String read_config() { 51 - try { 52 - Path configDir = Path.of("config/Ecological"); // Check that config/Ecological actually exists, so we can write a config file to it 53 - if (!Files.exists(configDir)) { 54 - Files.createDirectories(configDir); 55 - } 56 - File config = new File("config/Ecological/puddles.json"); 57 - Scanner reader = new Scanner(config); 58 - StringBuilder d = new StringBuilder(); 59 - while (reader.hasNextLine()) { 60 - String data = reader.nextLine(); 61 - d.append(data); 61 + fun read_config(): String? { 62 + try { 63 + val configDir = 64 + Path.of("config/Ecological") // Check that config/Ecological actually exists, so we can write a config file to it 65 + if (!Files.exists(configDir)) { 66 + Files.createDirectories(configDir) 67 + } 68 + val config = File("config/Ecological/puddles.json") 69 + val reader = Scanner(config) 70 + val d = StringBuilder() 71 + while (reader.hasNextLine()) { 72 + val data = reader.nextLine() 73 + d.append(data) 74 + } 75 + reader.close() 76 + return d.toString() 77 + } catch (e: FileNotFoundException) { 78 + return null 79 + } catch (e: IOException) { 80 + throw RuntimeException(e) 62 81 } 63 - reader.close(); 64 - return d.toString(); 65 - } catch (FileNotFoundException e) { 66 - return null; 67 - } catch (IOException e) { 68 - throw new RuntimeException(e); 69 82 } 70 - } 71 - static PuddleConfig default_config() { 72 - return new PuddleConfig(2, 32, 256, 64, 1024); 83 + 84 + fun default_config(): PuddleConfig { 85 + return PuddleConfig(2, 32, 256, 64, 1024) 86 + } 73 87 } 74 88 }