Skip to content

Commit be9a9a8

Browse files
committed
make block mode check subnet contents
1 parent 8a24812 commit be9a9a8

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

src/main/java/com/glodblock/github/inventory/FluidConvertingInventoryAdaptor.java

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package com.glodblock.github.inventory;
22

3+
import appeng.api.AEApi;
34
import appeng.api.config.FuzzyMode;
45
import appeng.api.parts.IPart;
6+
import appeng.api.storage.IMEMonitor;
7+
import appeng.api.storage.data.IAEFluidStack;
8+
import appeng.api.storage.data.IAEItemStack;
59
import appeng.fluids.helper.DualityFluidInterface;
610
import appeng.fluids.helper.IFluidInterfaceHost;
711
import appeng.helpers.DualityInterface;
@@ -20,7 +24,11 @@
2024
import com.glodblock.github.integration.mek.FakeGases;
2125
import com.glodblock.github.util.Ae2Reflect;
2226
import com.glodblock.github.util.ModAndClassUtil;
27+
import com.glodblock.github.util.Util;
28+
import com.mekeng.github.common.me.data.IAEGasStack;
2329
import com.mekeng.github.common.me.duality.IGasInterfaceHost;
30+
import com.mekeng.github.common.me.duality.impl.DualityGasInterface;
31+
import com.mekeng.github.common.me.storage.IGasStorageChannel;
2432
import mekanism.api.gas.GasStack;
2533
import mekanism.api.gas.GasTankInfo;
2634
import mekanism.api.gas.IGasHandler;
@@ -364,25 +372,49 @@ public boolean containsItems() {
364372
}
365373
boolean checkFluid = blockMode != 1;
366374
boolean checkItem = blockMode != 2;
367-
if (invFluids != null && checkFluid) {
375+
376+
IFluidInterfaceHost fluidHost = getFluidInterfaceTE((TileEntity) facingTE, facing);
377+
if (fluidHost != null && !isSameGrid(fluidHost) && checkFluid) {
378+
DualityFluidInterface inter = fluidHost.getDualityFluidInterface();
379+
IMEMonitor<IAEFluidStack> monitor = inter.getInventory(Util.getFluidChannel());
380+
if (monitor != null && !monitor.getStorageList().isEmpty()) {
381+
return true;
382+
}
383+
} else if (invFluids != null && checkFluid) {
368384
for (IFluidTankProperties tank : invFluids.getTankProperties()) {
369385
FluidStack fluid = tank.getContents();
370386
if (fluid != null && fluid.amount > 0) {
371387
return true;
372388
}
373389
}
374390
}
391+
375392
/*yeah, gas is fluid*/
376-
if (invGases != null && checkFluid) {
377-
IGasHandler gasHandler = (IGasHandler) invGases;
378-
for (GasTankInfo tank : gasHandler.getTankInfo()) {
379-
GasStack gas = tank.getGas();
380-
if (gas != null && gas.getGas() != null && gas.amount > 0) {
393+
if (ModAndClassUtil.GAS) {
394+
Object gasHost = getGasInterfaceTE((TileEntity) facingTE, facing);
395+
if (gasHost != null && !isSameGrid(((IGasInterfaceHost) gasHost).getProxy()) && checkFluid) {
396+
DualityGasInterface inter = ((IGasInterfaceHost) gasHost).getDualityGasInterface();
397+
IMEMonitor<IAEGasStack> monitor = inter.getInventory(AEApi.instance().storage().getStorageChannel(IGasStorageChannel.class));
398+
if (monitor != null && !monitor.getStorageList().isEmpty()) {
381399
return true;
382400
}
401+
} else if (invGases != null && checkFluid) {
402+
IGasHandler gasHandler = (IGasHandler) invGases;
403+
for (GasTankInfo tank : gasHandler.getTankInfo()) {
404+
GasStack gas = tank.getGas();
405+
if (gas != null && gas.getGas() != null && gas.amount > 0) {
406+
return true;
407+
}
408+
}
383409
}
384410
}
385-
if (invItems != null && checkItem) {
411+
412+
IInterfaceHost itemHost = getInterfaceTE((TileEntity) facingTE, facing);
413+
if (itemHost != null && !isSameGrid(itemHost) && checkItem) {
414+
DualityInterface inter = itemHost.getInterfaceDuality();
415+
IMEMonitor<IAEItemStack> monitor = inter.getInventory(Util.getItemChannel());
416+
return monitor != null && !monitor.getStorageList().isEmpty();
417+
} else if (invItems != null && checkItem) {
386418
return invItems.containsItems();
387419
}
388420
return false;
@@ -420,6 +452,19 @@ protected static IFluidInterfaceHost getFluidInterfaceTE(TileEntity te, EnumFaci
420452
return null;
421453
}
422454

455+
@Nullable
456+
protected static Object getGasInterfaceTE(TileEntity te, EnumFacing face) {
457+
if (te instanceof IGasInterfaceHost) {
458+
return te;
459+
} else if (te instanceof TileCableBus) {
460+
IPart part = ((TileCableBus) te).getPart(face.getOpposite());
461+
if (part instanceof IGasInterfaceHost) {
462+
return part;
463+
}
464+
}
465+
return null;
466+
}
467+
423468
protected static AENetworkProxy getGasInterfaceGrid(@Nullable TileEntity te, EnumFacing face) {
424469
if (te instanceof IGasInterfaceHost) {
425470
return Ae2Reflect.getGasInterfaceGrid(((IGasInterfaceHost) te).getDualityGasInterface());

0 commit comments

Comments
 (0)