Skip to content

Commit

Permalink
add research tab user sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Glease committed Jun 20, 2023
1 parent 87db8c7 commit b973cb1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/main/java/net/glease/tc4tweak/ClientProxy.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.glease.tc4tweak;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
Expand All @@ -21,6 +20,7 @@
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.world.WorldEvent;
import org.lwjgl.input.Mouse;
import thaumcraft.client.fx.other.FXSonic;
import thaumcraft.client.gui.GuiResearchRecipe;
Expand Down Expand Up @@ -160,6 +160,13 @@ public void postInit(FMLPostInitializationEvent e) {
} catch (ReflectiveOperationException ignored) {
// WG is probably not installed, ignoring
}
FMLCommonHandler.instance().bus().register(this);
}

@SubscribeEvent
public void onWorldLoad(WorldEvent.Load e) {
if (e.world.isRemote)
CommonUtils.sortResearchCategories(false);
}

@SubscribeEvent(priority = EventPriority.LOWEST)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/glease/tc4tweak/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartedEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.relauncher.Side;
Expand All @@ -31,7 +32,7 @@ public void preInit(FMLPreInitializationEvent e) {
addDummyCategories(debugadd, "DUMMYPRE");
}

public void serverStarted() {
public void serverStarted(FMLServerStartedEvent e) {
FlushableCache.enableAll(true);
NetworkedConfiguration.reset();
FMLCommonHandler.instance().bus().register(this);
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/net/glease/tc4tweak/CommonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,40 @@

import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.CrucibleRecipe;
import thaumcraft.api.research.ResearchCategories;
import thaumcraft.api.research.ResearchCategoryList;

import java.util.*;
import java.util.stream.Collectors;

public class CommonUtils {
// only keep the strings, so tab objects doesn't leak if they are ever removed
private static final LinkedHashSet<String> originalTabOrders = new LinkedHashSet<>();

public static String toString(AspectList al) {
return al.aspects.entrySet().stream().filter(e -> e.getKey() != null && e.getValue() != null).map(e -> String.format("%dx%s", e.getValue(), e.getKey().getName())).collect(Collectors.joining(";"));
}
public static String toString(CrucibleRecipe r) {
return "CrucibleRecipe{key="+r.key+",catalyst="+r.catalyst+",output="+r.getRecipeOutput()+",aspects="+toString(r.aspects)+"}";
}

static void sortResearchCategories(boolean force) {
if (force || !ConfigurationHandler.INSTANCE.getCategoryOrder().isEmpty()) {
// no need to synchronize
// we fetch data from a practically immutable collection
// then create a local copy
// then replace the reference to that immutable collection with our local copy,
// which is a simple PUTFIELD, which is atomic.
LinkedHashMap<String, ResearchCategoryList> categories = ResearchCategories.researchCategories;
originalTabOrders.addAll(categories.keySet());
Set<String> realOrder = new LinkedHashSet<>(ConfigurationHandler.INSTANCE.getCategoryOrder());
realOrder.addAll(originalTabOrders);
LinkedHashMap<String, ResearchCategoryList> newCategories = new LinkedHashMap<>();
for (String tab : realOrder) {
if (categories.containsKey(tab))
newCategories.put(tab, categories.get(tab));
}
ResearchCategories.researchCategories = newCategories;
}
}
}
12 changes: 10 additions & 2 deletions src/main/java/net/glease/tc4tweak/ConfigurationHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.glease.tc4tweak;

import com.google.common.collect.ImmutableList;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -15,8 +16,7 @@
import thaumcraft.api.ThaumcraftApiHelper;

import java.io.File;
import java.util.Arrays;
import java.util.Map;
import java.util.*;

public enum ConfigurationHandler {
INSTANCE;
Expand All @@ -41,6 +41,7 @@ public enum ConfigurationHandler {
private int browserHeight = 230;
private int browserWidth = 256;
private InfusionOreDictMode infusionOreDictMode = InfusionOreDictMode.Default;
private List<String> categoryOrder = new ArrayList<>();

ConfigurationHandler() {
FMLCommonHandler.instance().bus().register(this);
Expand Down Expand Up @@ -68,6 +69,7 @@ public void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent e) {
if (e.modID.equals(TC4Tweak.MOD_ID)) {
loadConfig(true);
FlushableCache.enableAll(false);
CommonUtils.sortResearchCategories(true);
}
}

Expand Down Expand Up @@ -103,6 +105,7 @@ private void loadConfig(boolean send) {
smallerJars = config.getBoolean("smallerJars", "general", FMLLaunchHandler.side().isServer(), "If true, jars (brain in jar, essentia jars, etc) will have a collision box the same as block outline. Otherwise it will have a collision box of 1x1x1, which is the vanilla tc4 behavior.");
moreRandomizedLoot = config.getBoolean("moreRandomizedLoot", "general", true, "If true, enchanted books will have randomized enchantment and vis stone will have different vis stored even without server restart.");
infusionOreDictMode = InfusionOreDictMode.get(config.getString("infusionOreDictMode", "general", infusionOreDictMode.name(), "Select the infusion oredict mode. Default: vanilla TC4 behavior. Strict: all oredict names must match to count as oredict substitute. Relaxed: oredict names needs only overlaps to count as oredict substitute. None: no oredict substitute at all.", Arrays.stream(InfusionOreDictMode.values()).map(Enum::name).toArray(String[]::new)));
categoryOrder = ImmutableList.copyOf(config.getStringList("categoryOrder", "client", new String[] {"BASICS","THAUMATURGY","ALCHEMY","ARTIFICE","GOLEMANCY","ELDRITCH",}, "Specify a full sorting order of research tabs. An empty list here means the feature is disabled. any research tab not listed here will be appended to the end in their original order. Use NEI utility to dump a list of all research tabs. Default is the list of all vanilla thaumcraft tabs."));

// validation
if (inferBrowserScaleLowerBound > inferBrowserScaleUpperBound)
Expand Down Expand Up @@ -185,6 +188,7 @@ public boolean isSmallerJars() {
return smallerJars;
}

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public boolean isMoreRandomizedLoot() {
return moreRandomizedLoot;
}
Expand All @@ -193,6 +197,10 @@ public InfusionOreDictMode getInfusionOreDictMode() {
return InfusionOreDictMode.Default; // TODO
}

public List<String> getCategoryOrder() {
return categoryOrder;
}

public enum InfusionOreDictMode {
Default {
@SuppressWarnings("deprecation")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/glease/tc4tweak/TC4Tweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void postInit(FMLPostInitializationEvent e) {

@Mod.EventHandler
public void serverStarted(FMLServerStartedEvent e) {
proxy.serverStarted();
proxy.serverStarted(e);
}

@NetworkCheckHandler
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/tc4tweak/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ tc4tweaks.config.client.limitOversizedNodeRender=Maximum Node Rendered Size
tc4tweaks.config.client.limitOversizedNodeRender.tooltip=The upper limit on how big nodes can be rendered. This is purely a visual thing and will not affect how big your node can actually grow. Setting a value like 10000.0 will effectively turn off this functionality, i.e. not limit the rendered size. \n[range: 0.5 ~ 1.0E10]
tc4tweaks.config.client.updateInterval=Arcane Workbench GUI Update Interval
tc4tweaks.config.client.updateInterval.tooltip=How often should Arcane Workbench update displayed crafting result. Unit is in game ticks. \n[range: 0 ~ 40]
tc4tweaks.config.client.categoryOrder=Reorder Research Tabs
tc4tweaks.config.client.categoryOrder.tooltip=Specify a full sorting order of research tabs. An empty list here means the feature is disabled. any research tab not listed here will be appended to the end in their original order. Use NEI utility to dump a list of all research tabs. Default is the list of all vanilla thaumcraft tabs, i.e. no change.
tc4tweaks.config.general=General Configurations
tc4tweaks.config.general.tooltip=Configurations that can alter the mechanisms of the game
tc4tweaks.config.general.arcaneCraftingHistorySize=Arcane Crafting History Size
Expand Down

0 comments on commit b973cb1

Please sign in to comment.