Compare commits

..

3 Commits

Author SHA1 Message Date
PrototypeTrousers 3ae251f098 Revert "Merge remote-tracking branch 'LasmGratel/async-itemrepo' into AE2-Omnifactory"
This reverts commit 86a42e970f.
2023-01-09 01:03:55 -03:00
PrototypeTrousers 82a906886f Revert "delay repo view sorting to once per tick"
This reverts commit d9588441b0.
2023-01-09 01:03:51 -03:00
PrototypeTrousers 5b2c6658c0 Revert "synchronizedList must be in a synchronized block when iterating"
This reverts commit 1f12fc5e91.
2023-01-09 01:03:51 -03:00
14 changed files with 115 additions and 270 deletions
+1 -3
View File
@@ -83,9 +83,7 @@ configurations {
dependencies {
// deobfCompile "gregtechce:gregtech:1.12.2:1.15.1.735"
// installable runtime dependencies
//deobfCompile "curse.maven:gregtechceu-557242:3949406"
compileOnly(files("etc/gregtech-1.12.2-2.4.4-beta.jar"))
deobfCompile "curse.maven:gregtechceu-557242:3949406"
compileOnly "curse.maven:chisel-235279:2915375"
@@ -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<T extends IAEStack<T>> extends IItemContainer<T>, Iterable<T>, Cloneable
public interface IItemList<T extends IAEStack<T>> extends IItemContainer<T>, Iterable<T>
{
/**
@@ -85,9 +85,4 @@ public interface IItemList<T extends IAEStack<T>> extends IItemContainer<T>, Ite
* resets stack sizes to 0.
*/
void resetStatus();
/**
* create a copy of this list.
*/
IItemList<T> clone();
}
}
@@ -1,11 +0,0 @@
package com.enderio.core.common.interfaces;
import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull;
public interface IOverlayRenderAware {
public void renderItemOverlayIntoGUI(@Nonnull ItemStack stack, int xPosition, int yPosition);
}
@@ -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() {
@@ -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() {
+87 -125
View File
@@ -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<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
private final List<IAEItemStack> view;
private List<IAEItemStack> asyncUpdatedView;
private boolean updated;
private final ArrayList<IAEItemStack> view = new ArrayList<>();
private final IScrollSource src;
private final ISortSource sortSrc;
private int rowSize = 9;
private volatile String searchString = "";
private String searchString = "";
private IPartitionList<IAEItemStack> 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<Void> 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<IAEItemStack> list = this.list.clone();
List<IAEItemStack> 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.<IAEItemStack>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<String> 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<String> 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<IAEItemStack> getList() {
@@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
public class CraftingTreeNode {
// what slot!
@@ -161,13 +161,6 @@ public final class FluidList implements IItemList<IAEFluidStack> {
}
}
@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);
}
@@ -1,74 +0,0 @@
package appeng.integration.modules.gregtech;
import net.minecraft.item.ItemStack;
import net.minecraft.launchwrapper.Launch;
import net.minecraftforge.fml.relauncher.ReflectionHelper;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ToolClass {
private static Class<?> GTToolClass;
private static Method getMaxItemDamage = null;
private static Method getItemDamage = null;
static {
try {
GTToolClass = Class.forName("gregtech.api.items.IToolItem", false, Launch.classLoader);
getItemDamage = ReflectionHelper.findMethod(GTToolClass, "getItemDamage", null, ItemStack.class);
getMaxItemDamage = ReflectionHelper.findMethod(GTToolClass, "getMaxItemDamage", null, ItemStack.class);
} catch (ClassNotFoundException ignored) {
try {
GTToolClass = Class.forName("gregtech.api.items.toolitem.IGTTool", false, Launch.classLoader);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
}
private static final Enum<Interfaces> GTToolInterface = getGTToolInterface();
public static Class<?> getGTToolClass() {
if (GTToolClass == null) {
System.out.printf("TToolClass == null");
}
return GTToolClass;
}
public static Enum<Interfaces> getGTToolInterface() {
if (GTToolClass.getName().equals("IToolItem")) {
return Interfaces.ITOOLITEM;
} else {
return Interfaces.IGTTOOL;
}
}
public static int getGTMaxDamage(ItemStack itemStack) {
if (GTToolInterface == Interfaces.ITOOLITEM) {
try {
return (int) getMaxItemDamage.invoke(itemStack.getItem(), itemStack);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
return itemStack.getMaxDamage();
}
}
public static int getGTitemDamage(ItemStack itemStack) {
if (GTToolInterface == Interfaces.ITOOLITEM) {
try {
return (int) getItemDamage.invoke(itemStack.getItem(), itemStack);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
} else {
return itemStack.getItemDamage();
}
}
enum Interfaces {
ITOOLITEM,
IGTTOOL
}
}
+3 -2
View File
@@ -56,7 +56,6 @@ import appeng.fluids.util.AEFluidStack;
import appeng.hooks.TickHandler;
import appeng.integration.Integrations;
import appeng.integration.modules.bogosorter.InventoryBogoSortModule;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.me.GridAccessException;
import appeng.me.GridNode;
import appeng.me.helpers.AENetworkProxy;
@@ -68,6 +67,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import gregtech.api.block.machines.BlockMachine;
import gregtech.api.items.IToolItem;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.util.GTUtility;
import ic2.api.item.ICustomDamageItem;
@@ -126,6 +126,7 @@ import java.util.*;
* @version rv2
* @since rv0
*/
@Optional.Interface(iface = "gregtech.api.items.IToolItem", modid = "gregtech")
@Optional.Interface(iface = "ic2.api.item.ICustomDamageItem", modid = "IC2")
public class Platform {
@@ -1416,7 +1417,7 @@ public class Platform {
//consider methods below moving to a compability class
public static boolean isGTDamageableItem(Item item) {
return ((GTLoaded) && ToolClass.getGTToolClass().isAssignableFrom(item.getClass()));
return ((GTLoaded) && item instanceof IToolItem);
}
public static MetaTileEntity getMetaTileEntity(IBlockAccess world, BlockPos pos) {
@@ -94,9 +94,4 @@ public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<
public void resetStatus() {
this.target.resetStatus();
}
@Override
public ItemListIgnoreCrafting<T> clone() {
return new ItemListIgnoreCrafting<>(target);
}
}
@@ -23,9 +23,9 @@ import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.Api;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.util.Platform;
import com.google.common.primitives.Ints;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
@@ -326,7 +326,7 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
} else if (a.getItem().isDamageable()) {
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
} else if (Platform.isGTDamageableItem(a.getItem())) {
return (ToolClass.getGTitemDamage(a) > 1 == ToolClass.getGTitemDamage(b) > 1);
return ((IToolItem) a.getItem()).getItemDamage(a) > 1 == ((IToolItem) b.getItem()).getItemDamage(b) > 1;
}
} else {
float percentDamageOfA = 0;
@@ -338,8 +338,8 @@ public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
} else if (Platform.isGTDamageableItem(a.getItem())) {
percentDamageOfA = (float) ToolClass.getGTitemDamage(a) / ToolClass.getGTMaxDamage(a);
percentDamageOfB = (float) ToolClass.getGTitemDamage(b) / ToolClass.getGTMaxDamage(b);
percentDamageOfA = (float) ((IToolItem) a.getItem()).getItemDamage(a) / ((IToolItem) a.getItem()).getMaxItemDamage(a);
percentDamageOfB = (float) ((IToolItem) b.getItem()).getItemDamage(b) / ((IToolItem) b.getItem()).getMaxItemDamage(b);
}
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
@@ -20,9 +20,9 @@ package appeng.util.item;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.integration.modules.gregtech.ToolClass;
import appeng.util.Platform;
import com.google.common.base.Preconditions;
import gregtech.api.items.IToolItem;
import ic2.api.item.ICustomDamageItem;
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
@@ -154,8 +154,8 @@ class FuzzyItemVariantList extends ItemVariantList {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ToolClass.getGTMaxDamage(stack);
damage = ToolClass.getGTitemDamage(stack);
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
@@ -189,8 +189,8 @@ class FuzzyItemVariantList extends ItemVariantList {
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
} else if (Platform.isGTDamageableItem(stack.getItem())) {
maxDamage = ToolClass.getGTMaxDamage(stack);
damage = ToolClass.getGTitemDamage(stack);
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
} else {
maxDamage = stack.getMaxDamage();
damage = stack.getItemDamage();
@@ -140,14 +140,6 @@ public final class ItemList implements IItemList<IAEItemStack> {
}
}
@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);
}