Skip to content

Commit

Permalink
Add a "hidden" option to thaumcraft research (#4)
Browse files Browse the repository at this point in the history
* Add a "hidden" option to thaumcraft research

* Add aspect triggers for "hidden" option

* Reformat
  • Loading branch information
xchgeax authored Jul 31, 2022
1 parent fb75772 commit ceabe58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/main/java/modtweaker2/mods/thaumcraft/handlers/Research.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ public static void orphanResearch(String research) {
@ZenMethod
public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, String domain, String path) {

MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, new ResourceLocation(domain, path)), null, null));
MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, new ResourceLocation(domain, path)), null, null, null));
}

@ZenMethod
public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item) {

MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)),null, null));
MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)),null, null, null));
}

@ZenMethod
public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item, IItemStack[] triggers, String[] entTriggers) {
public static void addResearch(String key, String tab, @Optional String aspects, int x, int y, int difficulty, IItemStack item, IItemStack[] triggers, String[] entTriggers, String aspectsTrigger) {

MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)), InputHelper.toStacks(triggers), entTriggers));
MineTweakerAPI.apply(new AddResearch(new ResearchItem(key, tab, ThaumcraftHelper.parseAspects(aspects), x, y, difficulty, toStack(item)), InputHelper.toStacks(triggers), entTriggers, ThaumcraftHelper.parseAspects(aspectsTrigger)));
}

@ZenMethod
Expand Down Expand Up @@ -201,6 +201,11 @@ public static void setConcealed(String key, boolean flag) {
MineTweakerAPI.apply(new SetResearch(key, flag, SetType.CONCEAL));
}

@ZenMethod
public static void setHidden(String key, boolean flag) {
MineTweakerAPI.apply(new SetResearch(key, flag, SetType.HIDDEN));
}

@ZenMethod
public static void setAspects(String key, String aspects) {

Expand Down Expand Up @@ -231,7 +236,7 @@ public static boolean hasResearched(IPlayer player, String key) {
return ThaumcraftApiHelper.isResearchComplete(player.getName(), key);
}

public static enum SetType {
AUTO, ROUND, SPIKE, SECONDARY, STUB, VIRTUAL, CONCEAL
public enum SetType {
AUTO, ROUND, SPIKE, SECONDARY, STUB, VIRTUAL, CONCEAL, HIDDEN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.minecraft.item.ItemStack;
import minetweaker.IUndoableAction;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.research.ResearchCategories;
import thaumcraft.api.research.ResearchItem;

Expand All @@ -12,13 +14,15 @@ public class AddResearch implements IUndoableAction {
ResearchItem oldResearch;
ItemStack[] itemTriggers;
String[] entityTriggers;
AspectList aspectTriggers;

public AddResearch(ResearchItem res, ItemStack[] triggers, String[] entTriggers) {
public AddResearch(ResearchItem res, ItemStack[] itemTriggers, String[] entityTriggers, AspectList aspectTriggers) {
research = res;
tab = research.category;
key = research.key;
itemTriggers = triggers;
entityTriggers = entTriggers;
this.itemTriggers = itemTriggers;
this.entityTriggers = entityTriggers;
this.aspectTriggers = aspectTriggers;
}

@Override
Expand All @@ -30,6 +34,9 @@ public void apply() {
if (entityTriggers != null) {
research = research.setEntityTriggers(entityTriggers);
}
if (aspectTriggers != null) {
research = research.setAspectTriggers(aspectTriggers.getAspects());
}
research.registerResearchItem();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void apply() {
else if (type == SetType.STUB) research.setStub();
else if (type == SetType.VIRTUAL) research.setVirtual();
else if (type == SetType.CONCEAL) research.setConcealed();
else if (type == SetType.HIDDEN) research.setHidden();
applied = true;
} else {
try {
Expand All @@ -46,6 +47,7 @@ public void apply() {
else if (type == SetType.STUB) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isStub");
else if (type == SetType.VIRTUAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isVirtual");
else if (type == SetType.CONCEAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isConcealed");
else if (type == SetType.HIDDEN) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isHidden");

if (target != null) {
target.setAccessible(true);
Expand Down Expand Up @@ -83,6 +85,7 @@ public void undo() {
else if (type == SetType.STUB) research.setStub();
else if (type == SetType.VIRTUAL) research.setVirtual();
else if (type == SetType.CONCEAL) research.setConcealed();
else if (type == SetType.HIDDEN) research.setHidden();
} else {
try {
Field target = null;
Expand All @@ -93,6 +96,7 @@ public void undo() {
else if (type == SetType.STUB) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isStub");
else if (type == SetType.VIRTUAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isVirtual");
else if (type == SetType.CONCEAL) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isConcealed");
else if (type == SetType.HIDDEN) target = Class.forName("thaumcraft.api.research.ResearchItem").getDeclaredField("isHidden");

if (target != null) {
target.setAccessible(true);
Expand Down

0 comments on commit ceabe58

Please sign in to comment.