Files
ModTweaker/src/main/java/modtweaker2/mods/thaumcraft/research/Difficulty.java
T
jaredlll08 ec562b62ea This closes #17 and closes #58, I tested and it worked using the script given
Also changes like all packages
inb4 "jared changes a package name in ModTweaker2 breaking compatability
with everything" drama tweet.
2015-02-20 23:57:32 +02:00

69 lines
1.8 KiB
Java

package modtweaker2.mods.thaumcraft.research;
import java.lang.reflect.Field;
import minetweaker.IUndoableAction;
import modtweaker2.mods.thaumcraft.ThaumcraftHelper;
import thaumcraft.api.research.ResearchCategories;
import thaumcraft.api.research.ResearchItem;
public class Difficulty implements IUndoableAction {
String key;
String tab;
int difficulty;
int oldDif;
boolean applied = false;
public Difficulty(String res, int dif) {
key = res;
tab = ThaumcraftHelper.getResearchTab(key);
difficulty = dif;
}
@Override
public void apply() {
ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key);
oldDif = research.getComplexity();
try {
Field complexity = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("complexity");
complexity.setAccessible(true);
complexity.set(research, difficulty);
applied = true;
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public String describe() {
return "Changing Complexity for " + key;
}
@Override
public boolean canUndo() {
return applied;
}
@Override
public void undo() {
try {
ResearchItem research = ResearchCategories.researchCategories.get(tab).research.get(key);
Field complexity = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("complexity");
complexity.setAccessible(true);
complexity.set(research, oldDif);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public String describeUndo() {
return "Restoring Complexity for " + key;
}
@Override
public String getOverrideKey() {
return null;
}
}