Added a new ImbuementActivateEvent to allow addons hooking into the imbuement process
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
package electroblob.wizardry.event;
|
||||||
|
|
||||||
|
import electroblob.wizardry.constants.Element;
|
||||||
|
import electroblob.wizardry.tileentity.TileEntityImbuementAltar;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ImbuementActivateEvent is fired when {@link TileEntityImbuementAltar#getImbuementResult(net.minecraft.item.ItemStack, electroblob.wizardry.constants.Element[],
|
||||||
|
* boolean, net.minecraft.world.World, net.minecraft.entity.player.EntityPlayer)} is called to allow adding in imbuement "recipes" dynamically, based on the
|
||||||
|
* contents of the Imbuement altar's receptacles and the item placed on the altar.
|
||||||
|
*
|
||||||
|
* <i>Note that this event is only fired on the server side.</i><br>
|
||||||
|
* <br>
|
||||||
|
* To alter the result of the imbuement process, change the {@link electroblob.wizardry.event.ImbuementActivateEvent#result} result of the process.<br>
|
||||||
|
* <br>
|
||||||
|
* This event is {@link Cancelable}. If this event is canceled, no further processing takes place.<br>
|
||||||
|
* <br>
|
||||||
|
* This event does not have a result. {@link Event.HasResult}<br>
|
||||||
|
* <br>
|
||||||
|
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||||
|
*
|
||||||
|
* @author WinDanesz
|
||||||
|
* @since Wizardry 4.3.5
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public class ImbuementActivateEvent extends Event {
|
||||||
|
|
||||||
|
/** The item stack being imbued */
|
||||||
|
ItemStack input;
|
||||||
|
|
||||||
|
/** The elements of the four receptacles */
|
||||||
|
Element[] receptacleElements;
|
||||||
|
|
||||||
|
/** A reference to the current world object (may be null if {@code fullLootGen} is false) */
|
||||||
|
World world;
|
||||||
|
|
||||||
|
/** The player that last interacted with the imbuement altar, or null if there isn't one (or if this is being queried for other reasons, e.g. JEI) */
|
||||||
|
EntityPlayer lastUser;
|
||||||
|
|
||||||
|
/** The resulting item stack of the imbuement process */
|
||||||
|
ItemStack result;
|
||||||
|
|
||||||
|
public ImbuementActivateEvent(ItemStack input, Element[] receptacleElements, World world, EntityPlayer lastUser, ItemStack result) {
|
||||||
|
super();
|
||||||
|
this.input = input;
|
||||||
|
this.receptacleElements = receptacleElements;
|
||||||
|
this.world = world;
|
||||||
|
this.lastUser = lastUser;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package electroblob.wizardry.tileentity;
|
|||||||
|
|
||||||
import electroblob.wizardry.block.BlockReceptacle;
|
import electroblob.wizardry.block.BlockReceptacle;
|
||||||
import electroblob.wizardry.constants.Element;
|
import electroblob.wizardry.constants.Element;
|
||||||
|
import electroblob.wizardry.event.ImbuementActivateEvent;
|
||||||
import electroblob.wizardry.item.IManaStoringItem;
|
import electroblob.wizardry.item.IManaStoringItem;
|
||||||
import electroblob.wizardry.item.ItemWizardArmour;
|
import electroblob.wizardry.item.ItemWizardArmour;
|
||||||
import electroblob.wizardry.registry.*;
|
import electroblob.wizardry.registry.*;
|
||||||
@@ -24,6 +25,7 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import net.minecraft.world.storage.loot.LootContext;
|
import net.minecraft.world.storage.loot.LootContext;
|
||||||
import net.minecraft.world.storage.loot.LootTable;
|
import net.minecraft.world.storage.loot.LootTable;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -233,6 +235,14 @@ public class TileEntityImbuementAltar extends TileEntity implements ITickable {
|
|||||||
*/
|
*/
|
||||||
public static ItemStack getImbuementResult(ItemStack input, Element[] receptacleElements, boolean fullLootGen, World world, EntityPlayer lastUser){
|
public static ItemStack getImbuementResult(ItemStack input, Element[] receptacleElements, boolean fullLootGen, World world, EntityPlayer lastUser){
|
||||||
|
|
||||||
|
ItemStack eventResult = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
if (world != null && MinecraftForge.EVENT_BUS.post(new ImbuementActivateEvent(input, receptacleElements, world, lastUser, eventResult))) {
|
||||||
|
// return the stack if something changes the result from an empty stack.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
if (eventResult != ItemStack.EMPTY) return eventResult;
|
||||||
|
}
|
||||||
|
|
||||||
if(input.getItem() instanceof ItemWizardArmour && ((ItemWizardArmour)input.getItem()).element == null){
|
if(input.getItem() instanceof ItemWizardArmour && ((ItemWizardArmour)input.getItem()).element == null){
|
||||||
|
|
||||||
if(Arrays.stream(receptacleElements).distinct().count() == 1 && receptacleElements[0] != null){ // All the same element
|
if(Arrays.stream(receptacleElements).distinct().count() == 1 && receptacleElements[0] != null){ // All the same element
|
||||||
|
|||||||
Reference in New Issue
Block a user