Skip to content
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

Add Lua API function to resolve node/collision/selection boxes #13964

Merged
merged 6 commits into from Feb 6, 2024

Conversation

grorp
Copy link
Member

@grorp grorp commented Nov 7, 2023

For some purposes, it is useful for modders to be able to retrieve the actual collision or selection boxes of a node. This includes:

However, manually resolving node/collision/selection boxes in a node definition into actual boxes can be quite complex, depending on the type of box. Boxes can be facedir-rotated, wallmounted, leveled and/or connected. #11391 will further increase the number of cases to consider. There is a Lua implementation by @appgurueu: boxes.lua

This PR instead exposes the existing engine method for resolving boxes to the Lua API:

* `minetest.get_node_boxes(box_type, pos, [node])`
    * `box_type` must be `"node_box"`, `"collision_box"` or `"selection_box"`.
    * `pos` must be a node position.
    * `node` can be a table in the form `{name=string, param1=number, param2=number}`.
      If `node` is `nil`, the actual node at `pos` is used instead.
    * Resolves any facedir-rotated boxes, connected boxes and the like into
      actual boxes.
    * Returns a list of boxes in the form
      `{{x1, y1, z1, x2, y2, z2}, {x1, y1, z1, x2, y2, z2}, ...}`. Coordinates
      are relative to `pos`.

I also added the "Node Box Visualizer", a Devtest tool for testing the new function.

To do

This PR is a Ready for Review.

How to test

Start a Devtest world and get yourself the "Node Box Visualizer" tool. Press the place button to change the selected box type. Punch a node to show its boxes of the selected type.

@grorp grorp added @ Script API Feature ✨ PRs that add or enhance a feature labels Nov 7, 2023
@sfan5
Copy link
Member

sfan5 commented Nov 19, 2023

Idea: add a variant of the api that can work with a {name=...,param1=....,param2=...} table
This answers the question "what would the boxes of this node look like" (with the caveat that connected ones wouldn't work).

@grorp
Copy link
Member Author

grorp commented Dec 16, 2023

Idea: add a variant of the api that can work with a {name=...,param1=....,param2=...} table This answers the question "what would the boxes of this node look like" (with the caveat that connected ones wouldn't work).

That's a good idea, I've implemented it.

@appgurueu appgurueu added the Concept approved Approved by a core dev: PRs welcomed! label Jan 11, 2024
@Zughy Zughy added Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR and removed Concept approved Approved by a core dev: PRs welcomed! labels Jan 21, 2024
Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments are out of date, otherwise looks good, tested and works.

Also a nitpick / detail: Maybe it would make sense to return nil for collision boxes if a node is not walkable / nil for selection boxes if a node is not pointable / nil for node boxes if a node doesn't use node boxes.

src/script/lua_api/l_env.cpp Outdated Show resolved Hide resolved
src/script/lua_api/l_env.h Outdated Show resolved Hide resolved
@grorp
Copy link
Member Author

grorp commented Feb 6, 2024

Also a nitpick / detail: Maybe it would make sense to return nil for collision boxes if a node is not walkable / nil for selection boxes if a node is not pointable / nil for node boxes if a node doesn't use node boxes.

For selection boxes, returning nil if pointable = false doesn't make sense anymore since #13992 was merged. Conceptually, you could argue that the boxes are still there, they're just not used.

@grorp grorp merged commit f2b9933 into minetest:master Feb 6, 2024
15 checks passed
@grorp grorp deleted the lua-get-node-boxes branch February 9, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature One approval ✅ ◻️ @ Script API Supported by core dev Not on the roadmap, yet some core dev decided to take care of this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants