Finished migrating crop stuff to Geolyzer/converter logic (mostly because I cba to make new graphics >_>).

Also added AgriCraft API as JAR lib because getting the Gradle dep to work is a royal pita and I wasted too much time on trying that already...
This commit is contained in:
Florian Nücke 2015-08-29 15:10:44 +02:00
parent f41fe495b7
commit 83ce705a99
11 changed files with 122 additions and 155 deletions

Binary file not shown.

View File

@ -1,5 +0,0 @@
package li.cil.oc.common.item
class UpgradeFarming (val parent: Delegator) extends traits.Delegate with traits.ItemTier{
}

View File

@ -19,7 +19,7 @@ object Mods {
def All = knownMods.clone()
val AgriCraft = new SimpleMod(IDs.AgriCraft)
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)

View File

@ -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
}
}

View File

@ -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 _ =>
}
}
}

View File

@ -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.
}
}
})
}
}

View File

@ -1,38 +1,17 @@
package li.cil.oc.integration.agricraft
import com.InfinityRaider.AgriCraft.blocks.BlockCrop
import li.cil.oc.integration.util.Crop
import li.cil.oc.integration.util.Crop.CropProvider
import li.cil.oc.integration.{Mods, Mod, ModProxy}
import li.cil.oc.server.component._
import li.cil.oc.util.BlockPosition
import net.minecraft.block.Block
import net.minecraft.item.Item
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 with CropProvider {
object ModAgriCraft extends ModProxy {
override def getMod: Mod = Mods.AgriCraft
override def initialize(): Unit = {
Crop.addProvider(this)
}
Driver.add(ConverterSeeds)
override def getInformation(pos: BlockPosition): Array[AnyRef] = {
val world = pos.world.get
val target = world.getBlock(pos.x,pos.y,pos.z)
target match {
case crop:BlockCrop=>{
val meta = world.getBlockMetadata(pos.x, pos.y, pos.z)
val value = meta * 100 / 2
result(Item.itemRegistry.getNameForObject(crop.getSeed))
}
case _=>result(Unit,"not a thing")
}
}
override def isValidFor(block: Block): Boolean = {
block match {
case _: BlockCrop => true
case _ => false
}
MinecraftForge.EVENT_BUS.register(EventHandlerAgriCraft)
}
}

View File

@ -1,26 +0,0 @@
package li.cil.oc.integration.util
import li.cil.oc.util.BlockPosition
import net.minecraft.block.Block
import scala.collection.mutable
object Crop {
val providers = mutable.Buffer.empty[CropProvider]
def addProvider(provider: CropProvider): Unit = providers += provider
def getProviderForBlock(block: Block): Option[CropProvider] = {
providers.find(_.isValidFor(block))
}
trait CropProvider {
def getInformation(pos: BlockPosition): Array[AnyRef]
def isValidFor(block: Block): Boolean
}
}

View File

@ -0,0 +1,28 @@
package li.cil.oc.integration.vanilla
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import li.cil.oc.api.event.GeolyzerEvent
import net.minecraft.block.BlockCrops
import net.minecraft.init.Blocks
import scala.collection.convert.WrapAsScala._
object EventHandlerVanilla {
@SubscribeEvent
def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) {
val world = e.host.world
val block = world.getBlock(e.x, e.y, e.z)
if (block.isInstanceOf[BlockCrops] || block == Blocks.melon_stem || block == Blocks.pumpkin_stem || block == Blocks.carrots || block == Blocks.potatoes) {
e.data += "growth" -> float2Float((world.getBlockMetadata(e.x, e.y, e.z) / 7f) max 0 min 1)
}
if (block == Blocks.cocoa) {
e.data += "growth" -> float2Float(((world.getBlockMetadata(e.x, e.y, e.z) >> 2) / 2f) max 0 min 1)
}
if (block == Blocks.nether_wart) {
e.data += "growth" -> float2Float((world.getBlockMetadata(e.x, e.y, e.z) / 3f) max 0 min 1)
}
if (block == Blocks.melon_block || block == Blocks.pumpkin || block == Blocks.cactus || block == Blocks.reeds) {
e.data += "growth" -> float2Float(1f)
}
}
}

View File

