Block & item config split

This commit is contained in:
paulevsGitch 2020-12-12 13:11:37 +03:00
parent decc2097a3
commit a82c9225a4
9 changed files with 105 additions and 113 deletions

View file

@ -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;

View file

@ -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 extends Entry<?>> E getEntry(Identifier biome, String key) {
return this.getEntry(createKey(biome, key));
}
@Nullable
public <T> 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 <T extends Comparable<T>> 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);
}
}

View file

@ -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 <T extends Comparable<T>> boolean setRanged(ConfigKey key, T value) {
protected <T extends Comparable<T>> boolean setRanged(ConfigKey key, T value) {
try {
RangeEntry<T> 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;

View file

@ -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 {

View file

@ -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();
}
}

View file

@ -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 extends Entry<?>> E getEntry(Identifier id, String key) {
return this.getEntry(createKey(id, key));
}
@Nullable
public <T> 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 <T extends Comparable<T>> 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);
}
}

View file

@ -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 {

View file

@ -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);

View file

@ -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<Item> MOD_BLOCKS = Lists.newArrayList();
private static final List<Item> 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);