mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-24 22:14:32 +00:00
Add generic EntityTeleportEvent (#7694)
This commit is contained in:
1 parent
f47429717d
commit
80feb0aeb2
11 files changed
+332
-8
No files matched your search
@@ -25,8 +25,9 @@ import net.minecraft.entity.LivingEntity;
|
||||
/**
|
||||
* Event for when an Enderman/Shulker teleports or an ender pearl is used. Can be used to either modify the target position, or cancel the teleport outright.
|
||||
* @author Mithion
|
||||
*
|
||||
* @deprecated Use {@link EntityTeleportEvent.EnderEntity} or {@link EntityTeleportEvent.EnderPearl}.
|
||||
*/
|
||||
@Deprecated //TODO Forge: Remove in 1.17
|
||||
@Cancelable
|
||||
public class EnderTeleportEvent extends LivingEvent
|
||||
{
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
package net.minecraftforge.event.entity.living;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.item.EnderPearlEntity;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent is fired when an event involving any teleportation of an Entity occurs.<br>
|
||||
* If a method utilizes this {@link net.minecraftforge.eventbus.api.Event} as its parameter, the method will
|
||||
* receive every child event of this class.<br>
|
||||
* <br>
|
||||
* {@link #getTarget()} contains the target destination.<br>
|
||||
* {@link #getPrev()} contains the entity's current position.<br>
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class EntityTeleportEvent extends EntityEvent
|
||||
{
|
||||
protected double targetX;
|
||||
protected double targetY;
|
||||
protected double targetZ;
|
||||
|
||||
public EntityTeleportEvent(Entity entity, double targetX, double targetY, double targetZ) {
|
||||
super(entity);
|
||||
this.targetX = targetX;
|
||||
this.targetY = targetY;
|
||||
this.targetZ = targetZ;
|
||||
}
|
||||
|
||||
public double getTargetX() { return targetX; }
|
||||
public void setTargetX(double targetX) { this.targetX = targetX; }
|
||||
public double getTargetY() { return targetY; }
|
||||
public void setTargetY(double targetY) { this.targetY = targetY; }
|
||||
public double getTargetZ() { return targetZ; }
|
||||
public void setTargetZ(double targetZ) { this.targetZ = targetZ; }
|
||||
public Vector3d getTarget() { return new Vector3d(this.targetX, this.targetY, this.targetZ); }
|
||||
public double getPrevX() { return getEntity().getX(); }
|
||||
public double getPrevY() { return getEntity().getY(); }
|
||||
public double getPrevZ() { return getEntity().getZ(); }
|
||||
public Vector3d getPrev() { return getEntity().position(); }
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent.TeleportCommand is fired before a living entity is teleported
|
||||
* from use of {@link net.minecraft.command.impl.TeleportCommand}.
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link net.minecraftforge.fml.LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class TeleportCommand extends EntityTeleportEvent
|
||||
{
|
||||
public TeleportCommand(Entity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent.SpreadPlayersCommand is fired before a living entity is teleported
|
||||
* from use of {@link net.minecraft.command.impl.SpreadPlayersCommand}.
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link net.minecraftforge.fml.LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class SpreadPlayersCommand extends EntityTeleportEvent
|
||||
{
|
||||
public SpreadPlayersCommand(Entity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent.EnderEntity is fired before an Enderman or Shulker randomly teleports.
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link net.minecraftforge.fml.LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EnderEntity extends EntityTeleportEvent
|
||||
{
|
||||
private final LivingEntity entityLiving;
|
||||
|
||||
public EnderEntity(LivingEntity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.entityLiving = entity;
|
||||
}
|
||||
|
||||
public LivingEntity getEntityLiving()
|
||||
{
|
||||
return entityLiving;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent.EnderPearl is fired before an Entity is teleported from an EnderPearlEntity.
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link net.minecraftforge.fml.LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class EnderPearl extends EntityTeleportEvent
|
||||
{
|
||||
private final ServerPlayerEntity player;
|
||||
private final EnderPearlEntity pearlEntity;
|
||||
private float attackDamage;
|
||||
|
||||
public EnderPearl(ServerPlayerEntity entity, double targetX, double targetY, double targetZ, EnderPearlEntity pearlEntity, float attackDamage)
|
||||
{
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.pearlEntity = pearlEntity;
|
||||
this.player = entity;
|
||||
this.attackDamage = attackDamage;
|
||||
}
|
||||
|
||||
public EnderPearlEntity getPearlEntity()
|
||||
{
|
||||
return pearlEntity;
|
||||
}
|
||||
|
||||
public ServerPlayerEntity getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
public float getAttackDamage()
|
||||
{
|
||||
return attackDamage;
|
||||
}
|
||||
|
||||
public void setAttackDamage(float attackDamage)
|
||||
{
|
||||
this.attackDamage = attackDamage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityTeleportEvent.ChorusFruit is fired before a LivingEntity is teleported due to consuming Chorus Fruit.
|
||||
* <br>
|
||||
* This event is {@link net.minecraftforge.eventbus.api.Cancelable}.<br>
|
||||
* If the event is not canceled, the entity will be teleported.
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
* <br>
|
||||
* This event is only fired on the {@link net.minecraftforge.fml.LogicalSide#SERVER} side.<br>
|
||||
* <br>
|
||||
* If this event is canceled, the entity will not be teleported.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ChorusFruit extends EntityTeleportEvent
|
||||
{
|
||||
private final LivingEntity entityLiving;
|
||||
|
||||
public ChorusFruit(LivingEntity entity, double targetX, double targetY, double targetZ)
|
||||
{
|
||||
super(entity, targetX, targetY, targetZ);
|
||||
this.entityLiving = entity;
|
||||
}
|
||||
|
||||
public LivingEntity getEntityLiving()
|
||||
{
|
||||
return entityLiving;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user