Add HitResult to EntityTeleportEvent$EnderPearl (#9135)

This commit is contained in:
matyrobbrt authored and GitHub committed 2022-11-08 12:17:18 -08:00
1 parent 84ab9764e3
commit 1a2207b3b2
3 files changed
+37 -3

No files matched your search

@@ -719,9 +719,20 @@ public class ForgeEventFactory
return event;
}
/**
* @deprecated Use {@linkplain #onEnderPearlLand(ServerPlayer, double, double, double, ThrownEnderpearl, float, HitResult) the hit result-sensitive version}.
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true, since = "1.19.2")
public static EntityTeleportEvent.EnderPearl onEnderPearlLand(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage)
{
EntityTeleportEvent.EnderPearl event = new EntityTeleportEvent.EnderPearl(entity, targetX, targetY, targetZ, pearlEntity, attackDamage);
return onEnderPearlLand(entity, targetX, targetY, targetZ, pearlEntity, attackDamage, null);
}
@ApiStatus.Internal // TODO - 1.20: remove the nullable
public static EntityTeleportEvent.EnderPearl onEnderPearlLand(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage, @Nullable HitResult hitResult)
{
EntityTeleportEvent.EnderPearl event = new EntityTeleportEvent.EnderPearl(entity, targetX, targetY, targetZ, pearlEntity, attackDamage, hitResult);
MinecraftForge.EVENT_BUS.post(event);
return event;
}
@@ -9,11 +9,14 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrownEnderpearl;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* EntityTeleportEvent is fired when an event involving any teleportation of an Entity occurs.<br>
@@ -150,13 +153,27 @@ public class EntityTeleportEvent extends EntityEvent
private final ServerPlayer player;
private final ThrownEnderpearl pearlEntity;
private float attackDamage;
@Nullable
private final HitResult hitResult; // TODO - 1.20: make the hit result nonnull, remove the other constructor
public EnderPearl(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage)
@ApiStatus.Internal
public EnderPearl(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage, @Nullable HitResult hitResult)
{
super(entity, targetX, targetY, targetZ);
this.pearlEntity = pearlEntity;
this.player = entity;
this.attackDamage = attackDamage;
this.hitResult = hitResult;
}
/**
* @deprecated Use {@linkplain #EnderPearl(ServerPlayer, double, double, double, ThrownEnderpearl, float, HitResult)} the hit result-sensitive version}.
*/
@ApiStatus.Internal
@Deprecated(forRemoval = true, since = "1.19.2")
public EnderPearl(ServerPlayer entity, double targetX, double targetY, double targetZ, ThrownEnderpearl pearlEntity, float attackDamage)
{
this(entity, targetX, targetY, targetZ, pearlEntity, attackDamage, null);
}
public ThrownEnderpearl getPearlEntity()
@@ -169,6 +186,12 @@ public class EntityTeleportEvent extends EntityEvent
return player;
}
@Nullable
public HitResult getHitResult()
{
return this.hitResult;
}
public float getAttackDamage()
{
return attackDamage;