From 784c65a88403a6d6849c731f332cc222efad724a Mon Sep 17 00:00:00 2001 From: MauveCloud Date: Tue, 26 Apr 2016 13:30:26 -0700 Subject: [PATCH] Added Crop Calculator support. --- .../java/gregtech/api/util/GT_BaseCrop.java | 41 ++++++++++++++++++- .../speiger/src/crops/api/ICropCardInfo.java | 19 +++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/main/java/speiger/src/crops/api/ICropCardInfo.java diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java index 5ca5af2e..304a0f3c 100644 --- a/src/main/java/gregtech/api/util/GT_BaseCrop.java +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -1,5 +1,6 @@ package gregtech.api.util; +import cpw.mods.fml.common.Loader; import gregtech.GT_Mod; import gregtech.api.GregTech_API; import gregtech.api.enums.ConfigCategories; @@ -16,18 +17,21 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import speiger.src.crops.api.ICropCardInfo; import java.util.ArrayList; +import java.util.List; import java.util.Random; import static gregtech.api.enums.GT_Values.E; -public class GT_BaseCrop extends CropCard { +public class GT_BaseCrop extends CropCard implements ICropCardInfo { public static ArrayList sCropList = new ArrayList(); private String mName = E, mDiscoveredBy = "Gregorius Techneticies", mAttributes[]; private int mTier = 0, mMaxSize = 0, mAfterHarvestSize = 0, mHarvestSize = 0, mStats[] = new int[5], mGrowthSpeed = 0; private ItemStack mDrop = null, mSpecialDrops[] = null; private Materials mBlock = null; + private static boolean bIc2NeiLoaded = Loader.isModLoaded("Ic2Nei"); /** * To create new Crops @@ -85,6 +89,25 @@ public class GT_BaseCrop extends CropCard { if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, this, 1, 1, 1, 1); sCropList.add(this);} } + if (bIc2NeiLoaded) { + try { + Class.forName("speiger.src.crops.api.CropPluginAPI").getMethod("registerCropInfo", Class.forName("speiger.src.crops.api.ICropCardInfo")).invoke(Class.forName("speiger.src.crops.api.CropPluginAPI").getField("instance"), this); + } catch (IllegalAccessException ex) { + bIc2NeiLoaded = false; + } catch (IllegalArgumentException ex) { + bIc2NeiLoaded = false; + } catch (java.lang.reflect.InvocationTargetException ex) { + bIc2NeiLoaded = false; + } catch (NoSuchFieldException ex) { + bIc2NeiLoaded = false; + } catch (NoSuchMethodException ex) { + bIc2NeiLoaded = false; + } catch (SecurityException ex) { + bIc2NeiLoaded = false; + } catch (ClassNotFoundException ex) { + bIc2NeiLoaded = false; + } + } } @Override @@ -212,4 +235,20 @@ public class GT_BaseCrop extends CropCard { return false; } + public List getCropInformation() { + if (mBlock != null) { + ArrayList result = new ArrayList(1); + result.add(String.format("Requires %s Ore or Block of %s as soil block to reach full growth.", mBlock.name(), mBlock.name())); + return result; + } + return null; + } + + public ItemStack getDisplayItem() { + if (mSpecialDrops != null && mSpecialDrops[mSpecialDrops.length - 1] != null) { + return GT_Utility.copy(mSpecialDrops[mSpecialDrops.length - 1]); + } + return GT_Utility.copy(mDrop); + } + } diff --git a/src/main/java/speiger/src/crops/api/ICropCardInfo.java b/src/main/java/speiger/src/crops/api/ICropCardInfo.java new file mode 100644 index 00000000..34d35edc --- /dev/null +++ b/src/main/java/speiger/src/crops/api/ICropCardInfo.java @@ -0,0 +1,19 @@ +package speiger.src.crops.api; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +/** + * + * @author Speiger + * Class to add Informations from CropCards. + * This has Priorty over the ICropInfo + * @requirement: The class that implement this class need to extends CropCard + */ +public interface ICropCardInfo +{ + public List getCropInformation(); + + public ItemStack getDisplayItem(); +}