BiomesOPlenty/common/biomesoplenty/configuration/BOPPotions.java

81 lines
2.4 KiB
Java
Raw Normal View History

package biomesoplenty.configuration;
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
import net.minecraft.potion.Potion;
import net.minecraftforge.common.MinecraftForge;
2013-05-25 09:33:37 +00:00
import biomesoplenty.api.Potions;
import biomesoplenty.potions.PotionEventHandler;
import biomesoplenty.potions.PotionParalysis;
2013-08-30 11:38:54 +00:00
import biomesoplenty.potions.PotionPossession;
import com.google.common.base.Optional;
2013-06-14 13:17:48 +00:00
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.registry.LanguageRegistry;
2013-05-31 10:34:02 +00:00
public class BOPPotions
{
2013-05-31 10:34:02 +00:00
public static int potionOffset;
private static final int MAXNEWPOTIONS = 8;
public static void init()
{
2013-05-31 10:34:02 +00:00
extendPotionsArray();
intializePotions();
registerPotionNames();
2013-05-31 10:34:02 +00:00
MinecraftForge.EVENT_BUS.register(new PotionEventHandler());
}
private static void intializePotions()
{
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-31 10:34:02 +00:00
private static void registerPotionNames()
{
LanguageRegistry.instance().addStringLocalization("potion.nourishment", "en_US", "Nourishment");
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-31 10:34:02 +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);
}
}
}