Compare commits

...
11 Commits
Author SHA1 Message Date
Lasm Gratel dc4426d9c9 fix #479 (#483) 2024-05-27 14:25:19 +02:00
Martin Robertz d05a9eafb3 update 2024-05-04 13:54:08 +02:00
Lasm Gratel 5056fe5437 Concurrent recipe profiler (#478)
* concurrent recipe profiler

* eliminate NPE by giving nulls a name
2024-05-04 13:50:56 +02:00
slprimeandslprime 9fd9aad357 Fix Bookmarks DnD (#476)
Co-authored-by: slprime <[email protected]>
2024-04-24 21:25:46 +02:00
Martin Robertz acaead41ee update 2024-04-22 12:51:44 +02:00
D-Cysteine 951f1b0d0d Add Railcraft NEI handlers to height hack (#475) 2024-04-21 21:52:54 +02:00
Martin Robertz daab313288 update 2024-03-21 20:35:30 +01:00
MalTeeez 25eaa492f7 Update icon (#471) 2024-03-21 20:32:17 +01:00
Caedis 1b34b24495 Adjust readability and padding of item panel footer size (#470) 2024-03-07 05:32:08 -06:00
Martin Robertz b9cd48f8f9 Update settings.gradle (#469) 2024-03-07 11:08:51 +01:00
Caedis b2afc8c9e0 Fix history being hidden when search is centered and item quantity bar is disabled (#468) 2024-03-07 11:01:02 +01:00
17 changed files with 116 additions and 30 deletions

No files matched your search

+1 -1
View File
@@ -117,7 +117,7 @@ minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
Binary file not shown.
+1 -1
View File
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
+1 -1
View File
@@ -17,7 +17,7 @@ pluginManagement {
}
plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.15'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.22'
}
@@ -2060,7 +2060,7 @@ public class BookmarkPanel extends PanelWidget {
return false;
}
if (NEIClientUtils.controlKey()) {
if (!inEditingState() && NEIClientUtils.controlKey()) {
final ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
if (slot != null) {
+12 -3
View File
@@ -168,7 +168,10 @@ public class ItemPanel extends PanelWidget {
}
protected int resizeFooter(GuiContainer gui) {
if (!NEIClientConfig.showItemQuantityWidget() && NEIClientConfig.isSearchWidgetCentered()) return 0;
if (!NEIClientConfig.showItemQuantityWidget() && NEIClientConfig.isSearchWidgetCentered()
&& !NEIClientConfig.showHistoryPanelWidget()) {
return 0;
}
final int BUTTON_SIZE = 20;
more.w = less.w = BUTTON_SIZE;
@@ -197,8 +200,14 @@ public class ItemPanel extends PanelWidget {
historyPanel.x = x;
historyPanel.w = w;
historyPanel.h = ItemsGrid.SLOT_SIZE * NEIClientConfig.getIntSetting("inventory.history.useRows");
historyPanel.y = quantity.y - PanelWidget.PADDING - historyPanel.h;
return quantity.h + historyPanel.h + PanelWidget.PADDING * 2;
if (NEIClientConfig.showItemQuantityWidget() || !NEIClientConfig.isSearchWidgetCentered()) {
historyPanel.y = quantity.y - historyPanel.h - PanelWidget.PADDING;
return quantity.h + historyPanel.h + PanelWidget.PADDING * 2;
} else {
historyPanel.y = y + h - historyPanel.h;
return historyPanel.h + PanelWidget.PADDING;
}
}
return quantity.h + PanelWidget.PADDING;
@@ -667,6 +667,10 @@ public class NEIClientConfig {
return !getBooleanSetting("tools.catalyst_load_from_config");
}
public static boolean isProfileRecipeEnabled() {
return NEIClientConfig.getBooleanSetting("inventory.profileRecipes");
}
public static void setEnabled(boolean flag) {
getSetting("inventory.widgetsenabled").setBooleanValue(flag);
}
@@ -34,7 +34,9 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
final BookmarkRecipeId recipeId;
if ("item".equals(outputId)) {
results = Arrays.asList(results).stream().map(rslt -> normalizeItemStack((ItemStack) rslt)).toArray();
for (int i = 0; i < results.length; i++) {
results[i] = normalizeItemStack((ItemStack) results[i]);
}
recipeId = getRecipeId(mc.currentScreen, (ItemStack) results[0]);
} else if ("recipeId".equals(outputId)) {
recipeId = (BookmarkRecipeId) results[1];
@@ -103,7 +105,7 @@ public class GuiCraftingRecipe extends GuiRecipe<ICraftingHandler> {
"outputId: " + outputId,
"results: " + Arrays.toString(results));
return recipeQuery.runWithProfiling("recipe.concurrent.crafting");
return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.crafting"));
}
private static ArrayList<ICraftingHandler> filterByHandlerName(ArrayList<ICraftingHandler> craftinghandlers,
@@ -416,8 +416,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
nextpage = new GuiNEIButton(2, leftButtonX, guiTop + 17, buttonWidth, buttonHeight, "<");
prevpage = new GuiNEIButton(3, rightButtonX, guiTop + 17, buttonWidth, buttonHeight, ">");
toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 38, 8, 8).setTextureSize(128, 128)
.build();
toggleSearch.icon = new DrawableBuilder("nei:textures/nei_sprites.png", 0, 76, 10, 10).build();
buttonList.addAll(Arrays.asList(nexttype, prevtype, nextpage, prevpage));
@@ -18,8 +18,9 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
public static boolean openRecipeGui(String inputId, Object... ingredients) {
if ("item".equals(inputId)) {
ingredients = Arrays.asList(ingredients).stream().map(ingr -> normalizeItemStack((ItemStack) ingr))
.toArray();
for (int i = 0; i < ingredients.length; i++) {
ingredients[i] = normalizeItemStack((ItemStack) ingredients[i]);
}
}
final ArrayList<IUsageHandler> handlers = getUsageHandlers(inputId, ingredients);
@@ -52,7 +53,7 @@ public class GuiUsageRecipe extends GuiRecipe<IUsageHandler> {
"inputId: " + inputId,
"ingredients: " + Arrays.toString(ingredients));
return recipeQuery.runWithProfiling("recipe.concurrent.usage");
return recipeQuery.runWithProfiling(NEIClientUtils.translate("recipe.concurrent.usage"));
}
private static ItemStack normalizeItemStack(ItemStack stack) {
@@ -81,7 +81,7 @@ class ItemsHistoryHandler implements ICraftingHandler, IUsageHandler {
@Override
public String getRecipeName() {
return null;
return "Items History";
}
@Override
@@ -3,29 +3,26 @@ package codechicken.nei.recipe;
import static codechicken.lib.gui.GuiDraw.drawString;
import static codechicken.lib.gui.GuiDraw.getStringWidth;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import codechicken.core.TaskProfiler;
import codechicken.core.TaskProfiler.ProfilerResult;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.api.IRecipeOverlayRenderer;
import codechicken.nei.util.AsyncTaskProfiler;
public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
private static final TaskProfiler profiler = new TaskProfiler();
private static final AsyncTaskProfiler profiler = new AsyncTaskProfiler();
public static TaskProfiler getProfiler() {
profiler.clear();
public static AsyncTaskProfiler getProfiler() {
return profiler;
}
@@ -42,7 +39,7 @@ public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
@Override
public int numRecipes() {
if (!NEIClientConfig.getBooleanSetting("inventory.profileRecipes")) return 0;
if (!NEIClientConfig.isProfileRecipeEnabled()) return 0;
return (int) Math.ceil(
((crafting ? GuiCraftingRecipe.craftinghandlers.size() : GuiUsageRecipe.usagehandlers.size()) - 1)
@@ -55,8 +52,7 @@ public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
@Override
public void drawForeground(int recipe) {
List<ProfilerResult> results = profiler.getResults();
for (Iterator<ProfilerResult> it = results.iterator(); it.hasNext();)
if (it.next().name.equals(getRecipeName())) it.remove();
results.removeIf(profilerResult -> getRecipeName().equals(profilerResult.name));
results.sort((o1, o2) -> o1.time < o2.time ? 1 : -1);
@@ -65,10 +61,9 @@ public class ProfilerRecipeHandler implements ICraftingHandler, IUsageHandler {
int y = (i % 6) * 20 + 6;
drawString(r.name, 8, y, 0xFF808080, false);
DecimalFormat format = new DecimalFormat("0.00");
String s = format.format(r.fraction * 100) + "%";
if (r.time < 1000000L) s += " (" + (r.time / 1000) + "us)";
else s += " (" + (r.time / 1000000) + "ms)";
String s;
if (r.time < 1000000L) s = (r.time / 1000) + "us";
else s = (r.time / 1000000) + "ms";
drawString(s, 156 - getStringWidth(s), y + 10, 0xFF404040, false);
}
@@ -15,6 +15,7 @@ import net.minecraft.util.IChatComponent;
import codechicken.core.TaskProfiler;
import codechicken.nei.ItemList;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.util.AsyncTaskProfiler;
class RecipeHandlerQuery<T extends IRecipeHandler> {
@@ -34,7 +35,15 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
ArrayList<T> runWithProfiling(String profilerSection) {
TaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
profiler.start(profilerSection);
// Save the current config state here, as it may be altered
// if getRecipeHandlesParallel took so long and player accidentally changed config.
boolean profileRecipes = NEIClientConfig.isProfileRecipeEnabled();
if (profileRecipes) {
profiler.clear();
profiler.start(profilerSection);
}
try {
ArrayList<T> handlers = getRecipeHandlersParallel();
@@ -47,7 +56,7 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
displayRecipeLookupError();
return new ArrayList<>(0);
} finally {
profiler.end();
if (profileRecipes) profiler.end();
}
}
@@ -63,12 +72,17 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
private ArrayList<T> getSerialHandlersWithRecipes() {
return serialRecipeHandlers.stream().map(handler -> {
AsyncTaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
profiler.clearCurrent();
profiler.start(handler.getRecipeName());
try {
return isHidden(handler) ? null : recipeHandlerFunction.apply(handler);
} catch (Throwable t) {
printLog(t);
error = true;
return null;
} finally {
profiler.end();
}
}).filter(h -> h != null && h.numRecipes() > 0 && SearchRecipeHandler.findFirst(h, (recipeIndex) -> true) != -1)
.collect(Collectors.toCollection(ArrayList::new));
@@ -77,12 +91,17 @@ class RecipeHandlerQuery<T extends IRecipeHandler> {
private ArrayList<T> getHandlersWithRecipes() throws InterruptedException, ExecutionException {
return ItemList.forkJoinPool.submit(() -> recipeHandlers.parallelStream().map(handler -> {
AsyncTaskProfiler profiler = ProfilerRecipeHandler.getProfiler();
profiler.clearCurrent();
profiler.start(handler.getRecipeName());
try {
return isHidden(handler) ? null : recipeHandlerFunction.apply(handler);
} catch (Throwable t) {
printLog(t);
error = true;
return null;
} finally {
profiler.end();
}
}).filter(h -> h != null && h.numRecipes() > 0 && SearchRecipeHandler.findFirst(h, (recipeIndex) -> true) != -1)
.collect(Collectors.toCollection(ArrayList::new))).get();
@@ -0,0 +1,54 @@
package codechicken.nei.util;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import codechicken.core.TaskProfiler;
public class AsyncTaskProfiler extends TaskProfiler {
public ThreadLocal<TaskProfiler> threadedProfiler = ThreadLocal.withInitial(TaskProfiler::new);
public Map<String, Long> times = new ConcurrentHashMap<>();
@Override
public void start(String section) {
if (section == null) section = "<unnamed>";
threadedProfiler.get().start(section);
}
@Override
public void end() {
TaskProfiler profiler = threadedProfiler.get();
if (profiler != null) {
profiler.end();
if (profiler.times != null && !profiler.times.isEmpty()) {
times.putAll(threadedProfiler.get().times);
}
}
}
@Override
public List<ProfilerResult> getResults() {
ArrayList<ProfilerResult> results = new ArrayList<>(times.size());
long totalTime = times.values().stream().reduce(0L, Long::sum);
for (Entry<String, Long> e : times.entrySet())
results.add(new ProfilerResult(e.getKey(), e.getValue(), totalTime));
return results;
}
@Override
public void clear() {
if (threadedProfiler.get().currentSection != null) threadedProfiler.get().end();
threadedProfiler.get().clear();
times.clear();
}
public void clearCurrent() {
if (threadedProfiler.get().currentSection != null) threadedProfiler.get().end();
threadedProfiler.get().clear();
}
}
@@ -10,6 +10,7 @@ ic2.neiIntegration.core.recipehandler.*
mariculture.plugins.nei.*
redgear.brewcraft.plugins.nei.*
tconstruct.plugins.nei.*
tonius.neiintegration.mods.railcraft.*
WayofTime.alchemicalWizardry.client.nei.*
exnihilo.compatibility.nei.*
blusunrize.immersiveengineering.client.nei.*
@@ -321,6 +321,8 @@ nei.recipe.firework.tooltip2=Multiple charges can be spawned from one rocket
nei.recipe.brewing=Brewing
nei.recipe.profiler.crafting=Crafting Profiling
nei.recipe.profiler.usage=Usage Profiling
nei.recipe.concurrent.usage=Concurrent Usage - Total
nei.recipe.concurrent.crafting=Concurrent Crafting - Total
nei.itemsort.minecraft=Minecraft
nei.itemsort.minecraft.tip=Sorts items from vanilla minecraft first
Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB