Add projectile hit simulation API (#8816)

This adds API to force a projectile to hit a provided entity. Example usage could be if you have a player disguised as another entity, you could simulate an arrow colliding with the (fake) entity hitbox.
This commit is contained in:
SamB440
2023-02-11 15:41:06 +00:00
parent f40928931b
commit e343c4eb44
3 changed files with 53 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ // Paper start
+ @Override
+ protected void preOnHit(HitResult hitResult) {
+ public void preOnHit(HitResult hitResult) {
+ super.preOnHit(hitResult);
+ if (hitResult instanceof EntityHitResult entityHitResult && this.hitCancelled && this.getPierceLevel() > 0) {
+ if (this.piercingIgnoreEntityIds == null) {

View File

@@ -14,6 +14,8 @@ public net.minecraft.world.entity.projectile.AbstractArrow soundEvent
public net.minecraft.world.entity.projectile.ThrownTrident dealtDamage
public net.minecraft.world.entity.projectile.Projectile hasBeenShot
public net.minecraft.world.entity.projectile.Projectile leftOwner
public net.minecraft.world.entity.projectile.Projectile preOnHit(Lnet/minecraft/world/phys/HitResult;)V
public net.minecraft.world.entity.projectile.Projectile canHitEntity(Lnet/minecraft/world/entity/Entity;)Z
Co-authored-by: Nassim Jahnke <nassim@njahnke.dev>
@@ -72,6 +74,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ public boolean canHitEntity(org.bukkit.entity.Entity entity) {
+ return this.getHandle().canHitEntity(((CraftEntity) entity).getHandle());
+ }
+
+ @Override
+ public void hitEntity(org.bukkit.entity.Entity entity) {
+ this.getHandle().preOnHit(new net.minecraft.world.phys.EntityHitResult(((CraftEntity) entity).getHandle()));
+ }
+
+ @Override
+ public void hitEntity(org.bukkit.entity.Entity entity, org.bukkit.util.Vector vector) {
+ this.getHandle().preOnHit(new net.minecraft.world.phys.EntityHitResult(((CraftEntity) entity).getHandle(), new net.minecraft.world.phys.Vec3(vector.getX(), vector.getY(), vector.getZ())));
+ }
+
+ @Override
+ public net.minecraft.world.entity.projectile.Projectile getHandle() {
+ return (net.minecraft.world.entity.projectile.Projectile) entity;
+ }