PocketMine-MP icon indicating copy to clipboard operation
PocketMine-MP copied to clipboard

A way to handle fertilizers correctly

Open ShockedPlot7560 opened this issue 1 month ago • 3 comments

Problem description

Currently, if a block needs to perform an action depending on whether it was clicked by a fertilizer (or not), we have to use instanceof. In most cases, this seems fine, but when it's repeated many times, I wonder if there might be a cleaner solution.

In addition, as described in #6102, plugins actually do not have much control over the action performed by the fertilizer:

  • the block spawn table: ability to add/remove/modify the percentage of blocks?
  • cancel fertilization without having to cancel the entire block interaction
  • precisely manage the growth of the block in question.

Proposed solution

  1. A BlockFertilizeEvent. Give some control but add code shit in all growing blocks and don't give much control on the spawn table : need to recalculate alls blocks if you want just a different percentage.
  2. The first solution combined with a seperate dedicated spawn table utility
  3. Maybe more ? Idk

Alternative solutions or workarounds

  • Cancelling block interaction -> preventing other logics to be processed
  • Cancelling block placing ? Looks difficult to detect
  • Overriding the block in question -> whereas some blocks already delegate to utilities (like Grass)

ShockedPlot7560 avatar Nov 04 '25 19:11 ShockedPlot7560

I'm thinking an event that gives a list of blocks to be changed (or a BlockTransaction) would be a good enough start. I haven't given much thought to probabilities, but I think the biggest issue for plugins is just not being able to cancel the generation of randomly positioned blocks.

dktapps avatar Nov 05 '25 22:11 dktapps

Cancelling the generation is the biggest but other issue is still important like adding / removing blocks (BlockTransaction could be a good start yes). Moving closer to something like probability tables in Java and chests could be a good way to adapt the systems. We'll see. Other solutions may exist.

ShockedPlot7560 avatar Nov 12 '25 11:11 ShockedPlot7560

That seems like overkill to me. I don't know how that would even be implemented.

dktapps avatar Nov 12 '25 14:11 dktapps