PaperMC / PaperMC/Paper

Add API to retrieve blocks which would be broken by explosion

Open
#12,348 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: needs triage
Dominant language
Java
Stars
12.7k
Forks
3.5k
Avg merge
3d 13h
Merged PRs (30d)
11

Description

Is your feature request related to a problem?

During the implementation of a custom explosion, where I wanted more control over the blocks actually involved in the explosion, I came across a lack of API. Basically, you are currently only able to explode manually using boolean World#createExplosion(...) and its many many overloads. You cannot actually retrieve the blocks that would be broken by a theoretical explosion, and perform your own logic, so not exploding certain blocks, or running some sort of operation on them instead of just removing them.

Describe the solution you'd like.

I'd like a new collection of methods, List<Block> World#getExplodedBlocks(...), which run the underlying ServerExplosion#explode() logic until the this.calculateExplodedPositions() part, and then returns. Perhaps instead of it being a List<Block>, it could be more versatile and instead be a record class, which also contains data for stuff like potential fire locations (if fire is enable) and the damage done to entities. But I am down to discuss the specifics.

Describe alternatives you've considered.

There are basically three alternatives that I could think of, when I encountered this problem:

  1. Just do a very simple, basic calculation, which just takes all blocks from a radius and calls it a day. No extra logic.
  2. Run the World#createExplosion method and listen for BlockExplodeEvents (probably the most sane variant atm)
  3. Use NMS + reflection to get access to the ServerExplosion#calculateExplodedPositions, ServerExplosion#hurtEntities, and ServerExplosion#createFire methods (the one I went with)
Other

None 🚀

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading World#createExplosion(...) and the ServerExplosion#explode() flow, especially calculateExplodedPositions(), hurtEntities(), and createFire(). Compare the proposed API with the existing BlockExplodeEvent alternative. Done would require a settled API design and implementation that exposes the intended explosion results, but the issue leaves those specifics open.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.