diff --git a/src/main/java/WayofTime/bloodmagic/api/recipe/ShapedBloodOrbRecipe.java b/src/main/java/WayofTime/bloodmagic/api/recipe/ShapedBloodOrbRecipe.java index 0469089f..8ceead6e 100644 --- a/src/main/java/WayofTime/bloodmagic/api/recipe/ShapedBloodOrbRecipe.java +++ b/src/main/java/WayofTime/bloodmagic/api/recipe/ShapedBloodOrbRecipe.java @@ -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; diff --git a/src/main/java/WayofTime/bloodmagic/api/recipe/ShapelessBloodOrbRecipe.java b/src/main/java/WayofTime/bloodmagic/api/recipe/ShapelessBloodOrbRecipe.java index 00e45c50..8404426f 100644 --- a/src/main/java/WayofTime/bloodmagic/api/recipe/ShapelessBloodOrbRecipe.java +++ b/src/main/java/WayofTime/bloodmagic/api/recipe/ShapelessBloodOrbRecipe.java @@ -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; diff --git a/src/main/java/WayofTime/bloodmagic/api/registry/OrbRegistry.java b/src/main/java/WayofTime/bloodmagic/api/registry/OrbRegistry.java index 7c1ce86d..bb6a47ff 100644 --- a/src/main/java/WayofTime/bloodmagic/api/registry/OrbRegistry.java +++ b/src/main/java/WayofTime/bloodmagic/api/registry/OrbRegistry.java @@ -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 orbs = new ArrayList(); + @Getter + private static ArrayListMultimap 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 getOrbsForTier(int tier) + { + if (getTierMap().containsKey(tier)) + return getTierMap().get(tier); + + return Collections.emptyList(); + } + + public static List getOrbsUpToTier(int tier) + { + List ret = new ArrayList(); + + for (int i = 1; i <= tier; i++) + ret.addAll(getOrbsForTier(i)); + + return ret; + } + + public static List getOrbsDownToTier(int tier) + { + List ret = new ArrayList(); + + 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)); diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/BloodMagicPlugin.java b/src/main/java/WayofTime/bloodmagic/compat/jei/BloodMagicPlugin.java index bece7c48..2c449576 100644 --- a/src/main/java/WayofTime/bloodmagic/compat/jei/BloodMagicPlugin.java +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/BloodMagicPlugin.java @@ -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); } } diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeHandler.java b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeHandler.java new file mode 100644 index 00000000..4c4b35de --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeHandler.java @@ -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 +{ + + @Nonnull + @Override + public Class 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; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeJEI.java b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeJEI.java new file mode 100644 index 00000000..c5410fc1 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapedOrbRecipeJEI.java @@ -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 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 getFluidInputs() + { + return null; + } + + @Override + public List 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 getTooltipStrings(int mouseX, int mouseY) + { + return null; + } + + @Override + public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton) + { + return false; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeHandler.java b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeHandler.java new file mode 100644 index 00000000..0af2ff69 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeHandler.java @@ -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 +{ + + @Nonnull + @Override + public Class 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; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeJEI.java b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeJEI.java new file mode 100644 index 00000000..3646e069 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/orb/ShapelessOrbRecipeJEI.java @@ -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 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 getFluidInputs() + { + return null; + } + + @Override + public List 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 getTooltipStrings(int mouseX, int mouseY) + { + return null; + } + + @Override + public boolean handleClick(@Nonnull Minecraft minecraft, int mouseX, int mouseY, int mouseButton) + { + return false; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java index c255a4e2..529010b0 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java @@ -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)));