Invert the meaning of screwdriver Sneak for doors

master
Wuzzy 2021-10-09 22:05:24 +02:00
parent 5f37eaa95e
commit b5aa07dbe3
3 changed files with 21 additions and 1 deletions

View File

@ -103,6 +103,10 @@ Action groups:
* `flora`: This is a plant that spreads on Dirt with Grass
* `soil`: Usable by hoe
* `not_in_craft_guide`: Item won't appear in craft guide
* `rotation_takes_precedence=1`: Group for nodes. Normally, if rotation tool (e.g. screwdriver) is "placed"
on this node, the `on_rightclick` action takes precedence, and the rotation action is used when Sneak
key is held. But if this group is set, it's the other way around: The rotation action is executed
by default and if Sneak is pressed, `on_rightclick` is executed instead
Legacy groups:
* `flammable`: Considered flammable (Note: This game has no fire)

View File

@ -891,6 +891,7 @@ function doors.register_door( name, def )
def.drop = name
def.groups.not_in_creative_inventory = 1
def.groups.door = 1
def.groups.rotation_takes_precedence = 1
-- define the crafting recipe
@ -1063,6 +1064,7 @@ function doors.register_trapdoor( name, def )
def.groups = {}
end
def.groups.trapdoor = 1
def.groups.rotation_takes_precedence = 1
-- define the opening/closing sounds

View File

@ -104,8 +104,22 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
if not ndef then
return itemstack
end
-- Execute `on_rightclick` of node if present and player did not press Sneak,
-- otherwise, the rotation action is executed.
-- If `rotation_takes_precedence=1` group is present, this behavior is flipped:
-- `on_rightclick` executed if sneak pressed, rotation action executed if sneak
-- not pressed.
local prec = minetest.get_item_group(node.name, "rotation_takes_precedence") == 1
local sneak = false
if user then
sneak = user:get_player_control().sneak
if prec then
sneak = not sneak
end
end
if mode == screwdriver.ROTATE_AXIS and ndef and ndef.on_rightclick and
((not user) or (user and not user:get_player_control().sneak)) then
((not user) or (not sneak)) then
return ndef.on_rightclick(pos, node, user, itemstack,
pointed_thing) or itemstack
end