Add resurrection event
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
package electroblob.wizardry.event;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ResurrectionEvent is fired when a player is about to be resurrected, after all other checks have been performed.
|
||||||
|
* <i>Note that this event is only fired on the server side.</i><br>
|
||||||
|
* <br>
|
||||||
|
* This event is {@link Cancelable}. If this event is canceled, the player is not resurrected.<br>
|
||||||
|
* <br>
|
||||||
|
* This event does not have a result. {@link HasResult}<br>
|
||||||
|
* <br>
|
||||||
|
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||||
|
*
|
||||||
|
* @author Electroblob
|
||||||
|
* @since Wizardry 2.1
|
||||||
|
*/
|
||||||
|
@Cancelable
|
||||||
|
public class ResurrectionEvent extends PlayerEvent {
|
||||||
|
|
||||||
|
private final EntityPlayer caster;
|
||||||
|
|
||||||
|
public ResurrectionEvent(EntityPlayer player, EntityPlayer caster){
|
||||||
|
super(player);
|
||||||
|
this.caster = caster;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the player that cast the resurrection spell. If the player resurrected themselves, this will be the
|
||||||
|
* same as {@link ResurrectionEvent#getEntityPlayer()}. */
|
||||||
|
public EntityPlayer getCaster(){
|
||||||
|
return caster;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package electroblob.wizardry.packet;
|
package electroblob.wizardry.packet;
|
||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
|
import electroblob.wizardry.event.ResurrectionEvent;
|
||||||
import electroblob.wizardry.inventory.ContainerArcaneWorkbench;
|
import electroblob.wizardry.inventory.ContainerArcaneWorkbench;
|
||||||
import electroblob.wizardry.item.ISpellCastingItem;
|
import electroblob.wizardry.item.ISpellCastingItem;
|
||||||
import electroblob.wizardry.packet.PacketControlInput.Message;
|
import electroblob.wizardry.packet.PacketControlInput.Message;
|
||||||
@@ -13,6 +14,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||||
@@ -79,6 +81,7 @@ public class PacketControlInput implements IMessageHandler<Message, IMessage> {
|
|||||||
.filter(s -> Resurrection.canStackResurrect(s, player)).findFirst().orElse(null);
|
.filter(s -> Resurrection.canStackResurrect(s, player)).findFirst().orElse(null);
|
||||||
|
|
||||||
if(stack != null){
|
if(stack != null){
|
||||||
|
if(MinecraftForge.EVENT_BUS.post(new ResurrectionEvent(player, player))) break;
|
||||||
// This should suffice, since this is the only way a player can cast resurrection when dead!
|
// This should suffice, since this is the only way a player can cast resurrection when dead!
|
||||||
((ISpellCastingItem)stack.getItem()).cast(stack, Spells.resurrection, player, EnumHand.MAIN_HAND, 0, new SpellModifiers());
|
((ISpellCastingItem)stack.getItem()).cast(stack, Spells.resurrection, player, EnumHand.MAIN_HAND, 0, new SpellModifiers());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package electroblob.wizardry.spell;
|
|||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.data.WizardData;
|
import electroblob.wizardry.data.WizardData;
|
||||||
|
import electroblob.wizardry.event.ResurrectionEvent;
|
||||||
import electroblob.wizardry.item.ISpellCastingItem;
|
import electroblob.wizardry.item.ISpellCastingItem;
|
||||||
import electroblob.wizardry.item.SpellActions;
|
import electroblob.wizardry.item.SpellActions;
|
||||||
import electroblob.wizardry.packet.PacketResurrection;
|
import electroblob.wizardry.packet.PacketResurrection;
|
||||||
@@ -18,6 +19,7 @@ import net.minecraft.util.EnumHand;
|
|||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
||||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
@@ -61,6 +63,9 @@ public class Resurrection extends Spell {
|
|||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if(nearestDeadAlly != null){
|
if(nearestDeadAlly != null){
|
||||||
|
|
||||||
|
if(MinecraftForge.EVENT_BUS.post(new ResurrectionEvent(nearestDeadAlly, caster))) return false;
|
||||||
|
|
||||||
// When the player entity dies, it is removed from world#loadedEntityList. However, it is NOT removed
|
// When the player entity dies, it is removed from world#loadedEntityList. However, it is NOT removed
|
||||||
// from playerEntityList (and probably a few other places) until respawn is clicked, and since that
|
// from playerEntityList (and probably a few other places) until respawn is clicked, and since that
|
||||||
// never happens here we need to clean up those references or the player will have duplicate entries
|
// never happens here we need to clean up those references or the player will have duplicate entries
|
||||||
|
|||||||
Reference in New Issue
Block a user