diff --git a/src/api/java/appeng/api/storage/data/IItemList.java b/src/api/java/appeng/api/storage/data/IItemList.java index 4292f49b7..4d37ce012 100644 --- a/src/api/java/appeng/api/storage/data/IItemList.java +++ b/src/api/java/appeng/api/storage/data/IItemList.java @@ -39,7 +39,7 @@ import appeng.api.storage.IStorageChannel; * - For fluids: AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class).createList() * - Replace with the corresponding {@link IStorageChannel} type for non native channels */ -public interface IItemList> extends IItemContainer, Iterable, Cloneable +public interface IItemList> extends IItemContainer, Iterable { /** @@ -85,9 +85,4 @@ public interface IItemList> extends IItemContainer, Ite * resets stack sizes to 0. */ void resetStatus(); - - /** - * create a copy of this list. - */ - IItemList clone(); -} +} \ No newline at end of file diff --git a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java index da75b2b73..2567cac39 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiMEMonitorable.java @@ -103,7 +103,6 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi private int currentMouseY = 0; private boolean delayedUpdate; - private boolean updateView = true; protected int jeiOffset = Loader.isModLoaded("jei") ? 24 : 0; public GuiMEMonitorable(final InventoryPlayer inventoryPlayer, final ITerminalHost te) { @@ -162,7 +161,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi } if (!this.delayedUpdate) { - this.updateView = true; + this.repo.updateView(); + this.setScrollBar(); } } @@ -319,7 +319,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi this.searchField.setText(memoryText); this.searchField.selectAll(); this.repo.setSearchString(memoryText); - this.updateView = true; + this.repo.updateView(); + this.setScrollBar(); } craftingGridOffsetX = Integer.MAX_VALUE; @@ -380,7 +381,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) { this.searchField.setText(""); this.repo.setSearchString(""); - this.updateView = true; + this.repo.updateView(); + this.setScrollBar(); } super.mouseClicked(xCoord, yCoord, btn); @@ -474,7 +476,8 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi if (this.searchField.textboxKeyTyped(character, key)) { this.repo.setSearchString(this.searchField.getText()); - this.updateView = true; + this.repo.updateView(); + this.setScrollBar(); // tell forge the key event is handled and should not be sent out this.keyHandled = mouseInGui; } else { @@ -501,7 +504,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi this.delayedUpdate = false; } } - if (!this.delayedUpdate && updateView) { + if (!this.delayedUpdate) { this.repo.updateView(); this.setScrollBar(); } @@ -537,7 +540,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE)); } - this.updateView = true; + this.repo.updateView(); } int getReservedSpace() { diff --git a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java index 907a90dcd..5111de23a 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java +++ b/src/main/java/appeng/client/gui/implementations/GuiNetworkStatus.java @@ -55,8 +55,6 @@ public class GuiNetworkStatus extends AEBaseGui implements ISortSource { private GuiImgButton units; private int tooltip = -1; - private boolean updateView = true; - public GuiNetworkStatus(final InventoryPlayer inventoryPlayer, final INetworkTool te) { super(new ContainerNetworkStatus(inventoryPlayer, te)); final GuiScrollbar scrollbar = new GuiScrollbar(); @@ -208,17 +206,9 @@ public class GuiNetworkStatus extends AEBaseGui implements ISortSource { for (final IAEItemStack is : list) { this.repo.postUpdate(is); } - this.updateView = true; - } - @Override - public void updateScreen() { - if (updateView) { - this.repo.updateView(); - this.setScrollBar(); - updateView = false; - } - super.updateScreen(); + this.repo.updateView(); + this.setScrollBar(); } private void setScrollBar() { diff --git a/src/main/java/appeng/client/me/ItemRepo.java b/src/main/java/appeng/client/me/ItemRepo.java index 466b3ee9e..22a211a6a 100644 --- a/src/main/java/appeng/client/me/ItemRepo.java +++ b/src/main/java/appeng/client/me/ItemRepo.java @@ -39,22 +39,19 @@ import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.regex.Pattern; public class ItemRepo { private final IItemList list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); - private final List view; - private List asyncUpdatedView; - private boolean updated; + private final ArrayList view = new ArrayList<>(); private final IScrollSource src; private final ISortSource sortSrc; private int rowSize = 9; - private volatile String searchString = ""; + private String searchString = ""; private IPartitionList myPartitionList; private String innerSearch = ""; private boolean hasPower; @@ -62,14 +59,11 @@ public class ItemRepo { public ItemRepo(final IScrollSource src, final ISortSource sortSrc) { this.src = src; this.sortSrc = sortSrc; - - this.view = Collections.synchronizedList(new ArrayList<>()); - this.asyncUpdatedView = Collections.synchronizedList(new ArrayList<>()); - list.forEach(this.view::add); } public IAEItemStack getReferenceItem(int idx) { idx += this.src.getCurrentScroll() * this.rowSize; + if (idx >= this.view.size()) { return null; } @@ -101,128 +95,111 @@ public class ItemRepo { this.updateView(); } - private CompletableFuture searchTask = null; - public void updateView() { - if (searchTask != null) { - return; + this.view.clear(); + + this.view.ensureCapacity(this.list.size()); + + final Enum viewMode = this.sortSrc.getSortDisplay(); + final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE); + final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE; + + if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) { + this.updateJEI(this.searchString); } - if (updated) { - this.view.clear(); - this.view.addAll(asyncUpdatedView); - this.asyncUpdatedView.clear(); - this.updated = false; + final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO; + + boolean searchMod = false; + + this.innerSearch = searchString.toLowerCase(); + if (this.innerSearch.startsWith("@")) { + searchMod = true; + this.innerSearch = this.innerSearch.substring(1); } - // Since sortSrc is final, so we can safely call it inside lambda - searchTask = CompletableFuture.supplyAsync(() -> { - IItemList list = this.list.clone(); - List view = new ArrayList<>(list.size()); - Enum viewMode = this.sortSrc.getSortDisplay(); - - boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE; - - boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO; - - boolean searchMod = false; - - String innerSearch = searchString.toLowerCase(); - if (innerSearch.startsWith("@")) { - searchMod = true; - innerSearch = innerSearch.substring(1); - } - - Pattern m = null; + Pattern m = null; + try { + m = Pattern.compile(this.innerSearch, Pattern.CASE_INSENSITIVE); + } catch (final Throwable ignore) { try { - m = Pattern.compile(innerSearch, Pattern.CASE_INSENSITIVE); - } catch (final Throwable ignore) { - try { - m = Pattern.compile(Pattern.quote(innerSearch), Pattern.CASE_INSENSITIVE); - } catch (final Throwable __) { - return Collections.emptyList(); + m = Pattern.compile(Pattern.quote(this.innerSearch), Pattern.CASE_INSENSITIVE); + } catch (final Throwable __) { + return; + } + } + + boolean notDone = false; + for (IAEItemStack is : this.list) { + if (this.myPartitionList != null) { + if (!this.myPartitionList.isListed(is)) { + continue; } } + if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { + continue; + } - for (IAEItemStack is : list) { - if (this.myPartitionList != null) { - if (!this.myPartitionList.isListed(is)) { - continue; - } - } + if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { + continue; + } - if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { - continue; - } + final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase(); + boolean foundMatchingItemStack = true; - if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { - continue; - } - - final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase(); - boolean foundMatchingItemStack = true; - - for (String term : innerSearch.split(" ")) { - if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) { - term = term.substring(1); - if (dspName.contains(term)) { - foundMatchingItemStack = false; - break; - } - } else if (!dspName.contains(term)) { + for (String term : innerSearch.split(" ")) { + if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) { + term = term.substring(1); + if (dspName.contains(term)) { foundMatchingItemStack = false; break; } - } - - if (terminalSearchToolTips && !foundMatchingItemStack) { - final List tooltip = Platform.getTooltip(is); - for (final String line : tooltip) { - if (m.matcher(line).find()) { - foundMatchingItemStack = true; - break; - } - } - } - - if (foundMatchingItemStack) { - if (needsZeroCopy) { - is = is.copy(); - is.setStackSize(0); - } - - view.add(is); + } else if (!dspName.contains(term)) { + foundMatchingItemStack = false; + break; } } - final Enum SortBy = this.sortSrc.getSortBy(); - final Enum SortDir = this.sortSrc.getSortDir(); - - ItemSorters.setDirection((appeng.api.config.SortDir) SortDir); - ItemSorters.init(); - - if (SortBy == SortOrder.MOD) { - view.sort(ItemSorters.CONFIG_BASED_SORT_BY_MOD); - } else if (SortBy == SortOrder.AMOUNT) { - view.sort(ItemSorters.CONFIG_BASED_SORT_BY_SIZE); - } else if (SortBy == SortOrder.INVTWEAKS) { - if (InventoryBogoSortModule.isLoaded()) { - view.sort(InventoryBogoSortModule.COMPARATOR); - } else { - view.sort(ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS); + if (terminalSearchToolTips && !foundMatchingItemStack) { + final List tooltip = Platform.getTooltip(is); + for (final String line : tooltip) { + if (m.matcher(line).find()) { + foundMatchingItemStack = true; + break; + } } + } + + if (foundMatchingItemStack) { + if (needsZeroCopy) { + is = is.copy(); + is.setStackSize(0); + } + + this.view.add(is); + } + } + + final Enum SortBy = this.sortSrc.getSortBy(); + final Enum SortDir = this.sortSrc.getSortDir(); + + ItemSorters.setDirection((appeng.api.config.SortDir) SortDir); + ItemSorters.init(); + + if (SortBy == SortOrder.MOD) { + Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_MOD); + } else if (SortBy == SortOrder.AMOUNT) { + Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_SIZE); + } else if (SortBy == SortOrder.INVTWEAKS) { + if (InventoryBogoSortModule.isLoaded()) { + Collections.sort(this.view, InventoryBogoSortModule.COMPARATOR); } else { - view.sort(ItemSorters.CONFIG_BASED_SORT_BY_NAME); + Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS); } - - return view; - }).thenAcceptAsync(view -> { - this.updated = true; - this.asyncUpdatedView.addAll(view); - }).thenRunAsync(() -> { - this.searchTask = null; // Prevent redundant cancellation - }); + } else { + Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_NAME); + } } private void updateJEI(String filter) { @@ -234,10 +211,6 @@ public class ItemRepo { } public void clear() { - if (searchTask != null) { - searchTask.cancel(true); - searchTask = null; - } this.list.resetStatus(); } @@ -263,17 +236,6 @@ public class ItemRepo { public void setSearchString(@Nonnull final String searchString) { this.searchString = searchString; - - if (searchTask != null) { - searchTask.cancel(true); - searchTask = null; - } - - // Passive JEI auto search - final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE); - if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) { - this.updateJEI(this.searchString); - } } public IItemList getList() { diff --git a/src/main/java/appeng/fluids/util/FluidList.java b/src/main/java/appeng/fluids/util/FluidList.java index d04917548..7a8e8485a 100644 --- a/src/main/java/appeng/fluids/util/FluidList.java +++ b/src/main/java/appeng/fluids/util/FluidList.java @@ -161,13 +161,6 @@ public final class FluidList implements IItemList { } } - @Override - public FluidList clone() { - FluidList list = new FluidList(); - list.records.putAll(records); - return list; - } - private IAEFluidStack getFluidRecord(final IAEFluidStack fluid) { return this.records.get(fluid); } diff --git a/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java b/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java index 370955cf9..6b39463fe 100644 --- a/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java +++ b/src/main/java/appeng/util/inv/ItemListIgnoreCrafting.java @@ -94,9 +94,4 @@ public class ItemListIgnoreCrafting> implements IItemList< public void resetStatus() { this.target.resetStatus(); } - - @Override - public ItemListIgnoreCrafting clone() { - return new ItemListIgnoreCrafting<>(target); - } } diff --git a/src/main/java/appeng/util/item/ItemList.java b/src/main/java/appeng/util/item/ItemList.java index 04e8e58f7..0c0223e7d 100644 --- a/src/main/java/appeng/util/item/ItemList.java +++ b/src/main/java/appeng/util/item/ItemList.java @@ -140,14 +140,6 @@ public final class ItemList implements IItemList { } } - @Override - public ItemList clone() { - ItemList list = new ItemList(); - list.records.putAll(records); - list.version.set(version.get()); - return list; - } - private ItemVariantList getOrCreateRecord(Item item) { return this.records.computeIfAbsent(item, this::makeRecordMap); }