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:
+70
@@ -0,0 +1,70 @@
|
||||
package io.papermc.paper.event.entity;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
/**
|
||||
* Called when a {@link LivingEntity} attempts to perform an automatic spin attack
|
||||
* against a target entity.
|
||||
*/
|
||||
@NullMarked
|
||||
public class EntityAttemptSpinAttackEvent extends EntityEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final LivingEntity target;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public EntityAttemptSpinAttackEvent(final LivingEntity entity, final LivingEntity target) {
|
||||
super(entity);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return (LivingEntity) this.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity that is being attacked
|
||||
* in the spin attack.
|
||||
*
|
||||
* @return the entity being attacked
|
||||
*/
|
||||
public LivingEntity getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* It should be noted that both the client and server independently check
|
||||
* for a spin attack. Cancelling this on the server means the animation is not
|
||||
* interrupted and no attack is performed, but the client will still collide
|
||||
* and bounce away.
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLER_LIST;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -14,13 +15,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
* N.B. the riptide action is currently performed client side, so manipulating
|
||||
* the player in this event may have undesired effects.
|
||||
*/
|
||||
public class PlayerRiptideEvent extends PlayerEvent {
|
||||
public class PlayerRiptideEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
|
||||
private final ItemStack item;
|
||||
private final Vector velocity;
|
||||
|
||||
private boolean cancelled;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public PlayerRiptideEvent(@NotNull final Player player, @NotNull final ItemStack item, @NotNull Vector velocity) {
|
||||
super(player);
|
||||
@@ -54,6 +57,16 @@ public class PlayerRiptideEvent extends PlayerEvent {
|
||||
return this.velocity.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user