Allow grid filter searching in crafter manager and fix misc bugs
This commit is contained in:
@@ -4,6 +4,9 @@ import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
|||||||
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeCrafterManager;
|
import com.raoulvdberge.refinedstorage.apiimpl.network.node.NetworkNodeCrafterManager;
|
||||||
import com.raoulvdberge.refinedstorage.container.slot.SlotCrafterManager;
|
import com.raoulvdberge.refinedstorage.container.slot.SlotCrafterManager;
|
||||||
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
|
import com.raoulvdberge.refinedstorage.gui.IResizableDisplay;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.filtering.GridFilterParser;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.GridStackItem;
|
||||||
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
|
||||||
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
import com.raoulvdberge.refinedstorage.inventory.ItemHandlerBase;
|
||||||
import com.raoulvdberge.refinedstorage.item.ItemPattern;
|
import com.raoulvdberge.refinedstorage.item.ItemPattern;
|
||||||
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
import com.raoulvdberge.refinedstorage.tile.TileCrafterManager;
|
||||||
@@ -19,9 +22,11 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
|||||||
import net.minecraftforge.items.SlotItemHandler;
|
import net.minecraftforge.items.SlotItemHandler;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class ContainerCrafterManager extends ContainerBase {
|
public class ContainerCrafterManager extends ContainerBase {
|
||||||
public class CrafterManagerListener implements IContainerListener {
|
public class CrafterManagerListener implements IContainerListener {
|
||||||
@@ -70,6 +75,7 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
private Map<String, Integer> containerData;
|
private Map<String, Integer> containerData;
|
||||||
private Map<String, IItemHandlerModifiable> dummyInventories = new HashMap<>();
|
private Map<String, IItemHandlerModifiable> dummyInventories = new HashMap<>();
|
||||||
private Map<String, Integer> headings = new HashMap<>();
|
private Map<String, Integer> headings = new HashMap<>();
|
||||||
|
private int rows;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(IContainerListener listener) {
|
public void addListener(IContainerListener listener) {
|
||||||
@@ -116,11 +122,15 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
this.inventoryItemStacks.clear();
|
this.inventoryItemStacks.clear();
|
||||||
this.headings.clear();
|
this.headings.clear();
|
||||||
|
|
||||||
|
rows = 0;
|
||||||
|
|
||||||
addPlayerInventory(8, display.getYPlayerInventory());
|
addPlayerInventory(8, display.getYPlayerInventory());
|
||||||
|
|
||||||
int y = 19 + 18 - display.getCurrentOffset() * 18;
|
int y = 19 + 18 - display.getCurrentOffset() * 18;
|
||||||
int x = 8;
|
int x = 8;
|
||||||
|
|
||||||
|
List<Predicate<IGridStack>> filters = GridFilterParser.getFilters(null, display.getSearchFieldText(), Collections.emptyList());
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> category : containerData.entrySet()) {
|
for (Map.Entry<String, Integer> category : containerData.entrySet()) {
|
||||||
IItemHandlerModifiable dummy;
|
IItemHandlerModifiable dummy;
|
||||||
|
|
||||||
@@ -139,6 +149,7 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
|
|
||||||
int yHeading = y - 19;
|
int yHeading = y - 19;
|
||||||
|
|
||||||
|
int slotFound = 0;
|
||||||
for (int slot = 0; slot < category.getValue(); ++slot) {
|
for (int slot = 0; slot < category.getValue(); ++slot) {
|
||||||
boolean visible = true;
|
boolean visible = true;
|
||||||
|
|
||||||
@@ -153,9 +164,13 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
visible = false;
|
visible = false;
|
||||||
|
|
||||||
for (ItemStack output : pattern.getOutputs()) {
|
for (ItemStack output : pattern.getOutputs()) {
|
||||||
if (output.getDisplayName().toLowerCase().contains(display.getSearchFieldText().toLowerCase())) {
|
GridStackItem outputConverted = new GridStackItem(output);
|
||||||
visible = true;
|
|
||||||
break;
|
for (Predicate<IGridStack> filter : filters) {
|
||||||
|
if (filter.test(outputConverted)) {
|
||||||
|
visible = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,10 +184,13 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
x += 18;
|
x += 18;
|
||||||
|
|
||||||
// Don't increase y level if we are on our last slot row (otherwise we do y += 18 * 3)
|
// Don't increase y level if we are on our last slot row (otherwise we do y += 18 * 3)
|
||||||
if ((slot + 1) % 9 == 0 && slot + 1 < category.getValue()) {
|
if ((slotFound + 1) % 9 == 0 && slot + 1 < category.getValue()) {
|
||||||
x = 8;
|
x = 8;
|
||||||
y += 18;
|
y += 18;
|
||||||
|
rows++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slotFound++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +199,7 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
|
|
||||||
x = 8;
|
x = 8;
|
||||||
y += 18 * 2;
|
y += 18 * 2;
|
||||||
|
rows += 2; // Heading and first row
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,8 +208,8 @@ public class ContainerCrafterManager extends ContainerBase {
|
|||||||
return headings;
|
return headings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getContainerData() {
|
public int getRows() {
|
||||||
return containerData;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -73,20 +73,7 @@ public class GuiCrafterManager extends GuiBase implements IResizableDisplay {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRows() {
|
public int getRows() {
|
||||||
if (container == null || container.getContainerData() == null) {
|
return (container == null || !crafterManager.isActive()) ? 0 : container.getRows();
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rows = 0;
|
|
||||||
|
|
||||||
for (Map.Entry<String, Integer> containerData : container.getContainerData().entrySet()) {
|
|
||||||
if (t(containerData.getKey()).toLowerCase().contains(getSearchFieldText().toLowerCase())) {
|
|
||||||
rows++;
|
|
||||||
rows += Math.ceil((double) Math.max(9, containerData.getValue()) / 9D);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
|||||||
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
import com.raoulvdberge.refinedstorage.api.util.IFilter;
|
||||||
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
|
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public final class GridFilterParser {
|
public final class GridFilterParser {
|
||||||
public static List<Predicate<IGridStack>> getFilters(IGrid grid, String query, List<IFilter> filters) {
|
public static List<Predicate<IGridStack>> getFilters(@Nullable IGrid grid, String query, List<IFilter> filters) {
|
||||||
List<Predicate<IGridStack>> gridFilters = new LinkedList<>();
|
List<Predicate<IGridStack>> gridFilters = new LinkedList<>();
|
||||||
|
|
||||||
for (String part : query.toLowerCase().trim().split(" ")) {
|
for (String part : query.toLowerCase().trim().split(" ")) {
|
||||||
@@ -24,10 +25,12 @@ public final class GridFilterParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grid.getViewType() == IGrid.VIEW_TYPE_NON_CRAFTABLES) {
|
if (grid != null) {
|
||||||
gridFilters.add(new GridFilterCraftable(false));
|
if (grid.getViewType() == IGrid.VIEW_TYPE_NON_CRAFTABLES) {
|
||||||
} else if (grid.getViewType() == IGrid.VIEW_TYPE_CRAFTABLES) {
|
gridFilters.add(new GridFilterCraftable(false));
|
||||||
gridFilters.add(new GridFilterCraftable(true));
|
} else if (grid.getViewType() == IGrid.VIEW_TYPE_CRAFTABLES) {
|
||||||
|
gridFilters.add(new GridFilterCraftable(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filters.isEmpty()) {
|
if (!filters.isEmpty()) {
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ public class GridStackItem implements IGridStack {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private IStorageTracker.IStorageTrackerEntry entry;
|
private IStorageTracker.IStorageTrackerEntry entry;
|
||||||
|
|
||||||
|
public GridStackItem(ItemStack stack) {
|
||||||
|
this.stack = stack;
|
||||||
|
}
|
||||||
|
|
||||||
public GridStackItem(ByteBuf buf) {
|
public GridStackItem(ByteBuf buf) {
|
||||||
this.stack = StackUtils.readItemStack(buf);
|
this.stack = StackUtils.readItemStack(buf);
|
||||||
this.hash = buf.readInt();
|
this.hash = buf.readInt();
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import net.minecraftforge.fml.common.event.FMLInterModComms;
|
|||||||
public class IntegrationInventorySorter {
|
public class IntegrationInventorySorter {
|
||||||
public static void register() {
|
public static void register() {
|
||||||
// Prevent items moving while scrolling through slots with Inventory Sorter in the Crafter Manager
|
// Prevent items moving while scrolling through slots with Inventory Sorter in the Crafter Manager
|
||||||
FMLInterModComms.sendMessage("inventorysorter", "slotblacklist", "com.raoulvdberge.refinedstorage.container.slot.SlotCrafterManager");
|
FMLInterModComms.sendMessage("inventorysorter", "containerblacklist", "com.raoulvdberge.refinedstorage.container.ContainerCrafterManager");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user