BloodMagic/src/main/java/WayofTime/bloodmagic/registry/ModPotions.java

72 lines
2.5 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.registry;
2015-12-27 19:38:12 -05:00
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import net.minecraft.potion.Potion;
import net.minecraft.util.ResourceLocation;
import WayofTime.bloodmagic.potion.PotionBloodMagic;
import WayofTime.bloodmagic.potion.PotionEventHandlers;
public class ModPotions
{
2015-12-27 19:38:12 -05:00
public static Potion drowning;
public static Potion boost;
public static Potion heavyHeart;
2015-12-28 19:09:51 -05:00
public static Potion whirlwind;
public static Potion planarBinding;
2015-12-27 19:38:12 -05:00
public static void init()
{
if (Potion.potionTypes.length < 256)
extendPortionArray();
2015-12-27 19:38:12 -05:00
new PotionEventHandlers();
// TODO FUTURE MAKE POTION TEXTURES
2015-12-27 19:38:12 -05:00
// final String resourceLocation = Constants.Mod.MODID +
// ":textures/potions/";
2015-12-27 19:38:12 -05:00
// drowning = new PotionBloodMagic("Drowning", new
// ResourceLocation(resourceLocation +
// drowning.getName().toLowerCase()), true, 0, 0, 0);
2015-12-28 19:09:51 -05:00
boost = new PotionBloodMagic("Boost", new ResourceLocation("boost")
// new ResourceLocation(resourceLocation +
// boost.getName().toLowerCase())
2015-12-31 13:50:38 -05:00
, false, 0, 0, 0);
2015-12-28 19:09:51 -05:00
whirlwind = new PotionBloodMagic("Whirlwind", new ResourceLocation("whirlwind"), false, 0, 0, 0);
planarBinding = new PotionBloodMagic("Planar Binding", new ResourceLocation("planarBinding"), false, 0, 0, 0);
// heavyHeart = new PotionBloodMagic("Heavy Heart", new
// ResourceLocation(resourceLocation +
// heavyHeart.getName().toLowerCase()), true, 0, 0, 0);
2015-12-27 19:38:12 -05:00
}
public static void extendPortionArray()
{
2015-12-27 19:38:12 -05:00
Potion[] potionTypes;
for (Field f : Potion.class.getDeclaredFields())
{
2015-12-27 19:38:12 -05:00
f.setAccessible(true);
try
{
if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a"))
{
2015-12-27 19:38:12 -05:00
Field field = Field.class.getDeclaredField("modifiers");
field.setAccessible(true);
field.setInt(f, f.getModifiers() & ~Modifier.FINAL);
2015-12-27 19:38:12 -05:00
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 e)
{
2015-12-27 19:38:12 -05:00
System.err.println(e);
}
}
}
}