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

Fix overrideable hand ToolCapabilities and range #15743

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

cx384
Copy link
Contributor

@cx384 cx384 commented Feb 1, 2025

Fixes #15740

To avoid confusion, notice:
selected_item is the item selected in the hotbar, ("" if empty)
hand_item is the overwritten hand ("" by default).
tool_item/playeritem/punchitem is what should be used for getToolCapabilities (getWieldedItem returns this)

getToolCapabilities needs both tool_item and hand_item as a fallback.

Callbacks and node placement still only uses selected_item.

To do

Ready for Review.

How to test

  • Like explained in the issue, try e.g.
core.register_item("default:hand", {
	type = "none",
	range = 20,
	tool_capabilities = {
		groupcaps = {
			crumbly = {times={[1] = 0.1, [2] = 0.1, [3] = 0.1}, uses = 0, maxlevel = 1},
			cracky = {times={[1] = 0.1, [2] = 0.1, [3] = 0.1}, uses = 0, maxlevel = 1},
		}
	}
})

core.register_chatcommand('hand', {
	func = function(name, param)
		local player = core.get_player_by_name(name)

		local handitem
		if param == 'reset' then
			handitem = ''
		else
			handitem = 'default:hand'
		end

		local inv = player:get_inventory()
		inv:set_size('hand', 1)
		inv:set_stack('hand', 1, ItemStack(handitem))
	end
})
  • See that it works while wielding nothing, and while e.g. a node

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.

Mostly nitpicks. Works as expected in testing.

The code looks sensible: It adds the hand as a parameter to getToolCapabilities, and then the rest are primarily changes to pass the hand around.

src/inventory.h Outdated Show resolved Hide resolved
src/inventory.h Outdated Show resolved Hide resolved
src/inventory.h Outdated Show resolved Hide resolved
src/client/game.cpp Outdated Show resolved Hide resolved
src/inventory.h Outdated Show resolved Hide resolved
@cx384
Copy link
Contributor Author

cx384 commented Feb 5, 2025

Thanks for reviewing, applied everything.
(At first I added the explicit nullptr comparisons, since I thought we may want them for readability considering the old code, but they are gone now.)

About the changes this PR makes, there is also a replacement of selected_item with tool_item.
This is needed, since selected_item is never the hand, it can only be empty (which is equal to the default hand ""), and this would then be preferred by getToolCapabilities instead of the actual hand.
And as I already wrote, the item callbacks still only use selected_item.
(Changing this may cause some problems in case a mod allows using an arbitrary item as hand.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix 🐛 PRs that fix a bug @ Script API
Projects
None yet
2 participants