mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-14 01:14:11 +00:00
AE API: Add a method to blacklist items/provide filters based on item/fluid (#322)
* AE API: Add a method to blacklist items/provide filters based on item/fluid. Items can now be added to the blacklist to prevent them from being shown. This does NOT blacklist them from being stored in storage cells (for the time being). While the type filters were previously implemented directly in ItemRepo, this commit adds them to the API. ItemRepo is now extracted as an interface, primarily for AE2FC and other add-ons. * Update buildscript
This commit is contained in:
1 parent
a99d8dffe9
commit
cc8b77e488
8 files changed
+175
-35
No files matched your search
+3
-3
@@ -1,4 +1,4 @@
|
||||
//version: 1683705740
|
||||
//version: 1684218858
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
Also, you may replace this file at any time if there is an update available.
|
||||
@@ -69,7 +69,7 @@ plugins {
|
||||
id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version
|
||||
id 'com.modrinth.minotaur' version '2.+' apply false
|
||||
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
|
||||
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.11'
|
||||
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.14'
|
||||
}
|
||||
|
||||
print("You might want to check out './gradlew :faq' if your build fails.\n")
|
||||
@@ -730,7 +730,7 @@ dependencies {
|
||||
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
|
||||
}
|
||||
if (modId != 'hodgepodge') {
|
||||
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.8')
|
||||
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.13')
|
||||
}
|
||||
|
||||
java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false}
|
||||
|
||||
@@ -17,6 +17,7 @@ import appeng.api.movable.IMovableRegistry;
|
||||
import appeng.api.networking.IGridCacheRegistry;
|
||||
import appeng.api.storage.ICellRegistry;
|
||||
import appeng.api.storage.IExternalStorageRegistry;
|
||||
import appeng.api.storage.IItemDisplayRegistry;
|
||||
|
||||
/**
|
||||
* @author AlgorithmX2
|
||||
@@ -57,6 +58,11 @@ public interface IRegistryContainer {
|
||||
*/
|
||||
ICellRegistry cell();
|
||||
|
||||
/**
|
||||
* Allows you to register items to be blacklisted from item terminals.
|
||||
*/
|
||||
IItemDisplayRegistry itemDisplay();
|
||||
|
||||
/**
|
||||
* Manage grinder recipes via API
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package appeng.api.storage;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.config.TypeFilter;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* API for item display repo.
|
||||
*/
|
||||
public interface IItemDisplayRegistry {
|
||||
|
||||
/**
|
||||
* Blacklist the specified item from the item terminals from being displayed in item terminals.
|
||||
*/
|
||||
void blacklistItemDisplay(Item item);
|
||||
|
||||
/**
|
||||
* Blacklist the specified item class from being displayed in item terminals. Note that all instances of this class
|
||||
* are blacklisted.
|
||||
*/
|
||||
void blacklistItemDisplay(Class<? extends Item> item);
|
||||
|
||||
boolean isBlacklisted(Item item);
|
||||
|
||||
boolean isBlacklisted(Class<? extends Item> item);
|
||||
|
||||
/**
|
||||
* Adds a filter option. This is primarily for ae2fc's item drops, but can be expanded.
|
||||
*/
|
||||
void addItemFilter(BiPredicate<TypeFilter, IAEItemStack> filter);
|
||||
|
||||
List<BiPredicate<TypeFilter, IAEItemStack>> getItemFilters();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package appeng.api.storage.data;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Used to display and filter items shown.
|
||||
*/
|
||||
public interface IDisplayRepo {
|
||||
|
||||
void postUpdate(final IAEItemStack stack);
|
||||
|
||||
void setViewCell(final ItemStack[] filters);
|
||||
|
||||
ItemStack getItem(int idx);
|
||||
|
||||
void updateView();
|
||||
|
||||
int size();
|
||||
|
||||
void clear();
|
||||
|
||||
boolean hasPower();
|
||||
|
||||
void setPowered(final boolean hasPower);
|
||||
|
||||
int getRowSize();
|
||||
|
||||
void setRowSize(final int rowSize);
|
||||
|
||||
String getSearchString();
|
||||
|
||||
void setSearchString(@Nonnull final String searchString);
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.implementations.guiobjects.IPortableCell;
|
||||
import appeng.api.implementations.tiles.IMEChest;
|
||||
@@ -265,7 +266,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
||||
this.configSrc.getSetting(Settings.VIEW_MODE)));
|
||||
offset += 20;
|
||||
}
|
||||
if (ItemRepo.getFilter().containsKey(TypeFilter.FLUIDS)) {
|
||||
if (!AEApi.instance().registries().itemDisplay().getItemFilters().isEmpty()) {
|
||||
this.buttonList.add(
|
||||
this.typeFilter = new GuiImgButton(
|
||||
this.guiLeft - 18,
|
||||
@@ -512,7 +513,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
this.repo.setPower(this.monitorableContainer.isPowered());
|
||||
this.repo.setPowered(this.monitorableContainer.isPowered());
|
||||
super.updateScreen();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,13 +21,11 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.storage.IItemDisplayRegistry;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IDisplayRepo;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.gui.widgets.IScrollSource;
|
||||
import appeng.client.gui.widgets.ISortSource;
|
||||
@@ -40,7 +38,7 @@ import appeng.util.item.OreReference;
|
||||
import appeng.util.prioitylist.IPartitionList;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
|
||||
public class ItemRepo {
|
||||
public class ItemRepo implements IDisplayRepo {
|
||||
|
||||
private final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
private final ArrayList<IAEItemStack> view = new ArrayList<>();
|
||||
@@ -52,20 +50,8 @@ public class ItemRepo {
|
||||
|
||||
private String searchString = "";
|
||||
private IPartitionList<IAEItemStack> myPartitionList;
|
||||
private String innerSearch = "";
|
||||
private String NEIWord = null;
|
||||
private boolean hasPower;
|
||||
private static final ListMultimap<Enum<TypeFilter>, BiPredicate<IAEStack<?>, TypeFilter>> filters = ArrayListMultimap
|
||||
.create(4, 8);
|
||||
|
||||
public static <StackType extends IAEStack<StackType>> void registerTypeHandler(
|
||||
BiPredicate<IAEStack<?>, TypeFilter> filter, TypeFilter type) {
|
||||
filters.put(type, filter);
|
||||
}
|
||||
|
||||
public static ListMultimap<Enum<TypeFilter>, BiPredicate<IAEStack<?>, TypeFilter>> getFilter() {
|
||||
return filters;
|
||||
}
|
||||
|
||||
public ItemRepo(final IScrollSource src, final ISortSource sortSrc) {
|
||||
this.src = src;
|
||||
@@ -81,6 +67,7 @@ public class ItemRepo {
|
||||
return this.view.get(idx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(int idx) {
|
||||
idx += this.src.getCurrentScroll() * this.rowSize;
|
||||
|
||||
@@ -90,10 +77,7 @@ public class ItemRepo {
|
||||
return this.dsp.get(idx);
|
||||
}
|
||||
|
||||
void setSearch(final String search) {
|
||||
this.searchString = search == null ? "" : search;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postUpdate(final IAEItemStack is) {
|
||||
final IAEItemStack st = this.list.findPrecise(is);
|
||||
|
||||
@@ -105,11 +89,13 @@ public class ItemRepo {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setViewCell(final ItemStack[] list) {
|
||||
this.myPartitionList = ItemViewCell.createFilter(list);
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateView() {
|
||||
this.view.clear();
|
||||
this.dsp.clear();
|
||||
@@ -124,39 +110,43 @@ public class ItemRepo {
|
||||
this.updateNEI(this.searchString);
|
||||
}
|
||||
|
||||
this.innerSearch = this.searchString;
|
||||
String innerSearch = this.searchString;
|
||||
// final boolean terminalSearchToolTips =
|
||||
// AEConfig.instance.settings.getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO;
|
||||
// boolean terminalSearchMods = Configuration.INSTANCE.settings.getSetting( Settings.SEARCH_MODS ) != YesNo.NO;
|
||||
final SearchMode searchWhat;
|
||||
if (this.innerSearch.length() == 0) {
|
||||
if (innerSearch.length() == 0) {
|
||||
searchWhat = SearchMode.ITEM;
|
||||
} else {
|
||||
searchWhat = switch (this.innerSearch.substring(0, 1)) {
|
||||
searchWhat = switch (innerSearch.substring(0, 1)) {
|
||||
case "#" -> SearchMode.TOOLTIPS;
|
||||
case "@" -> SearchMode.MOD;
|
||||
case "$" -> SearchMode.ORE;
|
||||
default -> SearchMode.ITEM;
|
||||
};
|
||||
if (searchWhat != SearchMode.ITEM) this.innerSearch = this.innerSearch.substring(1);
|
||||
if (searchWhat != SearchMode.ITEM) innerSearch = innerSearch.substring(1);
|
||||
}
|
||||
Pattern m = null;
|
||||
try {
|
||||
m = Pattern.compile(this.innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE);
|
||||
m = Pattern.compile(innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE);
|
||||
} catch (final Throwable ignore) {
|
||||
try {
|
||||
m = Pattern.compile(Pattern.quote(this.innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE);
|
||||
m = Pattern.compile(Pattern.quote(innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE);
|
||||
} catch (final Throwable __) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
IItemDisplayRegistry registry = AEApi.instance().registries().itemDisplay();
|
||||
|
||||
boolean notDone = false;
|
||||
out: for (IAEItemStack is : this.list) {
|
||||
// filter AEStack type
|
||||
IAEItemStack finalIs = is;
|
||||
for (final BiPredicate<IAEStack<?>, TypeFilter> filter : filters.values()) {
|
||||
if (!filter.test(finalIs, (TypeFilter) typeFilter)) continue out;
|
||||
if (registry.isBlacklisted(finalIs.getItem()) || registry.isBlacklisted(finalIs.getItem().getClass())) {
|
||||
continue;
|
||||
}
|
||||
for (final BiPredicate<TypeFilter, IAEItemStack> filter : registry.getItemFilters()) {
|
||||
if (!filter.test((TypeFilter) typeFilter, is)) continue out;
|
||||
}
|
||||
if (this.myPartitionList != null) {
|
||||
if (!this.myPartitionList.isListed(is)) {
|
||||
@@ -254,34 +244,42 @@ public class ItemRepo {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.view.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.list.resetStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPower() {
|
||||
return this.hasPower;
|
||||
}
|
||||
|
||||
public void setPower(final boolean hasPower) {
|
||||
@Override
|
||||
public void setPowered(final boolean hasPower) {
|
||||
this.hasPower = hasPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowSize() {
|
||||
return this.rowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRowSize(final int rowSize) {
|
||||
this.rowSize = rowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSearchString() {
|
||||
return this.searchString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSearchString(@Nonnull final String searchString) {
|
||||
this.searchString = searchString;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package appeng.core.features.registries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.config.TypeFilter;
|
||||
import appeng.api.storage.IItemDisplayRegistry;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public final class ItemDisplayRegistry implements IItemDisplayRegistry {
|
||||
|
||||
private final Set<Class<? extends Item>> blacklistedItemClasses;
|
||||
private final Set<Item> blacklistedItems;
|
||||
private final List<BiPredicate<TypeFilter, IAEItemStack>> itemFilters;
|
||||
|
||||
public ItemDisplayRegistry() {
|
||||
this.blacklistedItemClasses = new HashSet<>();
|
||||
this.blacklistedItems = new HashSet<>();
|
||||
this.itemFilters = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blacklistItemDisplay(Item item) {
|
||||
this.blacklistedItems.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void blacklistItemDisplay(Class<? extends Item> item) {
|
||||
this.blacklistedItemClasses.add(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlacklisted(Item item) {
|
||||
return blacklistedItems.contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlacklisted(Class<? extends Item> item) {
|
||||
return blacklistedItemClasses.contains(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addItemFilter(BiPredicate<TypeFilter, IAEItemStack> filter) {
|
||||
this.itemFilters.add(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BiPredicate<TypeFilter, IAEItemStack>> getItemFilters() {
|
||||
return itemFilters;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import appeng.api.movable.IMovableRegistry;
|
||||
import appeng.api.networking.IGridCacheRegistry;
|
||||
import appeng.api.storage.ICellRegistry;
|
||||
import appeng.api.storage.IExternalStorageRegistry;
|
||||
import appeng.api.storage.IItemDisplayRegistry;
|
||||
|
||||
/**
|
||||
* represents all registries
|
||||
@@ -30,6 +31,7 @@ public class RegistryContainer implements IRegistryContainer {
|
||||
private final IInscriberRegistry inscriber = new InscriberRegistry();
|
||||
private final IExternalStorageRegistry storage = new ExternalStorageRegistry();
|
||||
private final ICellRegistry cell = new CellRegistry();
|
||||
private final IItemDisplayRegistry itemDisplay = new ItemDisplayRegistry();
|
||||
private final ILocatableRegistry locatable = new LocatableRegistry();
|
||||
private final ISpecialComparisonRegistry comparison = new SpecialComparisonRegistry();
|
||||
private final IWirelessTermRegistry wireless = new WirelessRegistry();
|
||||
@@ -70,6 +72,11 @@ public class RegistryContainer implements IRegistryContainer {
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDisplayRegistry itemDisplay() {
|
||||
return itemDisplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRegistry grinder() {
|
||||
return this.grinder;
|
||||
|
||||
Reference in new issue
Block a user