2019-12-24 13:37:41 -08:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import java.awt.Point;
|
2019-12-24 13:37:41 -08:00
|
|
|
import java.io.File;
|
2022-01-09 19:05:30 +02:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
2019-12-24 13:37:41 -08:00
|
|
|
import java.io.IOException;
|
2022-06-24 12:32:13 +01:00
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.io.OutputStream;
|
2023-09-24 23:02:09 +02:00
|
|
|
import java.util.ArrayList;
|
2024-07-26 03:41:15 +03:00
|
|
|
import java.util.Arrays;
|
2025-07-12 08:44:34 +03:00
|
|
|
import java.util.Collections;
|
2024-02-04 14:09:24 +02:00
|
|
|
import java.util.HashSet;
|
2023-09-24 23:02:09 +02:00
|
|
|
import java.util.List;
|
2025-04-24 18:48:40 +03:00
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import org.apache.commons.io.IOUtils;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.core.CommonUtils;
|
|
|
|
|
import codechicken.lib.gui.GuiDraw;
|
|
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.api.IBookmarkContainerHandler;
|
|
|
|
|
import codechicken.nei.bookmark.BookmarkGrid;
|
|
|
|
|
import codechicken.nei.bookmark.BookmarkGroup;
|
|
|
|
|
import codechicken.nei.bookmark.BookmarkItem;
|
2025-11-07 19:54:09 +02:00
|
|
|
import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType;
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.bookmark.BookmarkStorage;
|
|
|
|
|
import codechicken.nei.bookmark.BookmarksGridSlot;
|
|
|
|
|
import codechicken.nei.bookmark.GroupingItem;
|
|
|
|
|
import codechicken.nei.bookmark.SortableGroup;
|
|
|
|
|
import codechicken.nei.bookmark.SortableItem;
|
|
|
|
|
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
|
|
|
|
|
import codechicken.nei.recipe.BookmarkRecipeId;
|
|
|
|
|
import codechicken.nei.recipe.Recipe;
|
|
|
|
|
import codechicken.nei.recipe.Recipe.RecipeId;
|
|
|
|
|
import codechicken.nei.recipe.Recipe.RecipeIngredient;
|
|
|
|
|
import codechicken.nei.recipe.StackInfo;
|
|
|
|
|
import codechicken.nei.recipe.chain.RecipeChainMath;
|
|
|
|
|
import codechicken.nei.recipe.chain.RecipeChainTooltipLineHandler;
|
|
|
|
|
import codechicken.nei.util.NEIMouseUtils;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Deprecated
|
|
|
|
|
public static class BookmarkRecipe {
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public String handlerName = "";
|
|
|
|
|
public List<ItemStack> result = new ArrayList<>();
|
|
|
|
|
public List<ItemStack> ingredients = new ArrayList<>();
|
|
|
|
|
public BookmarkRecipeId recipeId = null;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public BookmarkRecipe(ItemStack... result) {
|
|
|
|
|
this.result.addAll(Arrays.asList(result));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public BookmarkRecipeId getRecipeId() {
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (!handlerName.isEmpty() && !ingredients.isEmpty() && recipeId == null) {
|
|
|
|
|
recipeId = new BookmarkRecipeId(handlerName, ingredients);
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return recipeId;
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public Recipe getRecipe() {
|
|
|
|
|
String handlerName = this.handlerName;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (handlerName.isEmpty() && recipeId != null) {
|
|
|
|
|
handlerName = recipeId.handlerName;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return Recipe.of(this.result, handlerName, this.ingredients);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public enum BookmarkViewMode {
|
|
|
|
|
DEFAULT,
|
|
|
|
|
TODO_LIST
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected BookmarkStorage storage = new BookmarkStorage();
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public SortableItem sortableItem;
|
|
|
|
|
public SortableGroup sortableGroup;
|
|
|
|
|
public GroupingItem groupingItem;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler;
|
|
|
|
|
protected RecipeChainTooltipLineHandler recipeChainTooltipLineHandler;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public Button namespacePrev;
|
|
|
|
|
public Button namespaceNext;
|
|
|
|
|
public Button pullBookmarkedItems;
|
|
|
|
|
public Label namespaceLabel;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public BookmarkPanel() {
|
|
|
|
|
this.grid = new BookmarkGrid();
|
2020-01-20 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public void update() {
|
|
|
|
|
this.grid = this.storage.getActiveGrid();
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void init() {
|
2022-01-02 23:30:54 +02:00
|
|
|
super.init();
|
|
|
|
|
|
|
|
|
|
namespaceLabel = new Label("1", true);
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
namespacePrev = new Button("<") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
if (inEditingState() || rightclick) {
|
2022-01-02 23:30:54 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return storage.prevNamespace();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
namespaceNext = new Button(">") {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
2024-02-04 14:09:24 +02:00
|
|
|
if (inEditingState() || rightclick) {
|
2022-01-02 23:30:54 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return storage.nextNamespace();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
pullBookmarkedItems = new Button("P") {
|
2023-08-07 15:29:05 +02:00
|
|
|
|
|
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (rightclick) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
return pullBookmarkItems(BookmarkGrid.DEFAULT_GROUP_ID, NEIClientUtils.shiftKey());
|
2023-08-07 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-04-24 18:48:40 +03:00
|
|
|
public String getButtonTip() {
|
|
|
|
|
return NEIClientUtils.translate("bookmark.pullBookmarkedItems.tip");
|
2023-08-07 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public BookmarksGridSlot getSlotMouseOver(int mousex, int mousey) {
|
|
|
|
|
return this.grid.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public String getLabelText() {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.grid.isCraftingMode(BookmarkGrid.DEFAULT_GROUP_ID)) {
|
2024-02-04 14:09:24 +02:00
|
|
|
return String.format("§2[§r%d/%d§2]§r", getPage(), Math.max(1, getNumPages()));
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
return String.format("%d/%d", getPage(), Math.max(1, getNumPages()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean inEditingState() {
|
2024-08-17 23:24:27 +03:00
|
|
|
return this.sortableItem != null || this.sortableGroup != null
|
|
|
|
|
|| this.draggedStack != null
|
|
|
|
|
|| this.groupingItem != null && this.groupingItem.hasEndRow();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean addItem(ItemStack stack) {
|
|
|
|
|
return addItem(stack, null, BookmarkGrid.DEFAULT_GROUP_ID);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean addItem(ItemStack itemStack, RecipeId recipeId, int groupId) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (itemStack != null && this.grid.indexOf(groupId, itemStack, recipeId, false) == -1) {
|
|
|
|
|
final boolean existsRecipe = recipeId != null
|
|
|
|
|
&& this.grid.existsRecipe(recipeId, BookmarkGrid.DEFAULT_GROUP_ID);
|
|
|
|
|
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(itemStack);
|
2025-11-07 19:54:09 +02:00
|
|
|
long count = nbTag.getInteger("Count");
|
|
|
|
|
long factor = existsRecipe ? Math.max(count, 1) : 1;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (existsRecipe) {
|
|
|
|
|
for (int i = 0; i < this.grid.size(); i++) {
|
|
|
|
|
if (this.grid.getBookmarkItem(i).equalsRecipe(recipeId, groupId)) {
|
2025-10-09 22:22:37 +03:00
|
|
|
count *= this.grid.getBookmarkItem(i).getMultiplier();
|
2025-04-24 18:48:40 +03:00
|
|
|
break;
|
|
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
2025-10-09 22:22:37 +03:00
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-10-09 22:22:37 +03:00
|
|
|
this.grid.addItem(
|
2025-11-07 19:54:09 +02:00
|
|
|
BookmarkItem.of(
|
|
|
|
|
groupId,
|
|
|
|
|
StackInfo.withAmount(itemStack, count),
|
|
|
|
|
factor,
|
|
|
|
|
recipeId,
|
|
|
|
|
existsRecipe ? BookmarkItemType.RESULT : BookmarkItemType.ITEM),
|
2025-10-09 22:22:37 +03:00
|
|
|
true);
|
2025-04-24 18:48:40 +03:00
|
|
|
return true;
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return false;
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-08-22 15:06:27 +03:00
|
|
|
public boolean addRecipe(Recipe recipe, int multiplier, int groupId) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final RecipeId recipeId = recipe.getRecipeId();
|
|
|
|
|
|
|
|
|
|
if (recipe != null && this.grid.getGroup(groupId) != null && !this.grid.existsRecipe(recipeId, groupId)) {
|
2025-08-22 15:06:27 +03:00
|
|
|
this.grid.addRecipe(recipe, multiplier, groupId);
|
2025-04-24 18:48:40 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean addGroup(List<?> items, BookmarkViewMode viewMode, boolean crafting) {
|
|
|
|
|
if (items.isEmpty()) return false;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (viewMode == null) {
|
|
|
|
|
viewMode = this.grid.getViewMode(BookmarkGrid.DEFAULT_GROUP_ID);
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final int groupId = this.grid.addGroup(new BookmarkGroup(viewMode, crafting));
|
|
|
|
|
final ItemStackSet uniqueStack = new ItemStackSet();
|
|
|
|
|
final Set<RecipeId> uniqueRecipe = new HashSet<>();
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
for (Object item : items) {
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item instanceof Recipe recipe) {
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (uniqueRecipe.add(recipe.getRecipeId())) {
|
2025-08-22 15:06:27 +03:00
|
|
|
this.grid.addRecipe(recipe, 1, groupId);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
} else if (item instanceof RecipeId recipeId) {
|
|
|
|
|
ItemStack stack = recipeId.getResult();
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (stack != null && uniqueRecipe.add(recipeId)) {
|
|
|
|
|
this.grid.addItem(
|
2025-11-07 19:54:09 +02:00
|
|
|
BookmarkItem
|
|
|
|
|
.of(groupId, stack, StackInfo.getAmount(stack), recipeId, BookmarkItemType.ITEM),
|
2025-04-24 18:48:40 +03:00
|
|
|
true);
|
|
|
|
|
uniqueStack.add(stack);
|
|
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
} else {
|
|
|
|
|
ItemStack stack = extractItem(item);
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (stack != null && !uniqueStack.contains(stack)) {
|
|
|
|
|
this.grid.addItem(BookmarkItem.of(groupId, stack), true);
|
|
|
|
|
uniqueStack.add(stack);
|
|
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
2024-07-26 03:41:15 +03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return true;
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected static ItemStack extractItem(Object item) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item instanceof PositionedStack positionedStack) {
|
|
|
|
|
return positionedStack.item;
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item instanceof NBTTagCompound nbTag) {
|
|
|
|
|
return StackInfo.loadFromNBT(nbTag);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item instanceof RecipeIngredient ingr) {
|
|
|
|
|
return ingr.getItemStack();
|
2024-07-26 03:41:15 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item instanceof ItemStack stack) {
|
|
|
|
|
return stack;
|
|
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return null;
|
2022-08-19 15:03:42 +03:00
|
|
|
}
|
2020-01-05 12:13:50 -08:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean removeItem(ItemStack itemStack, RecipeId recipeId, int groupId) {
|
|
|
|
|
final int itemIndex = this.grid.indexOf(groupId, itemStack, recipeId, false);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (itemIndex != -1) {
|
|
|
|
|
this.grid.removeRecipe(itemIndex, false);
|
|
|
|
|
return true;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return false;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean removeSlot(int mousex, int mousey, boolean removeFullRecipe) {
|
|
|
|
|
final BookmarksGridSlot slot = getSlotMouseOver(mousex, mousey);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (slot == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final int groupId = slot.getGroupId();
|
2025-11-07 19:54:09 +02:00
|
|
|
final RecipeId recipeId = slot.getType() == BookmarkItemType.ITEM ? null : slot.getRecipeId();
|
2025-04-24 18:48:40 +03:00
|
|
|
final BookmarkGroup group = slot.getGroup();
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-08-22 15:22:09 +03:00
|
|
|
if (group.crafting != null && group.collapsed) {
|
|
|
|
|
|
|
|
|
|
if (!removeFullRecipe) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-07-12 08:44:34 +03:00
|
|
|
this.grid.removeGroup(groupId);
|
|
|
|
|
return true;
|
2025-08-22 15:22:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (recipeId != null && group.crafting != null) {
|
2025-07-12 08:44:34 +03:00
|
|
|
Set<RecipeId> recipes = group.crafting.recipeRelations.getOrDefault(recipeId, Collections.emptySet());
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-08-22 15:22:09 +03:00
|
|
|
if (recipes.isEmpty()) {
|
2025-07-12 08:44:34 +03:00
|
|
|
for (Map.Entry<RecipeId, Set<RecipeId>> entry : group.crafting.recipeRelations.entrySet()) {
|
|
|
|
|
if (entry.getValue().contains(recipeId)) {
|
|
|
|
|
recipes = entry.getValue();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-07-12 08:44:34 +03:00
|
|
|
if (!recipes.isEmpty()) {
|
|
|
|
|
|
2025-08-22 15:22:09 +03:00
|
|
|
if (!removeFullRecipe) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean removed = false;
|
2025-07-12 08:44:34 +03:00
|
|
|
for (RecipeId relRecipeId : recipes) {
|
|
|
|
|
removed = this.grid.removeRecipe(relRecipeId, groupId) || removed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return removed;
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-08-22 15:22:09 +03:00
|
|
|
if (recipeId == null || !removeFullRecipe) {
|
|
|
|
|
this.grid.removeRecipe(slot.itemIndex, removeFullRecipe);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return this.grid.removeRecipe(recipeId, groupId);
|
2020-01-05 12:13:50 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean removeRecipe(RecipeId recipeId, int groupId) {
|
|
|
|
|
return this.grid.removeRecipe(recipeId, groupId);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean removeGroup(int groupId) {
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.grid.getGroup(groupId) != null) {
|
|
|
|
|
this.grid.removeGroup(groupId);
|
2022-01-02 23:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public RecipeId getRecipeId(int itemIndex) {
|
|
|
|
|
BookmarkItem meta = this.grid.getCalculatedItem(itemIndex);
|
2025-11-07 19:54:09 +02:00
|
|
|
return meta.type == BookmarkItemType.INGREDIENT ? null : meta.recipeId;
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean existsRecipe(RecipeId recipeId, int groupId) {
|
|
|
|
|
return this.grid.existsRecipe(recipeId, groupId);
|
2020-01-05 12:13:50 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public int getHoveredGroupId(boolean groupPanel) {
|
|
|
|
|
final int overRowIndex = this.grid.getHoveredRowIndex(groupPanel);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (groupPanel && overRowIndex == -1 && !this.grid.isEmpty()) {
|
|
|
|
|
final Point mouse = GuiDraw.getMousePosition();
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(mouse.x, mouse.y)) {
|
|
|
|
|
return BookmarkGrid.DEFAULT_GROUP_ID;
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (overRowIndex >= 0) {
|
|
|
|
|
int groupId = this.grid.getRowGroupId(overRowIndex);
|
|
|
|
|
return groupId == BookmarkGrid.DEFAULT_GROUP_ID ? -1 : groupId;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
return -1;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected String getNamespaceLabelText(boolean shortFormat) {
|
|
|
|
|
String activePage = String.valueOf(this.storage.getActiveIndex() + 1);
|
|
|
|
|
|
|
|
|
|
return shortFormat ? activePage : (activePage + "/" + this.storage.getNamespaceSize());
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-29 23:14:52 +03:00
|
|
|
public void load() {
|
|
|
|
|
String worldPath = "global";
|
|
|
|
|
|
|
|
|
|
if (NEIClientConfig.getBooleanSetting("inventory.bookmarks.worldSpecific")) {
|
|
|
|
|
worldPath = NEIClientConfig.getWorldPath();
|
|
|
|
|
}
|
2022-01-09 19:05:30 +02:00
|
|
|
|
|
|
|
|
final File dir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
|
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
dir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final File bookmarkFile = new File(dir, "bookmarks.ini");
|
2022-01-09 19:05:30 +02:00
|
|
|
|
|
|
|
|
if (!bookmarkFile.exists()) {
|
|
|
|
|
final File globalBookmarks = new File(CommonUtils.getMinecraftDir(), "saves/NEI/global/bookmarks.ini");
|
|
|
|
|
final File configBookmarks = new File(NEIClientConfig.configDir, "bookmarks.ini");
|
2022-06-24 12:32:13 +01:00
|
|
|
final File defaultBookmarks = configBookmarks.exists() ? configBookmarks : globalBookmarks;
|
2022-01-09 19:05:30 +02:00
|
|
|
|
|
|
|
|
if (defaultBookmarks.exists()) {
|
|
|
|
|
|
|
|
|
|
try {
|
2024-08-29 23:14:52 +03:00
|
|
|
if (bookmarkFile.createNewFile()) {
|
|
|
|
|
InputStream src = new FileInputStream(defaultBookmarks);
|
|
|
|
|
OutputStream dst = new FileOutputStream(bookmarkFile);
|
2022-01-09 19:05:30 +02:00
|
|
|
|
2024-08-29 23:14:52 +03:00
|
|
|
IOUtils.copy(src, dst);
|
2022-01-09 19:05:30 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
src.close();
|
|
|
|
|
dst.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {}
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
this.storage.load(bookmarkFile);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public void save() {
|
|
|
|
|
this.storage.save();
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int resizeHeader(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final LayoutStyleMinecraft layout = (LayoutStyleMinecraft) LayoutManager.getLayoutStyle();
|
|
|
|
|
final int rows = (int) Math.ceil((double) layout.buttonCount / layout.numButtons);
|
2025-08-22 15:03:05 +03:00
|
|
|
final int diff = rows * 19 + PADDING - y;
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
if (diff > 0) {
|
|
|
|
|
y += diff;
|
|
|
|
|
h -= diff;
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
return super.resizeHeader(gui);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int resizeFooter(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final int BUTTON_SIZE = 16;
|
|
|
|
|
|
|
|
|
|
final ButtonCycled button = LayoutManager.bookmarksButton;
|
2022-06-24 12:32:13 +01:00
|
|
|
final int leftBorder = y + h > button.y ? button.x + button.w + 2 : x;
|
2022-01-02 23:30:54 +02:00
|
|
|
final int rightBorder = x + w;
|
2022-05-06 22:41:45 +03:00
|
|
|
final int center = leftBorder + Math.max(0, (rightBorder - leftBorder) / 2);
|
2025-04-24 18:48:40 +03:00
|
|
|
int labelWidth;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2023-08-07 15:29:05 +02:00
|
|
|
namespacePrev.h = namespaceNext.h = pullBookmarkedItems.h = BUTTON_SIZE;
|
|
|
|
|
namespacePrev.w = namespaceNext.w = pullBookmarkedItems.w = BUTTON_SIZE;
|
|
|
|
|
namespacePrev.y = namespaceNext.y = pullBookmarkedItems.y = y + h - BUTTON_SIZE;
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (rightBorder - leftBorder >= 70) {
|
|
|
|
|
labelWidth = 36;
|
|
|
|
|
namespaceLabel.text = getNamespaceLabelText(false);
|
|
|
|
|
} else {
|
|
|
|
|
labelWidth = 18;
|
|
|
|
|
namespaceLabel.text = getNamespaceLabelText(true);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
namespaceLabel.y = namespacePrev.y + 5;
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaceLabel.x = center;
|
|
|
|
|
|
|
|
|
|
namespacePrev.x = center - labelWidth / 2 - 2 - namespacePrev.w;
|
|
|
|
|
namespaceNext.x = center + labelWidth / 2 + 2;
|
2023-08-07 15:29:05 +02:00
|
|
|
pullBookmarkedItems.x = center + 2 * labelWidth / 2 + 2;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
return BUTTON_SIZE + 2;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2020-02-04 20:11:17 -08:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setVisible() {
|
2022-01-02 23:30:54 +02:00
|
|
|
super.setVisible();
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (grid.getPerPage() > 0 && !this.storage.isEmpty()) {
|
2022-05-06 22:41:45 +03:00
|
|
|
LayoutManager.addWidget(namespacePrev);
|
|
|
|
|
LayoutManager.addWidget(namespaceNext);
|
|
|
|
|
LayoutManager.addWidget(namespaceLabel);
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
if (!grid.isEmpty()
|
|
|
|
|
&& BookmarkContainerInfo.getBookmarkContainerHandler(NEIClientUtils.getGuiContainer()) != null) {
|
2023-09-08 07:16:37 +02:00
|
|
|
LayoutManager.addWidget(pullBookmarkedItems);
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-09 23:11:10 +02:00
|
|
|
@Override
|
2025-08-22 15:03:05 +03:00
|
|
|
public Rectangle4i calculateBounds() {
|
|
|
|
|
final GuiContainer gui = NEIClientUtils.getGuiContainer();
|
2026-02-09 23:11:10 +02:00
|
|
|
final int maxWidth = (gui.width - 176) / 2 - PADDING * 2;
|
|
|
|
|
final int maxHeight = gui.height - PADDING * 2;
|
|
|
|
|
final int freeSpace = (gui.width - gui.xSize) / 2 - PADDING * 2;
|
|
|
|
|
|
|
|
|
|
final int paddingLeft = (int) Math
|
|
|
|
|
.ceil(maxWidth * NEIClientConfig.getSetting("world.panels.bookmarks.left").getIntValue() / 100000.0);
|
|
|
|
|
final int paddingTop = (int) Math
|
|
|
|
|
.ceil(maxHeight * NEIClientConfig.getSetting("world.panels.bookmarks.top").getIntValue() / 100000.0);
|
|
|
|
|
final int paddingRight = (int) Math
|
|
|
|
|
.ceil(maxWidth * NEIClientConfig.getSetting("world.panels.bookmarks.right").getIntValue() / 100000.0);
|
|
|
|
|
final int paddingBottom = (int) Math
|
|
|
|
|
.ceil(maxHeight * NEIClientConfig.getSetting("world.panels.bookmarks.bottom").getIntValue() / 100000.0);
|
|
|
|
|
|
|
|
|
|
final int width = Math.max(
|
|
|
|
|
ItemsGrid.SLOT_SIZE,
|
|
|
|
|
snapDownToMultiple(
|
2026-02-10 19:41:28 +02:00
|
|
|
Math.min(freeSpace - paddingLeft, maxWidth - paddingLeft - paddingRight)
|
|
|
|
|
- BookmarkGrid.GROUP_PANEL_WIDTH,
|
|
|
|
|
ItemsGrid.SLOT_SIZE))
|
|
|
|
|
+ BookmarkGrid.GROUP_PANEL_WIDTH;
|
2026-02-09 23:11:10 +02:00
|
|
|
final int height = Math.max(ItemsGrid.SLOT_SIZE, maxHeight - paddingTop - paddingBottom);
|
|
|
|
|
|
|
|
|
|
return new Rectangle4i(paddingLeft + PADDING, paddingTop + PADDING, width, height);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
|
|
|
|
|
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmount(itemStack));
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2021-11-22 05:31:02 +02:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void mouseDragged(int mousex, int mousey, int button, long heldTime) {
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.grid.getSlotBySlotIndex(this.mouseDownSlot) == null) {
|
|
|
|
|
this.mouseDownSlot = -1;
|
2024-09-12 19:14:00 +03:00
|
|
|
}
|
2022-10-13 11:06:08 +03:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
if (this.groupingItem != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = grid.getRowIndex(mousey);
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.groupingItem.hasEndRow() || overRowIndex != this.groupingItem.getStartSlotIndex()
|
|
|
|
|
|| heldTime > 250) {
|
|
|
|
|
this.groupingItem.setEndPoint(Math.max(0, Math.min(overRowIndex, grid.getLastRowIndex())));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
return;
|
|
|
|
|
} else if (this.sortableGroup != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = grid.getRowIndex(mousey);
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (overRowIndex >= 0 && this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
|
|
|
|
|
this.grid.moveGroup(this.sortableGroup, overRowIndex);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
return;
|
|
|
|
|
} else if (this.sortableItem != null) {
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (!this.sortableItem.isEmpty()) {
|
|
|
|
|
this.sortableItem.mouseDragged(mousex, mousey);
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
|
|
|
|
return;
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (button == 0 && NEIClientUtils.shiftKey() && this.mouseDownSlot >= 0 && this.sortableItem == null) {
|
|
|
|
|
final BookmarksGridSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (mouseOverSlot == null || mouseOverSlot.slotIndex != this.mouseDownSlot || heldTime > 250) {
|
|
|
|
|
final BookmarksGridSlot slot = this.grid.getSlotBySlotIndex(this.mouseDownSlot);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (slot != null && slot.itemIndex >= 0) {
|
|
|
|
|
this.sortableItem = new SortableItem(this.grid, slot.getBookmarkItem());
|
|
|
|
|
this.grid.onGridChanged();
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
super.mouseDragged(mousex, mousey, button, heldTime);
|
2022-09-18 19:08:16 +09:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
private int getNextSlot() {
|
|
|
|
|
final int columns = this.grid.getColumns();
|
|
|
|
|
final int perPage = this.grid.getRows() * columns;
|
|
|
|
|
final boolean line = this.grid.getViewMode(BookmarkGrid.DEFAULT_GROUP_ID) == BookmarkViewMode.TODO_LIST;
|
|
|
|
|
final List<BookmarksGridSlot> mask = this.grid.getMask();
|
|
|
|
|
int slotIndex = mask.isEmpty() ? 0 : mask.get(mask.size() - 1).slotIndex + 1;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
while (slotIndex < perPage) {
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if ((!line || (slotIndex % columns) == 0) && !grid.isInvalidSlot(slotIndex)) {
|
|
|
|
|
return slotIndex;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
slotIndex++;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
return -1;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void postDraw(int mousex, int mousey) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
if (this.sortableItem != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.sortableItem.postDraw(mousex, mousey);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.sortableGroup != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.sortableGroup.postDraw(mousex, mousey);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (ItemPanels.itemPanel.draggedStack != null && contains(mousex, mousey)) {
|
|
|
|
|
final int slotIndex = getNextSlot();
|
2022-10-13 11:06:08 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (slotIndex >= 0) {
|
|
|
|
|
Rectangle4i rect = this.grid.getSlotRect(slotIndex);
|
|
|
|
|
NEIClientUtils.drawRect(rect.x, rect.y, rect.w, rect.h, ItemsGrid.HIGHLIGHT_COLOR);
|
2022-10-13 11:06:08 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
super.postDraw(mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean handleClickExt(int mousex, int mousey, int button) {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
if (button == 0 && NEIClientUtils.shiftKey()) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = this.grid.getHoveredRowIndex(true);
|
|
|
|
|
final int groupId = overRowIndex != -1 ? this.grid.getRowGroupId(overRowIndex)
|
|
|
|
|
: BookmarkGrid.DEFAULT_GROUP_ID;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
if (groupId != BookmarkGrid.DEFAULT_GROUP_ID) {
|
|
|
|
|
int rowIndex = overRowIndex;
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
while (rowIndex >= 0 && groupId == this.grid.getRowGroupId(rowIndex)) {
|
2024-08-17 23:24:27 +03:00
|
|
|
rowIndex--;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
Rectangle4i rect = this.grid.getSlotRect(rowIndex + 1, 0);
|
|
|
|
|
this.sortableGroup = new SortableGroup(this.grid, groupId);
|
2024-08-17 23:24:27 +03:00
|
|
|
this.sortableGroup.shiftX = rect.x - mousex;
|
|
|
|
|
this.sortableGroup.shiftY = rect.y - mousey;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!NEIClientUtils.shiftKey() && (button == 0 || button == 1)) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = this.grid.getHoveredRowIndex(true);
|
2024-02-04 14:09:24 +02:00
|
|
|
|
|
|
|
|
if (overRowIndex != -1) {
|
2025-04-24 18:48:40 +03:00
|
|
|
int groupId = this.grid.getRowGroupId(overRowIndex);
|
|
|
|
|
|
|
|
|
|
if (button == 1) {
|
|
|
|
|
groupId = BookmarkGrid.DEFAULT_GROUP_ID;
|
|
|
|
|
} else if (groupId == BookmarkGrid.DEFAULT_GROUP_ID) {
|
|
|
|
|
groupId = Integer.MIN_VALUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.groupingItem = new GroupingItem(this.grid, groupId, overRowIndex);
|
|
|
|
|
|
|
|
|
|
if (this.groupingItem.startPoint.topRowIndex == -1
|
|
|
|
|
|| this.groupingItem.startPoint.bottomRowIndex == -1) {
|
|
|
|
|
this.groupingItem = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 14:09:24 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(mousex, mousey)) {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (NEIClientUtils.altKey() && button == 0) {
|
|
|
|
|
this.grid.toggleCollapsedState(BookmarkGrid.DEFAULT_GROUP_ID);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
} else if (button == 0) {
|
|
|
|
|
this.grid.toggleViewMode(BookmarkGrid.DEFAULT_GROUP_ID);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
2024-02-04 14:09:24 +02:00
|
|
|
} else if (button == 1) {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.grid.toggleCraftingMode(BookmarkGrid.DEFAULT_GROUP_ID);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return super.handleClickExt(mousex, mousey, button);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-10-12 19:39:21 +03:00
|
|
|
public List<String> handleTooltip(int mousex, int mousey, List<String> currenttip) {
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.grid.getPerPage() == 0 || this.grid.isEmpty()) {
|
|
|
|
|
return new ArrayList<>();
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = this.grid.getHoveredRowIndex(true);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
if (overRowIndex != -1) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int groupId = this.grid.getRowGroupId(overRowIndex);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
currenttip.add(NEIClientUtils.translate("bookmark.group"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
if (groupId != BookmarkGrid.DEFAULT_GROUP_ID) {
|
2025-04-24 18:48:40 +03:00
|
|
|
currenttip = recipeChainTooltip(groupId, currenttip);
|
2024-08-17 23:24:27 +03:00
|
|
|
} else {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.recipeChainTooltipLineHandler = null;
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
} else
|
|
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(mousex, mousey)) {
|
|
|
|
|
currenttip.add(NEIClientUtils.translate("bookmark.group"));
|
|
|
|
|
currenttip = recipeChainTooltip(BookmarkGrid.DEFAULT_GROUP_ID, currenttip);
|
|
|
|
|
} else {
|
|
|
|
|
this.recipeChainTooltipLineHandler = null;
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
return super.handleTooltip(mousex, mousey, currenttip);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Override
|
|
|
|
|
public boolean handleClick(int mousex, int mousey, int button) {
|
|
|
|
|
final BookmarksGridSlot hoverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (hoverSlot != null && button == 0 && NEIClientUtils.altKey()) {
|
|
|
|
|
final BookmarkGroup group = hoverSlot.getGroup();
|
|
|
|
|
|
|
|
|
|
if (group.collapsed) {
|
|
|
|
|
group.collapsed = false;
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
grid.onItemsChanged();
|
|
|
|
|
} else if (group.crafting != null && hoverSlot.getRecipeId() != null) {
|
|
|
|
|
grid.toggleCollapsedRecipe(hoverSlot.getGroupId(), hoverSlot.getRecipeId());
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.handleClick(mousex, mousey, button);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
@Override
|
2025-10-12 19:39:21 +03:00
|
|
|
public Map<String, String> handleHotkeys(int mousex, int mousey, Map<String, String> hotkeys) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = this.grid.getHoveredRowIndex(true);
|
|
|
|
|
final BookmarksGridSlot slot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (this.grid.getPerPage() == 0 || this.grid.isEmpty()) {
|
|
|
|
|
return hotkeys;
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(mousex, mousey)) {
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
2025-04-24 18:48:40 +03:00
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH + NEIClientUtils.ALT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity_step"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_mode"));
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_RMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_crafting_chain"));
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientConfig.getKeyName("gui.remove_recipe"),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.remove_recipe"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
if (BookmarkContainerInfo.getBookmarkContainerHandler(NEIClientUtils.getGuiContainer()) != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientConfig.getKeyName("gui.bookmark_pull_items"),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.pull_items"));
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientConfig.getKeyName("gui.bookmark_pull_items", NEIClientUtils.SHIFT_HASH),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.pull_items_shift"));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_collapse"));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (overRowIndex != -1) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int groupId = this.grid.getRowGroupId(overRowIndex);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB + NEIMouseUtils.MOUSE_DRAG),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.include_group"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
|
|
|
|
if (groupId != BookmarkGrid.DEFAULT_GROUP_ID) {
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
2025-04-24 18:48:40 +03:00
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH + NEIClientUtils.ALT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity_step"));
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_RMB + NEIMouseUtils.MOUSE_DRAG),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.exclude_group"));
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_mode"));
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_RMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_crafting_chain"));
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.SHIFT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_LMB + NEIMouseUtils.MOUSE_DRAG),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.sorting"));
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_collapse"));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (slot != null) {
|
|
|
|
|
final BookmarkGroup group = slot.getGroup();
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity"));
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.CTRL_HASH + NEIClientUtils.ALT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("bookmark.change_quantity_step"));
|
|
|
|
|
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.SHIFT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_LMB + NEIMouseUtils.MOUSE_DRAG),
|
|
|
|
|
NEIClientUtils.translate("bookmark.item.sorting"));
|
|
|
|
|
|
|
|
|
|
if (group.collapsed) {
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.group.toggle_collapse"));
|
|
|
|
|
} else if (group.crafting != null) {
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB),
|
|
|
|
|
NEIClientUtils.translate("bookmark.recipe.toggle_collapse"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.acceptsFollowingTooltipLineHandler != null) {
|
|
|
|
|
hotkeys.put(
|
|
|
|
|
NEIClientUtils.getKeyName(
|
|
|
|
|
NEIClientUtils.SHIFT_HASH,
|
|
|
|
|
NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL),
|
|
|
|
|
NEIClientUtils.translate("recipe.accepts.scroll"));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 19:39:21 +03:00
|
|
|
return super.handleHotkeys(mousex, mousey, hotkeys);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
private List<String> recipeChainTooltip(int groupId, List<String> currenttip) {
|
|
|
|
|
boolean crafting = this.grid.getGroup(groupId).crafting != null;
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.recipeChainTooltipLineHandler == null || this.recipeChainTooltipLineHandler.groupId != groupId
|
|
|
|
|
|| this.recipeChainTooltipLineHandler.crafting != crafting) {
|
|
|
|
|
this.recipeChainTooltipLineHandler = new RecipeChainTooltipLineHandler(
|
|
|
|
|
groupId,
|
|
|
|
|
crafting,
|
|
|
|
|
this.grid.createRecipeChainMath(groupId));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.recipeChainTooltipLineHandler != null) {
|
|
|
|
|
currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.recipeChainTooltipLineHandler));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return currenttip;
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 22:12:26 +02:00
|
|
|
@Override
|
|
|
|
|
public boolean contains(int px, int py) {
|
|
|
|
|
|
|
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(px, py)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.grid.getHoveredRowIndex(true) != -1) {
|
2025-01-16 22:12:26 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.contains(px, py);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
@Override
|
2025-10-12 19:39:21 +03:00
|
|
|
public List<String> handleItemTooltip(ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final BookmarksGridSlot slot = this.grid.getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (slot != null) {
|
|
|
|
|
|
2025-11-07 19:54:09 +02:00
|
|
|
if (slot.getType() == BookmarkItemType.INGREDIENT && slot.getRecipeId() != null
|
|
|
|
|
&& slot.getBookmarkItem().permutations.size() > 1) {
|
2025-04-24 18:48:40 +03:00
|
|
|
RecipeId recipeId = slot.getRecipeId();
|
|
|
|
|
|
|
|
|
|
if (recipeId == null) {
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler = null;
|
|
|
|
|
} else if (this.acceptsFollowingTooltipLineHandler == null
|
|
|
|
|
|| ((int) this.acceptsFollowingTooltipLineHandler.tooltipGUID) != slot.itemIndex) {
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler = AcceptsFollowingTooltipLineHandler.of(
|
|
|
|
|
slot.itemIndex,
|
|
|
|
|
new ArrayList<>(slot.getBookmarkItem().permutations.values()),
|
|
|
|
|
slot.getItemStack(),
|
|
|
|
|
2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.acceptsFollowingTooltipLineHandler != null) {
|
|
|
|
|
currenttip.add(
|
|
|
|
|
GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsFollowingTooltipLineHandler));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler = null;
|
|
|
|
|
}
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
} else {
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler = null;
|
2023-08-07 15:29:05 +02:00
|
|
|
}
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
return currenttip;
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2021-11-22 05:31:02 +02:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void mouseUp(int mousex, int mousey, int button) {
|
2024-02-04 14:09:24 +02:00
|
|
|
|
|
|
|
|
if (this.sortableItem != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
grid.onItemsChanged();
|
2024-08-17 23:24:27 +03:00
|
|
|
} else if (this.sortableGroup != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
grid.onItemsChanged();
|
|
|
|
|
} else if (this.groupingItem != null && this.groupingItem.hasEndRow()) {
|
|
|
|
|
this.grid.createGroup(this.groupingItem);
|
|
|
|
|
this.grid.onItemsChanged();
|
|
|
|
|
} else {
|
|
|
|
|
int rowIndex = this.grid.getHoveredRowIndex(true);
|
|
|
|
|
int groupId = rowIndex != -1 ? this.grid.getRowGroupId(rowIndex) : BookmarkGrid.DEFAULT_GROUP_ID;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (groupId != BookmarkGrid.DEFAULT_GROUP_ID) {
|
|
|
|
|
if (button == 0 && NEIClientUtils.altKey()) {
|
|
|
|
|
this.grid.toggleCollapsedState(groupId);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
} else if (button == 0) {
|
|
|
|
|
this.grid.toggleViewMode(groupId);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
} else if (button == 1) {
|
|
|
|
|
this.grid.toggleCraftingMode(groupId);
|
|
|
|
|
NEIClientUtils.playClickSound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.grid.onItemsChanged();
|
2024-02-04 14:09:24 +02:00
|
|
|
} else {
|
2025-04-24 18:48:40 +03:00
|
|
|
super.mouseUp(mousex, mousey, button);
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
this.sortableItem = null;
|
|
|
|
|
this.sortableGroup = null;
|
|
|
|
|
this.groupingItem = null;
|
|
|
|
|
this.mouseDownSlot = -1;
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public boolean onMouseWheel(int shift, int mousex, int mousey) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-12-16 23:39:32 +02:00
|
|
|
if ((!inEditingState() || this.sortableGroup != null) && new Rectangle4i(
|
2022-06-24 12:32:13 +01:00
|
|
|
namespacePrev.x,
|
|
|
|
|
namespacePrev.y,
|
|
|
|
|
namespaceNext.x + namespaceNext.w - namespacePrev.x,
|
|
|
|
|
namespacePrev.h).contains(mousex, mousey)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
if (shift > 0) {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.storage.prevNamespace();
|
2022-01-02 23:30:54 +02:00
|
|
|
} else {
|
2025-04-24 18:48:40 +03:00
|
|
|
this.storage.nextNamespace();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!contains(mousex, mousey)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-24 22:25:46 +03:00
|
|
|
if (!inEditingState() && NEIClientUtils.controlKey()) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final BookmarksGridSlot slot = this.grid.getSlotMouseOver(mousex, mousey);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
if (slot != null) {
|
2025-04-24 18:48:40 +03:00
|
|
|
int multiplier = 1;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2023-09-09 02:22:33 -05:00
|
|
|
if (NEIClientUtils.altKey()) {
|
2025-04-24 18:48:40 +03:00
|
|
|
multiplier = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0;
|
|
|
|
|
if (multiplier == 0) {
|
2025-11-07 19:54:09 +02:00
|
|
|
multiplier = StackInfo.itemStackToNBT(slot.getItemStack()).hasKey("gtFluidName") ? 144
|
|
|
|
|
: slot.getItemStack().getMaxStackSize();
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
2023-09-09 02:22:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
this.grid.shiftItemAmount(slot.itemIndex, multiplier * shift);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
final int groupId = getHoveredGroupId(true);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (groupId != -1) {
|
|
|
|
|
int multiplier = 1;
|
|
|
|
|
|
|
|
|
|
if (NEIClientUtils.altKey()) {
|
|
|
|
|
multiplier = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0;
|
|
|
|
|
if (multiplier == 0) {
|
|
|
|
|
multiplier = 64;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
this.grid.shiftGroupAmount(groupId, multiplier * shift);
|
|
|
|
|
return true;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (!inEditingState() && NEIClientUtils.shiftKey()
|
|
|
|
|
&& this.grid.contains(mousex, mousey)
|
|
|
|
|
&& this.acceptsFollowingTooltipLineHandler != null) {
|
|
|
|
|
int itemIndex = (int) this.acceptsFollowingTooltipLineHandler.tooltipGUID;
|
|
|
|
|
final BookmarkItem item = this.grid.getCalculatedItem(itemIndex);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (item.permutations.size() > 1) {
|
|
|
|
|
final List<ItemStack> items = acceptsFollowingTooltipLineHandler.items;
|
|
|
|
|
ItemStack activeStack = this.acceptsFollowingTooltipLineHandler.getActiveStack();
|
|
|
|
|
int stackIndex = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < items.size(); i++) {
|
|
|
|
|
if (StackInfo.equalItemAndNBT(activeStack, items.get(i), true)) {
|
|
|
|
|
stackIndex = i;
|
|
|
|
|
break;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
activeStack = items.get((items.size() - shift + stackIndex) % items.size());
|
|
|
|
|
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler.setActiveStack(activeStack);
|
|
|
|
|
this.grid.getBookmarkItem(Math.abs(itemIndex)).itemStack = activeStack;
|
|
|
|
|
this.grid.onItemsChanged();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
return true;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-17 23:24:27 +03:00
|
|
|
if (super.onMouseWheel(shift, mousex, mousey)) {
|
2025-04-24 18:48:40 +03:00
|
|
|
final int overRowIndex = grid.getRowIndex(mousey);
|
2024-08-17 23:24:27 +03:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (this.sortableGroup != null && overRowIndex >= 0
|
|
|
|
|
&& this.sortableGroup.groupId != this.grid.getRowGroupId(overRowIndex)) {
|
|
|
|
|
this.grid.moveGroup(this.sortableGroup, overRowIndex);
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.groupingItem != null
|
2025-04-24 18:48:40 +03:00
|
|
|
&& (this.groupingItem.hasEndRow() || overRowIndex != this.groupingItem.getStartSlotIndex())) {
|
|
|
|
|
this.groupingItem.setEndPoint(Math.max(0, Math.min(overRowIndex, grid.getLastRowIndex())));
|
2024-08-17 23:24:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean pullBookmarkItems(int groupId, boolean shift) {
|
|
|
|
|
return pullBookmarkItems(this.grid.createRecipeChainMath(groupId), shift);
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
2023-08-07 15:29:05 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
public boolean pullBookmarkItems(RecipeChainMath math, boolean shift) {
|
|
|
|
|
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
|
2024-09-28 19:05:06 +03:00
|
|
|
final IBookmarkContainerHandler containerHandler = BookmarkContainerInfo
|
|
|
|
|
.getBookmarkContainerHandler(guiContainer);
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (containerHandler == null || math == null) {
|
2023-08-07 15:29:05 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
final ItemStackAmount pullItemStacks = new ItemStackAmount();
|
|
|
|
|
final InventoryPlayer playerInventory = guiContainer.mc.thePlayer.inventory;
|
|
|
|
|
final ItemStackAmount inventory = shift ? ItemStackAmount.of(Arrays.asList(playerInventory.mainInventory))
|
|
|
|
|
: new ItemStackAmount();
|
|
|
|
|
|
|
|
|
|
if (math.outputRecipes.isEmpty()) {
|
|
|
|
|
|
|
|
|
|
for (BookmarkItem item : math.initialItems) {
|
|
|
|
|
final long invStackSize = inventory.getOrDefault(item.itemStack, 0L);
|
|
|
|
|
final long amount = item.amount - invStackSize * item.fluidCellAmount;
|
|
|
|
|
if (amount > 0) {
|
|
|
|
|
pullItemStacks.add(item.getItemStack(amount));
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
} else {
|
|
|
|
|
final ItemStackAmount containerStorage = ItemStackAmount
|
|
|
|
|
.of(containerHandler.getStorageStacks(guiContainer));
|
|
|
|
|
final List<BookmarkItem> initialItems = new ArrayList<>();
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
for (BookmarkItem item : math.initialItems) {
|
|
|
|
|
final long invStackSize = inventory.getOrDefault(item.itemStack, 0L);
|
|
|
|
|
final long strStackSize = containerStorage.getOrDefault(item.itemStack, 0L);
|
|
|
|
|
final long amount = item.amount - invStackSize * item.fluidCellAmount
|
|
|
|
|
- strStackSize * item.fluidCellAmount;
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (amount > 0) {
|
|
|
|
|
initialItems.add(item.copyWithAmount(amount));
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
math.initialItems.clear();
|
|
|
|
|
math.initialItems.addAll(initialItems);
|
|
|
|
|
|
|
|
|
|
for (ItemStack stack : inventory.values()) {
|
|
|
|
|
math.initialItems.add(BookmarkItem.of(-1, stack));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (ItemStack stack : containerStorage.values()) {
|
|
|
|
|
math.initialItems.add(BookmarkItem.of(-2, stack));
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
math.refresh();
|
|
|
|
|
|
|
|
|
|
for (BookmarkItem item : math.initialItems) {
|
|
|
|
|
if (item.groupId == -2 && math.requiredAmount.getOrDefault(item, -1L) > 0) {
|
|
|
|
|
pullItemStacks.add(item.getItemStack(math.requiredAmount.get(item)));
|
|
|
|
|
}
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pullItemStacks.isEmpty()) {
|
|
|
|
|
return false;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
ArrayList<ItemStack> items = new ArrayList<>();
|
|
|
|
|
int freeSlots = 0;
|
|
|
|
|
|
|
|
|
|
for (ItemStack stack : playerInventory.mainInventory) {
|
|
|
|
|
if (stack == null || stack.stackSize < stack.getMaxStackSize() && pullItemStacks.contains(stack)) {
|
|
|
|
|
freeSlots++;
|
2024-02-04 14:09:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
if (freeSlots == 0) {
|
2024-02-04 14:09:24 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
for (ItemStack stack : pullItemStacks.values()) {
|
|
|
|
|
stack.stackSize = Math.min(stack.stackSize, freeSlots * stack.getMaxStackSize());
|
|
|
|
|
if (stack.stackSize > 0) {
|
|
|
|
|
items.add(stack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!items.isEmpty()) {
|
2025-11-13 08:19:55 +02:00
|
|
|
final int helmStackIndex = FastTransferManager.dropHeldItem(guiContainer);
|
|
|
|
|
|
|
|
|
|
if (guiContainer.mc.thePlayer.inventory.getItemStack() == null) {
|
|
|
|
|
containerHandler.pullBookmarkItemsFromContainer(guiContainer, items);
|
|
|
|
|
|
|
|
|
|
if (helmStackIndex != -1) {
|
|
|
|
|
FastTransferManager.clickSlot(guiContainer, helmStackIndex, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 15:29:05 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-07-01 13:52:46 +03:00
|
|
|
public void clearTooltips() {
|
|
|
|
|
this.acceptsFollowingTooltipLineHandler = null;
|
|
|
|
|
this.recipeChainTooltipLineHandler = null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
@Deprecated
|
|
|
|
|
public void addItem(ItemStack stack, boolean saveSize) {
|
|
|
|
|
addItem(saveSize ? stack : StackInfo.withAmount(stack, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addOrRemoveItem(ItemStack stack) {
|
|
|
|
|
if (!removeItem(stack, null, BookmarkGrid.DEFAULT_GROUP_ID)) {
|
|
|
|
|
addItem(stack);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addOrRemoveItem(ItemStack stack, String handlerName, List<PositionedStack> ingredients,
|
|
|
|
|
boolean saveIngredients, boolean saveSize) {
|
|
|
|
|
|
|
|
|
|
if (!removeItem(stack, null, BookmarkGrid.DEFAULT_GROUP_ID)) {
|
|
|
|
|
if (saveIngredients && handlerName != null
|
|
|
|
|
&& !handlerName.isEmpty()
|
|
|
|
|
&& ingredients != null
|
|
|
|
|
&& !ingredients.isEmpty()) {
|
2025-08-22 15:06:27 +03:00
|
|
|
addRecipe(
|
|
|
|
|
Recipe.of(Arrays.asList(stack), handlerName, ingredients),
|
|
|
|
|
saveSize ? 1 : 0,
|
|
|
|
|
BookmarkGrid.DEFAULT_GROUP_ID);
|
2025-04-24 18:48:40 +03:00
|
|
|
} else {
|
|
|
|
|
addItem(stack, saveSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addRecipe(BookmarkRecipe recipe, boolean saveSize) {
|
|
|
|
|
addRecipe(recipe, saveSize, BookmarkGrid.DEFAULT_GROUP_ID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addRecipe(BookmarkRecipe recipe, boolean saveSize, int groupId) {
|
2025-08-22 15:06:27 +03:00
|
|
|
addRecipe(recipe.getRecipe(), saveSize ? 1 : 0, groupId);
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addBookmarkGroup(List<ItemStack> items, BookmarkViewMode viewMode) {
|
|
|
|
|
addGroup(items, viewMode, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public void addBookmarkGroup(List<BookmarkRecipe> recipes, BookmarkViewMode viewMode, boolean crafting) {
|
|
|
|
|
List<Recipe> items = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (BookmarkRecipe recipe : recipes) {
|
|
|
|
|
items.add(recipe.getRecipe());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
addGroup(items, viewMode, crafting);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public BookmarkRecipeId getBookmarkRecipeId(int itemIndex) {
|
|
|
|
|
BookmarkItem item = this.grid.getCalculatedItem(itemIndex);
|
2025-11-07 19:54:09 +02:00
|
|
|
return item == null || item.type == BookmarkItemType.INGREDIENT || item.recipeId == null ? null
|
2025-04-24 18:48:40 +03:00
|
|
|
: new BookmarkRecipeId(item.recipeId.getHandleName(), item.recipeId.getIngredients());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public BookmarkRecipeId getBookmarkRecipeId(ItemStack stackA) {
|
|
|
|
|
BookmarkRecipeId recipeId = null;
|
|
|
|
|
|
|
|
|
|
for (int itemIndex = 0; itemIndex < this.grid.size(); itemIndex++) {
|
|
|
|
|
if (StackInfo.equalItemAndNBT(stackA, this.grid.getBookmarkItem(itemIndex).itemStack, true)
|
|
|
|
|
&& (recipeId = getBookmarkRecipeId(itemIndex)) != null) {
|
|
|
|
|
return recipeId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
public boolean removeBookmarkRecipeId(BookmarkRecipeId recipeId) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|