Compare commits

...
4 Commits
11 changed files with 175 additions and 39 deletions

No files matched your search

@@ -305,18 +305,20 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
final RecipeId recipeId = slot.getRecipeId();
final BookmarkGroup group = slot.getGroup();
if (recipeId == null || !removeFullRecipe) {
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
if (group.crafting != null && group.collapsed) {
if (!removeFullRecipe) {
return true;
}
this.grid.removeGroup(groupId);
return true;
}
if (group.crafting != null && group.collapsed && removeFullRecipe) {
this.grid.removeGroup(groupId);
return true;
} else if (group.crafting != null) {
if (recipeId != null && group.crafting != null) {
Set<RecipeId> recipes = group.crafting.recipeRelations.getOrDefault(recipeId, Collections.emptySet());
if (removeFullRecipe && recipes.isEmpty()) {
if (recipes.isEmpty()) {
for (Map.Entry<RecipeId, Set<RecipeId>> entry : group.crafting.recipeRelations.entrySet()) {
if (entry.getValue().contains(recipeId)) {
recipes = entry.getValue();
@@ -326,8 +328,12 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
}
if (!recipes.isEmpty()) {
boolean removed = false;
if (!removeFullRecipe) {
return true;
}
boolean removed = false;
for (RecipeId relRecipeId : recipes) {
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
}
@@ -336,6 +342,11 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
}
}
if (recipeId == null || !removeFullRecipe) {
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
return true;
}
return this.grid.removeRecipe(recipeId, groupId);
}
@@ -21,6 +21,7 @@ import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import codechicken.core.CommonUtils;
import codechicken.nei.SubsetWidget.SubsetTag;
import codechicken.nei.api.API;
import codechicken.nei.api.IRecipeFilter;
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
@@ -33,6 +34,7 @@ import codechicken.nei.util.NBTJson;
public class PresetsList {
public enum PresetMode {
SUBSET,
HIDE,
REMOVE,
GROUP;
@@ -216,6 +218,8 @@ public class PresetsList {
if (!preset.items.isEmpty()) {
presets.add(preset);
}
updateSubsets();
}
public static void savePresets() {
@@ -241,9 +245,24 @@ public class PresetsList {
recipeFilter.cache = null;
itemFilter.cache = null;
updateSubsets();
CollapsibleItems.saveStates();
CollapsibleItems.load();
LayoutManager.markItemsDirty();
}
private static void updateSubsets() {
SubsetWidget.removeTag("Presets");
for (Preset preset : PresetsList.presets) {
if (preset.enabled && preset.mode == PresetMode.SUBSET) {
SubsetWidget.addTag(
new SubsetTag(
"Presets." + preset.name,
stack -> preset.items.contains(Preset.getIdentifier(stack))));
}
}
}
}
@@ -415,6 +415,17 @@ public class SubsetWidget extends Button implements ItemFilterProvider, IContain
}
}
public static void removeTag(String path) {
updateState.stop();
synchronized (tags) {
tags.keySet().removeIf(
parentpath -> parentpath.equals(path.toLowerCase())
|| parentpath.startsWith(path.toLowerCase() + "."));
updateHiddenItems();
}
}
public static boolean isHidden(ItemStack item) {
try {
if (hiddenReadLock.tryLock(5, TimeUnit.SECONDS)) {
@@ -24,6 +24,7 @@ import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.SearchField;
import codechicken.nei.bookmark.BookmarkGrid;
import codechicken.nei.bookmark.BookmarkGroup;
import codechicken.nei.bookmark.BookmarkItem;
import codechicken.nei.bookmark.BookmarksGridSlot;
import codechicken.nei.recipe.AutoCraftingManager;
@@ -378,15 +379,56 @@ public abstract class ShortcutInputHandler {
final RecipeId recipeId = getHotkeyRecipeId(gui, mousex, mousey, stack, slot);
if (slot != null) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark"),
NEIClientUtils.translate(slot.isIngredient() ? "bookmark.remove_item" : "bookmark.remove_recipe"));
final BookmarkGroup group = slot.getGroup();
if (slot.isIngredient()) {
if (group.crafting != null && group.collapsed) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
NEIClientUtils.translate("bookmark.remove_recipe"));
}
NEIClientUtils.translate("bookmark.group.remove_recipe"));
} else if (slot.getRecipeId() == null) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark"),
NEIClientUtils.translate("bookmark.remove_item"));
} else if (group.crafting != null && group.crafting.recipeRelations.entrySet().stream().anyMatch(
entry -> entry.getKey().equals(slot.getRecipeId())
|| entry.getValue().contains(slot.getRecipeId()))) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
NEIClientUtils.translate("bookmark.remove_recipe"));
} else {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
NEIClientUtils.translate("bookmark.remove_recipe"));
if (slot.isIngredient()) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark"),
NEIClientUtils.translate("bookmark.remove_item"));
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
NEIClientUtils.translate("bookmark.remove_recipe"));
} else {
final BookmarkItem item = slot.getBookmarkItem();
if (ItemPanels.bookmarkPanel.getGrid().createChainItems(groupId).values().stream()
.noneMatch(
m -> !m.isIngredient && !m.equals(item) && item.equalsRecipe(m))) {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark"),
NEIClientUtils.translate("bookmark.remove_recipe"));
} else {
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark"),
NEIClientUtils.translate("bookmark.remove_item"));
hotkeys.put(
NEIClientConfig.getKeyName("gui.bookmark", NEIClientUtils.SHIFT_HASH),
NEIClientUtils.translate("bookmark.remove_recipe"));
}
}
}
if (BookmarkContainerInfo.getBookmarkContainerHandler(gui) != null) {
hotkeys.put(
@@ -904,7 +904,7 @@ public class BookmarkGrid extends ItemsGrid<BookmarksGridSlot, BookmarkGrid.Book
if (item.recipeId != null && removeFullRecipe) {
removeRecipe(item.recipeId, item.groupId);
} else {
} else if (itemIndex >= 0) {
this.bookmarkItems.remove(itemIndex);
onItemsChanged();
}
@@ -64,7 +64,7 @@ public class IMCHandler {
final boolean requiresMod = tag.getBoolean("modRequired");
final String excludedModId = tag.hasKey("excludedModId") ? tag.getString("excludedModId") : null;
if (handler.equals("") || modName.equals("") || modId.equals("")) {
if (handler.isEmpty() || modName.isEmpty() || modId.isEmpty()) {
NEIClientConfig.logger.warn("Missing relevant information to registerHandlerInfo!");
return;
}
@@ -74,7 +74,7 @@ public class IMCHandler {
HandlerInfo info = new HandlerInfo(handler, modName, modId, requiresMod, excludedModId);
final String imageResource = tag.hasKey("imageResource") ? tag.getString("imageResource") : null;
if (imageResource != null && !imageResource.equals("")) {
if (imageResource != null && !imageResource.isEmpty()) {
info.setImage(
imageResource,
tag.getInteger("imageX"),
@@ -84,7 +84,7 @@ public class IMCHandler {
}
if (!info.hasImageOrItem()) {
final String itemName = tag.getString("itemName");
if (itemName != null && !itemName.equals("")) {
if (itemName != null && !itemName.isEmpty()) {
info.setItem(itemName, tag.hasKey("nbtInfo") ? tag.getString("nbtInfo") : null);
}
}
@@ -103,6 +103,10 @@ public class IMCHandler {
NEIClientConfig.logger.info("Error setting handler dimensions for " + handler);
}
// true if not set to false
info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton"));
info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton"));
GuiRecipeTab.handlerAdderFromIMC.remove(handler);
GuiRecipeTab.handlerAdderFromIMC.put(handler, info);
}
@@ -207,6 +207,10 @@ public class GuiPresetList extends GuiOptionPane {
modeName = EnumChatFormatting.GOLD + NEIClientUtils.translate("presets.mode.hide.char")
+ EnumChatFormatting.RESET;
break;
case SUBSET:
modeName = EnumChatFormatting.DARK_PURPLE + NEIClientUtils.translate("presets.mode.subset.char")
+ EnumChatFormatting.RESET;
break;
case REMOVE:
modeName = EnumChatFormatting.RED + NEIClientUtils.translate("presets.mode.remove.char")
+ EnumChatFormatting.RESET;
@@ -86,6 +86,7 @@ public class LeftPanel extends GuiWidget {
protected Label modeLabel = new Label(NEIClientUtils.translate("presets.mode"), false);
protected CheckboxButton modeHide;
protected CheckboxButton modeSubset;
protected CheckboxButton modeRemove;
protected CheckboxButton modeGroup;
@@ -114,6 +115,19 @@ public class LeftPanel extends GuiWidget {
}
};
modeSubset = new CheckboxButton(NEIClientUtils.translate("presets.mode.subset")) {
@Override
public boolean isChecked() {
return preset.mode == PresetMode.SUBSET;
}
@Override
protected void onChange() {
preset.mode = this.checked ? PresetMode.SUBSET : null;
}
};
modeRemove = new CheckboxButton(NEIClientUtils.translate("presets.mode.remove")) {
@Override
@@ -164,6 +178,10 @@ public class LeftPanel extends GuiWidget {
modeHide.handleClick(x, y, button);
}
if (modeSubset.contains(x, y)) {
modeSubset.handleClick(x, y, button);
}
if (modeRemove.contains(x, y)) {
modeRemove.handleClick(x, y, button);
}
@@ -248,7 +266,7 @@ public class LeftPanel extends GuiWidget {
@Override
public void update() {
int CHECKBOX_WIDTH = (this.width - 12) / 3;
int CHECKBOX_WIDTH = (this.width - 12) / 4;
nameLabel.x = this.x + 2;
nameLabel.y = this.y + 4;
nameLabel.w = this.width;
@@ -269,12 +287,13 @@ public class LeftPanel extends GuiWidget {
modeLabel.w = this.width;
modeLabel.h = 10;
modeHide.w = modeRemove.w = modeGroup.w = CHECKBOX_WIDTH;
modeHide.h = modeRemove.h = modeGroup.h = INPUT_HEIGHT;
modeHide.y = modeRemove.y = modeGroup.y = modeLabel.y + modeLabel.h;
modeHide.w = modeSubset.w = modeRemove.w = modeGroup.w = CHECKBOX_WIDTH;
modeHide.h = modeSubset.h = modeRemove.h = modeGroup.h = INPUT_HEIGHT;
modeHide.y = modeSubset.y = modeRemove.y = modeGroup.y = modeLabel.y + modeLabel.h;
modeHide.x = this.x + 1;
modeRemove.x = modeHide.x + modeHide.w + 6;
modeSubset.x = modeHide.x + modeHide.w + 6;
modeRemove.x = modeSubset.x + modeSubset.w + 6;
modeGroup.x = modeRemove.x + modeRemove.w + 6;
grid.setGridSize(
@@ -292,6 +311,7 @@ public class LeftPanel extends GuiWidget {
modeLabel.draw(mousex, mousey);
modeHide.draw(mousex, mousey);
modeSubset.draw(mousex, mousey);
modeRemove.draw(mousex, mousey);
modeGroup.draw(mousex, mousey);
@@ -326,6 +346,8 @@ public class LeftPanel extends GuiWidget {
} else if (modeHide.contains(mousex, mousey)) {
tooltip.add(NEIClientUtils.translate("presets.mode.hide.tip"));
} else if (modeSubset.contains(mousex, mousey)) {
tooltip.add(NEIClientUtils.translate("presets.mode.subset.tip"));
} else if (modeRemove.contains(mousex, mousey)) {
tooltip.add(NEIClientUtils.translate("presets.mode.remove.tip"));
} else if (modeGroup.contains(mousex, mousey)) {
@@ -462,8 +462,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
if (!cacheKey.equals(this.recipePageCacheKey)) {
this.recipePageCacheKey = cacheKey;
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
final int recipeIndex = indices.get(refIndex);
for (final int recipeIndex : indices) {
for (PositionedStack pStack : handler.original.getIngredientStacks(recipeIndex)) {
pStack.setPermutationToRender(pStack.getFilteredPermutations().get(0));
}
@@ -472,7 +471,8 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
final int xOffset = (limitToOneRecipe ? 0 : guiLeft) + xSize - BORDER_PADDING;
final int yOffset = (limitToOneRecipe ? -BUTTON_HEIGHT : guiTop - 18) + getRefIndexPosition(0).y;
final int height = handlerInfo.getHeight() - yShift;
final boolean showFavorites = NEIClientConfig.favoritesEnabled();
final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton();
final boolean showOverlay = handlerInfo.getShowOverlayButton();
final UpdateRecipeButtonsEvent.Pre preEvent = new UpdateRecipeButtonsEvent.Pre(
this,
xOffset,
@@ -484,7 +484,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
if (MinecraftForge.EVENT_BUS.post(preEvent)) {
buttons = preEvent.buttonList;
} else {
for (int refIndex = 0; refIndex < indices.size(); refIndex++) {
final int recipeIndex = indices.get(refIndex);
@@ -493,20 +492,19 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
continue;
}
GuiRecipeButton button = new GuiOverlayButton(
firstGui,
RecipeHandlerRef.of(handler.original, recipeIndex),
xOffset - GuiRecipeButton.BUTTON_WIDTH,
yOffset + height * (refIndex + 1));
buttons.add(button);
if (showFavorites) {
int x = xOffset - GuiRecipeButton.BUTTON_WIDTH;
int y = yOffset + height * (refIndex + 1);
if (showOverlay) {
buttons.add(
new GuiFavoriteButton(
new GuiOverlayButton(
firstGui,
RecipeHandlerRef.of(handler.original, recipeIndex),
button.xPosition,
button.yPosition - button.height - 1));
x,
y));
y -= GuiRecipeButton.BUTTON_HEIGHT + 1;
}
if (showFavorites) {
buttons.add(new GuiFavoriteButton(RecipeHandlerRef.of(handler.original, recipeIndex), x, y));
}
}
@@ -522,6 +520,10 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
buttons.removeIf(GuiFavoriteButton.class::isInstance);
}
if (!showOverlay) {
buttons.removeIf(GuiOverlayButton.class::isInstance);
}
/** compatibility with old format */
this.overlayButtons = buttons.stream().filter(GuiOverlayButton.class::isInstance)
.toArray(GuiOverlayButton[]::new);
@@ -28,6 +28,8 @@ public class HandlerInfo {
private int height = DEFAULT_HEIGHT;
private int width = DEFAULT_WIDTH;
private int maxRecipesPerPage = DEFAULT_MAX_PER_PAGE;
private boolean showFavoritesButton = true;
private boolean showOverlayButton = true;
private ItemStack itemStack = null;
private DrawableResource image = null;
@@ -112,6 +114,22 @@ public class HandlerInfo {
this.yShift = yShift;
}
public boolean getShowFavoritesButton() {
return this.showFavoritesButton;
}
public void setShowFavoritesButton(boolean showFavoritesButton) {
this.showFavoritesButton = showFavoritesButton;
}
public boolean getShowOverlayButton() {
return this.showOverlayButton;
}
public void setShowOverlayButton(boolean showOverlayButton) {
this.showOverlayButton = showOverlayButton;
}
public static class Builder {
private final HandlerInfo info;
@@ -571,6 +571,9 @@ nei.presets.mode=Mode
nei.presets.mode.hide=Hide
nei.presets.mode.hide.char=H
nei.presets.mode.hide.tip=Hide items in panel
nei.presets.mode.subset=Subset
nei.presets.mode.subset.char=S
nei.presets.mode.subset.tip=Create custom subsets
nei.presets.mode.remove=Remove
nei.presets.mode.remove.tip=Hide items in panel and their recipes
nei.presets.mode.remove.char=R