Skip to content

Commit

Permalink
Reorder field accesses to work
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Jan 24, 2023
1 parent be56bf2 commit 2f5c710
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/main/java/thaumic/tinkerer/common/potion/ModPotions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Modifier;
import net.minecraft.potion.Potion;
import net.minecraftforge.common.MinecraftForge;
import thaumic.tinkerer.common.ThaumicTinkerer;
import thaumic.tinkerer.common.core.handler.ConfigHandler;

public final class ModPotions {
Expand All @@ -36,22 +35,23 @@ public static void initPotions() {
// Code based on potion code from WayOfTime
Potion[] potionTypes = null;

for (Field f : Potion.class.getDeclaredFields()) {
f.setAccessible(true);
try {
if (f.getName().equals("potionTypes") || f.getName().equals("field_76425_a")) {
potionTypes = (Potion[]) f.get(null);
if (potionTypes.length < 256) {
final Potion[] newPotionTypes = new Potion[256];
System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
if (Potion.potionTypes.length < 256) {
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);
final Potion[] oldPotionTypes = Potion.potionTypes;
final Potion[] newPotionTypes = new Potion[256];
System.arraycopy(oldPotionTypes, 0, newPotionTypes, 0, oldPotionTypes.length);
f.set(null, newPotionTypes);
}
} catch (Exception e) {
System.err.println("Severe error when extending the potion array:");
System.err.println(e);
}
} catch (Exception e) {
ThaumicTinkerer.log.error("Severe error when extending the potion array:", e);
}
}

Expand Down

0 comments on commit 2f5c710

Please sign in to comment.