Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper attached blocks API to AbstractArrow #12099

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/AbstractArrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;

/**
* Represents an arrow.
Expand Down Expand Up @@ -99,10 +101,23 @@ public interface AbstractArrow extends Projectile {
* Gets the block to which this arrow is attached.
*
* @return the attached block or null if not attached
* @deprecated can be attached to multiple blocks use {@link AbstractArrow#getAttachedBlocks()} instead
*/
@Nullable
@Deprecated(since = "1.21.4")
public Block getAttachedBlock();

/**
* Gets the block(s) which this arrow is attached to.
* All the returned blocks are responsible for preventing
* the arrow from falling.
*
* @return the attached block(s) or an empty list if not attached
*/
@NotNull
@Unmodifiable
List<Block> getAttachedBlocks();

/**
* Gets the current pickup status of this arrow.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
this.hasImpulse = true;
if (this.getPierceLevel() > 0 && projectileDeflection == ProjectileDeflection.NONE) {
continue;
@@ -313,6 +_,19 @@
@@ -313,13 +_,26 @@
}
}

Expand All @@ -97,6 +97,14 @@
@Override
protected double getDefaultGravity() {
return 0.05;
}

private boolean shouldFall() {
- return this.isInGround() && this.level().noCollision(new AABB(this.position(), this.position()).inflate(0.06));
+ return this.isInGround() && this.level().noCollision(new AABB(this.position(), this.position()).inflate(0.06)); // Paper - getAttachedBlocks api; diff on change
}

private void startFalling() {
@@ -329,7 +_,7 @@
this.life = 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.bukkit.craftbukkit.entity;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockCollisions;
import net.minecraft.world.phys.AABB;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.projectiles.ProjectileSource;
import java.util.List;

public class CraftAbstractArrow extends AbstractProjectile implements AbstractArrow {

Expand Down Expand Up @@ -68,12 +73,16 @@ public boolean isInBlock() {

@Override
public Block getAttachedBlock() {
return Iterables.getFirst(getAttachedBlocks(), null);
}

@Override
public List<Block> getAttachedBlocks() {
if (!this.isInBlock()) {
return null;
return ImmutableList.of();
}

BlockPos pos = this.getHandle().blockPosition();
return this.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ());
return ImmutableList.copyOf(new BlockCollisions<>(this.getHandle().level(), (Entity) null, new AABB(this.getHandle().position(), this.getHandle().position()).inflate(0.06), false, (mutableBlockPos, voxelShape) -> CraftBlock.at(this.getHandle().level(), mutableBlockPos)));
}

@Override
Expand Down
Loading