Fixed #184
This commit is contained in:
parent
6232506dce
commit
6628fe0499
|
@ -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;
|
||||
|
@ -22,49 +23,23 @@ public class BOPPotions
|
|||
extendPotionsArray();
|
||||
intializePotions();
|
||||
}
|
||||
|
||||
private static void extendPotionsArray()
|
||||
{
|
||||
FMLCommonHandler.instance().getFMLLogger().log(Level.INFO, "[BiomesOPlenty] Extending Potions Array.");
|
||||
potionOffset = Potion.potionTypes.length;
|
||||
|
||||
Potion[] potionTypes = new Potion[potionOffset + MAXNEWPOTIONS];
|
||||
System.arraycopy(Potion.potionTypes, 0, potionTypes, 0, potionOffset);
|
||||
|
||||
BOPReflectionHelper.setPrivateFinalValue(Potion.class, null, potionTypes, "potionTypes", "field_76425_a");
|
||||
}
|
||||
|
||||
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.");
|
||||
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("potionTypes"))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getNextID()
|
||||
{
|
||||
|
|
|
@ -35,30 +35,21 @@ 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;
|
||||
|
||||
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);
|
||||
|
||||
field.set(instance, value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
Field field = ReflectionHelper.findField(classToAccess, ObfuscationReflectionHelper.remapFieldNames(classToAccess.getName(), fieldNames));
|
||||
|
||||
try
|
||||
{
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
field.set(instance, value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue