Skip to content

Commit

Permalink
Update APIs (#130)
Browse files Browse the repository at this point in the history
* Add an API to allow other mods to blacklist fluids from this mod.

* Removed Thaumic Energistics config setting. This will be handled by
Thaumic Energistic's side (which also happens to have a config setting).

* Added an API that allows for blacklisting fluids from either the storage
or the display individually.

* Prevent blacklisted fluids from being discretized

* Update API usage

- use AE2's new API

- use ThE's config setting for aspect -> gas

* spotlessApply

---------

Co-authored-by: GitHub GTNH Actions <unknown>
  • Loading branch information
firenoo authored May 20, 2023
1 parent 14853a2 commit f87b763
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 79 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

dependencies {
api('com.github.GTNewHorizons:NotEnoughItems:2.3.50-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-208-GTNH:dev')
api('com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-215-GTNH:dev')
api('curse.maven:cofh-core-69162:2388751')
api('com.github.GTNewHorizons:waila:1.6.0:dev')
api('com.github.GTNewHorizons:Baubles:1.0.1.16:dev')
Expand All @@ -16,7 +16,7 @@ dependencies {
compileOnly('thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev')
compileOnly('com.gregoriust.gregtech:gregtech_1.7.10:6.14.23:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:OpenComputers:1.9.5-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.4.1-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:ThaumicEnergistics:1.4.2-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:GTplusplus:1.9.4:dev') { transitive = false }
compileOnly("com.github.GTNewHorizons:Hodgepodge:2.2.10:dev") { transitive = false }
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gradleTokenGroupName = GRADLETOKEN_GROUPNAME
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
apiPackage =
apiPackage = api

# Specify the configuration file for Forge's access transformers here. I must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/glodblock/github/FluidCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void postInit(FMLPostInitializationEvent event) {
CalculatorV2PluginLoader.installCalculatorV2Plugins();
}
if (ModAndClassUtil.isTypeFilter) {
FluidFilter.installFilter();
AEApi.instance().registries().itemDisplay().addItemFilter(FluidFilter::filter);
}

proxy.postInit(event);
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/glodblock/github/api/FluidCraftAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.glodblock.github.api;

import java.util.HashSet;
import java.util.Set;

import net.minecraftforge.fluids.Fluid;

public final class FluidCraftAPI implements IFluidCraftAPI {

private static final FluidCraftAPI API = new FluidCraftAPI();

/**
* These fluids will not be allowed to be stored in fluid storage cells.
*/
private final Set<Class<? extends Fluid>> blacklistedFluids = new HashSet<>();

/**
* These fluids will not be displayed in a fluid terminal.
*/
private final Set<Class<? extends Fluid>> blacklistedDispFluids = new HashSet<>();

public static FluidCraftAPI instance() {
return API;
}

@Override
public void blacklistFluidInStorage(Class<? extends Fluid> fluid) {
blacklistedFluids.add(fluid);
}

@Override
public void blacklistFluidInDisplay(Class<? extends Fluid> fluid) {
blacklistedDispFluids.add(fluid);
}

@Override
public boolean isBlacklistedInStorage(Class<? extends Fluid> fluid) {
return blacklistedFluids.contains(fluid);
}

@Override
public boolean isBlacklistedInDisplay(Class<? extends Fluid> fluid) {
return blacklistedDispFluids.contains(fluid);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/glodblock/github/api/IFluidCraftAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.glodblock.github.api;

import net.minecraftforge.fluids.Fluid;

@SuppressWarnings("unused")
public interface IFluidCraftAPI {

/**
* Blacklisted fluids will not be allowed to be added to a storage cell.
*/
void blacklistFluidInStorage(Class<? extends Fluid> fluid);

/**
* Blacklisted fluids will not be displayed in fluid terminals.
*/
void blacklistFluidInDisplay(Class<? extends Fluid> fluid);

/**
* Mostly for internal use; queries whether the fluid is blacklisted from storage cells.
*/
boolean isBlacklistedInStorage(Class<? extends Fluid> fluid);

/**
* Mostly for internal use; queries whether the fluid is blacklisted from being displayed.
*/
boolean isBlacklistedInDisplay(Class<? extends Fluid> fluid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import appeng.api.storage.ITerminalHost;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IDisplayRepo;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigurableObject;
import appeng.client.gui.widgets.*;
import appeng.client.me.InternalSlotME;
import appeng.client.me.ItemRepo;
import appeng.client.me.SlotDisconnected;
import appeng.client.me.SlotME;
import appeng.container.AEBaseContainer;
Expand Down Expand Up @@ -67,7 +67,7 @@ public abstract class FCGuiMonitor<T extends IAEStack<T>> extends FCBaseMEGui
protected final ItemStack[] myCurrentViewCells = new ItemStack[5];
public FCContainerMonitor<T> monitorableContainer;
public GuiTabButton craftingStatusBtn;
protected ItemRepo repo;
protected IDisplayRepo repo;
protected GuiImgButton craftingStatusImgBtn;
protected FCGuiTextField searchField;
protected int perRow = 9;
Expand Down Expand Up @@ -649,7 +649,7 @@ protected void keyTyped(final char character, final int key) {

@Override
public void updateScreen() {
this.repo.setPower(this.monitorableContainer.isPowered());
this.repo.setPowered(this.monitorableContainer.isPowered());
super.updateScreen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ public void postChange(Iterable<IAEFluidStack> change, ItemStack fluidContainer,
if (slotIndex == -1) {
out.stackSize = fluidContainer.stackSize;
} else {
if (drainStack != null) {
System.out.print("---------\n");
System.out.print(drainStack.right + "\n");
System.out.print(drainStack.left + "\n");
System.out.print(aeFluidStack.getStackSize() + "\n");
}
out.stackSize = (int) (fluidContainer.stackSize
- (aeFluidStack.getStackSize() / drainStack.left));
}
Expand Down
87 changes: 86 additions & 1 deletion src/main/java/com/glodblock/github/client/me/EssentiaRepo.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package com.glodblock.github.client.me;

import java.util.Iterator;
import java.util.regex.Pattern;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.crossmod.thaumcraft.AspectUtil;
import com.glodblock.github.util.FluidSorters;

import appeng.api.config.SearchBoxMode;
import appeng.api.config.Settings;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.IScrollSource;
import appeng.client.gui.widgets.ISortSource;
import appeng.core.AEConfig;

public class EssentiaRepo extends FluidRepo {

Expand All @@ -21,7 +29,84 @@ public EssentiaRepo(final IScrollSource src, final ISortSource sortSrc) {

@Override
public void updateView() {
super.updateView();
this.view.clear();
this.dsp.clear();

this.view.ensureCapacity(this.list.size());
this.dsp.ensureCapacity(this.list.size());

final Enum<?> viewMode = this.sortSrc.getSortDisplay();
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) {
this.updateNEI(this.searchString);
}

String innerSearch = this.searchString;

if (innerSearch.startsWith("@")) {
innerSearch = innerSearch.substring(1);
}

Pattern m;
try {
m = Pattern.compile(innerSearch.toLowerCase(), Pattern.CASE_INSENSITIVE);
} catch (final Throwable ignore) {
try {
m = Pattern.compile(Pattern.quote(innerSearch.toLowerCase()), Pattern.CASE_INSENSITIVE);
} catch (final Throwable __) {
return;
}
}

for (IAEItemStack is : this.list) {
if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
}
}

if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
continue;
}

if (viewMode == ViewItems.CRAFTABLE) {
is = is.copy();
is.setStackSize(0);
}

if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
continue;
}

Fluid fluid = ItemFluidDrop.getAeFluidStack(is).getFluid();
if (!AspectUtil.isEssentiaGas(fluid)) {
continue;
}

if (m.matcher(fluid.getLocalizedName().toLowerCase()).find()) {
this.view.add(is);
}
}

final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}

for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
Iterator<IAEItemStack> it1 = this.view.iterator();
while (it1.hasNext()) {
IAEFluidStack fluid = ItemFluidDrop.getAeFluidStack(it1.next());
Expand Down
Loading

0 comments on commit f87b763

Please sign in to comment.