From a82c9225a4bb48c144e7ebdfee66574d2b9576bb Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 12 Dec 2020 13:11:37 +0300 Subject: [PATCH] Block & item config split --- .../betterend/blocks/BlockLanceleafSeed.java | 2 +- .../java/ru/betterend/config/BiomeConfig.java | 84 ------------------- src/main/java/ru/betterend/config/Config.java | 26 +++--- .../ru/betterend/config/ConfigKeeper.java | 1 - .../java/ru/betterend/config/Configs.java | 6 +- .../ru/betterend/config/IdentifierConfig.java | 83 ++++++++++++++++++ .../java/ru/betterend/item/GuideBook.java | 1 - .../java/ru/betterend/registry/EndBlocks.java | 7 +- .../java/ru/betterend/registry/EndItems.java | 8 +- 9 files changed, 105 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/ru/betterend/config/BiomeConfig.java create mode 100644 src/main/java/ru/betterend/config/IdentifierConfig.java diff --git a/src/main/java/ru/betterend/blocks/BlockLanceleafSeed.java b/src/main/java/ru/betterend/blocks/BlockLanceleafSeed.java index 07eacedf..2744a0b8 100644 --- a/src/main/java/ru/betterend/blocks/BlockLanceleafSeed.java +++ b/src/main/java/ru/betterend/blocks/BlockLanceleafSeed.java @@ -4,8 +4,8 @@ import java.util.Random; import net.minecraft.block.BlockState; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; import net.minecraft.util.math.BlockPos.Mutable; +import net.minecraft.util.math.Direction; import net.minecraft.world.StructureWorldAccess; import ru.betterend.blocks.BlockProperties.PentaShape; import ru.betterend.blocks.basis.BlockPlantWithAge; diff --git a/src/main/java/ru/betterend/config/BiomeConfig.java b/src/main/java/ru/betterend/config/BiomeConfig.java deleted file mode 100644 index c9a63338..00000000 --- a/src/main/java/ru/betterend/config/BiomeConfig.java +++ /dev/null @@ -1,84 +0,0 @@ -package ru.betterend.config; - -import org.jetbrains.annotations.Nullable; - -import net.minecraft.util.Identifier; -import ru.betterend.config.ConfigKeeper.Entry; - -public class BiomeConfig extends Config { - - protected BiomeConfig() { - super("biomes"); - } - - @Override - protected void registerEntries() {} - - private ConfigKey createKey(Identifier biome, String key) { - Identifier groupId = new Identifier(group, biome.getNamespace()); - Identifier categoryId = new Identifier(biome.getPath(), key); - return new ConfigKey(groupId, categoryId); - } - - @Nullable - public > E getEntry(Identifier biome, String key) { - return this.getEntry(createKey(biome, key)); - } - - @Nullable - public T getDefault(Identifier biome, String key) { - return this.getDefault(createKey(biome, key)); - } - - public String getString(Identifier biome, String key, String defaultValue) { - return this.getString(createKey(biome, key), defaultValue); - } - - public String getString(Identifier biome, String key) { - return this.getString(createKey(biome, key)); - } - - public boolean setString(Identifier biome, String key, String value) { - return this.setString(createKey(biome, key), value); - } - - public int getInt(Identifier biome, String key, int defaultValue) { - return this.getInt(createKey(biome, key), defaultValue); - } - - public int getInt(Identifier biome, String key) { - return this.getInt(createKey(biome, key)); - } - - public boolean setInt(Identifier biome, String key, int value) { - return this.setInt(createKey(biome, key), value); - } - - public > boolean setRanged(Identifier biome, String key, T value) { - return this.setRanged(createKey(biome, key), value); - } - - public float getFloat(Identifier biome, String key, float defaultValue) { - return this.getFloat(createKey(biome, key), defaultValue); - } - - public float getFloat(Identifier biome, String key) { - return this.getFloat(createKey(biome, key)); - } - - public boolean setFloat(Identifier biome, String key, float value) { - return this.setFloat(createKey(biome, key), value); - } - - public boolean getBoolean(Identifier biome, String key, boolean defaultValue) { - return this.getBoolean(createKey(biome, key), defaultValue); - } - - public boolean getBoolean(Identifier biome, String key) { - return this.getBoolean(createKey(biome, key)); - } - - public boolean setBoolean(Identifier biome, String key, boolean value) { - return this.setBoolean(createKey(biome, key), value); - } -} diff --git a/src/main/java/ru/betterend/config/Config.java b/src/main/java/ru/betterend/config/Config.java index 0301eaab..769345b5 100644 --- a/src/main/java/ru/betterend/config/Config.java +++ b/src/main/java/ru/betterend/config/Config.java @@ -44,7 +44,7 @@ public abstract class Config { return entry != null ? entry.getDefault() : null; } - public String getString(ConfigKey key, String defaultValue) { + protected String getString(ConfigKey key, String defaultValue) { String str = configKeeper.getValue(key); if (str == null) { StringEntry entry = configKeeper.registerEntry(key, new StringEntry(defaultValue)); @@ -53,12 +53,12 @@ public abstract class Config { return str != null ? str : defaultValue; } - public String getString(ConfigKey key) { + protected String getString(ConfigKey key) { String str = configKeeper.getValue(key); return str != null ? str : ""; } - public boolean setString(ConfigKey key, String value) { + protected boolean setString(ConfigKey key, String value) { try { StringEntry entry = configKeeper.getEntry(key); if (entry == null) return false; @@ -70,7 +70,7 @@ public abstract class Config { return false; } - public int getInt(ConfigKey key, int defaultValue) { + protected int getInt(ConfigKey key, int defaultValue) { Integer val = configKeeper.getValue(key); if (val == null) { IntegerEntry entry = configKeeper.registerEntry(key, new IntegerEntry(defaultValue)); @@ -79,12 +79,12 @@ public abstract class Config { return val != null ? val : defaultValue; } - public int getInt(ConfigKey key) { + protected int getInt(ConfigKey key) { Integer val = configKeeper.getValue(key); return val != null ? val : 0; } - public boolean setInt(ConfigKey key, int value) { + protected boolean setInt(ConfigKey key, int value) { try { IntegerEntry entry = configKeeper.getEntry(key); if (entry == null) return false; @@ -96,7 +96,7 @@ public abstract class Config { return false; } - public > boolean setRanged(ConfigKey key, T value) { + protected > boolean setRanged(ConfigKey key, T value) { try { RangeEntry entry = configKeeper.getEntry(key); if (entry == null) return false; @@ -108,7 +108,7 @@ public abstract class Config { return false; } - public float getFloat(ConfigKey key, float defaultValue) { + protected float getFloat(ConfigKey key, float defaultValue) { Float val = configKeeper.getValue(key); if (val == null) { FloatEntry entry = configKeeper.registerEntry(key, new FloatEntry(defaultValue)); @@ -117,12 +117,12 @@ public abstract class Config { return val != null ? val : defaultValue; } - public float getFloat(ConfigKey key) { + protected float getFloat(ConfigKey key) { Float val = configKeeper.getValue(key); return val != null ? val : 0.0F; } - public boolean setFloat(ConfigKey key, float value) { + protected boolean setFloat(ConfigKey key, float value) { try { FloatEntry entry = configKeeper.getEntry(key); if (entry == null) return false; @@ -134,7 +134,7 @@ public abstract class Config { return false; } - public boolean getBoolean(ConfigKey key, boolean defaultValue) { + protected boolean getBoolean(ConfigKey key, boolean defaultValue) { Boolean val = configKeeper.getValue(key); if (val == null) { BooleanEntry entry = configKeeper.registerEntry(key, new BooleanEntry(defaultValue)); @@ -143,12 +143,12 @@ public abstract class Config { return val != null ? val : defaultValue; } - public boolean getBoolean(ConfigKey key) { + protected boolean getBoolean(ConfigKey key) { Boolean val = configKeeper.getValue(key); return val != null ? val : false; } - public boolean setBoolean(ConfigKey key, boolean value) { + protected boolean setBoolean(ConfigKey key, boolean value) { try { BooleanEntry entry = configKeeper.getEntry(key); if (entry == null) return false; diff --git a/src/main/java/ru/betterend/config/ConfigKeeper.java b/src/main/java/ru/betterend/config/ConfigKeeper.java index 195dc67c..8a6ad88f 100644 --- a/src/main/java/ru/betterend/config/ConfigKeeper.java +++ b/src/main/java/ru/betterend/config/ConfigKeeper.java @@ -14,7 +14,6 @@ import com.google.gson.JsonObject; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; - import ru.betterend.util.JsonFactory; public final class ConfigKeeper { diff --git a/src/main/java/ru/betterend/config/Configs.java b/src/main/java/ru/betterend/config/Configs.java index e454be83..2e00f4a6 100644 --- a/src/main/java/ru/betterend/config/Configs.java +++ b/src/main/java/ru/betterend/config/Configs.java @@ -1,11 +1,13 @@ package ru.betterend.config; public class Configs { - public static final ItemConfig ITEM_CONFIG = new ItemConfig(); - public static final BiomeConfig BIOME_CONFIG = new BiomeConfig(); + public static final IdentifierConfig ITEM_CONFIG = new IdentifierConfig("items"); + public static final IdentifierConfig BLOCK_CONFIG = new IdentifierConfig("blocks"); + public static final IdentifierConfig BIOME_CONFIG = new IdentifierConfig("biomes"); public static void saveConfigs() { ITEM_CONFIG.saveChanges(); + BLOCK_CONFIG.saveChanges(); BIOME_CONFIG.saveChanges(); } } diff --git a/src/main/java/ru/betterend/config/IdentifierConfig.java b/src/main/java/ru/betterend/config/IdentifierConfig.java new file mode 100644 index 00000000..4e44b370 --- /dev/null +++ b/src/main/java/ru/betterend/config/IdentifierConfig.java @@ -0,0 +1,83 @@ +package ru.betterend.config; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.util.Identifier; +import ru.betterend.config.ConfigKeeper.Entry; + +public class IdentifierConfig extends Config { + public IdentifierConfig(String group) { + super(group); + } + + @Override + protected void registerEntries() {} + + private ConfigKey createKey(Identifier id, String key) { + Identifier groupId = new Identifier(group, id.getNamespace()); + Identifier categoryId = new Identifier(id.getPath(), key); + return new ConfigKey(groupId, categoryId); + } + + @Nullable + public > E getEntry(Identifier id, String key) { + return this.getEntry(createKey(id, key)); + } + + @Nullable + public T getDefault(Identifier id, String key) { + return this.getDefault(createKey(id, key)); + } + + public String getString(Identifier id, String key, String defaultValue) { + return this.getString(createKey(id, key), defaultValue); + } + + public String getString(Identifier id, String key) { + return this.getString(createKey(id, key)); + } + + public boolean setString(Identifier id, String key, String value) { + return this.setString(createKey(id, key), value); + } + + public int getInt(Identifier id, String key, int defaultValue) { + return this.getInt(createKey(id, key), defaultValue); + } + + public int getInt(Identifier id, String key) { + return this.getInt(createKey(id, key)); + } + + public boolean setInt(Identifier id, String key, int value) { + return this.setInt(createKey(id, key), value); + } + + public > boolean setRanged(Identifier id, String key, T value) { + return this.setRanged(createKey(id, key), value); + } + + public float getFloat(Identifier id, String key, float defaultValue) { + return this.getFloat(createKey(id, key), defaultValue); + } + + public float getFloat(Identifier id, String key) { + return this.getFloat(createKey(id, key)); + } + + public boolean setFloat(Identifier id, String key, float value) { + return this.setFloat(createKey(id, key), value); + } + + public boolean getBoolean(Identifier id, String key, boolean defaultValue) { + return this.getBoolean(createKey(id, key), defaultValue); + } + + public boolean getBoolean(Identifier id, String key) { + return this.getBoolean(createKey(id, key)); + } + + public boolean setBoolean(Identifier id, String key, boolean value) { + return this.setBoolean(createKey(id, key), value); + } +} diff --git a/src/main/java/ru/betterend/item/GuideBook.java b/src/main/java/ru/betterend/item/GuideBook.java index 4662699c..702c9cd5 100644 --- a/src/main/java/ru/betterend/item/GuideBook.java +++ b/src/main/java/ru/betterend/item/GuideBook.java @@ -16,7 +16,6 @@ import net.minecraft.world.World; import ru.betterend.BetterEnd; import ru.betterend.registry.EndItems; import ru.betterend.util.LangUtil; - import vazkii.patchouli.api.PatchouliAPI; public class GuideBook extends PatternedItem { diff --git a/src/main/java/ru/betterend/registry/EndBlocks.java b/src/main/java/ru/betterend/registry/EndBlocks.java index 9b0a8881..7dc5dc56 100644 --- a/src/main/java/ru/betterend/registry/EndBlocks.java +++ b/src/main/java/ru/betterend/registry/EndBlocks.java @@ -32,10 +32,10 @@ import ru.betterend.blocks.BlockEndLotusSeed; import ru.betterend.blocks.BlockEndLotusStem; import ru.betterend.blocks.BlockEndstoneDust; import ru.betterend.blocks.BlockGlowingMoss; -import ru.betterend.blocks.BlockHelixTreeLeaves; import ru.betterend.blocks.BlockGlowingPillarLuminophor; import ru.betterend.blocks.BlockGlowingPillarRoots; import ru.betterend.blocks.BlockGlowingPillarSeed; +import ru.betterend.blocks.BlockHelixTreeLeaves; import ru.betterend.blocks.BlockHelixTreeSapling; import ru.betterend.blocks.BlockHydralux; import ru.betterend.blocks.BlockHydraluxPetal; @@ -86,12 +86,9 @@ import ru.betterend.blocks.basis.BlockWallPlant; import ru.betterend.blocks.complex.ColoredMaterial; import ru.betterend.blocks.complex.StoneMaterial; import ru.betterend.blocks.complex.WoodenMaterial; -import ru.betterend.config.ItemConfig; import ru.betterend.config.Configs; public class EndBlocks { - private static final ItemConfig CONFIG = Configs.ITEM_CONFIG; - // Terrain // public static final Block ENDSTONE_DUST = registerBlock("endstone_dust", new BlockEndstoneDust()); public static final Block END_MYCELIUM = registerBlock("end_mycelium", new BlockTerrain(MaterialColor.LIGHT_BLUE)); @@ -267,7 +264,7 @@ public class EndBlocks { public static void register() {} public static Block registerBlock(Identifier id, Block block) { - if (!CONFIG.getBoolean(id, "blocks", true)) { + if (!Configs.BLOCK_CONFIG.getBoolean(id, "blocks", true)) { return block; } Registry.register(Registry.BLOCK, id, block); diff --git a/src/main/java/ru/betterend/registry/EndItems.java b/src/main/java/ru/betterend/registry/EndItems.java index b8fdc8c3..65753f6b 100644 --- a/src/main/java/ru/betterend/registry/EndItems.java +++ b/src/main/java/ru/betterend/registry/EndItems.java @@ -32,9 +32,7 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPointer; import net.minecraft.util.math.Direction; import net.minecraft.util.registry.Registry; - import ru.betterend.BetterEnd; -import ru.betterend.config.ItemConfig; import ru.betterend.config.Configs; import ru.betterend.item.EndArmorMaterial; import ru.betterend.item.EndAxe; @@ -49,8 +47,6 @@ import ru.betterend.tab.CreativeTabs; import ru.betterend.util.TagHelper; public class EndItems { - - private static final ItemConfig CONFIG = Configs.ITEM_CONFIG; private static final List MOD_BLOCKS = Lists.newArrayList(); private static final List MOD_ITEMS = Lists.newArrayList(); @@ -122,7 +118,7 @@ public class EndItems { } public static Item registerItem(Identifier id, Item item) { - if (!(item instanceof BlockItem) && !CONFIG.getBoolean(id, "items", true)) { + if (!Configs.ITEM_CONFIG.getBoolean(id, "items", true)) { return item; } if (item != Items.AIR) { @@ -137,7 +133,7 @@ public class EndItems { protected static ToolItem registerTool(String name, ToolItem item) { Identifier id = BetterEnd.makeID(name); - if (!CONFIG.getBoolean(id, "items", true)) { + if (!Configs.ITEM_CONFIG.getBoolean(id, "items", true)) { return item; } Registry.register(Registry.ITEM, id, item);