2019-12-24 13:37:41 -08:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import codechicken.core.CommonUtils;
|
|
|
|
|
import codechicken.lib.vec.Rectangle4i;
|
|
|
|
|
import codechicken.nei.ItemPanel.ItemPanelSlot;
|
|
|
|
|
import codechicken.nei.api.IBookmarkContainerHandler;
|
|
|
|
|
import codechicken.nei.guihook.GuiContainerManager;
|
|
|
|
|
import codechicken.nei.recipe.BookmarkRecipeId;
|
|
|
|
|
import codechicken.nei.recipe.StackInfo;
|
|
|
|
|
import codechicken.nei.util.NBTJson;
|
|
|
|
|
import codechicken.nei.util.ReadableNumberConverter;
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
|
import com.google.gson.JsonPrimitive;
|
|
|
|
|
import com.google.gson.JsonSyntaxException;
|
|
|
|
|
import net.minecraft.client.gui.FontRenderer;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
import java.awt.Point;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
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;
|
2022-05-27 18:38:54 +01:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2023-09-24 23:02:09 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.WeakHashMap;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2023-09-25 00:34:42 +02:00
|
|
|
import static codechicken.lib.gui.GuiDraw.drawRect;
|
|
|
|
|
import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
|
|
|
|
import static codechicken.nei.NEIClientUtils.getGuiContainer;
|
|
|
|
|
import static codechicken.nei.NEIClientUtils.translate;
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public class BookmarkPanel extends PanelWidget {
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2022-01-09 19:05:30 +02:00
|
|
|
protected File bookmarkFile;
|
2021-11-22 05:31:02 +02:00
|
|
|
protected boolean bookmarksIsLoaded = false;
|
|
|
|
|
public int sortedStackIndex = -1;
|
2022-01-02 23:30:54 +02:00
|
|
|
public int sortedNamespaceIndex = -1;
|
|
|
|
|
|
|
|
|
|
public Button namespacePrev;
|
|
|
|
|
public Button namespaceNext;
|
2023-08-07 15:29:05 +02:00
|
|
|
public Button pullBookmarkedItems;
|
2022-01-02 23:30:54 +02:00
|
|
|
public Label namespaceLabel;
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
protected List<BookmarkGrid> namespaces = new ArrayList<>();
|
2022-05-06 22:41:45 +03:00
|
|
|
protected int activeNamespaceIndex = 0;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected static class BookmarkStackMeta {
|
2023-01-28 17:55:51 -08:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
public int factor;
|
|
|
|
|
public BookmarkRecipeId recipeId;
|
|
|
|
|
public boolean ingredient = false;
|
2022-05-06 22:41:45 +03:00
|
|
|
public boolean fluidDisplay = false;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkStackMeta(BookmarkRecipeId recipeId, int count, boolean ingredient, boolean fluidDisplay) {
|
2022-01-02 23:30:54 +02:00
|
|
|
this.recipeId = recipeId;
|
|
|
|
|
this.factor = count;
|
|
|
|
|
this.ingredient = ingredient;
|
2022-05-06 22:41:45 +03:00
|
|
|
this.fluidDisplay = fluidDisplay;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public static enum BookmarkViewMode {
|
|
|
|
|
DEFAULT,
|
|
|
|
|
TODO_LIST
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
public static class BookmarkGrid extends ItemsGrid {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
protected static final float SCALE_SPEED = 0.1f;
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
protected List<List<Integer>> gridMask;
|
2022-01-02 23:30:54 +02:00
|
|
|
protected List<BookmarkStackMeta> metadata = new ArrayList<>();
|
2022-10-13 11:06:08 +03:00
|
|
|
protected WeakHashMap<ItemStack, Float> animation = new WeakHashMap<>();
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
protected BookmarkViewMode viewMode = BookmarkViewMode.DEFAULT;
|
|
|
|
|
protected boolean[] todoSpaces;
|
|
|
|
|
protected int todoItemsCount = 0;
|
|
|
|
|
|
2023-07-10 17:38:07 +01:00
|
|
|
public BookmarkGrid() {
|
|
|
|
|
this.setShowRecipeTooltips(true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setViewMode(BookmarkViewMode mode) {
|
2022-06-23 01:03:29 +03:00
|
|
|
if (viewMode == mode) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
viewMode = mode;
|
|
|
|
|
|
|
|
|
|
if (mode == BookmarkViewMode.DEFAULT) {
|
|
|
|
|
sortIngredients(false);
|
|
|
|
|
todoItemsCount = 0;
|
|
|
|
|
gridMask = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onGridChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkViewMode getViewMode() {
|
2022-06-23 01:03:29 +03:00
|
|
|
return viewMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getNumPages() {
|
2022-06-23 01:03:29 +03:00
|
|
|
if (gridMask != null) {
|
|
|
|
|
return gridMask.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.getNumPages();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
protected List<Integer> getMask() {
|
2022-06-23 01:03:29 +03:00
|
|
|
if (gridMask != null) {
|
2022-06-24 12:32:13 +01:00
|
|
|
return gridMask.size() > page ? gridMask.get(page) : new ArrayList<>();
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.getMask();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
private void sortIngredients(final boolean forward) {
|
2022-06-23 01:03:29 +03:00
|
|
|
BookmarkStackMeta meta;
|
2022-06-24 12:32:13 +01:00
|
|
|
int dir = forward ? 1 : -1;
|
2022-06-23 01:03:29 +03:00
|
|
|
|
|
|
|
|
for (int i = 0; i < realItems.size(); i++) {
|
|
|
|
|
meta = metadata.get(i);
|
|
|
|
|
|
|
|
|
|
if (meta.recipeId != null && !meta.ingredient) {
|
|
|
|
|
int shift = 0;
|
|
|
|
|
|
|
|
|
|
for (int j = i + 1; j < realItems.size(); j++) {
|
|
|
|
|
if (meta.recipeId.equals(metadata.get(j).recipeId)) {
|
|
|
|
|
if (i + shift + dir != j) {
|
|
|
|
|
realItems.add(i + shift + Math.max(dir, 0), realItems.remove(j));
|
|
|
|
|
metadata.add(i + shift + Math.max(dir, 0), metadata.remove(j));
|
|
|
|
|
}
|
|
|
|
|
shift++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = i + shift - 1; j >= 0; j--) {
|
|
|
|
|
if (meta.recipeId.equals(metadata.get(j).recipeId)) {
|
|
|
|
|
if (i + shift + dir != j) {
|
|
|
|
|
realItems.add(i + shift + Math.min(dir, 0), realItems.remove(j));
|
|
|
|
|
metadata.add(i + shift + Math.min(dir, 0), metadata.remove(j));
|
|
|
|
|
}
|
|
|
|
|
shift--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i += Math.max(0, shift);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
private void generateToDoSpaces() {
|
2022-06-23 01:03:29 +03:00
|
|
|
todoItemsCount = 0;
|
|
|
|
|
gridMask = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
if (rows * columns == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BookmarkStackMeta meta;
|
|
|
|
|
int size = size();
|
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
|
|
while (idx < size) {
|
|
|
|
|
ArrayList<Integer> pmask = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0, perPage = rows * columns; i < perPage && idx < size; i++) {
|
|
|
|
|
if (isInvalidSlot(i)) {
|
|
|
|
|
pmask.add(null);
|
|
|
|
|
} else {
|
|
|
|
|
meta = getMetadata(idx);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
if (idx > 0 && ((i % columns) == 0) == (meta.recipeId != null && meta.ingredient
|
|
|
|
|
&& meta.recipeId.equals(getRecipeId(idx - 1)))) {
|
2022-06-23 01:03:29 +03:00
|
|
|
pmask.add(null);
|
|
|
|
|
} else {
|
|
|
|
|
pmask.add(idx++);
|
|
|
|
|
|
|
|
|
|
if ((i % columns) == 0) {
|
|
|
|
|
todoItemsCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gridMask.add(pmask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected void onGridChanged() {
|
2022-06-23 01:03:29 +03:00
|
|
|
super.onGridChanged();
|
|
|
|
|
|
|
|
|
|
if (getViewMode() == BookmarkViewMode.TODO_LIST) {
|
|
|
|
|
sortIngredients(true);
|
|
|
|
|
generateToDoSpaces();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int indexOf(ItemStack stackA, BookmarkRecipeId recipeId) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final boolean useNBT = NEIClientConfig.useNBTInBookmarks();
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
for (int idx = 0; idx < realItems.size(); idx++) {
|
|
|
|
|
final BookmarkStackMeta meta = getMetadata(idx);
|
2022-06-24 12:32:13 +01:00
|
|
|
if ((recipeId == null && meta.recipeId == null
|
|
|
|
|
|| recipeId != null && meta.recipeId != null && recipeId.equals(meta.recipeId))
|
2022-09-18 19:08:16 +09:00
|
|
|
&& StackInfo.equalItemAndNBT(stackA, getItem(idx), useNBT)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
return idx;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkStackMeta getMetadata(int idx) {
|
2022-01-02 23:30:54 +02:00
|
|
|
return metadata.get(idx);
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
public void addItem(ItemStack stackA, BookmarkStackMeta meta) {
|
|
|
|
|
addItem(stackA, meta, true);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
public void addItem(ItemStack stackA, BookmarkStackMeta meta, boolean animate) {
|
|
|
|
|
realItems.add(stackA);
|
|
|
|
|
metadata.add(meta);
|
|
|
|
|
|
|
|
|
|
if (animate && !NEIClientConfig.shouldCacheItemRendering() && NEIClientConfig.areBookmarksAnimated()) {
|
|
|
|
|
animation.put(stackA, 0f);
|
2022-09-18 19:08:16 +09:00
|
|
|
}
|
2022-10-13 11:06:08 +03:00
|
|
|
|
2022-09-18 19:08:16 +09:00
|
|
|
onGridChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void replaceItem(int idx, ItemStack stack) {
|
2022-10-13 11:06:08 +03:00
|
|
|
realItems.set(idx, stack);
|
2022-06-23 01:03:29 +03:00
|
|
|
onGridChanged();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void removeRecipe(int idx, boolean removeFullRecipe) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final BookmarkStackMeta meta = getMetadata(idx);
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
if (meta.recipeId != null && (removeFullRecipe || !meta.ingredient)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
removeRecipe(meta.recipeId);
|
|
|
|
|
} else {
|
|
|
|
|
removeItem(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void removeRecipe(BookmarkRecipeId recipeIdA) {
|
2022-01-02 23:30:54 +02:00
|
|
|
BookmarkRecipeId recipeIdB;
|
|
|
|
|
|
|
|
|
|
for (int slotIndex = metadata.size() - 1; slotIndex >= 0; slotIndex--) {
|
|
|
|
|
recipeIdB = getRecipeId(slotIndex);
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
if (recipeIdB != null && recipeIdB.equals(recipeIdA)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
removeItem(slotIndex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
protected boolean removeItem(int idx) {
|
2022-10-13 11:06:08 +03:00
|
|
|
animation.remove(getItem(idx));
|
2022-01-02 23:30:54 +02:00
|
|
|
realItems.remove(idx);
|
|
|
|
|
metadata.remove(idx);
|
2022-06-23 01:03:29 +03:00
|
|
|
onGridChanged();
|
2022-01-02 23:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkRecipeId getRecipeId(int idx) {
|
2022-01-02 23:30:54 +02:00
|
|
|
return getMetadata(idx).recipeId;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkRecipeId findRecipeId(ItemStack stackA) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final boolean useNBT = NEIClientConfig.useNBTInBookmarks();
|
|
|
|
|
|
|
|
|
|
for (int idx = 0; idx < realItems.size(); idx++) {
|
|
|
|
|
if (StackInfo.equalItemAndNBT(stackA, getItem(idx), useNBT)) {
|
|
|
|
|
return getRecipeId(idx);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void moveItem(int src, int dst) {
|
2022-01-02 23:30:54 +02:00
|
|
|
realItems.add(dst, realItems.remove(src));
|
|
|
|
|
metadata.add(dst, metadata.remove(src));
|
2022-06-23 01:03:29 +03:00
|
|
|
onGridChanged();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
private boolean isPartOfFocusedRecipe(ItemPanelSlot focused, int myIdx) {
|
2022-06-23 01:03:29 +03:00
|
|
|
return NEIClientUtils.shiftKey() && focused != null
|
2022-06-24 12:32:13 +01:00
|
|
|
&& LayoutManager.bookmarkPanel.sortedStackIndex == -1
|
|
|
|
|
&& getRecipeId(focused.slotIndex) != null
|
|
|
|
|
&& getRecipeId(myIdx) != null
|
|
|
|
|
&& getRecipeId(focused.slotIndex).equals(getRecipeId(myIdx));
|
2022-05-27 07:42:41 -04:00
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-05-27 07:42:41 -04:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
protected void drawSlotOutline(@Nullable ItemPanelSlot focus, int idx, Rectangle4i rect) {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (LayoutManager.bookmarkPanel.sortedNamespaceIndex == LayoutManager.bookmarkPanel.activeNamespaceIndex
|
|
|
|
|
&& LayoutManager.bookmarkPanel.sortedStackIndex == idx) {
|
|
|
|
|
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555); // highlight
|
2022-06-23 01:03:29 +03:00
|
|
|
} else if (focus != null) {
|
2022-05-27 07:42:41 -04:00
|
|
|
BookmarkStackMeta meta = getMetadata(idx);
|
|
|
|
|
if (isPartOfFocusedRecipe(focus, idx)) {
|
2022-06-24 12:32:13 +01:00
|
|
|
drawRect(rect.x, rect.y, rect.w, rect.h, meta.ingredient ? 0x88b3b300 : 0x88009933); // highlight
|
|
|
|
|
// recipe
|
|
|
|
|
} else if (focus.slotIndex == idx) {
|
|
|
|
|
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555); // highlight
|
2022-05-27 07:42:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
protected void drawItem(Rectangle4i rect, int idx) {
|
|
|
|
|
if (LayoutManager.bookmarkPanel.sortedNamespaceIndex != LayoutManager.bookmarkPanel.activeNamespaceIndex
|
|
|
|
|
|| LayoutManager.bookmarkPanel.sortedStackIndex != idx) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final ItemStack stack = getItem(idx);
|
|
|
|
|
final BookmarkStackMeta meta = getMetadata(idx);
|
2023-01-23 17:59:29 +08:00
|
|
|
final String stackSize = meta.factor < 0 || meta.fluidDisplay ? ""
|
|
|
|
|
: ReadableNumberConverter.INSTANCE.toWideReadableForm(stack.stackSize);
|
2022-10-13 11:06:08 +03:00
|
|
|
if (animation.containsKey(stack) && animation.get(stack) < 1) {
|
|
|
|
|
final float currentScale = animation.get(stack) + SCALE_SPEED;
|
|
|
|
|
animation.put(stack, currentScale);
|
|
|
|
|
drawPoppingItem(rect, stack, stackSize, currentScale);
|
|
|
|
|
} else {
|
|
|
|
|
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, stack, true, stackSize);
|
|
|
|
|
if (meta.recipeId != null && !meta.ingredient && NEIClientConfig.showRecipeMarker()) {
|
|
|
|
|
drawRecipeMarker(rect.x, rect.y, GuiContainerManager.getFontRenderer(stack));
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
protected void drawPoppingItem(Rectangle4i rect, ItemStack stack, String stackSize, float currentScale) {
|
|
|
|
|
GL11.glScalef(currentScale, currentScale, currentScale); // push & pop matrix crashes the game
|
|
|
|
|
|
|
|
|
|
GuiContainerManager.drawItem(
|
|
|
|
|
Math.round((rect.x + 1 + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
|
|
|
|
|
Math.round((rect.y + 1 + (SLOT_SIZE / 2 - currentScale * SLOT_SIZE / 2)) / currentScale),
|
|
|
|
|
stack,
|
|
|
|
|
true,
|
|
|
|
|
stackSize);
|
|
|
|
|
|
|
|
|
|
GL11.glScalef(1 / currentScale, 1 / currentScale, 1 / currentScale);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected void drawRecipeMarker(int offsetX, int offsetY, FontRenderer fontRenderer) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final float scaleFactor = fontRenderer.getUnicodeFlag() ? 0.85f : 0.5f;
|
|
|
|
|
final float inverseScaleFactor = 1.0f / scaleFactor;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
GuiContainerManager.enable2DRender();
|
|
|
|
|
GL11.glScaled(scaleFactor, scaleFactor, scaleFactor);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
|
|
|
|
final int X = (int) (((float) offsetX + 1.0f) * inverseScaleFactor);
|
|
|
|
|
final int Y = (int) (((float) offsetY + 1.0f) * inverseScaleFactor);
|
2022-05-06 22:41:45 +03:00
|
|
|
fontRenderer.drawStringWithShadow("R", X, Y, 0xA0A0A0);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
GL11.glScaled(inverseScaleFactor, inverseScaleFactor, inverseScaleFactor);
|
|
|
|
|
GuiContainerManager.enable3DRender();
|
|
|
|
|
}
|
2020-01-20 09:42:39 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public BookmarkPanel() {
|
2022-01-02 23:30:54 +02:00
|
|
|
grid = new BookmarkGrid();
|
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);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
namespacePrev = new Button("Prev") {
|
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
|
|
|
|
|
|
|
|
if (rightclick) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prevNamespace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public String getRenderLabel() {
|
2022-01-02 23:30:54 +02:00
|
|
|
return "<";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
namespaceNext = new Button("Next") {
|
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
|
|
|
if (rightclick) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nextNamespace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public String getRenderLabel() {
|
2022-01-02 23:30:54 +02:00
|
|
|
return ">";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-08-07 15:29:05 +02:00
|
|
|
pullBookmarkedItems = new Button("Pull") {
|
|
|
|
|
|
|
|
|
|
public boolean onButtonPress(boolean rightclick) {
|
|
|
|
|
if (rightclick) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return pullBookmarkItems();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String getRenderLabel() {
|
|
|
|
|
return "P";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaces.add(new BookmarkGrid());
|
|
|
|
|
grid = namespaces.get(activeNamespaceIndex);
|
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 String getLabelText() {
|
2022-06-23 01:03:29 +03:00
|
|
|
int size = grid.size();
|
|
|
|
|
|
|
|
|
|
if (((BookmarkGrid) grid).getViewMode() == BookmarkViewMode.TODO_LIST) {
|
|
|
|
|
size = ((BookmarkGrid) grid).todoItemsCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return String.format("(%d/%d) [%d]", getPage(), Math.max(1, getNumPages()), size);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
public void addItem(ItemStack itemStack) {
|
|
|
|
|
addItem(itemStack, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void addItem(ItemStack itemStack, boolean saveStackSize) {
|
|
|
|
|
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
|
|
|
|
int idx = BGrid.indexOf(itemStack, true);
|
|
|
|
|
if (idx != -1) {
|
|
|
|
|
BGrid.removeItem(idx);
|
|
|
|
|
}
|
|
|
|
|
addOrRemoveItem(itemStack, null, null, false, saveStackSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getNameSpaceSize() {
|
|
|
|
|
return namespaces.size();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void addOrRemoveItem(ItemStack stackA) {
|
2022-08-19 15:03:42 +03:00
|
|
|
addOrRemoveItem(stackA, null, null, false, false);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
public void addOrRemoveItem(ItemStack stackover, final String handlerName, final List<PositionedStack> ingredients,
|
|
|
|
|
boolean saveIngredients, boolean saveStackSize) {
|
2021-11-22 05:31:02 +02:00
|
|
|
loadBookmarksIfNeeded();
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
final Point mousePos = getMousePosition();
|
2022-01-02 23:30:54 +02:00
|
|
|
final ItemPanelSlot slot = getSlotMouseOver(mousePos.x, mousePos.y);
|
|
|
|
|
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
|
|
|
|
|
|
|
|
|
if (slot != null && StackInfo.equalItemAndNBT(slot.item, stackover, true)) {
|
2022-08-19 15:03:42 +03:00
|
|
|
BGrid.removeRecipe(slot.slotIndex, saveIngredients);
|
2022-01-02 23:30:54 +02:00
|
|
|
} else {
|
|
|
|
|
final NBTTagCompound nbTagA = StackInfo.itemStackToNBT(stackover, saveStackSize);
|
|
|
|
|
final ItemStack normalizedA = StackInfo.loadFromNBT(nbTagA);
|
|
|
|
|
BookmarkRecipeId recipeId = null;
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2023-07-10 17:38:07 +01:00
|
|
|
if (handlerName != "" && ingredients != null) {
|
2022-01-02 23:30:54 +02:00
|
|
|
recipeId = new BookmarkRecipeId(handlerName, ingredients);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final int idx = BGrid.indexOf(normalizedA, recipeId);
|
|
|
|
|
|
|
|
|
|
if (idx != -1) {
|
2022-08-19 15:03:42 +03:00
|
|
|
BGrid.removeRecipe(idx, saveIngredients);
|
2022-01-02 23:30:54 +02:00
|
|
|
} else {
|
|
|
|
|
|
2023-07-10 17:38:07 +01:00
|
|
|
if (saveIngredients && handlerName != "" && ingredients != null) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final Map<NBTTagCompound, Integer> unique = new HashMap<>();
|
|
|
|
|
final ArrayList<NBTTagCompound> sorted = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
BGrid.removeRecipe(recipeId);
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
for (PositionedStack stack : ingredients) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack.item, saveStackSize);
|
|
|
|
|
|
2022-01-07 19:06:05 +02:00
|
|
|
if (unique.get(nbTag) == null) {
|
|
|
|
|
unique.put(nbTag, 1);
|
|
|
|
|
sorted.add(nbTag);
|
2022-08-19 15:03:42 +03:00
|
|
|
} else {
|
2022-01-07 19:06:05 +02:00
|
|
|
unique.put(nbTag, unique.get(nbTag) + 1);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
for (NBTTagCompound nbTag : sorted) {
|
2022-08-19 15:03:42 +03:00
|
|
|
final int count = nbTag.getInteger("Count") * unique.get(nbTag);
|
|
|
|
|
nbTag.setInteger("Count", count);
|
2022-06-24 12:32:13 +01:00
|
|
|
BGrid.addItem(
|
|
|
|
|
StackInfo.loadFromNBT(nbTag),
|
|
|
|
|
new BookmarkStackMeta(
|
2022-08-19 15:03:42 +03:00
|
|
|
recipeId != null ? recipeId.copy() : null,
|
|
|
|
|
(saveStackSize ? 1 : -1) * count,
|
2022-06-24 12:32:13 +01:00
|
|
|
true,
|
2022-10-13 11:06:08 +03:00
|
|
|
nbTag.hasKey("gtFluidName")));
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
BGrid.addItem(
|
|
|
|
|
normalizedA,
|
|
|
|
|
new BookmarkStackMeta(
|
|
|
|
|
recipeId,
|
|
|
|
|
(saveStackSize ? 1 : -1) * nbTagA.getInteger("Count"),
|
|
|
|
|
false,
|
2022-10-13 11:06:08 +03:00
|
|
|
nbTagA.hasKey("gtFluidName")));
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-04 13:28:43 +02:00
|
|
|
fixCountOfNamespaces();
|
2019-12-24 13:37:41 -08:00
|
|
|
saveBookmarks();
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
public BookmarkRecipeId getBookmarkRecipeId(int slotIndex) {
|
|
|
|
|
return ((BookmarkGrid) grid).getRecipeId(slotIndex);
|
|
|
|
|
}
|
2020-01-05 12:13:50 -08:00
|
|
|
|
2022-08-19 15:03:42 +03:00
|
|
|
public BookmarkRecipeId getBookmarkRecipeId(ItemStack stackA) {
|
2022-01-02 23:30:54 +02:00
|
|
|
BookmarkRecipeId recipeId = ((BookmarkGrid) grid).findRecipeId(stackA);
|
|
|
|
|
|
|
|
|
|
if (recipeId == null) {
|
2023-01-23 17:59:29 +08:00
|
|
|
for (int idx = 0; idx < getNameSpaceSize() && recipeId == null; idx++) {
|
2022-01-02 23:30:54 +02:00
|
|
|
if (idx == activeNamespaceIndex) continue;
|
|
|
|
|
recipeId = namespaces.get(idx).findRecipeId(stackA);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return recipeId;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected String getNamespaceLabelText(boolean shortFormat) {
|
2022-01-02 23:30:54 +02:00
|
|
|
String activePage = String.valueOf(activeNamespaceIndex + 1);
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
return shortFormat ? activePage : (activePage + "/" + fixCountOfNamespaces());
|
2020-01-05 12:13:50 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected int fixCountOfNamespaces() {
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
if (namespaces.get(getNameSpaceSize() - 1).size() > 0) {
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaces.add(new BookmarkGrid());
|
2023-01-23 17:59:29 +08:00
|
|
|
} else if (activeNamespaceIndex == getNameSpaceSize() - 2 && grid.size() == 0) {
|
|
|
|
|
namespaces.remove(getNameSpaceSize() - 1);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
return getNameSpaceSize();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected boolean removeEmptyNamespaces() {
|
|
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
if (activeNamespaceIndex != getNameSpaceSize() - 1 && grid.size() == 0) {
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaces.remove(activeNamespaceIndex);
|
|
|
|
|
grid = namespaces.get(activeNamespaceIndex);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected boolean prevNamespace() {
|
2022-01-02 23:30:54 +02:00
|
|
|
if (!bookmarksIsLoaded) {
|
|
|
|
|
return false;
|
2020-01-05 12:13:50 -08:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
fixCountOfNamespaces();
|
|
|
|
|
removeEmptyNamespaces();
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (activeNamespaceIndex == 0) {
|
2023-01-23 17:59:29 +08:00
|
|
|
activeNamespaceIndex = getNameSpaceSize() - 1;
|
2022-01-02 23:30:54 +02:00
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
activeNamespaceIndex--;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid = namespaces.get(activeNamespaceIndex);
|
|
|
|
|
|
|
|
|
|
return true;
|
2020-01-05 12:13:50 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected boolean nextNamespace() {
|
2022-01-02 23:30:54 +02:00
|
|
|
if (!bookmarksIsLoaded) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (removeEmptyNamespaces()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (activeNamespaceIndex == fixCountOfNamespaces() - 1) {
|
|
|
|
|
activeNamespaceIndex = 0;
|
|
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
activeNamespaceIndex++;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid = namespaces.get(activeNamespaceIndex);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void setBookmarkFile(String worldPath) {
|
2022-01-09 19:05:30 +02:00
|
|
|
|
|
|
|
|
final File dir = new File(CommonUtils.getMinecraftDir(), "saves/NEI/" + worldPath);
|
|
|
|
|
|
|
|
|
|
if (!dir.exists()) {
|
|
|
|
|
dir.mkdirs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookmarkFile = new File(dir, "bookmarks.ini");
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
bookmarkFile.createNewFile();
|
|
|
|
|
|
|
|
|
|
InputStream src = new FileInputStream(defaultBookmarks);
|
|
|
|
|
OutputStream dst = new FileOutputStream(bookmarkFile);
|
|
|
|
|
|
|
|
|
|
IOUtils.copy(src, dst);
|
|
|
|
|
|
|
|
|
|
src.close();
|
|
|
|
|
dst.close();
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
} catch (IOException e) {}
|
2022-01-09 19:05:30 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookmarksIsLoaded = false;
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void saveBookmarks() {
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-02-06 17:42:11 +02:00
|
|
|
if (bookmarkFile == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
ArrayList<String> strings = new ArrayList<>();
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2023-01-23 17:59:29 +08:00
|
|
|
for (int grpIdx = 0; grpIdx < getNameSpaceSize() - 1; grpIdx++) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final BookmarkGrid grid = namespaces.get(grpIdx);
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
JsonObject settings = new JsonObject();
|
|
|
|
|
settings.add("viewmode", new JsonPrimitive(grid.getViewMode().toString()));
|
|
|
|
|
settings.add("active", new JsonPrimitive(activeNamespaceIndex == grpIdx));
|
|
|
|
|
strings.add("; " + NBTJson.toJson(settings));
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
for (int idx = 0; idx < grid.size(); idx++) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(grid.getItem(idx));
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (nbTag != null) {
|
|
|
|
|
JsonObject row = new JsonObject();
|
|
|
|
|
BookmarkStackMeta meta = grid.getMetadata(idx);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
row.add("item", NBTJson.toJsonObject(nbTag));
|
|
|
|
|
row.add("factor", new JsonPrimitive(meta.factor));
|
|
|
|
|
row.add("ingredient", new JsonPrimitive(meta.ingredient));
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (meta.recipeId != null) {
|
|
|
|
|
row.add("recipeId", meta.recipeId.toJsonObject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strings.add(NBTJson.toJson(row));
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
} catch (JsonSyntaxException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to stringify bookmarked ItemStack to json string");
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-02-06 17:42:11 +02:00
|
|
|
try (FileOutputStream output = new FileOutputStream(bookmarkFile)) {
|
2022-05-27 18:38:54 +01:00
|
|
|
IOUtils.writeLines(strings, "\n", output, StandardCharsets.UTF_8);
|
2022-02-06 17:42:11 +02:00
|
|
|
} catch (IOException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", bookmarkFile, e);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public void loadBookmarksIfNeeded() {
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (bookmarksIsLoaded) {
|
2021-11-22 05:31:02 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bookmarksIsLoaded = true;
|
|
|
|
|
|
2022-01-09 19:05:30 +02:00
|
|
|
if (bookmarkFile == null || !bookmarkFile.exists()) {
|
2019-12-24 13:37:41 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
List<String> itemStrings;
|
2022-05-27 18:38:54 +01:00
|
|
|
try (FileInputStream reader = new FileInputStream(bookmarkFile)) {
|
2022-01-09 19:05:30 +02:00
|
|
|
NEIClientConfig.logger.info("Loading bookmarks from file {}", bookmarkFile);
|
2022-05-27 18:38:54 +01:00
|
|
|
itemStrings = IOUtils.readLines(reader, StandardCharsets.UTF_8);
|
2019-12-24 13:37:41 -08:00
|
|
|
} catch (IOException e) {
|
2022-01-09 19:05:30 +02:00
|
|
|
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", bookmarkFile, e);
|
2019-12-24 13:37:41 -08:00
|
|
|
return;
|
|
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaces.clear();
|
|
|
|
|
namespaces.add(new BookmarkGrid());
|
2022-06-23 01:03:29 +03:00
|
|
|
activeNamespaceIndex = -1;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
final JsonParser parser = new JsonParser();
|
2022-06-23 01:03:29 +03:00
|
|
|
int namespaceIndex = 0;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
for (String itemStr : itemStrings) {
|
2022-06-23 01:03:29 +03:00
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
try {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
if (itemStr.isEmpty()) {
|
2022-06-23 01:03:29 +03:00
|
|
|
itemStr = "; {}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemStr.startsWith("; ")) {
|
|
|
|
|
JsonObject settings = parser.parse(itemStr.substring(2)).getAsJsonObject();
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
if (namespaces.get(namespaceIndex).size() > 0) {
|
2022-06-24 12:32:13 +01:00
|
|
|
// do not create empty namespaces
|
2022-01-02 23:30:54 +02:00
|
|
|
namespaces.add(new BookmarkGrid());
|
2022-06-23 01:03:29 +03:00
|
|
|
namespaceIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.get("viewmode") != null) {
|
2022-06-24 12:32:13 +01:00
|
|
|
namespaces.get(namespaceIndex)
|
|
|
|
|
.setViewMode(BookmarkViewMode.valueOf(settings.get("viewmode").getAsString()));
|
2022-06-23 01:03:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (settings.get("active") != null && settings.get("active").getAsBoolean()) {
|
|
|
|
|
activeNamespaceIndex = namespaceIndex;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-22 05:31:02 +02:00
|
|
|
JsonObject jsonObject = parser.parse(itemStr).getAsJsonObject();
|
|
|
|
|
BookmarkRecipeId recipeId = null;
|
2022-01-02 23:30:54 +02:00
|
|
|
NBTTagCompound itemStackNBT;
|
2021-11-22 05:31:02 +02:00
|
|
|
|
|
|
|
|
if (jsonObject.get("item") != null) {
|
|
|
|
|
itemStackNBT = (NBTTagCompound) NBTJson.toNbt(jsonObject.get("item"));
|
2022-06-24 12:32:13 +01:00
|
|
|
} else { // old format
|
2021-11-22 05:31:02 +02:00
|
|
|
itemStackNBT = (NBTTagCompound) NBTJson.toNbt(jsonObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jsonObject.get("recipeId") != null && jsonObject.get("recipeId") instanceof JsonObject) {
|
|
|
|
|
recipeId = new BookmarkRecipeId((JsonObject) jsonObject.get("recipeId"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemStack itemStack = StackInfo.loadFromNBT(itemStackNBT);
|
|
|
|
|
|
2019-12-24 13:37:41 -08:00
|
|
|
if (itemStack != null) {
|
2022-06-24 12:32:13 +01:00
|
|
|
namespaces.get(namespaceIndex).addItem(
|
|
|
|
|
itemStack,
|
|
|
|
|
new BookmarkStackMeta(
|
|
|
|
|
recipeId,
|
|
|
|
|
jsonObject.has("factor") ? jsonObject.get("factor").getAsInt() : 0,
|
|
|
|
|
jsonObject.has("ingredient") ? jsonObject.get("ingredient").getAsBoolean() : false,
|
2022-09-18 19:08:16 +09:00
|
|
|
itemStackNBT.hasKey("gtFluidName")),
|
|
|
|
|
false);
|
2019-12-24 13:37:41 -08:00
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
NEIClientConfig.logger.warn(
|
|
|
|
|
"Failed to load bookmarked ItemStack from json string, the item no longer exists:\n{}",
|
|
|
|
|
itemStr);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2021-02-13 14:10:56 -08:00
|
|
|
} catch (IllegalArgumentException | JsonSyntaxException e) {
|
|
|
|
|
NEIClientConfig.logger.error("Failed to load bookmarked ItemStack from json string:\n{}", itemStr);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
if (activeNamespaceIndex == -1) {
|
|
|
|
|
activeNamespaceIndex = namespaceIndex;
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
grid = namespaces.get(activeNamespaceIndex);
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2021-11-22 05:31:02 +02:00
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public void resize(GuiContainer gui) {
|
2021-11-22 05:31:02 +02:00
|
|
|
loadBookmarksIfNeeded();
|
2022-01-02 23:30:54 +02:00
|
|
|
super.resize(gui);
|
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);
|
2022-06-23 01:03:29 +03:00
|
|
|
final int diff = rows * BookmarkGrid.SLOT_SIZE + getMarginTop(gui) - 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);
|
2022-01-02 23:30:54 +02:00
|
|
|
int labelWidth = 2;
|
|
|
|
|
|
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();
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
if (grid.getPerPage() > 0) {
|
|
|
|
|
LayoutManager.addWidget(namespacePrev);
|
|
|
|
|
LayoutManager.addWidget(namespaceNext);
|
|
|
|
|
LayoutManager.addWidget(namespaceLabel);
|
2023-09-08 07:16:37 +02:00
|
|
|
if (BookmarkContainerInfo.getBookmarkContainerHandler(getGuiContainer()) != null) {
|
|
|
|
|
LayoutManager.addWidget(pullBookmarkedItems);
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected String getPositioningSettingName() {
|
2022-05-06 22:41:45 +03:00
|
|
|
return "world.panels.bookmarks";
|
2020-02-04 20:11:17 -08:00
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getMarginLeft(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return PADDING;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getMarginTop(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return PADDING;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getWidth(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return gui.width - (gui.xSize + gui.width) / 2 - PADDING * 2;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
public int getHeight(GuiContainer gui) {
|
2022-05-06 22:41:45 +03:00
|
|
|
return gui.height - getMarginTop(gui) - PADDING;
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot) {
|
2022-05-06 22:41:45 +03:00
|
|
|
final ItemStack stack = grid.getItem(mouseDownSlot);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
if (stack == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final BookmarkStackMeta meta = ((BookmarkGrid) grid).getMetadata(mouseDownSlot);
|
|
|
|
|
int amount = stack.stackSize;
|
|
|
|
|
|
|
|
|
|
if (meta.factor < 0 && !meta.fluidDisplay) {
|
2022-08-19 15:03:42 +03:00
|
|
|
amount = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0;
|
2022-05-06 22:41:45 +03:00
|
|
|
|
|
|
|
|
if (amount == 0) {
|
|
|
|
|
amount = stack.getMaxStackSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NEIServerUtils.copyStack(stack, amount);
|
|
|
|
|
}
|
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) {
|
2022-10-13 11:06:08 +03:00
|
|
|
|
|
|
|
|
if (button == 0 && NEIClientUtils.shiftKey() && mouseDownSlot >= 0) {
|
2021-11-22 05:31:02 +02:00
|
|
|
ItemPanelSlot mouseOverSlot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (sortedStackIndex == -1) {
|
2022-01-02 23:30:54 +02:00
|
|
|
final ItemStack stack = grid.getItem(mouseDownSlot);
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (stack != null
|
|
|
|
|
&& (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 250)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
sortedNamespaceIndex = activeNamespaceIndex;
|
2021-11-22 05:31:02 +02:00
|
|
|
sortedStackIndex = mouseDownSlot;
|
2022-06-23 01:03:29 +03:00
|
|
|
grid.onGridChanged();
|
2021-11-22 05:31:02 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
} else {
|
2021-11-22 05:31:02 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
if (sortedNamespaceIndex != activeNamespaceIndex) {
|
|
|
|
|
final BookmarkGrid hoverGrid = namespaces.get(activeNamespaceIndex);
|
|
|
|
|
final BookmarkGrid sortedGrid = namespaces.get(sortedNamespaceIndex);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (mouseOverSlot != null || getNextSlot(new Point(mousex, mousey)) >= 0) {
|
2022-06-23 01:03:29 +03:00
|
|
|
final ItemStack stack = sortedGrid.getItem(sortedStackIndex);
|
|
|
|
|
final BookmarkStackMeta meta = sortedGrid.getMetadata(sortedStackIndex);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
sortedGrid.removeItem(sortedStackIndex);
|
2022-10-13 11:06:08 +03:00
|
|
|
hoverGrid.addItem(stack, meta, false);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
sortedNamespaceIndex = activeNamespaceIndex;
|
2022-06-23 01:03:29 +03:00
|
|
|
sortedStackIndex = hoverGrid.indexOf(stack, meta.recipeId);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
} else if (mouseOverSlot == null || mouseOverSlot.slotIndex != sortedStackIndex) {
|
|
|
|
|
final BookmarkGrid sortedGrid = namespaces.get(sortedNamespaceIndex);
|
|
|
|
|
|
|
|
|
|
if (mouseOverSlot != null && sortedGrid.getViewMode() == BookmarkViewMode.DEFAULT) {
|
|
|
|
|
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
|
2022-01-02 23:30:54 +02:00
|
|
|
sortedStackIndex = mouseOverSlot.slotIndex;
|
2022-06-23 01:03:29 +03:00
|
|
|
} else if (sortedGrid.getViewMode() == BookmarkViewMode.TODO_LIST) {
|
|
|
|
|
final ItemStack stack = sortedGrid.getItem(sortedStackIndex);
|
|
|
|
|
final BookmarkStackMeta meta = sortedGrid.getMetadata(sortedStackIndex);
|
2022-06-24 12:32:13 +01:00
|
|
|
final boolean isIngredient = sortedStackIndex > 0 && meta.recipeId != null
|
|
|
|
|
&& meta.ingredient
|
|
|
|
|
&& meta.recipeId.equals(sortedGrid.getRecipeId(sortedStackIndex - 1));
|
2022-06-23 01:03:29 +03:00
|
|
|
|
|
|
|
|
if (!isIngredient) {
|
|
|
|
|
mouseOverSlot = getSlotMouseOver(grid.marginLeft + grid.paddingLeft, mousey);
|
|
|
|
|
|
|
|
|
|
if (mouseOverSlot != null && sortedStackIndex != mouseOverSlot.slotIndex) {
|
|
|
|
|
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
|
|
|
|
|
sortedStackIndex = sortedGrid.indexOf(stack, meta.recipeId);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
} else if (mouseOverSlot != null && meta.recipeId != null
|
|
|
|
|
&& sortedGrid.getMetadata(mouseOverSlot.slotIndex).ingredient
|
|
|
|
|
&& meta.recipeId.equals(sortedGrid.getRecipeId(mouseOverSlot.slotIndex))) {
|
2022-06-23 01:03:29 +03:00
|
|
|
sortedGrid.moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
|
|
|
|
|
sortedStackIndex = sortedGrid.indexOf(stack, meta.recipeId);
|
|
|
|
|
}
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
private int getNextSlot(final Point point) {
|
2022-06-23 01:03:29 +03:00
|
|
|
final List<Integer> mask = grid.getMask();
|
|
|
|
|
final int columns = grid.getColumns();
|
|
|
|
|
final int perPage = grid.getRows() * columns;
|
2022-10-13 11:06:08 +03:00
|
|
|
final boolean line = ((BookmarkGrid) grid).getViewMode() == BookmarkViewMode.TODO_LIST;
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
for (int i = mask.size(); i < perPage; i++) {
|
|
|
|
|
if (!grid.isInvalidSlot(i) && (!line || (i % columns) == 0)) {
|
2022-01-02 23:30:54 +02:00
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (point == null || grid.getSlotRect(i).contains(point.x, point.y)) {
|
|
|
|
|
return i;
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (sortedStackIndex != -1) {
|
2022-01-02 23:30:54 +02:00
|
|
|
GuiContainerManager.drawItems.zLevel += 100;
|
2022-06-24 12:32:13 +01:00
|
|
|
GuiContainerManager.drawItem(
|
|
|
|
|
mousex - 8,
|
|
|
|
|
mousey - 8,
|
|
|
|
|
namespaces.get(sortedNamespaceIndex).getItem(sortedStackIndex).copy(),
|
|
|
|
|
true);
|
2022-01-02 23:30:54 +02:00
|
|
|
GuiContainerManager.drawItems.zLevel -= 100;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-13 11:06:08 +03:00
|
|
|
if (ItemPanels.itemPanel.draggedStack != null && this.contains(mousex, mousey)) {
|
|
|
|
|
final int idx = getNextSlot(null);
|
|
|
|
|
|
|
|
|
|
if (idx >= 0) {
|
|
|
|
|
Rectangle4i rect = grid.getSlotRect(idx);
|
|
|
|
|
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555); // highlight
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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)) {
|
|
|
|
|
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
2022-06-23 01:03:29 +03:00
|
|
|
|
|
|
|
|
if (BGrid.getViewMode() == BookmarkViewMode.DEFAULT) {
|
|
|
|
|
BGrid.setViewMode(BookmarkViewMode.TODO_LIST);
|
|
|
|
|
} else {
|
|
|
|
|
BGrid.setViewMode(BookmarkViewMode.DEFAULT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saveBookmarks();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return super.handleClickExt(mousex, mousey, button);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-06-24 12:32:13 +01:00
|
|
|
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
|
|
|
|
|
|
|
|
|
|
if (new Rectangle4i(pagePrev.x + pagePrev.w, pagePrev.y, pageNext.x - (pagePrev.x + pagePrev.w), pagePrev.h)
|
|
|
|
|
.contains(mx, my)) {
|
2022-06-23 01:03:29 +03:00
|
|
|
tooltip.add(translate("bookmark.viewmode.toggle.tip"));
|
|
|
|
|
}
|
2023-08-07 15:29:05 +02:00
|
|
|
if (new Rectangle4i(pullBookmarkedItems.x, pullBookmarkedItems.y, pullBookmarkedItems.w, pullBookmarkedItems.h)
|
2023-09-08 07:16:37 +02:00
|
|
|
.contains(mx, my) && BookmarkContainerInfo.getBookmarkContainerHandler(getGuiContainer()) != null) {
|
2023-08-07 15:29:05 +02:00
|
|
|
tooltip.add(translate("bookmark.pullBookmarkedItems.tip"));
|
|
|
|
|
}
|
2022-06-23 01:03:29 +03:00
|
|
|
|
|
|
|
|
return super.handleTooltip(mx, my, tooltip);
|
|
|
|
|
}
|
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) {
|
2022-10-13 11:06:08 +03:00
|
|
|
if (sortedStackIndex != -1) {
|
|
|
|
|
draggedStack = null;
|
2022-01-02 23:30:54 +02:00
|
|
|
sortedNamespaceIndex = -1;
|
2021-11-22 05:31:02 +02:00
|
|
|
sortedStackIndex = -1;
|
|
|
|
|
mouseDownSlot = -1;
|
2022-06-23 01:03:29 +03:00
|
|
|
grid.onGridChanged(); /* make sure grid redraws the new item */
|
2021-11-22 05:31:02 +02:00
|
|
|
saveBookmarks();
|
|
|
|
|
} else {
|
|
|
|
|
super.mouseUp(mousex, mousey, button);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
if (new Rectangle4i(
|
|
|
|
|
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) {
|
|
|
|
|
prevNamespace();
|
|
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
nextNamespace();
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-06-23 01:03:29 +03:00
|
|
|
saveBookmarks();
|
2022-01-02 23:30:54 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!contains(mousex, mousey)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (NEIClientUtils.controlKey()) {
|
|
|
|
|
final ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
|
|
|
|
|
|
|
|
|
|
if (slot != null) {
|
2022-06-24 12:32:13 +01:00
|
|
|
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
2022-01-02 23:30:54 +02:00
|
|
|
final BookmarkRecipeId recipeId = BGrid.getRecipeId(slot.slotIndex);
|
|
|
|
|
final boolean addFullRecipe = NEIClientUtils.shiftKey();
|
|
|
|
|
|
2023-09-09 02:22:33 -05:00
|
|
|
if (NEIClientUtils.altKey()) {
|
|
|
|
|
shift *= slot.item.getMaxStackSize();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-02 23:30:54 +02:00
|
|
|
if (addFullRecipe) {
|
|
|
|
|
BookmarkStackMeta iMeta;
|
|
|
|
|
|
|
|
|
|
for (int slotIndex = grid.size() - 1; slotIndex >= 0; slotIndex--) {
|
|
|
|
|
iMeta = BGrid.getMetadata(slotIndex);
|
2022-06-24 12:32:13 +01:00
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
if (iMeta.recipeId != null && iMeta.recipeId.equals(recipeId) && slotIndex != slot.slotIndex) {
|
|
|
|
|
shiftStackSize(slotIndex, shift);
|
2022-01-02 23:30:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-06 22:41:45 +03:00
|
|
|
shiftStackSize(slot.slotIndex, shift);
|
2022-01-02 23:30:54 +02:00
|
|
|
|
|
|
|
|
saveBookmarks();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return super.onMouseWheel(shift, mousex, mousey);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 12:32:13 +01:00
|
|
|
protected void shiftStackSize(int slotIndex, int shift) {
|
|
|
|
|
final BookmarkGrid BGrid = (BookmarkGrid) grid;
|
2022-05-06 22:41:45 +03:00
|
|
|
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(BGrid.getItem(slotIndex), true);
|
|
|
|
|
final BookmarkStackMeta meta = BGrid.getMetadata(slotIndex);
|
|
|
|
|
final int factor = Math.abs(meta.factor);
|
|
|
|
|
|
|
|
|
|
if (nbTag.getInteger("Count") == factor && meta.factor < 0 && shift > 0) {
|
|
|
|
|
meta.factor = factor;
|
|
|
|
|
} else {
|
2022-06-24 12:32:13 +01:00
|
|
|
meta.factor = nbTag.getInteger("Count") == factor && shift < 0 ? -1 * factor : factor;
|
2023-01-23 17:59:29 +08:00
|
|
|
if ((long) nbTag.getInteger("Count") + ((long) factor * shift) <= Integer.MAX_VALUE) {
|
|
|
|
|
nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + factor * shift, factor));
|
|
|
|
|
BGrid.replaceItem(slotIndex, StackInfo.loadFromNBT(nbTag));
|
|
|
|
|
}
|
2022-05-06 22:41:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-07 15:29:05 +02:00
|
|
|
|
|
|
|
|
public boolean pullBookmarkItems() {
|
|
|
|
|
IBookmarkContainerHandler containerHandler = BookmarkContainerInfo
|
|
|
|
|
.getBookmarkContainerHandler(getGuiContainer());
|
|
|
|
|
if (containerHandler == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
containerHandler.pullBookmarkItemsFromContainer(getGuiContainer(), ((BookmarkGrid) grid).realItems);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-12-24 13:37:41 -08:00
|
|
|
}
|