From e51b1b709a9020b6d95e240c8dc8c8515a3208ff Mon Sep 17 00:00:00 2001 From: OldCoder Date: Tue, 27 Jul 2021 22:01:23 -0700 Subject: [PATCH] Convert ZIP version to git repo --- depends.txt | 1 + init.lua | 145 +++++++++++++++++++++++++++++++++++++++++ textures/door_wood.png | Bin 0 -> 166 bytes 3 files changed, 146 insertions(+) create mode 100644 depends.txt create mode 100644 init.lua create mode 100644 textures/door_wood.png diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +default diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..620f242 --- /dev/null +++ b/init.lua @@ -0,0 +1,145 @@ +-- xDoors mod by xyz + +models = { + { + -- bottom part + {-0.5, -0.5, -0.5, -0.4, 0.5, 0.5}, + -- A + {-0.5, 0.5, -0.5, -0.4, 1.5, -0.3}, + -- B + {-0.5, 0.5, 0.3, -0.4, 1.5, 0.5}, + -- C + {-0.5, 1.3, -0.3, -0.4, 1.5, 0.3}, + -- D + {-0.5, 0.5, -0.3, -0.4, 0.6, 0.3}, + -- E + {-0.5, 0.6, -0.05, -0.4, 1.3, 0.05}, + -- F + {-0.5, 0.9, -0.3, -0.4, 1, -0.05}, + -- G + {-0.5, 0.9, 0.05, -0.4, 1, 0.3} + }, + { + {0.4, -0.5, -0.5, 0.5, 0.5, 0.5}, + {0.4, 0.5, -0.5, 0.5, 1.5, -0.3}, + {0.4, 0.5, 0.3, 0.5, 1.5, 0.5}, + {0.4, 1.3, -0.3, 0.5, 1.5, 0.3}, + {0.4, 0.5, -0.3, 0.5, 0.6, 0.3}, + {0.4, 0.6, -0.05, 0.5, 1.3, 0.05}, + {0.4, 0.9, -0.3, 0.5, 1, -0.05}, + {0.4, 0.9, 0.05, 0.5, 1, 0.3} + }, + { + {-0.5, -0.5, -0.5, 0.5, 0.5, -0.4}, + {-0.5, 0.5, -0.5, -0.3, 1.5, -0.4}, + {0.3, 0.5, -0.5, 0.5, 1.5, -0.4}, + {-0.3, 1.3, -0.5, 0.3, 1.5, -0.4}, + {-0.3, 0.5, -0.5, 0.3, 0.6, -0.4}, + {-0.05, 0.6, -0.5, 0.05, 1.3, -0.4}, + {-0.3, 0.9, -0.5, -0.05, 1, -0.4}, + {0.05, 0.9, -0.5, 0.3, 1, -0.4} + }, + { + {-0.5, -0.5, 0.4, 0.5, 0.5, 0.5}, + {-0.5, 0.5, 0.4, -0.3, 1.5, 0.5}, + {0.3, 0.5, 0.4, 0.5, 1.5, 0.5}, + {-0.3, 1.3, 0.4, 0.3, 1.5, 0.5}, + {-0.3, 0.5, 0.4, 0.3, 0.6, 0.5}, + {-0.05, 0.6, 0.4, 0.05, 1.3, 0.5}, + {-0.3, 0.9, 0.4, -0.05, 1, 0.5}, + {0.05, 0.9, 0.4, 0.3, 1, 0.5} + } +} + +selections = { + {-0.5, -0.5, -0.5, -0.4, 1.5, 0.5}, + {0.5, -0.5, -0.5, 0.4, 1.5, 0.5}, + {-0.5, -0.5, -0.5, 0.5, 1.5, -0.4}, + {-0.5, -0.5, 0.4, 0.5, 1.5, 0.5} +} + +transforms = { + door_1_1 = "door_4_2", + door_4_2 = "door_1_1", + door_2_1 = "door_3_2", + door_3_2 = "door_2_1", + door_3_1 = "door_1_2", + door_1_2 = "door_3_1", + door_4_1 = "door_2_2", + door_2_2 = "door_4_1" +} + +function xdoors_transform(pos, node, puncher) + local x, y = node.name:find(":") + local n = node.name:sub(x + 1) + if transforms[n] ~= nil then + minetest.env:add_node(pos, {name = "xdoors:"..transforms[n]}) + else + print("not implemented") + end +end + +for i = 1, 4 do + for j = 1, 2 do + minetest.register_node("xdoors:door_"..i.."_"..j, { + drawtype = "nodebox", + tile_images = {"default_wood.png"}, + paramtype = "light", + is_ground_content = true, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, + drop = "xdoors:door", + node_box = { + type = "fixed", + fixed = models[i] + }, + selection_box = { + type = "fixed", + fixed = { + selections[i] + } + }, + on_punch = xdoors_transform + }) + end +end + +minetest.register_node("xdoors:door", { + description = "Wooden door", + node_placement_prediction = "", + inventory_image = 'door_wood.png', + wield_image = 'door_wood.png', + after_place_node = function(node_pos, placer) + local best_distance = 1e50 + local best_number = 1 + local pos = placer:getpos() + for i = 1, 4 do + local box = minetest.registered_nodes["xdoors:door_"..i.."_1"].selection_box.fixed[1] + box = {box[1] + node_pos.x, box[2] + node_pos.y, box[3] + node_pos.z, box[4] + node_pos.x, box[5] + node_pos.y, box[6] + node_pos.z} + local center = {x = (box[1] + box[4]) / 2, y = (box[2] + box[5]) / 2, z = (box[3] + box[6]) / 2} + local dist = math.pow(math.pow(center.x - pos.x, 2) + math.pow(center.y - pos.y, 2) + math.pow(center.z - pos.z, 2), 0.5) + if dist < best_distance then + best_distance = dist + best_number = i + end + end + minetest.env:add_node(node_pos, {name = "xdoors:door_"..best_number.."_1"}) + end +}) + +minetest.register_on_placenode(function(pos, newnode, placer) + local b_pos = {x = pos.x, y = pos.y - 1, z = pos.z} + local node = minetest.env:get_node(b_pos) + if node.name:find("xdoors:door") ~= nil then + minetest.env:remove_node(pos) + minetest.env:add_item(pos, newnode.name) + end +end) + +minetest.register_craft({ + output = 'xdoors:door', + recipe = { + { 'default:wood', 'default:wood', '' }, + { 'default:wood', 'default:wood', '' }, + { 'default:wood', 'default:wood', '' }, + }, +}) diff --git a/textures/door_wood.png b/textures/door_wood.png new file mode 100644 index 0000000000000000000000000000000000000000..120fc982f7aeb151b2c014678b205072b2b20907 GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|5