Skip to content

Commit

Permalink
fc terminal add type filter (#98)
Browse files Browse the repository at this point in the history
* fc terminal add type filter

* Update dependencies.gradle

---------

Co-authored-by: Raven Szewczyk <[email protected]>
  • Loading branch information
asdflj and eigenraven authored Mar 12, 2023
1 parent c92f8bd commit b9724d9
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

dependencies {
compile('com.github.GTNewHorizons:NotEnoughItems:2.3.32-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-171-GTNH:dev')
compile('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-176-GTNH:dev')
compile('curse.maven:cofh-core-69162:2388751')
compile('com.github.GTNewHorizons:waila:1.5.22:dev')
compileOnly('com.github.GTNewHorizons:ExtraCells2:2.5.32:dev') { transitive = false }
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/glodblock/github/FluidCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.glodblock.github.loader.ChannelLoader;
import com.glodblock.github.loader.ItemAndBlockHolder;
import com.glodblock.github.loader.RecipeLoader;
import com.glodblock.github.loader.filter.FluidFilter;
import com.glodblock.github.proxy.CommonProxy;
import com.glodblock.github.util.ModAndClassUtil;

Expand Down Expand Up @@ -77,6 +78,9 @@ public static void postInit(FMLPostInitializationEvent event) {
if (ModAndClassUtil.isV2) {
CalculatorV2PluginLoader.installCalculatorV2Plugins();
}
if (ModAndClassUtil.isTypeFilter) {
FluidFilter.installFilter();
}

proxy.postInit(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
protected GuiImgButton searchBoxSettings;
protected GuiImgButton terminalStyleBox;
protected GuiImgButton searchStringSave;
protected GuiImgButton typeFilter;

@SuppressWarnings("unchecked")
public FCGuiMonitor(final InventoryPlayer inventoryPlayer, final ITerminalHost te, final FCContainerMonitor<T> c) {
Expand Down Expand Up @@ -228,6 +229,15 @@ public void initGui() {
this.configSrc.getSetting(Settings.VIEW_MODE)));
this.offsetY += 20;
}
if (ModAndClassUtil.isTypeFilter && this instanceof GuiItemMonitor) {
this.buttonList.add(
this.typeFilter = new GuiImgButton(
this.guiLeft - 18,
this.offsetY,
Settings.TYPE_FILTER,
this.configSrc.getSetting(Settings.TYPE_FILTER)));
this.offsetY += 20;
}

this.buttonList.add(
this.SortDirBox = new GuiImgButton(
Expand Down Expand Up @@ -658,6 +668,11 @@ public Enum<?> getSortDisplay() {
return this.configSrc.getSetting(Settings.VIEW_MODE);
}

@Override
public Enum getTypeFilter() {
return this.configSrc.getSetting(Settings.TYPE_FILTER);
}

@Override
public void updateSetting(final IConfigManager manager, final Enum settingName, final Enum newValue) {
if (this.SortByBox != null) {
Expand All @@ -671,6 +686,9 @@ public void updateSetting(final IConfigManager manager, final Enum settingName,
if (this.ViewBox != null) {
this.ViewBox.set(this.configSrc.getSetting(Settings.VIEW_MODE));
}
if (this.typeFilter != null) {
this.typeFilter.set(this.configSrc.getSetting(Settings.TYPE_FILTER));
}

this.repo.updateView();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected FCContainerMonitor(final InventoryPlayer ip, final ITerminalHost monit
this.clientCM.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.clientCM.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.clientCM.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.clientCM.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
}

public IMEMonitor<T> getMonitor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected FCPart(final ItemStack is, final boolean requireChannel) {
this.cm.registerSetting(Settings.SORT_BY, SortOrder.NAME);
this.cm.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
this.cm.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
this.cm.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
}

@MENetworkEventSubscribe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public IConfigManager getConfigManager() {
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public IConfigManager getConfigManager() {
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
this.readFromNBT();
return out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public IConfigManager getConfigManager() {
out.registerSetting(Settings.SORT_BY, SortOrder.NAME);
out.registerSetting(Settings.VIEW_MODE, ViewItems.ALL);
out.registerSetting(Settings.SORT_DIRECTION, SortDir.ASCENDING);
out.registerSetting(Settings.TYPE_FILTER, TypeFilter.ALL);
out.readFromNBT((NBTTagCompound) Platform.openNbtData(this.target).copy());
this.readFromNBT();
return out;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/com/glodblock/github/loader/filter/FluidFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.glodblock.github.loader.filter;

import static appeng.api.config.TypeFilter.*;

import net.minecraft.item.Item;

import appeng.api.config.TypeFilter;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.client.me.ItemRepo;

import com.glodblock.github.common.item.ItemFluidDrop;

public class FluidFilter {

public static void installFilter() {
ItemRepo.registerTypeHandler(FluidFilter::filter, FLUIDS);
}

private static boolean filter(IAEStack<?> stack, TypeFilter typeFilter) {
if (stack instanceof IAEItemStack) {
Item item = ((IAEItemStack) stack).getItem();
if (item != null) {
switch (typeFilter) {
case ITEMS:
return !(item instanceof ItemFluidDrop);
case FLUIDS:
return item instanceof ItemFluidDrop;
}
}
}
return true;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/glodblock/github/util/ModAndClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public final class ModAndClassUtil {
public static boolean WAILA = false;
public static boolean AVARITIA = false;
public static boolean isV2;
public static boolean isTypeFilter;
public static boolean isDoubleButton;
public static boolean isSaveText;
public static boolean isSearchStringTooltip;
Expand Down Expand Up @@ -111,6 +112,13 @@ public static void init() {
} catch (ClassNotFoundException e) {
isV2 = false;
}
try {
Field filters = Class.forName("appeng.client.me.ItemRepo").getDeclaredField("filters");
if (filters == null) isTypeFilter = false;
isTypeFilter = true;
} catch (ClassNotFoundException | NoSuchFieldException e) {
isTypeFilter = false;
}

try {
essentiaGas = Class.forName("thaumicenergistics.common.fluids.GaseousEssentia");
Expand Down

0 comments on commit b9724d9

Please sign in to comment.