From 55770131f26b72c2776ae7b1c938102d4ee1e5c2 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Mon, 23 Aug 2021 15:27:48 -0700 Subject: [PATCH] Add sample nodes & setting to enable them --- README.md | 4 +- init.lua | 5 + samples.lua | 145 ++++++++++++++++++ settingtypes.txt | 3 + .../simple_models_sample_cube_1x2x1_map.png | Bin .../simple_models_sample_panel_1x2x1_map.png | Bin 6 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 samples.lua create mode 100644 settingtypes.txt rename previews/cube_1x2x1_map.png => textures/simple_models_sample_cube_1x2x1_map.png (100%) rename previews/panel_1x2x1_map.png => textures/simple_models_sample_panel_1x2x1_map.png (100%) diff --git a/README.md b/README.md index 5341abb..d4f8ea4 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A set of very simple models for [Minetest](https://www.minetest.net/). - texture map: - + simple_models_panel_1x2x1: - for door or panel-like nodes with dimensions 1x2x1 @@ -27,7 +27,7 @@ simple_models_panel_1x2x1: - texture map: - + simple_models_panel_rear_1x2x1: - for door or panel-like nodes with dimensions 1x2x1 positioned at rear diff --git a/init.lua b/init.lua index 7e32fde..7555f66 100644 --- a/init.lua +++ b/init.lua @@ -57,3 +57,8 @@ simple_models.panel_rear = simple_models.panel_rear_1x2x1 if not core.global_exists("smodel") then smodel = simple_models end + + +if core.settings:get_bool("simple_models.enable_samples", false) then + dofile(core.get_modpath(core.get_current_modname()) .. "/samples.lua") +end diff --git a/samples.lua b/samples.lua new file mode 100644 index 0000000..70c7c1d --- /dev/null +++ b/samples.lua @@ -0,0 +1,145 @@ + +core.register_node("simple_models:node_tall", { + description = "Tall Node", + drawtype = "mesh", + mesh = smodel.cube.mesh, + tiles = {"simple_models_sample_cube_1x2x1_map.png"}, + collision_box = { + type = "fixed", + fixed = smodel.cube.box, + }, + selection_box = { + type = "fixed", + fixed = smodel.cube.box, + }, + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=1}, +}) + +core.register_node("simple_models:panel", { + description = "Panel", + drawtype = "mesh", + tiles = {"simple_models_sample_panel_1x2x1_map.png"}, + mesh = smodel.panel.mesh, + collision_box = { + type = "fixed", + fixed = smodel.panel.box, + }, + selection_box = { + type = "fixed", + fixed = smodel.panel.box, + }, + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=1}, + + on_rightclick = function(pos, node, clicker, stack, pointed_thing) + core.swap_node(pos, { + name = "simple_models:panel_rear", + param1 = node.param1, + param2 = node.param2, + }) + if core.global_exists("sounds") and sounds.woosh then + sounds.woosh() + end + + return stack + end, +}) + +core.register_node("simple_models:panel_rear", { + description = "Panel", + drawtype = "mesh", + tiles = {"simple_models_sample_panel_1x2x1_map.png"}, + mesh = smodel.panel_rear.mesh, + collision_box = { + type = "fixed", + fixed = smodel.panel_rear.box, + }, + selection_box = { + type = "fixed", + fixed = smodel.panel_rear.box, + }, + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=1}, + + on_rightclick = function(pos, node, clicker, stack, pointed_thing) + core.swap_node(pos, { + name="simple_models:panel", + param1 = node.param1, + param2 = node.param2, + }) + if core.global_exists("sounds") and sounds.woosh then + sounds.woosh() + end + + return stack + end, +}) + +core.register_node("simple_models:door", { + description = "Door", + drawtype = "mesh", + tiles = {"simple_models_sample_panel_1x2x1_map.png"}, + mesh = smodel.panel.mesh, + collision_box = { + type = "fixed", + fixed = smodel.panel.box, + }, + selection_box = { + type = "fixed", + fixed = smodel.panel.box, + }, + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=1}, + + on_rightclick = function(pos, node, clicker, stack, pointed_thing) + local rot = node.param2-1 + if rot < 0 then + rot = 3 + end + core.swap_node(pos, { + name = "simple_models:door_open", + param1 = node.param1, + param2 = rot, + }) + if core.global_exists("sounds") and sounds.door_open then + sounds.door_open() + end + + return stack + end, +}) + +core.register_node("simple_models:door_open", { + description = "Door", + drawtype = "mesh", + tiles = {"simple_models_sample_panel_1x2x1_map.png"}, + mesh = smodel.panel_rear.mesh, + collision_box = { + type = "fixed", + fixed = smodel.panel_rear.box, + }, + selection_box = { + type = "fixed", + fixed = smodel.panel_rear.box, + }, + paramtype2 = "facedir", + groups = {oddly_breakable_by_hand=1}, + + on_rightclick = function(pos, node, clicker, stack, pointed_thing) + local rot = node.param2+1 + if rot > 3 then + rot = 0 + end + core.swap_node(pos, { + name = "simple_models:door", + param1 = node.param1, + param2 = rot, + }) + if core.global_exists("sounds") and sounds.door_open then + sounds.door_open() + end + + return stack + end, +}) diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..4fc67ea --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,3 @@ + +# Enables some sample nodes using models. +simple_models.enable_samples (Enable node samples) bool false diff --git a/previews/cube_1x2x1_map.png b/textures/simple_models_sample_cube_1x2x1_map.png similarity index 100% rename from previews/cube_1x2x1_map.png rename to textures/simple_models_sample_cube_1x2x1_map.png diff --git a/previews/panel_1x2x1_map.png b/textures/simple_models_sample_panel_1x2x1_map.png similarity index 100% rename from previews/panel_1x2x1_map.png rename to textures/simple_models_sample_panel_1x2x1_map.png