From d382a965e9361fc3964a38a2b75a8213f640909b Mon Sep 17 00:00:00 2001 From: Aleksey Date: Tue, 22 Sep 2020 17:10:04 +0300 Subject: [PATCH] Added config for biomes --- .../ru/betterend/config/ClientConfig.java | 37 ---- src/main/java/ru/betterend/config/Config.java | 34 +-- .../ru/betterend/config/ConfigKeeper.java | 82 +++---- .../ru/betterend/config/ConfigWriter.java | 45 +++- .../java/ru/betterend/config/MainConfig.java | 34 +++ .../ru/betterend/{ => util}/BlocksHelper.java | 208 +++++++++--------- .../java/ru/betterend/{ => util}/MHelper.java | 102 ++++----- .../ru/betterend/world/biome/BiomeConfig.java | 43 ++++ .../world/biome/BiomeDefinition.java | 2 +- .../betterend/world/generator/BiomeMap.java | 2 +- 10 files changed, 322 insertions(+), 267 deletions(-) delete mode 100644 src/main/java/ru/betterend/config/ClientConfig.java create mode 100644 src/main/java/ru/betterend/config/MainConfig.java rename src/main/java/ru/betterend/{ => util}/BlocksHelper.java (96%) rename src/main/java/ru/betterend/{ => util}/MHelper.java (94%) create mode 100644 src/main/java/ru/betterend/world/biome/BiomeConfig.java diff --git a/src/main/java/ru/betterend/config/ClientConfig.java b/src/main/java/ru/betterend/config/ClientConfig.java deleted file mode 100644 index b3ca436a..00000000 --- a/src/main/java/ru/betterend/config/ClientConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -package ru.betterend.config; - -import com.google.gson.JsonObject; - -public class ClientConfig extends Config { - - private static ClientConfig instance; - - public static ClientConfig get() { - if (instance == null) { - instance = new ClientConfig(); - } - - return instance; - } - - private ClientConfig() { - JsonObject config = ConfigWriter.load(); - if (config.size() > 0) { - KEEPER.fromJson(config); - } else { - ConfigWriter.save(KEEPER.toJson()); - } - } - - public void reloadFromDisk() { - JsonObject config = ConfigWriter.load(); - if (config.size() > 0) { - KEEPER.fromJson(config); - } - } - - @Override - public void saveChanges() { - ConfigWriter.save(KEEPER.toJson()); - } -} diff --git a/src/main/java/ru/betterend/config/Config.java b/src/main/java/ru/betterend/config/Config.java index e1fab94e..e78c75a1 100644 --- a/src/main/java/ru/betterend/config/Config.java +++ b/src/main/java/ru/betterend/config/Config.java @@ -5,29 +5,29 @@ import ru.betterend.config.ConfigKeeper.*; public abstract class Config { - protected final static ConfigKeeper KEEPER = ConfigKeeper.getInstance(); + protected final ConfigKeeper configKeeper = new ConfigKeeper(); public abstract void saveChanges(); public > E getEntry(String key) { - return KEEPER.getEntry(key); + return this.configKeeper.getEntry(key); } public T getDefault(String key) { - Entry entry = KEEPER.getEntry(key); + Entry entry = configKeeper.getEntry(key); return entry != null ? entry.getDefault() : null; } public String getString(String key) { - String str = KEEPER.getValue(key); + String str = configKeeper.getValue(key); return str != null ? str : ""; } public boolean setString(String key, String value) { try { - StringEntry entry = KEEPER.getEntry(key); + StringEntry entry = configKeeper.getEntry(key); entry.setValue(value); - KEEPER.set(key, entry); + this.configKeeper.set(key, entry); return true; } catch (NullPointerException ex) { @@ -38,15 +38,15 @@ public abstract class Config { } public int getInt(String key) { - Integer val = KEEPER.getValue(key); + Integer val = configKeeper.getValue(key); return val != null ? val : 0; } public boolean setInt(String key, int value) { try { - IntegerEntry entry = KEEPER.getEntry(key); + IntegerEntry entry = configKeeper.getEntry(key); entry.setValue(value); - KEEPER.set(key, entry); + this.configKeeper.set(key, entry); return true; } catch (NullPointerException ex) { @@ -58,9 +58,9 @@ public abstract class Config { public > boolean setRanged(String key, T value) { try { - RangeEntry entry = KEEPER.getEntry(key); + RangeEntry entry = configKeeper.getEntry(key); entry.setValue(value); - KEEPER.set(key, entry); + this.configKeeper.set(key, entry); return true; } catch (NullPointerException | ClassCastException ex) { @@ -71,15 +71,15 @@ public abstract class Config { } public float getFloat(String key) { - Float val = KEEPER.getValue(key); + Float val = configKeeper.getValue(key); return val != null ? val : 0.0F; } public boolean setFloat(String key, float value) { try { - FloatEntry entry = KEEPER.getEntry(key); + FloatEntry entry = configKeeper.getEntry(key); entry.setValue(value); - KEEPER.set(key, entry); + this.configKeeper.set(key, entry); return true; } catch (NullPointerException ex) { @@ -90,15 +90,15 @@ public abstract class Config { } public boolean getBoolean(String key) { - Boolean val = KEEPER.getValue(key); + Boolean val = configKeeper.getValue(key); return val != null ? val : false; } public boolean setBoolean(String key, boolean value) { try { - BooleanEntry entry = KEEPER.getEntry(key); + BooleanEntry entry = configKeeper.getEntry(key); entry.setValue(value); - KEEPER.set(key, entry); + this.configKeeper.set(key, entry); return true; } catch (NullPointerException ex) { diff --git a/src/main/java/ru/betterend/config/ConfigKeeper.java b/src/main/java/ru/betterend/config/ConfigKeeper.java index 0400d801..0ad9043b 100644 --- a/src/main/java/ru/betterend/config/ConfigKeeper.java +++ b/src/main/java/ru/betterend/config/ConfigKeeper.java @@ -13,48 +13,9 @@ import ru.betterend.BetterEnd; public final class ConfigKeeper { - private static ConfigKeeper instance; - public static ConfigKeeper getInstance() { - if (instance == null) { - instance = new ConfigKeeper(); - } - return instance; - } - private Map> configEntries = new HashMap<>(); - private ConfigKeeper() {} - - @SuppressWarnings("unchecked") - public > E getEntry(String key) { - Entry entry = this.configEntries.get(key); - if (entry == null) { - BetterEnd.LOGGER.warning(String.format("Entry '%s' doesn't exists.", key)); - return null; - } - return (E) entry; - } - - public T getValue(String key) { - Entry entry = this.getEntry(key); - if (entry == null) { - BetterEnd.LOGGER.warning(String.format("Empty value will be returned.", key)); - return null; - } - return entry.getValue(); - } - - public void set(String key, Entry entry) { - configEntries.put(key, entry); - } - - public > void registerEntry(String key, T entry) { - configEntries.put(key, entry); - } - - public JsonElement toJson() { - JsonObject jsonObject = new JsonObject(); - + public JsonElement toJson(JsonObject jsonObject) { for (String param : configEntries.keySet()) { jsonObject.addProperty(param, configEntries.get(param).asString()); } @@ -71,6 +32,33 @@ public final class ConfigKeeper { } } + @SuppressWarnings("unchecked") + public > E getEntry(String key) { + Entry entry = this.configEntries.get(key); + if (entry == null) { + BetterEnd.LOGGER.warning(String.format("Entry '%s' doesn't exists.", key)); + return null; + } + return (E) entry; + } + + public T getValue(String key) { + Entry entry = this.getEntry(key); + if (entry == null) { + BetterEnd.LOGGER.warning("Empty value will be returned."); + return null; + } + return entry.getValue(); + } + + public void set(String key, Entry entry) { + configEntries.put(key, entry); + } + + public > void registerEntry(String key, T entry) { + configEntries.put(key, entry); + } + public static class BooleanEntry extends Entry { public BooleanEntry(Boolean defaultValue, Consumer consumer, Supplier supplier) { @@ -94,12 +82,12 @@ public final class ConfigKeeper { @Override public String asString() { - return getValue() ? "true" : "false"; + return this.getValue() ? "true" : "false"; } @Override public void fromString(String value) { - setValue(value.equals("true") ? true : false); + this.setValue(value.equals("true") ? true : false); } } @@ -132,7 +120,7 @@ public final class ConfigKeeper { @Override public void fromString(String value) { - setValue(Float.valueOf(value)); + this.setValue(Float.valueOf(value)); } } @@ -155,7 +143,7 @@ public final class ConfigKeeper { @Override public void fromString(String value) { - setValue(Float.valueOf(value)); + this.setValue(Float.valueOf(value)); } @Override @@ -193,7 +181,7 @@ public final class ConfigKeeper { @Override public void fromString(String value) { - setValue(Integer.valueOf(value)); + this.setValue(Integer.valueOf(value)); } } @@ -216,7 +204,7 @@ public final class ConfigKeeper { @Override public void fromString(String value) { - setValue(Integer.valueOf(value)); + this.setValue(Integer.valueOf(value)); } @Override @@ -254,7 +242,7 @@ public final class ConfigKeeper { @Override public void fromString(String value) { - setValue(value); + this.setValue(value); } } diff --git a/src/main/java/ru/betterend/config/ConfigWriter.java b/src/main/java/ru/betterend/config/ConfigWriter.java index 430be957..aee40972 100644 --- a/src/main/java/ru/betterend/config/ConfigWriter.java +++ b/src/main/java/ru/betterend/config/ConfigWriter.java @@ -13,24 +13,51 @@ import ru.betterend.util.JsonFactory; public class ConfigWriter { - private final static FabricLoader fabricLoader = FabricLoader.getInstance(); - private final static Path GAME_CONFIG_DIR = fabricLoader.getConfigDir(); - private final static File MOD_CONFIG_DIR = new File(GAME_CONFIG_DIR.toFile(), BetterEnd.MOD_ID); - private final static File CONFIG_FILE = new File(MOD_CONFIG_DIR, "settings.json"); + private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir(); + public final static File MOD_CONFIG_DIR = new File(GAME_CONFIG_DIR.toFile(), BetterEnd.MOD_ID); + private final static File MAIN_CONFIG_FILE = new File(MOD_CONFIG_DIR, "settings.json"); - private static JsonObject configObject; + private static JsonObject mainConfig; - private ConfigWriter() {} + private JsonObject configObject; + private File configFile; - public static JsonObject load() { + public JsonObject loadConfig(File configFile) { + this.configFile = configFile; if (configObject == null) { - configObject = JsonFactory.getJsonObject(CONFIG_FILE); + configObject = load(configFile); } return configObject; } + public void saveConfig() { + if (configFile == null || configObject == null) { + return; + } + save(configFile, configObject); + } + + public static JsonObject load() { + if (mainConfig == null) { + mainConfig = load(MAIN_CONFIG_FILE); + } + return mainConfig; + } + + public static JsonObject load(File configFile) { + return JsonFactory.getJsonObject(configFile); + } + + public static void save() { + save(MAIN_CONFIG_FILE, mainConfig); + } + public static void save(JsonElement config) { - JsonFactory.storeJson(CONFIG_FILE, config); + save(MAIN_CONFIG_FILE, config); + } + + public static void save(File configFile, JsonElement config) { + JsonFactory.storeJson(configFile, config); } } diff --git a/src/main/java/ru/betterend/config/MainConfig.java b/src/main/java/ru/betterend/config/MainConfig.java new file mode 100644 index 00000000..9f8b8e8a --- /dev/null +++ b/src/main/java/ru/betterend/config/MainConfig.java @@ -0,0 +1,34 @@ +package ru.betterend.config; + +import com.google.gson.JsonObject; + +public class MainConfig extends Config { + + private static MainConfig instance; + + public static MainConfig getInstance() { + if (instance == null) { + instance = new MainConfig(); + } + + return instance; + } + + private MainConfig() { + //TODO: Need to register config params in the Keeper + + JsonObject config = ConfigWriter.load(); + if (config.size() > 0) { + this.configKeeper.fromJson(config); + } else { + this.configKeeper.toJson(config); + ConfigWriter.save(); + } + } + + @Override + public void saveChanges() { + this.configKeeper.toJson(ConfigWriter.load()); + ConfigWriter.save(); + } +} diff --git a/src/main/java/ru/betterend/BlocksHelper.java b/src/main/java/ru/betterend/util/BlocksHelper.java similarity index 96% rename from src/main/java/ru/betterend/BlocksHelper.java rename to src/main/java/ru/betterend/util/BlocksHelper.java index c549bccc..741a8751 100644 --- a/src/main/java/ru/betterend/BlocksHelper.java +++ b/src/main/java/ru/betterend/util/BlocksHelper.java @@ -1,104 +1,104 @@ -package ru.betterend; - -import java.util.HashSet; -import java.util.Iterator; -import java.util.Random; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.Property; -import net.minecraft.util.BlockMirror; -import net.minecraft.util.BlockRotation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.util.math.Vec3i; -import net.minecraft.world.WorldAccess; - -public class BlocksHelper { - public static final int FLAG_UPDATE_BLOCK = 1; - public static final int FLAG_SEND_CLIENT_CHANGES = 2; - public static final int FLAG_NO_RERENDER = 4; - public static final int FORSE_RERENDER = 8; - public static final int FLAG_IGNORE_OBSERVERS = 16; - - public static final int SET_SILENT = FLAG_UPDATE_BLOCK | FLAG_IGNORE_OBSERVERS | FLAG_SEND_CLIENT_CHANGES; - public static final Direction[] HORIZONTAL = new Direction[] { Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST }; - - private static final Vec3i[] OFFSETS = new Vec3i[] { - new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1), - new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), - new Vec3i(-1, 1, -1), new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1), - - new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), - new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), new Vec3i(0, 0, 1), - new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1), - - new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), - new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1), - new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) - }; - - public static void setWithoutUpdate(WorldAccess world, BlockPos pos, BlockState state) { - world.setBlockState(pos, state, SET_SILENT); - } - - public static int upRay(WorldAccess world, BlockPos pos, int maxDist) { - int length = 0; - for (int j = 1; j < maxDist && (world.isAir(pos.up(j))); j++) - length++; - return length; - } - - public static int downRay(WorldAccess world, BlockPos pos, int maxDist) { - int length = 0; - for (int j = 1; j < maxDist && (world.isAir(pos.down(j))); j++) - length++; - return length; - } - - public static BlockState rotateHorizontal(BlockState state, BlockRotation rotation, Property facing) { - return (BlockState) state.with(facing, rotation.rotate((Direction) state.get(facing))); - } - - public static BlockState mirrorHorizontal(BlockState state, BlockMirror mirror, Property facing) { - return state.rotate(mirror.getRotation((Direction) state.get(facing))); - } - - public static int getLengthDown(ServerWorld world, BlockPos pos, Block block) { - int count = 1; - while (world.getBlockState(pos.down(count)).getBlock() == block) - count++; - return count; - } - - public static void cover(WorldAccess world, BlockPos center, Block ground, BlockState cover, int radius, Random random) { - HashSet points = new HashSet(); - HashSet points2 = new HashSet(); - if (world.getBlockState(center).getBlock() == ground) { - points.add(center); - points2.add(center); - for (int i = 0; i < radius; i++) { - Iterator iterator = points.iterator(); - while (iterator.hasNext()) { - BlockPos pos = iterator.next(); - for (Vec3i offset : OFFSETS) { - if (random.nextBoolean()) { - BlockPos pos2 = pos.add(offset); - if (random.nextBoolean() && world.getBlockState(pos2).getBlock() == ground - && !points.contains(pos2)) - points2.add(pos2); - } - } - } - points.addAll(points2); - points2.clear(); - } - Iterator iterator = points.iterator(); - while (iterator.hasNext()) { - BlockPos pos = iterator.next(); - BlocksHelper.setWithoutUpdate(world, pos, cover); - } - } - } -} +package ru.betterend.util; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.state.property.Property; +import net.minecraft.util.BlockMirror; +import net.minecraft.util.BlockRotation; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3i; +import net.minecraft.world.WorldAccess; + +public class BlocksHelper { + public static final int FLAG_UPDATE_BLOCK = 1; + public static final int FLAG_SEND_CLIENT_CHANGES = 2; + public static final int FLAG_NO_RERENDER = 4; + public static final int FORSE_RERENDER = 8; + public static final int FLAG_IGNORE_OBSERVERS = 16; + + public static final int SET_SILENT = FLAG_UPDATE_BLOCK | FLAG_IGNORE_OBSERVERS | FLAG_SEND_CLIENT_CHANGES; + public static final Direction[] HORIZONTAL = new Direction[] { Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST }; + + private static final Vec3i[] OFFSETS = new Vec3i[] { + new Vec3i(-1, -1, -1), new Vec3i(-1, -1, 0), new Vec3i(-1, -1, 1), + new Vec3i(-1, 0, -1), new Vec3i(-1, 0, 0), new Vec3i(-1, 0, 1), + new Vec3i(-1, 1, -1), new Vec3i(-1, 1, 0), new Vec3i(-1, 1, 1), + + new Vec3i(0, -1, -1), new Vec3i(0, -1, 0), new Vec3i(0, -1, 1), + new Vec3i(0, 0, -1), new Vec3i(0, 0, 0), new Vec3i(0, 0, 1), + new Vec3i(0, 1, -1), new Vec3i(0, 1, 0), new Vec3i(0, 1, 1), + + new Vec3i(1, -1, -1), new Vec3i(1, -1, 0), new Vec3i(1, -1, 1), + new Vec3i(1, 0, -1), new Vec3i(1, 0, 0), new Vec3i(1, 0, 1), + new Vec3i(1, 1, -1), new Vec3i(1, 1, 0), new Vec3i(1, 1, 1) + }; + + public static void setWithoutUpdate(WorldAccess world, BlockPos pos, BlockState state) { + world.setBlockState(pos, state, SET_SILENT); + } + + public static int upRay(WorldAccess world, BlockPos pos, int maxDist) { + int length = 0; + for (int j = 1; j < maxDist && (world.isAir(pos.up(j))); j++) + length++; + return length; + } + + public static int downRay(WorldAccess world, BlockPos pos, int maxDist) { + int length = 0; + for (int j = 1; j < maxDist && (world.isAir(pos.down(j))); j++) + length++; + return length; + } + + public static BlockState rotateHorizontal(BlockState state, BlockRotation rotation, Property facing) { + return (BlockState) state.with(facing, rotation.rotate((Direction) state.get(facing))); + } + + public static BlockState mirrorHorizontal(BlockState state, BlockMirror mirror, Property facing) { + return state.rotate(mirror.getRotation((Direction) state.get(facing))); + } + + public static int getLengthDown(ServerWorld world, BlockPos pos, Block block) { + int count = 1; + while (world.getBlockState(pos.down(count)).getBlock() == block) + count++; + return count; + } + + public static void cover(WorldAccess world, BlockPos center, Block ground, BlockState cover, int radius, Random random) { + HashSet points = new HashSet(); + HashSet points2 = new HashSet(); + if (world.getBlockState(center).getBlock() == ground) { + points.add(center); + points2.add(center); + for (int i = 0; i < radius; i++) { + Iterator iterator = points.iterator(); + while (iterator.hasNext()) { + BlockPos pos = iterator.next(); + for (Vec3i offset : OFFSETS) { + if (random.nextBoolean()) { + BlockPos pos2 = pos.add(offset); + if (random.nextBoolean() && world.getBlockState(pos2).getBlock() == ground + && !points.contains(pos2)) + points2.add(pos2); + } + } + } + points.addAll(points2); + points2.clear(); + } + Iterator iterator = points.iterator(); + while (iterator.hasNext()) { + BlockPos pos = iterator.next(); + BlocksHelper.setWithoutUpdate(world, pos, cover); + } + } + } +} diff --git a/src/main/java/ru/betterend/MHelper.java b/src/main/java/ru/betterend/util/MHelper.java similarity index 94% rename from src/main/java/ru/betterend/MHelper.java rename to src/main/java/ru/betterend/util/MHelper.java index f175f742..f6e51fe4 100644 --- a/src/main/java/ru/betterend/MHelper.java +++ b/src/main/java/ru/betterend/util/MHelper.java @@ -1,51 +1,51 @@ -package ru.betterend; - -import java.util.Random; - -public class MHelper { - public static final float PI2 = (float) (Math.PI * 2); - private static final int ALPHA = 255 << 24; - public static final Random RANDOM = new Random(); - - public static int color(int r, int g, int b) { - return ALPHA | (r << 16) | (g << 8) | b; - } - - public static int randRange(int min, int max, Random random) { - return min + random.nextInt(max - min + 1); - } - - public static float randRange(float min, float max, Random random) { - return min + random.nextFloat() * (max - min); - } - - public static byte setBit(byte source, int pos, boolean value) { - return value ? setBitTrue(source, pos) : setBitFalse(source, pos); - } - - public static byte setBitTrue(byte source, int pos) { - source |= 1 << pos; - return source; - } - - public static byte setBitFalse(byte source, int pos) { - source &= ~(1 << pos); - return source; - } - - public static boolean getBit(byte source, int pos) { - return ((source >> pos) & 1) == 1; - } - - public static int floor(float x) { - return x < 0 ? (int) (x - 1) : (int) x; - } - - public static float wrap(float x, float side) { - return x - floor(x / side) * side; - } - - public static int floor(double x) { - return x < 0 ? (int) (x - 1) : (int) x; - } -} +package ru.betterend.util; + +import java.util.Random; + +public class MHelper { + public static final float PI2 = (float) (Math.PI * 2); + private static final int ALPHA = 255 << 24; + public static final Random RANDOM = new Random(); + + public static int color(int r, int g, int b) { + return ALPHA | (r << 16) | (g << 8) | b; + } + + public static int randRange(int min, int max, Random random) { + return min + random.nextInt(max - min + 1); + } + + public static float randRange(float min, float max, Random random) { + return min + random.nextFloat() * (max - min); + } + + public static byte setBit(byte source, int pos, boolean value) { + return value ? setBitTrue(source, pos) : setBitFalse(source, pos); + } + + public static byte setBitTrue(byte source, int pos) { + source |= 1 << pos; + return source; + } + + public static byte setBitFalse(byte source, int pos) { + source &= ~(1 << pos); + return source; + } + + public static boolean getBit(byte source, int pos) { + return ((source >> pos) & 1) == 1; + } + + public static int floor(float x) { + return x < 0 ? (int) (x - 1) : (int) x; + } + + public static float wrap(float x, float side) { + return x - floor(x / side) * side; + } + + public static int floor(double x) { + return x < 0 ? (int) (x - 1) : (int) x; + } +} diff --git a/src/main/java/ru/betterend/world/biome/BiomeConfig.java b/src/main/java/ru/betterend/world/biome/BiomeConfig.java new file mode 100644 index 00000000..55d6a5ae --- /dev/null +++ b/src/main/java/ru/betterend/world/biome/BiomeConfig.java @@ -0,0 +1,43 @@ +package ru.betterend.world.biome; + +import java.io.File; +import java.nio.file.Path; + +import com.google.gson.JsonObject; + +import net.minecraft.util.Identifier; +import ru.betterend.config.Config; +import ru.betterend.config.ConfigWriter; + +public class BiomeConfig extends Config { + + private final static Path BIOME_CONFIG_DIR = ConfigWriter.MOD_CONFIG_DIR.toPath().resolve("biomes"); + + private EndBiome biome; + private ConfigWriter configWriter; + private File configFile; + + public BiomeConfig(EndBiome biome) { + this.biome = biome; + Identifier biomeId = biome.getID(); + this.configFile = new File(BIOME_CONFIG_DIR.toFile(), biomeId.getPath()); + this.configWriter = new ConfigWriter(); + this.registerEntries(); + JsonObject config = configWriter.loadConfig(configFile); + if (config.size() > 0) { + this.configKeeper.fromJson(config); + } else { + this.configKeeper.toJson(config); + this.configWriter.saveConfig(); + } + } + + private void registerEntries() { + //TODO: Need to register config params in the Keeper + } + + @Override + public void saveChanges() { + this.configWriter.saveConfig(); + } +} diff --git a/src/main/java/ru/betterend/world/biome/BiomeDefinition.java b/src/main/java/ru/betterend/world/biome/BiomeDefinition.java index dfbcb155..4c5cab00 100644 --- a/src/main/java/ru/betterend/world/biome/BiomeDefinition.java +++ b/src/main/java/ru/betterend/world/biome/BiomeDefinition.java @@ -26,7 +26,7 @@ import net.minecraft.world.gen.feature.ConfiguredFeature; import net.minecraft.world.gen.feature.ConfiguredStructureFeature; import net.minecraft.world.gen.surfacebuilder.ConfiguredSurfaceBuilders; import ru.betterend.BetterEnd; -import ru.betterend.MHelper; +import ru.betterend.util.MHelper; public class BiomeDefinition { diff --git a/src/main/java/ru/betterend/world/generator/BiomeMap.java b/src/main/java/ru/betterend/world/generator/BiomeMap.java index 82f6aa91..fd8b7897 100644 --- a/src/main/java/ru/betterend/world/generator/BiomeMap.java +++ b/src/main/java/ru/betterend/world/generator/BiomeMap.java @@ -4,8 +4,8 @@ import java.util.HashMap; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.gen.ChunkRandom; -import ru.betterend.MHelper; import ru.betterend.noise.OpenSimplexNoise; +import ru.betterend.util.MHelper; import ru.betterend.world.biome.EndBiome; public class BiomeMap