Config refactor

This commit is contained in:
Aleksey 2020-11-28 15:38:25 +03:00
parent 7f2bad86ca
commit 0f12a477e0
10 changed files with 408 additions and 265 deletions

View file

@ -1,9 +1,10 @@
package ru.betterend; package ru.betterend;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.api.BetterEndPlugin; import ru.betterend.api.BetterEndPlugin;
import ru.betterend.config.MainConfig; import ru.betterend.config.MainConfig;
import ru.betterend.effects.EndEnchantments; import ru.betterend.effects.EndEnchantments;
@ -28,8 +29,6 @@ import ru.betterend.world.generator.BetterEndBiomeSource;
public class BetterEnd implements ModInitializer { public class BetterEnd implements ModInitializer {
public static final String MOD_ID = "betterend"; public static final String MOD_ID = "betterend";
public static final Logger LOGGER = Logger.get(); public static final Logger LOGGER = Logger.get();
public static final MainConfig CONFIG = MainConfig.getInstance();
@Override @Override
public void onInitialize() { public void onInitialize() {
EndSounds.register(); EndSounds.register();
@ -51,9 +50,7 @@ public class BetterEnd implements ModInitializer {
EndStructures.register(); EndStructures.register();
FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class).forEach(BetterEndPlugin::register); FabricLoader.getInstance().getEntrypoints("betterend", BetterEndPlugin.class).forEach(BetterEndPlugin::register);
ServerLifecycleEvents.SERVER_STOPPING.register(server -> { MainConfig.saveConfig();
CONFIG.saveChanges();
});
} }
public static Identifier makeID(String path) { public static Identifier makeID(String path) {

View file

@ -1,101 +1,102 @@
package ru.betterend.world.biome; package ru.betterend.config;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import ru.betterend.config.Config; import ru.betterend.config.ConfigKeeper.Entry;
import ru.betterend.config.ConfigKeeper.Entry; import ru.betterend.world.biome.EndBiome;
import ru.betterend.config.ConfigWriter;
public class BiomeConfig extends Config {
public class BiomeConfig extends Config {
private final ConfigWriter writer;
private final ConfigWriter writer; private final String group = "biomes";
public BiomeConfig() { protected BiomeConfig() {
this.writer = new ConfigWriter("biomes"); this.writer = new ConfigWriter(group);
this.settings = writer.load(); this.settings = writer.load();
this.registerEntries(); this.registerEntries();
if (settings.size() > 0) { if (settings.size() > 0) {
this.configKeeper.fromJson(settings); this.configKeeper.fromJson(settings);
} else { } else {
this.configKeeper.toJson(settings); this.configKeeper.toJson(settings);
this.writer.save(); this.writer.save();
} }
} }
@Override @Override
protected void registerEntries() {} protected void registerEntries() {}
@Override @Override
public void saveChanges() { public void saveChanges() {
this.configKeeper.toJson(settings); this.configKeeper.toJson(settings);
this.writer.saveConfig(); this.writer.saveConfig();
} }
public String getCategory(EndBiome biome) { private ConfigKey createKey(Identifier biome, String key) {
Identifier biomeId = biome.getID(); Identifier groupId = new Identifier(group, biome.getNamespace());
return biomeId.getPath(); Identifier categoryId = new Identifier(biome.getPath(), key);
} return new ConfigKey(groupId, categoryId);
}
@Nullable
public <E extends Entry<?>> E getEntry(EndBiome biome, String key) { @Nullable
return this.getEntry(getCategory(biome), key); public <E extends Entry<?>> E getEntry(EndBiome biome, String key) {
} return this.getEntry(createKey(biome.getID(), key));
}
@Nullable
public <T> T getDefault(EndBiome biome, String key) { @Nullable
return this.getDefault(getCategory(biome), key); public <T> T getDefault(EndBiome biome, String key) {
} return this.getDefault(createKey(biome.getID(), key));
}
public String getString(EndBiome biome, String key, String defaultValue) {
return this.getString(getCategory(biome), key, defaultValue); public String getString(EndBiome biome, String key, String defaultValue) {
} return this.getString(createKey(biome.getID(), key), defaultValue);
}
public String getString(EndBiome biome, String key) {
return this.getString(getCategory(biome), key); public String getString(EndBiome biome, String key) {
} return this.getString(createKey(biome.getID(), key));
}
public boolean setString(EndBiome biome, String key, String value) {
return this.setString(getCategory(biome), key, value); public boolean setString(EndBiome biome, String key, String value) {
} return this.setString(createKey(biome.getID(), key), value);
}
public int getInt(EndBiome biome, String key, int defaultValue) {
return this.getInt(getCategory(biome), key, defaultValue); public int getInt(EndBiome biome, String key, int defaultValue) {
} return this.getInt(createKey(biome.getID(), key), defaultValue);
}
public int getInt(EndBiome biome, String key) {
return this.getInt(getCategory(biome), key); public int getInt(EndBiome biome, String key) {
} return this.getInt(createKey(biome.getID(), key));
}
public boolean setInt(EndBiome biome, String key, int value) {
return this.setInt(getCategory(biome), key, value); public boolean setInt(EndBiome biome, String key, int value) {
} return this.setInt(createKey(biome.getID(), key), value);
}
public <T extends Comparable<T>> boolean setRanged(EndBiome biome, String key, T value) {
return this.setRanged(getCategory(biome), key, value); public <T extends Comparable<T>> boolean setRanged(EndBiome biome, String key, T value) {
} return this.setRanged(createKey(biome.getID(), key), value);
}
public float getFloat(EndBiome biome, String key, float defaultValue) {
return this.getFloat(getCategory(biome), key, defaultValue); public float getFloat(EndBiome biome, String key, float defaultValue) {
} return this.getFloat(createKey(biome.getID(), key), defaultValue);
}
public float getFloat(EndBiome biome, String key) {
return this.getFloat(getCategory(biome), key); public float getFloat(EndBiome biome, String key) {
} return this.getFloat(createKey(biome.getID(), key));
}
public boolean setFloat(EndBiome biome, String key, float value) {
return this.setFloat(getCategory(biome), key, value); public boolean setFloat(EndBiome biome, String key, float value) {
} return this.setFloat(createKey(biome.getID(), key), value);
}
public boolean getBoolean(EndBiome biome, String key, boolean defaultValue) {
return this.getBoolean(getCategory(biome), key, defaultValue); public boolean getBoolean(EndBiome biome, String key, boolean defaultValue) {
} return this.getBoolean(createKey(biome.getID(), key), defaultValue);
}
public boolean getBoolean(EndBiome biome, String key) {
return this.getBoolean(getCategory(biome), key); public boolean getBoolean(EndBiome biome, String key) {
} return this.getBoolean(createKey(biome.getID(), key));
}
public boolean setBoolean(EndBiome biome, String key, boolean value) {
return this.setBoolean(getCategory(biome), key, value); public boolean setBoolean(EndBiome biome, String key, boolean value) {
} return this.setBoolean(createKey(biome.getID(), key), value);
} }
}

View file

@ -4,7 +4,6 @@ import org.jetbrains.annotations.Nullable;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.util.JsonHelper;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.config.ConfigKeeper.BooleanEntry; import ru.betterend.config.ConfigKeeper.BooleanEntry;
import ru.betterend.config.ConfigKeeper.Entry; import ru.betterend.config.ConfigKeeper.Entry;
@ -22,25 +21,23 @@ public abstract class Config {
protected abstract void registerEntries(); protected abstract void registerEntries();
@Nullable @Nullable
public <E extends Entry<?>> E getEntry(String category, String key) { public <E extends Entry<?>> E getEntry(ConfigKey key) {
return this.configKeeper.getEntry(category, key); return this.configKeeper.getEntry(key);
} }
@Nullable @Nullable
public <T> T getDefault(String category, String key) { public <T> T getDefault(ConfigKey key) {
Entry<T> entry = configKeeper.getEntry(category, key); Entry<T> entry = configKeeper.getEntry(key);
return entry != null ? entry.getDefault() : null; return entry != null ? entry.getDefault() : null;
} }
public String getString(String category, String key, String defaultValue) { public String getString(ConfigKey key, String defaultValue) {
String str = configKeeper.getValue(category, key); String str = configKeeper.getValue(key);
if (str == null) { if (str == null) {
StringEntry entry = this.configKeeper.registerEntry(category, key, new StringEntry(defaultValue)); StringEntry entry = this.configKeeper.registerEntry(key, new StringEntry(defaultValue));
if (settings != null && settings.has(category)) { if (settings != null) {
JsonObject params = JsonHelper.getObject(settings, category); if (settings != null) {
key += " [default: " + defaultValue + "]"; this.configKeeper.loadFromJson(settings, key, entry);
if (params.has(key)) {
entry.fromString(JsonHelper.getString(params, key));
return entry.getValue(); return entry.getValue();
} }
} }
@ -48,35 +45,30 @@ public abstract class Config {
return str != null ? str : defaultValue; return str != null ? str : defaultValue;
} }
public String getString(String category, String key) { public String getString(ConfigKey key) {
String str = configKeeper.getValue(category, key); String str = configKeeper.getValue(key);
return str != null ? str : ""; return str != null ? str : "";
} }
public boolean setString(String category, String key, String value) { public boolean setString(ConfigKey key, String value) {
try { try {
StringEntry entry = configKeeper.getEntry(category, key); StringEntry entry = configKeeper.getEntry(key);
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
this.configKeeper.set(category, key, entry);
return true; return true;
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.catching(ex);
} }
return false; return false;
} }
public int getInt(String category, String key, int defaultValue) { public int getInt(ConfigKey key, int defaultValue) {
Integer val = configKeeper.getValue(category, key); Integer val = configKeeper.getValue(key);
if (val == null) { if (val == null) {
IntegerEntry entry = this.configKeeper.registerEntry(category, key, new IntegerEntry(defaultValue)); IntegerEntry entry = this.configKeeper.registerEntry(key, new IntegerEntry(defaultValue));
if (settings != null && settings.has(category)) { if (settings != null) {
JsonObject params = JsonHelper.getObject(settings, category); if (settings != null) {
key += " [default: " + defaultValue + "]"; this.configKeeper.loadFromJson(settings, key, entry);
if (params.has(key)) {
entry.fromString(JsonHelper.getString(params, key));
return entry.getValue(); return entry.getValue();
} }
} }
@ -84,50 +76,42 @@ public abstract class Config {
return val != null ? val : defaultValue; return val != null ? val : defaultValue;
} }
public int getInt(String category, String key) { public int getInt(ConfigKey key) {
Integer val = configKeeper.getValue(category, key); Integer val = configKeeper.getValue(key);
return val != null ? val : 0; return val != null ? val : 0;
} }
public boolean setInt(String category, String key, int value) { public boolean setInt(ConfigKey key, int value) {
try { try {
IntegerEntry entry = configKeeper.getEntry(category, key); IntegerEntry entry = configKeeper.getEntry(key);
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
this.configKeeper.set(category, key, entry);
return true; return true;
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.catching(ex);
} }
return false; return false;
} }
public <T extends Comparable<T>> boolean setRanged(String category, String key, T value) { public <T extends Comparable<T>> boolean setRanged(ConfigKey key, T value) {
try { try {
RangeEntry<T> entry = configKeeper.getEntry(category, key); RangeEntry<T> entry = configKeeper.getEntry(key);
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
this.configKeeper.set(category, key, entry);
return true; return true;
} catch (NullPointerException | ClassCastException ex) { } catch (NullPointerException | ClassCastException ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.catching(ex);
} }
return false; return false;
} }
public float getFloat(String category, String key, float defaultValue) { public float getFloat(ConfigKey key, float defaultValue) {
Float val = configKeeper.getValue(category, key); Float val = configKeeper.getValue(key);
if (val == null) { if (val == null) {
FloatEntry entry = this.configKeeper.registerEntry(category, key, new FloatEntry(defaultValue)); FloatEntry entry = this.configKeeper.registerEntry(key, new FloatEntry(defaultValue));
if (settings != null && settings.has(category)) { if (settings != null) {
JsonObject params = JsonHelper.getObject(settings, category); if (settings != null) {
key += " [default: " + defaultValue + "]"; this.configKeeper.loadFromJson(settings, key, entry);
if (params.has(key)) {
entry.fromString(JsonHelper.getString(params, key));
return entry.getValue(); return entry.getValue();
} }
} }
@ -135,59 +119,49 @@ public abstract class Config {
return val != null ? val : defaultValue; return val != null ? val : defaultValue;
} }
public float getFloat(String category, String key) { public float getFloat(ConfigKey key) {
Float val = configKeeper.getValue(category, key); Float val = configKeeper.getValue(key);
return val != null ? val : 0.0F; return val != null ? val : 0.0F;
} }
public boolean setFloat(String category, String key, float value) { public boolean setFloat(ConfigKey key, float value) {
try { try {
FloatEntry entry = configKeeper.getEntry(category, key); FloatEntry entry = configKeeper.getEntry(key);
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
this.configKeeper.set(category, key, entry);
return true; return true;
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.catching(ex);
} }
return false; return false;
} }
public boolean getBoolean(String category, String key, boolean defaultValue) { public boolean getBoolean(ConfigKey key, boolean defaultValue) {
Boolean val = configKeeper.getValue(category, key); Boolean val = configKeeper.getValue(key);
if (val == null) { if (val == null) {
BooleanEntry entry = this.configKeeper.registerEntry(category, key, new BooleanEntry(defaultValue)); BooleanEntry entry = this.configKeeper.registerEntry(key, new BooleanEntry(defaultValue));
if (settings != null && settings.has(category)) { if (settings != null) {
JsonObject params = JsonHelper.getObject(settings, category); this.configKeeper.loadFromJson(settings, key, entry);
key += " [default: " + defaultValue + "]"; return entry.getValue();
if (params.has(key)) {
entry.fromString(JsonHelper.getString(params, key));
return entry.getValue();
}
} }
} }
return val != null ? val : defaultValue; return val != null ? val : defaultValue;
} }
public boolean getBoolean(String category, String key) { public boolean getBoolean(ConfigKey key) {
Boolean val = configKeeper.getValue(category, key); Boolean val = configKeeper.getValue(key);
return val != null ? val : false; return val != null ? val : false;
} }
public boolean setBoolean(String category, String key, boolean value) { public boolean setBoolean(ConfigKey key, boolean value) {
try { try {
BooleanEntry entry = configKeeper.getEntry(category, key); BooleanEntry entry = configKeeper.getEntry(key);
if (entry == null) return false; if (entry == null) return false;
entry.setValue(value); entry.setValue(value);
this.configKeeper.set(category, key, entry);
return true; return true;
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
BetterEnd.LOGGER.catching(ex); BetterEnd.LOGGER.catching(ex);
} }
return false; return false;
} }
} }

View file

@ -8,74 +8,83 @@ import com.google.common.collect.Maps;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.minecraft.util.Identifier;
import net.minecraft.util.JsonHelper; import net.minecraft.util.JsonHelper;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
public final class ConfigKeeper { public final class ConfigKeeper {
private Map<String, Map<String, Entry<?>>> configEntries = Maps.newHashMap(); private Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
public JsonElement toJson(JsonObject jsonObject) { public JsonElement toJson(JsonObject jsonObject) {
for (String category : configEntries.keySet()) { this.configEntries.forEach((key, entry) -> {
Map<String, Entry<?>> entryCategory = this.configEntries.get(category); Identifier categoryId = key.getCategory();
JsonObject jsonCategory = new JsonObject(); Identifier paramId = key.getParameter();
entryCategory.forEach((key, param) -> { String group = categoryId.getPath();
key += " [default: " + param.getDefault() + "]"; JsonObject jsonGroup;
jsonCategory.addProperty(key, param.asString()); if (jsonObject.has(group)) {
}); jsonGroup = JsonHelper.getObject(jsonObject, group);
jsonObject.add(category, jsonCategory); } else {
} jsonGroup = new JsonObject();
jsonObject.add(group, jsonGroup);
}
String category = paramId.getNamespace();
JsonObject jsonCategory;
if (jsonGroup.has(category)) {
jsonCategory = JsonHelper.getObject(jsonGroup, category);
} else {
jsonCategory = new JsonObject();
jsonGroup.add(category, jsonCategory);
}
String paramKey = paramId.getPath();
paramKey += " [default: " + entry.getDefault() + "]";
jsonCategory.addProperty(paramKey, entry.asString());
});
return jsonObject; return jsonObject;
} }
public void fromJson(JsonObject jsonObject) { public void fromJson(JsonObject jsonObject) {
if (jsonObject.size() == 0) return; if (jsonObject.size() == 0) return;
for (String category : configEntries.keySet()) { this.configEntries.forEach((key, entry) -> {
Map<String, Entry<?>> entryCategory = this.configEntries.get(category); this.loadFromJson(jsonObject, key, entry);
if (!jsonObject.has(category)) continue; });
JsonObject jsonCategory = jsonObject.getAsJsonObject(category); }
entryCategory.forEach((key, param) -> {
key += " [default: " + param.getDefault() + "]"; public <E extends Entry<?>> void loadFromJson(JsonObject jsonObject, ConfigKey key, E entry) {
if (!jsonCategory.has(key)) return; Identifier categoryId = key.getCategory();
param.fromString(JsonHelper.getString(jsonCategory, key)); Identifier paramId = key.getParameter();
}); String group = categoryId.getPath();
} if (!jsonObject.has(group)) return;
JsonObject jsonGroup = JsonHelper.getObject(jsonObject, group);
String category = paramId.getNamespace();
if (jsonGroup.has(category)) return;
JsonObject jsonCategory = JsonHelper.getObject(jsonGroup, category);
String paramKey = paramId.getPath();
paramKey += " [default: " + entry.getDefault() + "]";
entry.fromString(JsonHelper.getString(jsonCategory, paramKey));
} }
@Nullable @Nullable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <E extends Entry<?>> E getEntry(String category, String key) { public <E extends Entry<?>> E getEntry(ConfigKey key) {
Map<String, Entry<?>> entryCategory = this.configEntries.get(category); return (E) this.configEntries.get(key);
if (entryCategory == null) {
return null;
}
return (E) entryCategory.get(key);
} }
@Nullable @Nullable
public <T> T getValue(String category, String key) { public <T> T getValue(ConfigKey key) {
Entry<T> entry = this.getEntry(category, key); Entry<T> entry = this.getEntry(key);
if (entry == null) { if (entry == null) {
return null; return null;
} }
return entry.getValue(); return entry.getValue();
} }
public void set(String category, String key, Entry<?> entry) { public <T extends Entry<?>> T registerEntry(ConfigKey key, T entry) {
Map<String, Entry<?>> entryCategory = this.configEntries.get(category); this.configEntries.put(key, entry);
if (entryCategory != null) {
entryCategory.put(key, entry);
}
}
public <T extends Entry<?>> T registerEntry(String category, String key, T entry) {
Map<String, Entry<?>> entryCategory = this.configEntries.get(category);
if (entryCategory == null) {
entryCategory = Maps.newHashMap();
this.configEntries.put(category, entryCategory);
}
entryCategory.put(key, entry);
return entry; return entry;
} }

View file

@ -0,0 +1,56 @@
package ru.betterend.config;
import net.minecraft.util.Identifier;
public class ConfigKey {
private final Identifier category;
private final Identifier parameter;
public ConfigKey(Identifier category, Identifier parameter) {
this.category = category;
this.parameter = parameter;
}
public Identifier getCategory() {
return category;
}
public Identifier getParameter() {
return parameter;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((parameter == null) ? 0 : parameter.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ConfigKey)) {
return false;
}
ConfigKey other = (ConfigKey) obj;
if (category == null) {
if (other.category != null) {
return false;
}
} else if (!category.equals(other.category)) {
return false;
}
if (parameter == null) {
if (other.parameter != null) {
return false;
}
} else if (!parameter.equals(other.parameter)) {
return false;
}
return true;
}
}

View file

@ -0,0 +1,100 @@
package ru.betterend.config;
import org.jetbrains.annotations.Nullable;
import net.minecraft.util.Identifier;
import ru.betterend.config.ConfigKeeper.Entry;
public class ItemConfig extends Config {
private final ConfigWriter writer;
private final String group = "settings";
protected ItemConfig() {
this.writer = new ConfigWriter(group);
this.settings = this.writer.load();
this.registerEntries();
if (settings.size() > 0) {
this.configKeeper.fromJson(settings);
} else {
this.configKeeper.toJson(settings);
this.writer.save();
}
}
private ConfigKey createKey(Identifier item, String category) {
Identifier groupId = new Identifier(group, item.getNamespace());
Identifier categoryId = new Identifier(category, item.getPath());
return new ConfigKey(groupId, categoryId);
}
@Override
protected void registerEntries() {}
@Override
public void saveChanges() {
this.configKeeper.toJson(settings);
this.writer.save();
}
@Nullable
public <E extends Entry<?>> E getEntry(Identifier item, String category) {
return this.getEntry(createKey(item, category));
}
@Nullable
public <T> T getDefault(Identifier item, String category) {
return this.getDefault(createKey(item, category));
}
public String getString(Identifier item, String category, String defaultValue) {
return this.getString(createKey(item, category), defaultValue);
}
public String getString(Identifier item, String category) {
return this.getString(createKey(item, category));
}
public boolean setString(Identifier item, String category, String value) {
return this.setString(createKey(item, category), value);
}
public int getInt(Identifier item, String category, int defaultValue) {
return this.getInt(createKey(item, category), defaultValue);
}
public int getInt(Identifier item, String category) {
return this.getInt(createKey(item, category));
}
public boolean setInt(Identifier item, String category, int value) {
return this.setInt(createKey(item, category), value);
}
public <T extends Comparable<T>> boolean setRanged(Identifier item, String category, T value) {
return this.setRanged(createKey(item, category), value);
}
public float getFloat(Identifier item, String category, float defaultValue) {
return this.getFloat(createKey(item, category), defaultValue);
}
public float getFloat(Identifier item, String category) {
return this.getFloat(createKey(item, category));
}
public boolean setFloat(Identifier item, String category, float value) {
return this.setFloat(createKey(item, category), value);
}
public boolean getBoolean(Identifier item, String category, boolean defaultValue) {
return this.getBoolean(createKey(item, category), defaultValue);
}
public boolean getBoolean(Identifier item, String category) {
return this.getBoolean(createKey(item, category));
}
public boolean setBoolean(Identifier item, String category, boolean value) {
return this.setBoolean(createKey(item, category), value);
}
}

View file

@ -1,37 +1,28 @@
package ru.betterend.config; package ru.betterend.config;
public class MainConfig extends Config { public class MainConfig {
public static final ItemConfig ITEM_CONFIG = getItemConfig();
private static MainConfig instance; public static final BiomeConfig BIOME_CONFIG = getBiomeConfig();
public static MainConfig getInstance() { private static ItemConfig itemConfig;
if (instance == null) { private static BiomeConfig biomeConfig;
instance = new MainConfig();
} public static ItemConfig getItemConfig() {
if (itemConfig == null) {
return instance; itemConfig = new ItemConfig();
} }
return itemConfig;
private final ConfigWriter writer; }
private MainConfig() { public static BiomeConfig getBiomeConfig() {
this.writer = new ConfigWriter("settings"); if (biomeConfig == null) {
this.settings = this.writer.load(); biomeConfig = new BiomeConfig();
this.registerEntries(); }
if (settings.size() > 0) { return biomeConfig;
this.configKeeper.fromJson(settings); }
} else {
this.configKeeper.toJson(settings); public static void saveConfig() {
this.writer.save(); itemConfig.saveChanges();
} biomeConfig.saveChanges();
} }
}
@Override
protected void registerEntries() {}
@Override
public void saveChanges() {
this.configKeeper.toJson(settings);
this.writer.save();
}
}

View file

@ -0,0 +1,12 @@
package ru.betterend.item.model;
import net.minecraft.client.render.entity.model.BipedEntityModel;
import net.minecraft.entity.LivingEntity;
public class CrystaliteArmorModel extends BipedEntityModel<LivingEntity> {
public CrystaliteArmorModel(float scale) {
super(scale);
}
}

View file

@ -65,11 +65,12 @@ import ru.betterend.blocks.basis.BlockWallPlant;
import ru.betterend.blocks.complex.ColoredMaterial; import ru.betterend.blocks.complex.ColoredMaterial;
import ru.betterend.blocks.complex.StoneMaterial; import ru.betterend.blocks.complex.StoneMaterial;
import ru.betterend.blocks.complex.WoodenMaterial; import ru.betterend.blocks.complex.WoodenMaterial;
import ru.betterend.config.ItemConfig;
import ru.betterend.config.MainConfig; import ru.betterend.config.MainConfig;
import ru.betterend.tab.CreativeTab; import ru.betterend.tab.CreativeTab;
public class EndBlocks { public class EndBlocks {
private static final MainConfig CONFIG = MainConfig.getInstance(); private static final ItemConfig CONFIG = MainConfig.ITEM_CONFIG;
// Terrain // // Terrain //
public static final Block ENDSTONE_DUST = registerBlock("endstone_dust", new BlockEndstoneDust()); public static final Block ENDSTONE_DUST = registerBlock("endstone_dust", new BlockEndstoneDust());
@ -207,7 +208,7 @@ public class EndBlocks {
public static void register() {} public static void register() {}
public static Block registerBlock(Identifier id, Block block) { public static Block registerBlock(Identifier id, Block block) {
if (!CONFIG.getBoolean("blocks", id.getPath(), true)) { if (!CONFIG.getBoolean(id, "blocks", true)) {
return block; return block;
} }
Registry.register(Registry.BLOCK, id, block); Registry.register(Registry.BLOCK, id, block);

View file

@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.config.ItemConfig;
import ru.betterend.config.MainConfig; import ru.betterend.config.MainConfig;
import ru.betterend.item.EndArmorMaterial; import ru.betterend.item.EndArmorMaterial;
import ru.betterend.item.EndAxe; import ru.betterend.item.EndAxe;
@ -44,7 +45,7 @@ import ru.betterend.util.TagHelper;
public class EndItems { public class EndItems {
private static final MainConfig CONFIG = MainConfig.getInstance(); private static final ItemConfig CONFIG = MainConfig.ITEM_CONFIG;
private static final List<Item> MOD_BLOCKS = Lists.newArrayList(); private static final List<Item> MOD_BLOCKS = Lists.newArrayList();
private static final List<Item> MOD_ITEMS = Lists.newArrayList(); private static final List<Item> MOD_ITEMS = Lists.newArrayList();
@ -106,7 +107,7 @@ public class EndItems {
} }
public static Item registerItem(Identifier id, Item item) { public static Item registerItem(Identifier id, Item item) {
if (!(item instanceof BlockItem) && !CONFIG.getBoolean("items", id.getPath(), true)) { if (!(item instanceof BlockItem) && !CONFIG.getBoolean(id, "items", true)) {
return item; return item;
} }
if (item != Items.AIR) { if (item != Items.AIR) {
@ -120,10 +121,11 @@ public class EndItems {
} }
protected static ToolItem registerTool(String name, ToolItem item) { protected static ToolItem registerTool(String name, ToolItem item) {
if (!CONFIG.getBoolean("items", name, true)) { Identifier id = BetterEnd.makeID(name);
if (!CONFIG.getBoolean(id, "items", true)) {
return item; return item;
} }
Registry.register(Registry.ITEM, BetterEnd.makeID(name), item); Registry.register(Registry.ITEM, id, item);
MOD_ITEMS.add(item); MOD_ITEMS.add(item);
if (item instanceof ShovelItem) { if (item instanceof ShovelItem) {