API: Add IRecipeKeyProvider.

This commit is contained in:
Vasco Lavos committed 2014-03-20 18:13:38 +00:00
1 parent b41ae75007
commit 05d7da5c99
3 files changed
+33 -9

No files matched your search

@@ -0,0 +1,24 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under a
* Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License
* (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB)
*
* File Created @ [Mar 20, 2014, 6:08:48 PM (GMT)]
*/
package vazkii.botania.api.lexicon;
import net.minecraft.item.ItemStack;
/**
* Have an Item implement this so that the method used for mapping it into
* the lexicon recipe mappings isn't the typical id:meta key.
*/
public interface IRecipeKeyProvider {
public String getKey(ItemStack stack);
}
@@ -15,9 +15,6 @@ import java.util.HashMap;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.api.ISpecialFlower;
import vazkii.botania.api.subtile.SubTileEntity;
/**
* This class contains mappings for which entry and page correspond to each
@@ -49,11 +46,8 @@ public final class LexiconRecipeMappings {
}
public static String stackToString(ItemStack stack) {
if(stack.hasTagCompound() && stack.getItem() instanceof ISpecialFlower) {
NBTTagCompound cmp = stack.getTagCompound();
if(cmp.hasKey(SubTileEntity.TAG_TYPE))
return cmp.getString(SubTileEntity.TAG_TYPE);
}
if(stack.hasTagCompound() && stack.getItem() instanceof IRecipeKeyProvider)
return ((IRecipeKeyProvider) stack.getItem()).getKey(stack);
return stack.itemID + ":" + stack.getItemDamage();
}
@@ -22,6 +22,7 @@ import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import vazkii.botania.api.BotaniaAPI;
import vazkii.botania.api.ISpecialFlower;
import vazkii.botania.api.lexicon.IRecipeKeyProvider;
import vazkii.botania.api.subtile.SubTileEntity;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.tile.TileSpecialFlower;
@@ -29,7 +30,7 @@ import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibBlockNames;
import cpw.mods.fml.common.network.PacketDispatcher;
public class ItemBlockSpecialFlower extends ItemBlock implements ISpecialFlower {
public class ItemBlockSpecialFlower extends ItemBlock implements IRecipeKeyProvider {
public ItemBlockSpecialFlower(int par1) {
super(par1);
@@ -82,4 +83,9 @@ public class ItemBlockSpecialFlower extends ItemBlock implements ISpecialFlower
return stack;
}
@Override
public String getKey(ItemStack stack) {
return getType(stack);
}
}