Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IC2 crop breeding integration. #3317

Open
wants to merge 1 commit into
base: master-MC1.7.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}
maven {
url = "https://jitpack.io"
}
}
}
dependencies {
classpath 'com.github.CDAGaming:ForgeGradle:1c670759c5'
Expand Down Expand Up @@ -78,6 +78,10 @@ repositories {
name = "mightypirates"
url = "https://maven.cil.li/"
}
maven {
name = "ic2, forestry"
url = "http://maven.ic2.player.to/"
}
// These are necessary because some parts of the maven repo is weirdly structured, this needs to be fixed.
ivy {
name 'weird maven repos'
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ forestry.version=4.1.0.44
gc.build=3
gc.version=3.0.7
gt.version=5.04.06
ic2.version=2.2.654-experimental
ic2.version=2.2.828-experimental
igwmod.version=1.1.3-18
mekanism.build=5
mekanism.version=7.1.2
Expand Down
23 changes: 23 additions & 0 deletions src/main/scala/li/cil/oc/integration/ic2/ConverterBaseSeed.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package li.cil.oc.integration.ic2

import ic2.api.crops.BaseSeed
import ic2.api.crops.Crops
import li.cil.oc.api.driver.Converter
import net.minecraft.item.ItemStack
import java.util
import scala.collection.convert.WrapAsScala._

class ConverterBaseSeed extends Converter {
override def convert(value: Any, output: util.Map[AnyRef, AnyRef]): Unit = if (value.isInstanceOf[ItemStack]) {
val stack = value.asInstanceOf[ItemStack]
val cc = Crops.instance.getCropCard(stack)
if (cc != null && stack.getTagCompound().getByte("scan") == 4) {
output += "crop" -> Map("name" -> cc.name,
"tier" -> cc.tier,
"growth" -> stack.getTagCompound().getByte("growth"),
"gain" -> stack.getTagCompound().getByte("gain"),
"resistance" -> stack.getTagCompound().getByte("resistance")
)
}
}
}
93 changes: 93 additions & 0 deletions src/main/scala/li/cil/oc/integration/ic2/DriverCrop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package li.cil.oc.integration.ic2;

import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.ManagedEnvironment;
import li.cil.oc.api.prefab.DriverSidedTileEntity;
import ic2.api.crops.ICropTile;
import li.cil.oc.integration.ManagedTileEntityEnvironment;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public final class DriverCrop extends DriverSidedTileEntity {
@Override
public Class<?> getTileEntityClass() {
return ICropTile.class;
}

@Override
public ManagedEnvironment createEnvironment(World world, int x, int y, int z, ForgeDirection side) {
return new DriverCrop.Environment((ICropTile) world.getTileEntity(x, y, z));
}
public static final class Environment extends ManagedTileEntityEnvironment<ICropTile> {
public Environment(final ICropTile tileEntity) {
super(tileEntity, "crop");
}

@Callback
public Object[] getSize(final Context context, final Arguments args) {
return new Object[]{tileEntity.getSize()};
}
@Callback
public Object[] getGrowth(final Context context, final Arguments args) {
return new Object[]{tileEntity.getGrowth()};
}
@Callback
public Object[] getGain(final Context context, final Arguments args) {
return new Object[]{tileEntity.getGain()};
}
@Callback
public Object[] getResistance(final Context context, final Arguments args) {
return new Object[]{tileEntity.getResistance()};
}
@Callback
public Object[] getNutrientStorage(final Context context, final Arguments args) {
return new Object[]{tileEntity.getNutrientStorage()};
}
@Callback
public Object[] getHydrationStorage(final Context context, final Arguments args) {
return new Object[]{tileEntity.getHydrationStorage()};
}
@Callback
public Object[] getWeedExStorage(final Context context, final Arguments args) {
return new Object[]{tileEntity.getWeedExStorage()};
}
@Callback
public Object[] getHumidity(final Context context, final Arguments args) {
return new Object[]{tileEntity.getHumidity()};
}
@Callback
public Object[] getNutrients(final Context context, final Arguments args) {
return new Object[]{tileEntity.getNutrients()};
}
@Callback
public Object[] getAirQuality(final Context context, final Arguments args) {
return new Object[]{tileEntity.getAirQuality()};
}
@Callback
public Object[] getName(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().name()};
}
@Callback
public Object[] getRootsLength(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().getrootslength(tileEntity)};
}
@Callback
public Object[] getTier(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().tier()};
}
@Callback
public Object[] maxSize(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().maxSize()};
}
@Callback
public Object[] canGrow(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().canGrow(tileEntity)};
}
@Callback
public Object[] getOptimalHavestSize(final Context context, final Arguments args) {
return new Object[]{tileEntity.getCrop().getOptimalHavestSize(tileEntity)};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
package li.cil.oc.integration.ic2

import cpw.mods.fml.common.eventhandler.SubscribeEvent
import ic2.api.crops.ICropTile
import ic2.api.item.ElectricItem
import ic2.api.item.IElectricItem
import ic2.api.item.ISpecialElectricItem
import ic2.core.item.tool.ItemToolWrench
import li.cil.oc.api.event.RobotUsedToolEvent
import li.cil.oc.api.event.{GeolyzerEvent, RobotUsedToolEvent}
import li.cil.oc.integration.util.Power
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import scala.collection.convert.WrapAsScala._

object EventHandlerIndustrialCraft2 {
@SubscribeEvent
def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) {
val world = e.host.world
world.getTileEntity(e.x, e.y, e.z) match {
case crop: ICropTile =>
crop.setScanLevel(4)
val cc = crop.getCrop
if (cc != null) {
e.data += "crop:name" -> cc.name()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgriCraft doesn't use a crop: prefix. As per the fluid container discussion, would this be better without the prefix, or in a separate "crop" map?

e.data += "crop:tier" -> Int.box(cc.tier)
e.data += "crop:size" -> Int.box(crop.getSize)
e.data += "crop:maxSize" -> Int.box(cc.maxSize)
e.data += "crop:growth" -> Int.box(crop.getGrowth)
e.data += "crop:gain" -> Int.box(crop.getGain)
e.data += "crop:resistance" -> Int.box(crop.getResistance)
e.data += "crop:fertilizer" -> Int.box(crop.getNutrientStorage)
e.data += "crop:hydration" -> Int.box(crop.getHydrationStorage)
e.data += "crop:weedex" -> Int.box(crop.getWeedExStorage)
e.data += "crop:humidity" -> Int.box(crop.getHumidity)
e.data += "crop:nutrients" -> Int.box(crop.getNutrients)
e.data += "crop:air" -> Int.box(crop.getAirQuality)
e.data += "crop:roots" -> Int.box(cc.getrootslength(crop))
}
case _ => None
}
}
@SubscribeEvent
def onRobotApplyDamageRate(e: RobotUsedToolEvent.ApplyDamageRate) {
val optManagerBefore = e.toolBeforeUse.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(e.toolBeforeUse))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}
val optManagerAfter = e.toolAfterUse.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(e.toolAfterUse))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}
(optManagerBefore, optManagerAfter) match {
Expand Down Expand Up @@ -69,7 +97,7 @@ object EventHandlerIndustrialCraft2 {
def charge(stack: ItemStack, amount: Double, simulate: Boolean): Double = {
(stack.getItem match {
case item: ISpecialElectricItem => Option(item.getManager(stack))
case item: IElectricItem => Option(ElectricItem.manager)
case _: IElectricItem => Option(ElectricItem.manager)
case _ => None
}) match {
case Some(manager) => amount - Power.fromEU(manager.charge(stack, Power.toEU(amount), Int.MaxValue, true, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ object ModIndustrialCraft2 extends ModProxy {
Driver.add(new DriverReactorChamber)

Driver.add(new ConverterElectricItem)
Driver.add(new ConverterBaseSeed)
Driver.add(new DriverCrop)
}
}