Theoretical performance fix for #2062 "Massive search lag with external storage". Needs confirmation.
This commit is contained in:
@@ -1,35 +1,18 @@
|
||||
package com.raoulvdberge.refinedstorage.gui.grid.filtering;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.gui.grid.stack.IGridStack;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class GridFilterMod implements Predicate<IGridStack> {
|
||||
private String modName;
|
||||
private String inputModName;
|
||||
|
||||
public GridFilterMod(String modName) {
|
||||
this.modName = modName.toLowerCase().replace(" ", "");
|
||||
}
|
||||
|
||||
private String getModNameFromModId(String id) {
|
||||
ModContainer container = Loader.instance().getActiveModList().stream()
|
||||
.filter(m -> m.getModId().toLowerCase().equals(id))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
return container == null ? id : container.getName().toLowerCase().replace(" ", "");
|
||||
public GridFilterMod(String inputModName) {
|
||||
this.inputModName = inputModName.toLowerCase().replace(" ", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(IGridStack stack) {
|
||||
String otherModId = stack.getModId().toLowerCase();
|
||||
|
||||
if (!getModNameFromModId(otherModId).contains(modName)) {
|
||||
return stack.getModId().contains(modName);
|
||||
}
|
||||
|
||||
return true;
|
||||
return stack.getModId().contains(inputModName) || stack.getModName().contains(inputModName);
|
||||
}
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ public class GridStackFluid implements IGridStack {
|
||||
private IStorageTracker.IStorageTrackerEntry entry;
|
||||
private boolean craftable;
|
||||
private boolean displayCraftText;
|
||||
private String modId;
|
||||
private String modName;
|
||||
|
||||
public GridStackFluid(int hash, FluidStack stack, @Nullable IStorageTracker.IStorageTrackerEntry entry, boolean craftable, boolean displayCraftText) {
|
||||
this.hash = hash;
|
||||
@@ -55,7 +57,20 @@ public class GridStackFluid implements IGridStack {
|
||||
|
||||
@Override
|
||||
public String getModId() {
|
||||
return stack.getFluid().getStill(stack).getNamespace();
|
||||
if (modId == null) {
|
||||
modId = stack.getFluid().getStill(stack).getNamespace();
|
||||
}
|
||||
|
||||
return modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModName() {
|
||||
if (modName == null) {
|
||||
modName = GridStackItem.getModNameByModId(getModId());
|
||||
}
|
||||
|
||||
return modName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -9,6 +9,8 @@ import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -24,6 +26,8 @@ public class GridStackItem implements IGridStack {
|
||||
private String[] oreIds = null;
|
||||
@Nullable
|
||||
private IStorageTracker.IStorageTrackerEntry entry;
|
||||
private String modId;
|
||||
private String modName;
|
||||
|
||||
public GridStackItem(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
@@ -41,6 +45,15 @@ public class GridStackItem implements IGridStack {
|
||||
}
|
||||
}
|
||||
|
||||
static String getModNameByModId(String modId) {
|
||||
ModContainer container = Loader.instance().getActiveModList().stream()
|
||||
.filter(m -> m.getModId().toLowerCase().equals(modId))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
return container == null ? modId : container.getName().toLowerCase().replace(" ", "");
|
||||
}
|
||||
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
@@ -84,7 +97,20 @@ public class GridStackItem implements IGridStack {
|
||||
|
||||
@Override
|
||||
public String getModId() {
|
||||
return stack.getItem().getCreatorModId(stack);
|
||||
if (modId == null) {
|
||||
modId = stack.getItem().getCreatorModId(stack);
|
||||
}
|
||||
|
||||
return modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModName() {
|
||||
if (modName == null) {
|
||||
modName = getModNameByModId(getModId());
|
||||
}
|
||||
|
||||
return modName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -12,6 +12,8 @@ public interface IGridStack {
|
||||
|
||||
String getModId();
|
||||
|
||||
String getModName();
|
||||
|
||||
String[] getOreIds();
|
||||
|
||||
String getTooltip();
|
||||
|
Reference in New Issue
Block a user