Skip to content

Add proof of concept for blocks callback #15999

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sfence
Copy link
Contributor

@sfence sfence commented Apr 9, 2025

Delivered from #14138.

Proof of concept for allowing modders to apply Lua callback to all loaded/loadable mapblocks.

Have the potential to be used for some updating, emulating some environment things like Exile game does.

@kromka-chleba

Test:

core.blocks_callback({
  mode = "quick",
  callback = function(blockpos)
    print("Block po hash: "..blockpos)
  end
)}

@sfence sfence added @ Server / Client / Env. Feature ✨ PRs that add or enhance a feature Discussion Issues meant for discussion of one or more proposals labels Apr 9, 2025
@sfence sfence marked this pull request as draft April 9, 2025 18:35
@kromka-chleba
Copy link
Contributor

kromka-chleba commented Apr 10, 2025

I'll try testing this later.

Edit: I took a quick look at the API and am confused by these modes of operation - both appear to clear objects and what if I don't want to clear anything?

@kromka-chleba
Copy link
Contributor

Related? #14723 (comment)

@sfence
Copy link
Contributor Author

sfence commented Apr 10, 2025

I don't know if is tabstable now.

I reused clearobjects modes for now, which can be changed in the future. The point is to run Lua function over loaded blocks (it is quick mod) or all loadable blocks (it is full mode).

@sfence
Copy link
Contributor Author

sfence commented Apr 10, 2025

Ok, is testable.

@sfan5
Copy link
Collaborator

sfan5 commented Apr 21, 2025

I'm not sure what this would be useful for except for emulating something like clearobjects from Lua?

@sfence
Copy link
Contributor Author

sfence commented Apr 21, 2025

@sfan5 Yes, similar to calling clearobjects from Lua.
In quick mode it should operate as interaction over core.loaded_blocks array mentioned in #14723 (comment).
In full mode, it can be used by a server maintainer for whatever they need. Probably only in offline mode due to expected lag.

@kromka-chleba
Copy link
Contributor

kromka-chleba commented Apr 23, 2025

@sfence works well for my use case so I'd be happy with this alone merged. I wouldn't mind if api proposed by sfan5 was implemented though #14723 (comment)
Used it to spawn VMs for each loaded mapblock and change stuff there.

@sfan5 there's no other way to tell which blocks are loaded that I'm aware of, unless it's blind bruteforce status checks so this PR is an improvement IMO.

@appgurueu appgurueu changed the title Add proff of concept for blocks callback. Add proof of concept for blocks callback Apr 23, 2025
@sfan5
Copy link
Collaborator

sfan5 commented Apr 24, 2025

there's no other way to tell which blocks are loaded that I'm aware of, unless it's blind bruteforce status checks so this PR is an improvement IMO.

I'm aware, but there would be cleaner API designs to achieve that. "Someone could use it to work around the lack of a proper API" is not the measure we should be using.

@Desour
Copy link
Member

Desour commented Apr 24, 2025

There will certainly be users for an API to iterate over all emerged blocks.

The doc should probably include a warning about the performance implications.

(Idk if the proposed API in its current form is ideal. I'll wait for more input from other people.)

You could also consider to spread the execution over multiple server steps, to avoid the lag spike.
But then the question is how to spread it. Ideally the mod decides it. But then the current API is insufficient.
Maybe split it into functions to:

  • List all block positions in the db.
  • Try to load (or activate?) a block. Will also say whether it generated and so on.

For clearobject-like (or also lbm once) functionality, we could also add an API to get the old timestamp of each activated block. (I would like to have this.) (This doesn't cover the usecase where you just want to iterate over your whole map. So it's not an either-or situation.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion Issues meant for discussion of one or more proposals Feature ✨ PRs that add or enhance a feature @ Server / Client / Env.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants