Enderman Teleport Event

New event when an enderman teleports that allows the teleport location
to either be modified or completely cancelled.
This commit is contained in:
Mithion 2013-03-23 12:59:06 -04:00
parent 833e9f0c88
commit 4de9793ec9
2 changed files with 67 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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))