From 7af53ce85bd3d291b59e66c73e76f70100a1e639 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 23 Feb 2016 22:48:15 -0800 Subject: [PATCH] Add AltarCraftedEvent Called after an altar has crafted an item. Not cancellable, however the output itemstack may be modified. --- .../bloodmagic/altar/BloodAltar.java | 5 +++ .../api/event/AltarCraftedEvent.java | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/java/WayofTime/bloodmagic/api/event/AltarCraftedEvent.java diff --git a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java index e9598e26..b96b46b6 100644 --- a/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java +++ b/src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java @@ -2,6 +2,7 @@ package WayofTime.bloodmagic.altar; import java.util.List; +import WayofTime.bloodmagic.api.event.AltarCraftedEvent; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -10,6 +11,7 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumParticleTypes; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; import net.minecraftforge.fluids.FluidStack; @@ -73,6 +75,7 @@ public class BloodAltar implements IFluidHandler private int cooldownAfterCrafting = 60; + private AltarRecipe recipe; private ItemStack result; public BloodAltar(TileAltar tileAltar) @@ -311,6 +314,7 @@ public class BloodAltar implements IFluidHandler if (recipe.doesRequiredItemMatch(tileAltar.getStackInSlot(0), altarTier)) { this.isActive = true; + this.recipe = recipe; this.result = recipe.getOutput() == null ? null : new ItemStack(recipe.getOutput().getItem(), 1, recipe.getOutput().getMetadata()); this.liquidRequired = recipe.getSyphon(); this.canBeFilled = recipe.isFillable(); @@ -448,6 +452,7 @@ public class BloodAltar implements IFluidHandler if (result != null) result.stackSize *= stackSize; + MinecraftForge.EVENT_BUS.post(new AltarCraftedEvent(recipe, result)); tileAltar.setInventorySlotContents(0, result); progress = 0; diff --git a/src/main/java/WayofTime/bloodmagic/api/event/AltarCraftedEvent.java b/src/main/java/WayofTime/bloodmagic/api/event/AltarCraftedEvent.java new file mode 100644 index 00000000..b83a252f --- /dev/null +++ b/src/main/java/WayofTime/bloodmagic/api/event/AltarCraftedEvent.java @@ -0,0 +1,31 @@ +package WayofTime.bloodmagic.api.event; + +import WayofTime.bloodmagic.api.registry.AltarRecipeRegistry; +import lombok.Getter; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.eventhandler.Event; + +/** + * Fired whenever a craft is completed in a BloodAltar. + * + * It is not cancelable, however you can modify the output stack. + */ +@Getter +public class AltarCraftedEvent extends Event +{ + + private final AltarRecipeRegistry.AltarRecipe altarRecipe; + private final ItemStack output; + + /** + * @param altarRecipe + * - The recipe that was crafted. + * @param output + * - The item obtained from the recipe + */ + public AltarCraftedEvent(AltarRecipeRegistry.AltarRecipe altarRecipe, ItemStack output) + { + this.altarRecipe = altarRecipe; + this.output = output; + } +}