Add proper attached blocks API to AbstractArrow (#12099)

This commit is contained in:
Tamion
2025-02-12 23:13:07 +01:00
committed by GitHub
parent cf7c6c7483
commit 072a8317b2
3 changed files with 38 additions and 6 deletions

View File

@@ -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 {
@@ -68,12 +73,16 @@ public class CraftAbstractArrow extends AbstractProjectile implements AbstractAr
@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