mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-14 01:04:16 +00:00
Elven Trade recipes are now functional.
This commit is contained in:
1 parent
4a0c82fc01
commit
b4cb140db4
8 files changed
+179
-13
No files matched your search
@@ -35,6 +35,7 @@ import vazkii.botania.api.internal.IInternalMethodHandler;
|
||||
import vazkii.botania.api.lexicon.KnowledgeType;
|
||||
import vazkii.botania.api.lexicon.LexiconCategory;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.api.recipe.RecipeManaInfusion;
|
||||
import vazkii.botania.api.recipe.RecipePetals;
|
||||
import vazkii.botania.api.recipe.RecipeRuneAltar;
|
||||
@@ -53,6 +54,7 @@ public final class BotaniaAPI {
|
||||
public static List<RecipePetals> petalRecipes = new ArrayList<RecipePetals>();
|
||||
public static List<RecipeRuneAltar> runeAltarRecipes = new ArrayList<RecipeRuneAltar>();
|
||||
public static List<RecipeManaInfusion> manaInfusionRecipes = new ArrayList<RecipeManaInfusion>();
|
||||
public static List<RecipeElvenTrade> elvenTradeRecipes = new ArrayList<RecipeElvenTrade>();
|
||||
|
||||
private static BiMap<String, Class<? extends SubTileEntity>> subTiles = HashBiMap.<String, Class<? extends SubTileEntity>> create();
|
||||
public static Set<String> subtilesForCreativeMenu = new LinkedHashSet();
|
||||
@@ -194,6 +196,18 @@ public final class BotaniaAPI {
|
||||
recipe.setAlchemy(true);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a Elven Trade recipe (throw an item in an Alfheim Portal).
|
||||
* @param output The ItemStack to return.
|
||||
* @param inputs The items required, can be ItemStack or ore dictionary entry string.
|
||||
* @return The recipe created.
|
||||
*/
|
||||
public static RecipeElvenTrade registerElvenTradeRecipe(ItemStack output, Object... inputs) {
|
||||
RecipeElvenTrade recipe = new RecipeElvenTrade(output, inputs);
|
||||
elvenTradeRecipes.add(recipe);
|
||||
return recipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a SubTileEntity, a new special flower. Look in the subtile package of the API.
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package vazkii.botania.api.recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class RecipeElvenTrade {
|
||||
|
||||
ItemStack output;
|
||||
List<Object> inputs;
|
||||
|
||||
public RecipeElvenTrade(ItemStack output, Object... inputs) {
|
||||
this.output = output;
|
||||
|
||||
List<Object> inputsToSet = new ArrayList();
|
||||
for(Object obj : inputs) {
|
||||
if(obj instanceof String || obj instanceof ItemStack)
|
||||
inputsToSet.add(obj);
|
||||
else throw new IllegalArgumentException("Invalid input");
|
||||
}
|
||||
|
||||
this.inputs = inputsToSet;
|
||||
}
|
||||
|
||||
public boolean matches(List<ItemStack> stacks, boolean remove) {
|
||||
List<Object> inputsMissing = new ArrayList(inputs);
|
||||
List<Integer> indexesToRemove = new ArrayList();
|
||||
|
||||
int i = 0;
|
||||
for(ItemStack stack : stacks) {
|
||||
if(stack == null) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if(inputsMissing.isEmpty())
|
||||
break;
|
||||
|
||||
int stackIndex = -1, oredictIndex = -1;
|
||||
|
||||
for(int j = 0; j < inputsMissing.size(); j++) {
|
||||
Object input = inputsMissing.get(j);
|
||||
if(input instanceof String) {
|
||||
List<ItemStack> validStacks = OreDictionary.getOres((String) input);
|
||||
boolean found = false;
|
||||
for(ItemStack ostack : validStacks) {
|
||||
ItemStack cstack = ostack.copy();
|
||||
if(cstack.getItemDamage() == Short.MAX_VALUE)
|
||||
cstack.setItemDamage(stack.getItemDamage());
|
||||
|
||||
if(stack.isItemEqual(cstack)) {
|
||||
if(!indexesToRemove.contains(i))
|
||||
indexesToRemove.add(i);
|
||||
oredictIndex = j;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(found)
|
||||
break;
|
||||
} else if(input instanceof ItemStack && simpleAreStacksEqual((ItemStack) input, stack)) {
|
||||
stackIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(stackIndex != -1)
|
||||
inputsMissing.remove(stackIndex);
|
||||
else if(oredictIndex != -1)
|
||||
inputsMissing.remove(oredictIndex);
|
||||
i++;
|
||||
}
|
||||
|
||||
if(remove)
|
||||
for(int r : indexesToRemove)
|
||||
stacks.remove(r);
|
||||
|
||||
return inputsMissing.isEmpty();
|
||||
}
|
||||
|
||||
boolean simpleAreStacksEqual(ItemStack stack, ItemStack stack2) {
|
||||
return stack.getItem() == stack2.getItem() && stack.getItemDamage() == stack2.getItemDamage();
|
||||
}
|
||||
|
||||
public List<Object> getInputs() {
|
||||
return new ArrayList(inputs);
|
||||
}
|
||||
|
||||
public ItemStack getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package vazkii.botania.common.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import vazkii.botania.common.item.block.ItemBlockDreamwood;
|
||||
import vazkii.botania.common.item.block.ItemBlockPool;
|
||||
import vazkii.botania.common.lib.LibBlockNames;
|
||||
|
||||
public class BlockDreamwood extends BlockLivingwood {
|
||||
@@ -7,5 +11,9 @@ public class BlockDreamwood extends BlockLivingwood {
|
||||
public BlockDreamwood() {
|
||||
super(LibBlockNames.DREAM_WOOD);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void register(String name) {
|
||||
GameRegistry.registerBlock(this, ItemBlockDreamwood.class, name);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class BlockLivingwood extends BlockMod implements ILexiconable {
|
||||
protected boolean shouldRegisterInNameSet() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int damageDropped(int par1) {
|
||||
return par1;
|
||||
@@ -60,10 +60,14 @@ public class BlockLivingwood extends BlockMod implements ILexiconable {
|
||||
|
||||
@Override
|
||||
public Block setBlockName(String par1Str) {
|
||||
GameRegistry.registerBlock(this, ItemBlockWithMetadataAndName.class, par1Str);
|
||||
register(par1Str);
|
||||
return super.setBlockName(par1Str);
|
||||
}
|
||||
|
||||
|
||||
void register(String name) {
|
||||
GameRegistry.registerBlock(this, ItemBlockWithMetadataAndName.class, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
|
||||
for(int i = 0; i < TYPES; i++)
|
||||
|
||||
@@ -24,6 +24,7 @@ import net.minecraft.util.AxisAlignedBB;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.lexicon.ILexicon;
|
||||
import vazkii.botania.api.recipe.IElvenItem;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.common.Botania;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.block.tile.mana.TilePool;
|
||||
@@ -116,8 +117,6 @@ public class TileAlfPortal extends TileMod {
|
||||
if(ticksSinceLastItem >= 20) {
|
||||
if(!worldObj.isRemote)
|
||||
resolveRecipes();
|
||||
|
||||
ticksSinceLastItem = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +154,6 @@ public class TileAlfPortal extends TileMod {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 1 | 2);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 1 | 2);
|
||||
for(int i = 0; i < 36; i++)
|
||||
blockParticle(meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -192,13 +186,19 @@ public class TileAlfPortal extends TileMod {
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
// Handle recipe registry here
|
||||
for(RecipeElvenTrade recipe : BotaniaAPI.elvenTradeRecipes) {
|
||||
if(recipe.matches(stacksIn, false)) {
|
||||
recipe.matches(stacksIn, true);
|
||||
spawnItem(recipe.getOutput().copy());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void spawnItem(ItemStack stack) {
|
||||
EntityItem item = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, stack);
|
||||
worldObj.spawnEntityInWorld(item);
|
||||
ticksSinceLastItem = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,6 +30,7 @@ import vazkii.botania.common.core.handler.ManaNetworkHandler;
|
||||
import vazkii.botania.common.core.helper.Vector3;
|
||||
import vazkii.botania.common.core.version.CommandDownloadLatest;
|
||||
import vazkii.botania.common.crafting.ModCrafingRecipes;
|
||||
import vazkii.botania.common.crafting.ModElvenTradeRecipes;
|
||||
import vazkii.botania.common.crafting.ModManaAlchemyRecipes;
|
||||
import vazkii.botania.common.crafting.ModManaInfusionRecipes;
|
||||
import vazkii.botania.common.crafting.ModPetalRecipes;
|
||||
@@ -62,6 +63,7 @@ public class CommonProxy {
|
||||
ModRuneRecipes.init();
|
||||
ModManaInfusionRecipes.init();
|
||||
ModManaAlchemyRecipes.init();
|
||||
ModElvenTradeRecipes.init();
|
||||
|
||||
LexiconData.init();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package vazkii.botania.common.crafting;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.BotaniaAPI;
|
||||
import vazkii.botania.api.recipe.RecipeElvenTrade;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
import vazkii.botania.common.item.ModItems;
|
||||
import vazkii.botania.common.lib.LibOreDict;
|
||||
|
||||
public class ModElvenTradeRecipes {
|
||||
|
||||
public static RecipeElvenTrade dreamwoodRecipe;
|
||||
public static RecipeElvenTrade elementiumRecipe;
|
||||
public static RecipeElvenTrade pixieDustRecipe;
|
||||
public static RecipeElvenTrade dragonstoneRecipe;
|
||||
|
||||
public static void init() {
|
||||
dreamwoodRecipe = BotaniaAPI.registerElvenTradeRecipe(new ItemStack(ModBlocks.dreamwood), LibOreDict.LIVING_WOOD);
|
||||
elementiumRecipe = BotaniaAPI.registerElvenTradeRecipe(new ItemStack(ModItems.manaResource, 1, 7), LibOreDict.MANA_STEEL, LibOreDict.MANA_STEEL);
|
||||
pixieDustRecipe = BotaniaAPI.registerElvenTradeRecipe(new ItemStack(ModItems.manaResource, 1, 8), LibOreDict.MANA_PEARL);
|
||||
dragonstoneRecipe = BotaniaAPI.registerElvenTradeRecipe(new ItemStack(ModItems.manaResource, 1, 9), LibOreDict.MANA_DIAMOND);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package vazkii.botania.common.item.block;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import vazkii.botania.api.recipe.IElvenItem;
|
||||
|
||||
public class ItemBlockDreamwood extends ItemBlockWithMetadataAndName implements IElvenItem {
|
||||
|
||||
public ItemBlockDreamwood(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElvenItem(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user