Files
NotEnoughItems/src/main/java/codechicken/nei/BookmarkPanel.java
T

781 lines
24 KiB
Java
Raw Normal View History

2019-12-24 13:37:41 -08:00
package codechicken.nei;
2022-01-02 23:30:54 +02:00
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.util.NBTJson;
2021-11-22 05:31:02 +02:00
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.BookmarkRecipeId;
2022-01-02 23:30:54 +02:00
import codechicken.nei.guihook.GuiContainerManager;
import com.google.gson.JsonParser;
2022-01-02 23:30:54 +02:00
import com.google.gson.JsonPrimitive;
2021-11-22 05:31:02 +02:00
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
2019-12-24 13:37:41 -08:00
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import org.apache.commons.io.IOUtils;
2022-01-02 23:30:54 +02:00
import static codechicken.lib.gui.GuiDraw.getMousePosition;
import static codechicken.lib.gui.GuiDraw.drawRect;
import java.awt.Point;
2019-12-24 13:37:41 -08:00
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
2022-01-02 23:30:54 +02:00
import java.util.Map;
import java.util.HashMap;
2019-12-24 13:37:41 -08:00
2022-01-02 23:30:54 +02:00
public class BookmarkPanel extends ItemPanel
{
2019-12-24 13:37:41 -08:00
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;
public Label namespaceLabel;
protected ArrayList<BookmarkGrid> namespaces = new ArrayList<>();
public int activeNamespaceIndex = 0;
protected static class BookmarkStackMeta
{
public int factor;
public BookmarkRecipeId recipeId;
public boolean ingredient = false;
public BookmarkStackMeta(BookmarkRecipeId recipeId, int count, boolean ingredient)
{
this.recipeId = recipeId;
this.factor = count;
this.ingredient = ingredient;
}
2021-11-22 05:31:02 +02:00
2019-12-24 13:37:41 -08:00
}
2022-01-02 23:30:54 +02:00
protected static class BookmarkGrid extends ItemsGrid
{
protected List<BookmarkStackMeta> metadata = new ArrayList<>();
public int indexOf(ItemStack stackA, BookmarkRecipeId recipeId)
{
final boolean useNBT = NEIClientConfig.useNBTInBookmarks();
for (int idx = 0; idx < realItems.size(); idx++) {
final BookmarkStackMeta meta = getMetadata(idx);
if ((recipeId == null && meta.recipeId == null || recipeId != null && meta.recipeId != null && recipeId.equals(meta.recipeId)) && StackInfo.equalItemAndNBT(stackA, realItems.get(idx), useNBT)) {
return idx;
}
}
return -1;
}
public BookmarkStackMeta getMetadata(int idx)
{
return metadata.get(idx);
}
public void addItem(ItemStack stackA, BookmarkStackMeta meta)
{
realItems.add(stackA);
metadata.add(meta);
}
public void replaceItem(int idx, ItemStack stack)
{
realItems.set(idx, stack);
}
public void removeRecipe(int idx, boolean removeFullRecipe)
{
final BookmarkStackMeta meta = getMetadata(idx);
if (removeFullRecipe && meta.recipeId != null) {
removeRecipe(meta.recipeId);
} else {
removeItem(idx);
}
}
public void removeRecipe(BookmarkRecipeId recipeIdA)
{
BookmarkRecipeId recipeIdB;
for (int slotIndex = metadata.size() - 1; slotIndex >= 0; slotIndex--) {
recipeIdB = getRecipeId(slotIndex);
if (recipeIdB != null && recipeIdA.equals(recipeIdB)) {
removeItem(slotIndex);
}
}
}
protected boolean removeItem(int idx)
{
realItems.remove(idx);
metadata.remove(idx);
return true;
}
public BookmarkRecipeId getRecipeId(int idx)
{
return getMetadata(idx).recipeId;
}
public BookmarkRecipeId findRecipeId(ItemStack stackA)
{
final boolean useNBT = NEIClientConfig.useNBTInBookmarks();
for (int idx = 0; idx < realItems.size(); idx++) {
if (StackInfo.equalItemAndNBT(stackA, getItem(idx), useNBT)) {
return getRecipeId(idx);
}
}
return null;
}
public void moveItem(int src, int dst)
{
realItems.add(dst, realItems.remove(src));
metadata.add(dst, metadata.remove(src));
}
@Override
protected void drawItem(Rectangle4i rect, int idx, ItemPanelSlot focus)
{
if (LayoutManager.bookmarkPanel.sortedNamespaceIndex == LayoutManager.bookmarkPanel.activeNamespaceIndex && LayoutManager.bookmarkPanel.sortedStackIndex == idx) {
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight
} else {
if (focus != null) {
if (focus.slotIndex == idx) {
drawRect(rect.x, rect.y, rect.w, rect.h, 0xee555555);//highlight
} else if (
LayoutManager.bookmarkPanel.sortedStackIndex == -1 && //disabled when sorting
NEIClientUtils.shiftKey() && //show only with shift key
getRecipeId(focus.slotIndex) != null && getRecipeId(idx) != null && getRecipeId(focus.slotIndex).equals(getRecipeId(idx))//is some recipeId
) {
drawRect(rect.x, rect.y, rect.w, rect.h, getMetadata(idx).ingredient? 0x88b3b300: 0x88009933);//highlight recipe
}
}
GuiContainerManager.drawItem(rect.x + 1, rect.y + 1, getItem(idx), true);
}
}
2020-01-20 09:42:39 -08:00
}
2022-01-02 23:30:54 +02:00
public BookmarkPanel()
{
grid = new BookmarkGrid();
2019-12-24 13:37:41 -08:00
}
2022-01-02 23:30:54 +02:00
public void init()
2021-11-22 05:31:02 +02:00
{
2022-01-02 23:30:54 +02:00
super.init();
namespaceLabel = new Label("1", true);
namespacePrev = new Button("Prev")
{
public boolean onButtonPress(boolean rightclick)
{
if (rightclick) {
return false;
}
return prevNamespace();
}
@Override
public String getRenderLabel()
{
return "<";
}
};
namespaceNext = new Button("Next")
{
public boolean onButtonPress(boolean rightclick)
{
if (rightclick) {
return false;
}
return nextNamespace();
}
@Override
public String getRenderLabel()
{
return ">";
}
};
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
public String getLabelText()
{
return super.getLabelText() + " [" + grid.size() + "]";
}
public void addOrRemoveItem(ItemStack stackA)
{
addOrRemoveItem(stackA, "", null);
}
public void addOrRemoveItem(ItemStack stackover, String handlerName, List<PositionedStack> ingredients)
2021-11-22 05:31:02 +02:00
{
loadBookmarksIfNeeded();
2022-01-02 23:30:54 +02:00
final Point mousePos = getMousePosition();
final ItemPanelSlot slot = getSlotMouseOver(mousePos.x, mousePos.y);
final boolean addFullRecipe = NEIClientUtils.shiftKey();
final BookmarkGrid BGrid = (BookmarkGrid) grid;
if (slot != null && StackInfo.equalItemAndNBT(slot.item, stackover, true)) {
BGrid.removeRecipe(slot.slotIndex, addFullRecipe);
} else {
final boolean saveStackSize = NEIClientUtils.controlKey();
final NBTTagCompound nbTagA = StackInfo.itemStackToNBT(stackover, saveStackSize);
final ItemStack normalizedA = StackInfo.loadFromNBT(nbTagA);
BookmarkRecipeId recipeId = null;
if (NEIClientConfig.saveCurrentRecipeInBookmarksEnabled() && handlerName != "" && ingredients != null && ingredients.size() > 0) {
recipeId = new BookmarkRecipeId(handlerName, ingredients);
}
final int idx = BGrid.indexOf(normalizedA, recipeId);
if (idx != -1) {
BGrid.removeRecipe(idx, addFullRecipe);
} else {
if (addFullRecipe && handlerName != "" && ingredients != null) {
final Map<NBTTagCompound, Integer> unique = new HashMap<>();
final ArrayList<NBTTagCompound> sorted = new ArrayList<>();
BGrid.removeRecipe(recipeId);
for (PositionedStack stack : ingredients) {
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack.item, saveStackSize);
if (nbTag.getInteger("Count") > 0) {
if (unique.get(nbTag) == null) {
unique.put(nbTag, 1);
sorted.add(nbTag);
} else if (saveStackSize) {
unique.put(nbTag, unique.get(nbTag) + 1);
}
}
}
for (NBTTagCompound nbTag : sorted) {
nbTag.setInteger("Count", nbTag.getInteger("Count") * unique.get(nbTag));
BGrid.addItem(StackInfo.loadFromNBT(nbTag), new BookmarkStackMeta(recipeId, nbTag.getInteger("Count"), true));
}
}
BGrid.addItem(normalizedA, new BookmarkStackMeta(recipeId, nbTagA.getInteger("Count"), false));
}
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-01-04 13:28:43 +02:00
fixCountOfNamespaces();
2019-12-24 13:37:41 -08:00
saveBookmarks();
}
2022-01-02 23:30:54 +02:00
public BookmarkRecipeId getBookmarkRecipeId(ItemStack stackA)
2020-01-05 12:13:50 -08:00
{
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
final Point mousePos = getMousePosition();
final ItemPanelSlot slot = getSlotMouseOver(mousePos.x, mousePos.y);
if (slot != null && StackInfo.equalItemAndNBT(slot.item, stackA, true)) {
return ((BookmarkGrid) grid).getRecipeId(slot.slotIndex);
2020-01-05 12:13:50 -08:00
}
2022-01-02 23:30:54 +02:00
BookmarkRecipeId recipeId = ((BookmarkGrid) grid).findRecipeId(stackA);
if (recipeId == null) {
for (int idx = 0; idx < namespaces.size() && recipeId == null; idx++) {
if (idx == activeNamespaceIndex) continue;
recipeId = namespaces.get(idx).findRecipeId(stackA);
}
}
return recipeId;
}
protected String getNamespaceLabelText(boolean shortFormat)
{
String activePage = String.valueOf(activeNamespaceIndex + 1);
return shortFormat? activePage: (activePage + "/" + fixCountOfNamespaces());
2020-01-05 12:13:50 -08:00
}
2022-01-02 23:30:54 +02:00
protected int fixCountOfNamespaces()
2020-01-05 12:13:50 -08:00
{
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
if (namespaces.get(namespaces.size() - 1).size() > 0) {
namespaces.add(new BookmarkGrid());
} else if (activeNamespaceIndex == namespaces.size() - 2 && grid.size() == 0) {
namespaces.remove(namespaces.size() - 1);
}
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
return namespaces.size();
}
protected boolean removeEmptyNamespaces()
{
if (activeNamespaceIndex != namespaces.size() - 1 && grid.size() == 0) {
namespaces.remove(activeNamespaceIndex);
grid = namespaces.get(activeNamespaceIndex);
return true;
}
return false;
}
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
protected boolean prevNamespace()
{
if (!bookmarksIsLoaded) {
return false;
2020-01-05 12:13:50 -08: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) {
activeNamespaceIndex = namespaces.size() - 1;
} else {
activeNamespaceIndex --;
}
grid = namespaces.get(activeNamespaceIndex);
return true;
2020-01-05 12:13:50 -08:00
}
2022-01-02 23:30:54 +02:00
protected boolean nextNamespace()
{
if (!bookmarksIsLoaded) {
return false;
}
if (removeEmptyNamespaces()) {
return true;
}
if (activeNamespaceIndex == fixCountOfNamespaces() - 1) {
activeNamespaceIndex = 0;
} else {
activeNamespaceIndex ++;
}
grid = namespaces.get(activeNamespaceIndex);
return true;
}
2021-11-22 05:31:02 +02:00
public void saveBookmarks()
{
2022-01-02 23:30:54 +02:00
ArrayList<String> strings = new ArrayList<>();
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
for (int grpIdx = 0; grpIdx < namespaces.size() - 1; grpIdx++) {
final BookmarkGrid grid = namespaces.get(grpIdx);
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
if (grpIdx > 0) {
strings.add("");//namespace separator; ignore first namespace
}
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));
if (nbTag != null) {
JsonObject row = new JsonObject();
BookmarkStackMeta meta = grid.getMetadata(idx);
row.add("item", NBTJson.toJsonObject(nbTag));
row.add("factor", new JsonPrimitive(meta.factor));
row.add("ingredient", new JsonPrimitive(meta.ingredient));
if (meta.recipeId != null) {
row.add("recipeId", meta.recipeId.toJsonObject());
}
strings.add(NBTJson.toJson(row));
2021-11-22 05:31:02 +02: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
}
2022-01-02 23:30:54 +02:00
2021-11-22 05:31:02 +02:00
}
2019-12-24 13:37:41 -08:00
}
2021-11-22 05:31:02 +02:00
2019-12-24 13:37:41 -08:00
File file = NEIClientConfig.bookmarkFile;
2021-11-22 05:31:02 +02:00
if (file != null) {
2019-12-24 13:37:41 -08:00
try(FileWriter writer = new FileWriter(file)) {
IOUtils.writeLines(strings, "\n", writer);
} catch (IOException e) {
NEIClientConfig.logger.error("Filed to save bookmarks list to file {}", file, e);
}
}
2021-11-22 05:31:02 +02:00
2019-12-24 13:37:41 -08:00
}
2021-11-22 05:31:02 +02:00
public void loadBookmarksIfNeeded()
{
2022-01-02 23:30:54 +02:00
if (bookmarksIsLoaded) {
2021-11-22 05:31:02 +02:00
return;
}
bookmarksIsLoaded = true;
2019-12-24 13:37:41 -08:00
File file = NEIClientConfig.bookmarkFile;
if (file == null || !file.exists()) {
return;
}
2022-01-02 23:30:54 +02:00
2019-12-24 13:37:41 -08:00
List<String> itemStrings;
try (FileReader reader = new FileReader(file)) {
NEIClientConfig.logger.info("Loading bookmarks from file {}", file);
itemStrings = IOUtils.readLines(reader);
} catch (IOException e) {
NEIClientConfig.logger.error("Failed to load bookmarks from file {}", file, e);
return;
}
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
namespaces.clear();
namespaces.add(new BookmarkGrid());
activeNamespaceIndex = 0;
final JsonParser parser = new JsonParser();
2019-12-24 13:37:41 -08:00
for (String itemStr: itemStrings) {
try {
2022-01-02 23:30:54 +02:00
if (itemStr.isEmpty()) {
if (namespaces.get(activeNamespaceIndex).size() > 0) {
//do not create empty namespaces
namespaces.add(new BookmarkGrid());
activeNamespaceIndex++;
}
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-01-02 23:30:54 +02: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);
2022-01-02 23:30:54 +02:00
2019-12-24 13:37:41 -08:00
if (itemStack != null) {
2022-01-02 23:30:54 +02:00
namespaces.get(activeNamespaceIndex).addItem(itemStack, new BookmarkStackMeta(
recipeId,
jsonObject.has("factor")? jsonObject.get("factor").getAsInt(): 1,
jsonObject.has("ingredient")? jsonObject.get("ingredient").getAsBoolean(): false
));
2019-12-24 13:37:41 -08:00
} else {
NEIClientConfig.logger.warn("Failed to load bookmarked ItemStack from json string, the item no longer exists:\n{}", itemStr);
}
2021-11-22 05:31:02 +02: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
if (namespaces.get(activeNamespaceIndex).size() == 0) {
activeNamespaceIndex = Math.max(activeNamespaceIndex - 1, 0);
}
grid = namespaces.get(activeNamespaceIndex);
2019-12-24 13:37:41 -08:00
}
2022-01-02 23:30:54 +02:00
2021-11-22 05:31:02 +02:00
@Override
2022-01-02 23:30:54 +02: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);
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
final int buttonHeight = 16;
final int buttonWidth = 16;
final int buttonTop = gui.height - buttonHeight - 2;
final int leftBorder = LayoutManager.bookmarksButton.x + LayoutManager.bookmarksButton.w + 2;
final int rightBorder = x + w;
final int center = leftBorder + (rightBorder - leftBorder) / 2;
int labelWidth = 2;
namespacePrev.h = namespaceNext.h = buttonHeight;
namespacePrev.w = namespaceNext.w = buttonWidth;
namespacePrev.y = namespaceNext.y = buttonTop;
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-01-02 23:30:54 +02:00
namespaceLabel.y = buttonTop + 5;
namespaceLabel.x = center;
namespacePrev.x = center - labelWidth / 2 - 2 - namespacePrev.w;
namespaceNext.x = center + labelWidth / 2 + 2;
2019-12-24 13:37:41 -08:00
}
2020-02-04 20:11:17 -08:00
@Override
2022-01-02 23:30:54 +02:00
public void setVisible()
{
super.setVisible();
LayoutManager.addWidget(namespacePrev);
LayoutManager.addWidget(namespaceNext);
LayoutManager.addWidget(namespaceLabel);
2020-02-04 20:11:17 -08:00
}
2019-12-24 13:37:41 -08:00
@Override
2022-01-02 23:30:54 +02:00
public int getMarginLeft(GuiContainer gui)
{
2019-12-24 13:37:41 -08:00
return 5;
}
@Override
2022-01-02 23:30:54 +02:00
public int getMarginTop(GuiContainer gui)
{
2019-12-24 13:37:41 -08:00
LayoutStyleMinecraft layout = (LayoutStyleMinecraft)LayoutManager.getLayoutStyle();
return 2 + (((int)Math.ceil((double)layout.buttonCount / layout.numButtons)) * 18);
}
@Override
2022-01-02 23:30:54 +02:00
public int getWidth(GuiContainer gui)
{
return LayoutManager.getLeftSize(gui) - ((gui.xSize + gui.width) / 2 + 3) - 16;
2019-12-24 13:37:41 -08:00
}
@Override
2022-01-02 23:30:54 +02:00
public int getHeight(GuiContainer gui)
{
// - 19 = 22 + 1 -> input in bottom
return gui.height - getMarginTop(gui) - 23;
2019-12-24 13:37:41 -08:00
}
2021-11-22 05:31:02 +02:00
@Override
public void mouseDragged(int mousex, int mousey, int button, long heldTime)
{
if (button == 0 && NEIClientUtils.shiftKey() && mouseDownSlot >= 0) {
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-01-02 23:30:54 +02:00
if (stack != null && (mouseOverSlot == null || mouseOverSlot.slotIndex != mouseDownSlot || heldTime > 250)) {
sortedNamespaceIndex = activeNamespaceIndex;
2021-11-22 05:31:02 +02:00
sortedStackIndex = mouseDownSlot;
}
2022-01-02 23:30:54 +02:00
} else {
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
if (mouseOverSlot == null && sortedNamespaceIndex != activeNamespaceIndex) {
mouseOverSlot = getNextSlot(mousex, mousey);
}
2021-11-22 05:31:02 +02:00
2022-01-02 23:30:54 +02:00
if (mouseOverSlot != null) {
if (sortedNamespaceIndex != activeNamespaceIndex) {
BookmarkGrid BGrid = namespaces.get(sortedNamespaceIndex);
BookmarkStackMeta meta = BGrid.getMetadata(sortedStackIndex);
ItemStack stack = BGrid.getItem(sortedStackIndex);
BGrid.removeItem(sortedStackIndex);
((BookmarkGrid) grid).addItem(stack, meta);
sortedNamespaceIndex = activeNamespaceIndex;
sortedStackIndex = grid.size() - 1;
}
if (mouseOverSlot.slotIndex != sortedStackIndex) {
((BookmarkGrid) grid).moveItem(sortedStackIndex, mouseOverSlot.slotIndex);
sortedStackIndex = mouseOverSlot.slotIndex;
}
}
2021-11-22 05:31:02 +02:00
}
return;
}
super.mouseDragged(mousex, mousey, button, heldTime);
}
2022-01-02 23:30:54 +02:00
private ItemPanelSlot getNextSlot(int mousex, int mousey)
{
int idx = grid.getPage() * grid.getPerPage() - grid.getPerPage();
int gSize = grid.size();
for (int i = 0; i < grid.getRows() * grid.getColumns() && idx <= gSize; i++) {
if (!grid.isInvalidSlot(i)) {
if (idx == gSize && grid.getSlotRect(i).contains(mousex, mousey)) {
return new ItemPanelSlot(idx, null);
}
idx++;
}
}
return null;
}
@Override
public void postDraw(int mousex, int mousey)
{
if (sortedStackIndex != -1) {
GuiContainerManager.drawItems.zLevel += 100;
GuiContainerManager.drawItem(mousex - 8, mousey - 8, namespaces.get(sortedNamespaceIndex).getItem(sortedStackIndex).copy(), true);
GuiContainerManager.drawItems.zLevel -= 100;
}
super.postDraw(mousex, mousey);
}
@Override
protected ItemStack getDraggedStackWithQuantity(int mouseDownSlot)
{
ItemStack stack = grid.getItem(mouseDownSlot);
return stack != null? stack.copy(): null;
}
2021-11-22 05:31:02 +02:00
@Override
public void mouseUp(int mousex, int mousey, int button)
{
2022-01-02 23:30:54 +02:00
if (sortedStackIndex != -1) {
sortedNamespaceIndex = -1;
2021-11-22 05:31:02 +02:00
sortedStackIndex = -1;
mouseDownSlot = -1;
saveBookmarks();
} else {
super.mouseUp(mousex, mousey, button);
}
}
2022-01-02 23:30:54 +02:00
@Override
public boolean onMouseWheel(int shift, int mousex, int mousey)
{
if (new Rectangle4i(namespacePrev.x, namespacePrev.y, namespaceNext.x + namespaceNext.w - namespacePrev.x, namespacePrev.h).contains(mousex, mousey)) {
if (shift > 0) {
prevNamespace();
} else {
nextNamespace();
}
return true;
}
if (!contains(mousex, mousey)) {
return false;
}
if (NEIClientUtils.controlKey()) {
final ItemPanelSlot slot = getSlotMouseOver(mousex, mousey);
if (slot != null) {
final BookmarkGrid BGrid = (BookmarkGrid)grid;
final BookmarkRecipeId recipeId = BGrid.getRecipeId(slot.slotIndex);
final BookmarkStackMeta meta = BGrid.getMetadata(slot.slotIndex);
final boolean addFullRecipe = NEIClientUtils.shiftKey();
if (addFullRecipe) {
BookmarkStackMeta iMeta;
for (int slotIndex = grid.size() - 1; slotIndex >= 0; slotIndex--) {
iMeta = BGrid.getMetadata(slotIndex);
if (iMeta.recipeId != null && iMeta.recipeId.equals(recipeId)) {
NBTTagCompound nbTag = StackInfo.itemStackToNBT(BGrid.getItem(slotIndex), true);
nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + iMeta.factor * shift, iMeta.factor));
BGrid.replaceItem(slotIndex, StackInfo.loadFromNBT(nbTag));
}
}
}
NBTTagCompound nbTag = StackInfo.itemStackToNBT(slot.item, true);
nbTag.setInteger("Count", Math.max(nbTag.getInteger("Count") + meta.factor * shift, meta.factor));
BGrid.replaceItem(slot.slotIndex, StackInfo.loadFromNBT(nbTag));
saveBookmarks();
return true;
}
}
return super.onMouseWheel(shift, mousex, mousey);
}
2019-12-24 13:37:41 -08:00
}