summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/potions
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/potions')
-rw-r--r--src/main/java/darkknight/jewelrycraft/potions/PotionList.java133
-rw-r--r--src/main/java/darkknight/jewelrycraft/potions/PotionStun.java4
2 files changed, 78 insertions, 59 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/potions/PotionList.java b/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
index 2ee508d..6749c37 100644
--- a/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
+++ b/src/main/java/darkknight/jewelrycraft/potions/PotionList.java
@@ -1,55 +1,78 @@
-/**
- *
- */
-package darkknight.jewelrycraft.potions;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import net.minecraft.potion.Potion;
-import cpw.mods.fml.common.event.FMLInitializationEvent;
-import cpw.mods.fml.common.event.FMLPostInitializationEvent;
-import cpw.mods.fml.common.event.FMLPreInitializationEvent;
-
-/**
- * @author Sorin
- *
- */
-public class PotionList
-{
- public static Potion stun;
-
- public static void preInit(FMLPreInitializationEvent e)
- {
- Potion[] potionTypes = null;
-
- for (Field f : Potion.class.getDeclaredFields()) {
- f.setAccessible(true);
- try {
- if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
- Field modfield = Field.class.getDeclaredField("modifiers");
- modfield.setAccessible(true);
- modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);
-
- potionTypes = (Potion[])f.get(null);
- final Potion[] newPotionTypes = new Potion[256];
- System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
- f.set(null, newPotionTypes);
- }
- } catch (Exception e1) {
- System.err.println("Severe error, please report this to the mod author:");
- System.err.println(e1);
- }
- }
-
- }
-
- public static void init(FMLInitializationEvent e)
- {
- stun = new PotionStun(32, true, 0x000000);
- }
-
- public static void postInit(FMLPostInitializationEvent e)
- {
-
- }
-}
+/**
+ *
+ */
+package darkknight.jewelrycraft.potions;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import cpw.mods.fml.common.event.FMLInitializationEvent;
+import cpw.mods.fml.common.event.FMLPostInitializationEvent;
+import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import darkknight.jewelrycraft.JewelrycraftMod;
+import net.minecraft.potion.Potion;
+
+/**
+ * @author Sorin
+ * Code for extending Potion list from Mithion
+ * SOurce: https://github.com/Mithion/ArsMagica2/blob/master/src/main/java/am2/buffs/BuffList.java
+ */
+public class PotionList
+{
+ public static Potion stun;
+ private static int potionDefaultOffset = 0;
+
+ public static void preInit(FMLPreInitializationEvent e)
+ {
+ }
+
+ private static void setFinalStatic(Field field, Object newValue) throws Exception
+ {
+ field.setAccessible(true);
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
+ modifiersField.setAccessible(true);
+ modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
+ field.set(null, newValue);
+ }
+
+ private static void extendPotionsArray() throws Exception
+ {
+ JewelrycraftMod.logger.info("Extending potions array");
+ JewelrycraftMod.logger.info("Injecting potions starting from index " + Potion.potionTypes.length);
+ potionDefaultOffset = Potion.potionTypes.length;
+ setPotionArrayLength(255);
+ }
+
+ private static void setPotionArrayLength(int length) throws Exception
+ {
+ if (length <= Potion.potionTypes.length)
+ return;
+ Potion[] potions = new Potion[length];
+ for(int i = 0; i < Potion.potionTypes.length; ++i){
+ potions[i] = Potion.potionTypes[i];
+ }
+ Field field = null;
+ Field[] fields = Potion.class.getDeclaredFields();
+ for(Field f: fields){
+ if (f.getType().equals(Potion[].class)) {
+ field = f;
+ break;
+ }
+ }
+ setFinalStatic(field, potions);
+ }
+
+ public static void init(FMLInitializationEvent e)
+ {
+ try{
+ extendPotionsArray();
+ }
+ catch(Throwable t){
+ JewelrycraftMod.logger.error("Failed to extend potion ids!");
+ t.printStackTrace();
+ }
+ stun = new PotionStun(potionDefaultOffset + 0, true, 0x000000);
+ }
+
+ public static void postInit(FMLPostInitializationEvent e)
+ {}
+}
diff --git a/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java b/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
index 0e8ad7f..e1f43e6 100644
--- a/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
+++ b/src/main/java/darkknight/jewelrycraft/potions/PotionStun.java
@@ -3,12 +3,8 @@
*/
package darkknight.jewelrycraft.potions;
-import cpw.mods.fml.relauncher.Side;
-import cpw.mods.fml.relauncher.SideOnly;
import darkknight.jewelrycraft.util.Variables;
import net.minecraft.entity.EntityLivingBase;
-import net.minecraft.potion.Potion;
-import net.minecraft.potion.PotionEffect;
/**
* @author Sorin