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 org.apache.logging.log4j.Level;
import biomesoplenty.api.BOPPotionHelper; import biomesoplenty.api.BOPPotionHelper;
import biomesoplenty.common.helpers.BOPReflectionHelper;
import biomesoplenty.common.potions.PotionParalysis; import biomesoplenty.common.potions.PotionParalysis;
import biomesoplenty.common.potions.PotionPossession; import biomesoplenty.common.potions.PotionPossession;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -23,12 +24,6 @@ public class BOPPotions
intializePotions(); 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() private static void extendPotionsArray()
{ {
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array."); FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array.");
@ -37,33 +32,13 @@ public class BOPPotions
Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS]; Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS];
System.arraycopy(Potion.potionTypes, 0, potionTypes, 0, potionOffset); System.arraycopy(Potion.potionTypes, 0, potionTypes, 0, potionOffset);
Field field = null; BOPReflectionHelper.setPrivateFinalValue(Potion.class, null, potionTypes, "potionTypes", "field_76425_a");
Field[] fields = Potion.class.getDeclaredFields();
for (Field f : fields)
{
if (f.getName().equals("potionTypes") || f.getName().equals("potionTypes"))
{
field = f;
break;
}
} }
try private static void intializePotions()
{ {
field.setAccessible(true); registerPotion(new PotionParalysis(getNextID(), true, 16767262).setPotionName("potion.paralysis"));
registerPotion(new PotionPossession(getNextID(), true, 1280).setPotionName("potion.possession"));
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);
}
} }
public static int getNextID() 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 try
{ {
if (isDeobfuscated)
{
field = ReflectionHelper.findField(classToAccess, fieldName);
}
else
{
field = ReflectionHelper.findField(classToAccess, ObfuscationReflectionHelper.remapFieldNames(classToAccess.getName(), obfFieldName));
}
Field modifiersField = Field.class.getDeclaredField("modifiers"); Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true); modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);