forked from TAIGA/TAIGA
first attempt ti implement a config file, does not function atm
This commit is contained in:
84
build.gradle
84
build.gradle
@@ -71,6 +71,7 @@ minecraft {
|
||||
replace "${version}", project.version
|
||||
}
|
||||
|
||||
//noinspection GroovyAssignabilityCheck
|
||||
ext.mc_version = project.minecraft.version.split('-')[0]
|
||||
version = "${mc_version}-${project.buildInfo.revision}"
|
||||
|
||||
@@ -141,85 +142,4 @@ curseforge {
|
||||
requiredLibrary 'tinkers-construct'
|
||||
}
|
||||
}
|
||||
}
|
||||
/* FOR AUTO JSON
|
||||
ext.args = [:]
|
||||
|
||||
ext.requireArgument = {String property, String displayValue ->
|
||||
def value = args[property]
|
||||
if (value == null) {
|
||||
throw new InvalidUserDataException("$property must be set with \'$property=$displayValue\'")
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
tasks.addRule("Pattern: <property>=<value>: Passes arguments to the scripts") { String taskName ->
|
||||
def match = taskName =~ /(.*?)=(.*?$)/
|
||||
if (match) {
|
||||
def property = match[0][1]
|
||||
def value = match[0][2]
|
||||
ext.args[property] = value;
|
||||
task(taskName) << {
|
||||
println "Passes value \'$value\' to args[\'$property\']"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
import org.apache.tools.ant.filters.FixCrLfFilter
|
||||
|
||||
class CopyJsonTemplate extends DefaultTask {
|
||||
@Input
|
||||
def template
|
||||
|
||||
@Input
|
||||
def arguments
|
||||
|
||||
@Input
|
||||
def jsonRename
|
||||
|
||||
@TaskAction
|
||||
def build() {
|
||||
def args = arguments()
|
||||
project.copy {
|
||||
from("templates/${template}") {
|
||||
expand(args)
|
||||
filter(FixCrLfFilter, eol: FixCrLfFilter.CrLf.newInstance('crlf'))
|
||||
}
|
||||
into 'src/main/resources'
|
||||
rename { String filename ->
|
||||
def match = filename =~ /(.*)\.json/
|
||||
if (match) {
|
||||
def prevFilename = match[0][1]
|
||||
def newFilename = jsonRename.call(prevFilename)
|
||||
return "${newFilename}.json"
|
||||
}
|
||||
else {
|
||||
return filename
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task generateBlockModel(type: CopyJsonTemplate) {
|
||||
template 'block'
|
||||
arguments {
|
||||
def blockName = requireArgument('blockName', 'block_name')
|
||||
return ['modid':archivesBaseName, 'block_name':blockName]
|
||||
}
|
||||
jsonRename {
|
||||
return args['blockName']
|
||||
}
|
||||
}
|
||||
|
||||
task generateItemModel(type: CopyJsonTemplate) {
|
||||
template 'item'
|
||||
arguments {
|
||||
def itemName = requireArgument('itemName', 'item_name')
|
||||
return ['modid':archivesBaseName, 'item_name':itemName]
|
||||
}
|
||||
jsonRename {
|
||||
return args['itemName']
|
||||
}
|
||||
}*/
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
package com.sosnitzka.taiga;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sosnitzka.taiga.proxy.ServerProxy;
|
||||
import com.sosnitzka.taiga.proxy.CommonProxy;
|
||||
import com.sosnitzka.taiga.recipes.Crafting;
|
||||
import com.sosnitzka.taiga.recipes.Smelting;
|
||||
import com.sosnitzka.taiga.util.FuelHandler;
|
||||
@@ -31,19 +31,22 @@ import static com.sosnitzka.taiga.Fluids.*;
|
||||
import static com.sosnitzka.taiga.MaterialTraits.*;
|
||||
import static slimeknights.tconstruct.library.utils.HarvestLevels.*;
|
||||
|
||||
@Mod(modid = TAIGA.MODID, version = TAIGA.VERSION, dependencies = "required-after:tconstruct@[1.10-2.3.3,);" + "required-after:mantle@[1.10-0.10.3,)")
|
||||
@Mod(modid = TAIGA.MODID, version = TAIGA.VERSION, guiFactory = TAIGA.GUIFACTORY, dependencies = "required-after:tconstruct@[1.10-2.3.3,);" + "required-after:mantle@[1.10-0.10.3,)")
|
||||
public class TAIGA {
|
||||
|
||||
public static final String MODID = "taiga";
|
||||
public static final String VERSION = "${version}";
|
||||
public static final String GUIFACTORY = "com.sosnitzka.taiga.TAIGAGuiFactory";
|
||||
|
||||
@SidedProxy(clientSide = "com.sosnitzka.taiga.proxy.ClientProxy", serverSide = "com.sosnitzka.taiga.proxy.ServerProxy")
|
||||
public static ServerProxy proxy;
|
||||
@SidedProxy(clientSide = "com.sosnitzka.taiga.proxy.ClientProxy", serverSide = "com.sosnitzka.taiga.proxy.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
private List<MaterialIntegration> integrateList = Lists.newArrayList(); // List of materials needed to be integrated
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
proxy.initConfig();
|
||||
|
||||
Items.register(); // Registers items and its oreDict
|
||||
Blocks.register(); // Registers blocks and its items form a long with its oreDict
|
||||
Fluids.register(); // Registers all fluids and its buckets
|
||||
@@ -70,8 +73,6 @@ public class TAIGA {
|
||||
for (MaterialIntegration m : integrateList) {
|
||||
m.integrateRecipes();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -93,7 +94,6 @@ public class TAIGA {
|
||||
* @param craft Can craft parts in part builder
|
||||
* @param cast Can craft parts by casting with fluid (smeltery)
|
||||
*/
|
||||
|
||||
private void registerTinkerMaterial(String oreSuffix, Material material, Fluid fluid, int headDura, float headSpeed, float headAttack, float handleMod, int handleDura, int extra, int headLevel, boolean craft, boolean cast) {
|
||||
TinkerRegistry.addMaterialStats(material, new HeadMaterialStats(headDura, headSpeed, headAttack, headLevel));
|
||||
TinkerRegistry.addMaterialStats(material, new HandleMaterialStats(handleMod, handleDura));
|
||||
|
104
src/main/java/com/sosnitzka/taiga/TAIGAConfiguration.java
Normal file
104
src/main/java/com/sosnitzka/taiga/TAIGAConfiguration.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.sosnitzka.taiga;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TAIGAConfiguration {
|
||||
public static final String CATEGORY_NAME_GENERAL = "category_general";
|
||||
public static final String CATEGORY_NAME_ORE = "category_ore";
|
||||
public static int oreResistenceFactor;
|
||||
public static boolean slagIronGen;
|
||||
private static Configuration config = null;
|
||||
|
||||
public static void preInit() {
|
||||
File configFile = new File(Loader.instance().getConfigDir(), "TAIGA.cfg");
|
||||
config = new Configuration(configFile);
|
||||
|
||||
syncFromFile();
|
||||
}
|
||||
|
||||
public static void clientPreInit() {
|
||||
MinecraftForge.EVENT_BUS.register(new ConfigEventHandler());
|
||||
}
|
||||
|
||||
public static Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void syncFromFile() {
|
||||
syncConfig(true, true);
|
||||
}
|
||||
|
||||
public static void syncFromGUI() {
|
||||
syncConfig(false, true);
|
||||
}
|
||||
|
||||
public static void syncFromFields() {
|
||||
syncConfig(false, false);
|
||||
}
|
||||
|
||||
private static void syncConfig(boolean loadConfigFromFile, boolean readFieldsFromConfig) {
|
||||
if (loadConfigFromFile) {
|
||||
config.load();
|
||||
}
|
||||
|
||||
final int RESMUT_MIN_VALUE = 0;
|
||||
final int RESMUT_MAX_VALUE = 9999;
|
||||
final int RESMUT_DEFAULT_VALUE = 1;
|
||||
Property resMultiplier = config.get(CATEGORY_NAME_ORE, "res_multiplier", RESMUT_DEFAULT_VALUE,
|
||||
"Resistance multiplier", RESMUT_MIN_VALUE, RESMUT_MAX_VALUE);
|
||||
resMultiplier.setLanguageKey("gui.taiga_configuration.res_multiplier");
|
||||
|
||||
final boolean SLAGIRONGEN_DEFAULT_VALUE = true;
|
||||
Property slagIronSwitch = config.get(CATEGORY_NAME_GENERAL, "switch_slagiron", SLAGIRONGEN_DEFAULT_VALUE);
|
||||
slagIronSwitch.setComment("Switch slagiron on/off");
|
||||
slagIronSwitch.setLanguageKey("gui.taiga_configuration.gen_slagiron");
|
||||
|
||||
List<String> propOrderGeneral = new ArrayList<String>();
|
||||
propOrderGeneral.add(slagIronSwitch.getName());
|
||||
config.setCategoryPropertyOrder(CATEGORY_NAME_GENERAL, propOrderGeneral);
|
||||
|
||||
List<String> propOrderOre = new ArrayList<String>();
|
||||
propOrderOre.add(resMultiplier.getName());
|
||||
config.setCategoryPropertyOrder(CATEGORY_NAME_ORE, propOrderOre);
|
||||
|
||||
|
||||
if (readFieldsFromConfig) {
|
||||
//If getInt cannot get an integer value from the config file value of myInteger (e.g. corrupted file)
|
||||
// it will set it to the default value passed to the function
|
||||
oreResistenceFactor = resMultiplier.getInt(RESMUT_DEFAULT_VALUE);
|
||||
if (oreResistenceFactor > RESMUT_MAX_VALUE || oreResistenceFactor < RESMUT_MIN_VALUE) {
|
||||
oreResistenceFactor = RESMUT_DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
slagIronGen = slagIronSwitch.getBoolean(SLAGIRONGEN_DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
resMultiplier.set(oreResistenceFactor);
|
||||
slagIronSwitch.set(slagIronGen);
|
||||
|
||||
if (config.hasChanged()) {
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConfigEventHandler {
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public void onEvent(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (TAIGA.MODID.equals(event.getModID()) && !event.isWorldRunning()) {
|
||||
if (event.getConfigID().equals(CATEGORY_NAME_GENERAL) || event.getConfigID().equals(CATEGORY_NAME_ORE)) {
|
||||
syncFromGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
82
src/main/java/com/sosnitzka/taiga/TAIGAGuiFactory.java
Normal file
82
src/main/java/com/sosnitzka/taiga/TAIGAGuiFactory.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.sosnitzka.taiga;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.common.config.ConfigElement;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||
import net.minecraftforge.fml.client.config.DummyConfigElement;
|
||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||
import net.minecraftforge.fml.client.config.GuiConfigEntries;
|
||||
import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TAIGAGuiFactory implements IModGuiFactory {
|
||||
@Override
|
||||
public void initialize(Minecraft minecraftInstance) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends GuiScreen> mainConfigGuiClass() {
|
||||
return TAIGAConfigGui.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class TAIGAConfigGui extends GuiConfig {
|
||||
public TAIGAConfigGui(GuiScreen parentScreen) {
|
||||
super(parentScreen, getConfigElements(), TAIGA.MODID, false, false, I18n.format("gui.taiga_configuration.mainTitle"));
|
||||
}
|
||||
|
||||
private static List<IConfigElement> getConfigElements() {
|
||||
List<IConfigElement> list = new ArrayList<IConfigElement>();
|
||||
list.add(new DummyConfigElement.DummyCategoryElement("mainCfg", "gui.taiga_configuration.ctgy.general", CategoryEntryGeneral.class));
|
||||
list.add(new DummyConfigElement.DummyCategoryElement("oreCfg", "gui.taiga_configuration.ctgy.ore", CategoryEntryOre.class));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static class CategoryEntryGeneral extends GuiConfigEntries.CategoryEntry {
|
||||
public CategoryEntryGeneral(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop) {
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen() {
|
||||
Configuration configuration = TAIGAConfiguration.getConfig();
|
||||
ConfigElement cat_general = new ConfigElement(configuration.getCategory(TAIGAConfiguration.CATEGORY_NAME_GENERAL));
|
||||
List<IConfigElement> propertiesOnThisScreen = cat_general.getChildElements();
|
||||
String windowTitle = configuration.toString();
|
||||
|
||||
return new GuiConfig(this.owningScreen, propertiesOnThisScreen, this.owningScreen.modID, TAIGAConfiguration.CATEGORY_NAME_GENERAL, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart, this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, windowTitle);
|
||||
}
|
||||
}
|
||||
|
||||
public static class CategoryEntryOre extends GuiConfigEntries.CategoryEntry {
|
||||
public CategoryEntryOre(GuiConfig owningScreen, GuiConfigEntries owningEntryList, IConfigElement prop) {
|
||||
super(owningScreen, owningEntryList, prop);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiScreen buildChildScreen() {
|
||||
Configuration configuration = TAIGAConfiguration.getConfig();
|
||||
ConfigElement cat_general = new ConfigElement(configuration.getCategory(TAIGAConfiguration.CATEGORY_NAME_ORE));
|
||||
List<IConfigElement> propertiesOnThisScreen = cat_general.getChildElements();
|
||||
String windowTitle = configuration.toString();
|
||||
|
||||
return new GuiConfig(this.owningScreen, propertiesOnThisScreen, this.owningScreen.modID, TAIGAConfiguration.CATEGORY_NAME_ORE, this.configElement.requiresWorldRestart() || this.owningScreen.allRequireWorldRestart, this.configElement.requiresMcRestart() || this.owningScreen.allRequireMcRestart, windowTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ package com.sosnitzka.taiga.proxy;
|
||||
import com.sosnitzka.taiga.Blocks;
|
||||
import com.sosnitzka.taiga.Items;
|
||||
import com.sosnitzka.taiga.TAIGA;
|
||||
import com.sosnitzka.taiga.TAIGAConfiguration;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -24,7 +25,7 @@ import java.lang.reflect.Field;
|
||||
|
||||
import static com.sosnitzka.taiga.MaterialTraits.*;
|
||||
|
||||
public class ClientProxy extends ServerProxy {
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
||||
private static void registerBlockModel(Block block) {
|
||||
registerItemModel(Item.getItemFromBlock(block));
|
||||
@@ -112,6 +113,11 @@ public class ClientProxy extends ServerProxy {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initConfig() {
|
||||
TAIGAConfiguration.clientPreInit();
|
||||
}
|
||||
|
||||
public static class FluidStateMapper extends StateMapperBase implements ItemMeshDefinition {
|
||||
|
||||
public final Fluid fluid;
|
||||
|
@@ -1,9 +1,10 @@
|
||||
package com.sosnitzka.taiga.proxy;
|
||||
|
||||
import com.sosnitzka.taiga.TAIGAConfiguration;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import slimeknights.tconstruct.library.materials.Material;
|
||||
|
||||
public class ServerProxy {
|
||||
public class CommonProxy {
|
||||
|
||||
public void registerModels() {
|
||||
|
||||
@@ -15,4 +16,8 @@ public class ServerProxy {
|
||||
|
||||
public void registerFluidModels(Fluid fluid) {
|
||||
}
|
||||
|
||||
public void initConfig() {
|
||||
TAIGAConfiguration.preInit();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user