Support wallmounted nodes with default screwdriver behavior

master
entuland 2018-06-20 15:02:14 +02:00
parent 6378cbf733
commit 05cd360029
2 changed files with 42 additions and 0 deletions

View File

@ -85,5 +85,6 @@ Here are possible messages you can receive:
- Pulled closest edge (sneak + left click)
- Cannot rotate node with paramtype2 == glasslikeliquidlevel
- Unsupported node type: modname:nodename
- Wallmounted node rotated with default screwdriver behavior
plus some more messages warning about protected areas or rotations performed or prevented by custom on_rotate() handlers.

View File

@ -284,6 +284,47 @@ end
handlers.colorfacedir = handlers.facedir
-- ============================================================
-- Replicate default screwdriver behavior for wallmounted nodes
-- For attached wallmounted nodes: returns true if rotation is valid
-- simplified version of minetest:builtin/game/falling.lua#L148.
local function check_attached_node(pos, rotation)
local d = minetest.wallmounted_to_dir(rotation)
local p2 = vector.add(pos, d)
local n = minetest.get_node(p2).name
local def2 = minetest.registered_nodes[n]
if def2 and not def2.walkable then
return false
end
return true
end
local wallmounted_tbl = {
[PRIMARY_BTN] = {[2] = 5, [3] = 4, [4] = 2, [5] = 3, [1] = 0, [0] = 1},
[SECONDARY_BTN] = {[2] = 5, [3] = 4, [4] = 2, [5] = 1, [1] = 0, [0] = 3}
}
function handlers.wallmounted(node, player, pointed_thing, click)
local pos = pointed_thing.under
local rotation = node.param2 % 8 -- get first 3 bits
local other = node.param2 - rotation
rotation = wallmounted_tbl[click][rotation] or 0
if minetest.get_item_group(node.name, "attached_node") ~= 0 then
-- find an acceptable orientation
for i = 1, 5 do
if not check_attached_node(pos, rotation) then
rotation = wallmounted_tbl[click][rotation] or 0
else
break
end
end
end
return rotation + other, "Wallmounted node rotated with default screwdriver behavior"
end
handlers.colorwallmounted = handlers.wallmounted
-- ============================================================
-- interaction