mirror of
https://github.com/GTNewHorizons/GTNHLib.git
synced 2026-11-14 01:14:15 +00:00
Re-add IItemDuct support (includes EIO and BC) (#204)
Co-authored-by: Alexdoru <[email protected]>
This commit is contained in:
1 parent
d360191e8d
commit
48342d95bd
4 files changed
+64
-2
No files matched your search
+2
-1
@@ -31,5 +31,6 @@ dependencies {
|
||||
// For CapturingTesselator compat
|
||||
compileOnly("com.falsepattern:falsetweaks-mc1.7.10:3.8.4:api")
|
||||
|
||||
compileOnly('curse.maven:minefactory-reloaded-66672:2366150') { transitive = false }
|
||||
compileOnly(rfg.deobf('curse.maven:minefactory-reloaded-66672:2366150')) { transitive = false }
|
||||
compileOnly(rfg.deobf("curse.maven:cofh-core-69162:2388751")) { transitive = false }
|
||||
}
|
||||
@@ -26,6 +26,7 @@ public class GTNHLib {
|
||||
public static CommonProxy proxy;
|
||||
|
||||
public static boolean isMFRLoaded;
|
||||
public static boolean isCoFHCoreLoaded;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void construct(FMLConstructionEvent event) {
|
||||
@@ -35,6 +36,7 @@ public class GTNHLib {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
isMFRLoaded = Loader.isModLoaded("MineFactoryReloaded");
|
||||
isCoFHCoreLoaded = Loader.isModLoaded("CoFHCore");
|
||||
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.gtnewhorizon.gtnhlib.item.impl;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.gtnewhorizon.gtnhlib.GTNHLib;
|
||||
import com.gtnewhorizon.gtnhlib.capability.item.ItemSink;
|
||||
import com.gtnewhorizon.gtnhlib.item.ImmutableItemStack;
|
||||
|
||||
import cofh.api.transport.IItemDuct;
|
||||
|
||||
public class ItemDuctSink implements ItemSink {
|
||||
|
||||
public final IItemDuct itemDuct;
|
||||
private final ForgeDirection side;
|
||||
|
||||
public ItemDuctSink(IItemDuct itemDuct, ForgeDirection side) {
|
||||
this.itemDuct = itemDuct;
|
||||
this.side = side;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int store(ImmutableItemStack stack) {
|
||||
ItemStack rejected = itemDuct.insertItem(side, stack.toStack());
|
||||
|
||||
if (rejected == null) return 0;
|
||||
|
||||
if (!stack.matches(rejected)) {
|
||||
GTNHLib.LOG.error(
|
||||
"IItemDuct returned a rejected item that does not match what was inserted: deleting it to prevent dupes ({}x{})",
|
||||
rejected.stackSize,
|
||||
rejected.getDisplayName(),
|
||||
new Exception());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return rejected.stackSize;
|
||||
}
|
||||
}
|
||||
@@ -21,10 +21,12 @@ import com.gtnewhorizon.gtnhlib.capability.item.ItemSource;
|
||||
import com.gtnewhorizon.gtnhlib.item.InventoryItemSink;
|
||||
import com.gtnewhorizon.gtnhlib.item.InventoryItemSource;
|
||||
import com.gtnewhorizon.gtnhlib.item.WrappedItemIO;
|
||||
import com.gtnewhorizon.gtnhlib.item.impl.ItemDuctSink;
|
||||
import com.gtnewhorizon.gtnhlib.item.impl.mfr.DSUItemIO;
|
||||
import com.gtnewhorizon.gtnhlib.item.impl.mfr.DSUItemSink;
|
||||
import com.gtnewhorizon.gtnhlib.item.impl.mfr.DSUItemSource;
|
||||
|
||||
import cofh.api.transport.IItemDuct;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
|
||||
|
||||
@@ -36,7 +38,9 @@ public class ItemUtil {
|
||||
public static final int FOR_EXTRACTS = 0b1 << counter++;
|
||||
/// Create [ItemSink]s / [ItemSource]s for [IDeepStorageUnit]s.
|
||||
public static final int WRAP_DSUS = 0b1 << counter++;
|
||||
public static final int DEFAULT = WRAP_INVENTORIES | FOR_INSERTS | FOR_EXTRACTS | WRAP_DSUS;
|
||||
/// Create [ItemSink]s for [IItemDuct]s.
|
||||
public static final int WRAP_ITEM_DUCTS = 0b1 << counter++;
|
||||
public static final int DEFAULT = WRAP_INVENTORIES | FOR_INSERTS | FOR_EXTRACTS | WRAP_DSUS | WRAP_ITEM_DUCTS;
|
||||
|
||||
public static int getStackMeta(ItemStack stack) {
|
||||
return Items.feather.getDamage(stack);
|
||||
@@ -165,6 +169,12 @@ public class ItemUtil {
|
||||
if (sink != null) return sink;
|
||||
}
|
||||
|
||||
if ((usage & WRAP_ITEM_DUCTS) != 0 && GTNHLib.isCoFHCoreLoaded) {
|
||||
ItemSink sink = getDuctSink(obj, side);
|
||||
|
||||
if (sink != null) return sink;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -232,4 +242,13 @@ public class ItemUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "CoFHCore")
|
||||
private static ItemSink getDuctSink(Object obj, ForgeDirection side) {
|
||||
if (obj instanceof IItemDuct duct) {
|
||||
return new ItemDuctSink(duct, side);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user