Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ enum PickupRule {
*/
int getLifetimeTicks();

/**
* Gets the number of ticks this arrow may exist before it despawns
* automatically.
*
* @return maximum lifetime ticks for this arrow
*/
int getMaxLifetimeTicks();

/**
* Gets the sound that is played when this arrow hits an entity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.common.collect.Iterables;
import java.util.List;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.ThrownTrident;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockCollisions;
import net.minecraft.world.phys.AABB;
Expand Down Expand Up @@ -164,6 +165,23 @@ public int getLifetimeTicks() {
return this.getHandle().life;
}

@Override
public int getMaxLifetimeTicks() {
final net.minecraft.world.entity.projectile.AbstractArrow handle = this.getHandle();
final net.minecraft.world.level.Level level = handle.level();
if (level == null) {
return 1200; // Vanilla default fallback
}

return switch (handle.pickup) {
case CREATIVE_ONLY -> level.paperConfig().entities.spawning.creativeArrowDespawnRate.value();
case DISALLOWED -> level.paperConfig().entities.spawning.nonPlayerArrowDespawnRate.value();
default -> handle instanceof ThrownTrident
? level.spigotConfig.tridentDespawnRate
: level.spigotConfig.arrowDespawnRate;
};
}

@Override
public org.bukkit.Sound getHitSound() {
return org.bukkit.craftbukkit.CraftSound.minecraftToBukkit(this.getHandle().getHitGroundSoundEvent());
Expand Down