Skip to content

Commit

Permalink
make block mode check subnet contents
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Jul 5, 2024
1 parent 8a24812 commit be9a9a8
Showing 1 changed file with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.glodblock.github.inventory;

import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.parts.IPart;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.fluids.helper.DualityFluidInterface;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.helpers.DualityInterface;
Expand All @@ -20,7 +24,11 @@
import com.glodblock.github.integration.mek.FakeGases;
import com.glodblock.github.util.Ae2Reflect;
import com.glodblock.github.util.ModAndClassUtil;
import com.glodblock.github.util.Util;
import com.mekeng.github.common.me.data.IAEGasStack;
import com.mekeng.github.common.me.duality.IGasInterfaceHost;
import com.mekeng.github.common.me.duality.impl.DualityGasInterface;
import com.mekeng.github.common.me.storage.IGasStorageChannel;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTankInfo;
import mekanism.api.gas.IGasHandler;
Expand Down Expand Up @@ -364,25 +372,49 @@ public boolean containsItems() {
}
boolean checkFluid = blockMode != 1;
boolean checkItem = blockMode != 2;
if (invFluids != null && checkFluid) {

IFluidInterfaceHost fluidHost = getFluidInterfaceTE((TileEntity) facingTE, facing);
if (fluidHost != null && !isSameGrid(fluidHost) && checkFluid) {
DualityFluidInterface inter = fluidHost.getDualityFluidInterface();
IMEMonitor<IAEFluidStack> monitor = inter.getInventory(Util.getFluidChannel());
if (monitor != null && !monitor.getStorageList().isEmpty()) {
return true;
}
} else if (invFluids != null && checkFluid) {
for (IFluidTankProperties tank : invFluids.getTankProperties()) {
FluidStack fluid = tank.getContents();
if (fluid != null && fluid.amount > 0) {
return true;
}
}
}

/*yeah, gas is fluid*/
if (invGases != null && checkFluid) {
IGasHandler gasHandler = (IGasHandler) invGases;
for (GasTankInfo tank : gasHandler.getTankInfo()) {
GasStack gas = tank.getGas();
if (gas != null && gas.getGas() != null && gas.amount > 0) {
if (ModAndClassUtil.GAS) {
Object gasHost = getGasInterfaceTE((TileEntity) facingTE, facing);
if (gasHost != null && !isSameGrid(((IGasInterfaceHost) gasHost).getProxy()) && checkFluid) {
DualityGasInterface inter = ((IGasInterfaceHost) gasHost).getDualityGasInterface();
IMEMonitor<IAEGasStack> monitor = inter.getInventory(AEApi.instance().storage().getStorageChannel(IGasStorageChannel.class));
if (monitor != null && !monitor.getStorageList().isEmpty()) {
return true;
}
} else if (invGases != null && checkFluid) {
IGasHandler gasHandler = (IGasHandler) invGases;
for (GasTankInfo tank : gasHandler.getTankInfo()) {
GasStack gas = tank.getGas();
if (gas != null && gas.getGas() != null && gas.amount > 0) {
return true;
}
}
}
}
if (invItems != null && checkItem) {

IInterfaceHost itemHost = getInterfaceTE((TileEntity) facingTE, facing);
if (itemHost != null && !isSameGrid(itemHost) && checkItem) {
DualityInterface inter = itemHost.getInterfaceDuality();
IMEMonitor<IAEItemStack> monitor = inter.getInventory(Util.getItemChannel());
return monitor != null && !monitor.getStorageList().isEmpty();
} else if (invItems != null && checkItem) {
return invItems.containsItems();
}
return false;
Expand Down Expand Up @@ -420,6 +452,19 @@ protected static IFluidInterfaceHost getFluidInterfaceTE(TileEntity te, EnumFaci
return null;
}

@Nullable
protected static Object getGasInterfaceTE(TileEntity te, EnumFacing face) {
if (te instanceof IGasInterfaceHost) {
return te;
} else if (te instanceof TileCableBus) {
IPart part = ((TileCableBus) te).getPart(face.getOpposite());
if (part instanceof IGasInterfaceHost) {
return part;
}
}
return null;
}

protected static AENetworkProxy getGasInterfaceGrid(@Nullable TileEntity te, EnumFacing face) {
if (te instanceof IGasInterfaceHost) {
return Ae2Reflect.getGasInterfaceGrid(((IGasInterfaceHost) te).getDualityGasInterface());
Expand Down

0 comments on commit be9a9a8

Please sign in to comment.