From 2e3d1a3c0928a86c0e82e2104a8df30488d98946 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Mon, 30 Sep 2013 16:56:34 -0700 Subject: [PATCH] Add cancelable EntityStructByLightningEvent, Closes #789 --- .../entity/EntityStruckByLightningEvent.java | 17 ++++++++++++++ .../effect/EntityLightningBolt.java.patch | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 common/net/minecraftforge/event/entity/EntityStruckByLightningEvent.java create mode 100644 patches/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java.patch diff --git a/common/net/minecraftforge/event/entity/EntityStruckByLightningEvent.java b/common/net/minecraftforge/event/entity/EntityStruckByLightningEvent.java new file mode 100644 index 000000000..c55cc4fdb --- /dev/null +++ b/common/net/minecraftforge/event/entity/EntityStruckByLightningEvent.java @@ -0,0 +1,17 @@ +package net.minecraftforge.event.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.effect.EntityLightningBolt; +import net.minecraftforge.event.Cancelable; + +@Cancelable +public class EntityStruckByLightningEvent extends EntityEvent +{ + public final EntityLightningBolt lightning; + + public EntityStruckByLightningEvent(Entity entity, EntityLightningBolt lightning) + { + super(entity); + this.lightning = lightning; + } +} diff --git a/patches/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java.patch b/patches/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java.patch new file mode 100644 index 000000000..a0843132e --- /dev/null +++ b/patches/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java.patch @@ -0,0 +1,23 @@ +--- ../src_base/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java ++++ ../src_work/minecraft/net/minecraft/entity/effect/EntityLightningBolt.java +@@ -10,6 +10,8 @@ + import net.minecraft.util.MathHelper; + import net.minecraft.util.Vec3; + import net.minecraft.world.World; ++import net.minecraftforge.common.MinecraftForge; ++import net.minecraftforge.event.entity.EntityStruckByLightningEvent; + + public class EntityLightningBolt extends EntityWeatherEffect + { +@@ -116,7 +118,10 @@ + for (int l = 0; l < list.size(); ++l) + { + Entity entity = (Entity)list.get(l); +- entity.onStruckByLightning(this); ++ if (!MinecraftForge.EVENT_BUS.post(new EntityStruckByLightningEvent(entity, this))) ++ { ++ entity.onStruckByLightning(this); ++ } + } + } + }