-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Uploaded API Classes.
- Loading branch information
Showing
3 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |