This commit is contained in:
WayofTime 2014-01-17 14:12:49 -05:00
commit 8601e9faff
498 changed files with 45817 additions and 0 deletions

View file

@ -0,0 +1,10 @@
package thaumcraft.api.research;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface IScanEventHandler
{
ScanResult scanPhenomena(ItemStack stack, World world, EntityPlayer player);
}

View file

@ -0,0 +1,101 @@
package thaumcraft.api.research;
import java.util.Collection;
import java.util.LinkedHashMap;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
public class ResearchCategories
{
//Research
public static LinkedHashMap <String, ResearchCategoryList> researchCategories = new LinkedHashMap <String, ResearchCategoryList>();
/**
* @param key
* @return the research item linked to this key
*/
public static ResearchCategoryList getResearchList(String key)
{
return researchCategories.get(key);
}
/**
* @param key
* @return the name of the research category linked to this key.
* Must be stored as localization information in the LanguageRegistry.
*/
public static String getCategoryName(String key)
{
return StatCollector.translateToLocal("tc.research_category." + key);
}
/**
* @param key the research key
* @return the ResearchItem object.
*/
public static ResearchItem getResearch(String key)
{
Collection rc = researchCategories.values();
for (Object cat: rc)
{
Collection rl = ((ResearchCategoryList)cat).research.values();
for (Object ri: rl)
{
if ((((ResearchItem)ri).key).equals(key))
{
return (ResearchItem)ri;
}
}
}
return null;
}
/**
* @param key the key used for this category
* @param icon the icon to be used for the research category tab
* @param background the resource location of the background image to use for this category
* @return the name of the research linked to this key
*/
public static void registerCategory(String key, ResourceLocation icon, ResourceLocation background)
{
if (getResearchList(key) == null)
{
ResearchCategoryList rl = new ResearchCategoryList(icon, background);
researchCategories.put(key, rl);
}
}
public static void addResearch(ResearchItem ri)
{
ResearchCategoryList rl = getResearchList(ri.category);
if (rl != null && !rl.research.containsKey(ri.key))
{
rl.research.put(ri.key, ri);
if (ri.displayColumn < rl.minDisplayColumn)
{
rl.minDisplayColumn = ri.displayColumn;
}
if (ri.displayRow < rl.minDisplayRow)
{
rl.minDisplayRow = ri.displayRow;
}
if (ri.displayColumn > rl.maxDisplayColumn)
{
rl.maxDisplayColumn = ri.displayColumn;
}
if (ri.displayRow > rl.maxDisplayRow)
{
rl.maxDisplayRow = ri.displayRow;
}
}
}
}

View file

@ -0,0 +1,34 @@
package thaumcraft.api.research;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.util.ResourceLocation;
public class ResearchCategoryList
{
/** Is the smallest column used on the GUI. */
public int minDisplayColumn;
/** Is the smallest row used on the GUI. */
public int minDisplayRow;
/** Is the biggest column used on the GUI. */
public int maxDisplayColumn;
/** Is the biggest row used on the GUI. */
public int maxDisplayRow;
/** display variables **/
public ResourceLocation icon;
public ResourceLocation background;
public ResearchCategoryList(ResourceLocation icon, ResourceLocation background)
{
this.icon = icon;
this.background = background;
}
//Research
public Map<String, ResearchItem> research = new HashMap<String, ResearchItem>();
}

View file

@ -0,0 +1,336 @@
package thaumcraft.api.research;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ResearchItem
{
/**
* A short string used as a key for this research. Must be unique
*/
public final String key;
/**
* A short string used as a reference to the research category to which this must be added.
*/
public final String category;
/**
* The aspect tags and their values required to complete this research
*/
public final AspectList tags;
/**
* This links to any research that needs to be completed before this research can be discovered or learnt.
*/
public String[] parents = null;
/**
* Like parent above, but a line will not be displayed in the thaumonomicon linking them. Just used to prevent clutter.
*/
public String[] parentsHidden = null;
/**
* any research linked to this that will be unlocked automatically when this research is complete
*/
public String[] siblings = null;
/**
* the horizontal position of the research icon
*/
public final int displayColumn;
/**
* the vertical position of the research icon
*/
public final int displayRow;
/**
* the icon to be used for this research
*/
public final ItemStack icon_item;
/**
* the icon to be used for this research
*/
public final ResourceLocation icon_resource;
/**
* How large the research grid is. Valid values are 1 to 5.
*/
private int complexity;
/**
* Special research has a spiky border. Used for important research milestones.
*/
private boolean isSpecial;
/**
* This indicates if the research should use a circular icon border. Usually used for "passive" research
* that doesn't have recipes and grants passive effects, or that unlock automatically.
*/
private boolean isRound;
/**
* Stub research cannot be discovered by normal means, but can be unlocked via the sibling system.
*/
private boolean isStub;
/**
* This indicated that the research is completely hidden and cannot be discovered by any
* player-controlled means. The recipes will never show up in the thaumonomicon.
* Usually used to unlock "hidden" recipes via sibling unlocking, like
* the various cap and rod combos for wands.
*/
private boolean isVirtual;
/**
* Hidden research does not display in the thaumonomicon until discovered
*/
private boolean isHidden;
/**
* Concealed research does not display in the thaumonomicon until parent researches are discovered.
*/
private boolean isConcealed;
/**
* Lost research can only be discovered via knowledge fragments
*/
private boolean isLost;
/**
* These research items will automatically unlock for all players on game start
*/
private boolean isAutoUnlock;
private ResearchPage[] pages = null;
public ResearchItem(String par1, String par2)
{
this.key = par1;
this.category = par2;
this.tags = new AspectList();
this.icon_resource = null;
this.icon_item = null;
this.displayColumn = 0;
this.displayRow = 0;
this.setVirtual();
}
public ResearchItem(String par1, String par2, AspectList tags, int par3, int par4, int par5, ResourceLocation icon)
{
this.key = par1;
this.category = par2;
this.tags = tags;
this.icon_resource = icon;
this.icon_item = null;
this.displayColumn = par3;
this.displayRow = par4;
this.complexity = par5;
if (complexity < 1)
{
this.complexity = 1;
}
if (complexity > 5)
{
this.complexity = 5;
}
}
public ResearchItem(String par1, String par2, AspectList tags, int par3, int par4, int par5, ItemStack icon)
{
this.key = par1;
this.category = par2;
this.tags = tags;
this.icon_item = icon;
this.icon_resource = null;
this.displayColumn = par3;
this.displayRow = par4;
this.complexity = par5;
if (complexity < 0)
{
this.complexity = 0;
}
if (complexity > 5)
{
this.complexity = 5;
}
}
public ResearchItem setSpecial()
{
this.isSpecial = true;
return this;
}
public ResearchItem setStub()
{
this.isStub = true;
return this;
}
public ResearchItem setHidden()
{
this.isHidden = true;
return this;
}
public ResearchItem setConcealed()
{
this.isConcealed = true;
return this;
}
public ResearchItem setLost()
{
this.isLost = true;
return this;
}
public ResearchItem setVirtual()
{
this.isVirtual = true;
return this;
}
public ResearchItem setParents(String... par)
{
this.parents = par;
return this;
}
public ResearchItem setParentsHidden(String... par)
{
this.parentsHidden = par;
return this;
}
public ResearchItem setSiblings(String... sib)
{
this.siblings = sib;
return this;
}
public ResearchItem setPages(ResearchPage... par)
{
this.pages = par;
return this;
}
public ResearchPage[] getPages()
{
return pages;
}
public ResearchItem registerResearchItem()
{
ResearchCategories.addResearch(this);
return this;
}
@SideOnly(Side.CLIENT)
public String getName()
{
return StatCollector.translateToLocal("tc.research_name." + key);
}
@SideOnly(Side.CLIENT)
public String getText()
{
return StatCollector.translateToLocal("tc.research_text." + key);
}
@SideOnly(Side.CLIENT)
public boolean isSpecial()
{
return this.isSpecial;
}
public boolean isStub()
{
return this.isStub;
}
public boolean isHidden()
{
return this.isHidden;
}
public boolean isConcealed()
{
return this.isConcealed;
}
public boolean isLost()
{
return this.isLost;
}
public boolean isVirtual()
{
return this.isVirtual;
}
public boolean isAutoUnlock()
{
return isAutoUnlock;
}
public ResearchItem setAutoUnlock()
{
this.isAutoUnlock = true;
return this;
}
public boolean isRound()
{
return isRound;
}
public ResearchItem setRound()
{
this.isRound = true;
return this;
}
public int getComplexity()
{
return complexity;
}
public ResearchItem setComplexity(int complexity)
{
this.complexity = complexity;
return this;
}
/**
* @return the aspect aspects ordinal with the highest value. Used to determine scroll color and similar things
*/
public Aspect getResearchPrimaryTag()
{
Aspect aspect = null;
int highest = 0;
if (tags != null)
for (Aspect tag: tags.getAspects())
{
if (tags.getAmount(tag) > highest)
{
aspect = tag;
highest = tags.getAmount(tag);
};
}
return aspect;
}
}

View file

