aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/core/mod
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/binnie/core/mod')
-rw-r--r--src/Java/binnie/core/mod/config/BinnieConfiguration.java21
-rw-r--r--src/Java/binnie/core/mod/config/BinnieItemData.java15
-rw-r--r--src/Java/binnie/core/mod/config/ConfigFile.java11
-rw-r--r--src/Java/binnie/core/mod/config/ConfigProperty.java26
-rw-r--r--src/Java/binnie/core/mod/config/ConfigurationMain.java4
-rw-r--r--src/Java/binnie/core/mod/config/ConfigurationMods.java18
-rw-r--r--src/Java/binnie/core/mod/config/ManagerConfig.java71
-rw-r--r--src/Java/binnie/core/mod/config/PropBoolean.java38
-rw-r--r--src/Java/binnie/core/mod/config/PropDouble.java38
-rw-r--r--src/Java/binnie/core/mod/config/PropInteger.java38
-rw-r--r--src/Java/binnie/core/mod/config/PropPercentage.java43
-rw-r--r--src/Java/binnie/core/mod/config/PropertyBase.java72
-rw-r--r--src/Java/binnie/core/mod/parser/FieldParser.java55
-rw-r--r--src/Java/binnie/core/mod/parser/ItemParser.java24
14 files changed, 474 insertions, 0 deletions
diff --git a/src/Java/binnie/core/mod/config/BinnieConfiguration.java b/src/Java/binnie/core/mod/config/BinnieConfiguration.java
new file mode 100644
index 0000000000..09e5a657da
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/BinnieConfiguration.java
@@ -0,0 +1,21 @@
+package binnie.core.mod.config;
+
+import binnie.core.AbstractMod;
+import binnie.core.BinnieCore;
+import binnie.core.proxy.BinnieProxy;
+import java.io.File;
+import net.minecraftforge.common.config.Configuration;
+
+class BinnieConfiguration
+ extends Configuration
+{
+ public AbstractMod mod;
+ private String filename;
+
+ public BinnieConfiguration(String filename, AbstractMod mod)
+ {
+ super(new File(BinnieCore.proxy.getDirectory(), filename));
+ this.mod = mod;
+ this.filename = filename;
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/BinnieItemData.java b/src/Java/binnie/core/mod/config/BinnieItemData.java
new file mode 100644
index 0000000000..435edc122d
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/BinnieItemData.java
@@ -0,0 +1,15 @@
+package binnie.core.mod.config;
+
+class BinnieItemData
+{
+ private int item;
+ private BinnieConfiguration configFile;
+ private String configKey;
+
+ public BinnieItemData(int item, BinnieConfiguration configFile, String configKey)
+ {
+ this.item = item;
+ this.configFile = configFile;
+ this.configKey = configKey;
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/ConfigFile.java b/src/Java/binnie/core/mod/config/ConfigFile.java
new file mode 100644
index 0000000000..425ee52e98
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/ConfigFile.java
@@ -0,0 +1,11 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ConfigFile
+{
+ String filename();
+}
diff --git a/src/Java/binnie/core/mod/config/ConfigProperty.java b/src/Java/binnie/core/mod/config/ConfigProperty.java
new file mode 100644
index 0000000000..d8e5f48339
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/ConfigProperty.java
@@ -0,0 +1,26 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({java.lang.annotation.ElementType.FIELD})
+public @interface ConfigProperty
+{
+ String key();
+
+ String category() default "";
+
+ String[] comment() default {};
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({java.lang.annotation.ElementType.ANNOTATION_TYPE})
+ public static @interface Type
+ {
+ Class<? extends PropertyBase> propertyClass();
+
+ String category() default "general";
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/ConfigurationMain.java b/src/Java/binnie/core/mod/config/ConfigurationMain.java
new file mode 100644
index 0000000000..e7924abe47
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/ConfigurationMain.java
@@ -0,0 +1,4 @@
+package binnie.core.mod.config;
+
+@ConfigFile(filename="/config/forestry/binniecore/main.conf")
+public class ConfigurationMain {}
diff --git a/src/Java/binnie/core/mod/config/ConfigurationMods.java b/src/Java/binnie/core/mod/config/ConfigurationMods.java
new file mode 100644
index 0000000000..77c2f66930
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/ConfigurationMods.java
@@ -0,0 +1,18 @@
+package binnie.core.mod.config;
+
+@ConfigFile(filename="/config/forestry/binnie-mods.conf")
+public class ConfigurationMods
+{
+ @ConfigProperty(key="extraBees", comment={"Enables the Extra Bees Mod."})
+ @PropBoolean
+ public static boolean extraBees = true;
+ @ConfigProperty(key="extraTrees", comment={"Enables the Extra Trees Mod."})
+ @PropBoolean
+ public static boolean extraTrees = true;
+ @ConfigProperty(key="botany", comment={"Enables the Botany Mod."})
+ @PropBoolean
+ public static boolean botany = true;
+ @ConfigProperty(key="genetics", comment={"Enables the Genetics Mod."})
+ @PropBoolean
+ public static boolean genetics = true;
+}
diff --git a/src/Java/binnie/core/mod/config/ManagerConfig.java b/src/Java/binnie/core/mod/config/ManagerConfig.java
new file mode 100644
index 0000000000..16e6df78f4
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/ManagerConfig.java
@@ -0,0 +1,71 @@
+package binnie.core.mod.config;
+
+import binnie.core.AbstractMod;
+import binnie.core.ManagerBase;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import net.minecraftforge.common.config.Configuration;
+
+public class ManagerConfig
+ extends ManagerBase
+{
+ private Map<Class<?>, Configuration> configurations = new LinkedHashMap();
+
+ public void registerConfiguration(Class<?> cls, AbstractMod mod)
+ {
+ if (cls.isAnnotationPresent(ConfigFile.class)) {
+ loadConfiguration(cls, mod);
+ }
+ }
+
+ public void loadConfiguration(Class<?> cls, AbstractMod mod)
+ {
+ try
+ {
+ String filename = ((ConfigFile)cls.getAnnotation(ConfigFile.class)).filename();
+
+
+ BinnieConfiguration config = new BinnieConfiguration(filename, mod);
+
+ config.load();
+ for (Field field : cls.getFields()) {
+ if (field.isAnnotationPresent(ConfigProperty.class))
+ {
+ ConfigProperty propertyAnnot = (ConfigProperty)field.getAnnotation(ConfigProperty.class);
+ PropertyBase property;
+ for (Annotation annotation : field.getAnnotations()) {
+ if (annotation.annotationType().isAnnotationPresent(ConfigProperty.Type.class))
+ {
+ Class<?> propertyClass = ((ConfigProperty.Type)annotation.annotationType().getAnnotation(ConfigProperty.Type.class)).propertyClass();
+
+ property = (PropertyBase)propertyClass.getConstructor(new Class[] { Field.class, BinnieConfiguration.class, ConfigProperty.class, annotation.annotationType() }).newInstance(new Object[] { field, config, propertyAnnot, annotation.annotationType().cast(annotation) });
+ }
+ }
+ }
+ }
+ config.save();
+
+ this.configurations.put(cls, config);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private Map<AbstractMod, List<BinnieItemData>> itemIDs = new HashMap();
+
+ public void addItemID(Integer configValue, String configKey, BinnieConfiguration configFile)
+ {
+ if (!this.itemIDs.containsKey(configFile.mod)) {
+ this.itemIDs.put(configFile.mod, new ArrayList());
+ }
+ ((List)this.itemIDs.get(configFile.mod)).add(new BinnieItemData(configValue.intValue() + 256, configFile, configKey));
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/PropBoolean.java b/src/Java/binnie/core/mod/config/PropBoolean.java
new file mode 100644
index 0000000000..fc9094bdd8
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/PropBoolean.java
@@ -0,0 +1,38 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+@Retention(RetentionPolicy.RUNTIME)
+@ConfigProperty.Type(propertyClass=PropertyBoolean.class)
+public @interface PropBoolean
+{
+ public static class PropertyBoolean
+ extends PropertyBase<Boolean, PropBoolean>
+ {
+ public PropertyBoolean(Field field, BinnieConfiguration file, ConfigProperty configProperty, PropBoolean annotedProperty)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ super(file, configProperty, annotedProperty);
+ }
+
+ protected Property getProperty()
+ {
+ return this.file.get(getCategory(), getKey(), ((Boolean)this.defaultValue).booleanValue());
+ }
+
+ protected Boolean getConfigValue()
+ {
+ return Boolean.valueOf(this.property.getBoolean(((Boolean)this.defaultValue).booleanValue()));
+ }
+
+ protected void addComments()
+ {
+ addComment("Default value is " + this.defaultValue + ".");
+ }
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/PropDouble.java b/src/Java/binnie/core/mod/config/PropDouble.java
new file mode 100644
index 0000000000..331cd2774c
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/PropDouble.java
@@ -0,0 +1,38 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+@Retention(RetentionPolicy.RUNTIME)
+@ConfigProperty.Type(propertyClass=PropertyDouble.class)
+public @interface PropDouble
+{
+ public static class PropertyDouble
+ extends PropertyBase<Double, PropDouble>
+ {
+ public PropertyDouble(Field field, BinnieConfiguration file, ConfigProperty configProperty, PropDouble annotedProperty)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ super(file, configProperty, annotedProperty);
+ }
+
+ protected Property getProperty()
+ {
+ return this.file.get(getCategory(), getKey(), ((Double)this.defaultValue).doubleValue());
+ }
+
+ protected Double getConfigValue()
+ {
+ return Double.valueOf(this.property.getDouble(((Double)this.defaultValue).doubleValue()));
+ }
+
+ protected void addComments()
+ {
+ addComment("Default value is " + this.defaultValue + ".");
+ }
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/PropInteger.java b/src/Java/binnie/core/mod/config/PropInteger.java
new file mode 100644
index 0000000000..f74c625a8c
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/PropInteger.java
@@ -0,0 +1,38 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+@Retention(RetentionPolicy.RUNTIME)
+@ConfigProperty.Type(propertyClass=PropertyInteger.class)
+public @interface PropInteger
+{
+ public static class PropertyInteger
+ extends PropertyBase<Integer, PropInteger>
+ {
+ public PropertyInteger(Field field, BinnieConfiguration file, ConfigProperty configProperty, PropInteger annotedProperty)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ super(file, configProperty, annotedProperty);
+ }
+
+ protected Property getProperty()
+ {
+ return this.file.get(getCategory(), getKey(), ((Integer)this.defaultValue).intValue());
+ }
+
+ protected Integer getConfigValue()
+ {
+ return Integer.valueOf(this.property.getInt(((Integer)this.defaultValue).intValue()));
+ }
+
+ protected void addComments()
+ {
+ addComment("Default value is " + this.defaultValue + ".");
+ }
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/PropPercentage.java b/src/Java/binnie/core/mod/config/PropPercentage.java
new file mode 100644
index 0000000000..b51d8e3abf
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/PropPercentage.java
@@ -0,0 +1,43 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Field;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+@Retention(RetentionPolicy.RUNTIME)
+@ConfigProperty.Type(propertyClass=PropertyPercentage.class)
+public @interface PropPercentage
+{
+ int upper() default 100;
+
+ int lower() default 0;
+
+ public static class PropertyPercentage
+ extends PropertyBase<Integer, PropPercentage>
+ {
+ public PropertyPercentage(Field field, BinnieConfiguration file, ConfigProperty configProperty, PropPercentage annotedProperty)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ super(file, configProperty, annotedProperty);
+ }
+
+ protected Integer getConfigValue()
+ {
+ return Integer.valueOf(this.property.getInt(((Integer)this.defaultValue).intValue()));
+ }
+
+ protected void addComments()
+ {
+ addComment("Default value is " + this.defaultValue + "%.");
+ addComment("Range is " + ((PropPercentage)this.annotatedProperty).lower() + "-" + ((PropPercentage)this.annotatedProperty).upper() + "%.");
+ }
+
+ protected Property getProperty()
+ {
+ return this.file.get(getCategory(), getKey(), ((Integer)this.defaultValue).intValue());
+ }
+ }
+}
diff --git a/src/Java/binnie/core/mod/config/PropertyBase.java b/src/Java/binnie/core/mod/config/PropertyBase.java
new file mode 100644
index 0000000000..8ad13f833e
--- /dev/null
+++ b/src/Java/binnie/core/mod/config/PropertyBase.java
@@ -0,0 +1,72 @@
+package binnie.core.mod.config;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraftforge.common.config.Configuration;
+import net.minecraftforge.common.config.Property;
+
+abstract class PropertyBase<ValueType, AnnotationType extends Annotation>
+{
+ Configuration file;
+ Property property;
+ ValueType defaultValue;
+ private ConfigProperty configProperty;
+ AnnotationType annotatedProperty;
+ private List<String> comments = new ArrayList();
+ private Field field;
+
+ protected PropertyBase(Field field, BinnieConfiguration file, ConfigProperty configProperty, AnnotationType annotedProperty)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ this.field = field;
+ this.file = file;
+ this.configProperty = configProperty;
+ this.annotatedProperty = annotedProperty;
+ this.defaultValue = getDefaultValue(field);
+ this.property = getProperty();
+ for (String comment : configProperty.comment()) {
+ addComment(comment);
+ }
+ addComments();
+ this.property.comment = getComment();
+ field.set(null, getConfigValue());
+ }
+
+ protected abstract Property getProperty();
+
+ protected abstract ValueType getConfigValue();
+
+ protected abstract void addComments();
+
+ protected String getCategory()
+ {
+ return this.configProperty.category().equals("") ? ((ConfigProperty.Type)this.annotatedProperty.annotationType().getAnnotation(ConfigProperty.Type.class)).category() : this.configProperty.category();
+ }
+
+ protected String getKey()
+ {
+ return this.configProperty.key();
+ }
+
+ protected ValueType getDefaultValue(Field field)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ return field.get(null);
+ }
+
+ protected void addComment(String comment)
+ {
+ this.comments.add(comment);
+ }
+
+ protected String getComment()
+ {
+ String comment = "";
+ for (String com : this.comments) {
+ comment = comment + com + " ";
+ }
+ return comment;
+ }
+}
diff --git a/src/Java/binnie/core/mod/parser/FieldParser.java b/src/Java/binnie/core/mod/parser/FieldParser.java
new file mode 100644
index 0000000000..c063d5aca9
--- /dev/null
+++ b/src/Java/binnie/core/mod/parser/FieldParser.java
@@ -0,0 +1,55 @@
+package binnie.core.mod.parser;
+
+import binnie.core.AbstractMod;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+
+public abstract class FieldParser
+{
+ public static Collection<FieldParser> parsers = new ArrayList();
+
+ public abstract boolean isHandled(Field paramField, AbstractMod paramAbstractMod);
+
+ public void preInit(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {}
+
+ public void init(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {}
+
+ public void postInit(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {}
+
+ public static void preInitParse(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ for (FieldParser parser : parsers) {
+ if (parser.isHandled(field, mod)) {
+ parser.preInit(field, mod);
+ }
+ }
+ }
+
+ public static void initParse(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ for (FieldParser parser : parsers) {
+ if (parser.isHandled(field, mod)) {
+ parser.init(field, mod);
+ }
+ }
+ }
+
+ public static void postInitParse(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ for (FieldParser parser : parsers) {
+ if (parser.isHandled(field, mod)) {
+ parser.postInit(field, mod);
+ }
+ }
+ }
+}
diff --git a/src/Java/binnie/core/mod/parser/ItemParser.java b/src/Java/binnie/core/mod/parser/ItemParser.java
new file mode 100644
index 0000000000..8892a20aba
--- /dev/null
+++ b/src/Java/binnie/core/mod/parser/ItemParser.java
@@ -0,0 +1,24 @@
+package binnie.core.mod.parser;
+
+import binnie.core.AbstractMod;
+import cpw.mods.fml.common.registry.GameRegistry;
+import java.lang.reflect.Field;
+import net.minecraft.item.Item;
+
+public class ItemParser
+ extends FieldParser
+{
+ public boolean isHandled(Field field, AbstractMod mod)
+ {
+ return Item.class.isAssignableFrom(field.getType());
+ }
+
+ public void preInit(Field field, AbstractMod mod)
+ throws IllegalArgumentException, IllegalAccessException
+ {
+ Item item = (Item)field.get(null);
+ if (item != null) {
+ GameRegistry.registerItem(item, item.getUnlocalizedName().substring(5));
+ }
+ }
+}