diff --git a/src/main/java/WayofTime/bloodmagic/api/recipe/AlchemyTableRecipe.java b/src/main/java/WayofTime/bloodmagic/api/recipe/AlchemyTableRecipe.java index 74415832..457d180f 100644 --- a/src/main/java/WayofTime/bloodmagic/api/recipe/AlchemyTableRecipe.java +++ b/src/main/java/WayofTime/bloodmagic/api/recipe/AlchemyTableRecipe.java @@ -74,7 +74,15 @@ public class AlchemyTableRecipe return input.size(); } - public ItemStack getRecipeOutput() + /** + * Returns the output of the recipe, sensitive to the input list provided. + * If the input list does not technically match, the recipe should return + * the default output. + * + * @param inputList + * @return + */ + public ItemStack getRecipeOutput(List inputList) { return output.copy(); } diff --git a/src/main/java/WayofTime/bloodmagic/compat/jei/alchemyTable/AlchemyTableRecipeJEI.java b/src/main/java/WayofTime/bloodmagic/compat/jei/alchemyTable/AlchemyTableRecipeJEI.java index 6f41c45e..e0a00fc9 100644 --- a/src/main/java/WayofTime/bloodmagic/compat/jei/alchemyTable/AlchemyTableRecipeJEI.java +++ b/src/main/java/WayofTime/bloodmagic/compat/jei/alchemyTable/AlchemyTableRecipeJEI.java @@ -42,7 +42,7 @@ public class AlchemyTableRecipeJEI extends BlankRecipeWrapper @Nonnull public List getOutputs() { - return Collections.singletonList(recipe.getRecipeOutput()); + return Collections.singletonList(recipe.getRecipeOutput(new ArrayList())); } @Nullable diff --git a/src/main/java/WayofTime/bloodmagic/recipe/alchemyTable/AlchemyTableDyeableRecipe.java b/src/main/java/WayofTime/bloodmagic/recipe/alchemyTable/AlchemyTableDyeableRecipe.java new file mode 100644 index 00000000..465ecef2 --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/recipe/alchemyTable/AlchemyTableDyeableRecipe.java @@ -0,0 +1,144 @@ +package WayofTime.bloodmagic.recipe.alchemyTable; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.init.Items; +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.ItemBanner; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import WayofTime.bloodmagic.api.Constants; +import WayofTime.bloodmagic.api.recipe.AlchemyTableRecipe; + +public class AlchemyTableDyeableRecipe extends AlchemyTableRecipe +{ + private ItemStack inputItem; + + public AlchemyTableDyeableRecipe(int lpDrained, int ticksRequired, int tierRequired, ItemStack inputItem) + { + super(inputItem, lpDrained, ticksRequired, tierRequired); + + ArrayList validDyes = new ArrayList(); + validDyes.add(new ItemStack(Items.NAME_TAG)); + validDyes.add(new ItemStack(Items.DYE, 1, OreDictionary.WILDCARD_VALUE)); + + ArrayList recipe = new ArrayList(); + recipe.add(inputItem); + recipe.add(validDyes); + + this.input = recipe; + + this.inputItem = inputItem; + } + + @Override + public ItemStack getRecipeOutput(List inputList) + { + int nameTagOrDyeLocation = -1; + int inputItemLocation = -1; + for (int x = 0; x < inputList.size(); x++) + { + ItemStack slot = inputList.get(x); + + if (slot != null) + { + boolean match = OreDictionary.itemMatches(inputItem, slot, false); + + if (match) + { + inputItemLocation = x; + continue; + } else + { + if (slot.getItem() == Items.NAME_TAG || slot.getItem() == Items.DYE) + { + nameTagOrDyeLocation = x; + continue; + } + } + } + } + + if (nameTagOrDyeLocation != -1 && inputItemLocation != -1) + { + ItemStack tagOrDyeStack = inputList.get(nameTagOrDyeLocation); + ItemStack inputStack = inputList.get(inputItemLocation); + + if (inputStack == null || tagOrDyeStack == null) + { + return output.copy(); + } + + ItemStack outputStack = inputStack.copy(); + + if (tagOrDyeStack.getItem() == Items.NAME_TAG) + { + if (!outputStack.hasTagCompound()) + { + outputStack.setTagCompound(new NBTTagCompound()); + } + + outputStack.getTagCompound().setString(Constants.NBT.COLOR, tagOrDyeStack.getDisplayName()); + + return outputStack; + } else + { + EnumDyeColor dyeColor = ItemBanner.getBaseColor(tagOrDyeStack); + if (!outputStack.hasTagCompound()) + { + outputStack.setTagCompound(new NBTTagCompound()); + } + + outputStack.getTagCompound().setString(Constants.NBT.COLOR, String.valueOf(dyeColor.getMapColor().colorValue)); + + return outputStack; + } + } + + return output.copy(); + } + + @Override + public boolean matches(List checkedList, World world, BlockPos pos) + { + boolean hasNameTagOrDye = false; + boolean hasInputItem = false; + + for (int x = 0; x < checkedList.size(); x++) + { + ItemStack slot = checkedList.get(x); + + if (slot != null) + { + boolean match = OreDictionary.itemMatches(inputItem, slot, false); + + if (match && hasInputItem) + { + return false; + } else if (match) + { + hasInputItem = true; + continue; + } else + { + if (slot.getItem() == Items.NAME_TAG || slot.getItem() == Items.DYE) + { + if (hasNameTagOrDye) + { + return false; + } else + { + hasNameTagOrDye = true; + } + } + } + } + } + + return hasNameTagOrDye && hasInputItem; + } +} diff --git a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java index b6e71264..71f6d3c1 100644 --- a/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java +++ b/src/main/java/WayofTime/bloodmagic/registry/ModRecipes.java @@ -1,6 +1,5 @@ package WayofTime.bloodmagic.registry; -import WayofTime.bloodmagic.api.BloodMagicAPI; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -15,6 +14,7 @@ import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; import WayofTime.bloodmagic.BloodMagic; import WayofTime.bloodmagic.alchemyArray.AlchemyArrayEffectBinding; +import WayofTime.bloodmagic.api.BloodMagicAPI; import WayofTime.bloodmagic.api.Constants; import WayofTime.bloodmagic.api.altar.EnumAltarTier; import WayofTime.bloodmagic.api.compress.CompressionRegistry; @@ -36,6 +36,7 @@ import WayofTime.bloodmagic.item.ItemComponent; import WayofTime.bloodmagic.item.ItemDemonCrystal; import WayofTime.bloodmagic.item.alchemy.ItemCuttingFluid; import WayofTime.bloodmagic.item.soul.ItemSoulGem; +import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableDyeableRecipe; import com.google.common.base.Stopwatch; @@ -313,5 +314,7 @@ public class ModRecipes AlchemyTableRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.PLANT_OIL), 100, 100, 1, Items.POTATO, Items.POTATO, new ItemStack(Items.DYE, 1, 15)); AlchemyTableRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.PLANT_OIL), 100, 100, 1, Items.WHEAT, Items.WHEAT, new ItemStack(Items.DYE, 1, 15)); AlchemyTableRecipeRegistry.registerRecipe(ItemComponent.getStack(ItemComponent.PLANT_OIL), 100, 100, 1, Items.BEETROOT, Items.BEETROOT, Items.BEETROOT, new ItemStack(Items.DYE, 1, 15)); + + AlchemyTableRecipeRegistry.registerRecipe(new AlchemyTableDyeableRecipe(0, 100, 0, new ItemStack(ModItems.sigilHolding))); } } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java index cf6cba38..bb00f187 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java @@ -254,7 +254,7 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, worldObj.notifyBlockUpdate(getPos(), state, state, 3); } - if (canCraft(recipe)) + if (canCraft(inputList, recipe)) { ticksRequired = recipe.getTicksRequired(); burnTime++; @@ -274,7 +274,7 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, if (!worldObj.isRemote) { - craftItem(recipe); + craftItem(inputList, recipe); } } @@ -301,14 +301,14 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, return ((double) burnTime) / ticksRequired; } - private boolean canCraft(AlchemyTableRecipe recipe) + private boolean canCraft(List inputList, AlchemyTableRecipe recipe) { if (recipe == null) { return false; } - ItemStack outputStack = recipe.getRecipeOutput(); + ItemStack outputStack = recipe.getRecipeOutput(inputList); ItemStack currentOutputStack = getStackInSlot(outputSlot); if (outputStack == null) return false; @@ -365,11 +365,11 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, return 0; } - public void craftItem(AlchemyTableRecipe recipe) + public void craftItem(List inputList, AlchemyTableRecipe recipe) { - if (this.canCraft(recipe)) + if (this.canCraft(inputList, recipe)) { - ItemStack outputStack = recipe.getRecipeOutput(); + ItemStack outputStack = recipe.getRecipeOutput(inputList); ItemStack currentOutputStack = getStackInSlot(outputSlot); if (currentOutputStack == null)