diff --git a/build.gradle b/build.gradle index 6c40c253d..5a42b5f34 100644 --- a/build.gradle +++ b/build.gradle @@ -239,6 +239,7 @@ idea.module.scopes.PROVIDED.plus += [configurations.provided] sourceSets { main { scala { + exclude 'li/cil/oc/integration/agricraft/**' exclude 'li/cil/oc/integration/appeng/**' exclude 'li/cil/oc/integration/bloodmagic/**' exclude 'li/cil/oc/integration/bluepower/**' diff --git a/src/main/scala/li/cil/oc/integration/Mods.scala b/src/main/scala/li/cil/oc/integration/Mods.scala index 6d7499453..292770682 100644 --- a/src/main/scala/li/cil/oc/integration/Mods.scala +++ b/src/main/scala/li/cil/oc/integration/Mods.scala @@ -19,6 +19,7 @@ object Mods { def All = knownMods.clone() + val AgriCraft = new SimpleMod(IDs.AgriCraft, version = "@[1.4.0,)") val AppliedEnergistics2 = new SimpleMod(IDs.AppliedEnergistics2, version = "@[rv1,)", providesPower = true) val BattleGear2 = new SimpleMod(IDs.BattleGear2) val BetterRecords = new SimpleMod(IDs.BetterRecords) @@ -85,6 +86,7 @@ object Mods { // ----------------------------------------------------------------------- // val Proxies = Array( + // integration.agricraft.ModAgriCraft, // integration.appeng.ModAppEng, // integration.betterrecords.ModBetterRecords, // integration.bloodmagic.ModBloodMagic, @@ -157,6 +159,7 @@ object Mods { // ----------------------------------------------------------------------- // object IDs { + final val AgriCraft = "AgriCraft" final val AppliedEnergistics2 = "appliedenergistics2" final val BattleGear2 = "battlegear2" final val BetterRecords = "betterrecords" diff --git a/src/main/scala/li/cil/oc/integration/agricraft/ApiHandler.scala b/src/main/scala/li/cil/oc/integration/agricraft/ApiHandler.scala new file mode 100644 index 000000000..03d5b3bc3 --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/agricraft/ApiHandler.scala @@ -0,0 +1,17 @@ +package li.cil.oc.integration.agricraft + +import com.InfinityRaider.AgriCraft + +object ApiHandler { + lazy val Api = AgriCraft.api.API.getAPI(1) match { + case api: AgriCraft.api.v1.APIv1 if isApiUsable(api) => Option(api) + case _ => None + } + + private def isApiUsable(api: AgriCraft.api.APIBase) = { + val status = api.getStatus + status == AgriCraft.api.APIStatus.OK || + status == AgriCraft.api.APIStatus.BACKLEVEL_OK || + status == AgriCraft.api.APIStatus.BACKLEVEL_LIMITED + } +} diff --git a/src/main/scala/li/cil/oc/integration/agricraft/ConverterSeeds.scala b/src/main/scala/li/cil/oc/integration/agricraft/ConverterSeeds.scala new file mode 100644 index 000000000..e6b4c5a4d --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/agricraft/ConverterSeeds.scala @@ -0,0 +1,31 @@ +package li.cil.oc.integration.agricraft + +import java.util + +import com.InfinityRaider.AgriCraft.api.v1.ISeedStats +import li.cil.oc.api.driver.Converter +import net.minecraft.item.ItemStack + +import scala.collection.convert.WrapAsScala._ + +object ConverterSeeds extends Converter { + override def convert(value: scala.Any, output: util.Map[AnyRef, AnyRef]): Unit = { + value match { + case stack: ItemStack => ApiHandler.Api.foreach(api => { + if (api.isHandledByAgricraft(stack) && stack.hasTagCompound && stack.getTagCompound.getBoolean("analyzed")) api.getSeedStats(stack) match { + case stats: ISeedStats => + output += "agricraft" -> Map( + "gain" -> float2Float(stats.getGain), + "maxGain" -> float2Float(stats.getMaxGain), + "growth" -> float2Float(stats.getGrowth), + "maxGrowth" -> float2Float(stats.getMaxGrowth), + "strength" -> float2Float(stats.getStrength), + "maxStrength" -> float2Float(stats.getMaxStrength) + ) + case _ => + } + }) + case _ => + } + } +} diff --git a/src/main/scala/li/cil/oc/integration/agricraft/EventHandlerAgriCraft.scala b/src/main/scala/li/cil/oc/integration/agricraft/EventHandlerAgriCraft.scala new file mode 100644 index 000000000..5dc941772 --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/agricraft/EventHandlerAgriCraft.scala @@ -0,0 +1,31 @@ +package li.cil.oc.integration.agricraft + +import com.InfinityRaider.AgriCraft.api.v1.ISeedStats +import cpw.mods.fml.common.eventhandler.SubscribeEvent +import li.cil.oc.api.event.GeolyzerEvent + +import scala.collection.convert.WrapAsScala._ + +object EventHandlerAgriCraft { + @SubscribeEvent + def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) { + val world = e.host.world + + ApiHandler.Api.foreach(api => if (api.isCrops(world, e.x, e.y, e.z)) { + e.data += "growth" -> float2Float(if (api.isMature(world, e.x, e.y, e.z)) 1f else 0f) + + if (api.isAnalyzed(world, e.x, e.y, e.z)) { + api.getStats(world, e.x, e.y, e.z) match { + case stats: ISeedStats => + e.data += "gain" -> float2Float(stats.getGain) + e.data += "maxGain" -> float2Float(stats.getMaxGain) + e.data += "growth" -> float2Float(stats.getGrowth) + e.data += "maxGrowth" -> float2Float(stats.getMaxGrowth) + e.data += "strength" -> float2Float(stats.getStrength) + e.data += "maxStrength" -> float2Float(stats.getMaxStrength) + case _ => // Invalid crop. + } + } + }) + } +} diff --git a/src/main/scala/li/cil/oc/integration/agricraft/ModAgriCraft.scala b/src/main/scala/li/cil/oc/integration/agricraft/ModAgriCraft.scala new file mode 100644 index 000000000..f3325428f --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/agricraft/ModAgriCraft.scala @@ -0,0 +1,17 @@ +package li.cil.oc.integration.agricraft + +import li.cil.oc.api.Driver +import li.cil.oc.integration.Mod +import li.cil.oc.integration.ModProxy +import li.cil.oc.integration.Mods +import net.minecraftforge.common.MinecraftForge + +object ModAgriCraft extends ModProxy { + override def getMod: Mod = Mods.AgriCraft + + override def initialize(): Unit = { + Driver.add(ConverterSeeds) + + MinecraftForge.EVENT_BUS.register(EventHandlerAgriCraft) + } +} diff --git a/src/main/scala/li/cil/oc/integration/vanilla/EventHandlerVanilla.scala b/src/main/scala/li/cil/oc/integration/vanilla/EventHandlerVanilla.scala new file mode 100644 index 000000000..60ff823af --- /dev/null +++ b/src/main/scala/li/cil/oc/integration/vanilla/EventHandlerVanilla.scala @@ -0,0 +1,29 @@ +package li.cil.oc.integration.vanilla + +import li.cil.oc.api.event.GeolyzerEvent +import net.minecraft.block.BlockCrops +import net.minecraft.init.Blocks +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +import scala.collection.convert.WrapAsScala._ + +object EventHandlerVanilla { + @SubscribeEvent + def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) { + val world = e.host.world + val blockState = world.getBlockState(e.pos) + val block = blockState.getBlock + if (block.isInstanceOf[BlockCrops] || block == Blocks.melon_stem || block == Blocks.pumpkin_stem || block == Blocks.carrots || block == Blocks.potatoes) { + e.data += "growth" -> float2Float((block.getMetaFromState(blockState) / 7f) max 0 min 1) + } + if (block == Blocks.cocoa) { + e.data += "growth" -> float2Float(((block.getMetaFromState(blockState) >> 2) / 2f) max 0 min 1) + } + if (block == Blocks.nether_wart) { + e.data += "growth" -> float2Float((block.getMetaFromState(blockState) / 3f) max 0 min 1) + } + if (block == Blocks.melon_block || block == Blocks.pumpkin || block == Blocks.cactus || block == Blocks.reeds) { + e.data += "growth" -> float2Float(1f) + } + } +} diff --git a/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala b/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala index 5b7b97b5f..c95903413 100644 --- a/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala +++ b/src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala @@ -11,6 +11,7 @@ import li.cil.oc.util.ExtendedWorld._ import net.minecraft.block.BlockRedstoneWire import net.minecraft.init.Blocks import net.minecraft.util.EnumFacing +import net.minecraftforge.common.MinecraftForge object ModVanilla extends ModProxy with RedstoneProvider { def getMod = Mods.Minecraft @@ -45,6 +46,8 @@ object ModVanilla extends ModProxy with RedstoneProvider { RecipeHandler.init() BundledRedstone.addProvider(this) + + MinecraftForge.EVENT_BUS.register(EventHandlerVanilla) } override def computeInput(pos: BlockPosition, side: EnumFacing): Int = { diff --git a/src/main/scala/li/cil/oc/util/InventoryUtils.scala b/src/main/scala/li/cil/oc/util/InventoryUtils.scala index 7af9182b5..ff2936839 100644 --- a/src/main/scala/li/cil/oc/util/InventoryUtils.scala +++ b/src/main/scala/li/cil/oc/util/InventoryUtils.scala @@ -155,7 +155,10 @@ object InventoryUtils { (stack != null && limit > 0) && { var success = false var remaining = limit - val range = slots.getOrElse(0 until inventory.getSizeInventory) + val range = slots.getOrElse(inventory match { + case sided: ISidedInventory => sided.getSlotsForFace(side.orNull).toIterable + case _ => 0 until inventory.getSizeInventory + }) if (range.nonEmpty) { // This is a special case for inserting with an explicit ordering, @@ -204,8 +207,13 @@ object InventoryUtils { *
* This returns true if at least one item was extracted. */ - def extractFromInventory(consumer: (ItemStack) => Unit, inventory: IInventory, side: EnumFacing, limit: Int = 64) = - (0 until inventory.getSizeInventory).exists(slot => extractFromInventorySlot(consumer, inventory, side, slot, limit)) + def extractFromInventory(consumer: (ItemStack) => Unit, inventory: IInventory, side: EnumFacing, limit: Int = 64) = { + val range = inventory match { + case sided: ISidedInventory => sided.getSlotsForFace(side).toIterable + case _ => 0 until inventory.getSizeInventory + } + range.exists(slot => extractFromInventorySlot(consumer, inventory, side, slot, limit)) + } /** * Utility method for calling insertIntoInventory on an inventory