diff --git a/Source/speiger/src/crops/api/CropPluginAPI.java b/Source/speiger/src/crops/api/CropPluginAPI.java new file mode 100644 index 0000000..14ca045 --- /dev/null +++ b/Source/speiger/src/crops/api/CropPluginAPI.java @@ -0,0 +1,105 @@ +package speiger.src.crops.api; + +import ic2.api.crops.CropCard; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLLog; + +import net.minecraft.item.ItemStack; + +/** + * + * @author Speiger + * + * registry class + */ +public class CropPluginAPI +{ + private static List toProcess = new ArrayList(); + private Map> extraInfos = new HashMap>(); + private Map displayItems = new HashMap(); + + public static CropPluginAPI instance = new CropPluginAPI(); + + public void registerCropInfo(ICropInfo info) + { + if(info != null) + { + toProcess.add(info); + } + } + + public ItemStack getDisplayItem(CropCard card) + { + return displayItems.get(card); + } + + public List getExtraInfos(CropCard card) + { + List info = extraInfos.get(card); + if(info == null) + { + info = new ArrayList(); + } + return info; + } + + /** + * @IMPORTANT: Never call this Function! + */ + public void load(Map par1) + { + for(ICropInfo target : toProcess) + { + List cards = target.getSupportedCrops(); + if(cards == null || cards.isEmpty()) + { + continue; + } + for(CropCard card : cards) + { + List data = target.getCropInformation(card); + if(data != null && !data.isEmpty() && !extraInfos.containsKey(card)) + { + extraInfos.put(card, data); + } + ItemStack item = target.getDisplayItems(card); + if(item != null && !displayItems.containsKey(card)) + { + item = item.copy(); + item.setStackDisplayName("Crop "+card.name()); + displayItems.put(card, item); + } + } + } + toProcess.clear(); + for(CropCard card : par1.keySet()) + { + if(card instanceof ICropCardInfo) + { + ICropCardInfo info = (ICropCardInfo)card; + List data = info.getCropInformation(); + if(data != null && !data.isEmpty()) + { + extraInfos.put(card, data); + } + ItemStack item = info.getDisplayItem(); + if(item != null) + { + item = item.copy(); + item.setStackDisplayName("Crop "+card.name()); + displayItems.put(card, item); + } + } + if(!displayItems.containsKey(card)) + { + displayItems.put(card, par1.get(card)); + } + } + } +} diff --git a/Source/speiger/src/crops/api/ICropCardInfo.java b/Source/speiger/src/crops/api/ICropCardInfo.java new file mode 100644 index 0000000..94c7ff3 --- /dev/null +++ b/Source/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(); +} diff --git a/Source/speiger/src/crops/api/ICropInfo.java b/Source/speiger/src/crops/api/ICropInfo.java new file mode 100644 index 0000000..775e069 --- /dev/null +++ b/Source/speiger/src/crops/api/ICropInfo.java @@ -0,0 +1,40 @@ +package speiger.src.crops.api; + +import ic2.api.crops.CropCard; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +/** + * + * @author Speiger + * Class to add External Informations to Crop Cards + * Internal CropCard Information have Priority! + * + */ +public interface ICropInfo +{ + /** + * @return the CropCards that he checks for. + * a null or a empty list means that it get not loaded.. + */ + public List getSupportedCrops(); + + + /** + * @return a list of "Important" Information, + * which are needed to grow the Crop. + * Like: a Special Light Level or something. + * @param card: the CropCard which is asking for it. + * you can also return null or a empty list if you only + * want to add DisplayItems. + */ + public List getCropInformation(CropCard card); + + /** + * @return the DisplayItem for the CropCard he is checking. + * null means it get not implemented. So you can return null + */ + public ItemStack getDisplayItems(CropCard card); +}