JEI support for Blood Orb recipe type

We can now move all the recipes over to Shape(d/less)BloodOrbRecipe
This commit is contained in:
Nick 2016-02-16 20:48:42 -08:00
parent 65dd24b19b
commit af193c3e5b
9 changed files with 384 additions and 14 deletions

View file

@ -105,9 +105,15 @@ public class ShapedBloodOrbRecipe implements IRecipe
// If the item is an instanceof IBloodOrb then save the level of
// the orb.
if (in instanceof ItemStack)
itemMap.put(chr, ((IBloodOrb) ((ItemStack) in).getItem()).getOrbLevel(((ItemStack) in).getItemDamage()));
else
itemMap.put(chr, ((IBloodOrb) in).getOrbLevel(((ItemStack) in).getItemDamage()));
{
ItemStack inStack = (ItemStack) in;
tier = ((IBloodOrb) inStack.getItem()).getOrbLevel(inStack.getItemDamage());
itemMap.put(chr, tier);
} else
{
tier = ((IBloodOrb) in).getOrbLevel(0);
itemMap.put(chr, tier);
}
} else if (in instanceof ItemStack)
{
itemMap.put(chr, ((ItemStack) in).copy());
@ -238,7 +244,6 @@ public class ShapedBloodOrbRecipe implements IRecipe
if (slot != null && slot.getItem() instanceof IBloodOrb)
{
IBloodOrb orb = (IBloodOrb) slot.getItem();
tier = (Integer) target;
if (orb.getOrbLevel(slot.getItemDamage()) < (Integer) target)
{
return false;

View file

@ -40,13 +40,23 @@ public class ShapelessBloodOrbRecipe implements IRecipe
output = result.copy();
for (Object in : recipe)
{
if (in instanceof ItemStack)
if (in instanceof IBloodOrb || (in instanceof ItemStack && ((ItemStack) in).getItem() instanceof IBloodOrb))
{
if (((ItemStack) in).getItem() instanceof IBloodOrb)
// If the item is an instanceof IBloodOrb then save the level of
// the orb.
if (in instanceof ItemStack)
{
input.add(((IBloodOrb) ((ItemStack) in).getItem()).getOrbLevel(((ItemStack) in).getItemDamage()));
ItemStack inStack = (ItemStack) in;
tier = ((IBloodOrb) inStack.getItem()).getOrbLevel(inStack.getItemDamage());
input.add(tier);
} else
input.add(((ItemStack) in).copy());
{
tier = ((IBloodOrb) in).getOrbLevel(0);
input.add(tier);
}
}else if (in instanceof ItemStack)
{
input.add(((ItemStack) in).copy());
} else if (in instanceof Item)
{
input.add(new ItemStack((Item) in));
@ -134,7 +144,6 @@ public class ShapelessBloodOrbRecipe implements IRecipe
if (slot.getItem() instanceof IBloodOrb)
{
IBloodOrb orb = (IBloodOrb) slot.getItem();
tier = (Integer) next;
if (orb.getOrbLevel(slot.getItemDamage()) < (Integer) next)
{
return false;

View file

@ -2,7 +2,10 @@ package WayofTime.bloodmagic.api.registry;
import WayofTime.bloodmagic.api.BloodMagicAPI;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.altar.EnumAltarTier;
import WayofTime.bloodmagic.api.orb.BloodOrb;
import WayofTime.bloodmagic.api.orb.IBloodOrb;
import com.google.common.collect.ArrayListMultimap;
import lombok.Getter;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
@ -14,6 +17,7 @@ import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@ -24,17 +28,28 @@ public class OrbRegistry
{
@Getter
private static List<BloodOrb> orbs = new ArrayList<BloodOrb>();
@Getter
private static ArrayListMultimap<Integer, ItemStack> tierMap = ArrayListMultimap.create();
private static Item orbItem = Constants.BloodMagicItem.BLOOD_ORB.getItem();
public static void registerOrb(BloodOrb orb)
{
if (!orbs.contains(orb))
{
orbs.add(orb);
registerOrbForTier(orb.getTier(), getOrbStack(orb));
}
else
BloodMagicAPI.getLogger().error("Error adding orb %s. Orb already exists!", orb.toString());
}
public static void registerOrbForTier(int tier, ItemStack stack)
{
if (stack.getItem() instanceof IBloodOrb)
tierMap.put(tier, stack);
}
@SideOnly(Side.CLIENT)
public static void registerOrbTexture(BloodOrb orb, ResourceLocation resourceLocation)
{
@ -64,6 +79,34 @@ public class OrbRegistry
return orbs.size();
}
public static List<ItemStack> getOrbsForTier(int tier)
{
if (getTierMap().containsKey(tier))
return getTierMap().get(tier);
return Collections.emptyList();
}
public static List<ItemStack> getOrbsUpToTier(int tier)
{
List<ItemStack> ret = new ArrayList<ItemStack>();
for (int i = 1; i <= tier; i++)
ret.addAll(getOrbsForTier(i));
return ret;
}
public static List<ItemStack> getOrbsDownToTier(int tier)
{
List<ItemStack> ret = new ArrayList<ItemStack>();
for (int i = EnumAltarTier.MAXTIERS; i >= tier; i--)
ret.addAll(getOrbsForTier(i));
return ret;
}
public static ItemStack getOrbStack(BloodOrb orb)
{
return new ItemStack(orbItem, 1, getIndexOf(orb));

View file

@ -14,6 +14,8 @@ import WayofTime.bloodmagic.compat.jei.binding.BindingRecipeMaker;
import WayofTime.bloodmagic.compat.jei.forge.TartaricForgeRecipeCategory;
import WayofTime.bloodmagic.compat.jei.forge.TartaricForgeRecipeHandler;
import WayofTime.bloodmagic.compat.jei.forge.TartaricForgeRecipeMaker;
import WayofTime.bloodmagic.compat.jei.orb.ShapedOrbRecipeHandler;
import WayofTime.bloodmagic.compat.jei.orb.ShapelessOrbRecipeHandler;
import WayofTime.bloodmagic.item.ItemUpgradeTome;
import WayofTime.bloodmagic.registry.ModBlocks;
import WayofTime.bloodmagic.registry.ModItems;
@ -32,7 +34,7 @@ public class BloodMagicPlugin implements IModPlugin
{
registry.addRecipeCategories(new AltarRecipeCategory(), new BindingRecipeCategory(), new AlchemyArrayCraftingCategory(), new TartaricForgeRecipeCategory());
registry.addRecipeHandlers(new AltarRecipeHandler(), new BindingRecipeHandler(), new AlchemyArrayCraftingRecipeHandler(), new TartaricForgeRecipeHandler());
registry.addRecipeHandlers(new AltarRecipeHandler(), new BindingRecipeHandler(), new AlchemyArrayCraftingRecipeHandler(), new TartaricForgeRecipeHandler(), new ShapedOrbRecipeHandler(), new ShapelessOrbRecipeHandler());
registry.addRecipes(AltarRecipeMaker.getRecipes());
registry.addRecipes(BindingRecipeMaker.getRecipes());
@ -53,8 +55,8 @@ public class BloodMagicPlugin implements IModPlugin
for (int i = 0; i < maxLevel - 1; i++)
{
ItemStack stack = new ItemStack(ModItems.upgradeTome);
((ItemUpgradeTome)ModItems.upgradeTome).setKey(stack, key);
((ItemUpgradeTome)ModItems.upgradeTome).setLevel(stack, i);
ItemUpgradeTome.setKey(stack, key);
ItemUpgradeTome.setLevel(stack, i);
jeiHelper.getItemBlacklist().addItemToBlacklist(stack);
}
}

View file

@ -0,0 +1,40 @@
package WayofTime.bloodmagic.compat.jei.orb;
import WayofTime.bloodmagic.api.recipe.ShapedBloodOrbRecipe;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import javax.annotation.Nonnull;
import java.util.Arrays;
public class ShapedOrbRecipeHandler implements IRecipeHandler<ShapedBloodOrbRecipe>
{
@Nonnull
@Override
public Class<ShapedBloodOrbRecipe> getRecipeClass()
{
return ShapedBloodOrbRecipe.class;
}
@Nonnull
@Override
public String getRecipeCategoryUid()
{
return VanillaRecipeCategoryUid.CRAFTING;
}
@Nonnull
@Override
public IRecipeWrapper getRecipeWrapper(@Nonnull ShapedBloodOrbRecipe recipe)
{
return new ShapedOrbRecipeJEI(Arrays.asList(recipe.getInput()), recipe.getTier(), recipe.getRecipeOutput());
}
@Override
public boolean isRecipeValid(@Nonnull ShapedBloodOrbRecipe recipe)
{
return recipe.getInput().length > 0;
}
}

View file

@ -0,0 +1,122 @@
package WayofTime.bloodmagic.compat.jei.orb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.util.helper.TextHelper;
import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ShapedOrbRecipeJEI implements IShapedCraftingRecipeWrapper
{
@Nonnull
private final List inputs;
private final int tier;
@Nonnull
private final ItemStack output;
@SuppressWarnings("unchecked")
public ShapedOrbRecipeJEI(@Nonnull List input, int tier, @Nonnull ItemStack output)
{
ArrayList inputList = new ArrayList(input);
int replaceIndex = 0;
Object toReplace = null;
for (Object object : inputList)
{
if (object instanceof Integer)
{
replaceIndex = inputList.indexOf(object);
toReplace = object;
}
}
if (toReplace != null)
{
inputList.remove(replaceIndex);
inputList.add(replaceIndex, OrbRegistry.getOrbsDownToTier((Integer) toReplace));
}
this.inputs = inputList;
this.tier = tier;
this.output = output;
}
@Override
public int getWidth()
{
return 3;
}
@Override
public int getHeight()
{
return 3;
}
@Override
public List getInputs()
{
return inputs;
}
@Override
public List<ItemStack> getOutputs()
{
return Collections.singletonList(output);
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight)
{
String draw = TextHelper.localize("jei.BloodMagic.recipe.requiredTier", tier);
minecraft.fontRendererObj.drawString(draw, 72 - minecraft.fontRendererObj.getStringWidth(draw) / 2, 10, Color.gray.getRGB());
}
@Override
public List<FluidStack> getFluidInputs()
{
return null;
}
@Override
public List<FluidStack> getFluidOutputs()
{
return null;
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY)
{
}
@Override
public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight)
{
}
@Nullable
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY)
{
return null;
}
@Override
public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton)
{
return false;
}
}

View file

@ -0,0 +1,39 @@
package WayofTime.bloodmagic.compat.jei.orb;
import WayofTime.bloodmagic.api.recipe.ShapelessBloodOrbRecipe;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
import javax.annotation.Nonnull;
public class ShapelessOrbRecipeHandler implements IRecipeHandler<ShapelessBloodOrbRecipe>
{
@Nonnull
@Override
public Class<ShapelessBloodOrbRecipe> getRecipeClass()
{
return ShapelessBloodOrbRecipe.class;
}
@Nonnull
@Override
public String getRecipeCategoryUid()
{
return VanillaRecipeCategoryUid.CRAFTING;
}
@Nonnull
@Override
public IRecipeWrapper getRecipeWrapper(@Nonnull ShapelessBloodOrbRecipe recipe)
{
return new ShapelessOrbRecipeJEI(recipe.getInput(), recipe.getTier(), recipe.getRecipeOutput());
}
@Override
public boolean isRecipeValid(@Nonnull ShapelessBloodOrbRecipe recipe)
{
return recipe.getInput().size() > 0;
}
}

View file

@ -0,0 +1,110 @@
package WayofTime.bloodmagic.compat.jei.orb;
import WayofTime.bloodmagic.api.registry.OrbRegistry;
import WayofTime.bloodmagic.util.helper.TextHelper;
import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ShapelessOrbRecipeJEI implements ICraftingRecipeWrapper
{
@Nonnull
private final List inputs;
private final int tier;
@Nonnull
private final ItemStack output;
@SuppressWarnings("unchecked")
public ShapelessOrbRecipeJEI(@Nonnull List input, int tier, @Nonnull ItemStack output)
{
ArrayList inputList = new ArrayList(input);
int replaceIndex = 0;
Object toReplace = null;
for (Object object : inputList)
{
if (object instanceof Integer)
{
replaceIndex = inputList.indexOf(object);
toReplace = object;
}
}
if (toReplace != null)
{
inputList.remove(replaceIndex);
inputList.add(replaceIndex, OrbRegistry.getOrbsDownToTier((Integer) toReplace));
}
this.inputs = inputList;
this.tier = tier;
this.output = output;
}
@Override
public List getInputs()
{
return inputs;
}
@Override
public List<ItemStack> getOutputs()
{
return Collections.singletonList(output);
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight)
{
String draw = TextHelper.localize("jei.BloodMagic.recipe.requiredTier", tier);
minecraft.fontRendererObj.drawString(draw, 72 - minecraft.fontRendererObj.getStringWidth(draw) / 2, 10, Color.gray.getRGB());
}
@Override
public List<FluidStack> getFluidInputs()
{
return null;
}
@Override
public List<FluidStack> getFluidOutputs()
{
return null;
}
@Override
public void drawInfo(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY)
{
}
@Override
public void drawAnimations(@Nonnull Minecraft minecraft, int recipeWidth, int recipeHeight)
{
}
@Nullable
@Override
public List<String> getTooltipStrings(int mouseX, int mouseY)
{
return null;
}
@Override
public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton)
{
return false;
}
}

View file

@ -78,8 +78,8 @@ public class ModRecipes
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModItems.upgradeTrainer), "ngn", "ioi", "ngn", 'o', OrbRegistry.getOrbStack(ModItems.orbMaster), 'i', "ingotIron", 'n', "nuggetGold", 'g', "ingotGold"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(ModBlocks.incenseAltar), "s s", "shs", "coc", 'o', OrbRegistry.getOrbStack(ModItems.orbWeak), 's', "stone", 'c', "cobblestone", 'h', new ItemStack(Items.coal, 1, 1)));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ModBlocks.pathBlock, 4, 0), "plankWood", "plankWood", "plankWood", "plankWood", OrbRegistry.getOrbStack(ModItems.orbApprentice)));
GameRegistry.addRecipe(new ShapedBloodOrbRecipe(new ItemStack(ModBlocks.incenseAltar), "s s", "shs", "coc", 'o', OrbRegistry.getOrbStack(ModItems.orbWeak), 's', "stone", 'c', "cobblestone", 'h', new ItemStack(Items.coal, 1, 1)));
GameRegistry.addRecipe(new ShapelessBloodOrbRecipe(new ItemStack(ModBlocks.pathBlock, 4, 0), "plankWood", "plankWood", "plankWood", "plankWood", OrbRegistry.getOrbStack(ModItems.orbApprentice)));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ModBlocks.pathBlock, 4, 1), new ItemStack(ModBlocks.pathBlock, 1, 0), new ItemStack(ModBlocks.pathBlock, 1, 0), new ItemStack(ModBlocks.pathBlock, 1, 0), new ItemStack(ModBlocks.pathBlock, 1, 0)));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ModBlocks.pathBlock, 4, 2), "stone", "stone", "stone", "stone", OrbRegistry.getOrbStack(ModItems.orbMagician)));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(ModBlocks.pathBlock, 4, 3), new ItemStack(ModBlocks.pathBlock, 1, 2), new ItemStack(ModBlocks.pathBlock, 1, 2), new ItemStack(ModBlocks.pathBlock, 1, 2), new ItemStack(ModBlocks.pathBlock, 1, 2)));