Redid slightly the way potion array is extended.
This commit is contained in:
parent
66239a8687
commit
8cf4592350
3 changed files with 49 additions and 55 deletions
|
@ -18,7 +18,6 @@ import biomesoplenty.configuration.BOPEntities;
|
|||
import biomesoplenty.configuration.BOPItems;
|
||||
import biomesoplenty.configuration.BOPLiquids;
|
||||
import biomesoplenty.configuration.BOPPotions;
|
||||
import biomesoplenty.configuration.BOPReflection;
|
||||
import biomesoplenty.configuration.BOPVanillaCompat;
|
||||
import biomesoplenty.helpers.AchievementHelper;
|
||||
import biomesoplenty.helpers.BOPCraft;
|
||||
|
@ -97,8 +96,6 @@ public class BiomesOPlenty
|
|||
|
||||
tabBiomesOPlenty = new CreativeTabsBOP(CreativeTabs.getNextID(),"tabBiomesOPlenty");
|
||||
|
||||
BOPReflection.init();
|
||||
|
||||
BOPPotions.init();
|
||||
|
||||
BOPBlocks.init();
|
||||
|
|
|
@ -1,19 +1,26 @@
|
|||
package biomesoplenty.configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import biomesoplenty.api.Potions;
|
||||
import biomesoplenty.potions.PotionEventHandler;
|
||||
import biomesoplenty.potions.PotionNourishment;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||
import biomesoplenty.api.Potions;
|
||||
import biomesoplenty.helpers.BOPLiquidHelper;
|
||||
import biomesoplenty.potions.PotionEventHandler;
|
||||
import biomesoplenty.potions.PotionNourishment;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class BOPPotions
|
||||
{
|
||||
public static int potionOffset;
|
||||
private static final int MAXNEWPOTIONS = 8;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
extendPotionsArray();
|
||||
intializePotions();
|
||||
registerPotionNames();
|
||||
|
||||
|
@ -22,11 +29,46 @@ public class BOPPotions
|
|||
|
||||
private static void intializePotions()
|
||||
{
|
||||
Potions.nourishment = Optional.of((new PotionNourishment(32, false, 0)).setPotionName("potion.nourishment"));
|
||||
Potions.nourishment = Optional.of((new PotionNourishment(potionOffset + 0, false, 0)).setPotionName("potion.nourishment"));
|
||||
}
|
||||
|
||||
private static void registerPotionNames()
|
||||
{
|
||||
LanguageRegistry.instance().addStringLocalization("potion.nourishment", "en_US", "Nourishment");
|
||||
}
|
||||
|
||||
private static void extendPotionsArray()
|
||||
{
|
||||
System.out.println("[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("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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package biomesoplenty.configuration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class BOPReflection
|
||||
{
|
||||
public static void init()
|
||||
{
|
||||
potionReflection();
|
||||
}
|
||||
|
||||
private static void potionReflection()
|
||||
{
|
||||
Potion[] potionTypes = null;
|
||||
|
||||
for (Field f : Potion.class.getDeclaredFields())
|
||||
{
|
||||
f.setAccessible(true);
|
||||
|
||||
try
|
||||
{
|
||||
if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a"))
|
||||
{
|
||||
Field modfield = Field.class.getDeclaredField("modifiers");
|
||||
modfield.setAccessible(true);
|
||||
modfield.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
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)
|
||||
{
|
||||
System.err.println("Severe error, please report this to the mod author:");
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue