Improve APIs around riptide tridents (#12996)

Co-authored-by: Bjarne Koll <git@lynxplay.dev>
Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
This commit is contained in:
Aeltumn
2025-08-23 23:12:30 +02:00
committed by GitHub
parent 52d9a2216c
commit 614e9acfca
5 changed files with 121 additions and 4 deletions
@@ -1540,6 +1540,40 @@
this.doPush(entity1);
}
}
@@ -2954,16 +_,32 @@
protected void checkAutoSpinAttack(AABB boundingBoxBeforeSpin, AABB boundingBoxAfterSpin) {
AABB aabb = boundingBoxBeforeSpin.minmax(boundingBoxAfterSpin);
List<Entity> entities = this.level().getEntities(this, aabb);
+ int skippedAttackedEntitiesCounter = 0; // Paper - entity attempt spin attack event / hidden entities - count entities that are retroactively not part of the list
if (!entities.isEmpty()) {
for (Entity entity : entities) {
+ // Paper start - entity attempt spin attack event / hidden entities - skip hidden entities
+ if (this instanceof final ServerPlayer serverPlayer && !serverPlayer.getBukkitEntity().canSee(entity.getBukkitEntity())) {
+ ++skippedAttackedEntitiesCounter;
+ continue;
+ }
+ // Paper end - entity attempt spin attack event / hidden entities - skip hidden entities
if (entity instanceof LivingEntity) {
+ // Paper start - entity attempt spin attack event / hidden entities - skip hidden entities
+ if (!new io.papermc.paper.event.entity.EntityAttemptSpinAttackEvent(
+ getBukkitLivingEntity(),
+ ((LivingEntity) entity).getBukkitLivingEntity()
+ ).callEvent()) {
+ ++skippedAttackedEntitiesCounter;
+ continue;
+ }
+ // Paper end - entity attempt spin attack event / hidden entities - skip hidden entities
this.doAutoAttackOnTouch((LivingEntity)entity);
this.autoSpinAttackTicks = 0;
this.setDeltaMovement(this.getDeltaMovement().scale(-0.2));
break;
}
}
- } else if (this.horizontalCollision) {
+ } if (this.horizontalCollision && skippedAttackedEntitiesCounter == entities.size()) { // Paper - entity attempt spin attack event - only check if above list was either empty (size is 0, counter is 0 because of it) or filled completely with skipped entities.
this.autoSpinAttackTicks = 0;
}
@@ -2987,9 +_,16 @@
@Override
@@ -46,7 +46,7 @@
f *= tridentSpinAttackStrength / squareRoot;
f1 *= tridentSpinAttackStrength / squareRoot;
f2 *= tridentSpinAttackStrength / squareRoot;
+ org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerRiptideEvent(player, stack, f, f1, f2); // CraftBukkit
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerRiptideEvent(player, stack, f, f1, f2)) return false; // Paper - Add player riptide event
player.push(f, f1, f2);
player.startAutoSpinAttack(20, 8.0F, stack);
if (player.onGround()) {
@@ -1559,9 +1559,9 @@ public class CraftEventFactory {
return event;
}
public static void callPlayerRiptideEvent(net.minecraft.world.entity.player.Player player, ItemStack tridentItemStack, float velocityX, float velocityY, float velocityZ) {
public static boolean callPlayerRiptideEvent(net.minecraft.world.entity.player.Player player, ItemStack tridentItemStack, float velocityX, float velocityY, float velocityZ) {
PlayerRiptideEvent event = new PlayerRiptideEvent((Player) player.getBukkitEntity(), CraftItemStack.asCraftMirror(tridentItemStack), new Vector(velocityX, velocityY, velocityZ));
player.level().getCraftServer().getPluginManager().callEvent(event);
return event.callEvent();
}
public static BlockShearEntityEvent callBlockShearEntityEvent(Entity animal, org.bukkit.block.Block dispenser, CraftItemStack is, List<ItemStack> drops) { // Paper - custom shear drops