Skip to content

Commit

Permalink
Merge pull request #103 from GTNewHorizons/feature/fluids
Browse files Browse the repository at this point in the history
Change fluid amount from int to long in AE2 integration
  • Loading branch information
repo-alt authored Jul 5, 2023
2 parents 0ab96aa + 6156c98 commit 3b3f4a4
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 12 deletions.
5 changes: 4 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:EnderStorage:1.4.12:dev") {
transitive = false
}
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.42.82:dev") {
compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.43.99:dev") {
transitive = false
}
compile("com.github.GTNewHorizons:ForestryMC:4.6.6:dev") {
Expand Down Expand Up @@ -55,6 +55,9 @@ dependencies {
compileOnly("com.github.GTNewHorizons:ExtraCells2:2.5.33:dev") {
transitive = false
}
compileOnly('com.github.GTNewHorizons:AE2FluidCraft-Rework:1.1.21-gtnh:dev') {
transitive = false
}
compile("com.github.GTNewHorizons:EnderCore:0.2.14:dev")
compile("com.github.GTNewHorizons:EnderIO:2.4.11:dev") {
transitive = false
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/li/cil/oc/integration/Mods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ object Mods {

def All = knownMods.clone()

val Ae2Fc = new SimpleMod(IDs.Ae2Fc)
val AgriCraft = new SimpleMod(IDs.AgriCraft, version = "@[1.4.0,)")
val AppliedEnergistics2 = new SimpleMod(IDs.AppliedEnergistics2, version = "@[rv1,)")
val AvaritiaAddons = new SimpleMod(IDs.AvaritiaAddons)
Expand Down Expand Up @@ -89,6 +90,7 @@ object Mods {

val Proxies = Array(
integration.agricraft.ModAgriCraft,
integration.ae2fc.ModAe2fc,
integration.appeng.ModAppEng,
integration.avaritiaaddons.ModAvaritiaAddons,
integration.betterrecords.ModBetterRecords,
Expand Down Expand Up @@ -168,6 +170,7 @@ object Mods {

object IDs {
final val AgriCraft = "AgriCraft"
final val Ae2Fc = "ae2fc"
final val AppliedEnergistics2 = "appliedenergistics2"
final val AvaritiaAddons = "avaritiaddons"
final val BattleGear2 = "battlegear2"
Expand Down
8 changes: 8 additions & 0 deletions src/main/scala/li/cil/oc/integration/ae2fc/Ae2FcUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package li.cil.oc.integration.ae2fc

import appeng.api.storage.data.IAEFluidStack
import com.glodblock.github.api.FluidCraftAPI

object Ae2FcUtil {
def canSeeFluidInNetwork(fluid: IAEFluidStack) = fluid != null && fluid.getFluid != null && !FluidCraftAPI.instance().isBlacklistedInDisplay(fluid.getFluid.getClass)
}
8 changes: 8 additions & 0 deletions src/main/scala/li/cil/oc/integration/ae2fc/ModAe2fc.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package li.cil.oc.integration.ae2fc

import li.cil.oc.integration.{Mod, ModProxy, Mods}

object ModAe2fc extends ModProxy {
override def getMod: Mod = Mods.Ae2Fc
override def initialize(): Unit = {}
}
36 changes: 26 additions & 10 deletions src/main/scala/li/cil/oc/integration/appeng/NetworkControl.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package li.cil.oc.integration.appeng

import java.lang

import appeng.api.AEApi
import appeng.api.config.Actionable
import appeng.api.networking.IGridNode
import appeng.api.networking.crafting.{CraftingItemList, ICraftingLink, ICraftingRequester}
import appeng.api.networking.security.{BaseActionSource, IActionHost, MachineSource}
import appeng.api.networking.storage.IBaseMonitor
import appeng.api.storage.IMEMonitorHandlerReceiver
import appeng.api.storage.data.{IAEItemStack, IItemList}
import appeng.api.storage.data.{IAEFluidStack, IAEItemStack, IItemList}
import appeng.api.util.AECableType
import appeng.me.cluster.implementations.CraftingCPUCluster
import appeng.me.helpers.IGridProxyable
Expand All @@ -24,6 +23,7 @@ import li.cil.oc.api.network.Node
import li.cil.oc.api.prefab.AbstractValue
import li.cil.oc.common.EventHandler
import li.cil.oc.integration.Mods
import li.cil.oc.integration.ae2fc.Ae2FcUtil
import li.cil.oc.integration.appeng.NetworkControl._
import li.cil.oc.integration.ec.ECUtil
import li.cil.oc.server.driver.Registry
Expand Down Expand Up @@ -119,11 +119,14 @@ trait NetworkControl[AETile >: Null <: TileEntity with IGridProxyable with IActi
})
}

private def isFluidVisible(stack: IAEFluidStack) =
if (Mods.ExtraCells.isAvailable) ECUtil.canSeeFluidInNetwork(stack)
else if (Mods.Ae2Fc.isAvailable) Ae2FcUtil.canSeeFluidInNetwork(stack)
else true

@Callback(doc = "function():table -- Get a list of the stored fluids in the network.")
def getFluidsInNetwork(context: Context, args: Arguments): Array[AnyRef] =
result(tile.getProxy.getStorage.getFluidInventory.getStorageList.filter(stack =>
!Mods.ExtraCells.isAvailable || ECUtil.canSeeFluidInNetwork(stack)).
map(_.getFluidStack).toArray)
result(tile.getProxy.getStorage.getFluidInventory.getStorageList.filter(isFluidVisible).map(fs => convert(fs, tile)).toArray)

@Callback(doc = "function():number -- Get the average power injection into the network.")
def getAvgPowerInjection(context: Context, args: Arguments): Array[AnyRef] =
Expand Down Expand Up @@ -472,12 +475,13 @@ object NetworkControl {
aeCraftItem(aeItem, tile)
}

def hashConvert(value: java.util.HashMap[_, _]) = {
val hash = new java.util.HashMap[String, AnyRef]
value.collect { case (k: String, v: AnyRef) => hash += k -> v }
hash
}

def convert(aeItem: IAEItemStack, tile: TileEntity with IGridProxyable): java.util.HashMap[String, AnyRef] = {
def hashConvert(value: java.util.HashMap[_, _]) = {
val hash = new java.util.HashMap[String, AnyRef]
value.collect{ case (k:String, v:AnyRef) => hash += k -> v }
hash
}
val potentialItem = aePotentialItem(aeItem, tile)
val result = Registry.convert(Array[AnyRef](potentialItem.getItemStack))
.collect { case hash: java.util.HashMap[_,_] => hashConvert(hash) }
Expand All @@ -492,6 +496,18 @@ object NetworkControl {
null
}

def convert(aeItem: IAEFluidStack, tile: TileEntity with IGridProxyable): java.util.HashMap[String, AnyRef] = {
val result = Registry.convert(Array[AnyRef](aeItem.getFluidStack))
.collect { case hash: java.util.HashMap[_, _] => hashConvert(hash) }
if (result.length > 0) {
val hash = result(0)
hash.update("amount", Long.box(aeItem.getStackSize))
hash.update("isCraftable", Boolean.box(aeItem.isCraftable))
return hash
}
null
}

private def loadController(nbt: NBTTagCompound, f : TileEntity with IGridProxyable with IActionHost => Unit ) : Unit = {
if (nbt.hasKey("dimension")) {
val dimension = nbt.getInteger("dimension")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object EventHandlerGregTech {
val world = e.host.world
world.getTileEntity(e.x, e.y, e.z) match {
case tile : IGregTechTileEntity =>
e.data += "facing" -> ForgeDirection.getOrientation(tile.getFrontFacing).name()
e.data += "facing" -> tile.getFrontFacing.name
e.data += "sensorInformation" -> tile.getInfoData()
case _ =>
}
Expand Down

0 comments on commit 3b3f4a4

Please sign in to comment.