From 01c8701b68986ccfa83e902515716838d6829311 Mon Sep 17 00:00:00 2001 From: Onyx Date: Tue, 1 Dec 2015 20:55:30 +0000 Subject: - Fixed all of the bugs mentioned on github - Added new config options - Rabbits paw now increases the chance of spawning hearts, rather than itself spawning some - Hearts now have a much lower chance to spawn by default - You can no longer increase your health past 20 hearts (aka double the default health) - The guide now also shows the total number of pages on each tab - A new luck stat has been added to the Curse API - Cleaned up the code a bit (removed unused methods, imports etc) - The displayer's info now has a purple solid color background; the text also has a much closer shadow and now shrinks in height as well as in width when too big - I have modified the potion list to use Mithion's code, credits have been given --- .../jewelrycraft/potions/PotionList.java | 133 ++++++++++++--------- .../jewelrycraft/potions/PotionStun.java | 4 - 2 files changed, 78 insertions(+), 59 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/potions') 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 -- cgit v1.2.3