2013-05-25 08:57:21 +00:00
|
|
|
package biomesoplenty.configuration;
|
|
|
|
|
2013-05-25 10:08:07 +00:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Modifier;
|
2013-06-14 13:17:48 +00:00
|
|
|
import java.util.logging.Level;
|
2013-05-25 09:33:37 +00:00
|
|
|
|
2013-05-25 10:08:07 +00:00
|
|
|
import net.minecraft.potion.Potion;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2013-05-25 09:33:37 +00:00
|
|
|
import biomesoplenty.api.Potions;
|
2013-05-25 08:57:21 +00:00
|
|
|
import biomesoplenty.potions.PotionEventHandler;
|
2013-05-25 16:02:56 +00:00
|
|
|
import biomesoplenty.potions.PotionParalysis;
|
2013-08-30 11:38:54 +00:00
|
|
|
import biomesoplenty.potions.PotionPossession;
|
2013-05-25 10:08:07 +00:00
|
|
|
|
|
|
|
import com.google.common.base.Optional;
|
|
|
|
|
2013-06-14 13:17:48 +00:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2013-05-25 10:08:07 +00:00
|
|
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
2013-05-25 08:57:21 +00:00
|
|
|
|
2013-05-31 10:34:02 +00:00
|
|
|
public class BOPPotions
|
2013-05-25 08:57:21 +00:00
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
public static int potionOffset;
|
|
|
|
private static final int MAXNEWPOTIONS = 8;
|
|
|
|
|
2013-05-25 08:57:21 +00:00
|
|
|
public static void init()
|
|
|
|
{
|
2013-05-31 10:34:02 +00:00
|
|
|
extendPotionsArray();
|
2013-05-25 08:57:21 +00:00
|
|
|
intializePotions();
|
|
|
|
registerPotionNames();
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-05-25 08:57:21 +00:00
|
|
|
MinecraftForge.EVENT_BUS.register(new PotionEventHandler());
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void intializePotions()
|
|
|
|
{
|
2013-07-03 07:54:44 +00:00
|
|
|
Potions.paralysis = Optional.of((new PotionParalysis(potionOffset + 0, true, 16767262)).setPotionName("potion.paralysis"));
|
2013-08-30 12:04:03 +00:00
|
|
|
Potions.possession = Optional.of((new PotionPossession(potionOffset + 1, true, 1280)).setPotionName("potion.possession"));
|
2013-05-25 08:57:21 +00:00
|
|
|
}
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-05-25 08:57:21 +00:00
|
|
|
private static void registerPotionNames()
|
|
|
|
{
|
|
|
|
LanguageRegistry.instance().addStringLocalization("potion.nourishment", "en_US", "Nourishment");
|
2013-05-25 16:02:56 +00:00
|
|
|
LanguageRegistry.instance().addStringLocalization("potion.paralysis", "en_US", "Paralysis");
|
2013-08-30 11:38:54 +00:00
|
|
|
LanguageRegistry.instance().addStringLocalization("potion.possession", "en_US", "Possession");
|
2013-05-25 08:57:21 +00:00
|
|
|
}
|
2013-05-31 10:34:02 +00:00
|
|
|
|
2013-05-25 10:08:07 +00:00
|
|
|
private static void extendPotionsArray()
|
2013-05-31 10:34:02 +00:00
|
|
|
{
|
2013-06-14 13:17:48 +00:00
|
|
|
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array.");
|
2013-05-31 10:34:02 +00:00
|
|
|
potionOffset = Potion.potionTypes.length;
|
|
|
|
|
|
|
|
Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS];
|
|
|
|
System.arraycopy(Potion.potionTypes, 0, potionTypes, 0, potionOffset);
|
|
|
|
|
|
|
|
Field field = null;
|
|
|
|
Field[] fields = Potion.class.getDeclaredFields();
|
|
|
|
|
|
|
|
for (Field f : fields)
|
|
|
|
if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a"))
|
|
|
|
{
|
|
|
|
field = f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
|
|
|
Field modfield = Field.class.getDeclaredField("modifiers");
|
|
|
|
modfield.setAccessible(true);
|
|
|
|
modfield.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
|
|
|
|
|
|
|
field.set(null, potionTypes);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
System.err.println("[BiomesOPlenty] Severe error, please report this to the mod author:");
|
|
|
|
System.err.println(e);
|
|
|
|
}
|
|
|
|
}
|
2013-05-25 08:57:21 +00:00
|
|
|
}
|