@ -4,18 +4,15 @@ import li.cil.oc.Settings
import li.cil.oc.api.Driver
import li.cil.oc.integration.ModProxy
import li.cil.oc.integration.Mods
import li.cil.oc.integration.util.{Crop, BundledRedstone}
import li.cil.oc.integration.util.BundledRedstone
import li.cil.oc.integration.util.BundledRedstone.RedstoneProvider
import li.cil.oc.integration.util.Crop.CropProvider
import li.cil.oc.server.component._
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.ExtendedWorld._
import net.minecraft.block._
import net.minecraft.init.{Items, Blocks}
import net.minecraft.item.Item
import net.minecraft.init.Blocks
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.util.ForgeDirection
object ModVanilla extends ModProxy with RedstoneProvider with CropProvider {
object ModVanilla extends ModProxy with RedstoneProvider {
def getMod = Mods.Minecraft
def initialize() {
@ -48,7 +45,8 @@ object ModVanilla extends ModProxy with RedstoneProvider with CropProvider {
RecipeHandler.init()
BundledRedstone.addProvider(this)
Crop.addProvider(this)
MinecraftForge.EVENT_BUS.register(EventHandlerVanilla)
}
override def computeInput(pos: BlockPosition, side: ForgeDirection): Int = {
@ -58,57 +56,4 @@ object ModVanilla extends ModProxy with RedstoneProvider with CropProvider {
}
override def computeBundledInput(pos: BlockPosition, side: ForgeDirection): Array[Int] = null
override def getInformation(pos: BlockPosition): Array[AnyRef] = {
val world = pos.world.get
val target = world.getBlock(pos.x, pos.y, pos.z)
target match {
case crop: BlockBush => {
val meta = world.getBlockMetadata(pos.x, pos.y, pos.z)
var name = crop.getLocalizedName
var modifier = 7
crop match {
case Blocks.wheat => {
name = Item.itemRegistry.getNameForObject(Items.wheat)
}
case Blocks.melon_stem => {
//Localize this?
name = "Melon stem"
}
case Blocks.pumpkin_stem => {
name = "Pumpkin stem"
}
case Blocks.nether_wart => {
modifier = 3
}
case _ =>
}
result(name, meta * 100 / modifier)
}
case cocoa: BlockCocoa => {
val meta = world.getBlockMetadata(pos.x, pos.y, pos.z)
val value = meta * 100 / 2
result(cocoa.getLocalizedName, Math.min(value, 100))
}
case _: BlockMelon | _: BlockPumpkin => {
result(target.getLocalizedName, 100)
}
case _: BlockCactus | _: BlockReed => {
val meta = world.getBlockMetadata(pos.x, pos.y, pos.z)
result(target.getLocalizedName, meta)
}
case _ => result(Unit, "Not a crop")
}
}
override def isValidFor(block: Block): Boolean = {
block match {
//has to be specified for crops otherwise overriding blocks of other mods might not get their own Provider
case _: BlockStem | Blocks.wheat | Blocks.carrots | Blocks.potatoes | _: BlockCocoa | _: BlockMelon | _: BlockPumpkin | _: BlockCactus | _: BlockReed => true
case _ => false
}
}
}

View File

@ -1,33 +0,0 @@
package li.cil.oc.server.component
import li.cil.oc.api.driver.EnvironmentHost
import li.cil.oc.api.machine.{Callback, Arguments, Context}
import li.cil.oc.api.network.Visibility
import li.cil.oc.api.{Network, prefab, internal}
import li.cil.oc.integration.util.Crop
import li.cil.oc.integration.util.Crop.CropProvider
import li.cil.oc.util.BlockPosition
import net.minecraft.block._
import net.minecraft.init.{Items, Blocks}
import net.minecraft.item.Item
import net.minecraftforge.common.IPlantable
import net.minecraftforge.common.util.ForgeDirection
class UpgradeFarming(val host: EnvironmentHost with internal.Robot) extends prefab.ManagedEnvironment {
override val node = Network.newNode(this, Visibility.Network).
withComponent("farming").
create()
@Callback(doc = """function([count:number]):boolean -- checks the ripeness of the seed.""")
def check(context: Context, args: Arguments): Array[AnyRef] = {
val hostPos = BlockPosition(host)
val targetPos = hostPos.offset(ForgeDirection.DOWN)
val target = host.world.getBlock(targetPos.x, targetPos.y, targetPos.z)
Crop.getProviderForBlock(target) match {
case Some(provider) => provider.getInformation(BlockPosition(targetPos.x, targetPos.y, targetPos.z, host.world))
case _ => result(Unit, "Not a crop")
}
}
}