diff --git a/src/api/java/WayofTime/bloodmagic/api/event/BloodMagicCraftedEvent.java b/src/api/java/WayofTime/bloodmagic/api/event/BloodMagicCraftedEvent.java index 1df4bb13..0b92284c 100644 --- a/src/api/java/WayofTime/bloodmagic/api/event/BloodMagicCraftedEvent.java +++ b/src/api/java/WayofTime/bloodmagic/api/event/BloodMagicCraftedEvent.java @@ -1,16 +1,17 @@ package WayofTime.bloodmagic.api.event; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.Ingredient; import net.minecraftforge.fml.common.eventhandler.Event; public class BloodMagicCraftedEvent extends Event { private final boolean modifiable; + private final ItemStack[] inputs; private ItemStack output; - public BloodMagicCraftedEvent(ItemStack output, boolean modifiable) { + public BloodMagicCraftedEvent(ItemStack output, ItemStack[] inputs, boolean modifiable) { this.modifiable = modifiable; + this.inputs = inputs; this.output = output; } @@ -18,6 +19,10 @@ public class BloodMagicCraftedEvent extends Event { return modifiable; } + public ItemStack[] getInputs() { + return inputs; + } + public ItemStack getOutput() { return output; } @@ -28,22 +33,39 @@ public class BloodMagicCraftedEvent extends Event { } /** - * Fired whenever a craft is completed in a BloodAltar. - *

+ * Fired whenever a craft is completed in a Blood Altar. + * * It is not cancelable, however you can modify the output stack. */ public static class Altar extends BloodMagicCraftedEvent { - private final Ingredient input; - - public Altar(Ingredient input, ItemStack output) { - super(output, true); - - this.input = input; - } - - public Ingredient getInput() { - return input; + public Altar(ItemStack output, ItemStack input) { + super(output, new ItemStack[] { input }, true); } } + + /** + * Fired whenever a craft is completed in a Soul Forge. + * + * It is not cancelable, however you can modify the output stack. + */ + public static class SoulForge extends BloodMagicCraftedEvent { + + public SoulForge(ItemStack output, ItemStack[] inputs) { + super(output, inputs, true); + } + } + + /** + * Fired whenever a craft is completed in an Alchemy Table. + * + * It is not cancelable, however you can modify the output stack. + */ + public static class AlchemyTable extends BloodMagicCraftedEvent { + + public AlchemyTable(ItemStack output, ItemStack[] inputs) { + super(output, inputs, true); + } + } + } diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java index fd9de09f..11b9e8eb 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileAlchemyTable.java @@ -3,6 +3,7 @@ package WayofTime.bloodmagic.tile; import java.util.ArrayList; import java.util.List; +import WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent; import net.minecraft.block.state.IBlockState; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -12,6 +13,7 @@ import net.minecraft.tileentity.TileEntityHopper; import net.minecraft.util.EnumFacing; import net.minecraft.util.ITickable; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.ItemHandlerHelper; @@ -26,6 +28,7 @@ import WayofTime.bloodmagic.orb.IBloodOrb; import WayofTime.bloodmagic.recipe.alchemyTable.AlchemyTableRecipe; import WayofTime.bloodmagic.util.Constants; import WayofTime.bloodmagic.util.helper.NetworkHelper; +import org.apache.commons.lang3.ArrayUtils; public class TileAlchemyTable extends TileInventory implements ISidedInventory, ITickable { @@ -315,11 +318,18 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, } } + ItemStack[] inputs = new ItemStack[0]; + for (ItemStack stack : inputList) + ArrayUtils.add(inputs, stack.copy()); + + BloodMagicCraftedEvent.AlchemyTable event = new BloodMagicCraftedEvent.AlchemyTable(recipeAlchemyTable.getOutput().copy(), inputs); + MinecraftForge.EVENT_BUS.post(event); + ItemStack outputSlotStack = getStackInSlot(outputSlot); if (outputSlotStack.isEmpty()) - setInventorySlotContents(outputSlot, recipeAlchemyTable.getOutput().copy()); + setInventorySlotContents(outputSlot, event.getOutput()); else - outputSlotStack.grow(recipeAlchemyTable.getOutput().getCount()); + outputSlotStack.grow(event.getOutput().getCount()); for (int i = 0; i < 6; i++) { @@ -399,11 +409,19 @@ public class TileAlchemyTable extends TileInventory implements ISidedInventory, public void craftItem(List inputList, AlchemyTableRecipe recipe) { - if (this.canCraft(recipe.getRecipeOutput(inputList))) + ItemStack outputStack = recipe.getRecipeOutput(inputList); + if (this.canCraft(outputStack)) { - ItemStack outputStack = recipe.getRecipeOutput(inputList); ItemStack currentOutputStack = getStackInSlot(outputSlot); + ItemStack[] inputs = new ItemStack[0]; + for (ItemStack stack : inputList) + ArrayUtils.add(inputs, stack.copy()); + + BloodMagicCraftedEvent.AlchemyTable event = new BloodMagicCraftedEvent.AlchemyTable(outputStack.copy(), inputs); + MinecraftForge.EVENT_BUS.post(event); + outputStack = event.getOutput(); + if (currentOutputStack.isEmpty()) { setInventorySlotContents(outputSlot, outputStack); diff --git a/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java b/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java index 3640b6c7..4e737ae9 100644 --- a/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java +++ b/src/main/java/WayofTime/bloodmagic/tile/TileSoulForge.java @@ -1,5 +1,6 @@ package WayofTime.bloodmagic.tile; +import WayofTime.bloodmagic.api.event.BloodMagicCraftedEvent; import WayofTime.bloodmagic.api.impl.BloodMagicAPI; import WayofTime.bloodmagic.api.impl.recipe.RecipeTartaricForge; import WayofTime.bloodmagic.util.Constants; @@ -11,6 +12,7 @@ import WayofTime.bloodmagic.demonAura.WorldDemonWillHandler; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.items.ItemHandlerHelper; import java.util.ArrayList; @@ -132,10 +134,18 @@ public class TileSoulForge extends TileInventory implements ITickable, IDemonWil if (this.canCraft(recipe)) { ItemStack currentOutputStack = getStackInSlot(outputSlot); + List inputList = new ArrayList<>(); + for (int i = 0; i < 4; i++) + if (!getStackInSlot(i).isEmpty()) + inputList.add(getStackInSlot(i).copy()); + + BloodMagicCraftedEvent.SoulForge event = new BloodMagicCraftedEvent.SoulForge(recipe.getOutput().copy(), inputList.toArray(new ItemStack[0])); + MinecraftForge.EVENT_BUS.post(event); + if (currentOutputStack.isEmpty()) { - setInventorySlotContents(outputSlot, recipe.getOutput().copy()); - } else if (ItemHandlerHelper.canItemStacksStack(currentOutputStack, recipe.getOutput())) { - currentOutputStack.grow(recipe.getOutput().getCount()); + setInventorySlotContents(outputSlot, event.getOutput()); + } else if (ItemHandlerHelper.canItemStacksStack(currentOutputStack, event.getOutput())) { + currentOutputStack.grow(event.getOutput().getCount()); } consumeInventory();