Compare commits

...
4 Commits
8 changed files with 144 additions and 25 deletions

No files matched your search

+2 -2
View File
@@ -3,9 +3,9 @@ name: Build and test
on:
pull_request:
branches: [ master, main ]
branches: [ master, main, release/** ]
push:
branches: [ master, main ]
branches: [ master, main, release/** ]
jobs:
build-and-test:
@@ -54,7 +54,10 @@ import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.RecipeHandlerRef;
import codechicken.nei.recipe.RecipeItemInputHandler;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.debug.DebugHandlerWidget;
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@@ -444,6 +447,11 @@ public class ClientHandler {
if (event.world == mc.theWorld) {
NEIClientConfig.unloadWorld();
ItemMobSpawner.clearEntityReferences();
RecipeItemInputHandler.instance.clearTooltipCache();
RecipeHandlerRef.clearCache();
ItemPanels.itemPanel.craftablesPanel.clearGuiReferences();
DebugHandlerWidget.instance.clearGuiReferences();
NEIController.manager = null;
}
}
@@ -7,8 +7,11 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTBase.NBTPrimitive;
@@ -35,6 +38,7 @@ public class CollapsibleItems {
public ItemFilter filter;
public boolean expanded = false;
public String displayName = "";
public String unlocalizedName;
public void setFilter(String filter) {
this.filter = ItemStackFilterParser.parse(filter.trim());
@@ -46,15 +50,38 @@ public class CollapsibleItems {
this.guid = guid;
}
public String getDisplayName() {
if (this.unlocalizedName != null && !this.unlocalizedName.isEmpty()) {
final String translated = StatCollector.translateToLocal(this.unlocalizedName);
if (!translated.equals(this.unlocalizedName)) {
return translated;
}
}
return this.displayName;
}
public boolean matches(ItemStack stack) {
return this.filter.matches(stack);
}
}
public static class ApiGroup {
private String unlocalizedName;
public ApiGroup setName(String unlocalizedName) {
this.unlocalizedName = unlocalizedName;
return this;
}
}
private static final String STATE_KEY = "collapsibleitems";
protected static File statesFile;
protected static final List<GroupItem> groups = new ArrayList<>();
protected static final List<Supplier<GroupItem>> apiGroups = new CopyOnWriteArrayList<>();
protected static final Map<ItemStack, Integer> cache = new ConcurrentHashMap<>();
private CollapsibleItems() {}
@@ -77,11 +104,57 @@ public class CollapsibleItems {
ClientHandler.loadSettingsFile(
"collapsibleitems.cfg",
lines -> parseFile(lines.collect(Collectors.toCollection(ArrayList::new))));
for (Supplier<GroupItem> apiGroup : CollapsibleItems.apiGroups) {
try {
addGroup(apiGroup.get());
} catch (Exception e) {
NEIClientConfig.logger.error("Failed to add API group", e);
}
}
}
loadStates();
}
public static ApiGroup registerGroup(String filter) {
final ApiGroup apiGroup = new ApiGroup();
CollapsibleItems.apiGroups.add(() -> {
GroupItem group = new GroupItem();
group.setFilter(filter);
group.unlocalizedName = apiGroup.unlocalizedName;
return group;
});
return apiGroup;
}
public static ApiGroup registerGroup(Iterable<ItemStack> items) {
final ApiGroup apiGroup = new ApiGroup();
final ItemStackSet filter = new ItemStackSet();
for (ItemStack stack : items) {
if (stack != null) filter.add(stack.copy());
}
if (filter.isEmpty()) return apiGroup;
final String key = filter.keys().stream()
.map(stack -> Item.itemRegistry.getNameForObject(stack.getItem()) + ":" + stack.getItemDamage())
.sorted().collect(Collectors.joining(","));
final String guid = UUID.nameUUIDFromBytes(key.getBytes()).toString();
CollapsibleItems.apiGroups.add(() -> {
GroupItem group = new GroupItem();
group.setFilter(filter, guid);
group.unlocalizedName = apiGroup.unlocalizedName;
return group;
});
return apiGroup;
}
private static void parseFile(List<String> itemStrings) {
final JsonParser parser = new JsonParser();
GroupItem group = new GroupItem();
@@ -92,17 +165,8 @@ public class CollapsibleItems {
if (itemStr.startsWith("; ")) {
JsonObject settings = parser.parse(itemStr.substring(2)).getAsJsonObject();
if (settings.get("displayName") != null) {
group.displayName = settings.get("displayName").getAsString();
}
if (settings.get("unlocalizedName") != null) {
String unlocalizedName = settings.get("unlocalizedName").getAsString();
String displayName = StatCollector.translateToLocal(unlocalizedName);
if (!displayName.equals(unlocalizedName)) {
group.displayName = displayName;
}
group.unlocalizedName = settings.get("unlocalizedName").getAsString();
}
if (settings.get("expanded") != null) {
@@ -176,7 +240,7 @@ public class CollapsibleItems {
public static String getDisplayName(int groupIndex) {
if (groupIndex < CollapsibleItems.groups.size()) {
return CollapsibleItems.groups.get(groupIndex).displayName;
return CollapsibleItems.groups.get(groupIndex).getDisplayName();
}
return null;
@@ -137,7 +137,11 @@ public class ItemCraftablesPanel
@Override
public void execute() {
pendingResult.set(generateCraftables(ItemCraftablesPanel.this.pendingSnapshot));
final CraftablesSnapshot snapshot = ItemCraftablesPanel.this.pendingSnapshot;
if (snapshot != null) {
pendingResult.set(generateCraftables(snapshot));
}
}
};
@@ -298,6 +302,11 @@ public class ItemCraftablesPanel
}
}
public void clearGuiReferences() {
this.lastGuiContainer = null;
this.pendingSnapshot = null;
}
private GuiContainer getGuiContainer() {
final GuiContainer firstGui = NEIClientUtils.getGuiContainer();
return (firstGui instanceof GuiRecipe<?>gui) ? gui.firstGui : firstGui;
@@ -19,6 +19,7 @@ import org.lwjgl.input.Keyboard;
import com.google.common.collect.Sets;
import codechicken.nei.BookmarkContainerInfo;
import codechicken.nei.CollapsibleItems;
import codechicken.nei.ItemList;
import codechicken.nei.ItemSorter;
import codechicken.nei.ItemStackSet;
@@ -341,6 +342,30 @@ public class API {
SubsetWidget.addTag(tag);
}
/**
* Registers a group of items that is collapsed into a single entry in the item panel. Groups registered here have
* the lowest priority: an item that matches a preset or a collapsibleitems.cfg group stays there. They are active
* only while the Collapsible Items option is enabled. Must be called while plugins are loading.
*
* @param filter A search string for matching items that belong to this group. Also identifies the group when its
* expanded state is saved, so changing it resets the saved state.
* @return A handle to optionally set the name shown for the group
*/
public static CollapsibleItems.ApiGroup addCollapsibleGroup(String filter) {
return CollapsibleItems.registerGroup(filter);
}
/**
* Same as {@link #addCollapsibleGroup(String)}, but the group is given as a list of item stacks. The stacks
* identify the group when its expanded state is saved, so changing them resets the saved state.
*
* @param items Item stacks that belong to this group
* @return A handle to optionally set the name shown for the group
*/
public static CollapsibleItems.ApiGroup addCollapsibleGroup(Iterable<ItemStack> items) {
return CollapsibleItems.registerGroup(items);
}
@Deprecated
public static void addSearchProvider(ISearchProvider provider) {}
@@ -19,12 +19,21 @@ import codechicken.nei.recipe.Recipe.RecipeId;
public class RecipeItemInputHandler implements IContainerInputHandler, IContainerTooltipHandler {
public static final RecipeItemInputHandler instance = new RecipeItemInputHandler();
protected RecipeTooltipLineHandler recipeTooltipLineHandler = null;
protected RecipeItemInputHandler() {
}
public static void load() {
RecipeItemInputHandler recipeHandler = new RecipeItemInputHandler();
GuiContainerManager.addInputHandler(recipeHandler);
GuiContainerManager.addTooltipHandler(recipeHandler);
GuiContainerManager.addInputHandler(instance);
GuiContainerManager.addTooltipHandler(instance);
}
public void clearTooltipCache() {
this.recipeTooltipLineHandler = null;
}
@Override
@@ -64,16 +73,17 @@ public class RecipeItemInputHandler implements IContainerInputHandler, IContaine
: null;
if (recipeId == null) {
recipeTooltipLineHandler = null;
} else if (recipeTooltipLineHandler == null || !recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
clearTooltipCache();
} else if (this.recipeTooltipLineHandler == null
|| !this.recipeTooltipLineHandler.getRecipeId().equals(recipeId)) {
this.recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId);
}
if (recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(recipeTooltipLineHandler));
if (this.recipeTooltipLineHandler != null) {
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.recipeTooltipLineHandler));
}
} else {
recipeTooltipLineHandler = null;
clearTooltipCache();
}
return currenttip;
@@ -35,7 +35,6 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler {
protected long lastUpdate = System.currentTimeMillis();
protected String recipeName = "";
protected GuiRecipe<?> gui = null;
protected RecipeHandlerRef handlerRef = null;
protected RecipeWidget widget = null;
protected RecipeId recipeId = null;
@@ -733,6 +733,10 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
});
}
public void clearGuiReferences() {
this.hoveredRecipe = null;
}
public void loadHandlerInfoPatch() {
ClientHandler.loadSettingsFile("handlers.patch", lines -> {