mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-10 15:56:41 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into master-MC1.8
Conflicts: src/main/scala/li/cil/oc/integration/Mods.scala src/main/scala/li/cil/oc/integration/vanilla/ModVanilla.scala src/main/scala/li/cil/oc/util/InventoryUtils.scala
This commit is contained in:
commit
c36a22b9a3
@ -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/**'
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
}
|
||||
}
|
@ -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 _ =>
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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 = {
|
||||
|
@ -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 {
|
||||
* <p/>
|
||||
* This returns <tt>true</tt> 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 <tt>insertIntoInventory</tt> on an inventory
|
||||
|
Loading…
x
Reference in New Issue
Block a user