This commit is contained in:
Adubbz 2014-02-09 15:17:55 +11:00
parent 6232506dce
commit 6628fe0499
2 changed files with 27 additions and 61 deletions

View File

@ -8,6 +8,7 @@ import net.minecraft.potion.Potion;
import org.apache.logging.log4j.Level;
import biomesoplenty.api.BOPPotionHelper;
import biomesoplenty.common.helpers.BOPReflectionHelper;
import biomesoplenty.common.potions.PotionParalysis;
import biomesoplenty.common.potions.PotionPossession;
import cpw.mods.fml.common.FMLCommonHandler;
@ -23,12 +24,6 @@ public class BOPPotions
intializePotions();
}
private static void intializePotions()
{
registerPotion(new PotionParalysis(getNextID(), true, 16767262).setPotionName("potion.paralysis"));
registerPotion(new PotionPossession(getNextID(), true, 1280).setPotionName("potion.possession"));
}
private static void extendPotionsArray()
{
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array.");
@ -37,33 +32,13 @@ public class BOPPotions
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("potionTypes"))
{
field = f;
break;
}
BOPReflectionHelper.setPrivateFinalValue(Potion.class, null, potionTypes, "potionTypes", "field_76425_a");
}
try
private static void intializePotions()
{
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);
}
registerPotion(new PotionParalysis(getNextID(), true, 16767262).setPotionName("potion.paralysis"));
registerPotion(new PotionPossession(getNextID(), true, 1280).setPotionName("potion.possession"));
}
public static int getNextID()

View File

@ -35,21 +35,12 @@ public class BOPReflectionHelper
}
}
public static <T, E> void setPrivateFinalValue(Class <? super T > classToAccess, T instance, E value, String fieldName, String obfFieldName)
public static <T, E> void setPrivateFinalValue(Class <? super T > classToAccess, T instance, E value, String... fieldNames)
{
Field field = null;
Field field = ReflectionHelper.findField(classToAccess, ObfuscationReflectionHelper.remapFieldNames(classToAccess.getName(), fieldNames));
try
{
if (isDeobfuscated)
{
field = ReflectionHelper.findField(classToAccess, fieldName);
}
else
{
field = ReflectionHelper.findField(classToAccess, ObfuscationReflectionHelper.remapFieldNames(classToAccess.getName(), obfFieldName));
}
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);