Skip to content

Commit

Permalink
Initial Commit.
Browse files Browse the repository at this point in the history
-Uploaded API Classes.
  • Loading branch information
Speiger committed Jul 6, 2015
1 parent 7224b76 commit e814b0b
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 0 deletions.
105 changes: 105 additions & 0 deletions Source/speiger/src/crops/api/CropPluginAPI.java
Original file line number Diff line number Diff line change
@@ -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<ICropInfo> toProcess = new ArrayList<ICropInfo>();
private Map<CropCard, List<String>> extraInfos = new HashMap<CropCard, List<String>>();
private Map<CropCard, ItemStack> displayItems = new HashMap<CropCard, ItemStack>();

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<String> getExtraInfos(CropCard card)
{
List<String> info = extraInfos.get(card);
if(info == null)
{
info = new ArrayList<String>();
}
return info;
}

/**
* @IMPORTANT: Never call this Function!
*/
public void load(Map<CropCard, ItemStack> par1)
{
for(ICropInfo target : toProcess)
{
List<CropCard> cards = target.getSupportedCrops();
if(cards == null || cards.isEmpty())
{
continue;
}
for(CropCard card : cards)
{
List<String> 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<String> 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));
}
}
}
}
19 changes: 19 additions & 0 deletions Source/speiger/src/crops/api/ICropCardInfo.java
Original file line number Diff line number Diff line change
@@ -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<String> getCropInformation();

public ItemStack getDisplayItem();
}
40 changes: 40 additions & 0 deletions Source/speiger/src/crops/api/ICropInfo.java
Original file line number Diff line number Diff line change
@@ -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<CropCard> 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<String> 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);
}

0 comments on commit e814b0b

Please sign in to comment.