Actually filter items in grid
This commit is contained in:
@@ -59,6 +59,10 @@ public class ContainerGrid extends ContainerBase {
|
||||
addSlotToContainer(new SlotItemHandler(((TileGrid) grid).getPatterns(), 0, 152, 96));
|
||||
addSlotToContainer(new SlotOutput(((TileGrid) grid).getPatterns(), 1, 152, 132));
|
||||
}
|
||||
|
||||
if (!(grid instanceof WirelessGrid)) {
|
||||
addSlotToContainer(new SlotItemHandler(((TileGrid) grid).getFilter(), 0, 204, 6));
|
||||
}
|
||||
}
|
||||
|
||||
public IGrid getGrid() {
|
||||
|
@@ -13,6 +13,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.api.network.GridExtractFlags;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
@@ -45,7 +46,7 @@ public class GuiGrid extends GuiBase {
|
||||
private int slotNumber;
|
||||
|
||||
public GuiGrid(ContainerGrid container, IGrid grid) {
|
||||
super(container, 193, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 247 : 208);
|
||||
super(container, !(grid instanceof WirelessGrid) ? 227 : 193, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 247 : 208);
|
||||
|
||||
setScrollbar(new Scrollbar(174, 20, 12, (grid.getType() == EnumGridType.CRAFTING || grid.getType() == EnumGridType.PATTERN) ? 70 : 88));
|
||||
getScrollbar().setCanScroll(false);
|
||||
@@ -99,6 +100,26 @@ public class GuiGrid extends GuiBase {
|
||||
while (t.hasNext()) {
|
||||
ClientStack stack = t.next();
|
||||
|
||||
if (!(grid instanceof WirelessGrid)) {
|
||||
List<ItemStack> filteredItems = ((TileGrid) grid).getFilteredItems();
|
||||
|
||||
boolean found = filteredItems.isEmpty();
|
||||
|
||||
for (ItemStack item : filteredItems) {
|
||||
if (CompareUtils.compareStackNoQuantity(stack.getStack(), item)) {
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
t.remove();
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (grid.getViewType() == TileGrid.VIEW_TYPE_NON_CRAFTABLES && stack.isCraftable()) {
|
||||
t.remove();
|
||||
|
||||
@@ -222,7 +243,7 @@ public class GuiGrid extends GuiBase {
|
||||
ty = 2;
|
||||
}
|
||||
|
||||
drawTexture(x + 152, y + 114, 195, ty * 16, 16, 16);
|
||||
drawTexture(x + 152, y + 114, 240, ty * 16, 16, 16);
|
||||
}
|
||||
|
||||
searchField.drawTextBox();
|
||||
|
@@ -23,6 +23,7 @@ import refinedstorage.inventory.BasicItemHandler;
|
||||
import refinedstorage.inventory.BasicItemValidator;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.network.MessageGridSettingsUpdate;
|
||||
import refinedstorage.tile.TileBase;
|
||||
import refinedstorage.tile.TileNode;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
|
||||
@@ -65,6 +66,31 @@ public class TileGrid extends TileNode implements IGrid {
|
||||
private InventoryCraftResult result = new InventoryCraftResult();
|
||||
|
||||
private BasicItemHandler patterns = new BasicItemHandler(2, this, new BasicItemValidator(RefinedStorageItems.PATTERN));
|
||||
private BasicItemHandler filter = new BasicItemHandler(1, this, new BasicItemValidator(RefinedStorageItems.GRID_FILTER)) {
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
super.onContentsChanged(slot);
|
||||
|
||||
filteredItems.clear();
|
||||
|
||||
ItemStack stack = getStackInSlot(slot);
|
||||
|
||||
if (stack != null && stack.hasTagCompound()) {
|
||||
BasicItemHandler items = new BasicItemHandler(9 * 3);
|
||||
|
||||
TileBase.readItems(items, 0, stack.getTagCompound());
|
||||
|
||||
for (int i = 0; i < items.getSlots(); ++i) {
|
||||
ItemStack item = items.getStackInSlot(i);
|
||||
|
||||
if (item != null) {
|
||||
filteredItems.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
private List<ItemStack> filteredItems = new ArrayList<ItemStack>();
|
||||
|
||||
private EnumGridType type;
|
||||
|
||||
@@ -127,6 +153,14 @@ public class TileGrid extends TileNode implements IGrid {
|
||||
return patterns;
|
||||
}
|
||||
|
||||
public BasicItemHandler getFilter() {
|
||||
return filter;
|
||||
}
|
||||
|
||||
public List<ItemStack> getFilteredItems() {
|
||||
return filteredItems;
|
||||
}
|
||||
|
||||
public void onCraftingMatrixChanged() {
|
||||
markDirty();
|
||||
|
||||
@@ -334,6 +368,7 @@ public class TileGrid extends TileNode implements IGrid {
|
||||
|
||||
readItemsLegacy(matrix, 0, tag);
|
||||
readItems(patterns, 1, tag);
|
||||
readItems(filter, 2, tag);
|
||||
|
||||
if (tag.hasKey(NBT_VIEW_TYPE)) {
|
||||
viewType = tag.getInteger(NBT_VIEW_TYPE);
|
||||
@@ -358,6 +393,7 @@ public class TileGrid extends TileNode implements IGrid {
|
||||
|
||||
writeItemsLegacy(matrix, 0, tag);
|
||||
writeItems(patterns, 1, tag);
|
||||
writeItems(filter, 2, tag);
|
||||
|
||||
tag.setInteger(NBT_VIEW_TYPE, viewType);
|
||||
tag.setInteger(NBT_SORTING_DIRECTION, sortingDirection);
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Reference in New Issue
Block a user