2024-02-21 18:12:28 +02:00
|
|
|
package codechicken.nei;
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2024-02-21 18:12:28 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
2025-04-24 18:48:40 +03:00
|
|
|
import codechicken.nei.ItemsGrid.ItemsGridSlot;
|
|
|
|
|
import codechicken.nei.ItemsGrid.MouseContext;
|
2025-09-15 20:21:52 +03:00
|
|
|
import codechicken.nei.recipe.Recipe.RecipeId;
|
2024-02-21 18:12:28 +02:00
|
|
|
import codechicken.nei.recipe.StackInfo;
|
|
|
|
|
|
2025-09-15 20:21:52 +03:00
|
|
|
public class ItemHistoryPanel extends AbstractSubpanel<ItemsGrid<ItemHistoryPanel.HistoryGridSlot, MouseContext>> {
|
|
|
|
|
|
|
|
|
|
public static class HistoryGridSlot extends ItemsGridSlot {
|
|
|
|
|
|
|
|
|
|
public HistoryGridSlot(int slotIndex, int itemIndex, ItemStack item) {
|
|
|
|
|
super(slotIndex, itemIndex, item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public RecipeId getRecipeId() {
|
|
|
|
|
return FavoriteRecipes.getFavorite(this.item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
public ItemHistoryPanel() {
|
|
|
|
|
this.grid = new ItemsGrid<>() {
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-09-15 20:21:52 +03:00
|
|
|
protected List<HistoryGridSlot> gridMask;
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
@Override
|
|
|
|
|
protected void onGridChanged() {
|
|
|
|
|
this.gridMask = null;
|
|
|
|
|
super.onGridChanged();
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
@Override
|
2025-09-15 20:21:52 +03:00
|
|
|
public List<HistoryGridSlot> getMask() {
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
if (this.gridMask == null) {
|
|
|
|
|
this.gridMask = new ArrayList<>();
|
2025-11-05 21:55:33 +02:00
|
|
|
int itemIndex = 0;
|
|
|
|
|
for (int slotIndex = 0; slotIndex < this.rows * this.columns && itemIndex < size(); slotIndex++) {
|
|
|
|
|
if (!isInvalidSlot(slotIndex)) {
|
|
|
|
|
this.gridMask.add(new HistoryGridSlot(slotIndex, itemIndex, getItem(itemIndex)));
|
|
|
|
|
itemIndex++;
|
|
|
|
|
}
|
2025-08-22 14:58:41 +03:00
|
|
|
}
|
2025-11-05 21:55:33 +02:00
|
|
|
|
|
|
|
|
ItemHistoryPanel.this.updateLinePadding();
|
2025-08-22 14:58:41 +03:00
|
|
|
}
|
2025-04-24 18:48:40 +03:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
return this.gridMask;
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
@Override
|
|
|
|
|
protected MouseContext getMouseContext(int mousex, int mousey) {
|
2025-09-15 20:21:52 +03:00
|
|
|
final HistoryGridSlot hovered = getSlotMouseOver(mousex, mousey);
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
if (hovered != null) {
|
|
|
|
|
return new MouseContext(
|
|
|
|
|
hovered.slotIndex,
|
|
|
|
|
hovered.slotIndex / this.columns,
|
|
|
|
|
hovered.slotIndex % this.columns);
|
|
|
|
|
}
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
return null;
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
};
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-08-22 14:58:41 +03:00
|
|
|
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
|
|
|
|
|
return ItemQuantityField.prepareStackWithQuantity(itemStack, 0);
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-08-22 14:58:41 +03:00
|
|
|
public void draw(int mousex, int mousey) {
|
|
|
|
|
if (this.grid.size() > 0) {
|
|
|
|
|
super.draw(mousex, mousey);
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2025-08-22 14:58:41 +03:00
|
|
|
public int setPanelWidth(int width) {
|
|
|
|
|
final int columns = width / ItemsGrid.SLOT_SIZE;
|
|
|
|
|
final int useRows = NEIClientConfig.getIntSetting("inventory.history.useRows");
|
|
|
|
|
final int rows = (int) Math.min(Math.ceil(this.grid.size() * 1f / columns), useRows);
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
this.w = width;
|
|
|
|
|
this.h = 8 + ItemsGrid.SLOT_SIZE * Math.max(rows, 1);
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
return rows;
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
public void update() {
|
|
|
|
|
this.splittingLineColor = NEIClientConfig.getSetting("inventory.history.color").getHexValue();
|
|
|
|
|
super.update();
|
2025-04-24 18:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
public void addItem(ItemStack stack) {
|
|
|
|
|
if (stack != null) {
|
|
|
|
|
ItemStack is = StackInfo.withAmount(stack, 0);
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
this.grid.realItems.removeIf(historyStack -> StackInfo.equalItemAndNBT(historyStack, stack, true));
|
|
|
|
|
this.grid.realItems.add(0, is);
|
2024-02-21 18:12:28 +02:00
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
if (this.grid.realItems.size() > Math.max(50, this.grid.rows * this.grid.columns)) {
|
|
|
|
|
this.grid.realItems.remove(this.grid.realItems.size() - 1);
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-22 14:58:41 +03:00
|
|
|
this.grid.onItemsChanged();
|
2024-02-21 18:12:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|