Added the framework for a ritual that grants downgrades (instead of the potion method)

This commit is contained in:
WayofTime 2016-10-08 21:23:16 -04:00
parent 43f86abc58
commit ed8427c04e
13 changed files with 661 additions and 4 deletions

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.api.livingArmour;
import com.google.common.collect.Multimap;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
@ -16,6 +17,8 @@ public interface ILivingArmour
{
Multimap<String, AttributeModifier> getAttributeModifiers();
boolean canApplyUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade);
boolean upgradeArmour(EntityPlayer user, LivingArmourUpgrade upgrade);
boolean removeUpgrade(EntityPlayer user, LivingArmourUpgrade upgrade);

View file

@ -0,0 +1,135 @@
package WayofTime.bloodmagic.api.recipe;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
public class LivingArmourDowngradeRecipe
{
protected LivingArmourUpgrade upgrade = null;
protected ItemStack keyStack = null;
protected ArrayList<Object> input = new ArrayList<Object>();
public LivingArmourDowngradeRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe)
{
this.upgrade = upgrade;
this.keyStack = keyStack;
for (Object in : recipe)
{
if (in instanceof ItemStack)
{
input.add(((ItemStack) in).copy());
} else if (in instanceof Item)
{
input.add(new ItemStack((Item) in));
} else if (in instanceof Block)
{
input.add(new ItemStack((Block) in));
} else if (in instanceof String)
{
input.add(OreDictionary.getOres((String) in));
} else
{
String ret = "Invalid living armour downgrade recipe: ";
for (Object tmp : recipe)
{
ret += tmp + ", ";
}
ret += upgrade.toString();
throw new RuntimeException(ret);
}
}
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return input.size();
}
public LivingArmourUpgrade getRecipeOutput()
{
return upgrade;
}
/**
* Used to check if a recipe matches current crafting inventory. World and
* BlockPos are for future-proofing
*/
@SuppressWarnings("unchecked")
public boolean matches(ItemStack key, List<ItemStack> checkedList, World world, BlockPos pos)
{
if (!OreDictionary.itemMatches(keyStack, key, false))
{
return false;
}
ArrayList<Object> required = new ArrayList<Object>(input);
for (int x = 0; x < checkedList.size(); x++)
{
ItemStack slot = checkedList.get(x);
if (slot != null)
{
boolean inRecipe = false;
Iterator<Object> req = required.iterator();
while (req.hasNext())
{
boolean match = false;
Object next = req.next();
if (next instanceof ItemStack)
{
match = OreDictionary.itemMatches((ItemStack) next, slot, false);
} else if (next instanceof List)
{
Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
while (itr.hasNext() && !match)
{
match = OreDictionary.itemMatches(itr.next(), slot, false);
}
}
if (match)
{
inRecipe = true;
required.remove(next);
break;
}
}
if (!inRecipe)
{
return false;
}
}
}
return required.isEmpty();
}
/**
* Returns the input for this recipe, any mod accessing this value should
* never manipulate the values in this array as it will effect the recipe
* itself.
*
* @return The recipes input vales.
*/
public ArrayList<Object> getInput()
{
return this.input;
}
}

View file

@ -0,0 +1,72 @@
package WayofTime.bloodmagic.api.registry;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.bloodmagic.api.livingArmour.LivingArmourUpgrade;
import WayofTime.bloodmagic.api.recipe.LivingArmourDowngradeRecipe;
public class LivingArmourDowngradeRecipeRegistry
{
private static List<LivingArmourDowngradeRecipe> recipeList = new ArrayList<LivingArmourDowngradeRecipe>();
private static Map<ItemStack, Map<Integer, List<ITextComponent>>> dialogueMap = new HashMap<ItemStack, Map<Integer, List<ITextComponent>>>();
public static void registerRecipe(LivingArmourDowngradeRecipe recipe)
{
recipeList.add(recipe);
}
public static void registerDialog(ItemStack keyStack, Map<Integer, List<ITextComponent>> map)
{
dialogueMap.put(keyStack, map);
}
public static List<ITextComponent> getDialogForProcessTick(ItemStack keyStack, int tick)
{
for (Entry<ItemStack, Map<Integer, List<ITextComponent>>> entry : dialogueMap.entrySet())
{
ItemStack key = entry.getKey();
if (OreDictionary.itemMatches(key, keyStack, false))
{
Map<Integer, List<ITextComponent>> map = entry.getValue();
if (map.containsKey(tick))
{
return map.get(tick);
}
}
}
return null;
}
public static void registerRecipe(LivingArmourUpgrade upgrade, ItemStack keyStack, Object... recipe)
{
registerRecipe(new LivingArmourDowngradeRecipe(upgrade, keyStack, recipe));
}
public static LivingArmourDowngradeRecipe getMatchingRecipe(ItemStack keyStack, List<ItemStack> itemList, World world, BlockPos pos)
{
for (LivingArmourDowngradeRecipe recipe : recipeList)
{
if (recipe.matches(keyStack, itemList, world, pos))
{
return recipe;
}
}
return null;
}
public static List<LivingArmourDowngradeRecipe> getRecipeList()
{
return new ArrayList<LivingArmourDowngradeRecipe>(recipeList);
}
}