Doors: Allow schematic placement of wooden doors.
authorAuke Kok <sofar@foo-projects.org>
Mon, 21 Mar 2016 06:48:16 +0000 (23:48 -0700)
committerparamat <mat.gregory@virginmedia.com>
Tue, 22 Mar 2016 15:45:54 +0000 (15:45 +0000)
If LVM or some other nonmetadata method is used to place a door,
then metadata is missing that tells us whether the door is left
or right-hinged.

However, we can detect that nodemeta is missing and see if the node
name is _a or _b. In the case of _a, nothing needs to be done and we
can just open the door. In the case of _b we assume the door is right
hinged, and tune the state nodemeta value so that the door opens the
right way. This all of course assumes that the schematic method places
the doors *closed* by default, which is reasonable.

mods/doors/init.lua

index bd3e69985f7f4bf5e14755fddeac8b7c62df5ac8..c0fd5bfffa008b2a103cc23a4c7b33948a328b06 100644 (file)
@@ -132,10 +132,19 @@ local transform = {
 
 function _doors.door_toggle(pos, clicker)
        local meta = minetest.get_meta(pos)
-       local state = meta:get_int("state")
        local def = minetest.registered_nodes[minetest.get_node(pos).name]
        local name = def.door.name
 
+       local state = meta:get_string("state")
+       if state == "" then
+               -- fix up lvm-placed right-hinged doors, default closed
+               if minetest.get_node(pos).name:sub(-2) == "_b" then
+                       state = 2
+               end
+       else
+               state = tonumber(state)
+       end
+
        if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
                local owner = meta:get_string("doors_owner")
                if owner ~= "" then