@ -0,0 +1,198 @@
package thaumcraft.api.research;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.CrucibleRecipe;
import thaumcraft.api.crafting.IArcaneRecipe;
import thaumcraft.api.crafting.InfusionEnchantmentRecipe;
import thaumcraft.api.crafting.InfusionRecipe;
public class ResearchPage
{
public static enum PageType
{
TEXT,
TEXT_CONCEALED,
IMAGE,
CRUCIBLE_CRAFTING,
ARCANE_CRAFTING,
ASPECTS,
NORMAL_CRAFTING,
INFUSION_CRAFTING,
COMPOUND_CRAFTING,
INFUSION_ENCHANTMENT
}
public PageType type = PageType.TEXT;
public String text = null;
public String research = null;
public ResourceLocation image = null;
public AspectList aspects = null;
public Object recipe = null;
public ItemStack recipeOutput = null;
/**
* @param text this can (but does not have to) be a reference to a localization variable, not the actual text.
*/
public ResearchPage(String text)
{
this.type = PageType.TEXT;
this.text = text;
}
/**
* @param research this page will only be displayed if the player has discovered this research
* @param text this can (but does not have to) be a reference to a localization variable, not the actual text.
*/
public ResearchPage(String research, String text)
{
this.type = PageType.TEXT_CONCEALED;
this.research = research;
this.text = text;
}
/**
* @param recipe a vanilla crafting recipe.
*/
public ResearchPage(IRecipe recipe)
{
this.type = PageType.NORMAL_CRAFTING;
this.recipe = recipe;
this.recipeOutput = recipe.getRecipeOutput();
}
/**
* @param recipe a collection of vanilla crafting recipes.
*/
public ResearchPage(IRecipe[] recipe)
{
this.type = PageType.NORMAL_CRAFTING;
this.recipe = recipe;
}
/**
* @param recipe a collection of arcane crafting recipes.
*/
public ResearchPage(IArcaneRecipe[] recipe)
{
this.type = PageType.ARCANE_CRAFTING;
this.recipe = recipe;
}
/**
* @param recipe a collection of infusion crafting recipes.
*/
public ResearchPage(InfusionRecipe[] recipe)
{
this.type = PageType.INFUSION_CRAFTING;
this.recipe = recipe;
}
/**
* @param recipe a compound crafting recipe.
*/
public ResearchPage(List recipe)
{
this.type = PageType.COMPOUND_CRAFTING;
this.recipe = recipe;
}
/**
* @param recipe an arcane worktable crafting recipe.
*/
public ResearchPage(IArcaneRecipe recipe)
{
this.type = PageType.ARCANE_CRAFTING;
this.recipe = recipe;
this.recipeOutput = recipe.getRecipeOutput();
}
/**
* @param recipe an alchemy crafting recipe.
*/
public ResearchPage(CrucibleRecipe recipe)
{
this.type = PageType.CRUCIBLE_CRAFTING;
this.recipe = recipe;
this.recipeOutput = recipe.recipeOutput;
}
/**
* @param recipe an infusion crafting recipe.
*/
public ResearchPage(InfusionRecipe recipe)
{
this.type = PageType.INFUSION_CRAFTING;
this.recipe = recipe;
if (recipe.recipeOutput instanceof ItemStack)
{
this.recipeOutput = (ItemStack) recipe.recipeOutput;
}
else
{
this.recipeOutput = recipe.recipeInput;
}
}
/**
* @param recipe an infusion crafting recipe.
*/
public ResearchPage(InfusionEnchantmentRecipe recipe)
{
this.type = PageType.INFUSION_ENCHANTMENT;
this.recipe = recipe;
// if (recipe.recipeOutput instanceof ItemStack) {
// this.recipeOutput = (ItemStack) recipe.recipeOutput;
// } else {
// this.recipeOutput = recipe.recipeInput;
// }
}
/**
* @param image
* @param caption this can (but does not have to) be a reference to a localization variable, not the actual text.
*/
public ResearchPage(ResourceLocation image, String caption)
{
this.type = PageType.IMAGE;
this.image = image;
this.text = caption;
}
/**
* This function should really not be called directly - used internally
*/
public ResearchPage(AspectList as)
{
this.type = PageType.ASPECTS;
this.aspects = as;
}
/**
* returns a localized text of the text field (if one exists). Returns the text field itself otherwise.
* @return
*/
public String getTranslatedText()
{
String ret = "";
if (text != null)
{
ret = StatCollector.translateToLocal(text);
if (ret.isEmpty())
{
ret = text;
}
}
return ret;
}
}

View file

@ -0,0 +1,55 @@
package thaumcraft.api.research;
import net.minecraft.entity.Entity;
public class ScanResult
{
public byte type = 0; //1=blocks,2=entities,3=phenomena
public int blockId;
public int blockMeta;
public Entity entity;
public String phenomena;
public ScanResult(byte type, int blockId, int blockMeta, Entity entity,
String phenomena)
{
super();
this.type = type;
this.blockId = blockId;
this.blockMeta = blockMeta;
this.entity = entity;
this.phenomena = phenomena;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof ScanResult)
{
ScanResult sr = (ScanResult) obj;
if (type != sr.type)
{
return false;
}
if (type == 1
&& (blockId != sr.blockId || blockMeta != sr.blockMeta))
{
return false;
}
if (type == 2 && entity.entityId != sr.entity.entityId)
{
return false;
}
if (type == 3 && !phenomena.equals(sr.phenomena))
{
return false;
}
}
return true;
}
}