Open GreenDirkfried opened 2 years ago
Adding tool capabilities would probably not work because of not wanting to have digging times with the replacer, but maybe one could - similarly to tool capabilities- restrict the replacer to only dig nodes with a certain "maxlevel" or to not dig nodes from the "cracky" group...
the replacer is a very powerful tool, and part of the idea of this variant was to try to make it less "cheat-y", so i'm interested in this proposal.
tool capabilities vary a lot between "games", and i'd prefer to keep the tool as naive about those as possible, so i'm not too keen on constraining it that way.
being able to configure a universal "maxlevel" might work.
the only issue i see, is that the replacer fundamentally exists to aid in building, and not just creative building. the fact that it can be used to "mine" things instantly and w/out wearing down a tool, is a side effect, but not an easy one to create a general solution for, particularly w/out limiting builders.
if as a server owner, and you want to restrict usage of certain nodes w/ the replacer, there's a bit of an undocumented API.
replacer.api.replacer.blacklist_item(itemstring)
lets you blacklist a specific item from the replacer.
more generally, you can override replacer.api.replacer.can_dig(player, pos, node_name)
to your liking.
But contrary to the tool capabilities, the black listing does not take whole groups like "group:cracky" making it tedious to add all nodes that are you cannot dig with the hand. And while tool capabilities vary a lot between "games", nodes having different groups is part of MT itself https://minetest.gitlab.io/minetest/groups/
And the second thing is that I would like to distinguish between digging and placing: The replacer should be able to place stone stairs without being able to dig them. The black listing does not work like this :-/
This could allow that the focus is more on placing stairs and slabs with the right orientation (in general nodes with fixed param2).
Maybe one could make an exception for replacing the same node, like always allowing to replace certain stone stair with (the same kind of) stone stairs with another orientation (kind of like having a screwdriver with fixed setting), but not replacing stone bricks (a different node) with stone stairs (because stone bricks should not be this easy to dig) (while allowing replacing dirt (nodes of another group) with stone stairs, because this nodes are easy to dig).
Like you said, overwriting the more general function would probably work in this case Like doing something similar to line https://github.com/fluxionary/minetest-replacer_redo/blob/main/api/replacer.lua#L49
Do you have an idea how to add "forbidden" groups or max level there?
nodes having different groups is part of MT itself https://minetest.gitlab.io/minetest/groups/
groups and tool capabilities certainly are, but e.g. "crumbly" is not. i do, however, think a more advanced API for blacklisting stuff would be a good feature.
And the second thing is that I would like to distinguish between digging and placing: The replacer should be able to place stone stairs without being able to dig them. The black listing does not work like this :-/
hm, interesting. personally, i often use the replacer to correct the rotation of already placed nodes, but i can also see a possible use case for distinct blacklists for these actions. i've got some ideas, remind me in a few days if i don't come back w/ something.
That would be cool :-)
Yes, the correction of certain nodes is a useful feature. If differentiating between digging and placing, it would be cool to have an exception for this (always allow "rotating" nodes (if not protected)) :-D
oh it automagically closed this. @GreenDirkfried i wanted to ask if the updated API and documentation is enough for you to do what you want. https://github.com/fluxionary/minetest-replacer_redo/blob/main/README.md
EDIT: if you're not quite sure of how to do a specific thing w/ the provided API, i might be able to provide an example implementation, provided it's possible w/ the API i made.
i seem to have broken something and the group blacklisting isn't working. i'll look into it tomorrow.
I did not test it so far, but already: thanks very much for your work! :-)
I have one problem with the line "bans any node which has both cracky >= 2 and level >= 2" The "level >= 2" is fine, but in MTG a group rating cracky=1 is tougher than a group rating cracky=2, like a diamond ore having cracky=1 and an iron ore having cracky=2, see https://github.com/minetest/minetest_game/blob/master/mods/default/nodes.lua#L1301 In terms of tool capabilities, lower group rankings result in higher digging times and lower uses, see e.g. https://minetest.gitlab.io/minetest/tool-capabilities/#tool-capabilities So "cracky <= 2" would make more sense here (at least for MTG)
The "level >= 2" is fine, but in MTG a group rating cracky=1 is tougher than a group rating cracky=2
oh, right. let me think about the best way to solve that.
you might also be interested in another mod i wrote, hand_control, but it's very much not finished yet.
Ok, I think it kind of works, but now adding the advanced blacklisting (see below) I get a crash when trying to replace a node without defined level. The problem is: most nodes in MTG have no level defined (and are then probably level=0). (The problem may also occur, when a node is not "cracky".)
So what does NOT work is adding in blacklist.lua:
local api = replacer.api
pred1 = function(itemstring, definition) return definition.groups.level >= 2 and definition.groups.cracky <= 2 end
api.item_blacklist = {} api.predicate_blacklist = {} api.replace_item_blacklist = {} api.replace_predicate_blacklist = {pred1}
Do you have an idea for a better function?
sorry for not responding earlier, i've been dealing w/ the fallout of intentionally breaking other things.
I get a crash when trying to replace a node without defined level.
that's pretty serious, i'll try to fix that ASAP.
Do you have an idea for a better function?
i'll try to get to this tomorrow.
how about:
replacer.api.blacklist_predicate_replacement(function(itemstring, definition)
if not definition then
return false
end
local groups = definition.groups or {}
if (groups.cracky or tonumber("inf")) > 2 then
return false
end
if (groups.level or 0) < 2 then
return false
end
return true
end)
To better fit to survival gameplay it would be useful to add tool capabilities to the digging function of the replacer. For example "the hand" in MTG has the tool capabilities as defined in https://github.com/minetest/minetest_game/blob/master/mods/default/tools.lua#L10
While the replacer should still be able to place everything, adding this capabilities could prevent it from digging nodes of higher level or lower group ranking or different groups.
Would it be possible to include a feature like this?