Skip to content

Commit

Permalink
Java 12 compat: don't resize the potion array if already big enough.
Browse files Browse the repository at this point in the history
The actual compatible resizing is done in Hodgepodge.
  • Loading branch information
eigenraven committed Jan 23, 2023
1 parent 6de78aa commit ef378fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1673027205
//version: 1674409054
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -144,6 +144,7 @@ propertyDefaultIfUnset("modrinthProjectId", "")
propertyDefaultIfUnset("modrinthRelations", "")
propertyDefaultIfUnset("curseForgeProjectId", "")
propertyDefaultIfUnset("curseForgeRelations", "")
propertyDefaultIfUnset("minimizeShadowedDependencies", true)

String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
Expand Down Expand Up @@ -411,7 +412,9 @@ shadowJar {
attributes(getManifestAttributes())
}

minimize() // This will only allow shading for actually used classes
if (minimizeShadowedDependencies.toBoolean()) {
minimize() // This will only allow shading for actually used classes
}
configurations = [
project.configurations.shadowImplementation,
project.configurations.shadowCompile
Expand Down Expand Up @@ -554,7 +557,9 @@ task shadowDevJar(type: ShadowJar) {
attributes(getManifestAttributes())
}

minimize() // This will only allow shading for actually used classes
if (minimizeShadowedDependencies.toBoolean()) {
minimize() // This will only allow shading for actually used classes
}
configurations = [
project.configurations.shadowImplementation,
project.configurations.shadowCompile
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/WayofTime/alchemicalWizardry/AlchemicalWizardry.java
Original file line number Diff line number Diff line change
Expand Up @@ -463,24 +463,25 @@ public void preInit(FMLPreInitializationEvent event) {
BloodMagicConfiguration.init(new File(event.getModConfigurationDirectory(), "AWWayofTime.cfg"));

// Custom config stuff goes here
Potion[] potionTypes;

for (Field f : Potion.class.getDeclaredFields()) {
f.setAccessible(true);
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);
potionTypes = (Potion[]) f.get(null);
final Potion[] newPotionTypes = new Potion[256];
System.arraycopy(potionTypes, 0, newPotionTypes, 0, potionTypes.length);
f.set(null, newPotionTypes);
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, please report this to the mod author:");
System.err.println(e);
}
} catch (Exception e) {
System.err.println("Severe error, please report this to the mod author:");
System.err.println(e);
}
}
AlchemicalWizardry.lifeEssenceFluid = new LifeEssence("LifeEssence");
Expand Down

0 comments on commit ef378fb

Please sign in to comment.