From 4de9793ec947ef60bbd75122453da6933572a6d9 Mon Sep 17 00:00:00 2001 From: Mithion Date: Sat, 23 Mar 2013 12:59:06 -0400 Subject: [PATCH] Enderman Teleport Event New event when an enderman teleports that allows the teleport location to either be modified or completely cancelled. --- .../entity/living/EndermanTeleportEvent.java | 26 ++++++++++++ .../entity/monster/EntityEnderman.java.patch | 41 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 common/net/minecraftforge/event/entity/living/EndermanTeleportEvent.java create mode 100644 patches/minecraft/net/minecraft/entity/monster/EntityEnderman.java.patch diff --git a/common/net/minecraftforge/event/entity/living/EndermanTeleportEvent.java b/common/net/minecraftforge/event/entity/living/EndermanTeleportEvent.java new file mode 100644 index 000000000..a2d0688d4 --- /dev/null +++ b/common/net/minecraftforge/event/entity/living/EndermanTeleportEvent.java @@ -0,0 +1,26 @@ +package net.minecraftforge.event.entity.living; + +import net.minecraft.entity.EntityLiving; +import net.minecraftforge.event.Cancelable; +import net.minecraftforge.event.Event; + +/** + * Event for when an Enderman teleports. Can be used to either modify the target position, or cancel the teleport outright. + * @author Mithion + * + */ +@Cancelable +public class EndermanTeleportEvent extends LivingEvent{ + + public double targetX; + public double targetY; + public double targetZ; + + public EndermanTeleportEvent(EntityLiving entity, double targetX, double targetY, double targetZ) + { + super(entity); + this.targetX = targetX; + this.targetY = targetY; + this.targetZ = targetZ; + } +} diff --git a/patches/minecraft/net/minecraft/entity/monster/EntityEnderman.java.patch b/patches/minecraft/net/minecraft/entity/monster/EntityEnderman.java.patch new file mode 100644 index 000000000..c47dee917 --- /dev/null +++ b/patches/minecraft/net/minecraft/entity/monster/EntityEnderman.java.patch @@ -0,0 +1,41 @@ +--- ../src_base/minecraft/net/minecraft/entity/monster/EntityEnderman.java ++++ ../src_work/minecraft/net/minecraft/entity/monster/EntityEnderman.java +@@ -11,6 +11,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.living.EndermanTeleportEvent; + + public class EntityEnderman extends EntityMob + { +@@ -264,12 +266,17 @@ + */ + protected boolean teleportTo(double par1, double par3, double par5) + { ++ EndermanTeleportEvent event = new EndermanTeleportEvent(this, par1, par3, par5); ++ if (!MinecraftForge.EVENT_BUS.post(event)){ ++ return false; ++ } ++ + double d3 = this.posX; + double d4 = this.posY; + double d5 = this.posZ; +- this.posX = par1; +- this.posY = par3; +- this.posZ = par5; ++ this.posX = event.targetX; ++ this.posY = event.targetY; ++ this.posZ = event.targetZ; + boolean flag = false; + int i = MathHelper.floor_double(this.posX); + int j = MathHelper.floor_double(this.posY); +@@ -296,7 +303,7 @@ + } + + if (flag1) +- { ++ { + this.setPosition(this.posX, this.posY, this.posZ); + + if (this.worldObj.getCollidingBoundingBoxes(this, this.boundingBox).isEmpty() && !this.worldObj.isAnyLiquid(this.boundingBox))