From 87f79ba3f23e6ef1126c269fcdcc204947097961 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 5 Sep 2019 08:37:01 +0200 Subject: [PATCH 1/8] add luacheckrc --- .luacheckrc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..5fcaf02 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,21 @@ +unused_args = false +allow_defined_top = true + +globals = { + "minetest", + "mesecon" +} + +read_globals = { + -- Stdlib + string = {fields = {"split"}}, + table = {fields = {"copy", "getn"}}, + + -- Minetest + "vector", "ItemStack", + "dump", + + -- optional deps + "default", "stairsplus", "xpanes" + +} From 2ab7e3e6b5511bb68de069d1f28f842b2b13e513 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 5 Sep 2019 08:44:32 +0200 Subject: [PATCH 2/8] lua modules --- builder.lua | 95 ++++++ chest.lua | 124 ++++++++ init.lua | 888 +--------------------------------------------------- nodes.lua | 605 +++++++++++++++++++++++++++++++++++ plants.lua | 48 +++ 5 files changed, 883 insertions(+), 877 deletions(-) create mode 100644 builder.lua create mode 100644 chest.lua create mode 100644 nodes.lua create mode 100644 plants.lua diff --git a/builder.lua b/builder.lua new file mode 100644 index 0000000..6831d4a --- /dev/null +++ b/builder.lua @@ -0,0 +1,95 @@ + + +--the builder node + +local builder_formspec = + "size[8,9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[current_name;input;1,1;1,1;]" .. + "list[current_name;output;3,0;4,3;]" .. + "list[current_player;main;0,4.85;8,1;]" .. + "list[current_player;main;0,6.08;8,3;8]" .. + "listring[current_name;input]" .. + "listring[current_name;output]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,4.85) + +local input_items = { + {"default:steel_ingot 1", "scifi_nodes:black", "scifi_nodes:blue", "scifi_nodes:rough", "scifi_nodes:rust", "scifi_nodes:white", "scifi_nodes:grey", "scifi_nodes:pplwll", "scifi_nodes:greenmetal", "scifi_nodes:wall", "scifi_nodes:blue_square", "scifi_nodes:mesh", "scifi_nodes:greytile"} +} + +minetest.register_node("scifi_nodes:builder", { + description = "Sci-fi Node Builder", + tiles = { + "scifi_nodes_builder.png", + "scifi_nodes_builder.png", + "scifi_nodes_builder_side.png", + "scifi_nodes_builder_side.png", + "scifi_nodes_builder_side.png", + "scifi_nodes_builder_front.png" + }, + on_construct = function(pos) + --local meta = minetest.get_meta(pos) + --meta:set_string("infotext", "Node Builder (currently does nothing)") + + local meta = minetest.get_meta(pos) + meta:set_string("formspec", builder_formspec) + meta:set_string("infotext", "Node Builder") + local inv = meta:get_inventory() + inv:set_size("output", 4 * 3) + inv:set_size("input", 1 * 1) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local player_inv = player:get_inventory() + if listname == "output" then + player_inv:add_item("main", stack) + inv:set_stack("output", index, "") + end + if listname == "input" then + for _, row in ipairs(input_items) do + local item = row[1] + if inv:contains_item("input", item) then + inv:set_stack("output", 1, row[2]) + inv:set_stack("output", 2, row[3]) + inv:set_stack("output", 3, row[4]) + inv:set_stack("output", 4, row[5]) + inv:set_stack("output", 5, row[6]) + inv:set_stack("output", 6, row[7]) + inv:set_stack("output", 7, row[8]) + inv:set_stack("output", 8, row[9]) + inv:set_stack("output", 9, row[10]) + inv:set_stack("output", 10, row[11]) + inv:set_stack("output", 11, row[12]) + inv:set_stack("output", 12, row[13]) + end + end + end + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local stack = inv:get_stack("input", 1) + local stack_name = stack:get_name() + inv:remove_item("input", stack_name.." 1") + + inv:set_stack("output", 1, "") + inv:set_stack("output", 2, "") + inv:set_stack("output", 3, "") + inv:set_stack("output", 4, "") + inv:set_stack("output", 5, "") + inv:set_stack("output", 6, "") + inv:set_stack("output", 7, "") + inv:set_stack("output", 8, "") + inv:set_stack("output", 9, "") + inv:set_stack("output", 10, "") + inv:set_stack("output", 11, "") + inv:set_stack("output", 12, "") + end, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1, oddly_breakable_by_hand=1} +}) diff --git a/chest.lua b/chest.lua new file mode 100644 index 0000000..a1289e2 --- /dev/null +++ b/chest.lua @@ -0,0 +1,124 @@ + +--chest code from default(Copyright (C) 2012 celeron55, Perttu Ahola ) + +local chest_formspec = + "size[8,9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[current_name;main;0,0.3;8,4;]" .. + "list[current_player;main;0,4.85;8,1;]" .. + "list[current_player;main;0,6.08;8,3;8]" .. + "listring[current_name;main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,4.85) + +local function get_locked_chest_formspec(pos) + local spos = pos.x .. "," .. pos.y .. "," .. pos.z + local formspec = + "size[8,9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" .. + "list[current_player;main;0,4.85;8,1;]" .. + "list[current_player;main;0,6.08;8,3;8]" .. + "listring[nodemeta:" .. spos .. ";main]" .. + "listring[current_player;main]" .. + default.get_hotbar_bg(0,4.85) + return formspec +end + + +-- Helper functions + +local function drop_chest_stuff() + return function(pos, oldnode, oldmetadata, digger) + local meta = minetest.get_meta(pos) + meta:from_table(oldmetadata) + local inv = meta:get_inventory() + for i = 1, inv:get_size("main") do + local stack = inv:get_stack("main", i) + if not stack:is_empty() then + local p = { + x = pos.x + math.random(0, 5)/5 - 0.5, + y = pos.y, + z = pos.z + math.random(0, 5)/5 - 0.5} + minetest.add_item(p, stack) + end + end + end +end + +--chest code Copyright (C) 2011-2012 celeron55, Perttu Ahola +minetest.register_node("scifi_nodes:crate", { + description = "Crate", + tiles = {"scifi_nodes_crate.png"}, + paramtype2 = "facedir", + groups = {cracky = 1, oddly_breakable_by_hand = 2, fuel = 8}, + legacy_facedir_simple = true, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), + + after_dig_node = drop_chest_stuff(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", chest_formspec) + meta:set_string("infotext", "Crate") + local inv = meta:get_inventory() + inv:set_size("main", 8 * 4) + end, + on_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + minetest.log("action", player:get_player_name() .. + " moves stuff in chest at " .. minetest.pos_to_string(pos)) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " moves stuff to chest at " .. minetest.pos_to_string(pos)) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " takes stuff from chest at " .. minetest.pos_to_string(pos)) + end, +}) + +minetest.register_node("scifi_nodes:box", { + description = "Storage box", + tiles = { + "scifi_nodes_box_top.png", + "scifi_nodes_box_top.png", + "scifi_nodes_box.png", + "scifi_nodes_box.png", + "scifi_nodes_box.png", + "scifi_nodes_box.png" + }, + paramtype2 = "facedir", + groups = {cracky = 1}, + legacy_facedir_simple = true, + is_ground_content = false, + sounds = default.node_sound_metal_defaults(), + + after_dig_node = drop_chest_stuff(), + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", chest_formspec) + meta:set_string("infotext", "Box") + local inv = meta:get_inventory() + inv:set_size("main", 8 * 4) + end, + on_metadata_inventory_move = function(pos, from_list, from_index, + to_list, to_index, count, player) + minetest.log("action", player:get_player_name() .. + " moves stuff in chest at " .. minetest.pos_to_string(pos)) + end, + on_metadata_inventory_put = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " moves stuff to chest at " .. minetest.pos_to_string(pos)) + end, + on_metadata_inventory_take = function(pos, listname, index, stack, player) + minetest.log("action", player:get_player_name() .. + " takes stuff from chest at " .. minetest.pos_to_string(pos)) + end, +}) +--end of chest code \ No newline at end of file diff --git a/init.lua b/init.lua index 3d6eb52..7664821 100644 --- a/init.lua +++ b/init.lua @@ -1,881 +1,15 @@ --scifi_nodes by D00Med +local MP = minetest.get_modpath("scifi_nodes") ---the builder node - -local builder_formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;input;1,1;1,1;]" .. - "list[current_name;output;3,0;4,3;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[current_name;input]" .. - "listring[current_name;output]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) - -local input_items = { - {"default:steel_ingot 1", "scifi_nodes:black", "scifi_nodes:blue", "scifi_nodes:rough", "scifi_nodes:rust", "scifi_nodes:white", "scifi_nodes:grey", "scifi_nodes:pplwll", "scifi_nodes:greenmetal", "scifi_nodes:wall", "scifi_nodes:blue_square", "scifi_nodes:mesh", "scifi_nodes:greytile"} -} - -minetest.register_node("scifi_nodes:builder", { - description = "Sci-fi Node Builder", - tiles = { - "scifi_nodes_builder.png", - "scifi_nodes_builder.png", - "scifi_nodes_builder_side.png", - "scifi_nodes_builder_side.png", - "scifi_nodes_builder_side.png", - "scifi_nodes_builder_front.png" - }, - on_construct = function(pos) - --local meta = minetest.get_meta(pos) - --meta:set_string("infotext", "Node Builder (currently does nothing)") - - local meta = minetest.get_meta(pos) - meta:set_string("formspec", builder_formspec) - meta:set_string("infotext", "Node Builder") - local inv = meta:get_inventory() - inv:set_size("output", 4 * 3) - inv:set_size("input", 1 * 1) - end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local player_inv = player:get_inventory() - if listname == "output" then - player_inv:add_item("main", stack) - inv:set_stack("output", index, "") - end - if listname == "input" then - for _, row in ipairs(input_items) do - local item = row[1] - if inv:contains_item("input", item) then - inv:set_stack("output", 1, row[2]) - inv:set_stack("output", 2, row[3]) - inv:set_stack("output", 3, row[4]) - inv:set_stack("output", 4, row[5]) - inv:set_stack("output", 5, row[6]) - inv:set_stack("output", 6, row[7]) - inv:set_stack("output", 7, row[8]) - inv:set_stack("output", 8, row[9]) - inv:set_stack("output", 9, row[10]) - inv:set_stack("output", 10, row[11]) - inv:set_stack("output", 11, row[12]) - inv:set_stack("output", 12, row[13]) - end - end - end - end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local stack = inv:get_stack("input", 1) - local stack_name = stack:get_name() - inv:remove_item("input", stack_name.." 1") - - inv:set_stack("output", 1, "") - inv:set_stack("output", 2, "") - inv:set_stack("output", 3, "") - inv:set_stack("output", 4, "") - inv:set_stack("output", 5, "") - inv:set_stack("output", 6, "") - inv:set_stack("output", 7, "") - inv:set_stack("output", 8, "") - inv:set_stack("output", 9, "") - inv:set_stack("output", 10, "") - inv:set_stack("output", 11, "") - inv:set_stack("output", 12, "") - end, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1, oddly_breakable_by_hand=1} -}) - ---nodes - -minetest.register_node("scifi_nodes:grassblk", { - description = "Dirt With Alien Grass", - tiles = {"default_grass.png^[colorize:cyan:80", "default_dirt.png", - {name = "default_dirt.png^(default_grass_side.png^[colorize:cyan:80)", - tileable_vertical = false}}, - light_source = 2, - groups = {crumbly=1, oddly_breakable_by_hand=1, soil=1} -}) - -minetest.register_node("scifi_nodes:light", { - description = "blue lightbox", - sunlight_propagates = false, - tiles = { - "scifi_nodes_lighttop.png", - "scifi_nodes_lighttop.png", - "scifi_nodes_light.png", - "scifi_nodes_light.png", - "scifi_nodes_light.png", - "scifi_nodes_light.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1} -}) - -minetest.register_node("scifi_nodes:rfloor", { - description = "rusty floor", - tiles = { - "scifi_nodes_rustfloor.png", - }, - paramtype = "light", - paramtype2 = "facedir", - light_source = 10, - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults() -}) - -minetest.register_node("scifi_nodes:bfloor", { - description = "blue floor", - tiles = { - "scifi_nodes_bluefloor.png", - }, - paramtype = "light", - paramtype2 = "facedir", - light_source = 10, - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults() -}) - - -minetest.register_node("scifi_nodes:stripes2", { - description = "hazard stripes2", - sunlight_propagates = false, - tiles = { - "scifi_nodes_stripes2top.png", - "scifi_nodes_stripes2top.png", - "scifi_nodes_stripes2.png", - "scifi_nodes_stripes2.png", - "scifi_nodes_stripes2.png", - "scifi_nodes_stripes2.png" - }, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults() -}) - -minetest.register_node("scifi_nodes:gblock", { - description = "Green metal block", - sunlight_propagates = false, - tiles = { - "scifi_nodes_gblock.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock.png" - }, - paramtype = "light", - groups = {cracky=1}; - sounds = default.node_sound_metal_defaults() -}) - -minetest.register_node("scifi_nodes:gblock2", { - description = "Green metal block 2", - sunlight_propagates = false, - tiles = { - "scifi_nodes_gblock2_top.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock2.png", - "scifi_nodes_gblock2_fx.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock2_front1.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults() -}) - -minetest.register_node("scifi_nodes:gblock3", { - description = "Green metal block 3", - sunlight_propagates = false, - tiles = { - "scifi_nodes_gblock2_top.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock2.png", - "scifi_nodes_gblock2_fx.png", - "scifi_nodes_gblock.png", - "scifi_nodes_gblock2_screen.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults() -}) - - - -minetest.register_node("scifi_nodes:green_light", { - description = "green lightbox", - sunlight_propagates = false, - tiles = { - "scifi_nodes_lighttop.png", - "scifi_nodes_lighttop.png", - "scifi_nodes_greenlight.png", - "scifi_nodes_greenlight.png", - "scifi_nodes_greenlight.png", - "scifi_nodes_greenlight.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:red_light", { - description = "red lightbox", - sunlight_propagates = false, - tiles = { - "scifi_nodes_lighttop.png", - "scifi_nodes_lighttop.png", - "scifi_nodes_redlight.png", - "scifi_nodes_redlight.png", - "scifi_nodes_redlight.png", - "scifi_nodes_redlight.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:discs", { - description = "disc shelves", - sunlight_propagates = false, - tiles = { - "scifi_nodes_box_top.png", - "scifi_nodes_box_top.png", - "scifi_nodes_discs.png", - "scifi_nodes_discs.png", - "scifi_nodes_discs.png", - "scifi_nodes_discs.png" - }, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:disc", { - description = "disc", - drawtype = "torchlike", - sunlight_propagates = false, - tiles = { - "scifi_nodes_disc.png" - }, - inventory_image = "scifi_nodes_disc.png", - wield_image = "scifi_nodes_disc.png", - paramtype = "light", - groups = {cracky=1} -}) - - -minetest.register_node("scifi_nodes:blink", { - description = "blinking light", - sunlight_propagates = false, - tiles = {{ - name="scifi_nodes_lightbox.png", - animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.00}, - }}, - paramtype = "light", - groups = {cracky=1}, - light_source = 5, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:black_lights", { - description = "black wallpanel", - sunlight_propagates = false, - tiles = {{ - name="scifi_nodes_black_lights.png", - animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, - }}, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:black_screen", { - description = "black wall screen", - sunlight_propagates = false, - tiles = {{ - name="scifi_nodes_black_screen.png", - animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.00}, - }}, - paramtype = "light", - groups = {cracky=1}, - light_source = 1, - sounds = default.node_sound_stone_defaults() -}) - -minetest.register_node("scifi_nodes:screen", { - description = "electronic screen", - sunlight_propagates = false, - tiles = {{ - name="scifi_nodes_screen.png", - animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, - }}, - paramtype = "light", - groups = {cracky=1}, - light_source = 5, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:screen2", { - description = "electronic screen 2", - sunlight_propagates = false, - tiles = {{ - name="scifi_nodes_screen2.png", - animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, - }}, - paramtype = "light", - groups = {cracky=1}, - light_source = 5, - sounds = default.node_sound_glass_defaults() -}) - - - -minetest.register_node("scifi_nodes:white_pad", { - description = "white keypad", - sunlight_propagates = false, - tiles = { - "scifi_nodes_white2.png", - "scifi_nodes_white2.png", - "scifi_nodes_white2.png", - "scifi_nodes_white2.png", - "scifi_nodes_white2.png", - "scifi_nodes_white_pad.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:white_base", { - description = "white wall base", - sunlight_propagates = false, - tiles = { - "scifi_nodes_white2.png", - "scifi_nodes_white2.png", - "scifi_nodes_white_side.png", - "scifi_nodes_white_side.png", - "scifi_nodes_white_side.png", - "scifi_nodes_white_side.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:grnpipe", { - description = "green pipe", - sunlight_propagates = false, - tiles = { - "scifi_nodes_greenpipe_front.png", - "scifi_nodes_greenpipe_front.png", - "scifi_nodes_greenpipe_top.png", - "scifi_nodes_greenpipe_top.png", - "scifi_nodes_greenpipe_top.png", - "scifi_nodes_greenpipe_top.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults(), - on_place = minetest.rotate_node -}) - - -minetest.register_node("scifi_nodes:grnpipe2", { - description = "broken green pipe", - sunlight_propagates = false, - tiles = { - "scifi_nodes_greenpipe_front.png", - "scifi_nodes_greenpipe_front.png", - "scifi_nodes_greenpipe2_top.png", - "scifi_nodes_greenpipe2_top.png", - "scifi_nodes_greenpipe2_top.png", - "scifi_nodes_greenpipe2_top.png" - }, - paramtype = "light", - paramtype2 = "facedir", - groups = {cracky=1}, - sounds = default.node_sound_metal_defaults(), - on_place = minetest.rotate_node -}) - -minetest.register_node("scifi_nodes:octrng", { - description = "Orange Octagon Glass", - sunlight_propagates = false, - drawtype = "glasslike", - tiles = { - "scifi_nodes_octrng.png", - }, - paramtype = "light", - paramtype2 = "facedir", - use_texture_alpha = true, - light_source = 10, - groups = {cracky=2}, - sounds = default.node_sound_glass_defaults(), - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:octgrn", { - description = "Green Octagon Glass", - sunlight_propagates = false, - drawtype = "glasslike", - tiles = { - "scifi_nodes_octgrn.png", - }, - paramtype = "light", - paramtype2 = "facedir", - use_texture_alpha = true, - light_source = 10, - groups = {cracky=2}, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:octbl", { - description = "Blue Octagon Glass", - sunlight_propagates = false, - drawtype = "glasslike", - tiles = { - "scifi_nodes_octbl.png", - }, - paramtype = "light", - paramtype2 = "facedir", - use_texture_alpha = true, - light_source = 10, - groups = {cracky=2}, - sounds = default.node_sound_glass_defaults(), - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:octppl", { - description = "Purple Octagon Glass", - sunlight_propagates = false, - drawtype = "glasslike", - tiles = { - "scifi_nodes_octppl.png", - }, - paramtype = "light", - paramtype2 = "facedir", - use_texture_alpha = true, - light_source = 10, - groups = {cracky=2}, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:tower", { - description = "Wind tower", - sunlight_propagates = false, - drawtype = "plantlike", - tiles = {{ - name = "scifi_nodes_tower_anim.png", - animation = {type = "vertical_frames", aspect_w = 32, aspect_h = 32, length = 1.00}, - }}, - visual_scale = 2, - inventory_image = "scifi_nodes_tower.png", - paramtype = "light", - groups = {cracky=2}, - sounds = default.node_sound_metal_defaults() -}) - -minetest.register_node("scifi_nodes:junk", { - description = "Junk", - sunlight_propagates = true, - paramtype = "light", - liquid_viscosity = 8, - liquidtype = "source", - liquid_alternative_flowing = "scifi_nodes:junk", - liquid_alternative_source = "scifi_nodes:junk", - liquid_renewable = false, - liquid_range = 0, - walkable = false, - tiles = { - "scifi_nodes_junk.png" - }, - groups = {snappy=1, oddly_breakable_by_hand=1, liquid=3, dig_immediate=1} -}) - ---edited wool code (Copyright (C) 2012 celeron55, Perttu Ahola ) - -local node = {} --- This uses a trick: you can first define the recipes using all of the base --- colors, and then some recipes using more specific colors for a few non-base --- colors available. When crafting, the last recipes will be checked first. ---add new block using texture name(without "scifi_nodes_" prefix) then the description, and then the name of the block -node.types = { - {"blue", "blue lines", "blue"}, - {"holes", "metal with holes","holes"}, - {"white2", "plastic", "white2"}, - {"super_white", "Super Plastic", "super_white", 11}, - {"ultra_white", "Ultra Plastic", "ultra_white", default.LIGHT_MAX}, - {"engine", "engine", "engine"}, - {"wall", "metal wall", "wall"}, - {"white", "plastic wall", "white"}, - {"stripes2top", "dirty metal block","metal2"}, - {"rough", "rough metal", "rough"}, - {"lighttop", "metal block", "metal"}, - {"red", "red lines", "red"}, - {"green", "green lines", "green"}, - {"vent2", "vent", "vent"}, - {"stripes", "hazard stripes", "stripes"}, - {"rust", "rusty metal", "rust"}, - {"mesh", "metal mesh", "mesh"}, - {"black", "black wall", "black"}, - {"blackoct", "black octagon", "blackoct"}, - {"blackpipe", "black pipe", "blackpipe"}, - {"blacktile", "black tile", "blktl"}, - {"blacktile2", "black tile 2", "blktl2"}, - {"blackvent", "black vent", "blkvnt"}, - {"bluebars", "blue bars", "bluebars"}, - {"bluemetal", "blue metal", "blumtl"}, - {"bluetile", "blue tile", "blutl"}, - {"greytile", "grey tile", "grytl"}, - {"mesh2", "metal floormesh", "mesh2"}, - {"white", "plastic wall", "white"}, - {"pipe", "wall pipe", "pipe2"}, - {"pipeside", "side pipe", "pipe3"}, - {"tile", "white tile", "tile"}, - {"whiteoct", "white octagon", "whiteoct"}, - {"whitetile", "white tile2", "whttl"}, - {"black_detail", "black detail", "blckdtl"}, - {"green_square", "green metal block", "grnblck"}, - {"red_square", "red metal block", "redblck"}, - {"grey_square", "grey metal block", "greyblck"}, - {"blue_square", "blue metal block", "blublck"}, - {"black_mesh", "black vent block", "blckmsh"}, - {"dent", "dented metal block", "dent"}, - {"greenmetal", "green metal wall", "grnmetl"}, - {"greenmetal2", "green metal wall2", "grnmetl2"}, - {"greenlights", "green wall lights", "grnlt", 10}, - {"greenlights2", "green wall lights2", "grnlt2", 10}, - {"greenbar", "green light bar", "grnlghtbr", 10}, - {"green2", "green wall panel", "grn2"}, - {"greentubes", "green pipes", "grntubes"}, - {"grey", "grey wall", "gry"}, - {"greybolts", "grey wall bolts", "gryblts"}, - {"greybars", "grey bars", "grybrs"}, - {"greydots", "grey wall dots", "grydts"}, - {"greygreenbar", "gray power pipe", "grygrnbr", 10}, - {"octofloor", "Doom floor", "octofloor"}, - {"octofloor2", "Brown Doom floor", "octofloor2"}, - {"doomwall1", "Doom wall 1", "doomwall1"}, - {"doomwall2", "Doom wall 2", "doomwall2"}, - {"doomwall3", "Doom wall 3", "doomwall3"}, - {"doomwall4", "Doom wall 4", "doomwall4"}, - {"doomwall41", "Doom wall 4.1", "doomwall4.1"}, - {"doomwall42", "Doom wall 4.2", "doomwall4.2"}, - {"doomwall43", "Doom wall 4.3", "doomwall4.3"}, - {"doomwall431", "Doom wall 4.3.1", "doomwall4.3.1"}, - {"doomwall44", "Doom wall 4.4", "doomwall4.4"}, - {"blackdmg", "Damaged black wall", "blckdmg"}, - {"blackdmgstripe", "Damaged black wall(stripes)", "blckdmgstripe"}, - {"doomengine", "Doom engine wall", "doomengine"}, - {"monitorwall", "Wall monitors", "monitorwall"}, - {"screen3", "Wall monitor", "screen3"}, - {"doomlight", "Doom light", "doomlight", 12}, - {"bluwllight", "Blue wall light", "capsule3", default.LIGHT_MAX}, - {"bluegrid", "Blue Grid", "bluegrid", 5}, - {"fan", "Fan", "fan"}, - {"ppllght", "Purple wall light", "", default.LIGHT_MAX}, - {"pplwll", "Purple wall", "", 0}, - {"pplwll2", "Purple wall2", "", 0}, - {"pplwll3", "Purple wall3", "", 0}, - {"pplwll4", "Purple wall4", "", 0}, - {"pplblk", "Purple tile", "", 0}, - {"purple", "Purple node", "", 0}, - {"rock", "Moonstone", "", 0}, - {"rock2", "Moonstone2", "", 0}, - {"blackvnt", "Black vent", "", 0}, - {"blackplate", "Black plate", "", 0}, -} - -for _, row in ipairs(node.types) do - local name = row[1] - local desc = row[2] - local light = row[4] - -- Node Definition - minetest.register_node("scifi_nodes:"..name, { - description = desc, - tiles = {"scifi_nodes_"..name..".png"}, - groups = {cracky=1}, - paramtype = "light", - paramtype2 = "facedir", - light_source = light, - sounds = default.node_sound_glass_defaults() - }) +if minetest.get_modpath("xpanes") then + dofile(MP.."/panes.lua") end -node.plants = { - {"flower1", "Glow Flower", 1,0, default.LIGHT_MAX}, - {"flower2", "Pink Flower", 1.5,0, 10}, - {"flower3", "Triffid", 2,5, 0}, - {"flower4", "Weeping flower", 1.5,0, 0}, - {"plant1", "Bulb Plant", 1,0, 0}, - {"plant2", "Trap Plant", 1.5,0, default.LIGHT_MAX}, - {"plant3", "Blue Jelly Plant", 1.2,0, 10}, - {"plant4", "Green Jelly Plant", 1.2,0, 10}, - {"plant5", "Fern Plant", 1.7,0, 0}, - {"plant6", "Curly Plant", 1,0, 10}, - {"plant7", "Egg weed", 1,0, 0}, - {"plant8", "Slug weed", 1,0, 10}, - {"plant9", "Prickly Plant", 1,0, 0}, - {"plant10", "Umbrella weed", 1,0, 10}, - {"eyetree", "Eye Tree", 2.5,0, 0}, - {"grass", "Alien Grass", 1,0, 0}, -} - -for _, row in ipairs(node.plants) do - local name = row[1] - local desc = row[2] - local size = row[3] - local dmg = row[4] - local light = row[5] - -- Node Definition - minetest.register_node("scifi_nodes:"..name, { - description = desc, - tiles = {"scifi_nodes_"..name..".png"}, - drawtype = "plantlike", - inventory_image = {"scifi_nodes_"..name..".png"}, - groups = {snappy=1, oddly_breakable_by_hand=1, dig_immediate=3, flora=1}, - paramtype = "light", - visual_scale = size, - buildable_to = true, - walkable = false, - damage_per_second = dmg, - selection_box = { - type = "fixed", - fixed = { - {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}, - } - }, - is_ground_content = false, - light_source = light, - }) -end - ---chest code from default(Copyright (C) 2012 celeron55, Perttu Ahola ) - -local chest_formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[current_name;main;0,0.3;8,4;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[current_name;main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) - -local function get_locked_chest_formspec(pos) - local spos = pos.x .. "," .. pos.y .. "," .. pos.z - local formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[nodemeta:" .. spos .. ";main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) - return formspec -end - - --- Helper functions - -local function drop_chest_stuff() - return function(pos, oldnode, oldmetadata, digger) - local meta = minetest.get_meta(pos) - meta:from_table(oldmetadata) - local inv = meta:get_inventory() - for i = 1, inv:get_size("main") do - local stack = inv:get_stack("main", i) - if not stack:is_empty() then - local p = { - x = pos.x + math.random(0, 5)/5 - 0.5, - y = pos.y, - z = pos.z + math.random(0, 5)/5 - 0.5} - minetest.add_item(p, stack) - end - end - end -end - ---chest code Copyright (C) 2011-2012 celeron55, Perttu Ahola -minetest.register_node("scifi_nodes:crate", { - description = "Crate", - tiles = {"scifi_nodes_crate.png"}, - paramtype2 = "facedir", - groups = {cracky = 1, oddly_breakable_by_hand = 2, fuel = 8}, - legacy_facedir_simple = true, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), - - after_dig_node = drop_chest_stuff(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", chest_formspec) - meta:set_string("infotext", "Crate") - local inv = meta:get_inventory() - inv:set_size("main", 8 * 4) - end, - on_metadata_inventory_move = function(pos, from_list, from_index, - to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in chest at " .. minetest.pos_to_string(pos)) - end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " moves stuff to chest at " .. minetest.pos_to_string(pos)) - end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " takes stuff from chest at " .. minetest.pos_to_string(pos)) - end, -}) - -minetest.register_node("scifi_nodes:box", { - description = "Storage box", - tiles = { - "scifi_nodes_box_top.png", - "scifi_nodes_box_top.png", - "scifi_nodes_box.png", - "scifi_nodes_box.png", - "scifi_nodes_box.png", - "scifi_nodes_box.png" - }, - paramtype2 = "facedir", - groups = {cracky = 1}, - legacy_facedir_simple = true, - is_ground_content = false, - sounds = default.node_sound_metal_defaults(), - - after_dig_node = drop_chest_stuff(), - on_construct = function(pos) - local meta = minetest.get_meta(pos) - meta:set_string("formspec", chest_formspec) - meta:set_string("infotext", "Box") - local inv = meta:get_inventory() - inv:set_size("main", 8 * 4) - end, - on_metadata_inventory_move = function(pos, from_list, from_index, - to_list, to_index, count, player) - minetest.log("action", player:get_player_name() .. - " moves stuff in chest at " .. minetest.pos_to_string(pos)) - end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " moves stuff to chest at " .. minetest.pos_to_string(pos)) - end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", player:get_player_name() .. - " takes stuff from chest at " .. minetest.pos_to_string(pos)) - end, -}) ---end of chest code - -minetest.register_node("scifi_nodes:blumetlight", { - description = "blue metal light", - sunlight_propagates = false, - tiles = { - "scifi_nodes_bluemetal.png", - "scifi_nodes_bluemetal.png", - "scifi_nodes_blue_metal_light.png", - "scifi_nodes_blue_metal_light.png", - "scifi_nodes_blue_metal_light.png", - "scifi_nodes_blue_metal_light.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - - -minetest.register_node("scifi_nodes:lightstp", { - description = "twin lights", - sunlight_propagates = false, - tiles = { - "scifi_nodes_lightstripe.png" - }, - light_source = default.LIGHT_MAX, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:blklt2", { - description = "black stripe light", - sunlight_propagates = false, - tiles = { - "scifi_nodes_black_light2.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:blumetstr", { - description = "blue stripe light", - sunlight_propagates = false, - tiles = { - "scifi_nodes_blue_metal_stripes2.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:glass", { - description = "dark glass", - drawtype = "glasslike", - sunlight_propagates = true, - tiles = { - "scifi_nodes_glass.png" - }, - use_texture_alpha = true, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - -minetest.register_node("scifi_nodes:whtlightbnd", { - description = "white light stripe", - sunlight_propagates = false, - tiles = { - "scifi_nodes_lightband.png" - }, - light_source = 10, - paramtype = "light", - groups = {cracky=1}, - sounds = default.node_sound_glass_defaults() -}) - ---extra stuff -local xpane = minetest.get_modnames() -if xpane == xpane then -dofile(minetest.get_modpath("scifi_nodes").."/panes.lua") -end -dofile(minetest.get_modpath("scifi_nodes").."/doors.lua") -dofile(minetest.get_modpath("scifi_nodes").."/nodeboxes.lua") -dofile(minetest.get_modpath("scifi_nodes").."/models.lua") -dofile(minetest.get_modpath("scifi_nodes").."/crafts.lua") +dofile(MP.."/builder.lua") +dofile(MP.."/chest.lua") +dofile(MP.."/plants.lua") +dofile(MP.."/nodes.lua") +dofile(MP.."/doors.lua") +dofile(MP.."/nodeboxes.lua") +dofile(MP.."/models.lua") +dofile(MP.."/crafts.lua") diff --git a/nodes.lua b/nodes.lua new file mode 100644 index 0000000..8f8a407 --- /dev/null +++ b/nodes.lua @@ -0,0 +1,605 @@ + +--nodes + +minetest.register_node("scifi_nodes:grassblk", { + description = "Dirt With Alien Grass", + tiles = {"default_grass.png^[colorize:cyan:80", "default_dirt.png", + {name = "default_dirt.png^(default_grass_side.png^[colorize:cyan:80)", + tileable_vertical = false}}, + light_source = 2, + groups = {crumbly=1, oddly_breakable_by_hand=1, soil=1} +}) + +minetest.register_node("scifi_nodes:light", { + description = "blue lightbox", + sunlight_propagates = false, + tiles = { + "scifi_nodes_lighttop.png", + "scifi_nodes_lighttop.png", + "scifi_nodes_light.png", + "scifi_nodes_light.png", + "scifi_nodes_light.png", + "scifi_nodes_light.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1} +}) + +minetest.register_node("scifi_nodes:rfloor", { + description = "rusty floor", + tiles = { + "scifi_nodes_rustfloor.png", + }, + paramtype = "light", + paramtype2 = "facedir", + light_source = 10, + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults() +}) + +minetest.register_node("scifi_nodes:bfloor", { + description = "blue floor", + tiles = { + "scifi_nodes_bluefloor.png", + }, + paramtype = "light", + paramtype2 = "facedir", + light_source = 10, + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults() +}) + + +minetest.register_node("scifi_nodes:stripes2", { + description = "hazard stripes2", + sunlight_propagates = false, + tiles = { + "scifi_nodes_stripes2top.png", + "scifi_nodes_stripes2top.png", + "scifi_nodes_stripes2.png", + "scifi_nodes_stripes2.png", + "scifi_nodes_stripes2.png", + "scifi_nodes_stripes2.png" + }, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults() +}) + +minetest.register_node("scifi_nodes:gblock", { + description = "Green metal block", + sunlight_propagates = false, + tiles = { + "scifi_nodes_gblock.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock.png" + }, + paramtype = "light", + groups = {cracky=1}; + sounds = default.node_sound_metal_defaults() +}) + +minetest.register_node("scifi_nodes:gblock2", { + description = "Green metal block 2", + sunlight_propagates = false, + tiles = { + "scifi_nodes_gblock2_top.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock2.png", + "scifi_nodes_gblock2_fx.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock2_front1.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults() +}) + +minetest.register_node("scifi_nodes:gblock3", { + description = "Green metal block 3", + sunlight_propagates = false, + tiles = { + "scifi_nodes_gblock2_top.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock2.png", + "scifi_nodes_gblock2_fx.png", + "scifi_nodes_gblock.png", + "scifi_nodes_gblock2_screen.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults() +}) + + + +minetest.register_node("scifi_nodes:green_light", { + description = "green lightbox", + sunlight_propagates = false, + tiles = { + "scifi_nodes_lighttop.png", + "scifi_nodes_lighttop.png", + "scifi_nodes_greenlight.png", + "scifi_nodes_greenlight.png", + "scifi_nodes_greenlight.png", + "scifi_nodes_greenlight.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:red_light", { + description = "red lightbox", + sunlight_propagates = false, + tiles = { + "scifi_nodes_lighttop.png", + "scifi_nodes_lighttop.png", + "scifi_nodes_redlight.png", + "scifi_nodes_redlight.png", + "scifi_nodes_redlight.png", + "scifi_nodes_redlight.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:discs", { + description = "disc shelves", + sunlight_propagates = false, + tiles = { + "scifi_nodes_box_top.png", + "scifi_nodes_box_top.png", + "scifi_nodes_discs.png", + "scifi_nodes_discs.png", + "scifi_nodes_discs.png", + "scifi_nodes_discs.png" + }, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:disc", { + description = "disc", + drawtype = "torchlike", + sunlight_propagates = false, + tiles = { + "scifi_nodes_disc.png" + }, + inventory_image = "scifi_nodes_disc.png", + wield_image = "scifi_nodes_disc.png", + paramtype = "light", + groups = {cracky=1} +}) + + +minetest.register_node("scifi_nodes:blink", { + description = "blinking light", + sunlight_propagates = false, + tiles = {{ + name="scifi_nodes_lightbox.png", + animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.00}, + }}, + paramtype = "light", + groups = {cracky=1}, + light_source = 5, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:black_lights", { + description = "black wallpanel", + sunlight_propagates = false, + tiles = {{ + name="scifi_nodes_black_lights.png", + animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, + }}, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:black_screen", { + description = "black wall screen", + sunlight_propagates = false, + tiles = {{ + name="scifi_nodes_black_screen.png", + animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.00}, + }}, + paramtype = "light", + groups = {cracky=1}, + light_source = 1, + sounds = default.node_sound_stone_defaults() +}) + +minetest.register_node("scifi_nodes:screen", { + description = "electronic screen", + sunlight_propagates = false, + tiles = {{ + name="scifi_nodes_screen.png", + animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, + }}, + paramtype = "light", + groups = {cracky=1}, + light_source = 5, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:screen2", { + description = "electronic screen 2", + sunlight_propagates = false, + tiles = {{ + name="scifi_nodes_screen2.png", + animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.50}, + }}, + paramtype = "light", + groups = {cracky=1}, + light_source = 5, + sounds = default.node_sound_glass_defaults() +}) + + + +minetest.register_node("scifi_nodes:white_pad", { + description = "white keypad", + sunlight_propagates = false, + tiles = { + "scifi_nodes_white2.png", + "scifi_nodes_white2.png", + "scifi_nodes_white2.png", + "scifi_nodes_white2.png", + "scifi_nodes_white2.png", + "scifi_nodes_white_pad.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:white_base", { + description = "white wall base", + sunlight_propagates = false, + tiles = { + "scifi_nodes_white2.png", + "scifi_nodes_white2.png", + "scifi_nodes_white_side.png", + "scifi_nodes_white_side.png", + "scifi_nodes_white_side.png", + "scifi_nodes_white_side.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:grnpipe", { + description = "green pipe", + sunlight_propagates = false, + tiles = { + "scifi_nodes_greenpipe_front.png", + "scifi_nodes_greenpipe_front.png", + "scifi_nodes_greenpipe_top.png", + "scifi_nodes_greenpipe_top.png", + "scifi_nodes_greenpipe_top.png", + "scifi_nodes_greenpipe_top.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults(), + on_place = minetest.rotate_node +}) + + +minetest.register_node("scifi_nodes:grnpipe2", { + description = "broken green pipe", + sunlight_propagates = false, + tiles = { + "scifi_nodes_greenpipe_front.png", + "scifi_nodes_greenpipe_front.png", + "scifi_nodes_greenpipe2_top.png", + "scifi_nodes_greenpipe2_top.png", + "scifi_nodes_greenpipe2_top.png", + "scifi_nodes_greenpipe2_top.png" + }, + paramtype = "light", + paramtype2 = "facedir", + groups = {cracky=1}, + sounds = default.node_sound_metal_defaults(), + on_place = minetest.rotate_node +}) + +minetest.register_node("scifi_nodes:octrng", { + description = "Orange Octagon Glass", + sunlight_propagates = false, + drawtype = "glasslike", + tiles = { + "scifi_nodes_octrng.png", + }, + paramtype = "light", + paramtype2 = "facedir", + use_texture_alpha = true, + light_source = 10, + groups = {cracky=2}, + sounds = default.node_sound_glass_defaults(), + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:octgrn", { + description = "Green Octagon Glass", + sunlight_propagates = false, + drawtype = "glasslike", + tiles = { + "scifi_nodes_octgrn.png", + }, + paramtype = "light", + paramtype2 = "facedir", + use_texture_alpha = true, + light_source = 10, + groups = {cracky=2}, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:octbl", { + description = "Blue Octagon Glass", + sunlight_propagates = false, + drawtype = "glasslike", + tiles = { + "scifi_nodes_octbl.png", + }, + paramtype = "light", + paramtype2 = "facedir", + use_texture_alpha = true, + light_source = 10, + groups = {cracky=2}, + sounds = default.node_sound_glass_defaults(), + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:octppl", { + description = "Purple Octagon Glass", + sunlight_propagates = false, + drawtype = "glasslike", + tiles = { + "scifi_nodes_octppl.png", + }, + paramtype = "light", + paramtype2 = "facedir", + use_texture_alpha = true, + light_source = 10, + groups = {cracky=2}, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:tower", { + description = "Wind tower", + sunlight_propagates = false, + drawtype = "plantlike", + tiles = {{ + name = "scifi_nodes_tower_anim.png", + animation = {type = "vertical_frames", aspect_w = 32, aspect_h = 32, length = 1.00}, + }}, + visual_scale = 2, + inventory_image = "scifi_nodes_tower.png", + paramtype = "light", + groups = {cracky=2}, + sounds = default.node_sound_metal_defaults() +}) + +minetest.register_node("scifi_nodes:junk", { + description = "Junk", + sunlight_propagates = true, + paramtype = "light", + liquid_viscosity = 8, + liquidtype = "source", + liquid_alternative_flowing = "scifi_nodes:junk", + liquid_alternative_source = "scifi_nodes:junk", + liquid_renewable = false, + liquid_range = 0, + walkable = false, + tiles = { + "scifi_nodes_junk.png" + }, + groups = {snappy=1, oddly_breakable_by_hand=1, liquid=3, dig_immediate=1} +}) + + +minetest.register_node("scifi_nodes:blumetlight", { + description = "blue metal light", + sunlight_propagates = false, + tiles = { + "scifi_nodes_bluemetal.png", + "scifi_nodes_bluemetal.png", + "scifi_nodes_blue_metal_light.png", + "scifi_nodes_blue_metal_light.png", + "scifi_nodes_blue_metal_light.png", + "scifi_nodes_blue_metal_light.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + + +minetest.register_node("scifi_nodes:lightstp", { + description = "twin lights", + sunlight_propagates = false, + tiles = { + "scifi_nodes_lightstripe.png" + }, + light_source = default.LIGHT_MAX, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:blklt2", { + description = "black stripe light", + sunlight_propagates = false, + tiles = { + "scifi_nodes_black_light2.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:blumetstr", { + description = "blue stripe light", + sunlight_propagates = false, + tiles = { + "scifi_nodes_blue_metal_stripes2.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:glass", { + description = "dark glass", + drawtype = "glasslike", + sunlight_propagates = true, + tiles = { + "scifi_nodes_glass.png" + }, + use_texture_alpha = true, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +minetest.register_node("scifi_nodes:whtlightbnd", { + description = "white light stripe", + sunlight_propagates = false, + tiles = { + "scifi_nodes_lightband.png" + }, + light_source = 10, + paramtype = "light", + groups = {cracky=1}, + sounds = default.node_sound_glass_defaults() +}) + +--edited wool code (Copyright (C) 2012 celeron55, Perttu Ahola ) + + +-- This uses a trick: you can first define the recipes using all of the base +-- colors, and then some recipes using more specific colors for a few non-base +-- colors available. When crafting, the last recipes will be checked first. +--add new block using texture name(without "scifi_nodes_" prefix) then the description, and then the name of the block +local nodetypes = { + {"blue", "blue lines", "blue"}, + {"holes", "metal with holes","holes"}, + {"white2", "plastic", "white2"}, + {"super_white", "Super Plastic", "super_white", 11}, + {"ultra_white", "Ultra Plastic", "ultra_white", default.LIGHT_MAX}, + {"engine", "engine", "engine"}, + {"wall", "metal wall", "wall"}, + {"white", "plastic wall", "white"}, + {"stripes2top", "dirty metal block","metal2"}, + {"rough", "rough metal", "rough"}, + {"lighttop", "metal block", "metal"}, + {"red", "red lines", "red"}, + {"green", "green lines", "green"}, + {"vent2", "vent", "vent"}, + {"stripes", "hazard stripes", "stripes"}, + {"rust", "rusty metal", "rust"}, + {"mesh", "metal mesh", "mesh"}, + {"black", "black wall", "black"}, + {"blackoct", "black octagon", "blackoct"}, + {"blackpipe", "black pipe", "blackpipe"}, + {"blacktile", "black tile", "blktl"}, + {"blacktile2", "black tile 2", "blktl2"}, + {"blackvent", "black vent", "blkvnt"}, + {"bluebars", "blue bars", "bluebars"}, + {"bluemetal", "blue metal", "blumtl"}, + {"bluetile", "blue tile", "blutl"}, + {"greytile", "grey tile", "grytl"}, + {"mesh2", "metal floormesh", "mesh2"}, + {"white", "plastic wall", "white"}, + {"pipe", "wall pipe", "pipe2"}, + {"pipeside", "side pipe", "pipe3"}, + {"tile", "white tile", "tile"}, + {"whiteoct", "white octagon", "whiteoct"}, + {"whitetile", "white tile2", "whttl"}, + {"black_detail", "black detail", "blckdtl"}, + {"green_square", "green metal block", "grnblck"}, + {"red_square", "red metal block", "redblck"}, + {"grey_square", "grey metal block", "greyblck"}, + {"blue_square", "blue metal block", "blublck"}, + {"black_mesh", "black vent block", "blckmsh"}, + {"dent", "dented metal block", "dent"}, + {"greenmetal", "green metal wall", "grnmetl"}, + {"greenmetal2", "green metal wall2", "grnmetl2"}, + {"greenlights", "green wall lights", "grnlt", 10}, + {"greenlights2", "green wall lights2", "grnlt2", 10}, + {"greenbar", "green light bar", "grnlghtbr", 10}, + {"green2", "green wall panel", "grn2"}, + {"greentubes", "green pipes", "grntubes"}, + {"grey", "grey wall", "gry"}, + {"greybolts", "grey wall bolts", "gryblts"}, + {"greybars", "grey bars", "grybrs"}, + {"greydots", "grey wall dots", "grydts"}, + {"greygreenbar", "gray power pipe", "grygrnbr", 10}, + {"octofloor", "Doom floor", "octofloor"}, + {"octofloor2", "Brown Doom floor", "octofloor2"}, + {"doomwall1", "Doom wall 1", "doomwall1"}, + {"doomwall2", "Doom wall 2", "doomwall2"}, + {"doomwall3", "Doom wall 3", "doomwall3"}, + {"doomwall4", "Doom wall 4", "doomwall4"}, + {"doomwall41", "Doom wall 4.1", "doomwall4.1"}, + {"doomwall42", "Doom wall 4.2", "doomwall4.2"}, + {"doomwall43", "Doom wall 4.3", "doomwall4.3"}, + {"doomwall431", "Doom wall 4.3.1", "doomwall4.3.1"}, + {"doomwall44", "Doom wall 4.4", "doomwall4.4"}, + {"blackdmg", "Damaged black wall", "blckdmg"}, + {"blackdmgstripe", "Damaged black wall(stripes)", "blckdmgstripe"}, + {"doomengine", "Doom engine wall", "doomengine"}, + {"monitorwall", "Wall monitors", "monitorwall"}, + {"screen3", "Wall monitor", "screen3"}, + {"doomlight", "Doom light", "doomlight", 12}, + {"bluwllight", "Blue wall light", "capsule3", default.LIGHT_MAX}, + {"bluegrid", "Blue Grid", "bluegrid", 5}, + {"fan", "Fan", "fan"}, + {"ppllght", "Purple wall light", "", default.LIGHT_MAX}, + {"pplwll", "Purple wall", "", 0}, + {"pplwll2", "Purple wall2", "", 0}, + {"pplwll3", "Purple wall3", "", 0}, + {"pplwll4", "Purple wall4", "", 0}, + {"pplblk", "Purple tile", "", 0}, + {"purple", "Purple node", "", 0}, + {"rock", "Moonstone", "", 0}, + {"rock2", "Moonstone2", "", 0}, + {"blackvnt", "Black vent", "", 0}, + {"blackplate", "Black plate", "", 0}, +} + +for _, row in ipairs(nodetypes) do + local name = row[1] + local desc = row[2] + local light = row[4] + -- Node Definition + minetest.register_node("scifi_nodes:"..name, { + description = desc, + tiles = {"scifi_nodes_"..name..".png"}, + groups = {cracky=1}, + paramtype = "light", + paramtype2 = "facedir", + light_source = light, + sounds = default.node_sound_glass_defaults() + }) +end \ No newline at end of file diff --git a/plants.lua b/plants.lua new file mode 100644 index 0000000..f039de5 --- /dev/null +++ b/plants.lua @@ -0,0 +1,48 @@ + +local plants = { + {"flower1", "Glow Flower", 1,0, default.LIGHT_MAX}, + {"flower2", "Pink Flower", 1.5,0, 10}, + {"flower3", "Triffid", 2,5, 0}, + {"flower4", "Weeping flower", 1.5,0, 0}, + {"plant1", "Bulb Plant", 1,0, 0}, + {"plant2", "Trap Plant", 1.5,0, default.LIGHT_MAX}, + {"plant3", "Blue Jelly Plant", 1.2,0, 10}, + {"plant4", "Green Jelly Plant", 1.2,0, 10}, + {"plant5", "Fern Plant", 1.7,0, 0}, + {"plant6", "Curly Plant", 1,0, 10}, + {"plant7", "Egg weed", 1,0, 0}, + {"plant8", "Slug weed", 1,0, 10}, + {"plant9", "Prickly Plant", 1,0, 0}, + {"plant10", "Umbrella weed", 1,0, 10}, + {"eyetree", "Eye Tree", 2.5,0, 0}, + {"grass", "Alien Grass", 1,0, 0}, +} + +for _, row in ipairs(plants) do + local name = row[1] + local desc = row[2] + local size = row[3] + local dmg = row[4] + local light = row[5] + -- Node Definition + minetest.register_node("scifi_nodes:"..name, { + description = desc, + tiles = {"scifi_nodes_"..name..".png"}, + drawtype = "plantlike", + inventory_image = {"scifi_nodes_"..name..".png"}, + groups = {snappy=1, oddly_breakable_by_hand=1, dig_immediate=3, flora=1}, + paramtype = "light", + visual_scale = size, + buildable_to = true, + walkable = false, + damage_per_second = dmg, + selection_box = { + type = "fixed", + fixed = { + {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}, + } + }, + is_ground_content = false, + light_source = light, + }) +end From 707c21250e495f2e73f26d801f724e2810287d58 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 5 Sep 2019 09:00:39 +0200 Subject: [PATCH 3/8] luacheck fixes --- .luacheckrc | 2 +- builder.lua | 28 ++++++++++++++++++------- chest.lua | 15 ------------- crafts.lua | 20 ++++++++++++------ doors.lua | 12 +++++------ init.lua | 2 +- models.lua | 2 +- nodeboxes.lua | 58 +++++++++++++++++++++++++-------------------------- nodes.lua | 2 -- 9 files changed, 72 insertions(+), 69 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 5fcaf02..36cac9b 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,6 +16,6 @@ read_globals = { "dump", -- optional deps - "default", "stairsplus", "xpanes" + "default", "stairsplus", "xpanes", "screwdriver" } diff --git a/builder.lua b/builder.lua index 6831d4a..615c84c 100644 --- a/builder.lua +++ b/builder.lua @@ -2,7 +2,7 @@ --the builder node -local builder_formspec = +local builder_formspec = "size[8,9]" .. default.gui_bg .. default.gui_bg_img .. @@ -17,7 +17,21 @@ local builder_formspec = default.get_hotbar_bg(0,4.85) local input_items = { - {"default:steel_ingot 1", "scifi_nodes:black", "scifi_nodes:blue", "scifi_nodes:rough", "scifi_nodes:rust", "scifi_nodes:white", "scifi_nodes:grey", "scifi_nodes:pplwll", "scifi_nodes:greenmetal", "scifi_nodes:wall", "scifi_nodes:blue_square", "scifi_nodes:mesh", "scifi_nodes:greytile"} + { + "default:steel_ingot 1", + "scifi_nodes:black", + "scifi_nodes:blue", + "scifi_nodes:rough", + "scifi_nodes:rust", + "scifi_nodes:white", + "scifi_nodes:grey", + "scifi_nodes:pplwll", + "scifi_nodes:greenmetal", + "scifi_nodes:wall", + "scifi_nodes:blue_square", + "scifi_nodes:mesh", + "scifi_nodes:greytile" + } } minetest.register_node("scifi_nodes:builder", { @@ -33,7 +47,7 @@ minetest.register_node("scifi_nodes:builder", { on_construct = function(pos) --local meta = minetest.get_meta(pos) --meta:set_string("infotext", "Node Builder (currently does nothing)") - + local meta = minetest.get_meta(pos) meta:set_string("formspec", builder_formspec) meta:set_string("infotext", "Node Builder") @@ -66,16 +80,16 @@ minetest.register_node("scifi_nodes:builder", { inv:set_stack("output", 11, row[12]) inv:set_stack("output", 12, row[13]) end - end + end end end, on_metadata_inventory_take = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - local stack = inv:get_stack("input", 1) - local stack_name = stack:get_name() + local istack = inv:get_stack("input", 1) + local stack_name = istack:get_name() inv:remove_item("input", stack_name.." 1") - + inv:set_stack("output", 1, "") inv:set_stack("output", 2, "") inv:set_stack("output", 3, "") diff --git a/chest.lua b/chest.lua index a1289e2..411c171 100644 --- a/chest.lua +++ b/chest.lua @@ -13,21 +13,6 @@ local chest_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,4.85) -local function get_locked_chest_formspec(pos) - local spos = pos.x .. "," .. pos.y .. "," .. pos.z - local formspec = - "size[8,9]" .. - default.gui_bg .. - default.gui_bg_img .. - default.gui_slots .. - "list[nodemeta:" .. spos .. ";main;0,0.3;8,4;]" .. - "list[current_player;main;0,4.85;8,1;]" .. - "list[current_player;main;0,6.08;8,3;8]" .. - "listring[nodemeta:" .. spos .. ";main]" .. - "listring[current_player;main]" .. - default.get_hotbar_bg(0,4.85) - return formspec -end -- Helper functions diff --git a/crafts.lua b/crafts.lua index 97b34b3..daaa233 100644 --- a/crafts.lua +++ b/crafts.lua @@ -97,7 +97,7 @@ minetest.register_craft({ }) -- 8 ceiling light from 2 plastic and 1 meselamp --- Old recipe used "moreblocks:trap_super_glow_glass" +-- Old recipe used "moreblocks:trap_super_glow_glass" -- but moreblocks is an optional dependance minetest.register_craft({ output = "scifi_nodes:lightbar 8", @@ -191,7 +191,7 @@ minetest.register_craft({ {"scifi_nodes:black", "scifi_nodes:black", "scifi_nodes:black"} } }) - + -- 8 metal block from 8 black wall and 1 iron ingot minetest.register_craft({ output = "scifi_nodes:lighttop 8", @@ -343,7 +343,11 @@ minetest.register_craft({ output = "scifi_nodes:keysmonitor", recipe = { {"scifi_nodes:black", "scifi_nodes:widescreen", "scifi_nodes:black"}, - {"mesecons_microcontroller:microcontroller0000", "scifi_nodes:black_detail", "mesecons_microcontroller:microcontroller0000"} + { + "mesecons_microcontroller:microcontroller0000", + "scifi_nodes:black_detail", + "mesecons_microcontroller:microcontroller0000" + } } }) @@ -513,7 +517,7 @@ minetest.register_craft({ } }) --- 6 capsule from 1 plastic, 1 glass, 1 orange dye, 1 green dye and +-- 6 capsule from 1 plastic, 1 glass, 1 orange dye, 1 green dye and -- 1 cyan dye minetest.register_craft({ output = "scifi_nodes:capsule 6", @@ -608,7 +612,11 @@ minetest.register_craft({ output = "scifi_nodes:black_lights", recipe = { {"dye:red", "dye:green", "dye:yellow"}, - {"mesecons_microcontroller:microcontroller0000", "scifi_nodes:black", "mesecons_microcontroller:microcontroller0000"} + { + "mesecons_microcontroller:microcontroller0000", + "scifi_nodes:black", + "mesecons_microcontroller:microcontroller0000" + } } }) @@ -1100,7 +1108,7 @@ minetest.register_craft({ {"scifi_nodes:white2", ""}, {"scifi_nodes:white2","scifi_nodes:white2"} } -}) +}) -- 6 white slope from 3 plastic wall minetest.register_craft({ diff --git a/doors.lua b/doors.lua index 8b033b9..61f7dac 100644 --- a/doors.lua +++ b/doors.lua @@ -10,7 +10,7 @@ -- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -- 1. You are allowed to do whatever you want to with what content is using this license. --- 2. This content is provided 'as-is', without any express or implied warranty. In no event +-- 2. This content is provided 'as-is', without any express or implied warranty. In no event -- will the authors be held liable for any damages arising from the use of this content. @@ -57,7 +57,6 @@ for _, current_door in ipairs(doors) do local base_name = current_door.base_name local base_ingredient = current_door.base_ingredient local sound = current_door.sound - local doors_rightclick minetest.register_craft({ output = closed .. " 2", @@ -143,8 +142,8 @@ for _, current_door in ipairs(doors) do local f = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z-1}) local g = minetest.get_node({x=pos.x+1, y=pos.y, z=pos.z+1}) local h = minetest.get_node({x=pos.x-1, y=pos.y, z=pos.z+1}) - - + + minetest.set_node(pos, {name=opened, param2=node.param2}) minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z}, {name=opened_top, param2=node.param2}) @@ -184,7 +183,8 @@ for _, current_door in ipairs(doors) do end function afterplace(pos, placer, itemstack, pointed_thing) - minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=nodeu.param2}) + local node = minetest.get_node(pos) + minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name=opened_top,param2=node.param2}) end function ontimer(pos, elapsed) @@ -383,7 +383,7 @@ for _, current_door in ipairs(doors) do selection_box = { type = "fixed", fixed = { - {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, } }, }) diff --git a/init.lua b/init.lua index 7664821..86cc7fd 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ ---scifi_nodes by D00Med +--scifi_nodes by D00Med local MP = minetest.get_modpath("scifi_nodes") if minetest.get_modpath("xpanes") then diff --git a/models.lua b/models.lua index 96b6856..25b6ce7 100644 --- a/models.lua +++ b/models.lua @@ -158,7 +158,7 @@ node.types = { } if minetest.global_exists("stairsplus") then - + for _, row in ipairs(node.types) do local name = row[1] local desc = row[2] diff --git a/nodeboxes.lua b/nodeboxes.lua index 5f426f6..621e9ba 100644 --- a/nodeboxes.lua +++ b/nodeboxes.lua @@ -154,13 +154,13 @@ minetest.register_node("scifi_nodes:pad", { on_construct = function(pos, node, placer) local meta = minetest.get_meta(pos) if position1 == nil then - position1 = pos - meta:set_int("type", 1) + position1 = pos + meta:set_int("type", 1) elseif position2 == nil then - position2 = pos - meta:set_int("type", 2) - else - minetest.chat_send_all("There can only be two teleportation pads at a time!") + position2 = pos + meta:set_int("type", 2) + else + minetest.chat_send_all("There can only be two teleportation pads at a time!") end end, on_rightclick = function(pos, node, clicker) @@ -185,11 +185,9 @@ minetest.register_node("scifi_nodes:pad", { minetest.after(1, function() local ppos = clicker:getpos() if minetest.get_node({x=ppos.x, y=ppos.y, z=ppos.z}).name == "scifi_nodes:pad" then - clicker:setpos(position2) - else - --minetest.chat_send_all("Nothing to teleport!") + clicker:setpos(position2) end - local objs = minetest.env:get_objects_inside_radius(pos, 3) + local objs = minetest.env:get_objects_inside_radius(pos, 3) for _, obj in pairs(objs) do if obj:get_luaentity() and not obj:is_player() then if obj:get_luaentity().name == "__builtin:item" then @@ -221,11 +219,9 @@ minetest.register_node("scifi_nodes:pad", { minetest.after(1, function() local ppos = clicker:getpos() if minetest.get_node({x=ppos.x, y=ppos.y, z=ppos.z}).name == "scifi_nodes:pad" then - clicker:setpos(position1) - else - --minetest.chat_send_all("No-one to teleport!") + clicker:setpos(position1) end - local objs = minetest.env:get_objects_inside_radius(pos, 3) + local objs = minetest.env:get_objects_inside_radius(pos, 3) for _, obj in pairs(objs) do if obj:get_luaentity() and not obj:is_player() then if obj:get_luaentity().name == "__builtin:item" then @@ -390,12 +386,12 @@ minetest.register_node("scifi_nodes:pot", { } }, on_rightclick = function(pos, node, clicker, item, _) - local node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}) - if node.name == "scifi_nodes:pot_lid" then - minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=node.param2}) - elseif node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then - minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=node.param2}) - end + local lid_node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}) + if lid_node.name == "scifi_nodes:pot_lid" then + minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=lid_node.param2}) + elseif lid_node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then + minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=lid_node.param2}) + end end, on_destruct = function(pos, node, _) minetest.remove_node({x=pos.x, y=pos.y+2, z=pos.z}) @@ -426,12 +422,12 @@ minetest.register_node("scifi_nodes:pot2", { } }, on_rightclick = function(pos, node, clicker, item, _) - local node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}) - if node.name == "scifi_nodes:pot_lid" then - minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=node.param2}) - elseif node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then - minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=node.param2}) - end + local lid_node = minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}) + if lid_node.name == "scifi_nodes:pot_lid" then + minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="air", param2=lid_node.param2}) + elseif lid_node.name ~= "scifi_nodes:pot_lid" and node.name == "air" then + minetest.set_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="scifi_nodes:pot_lid", param2=lid_node.param2}) + end end, on_destruct = function(pos, node, _) minetest.remove_node({x=pos.x, y=pos.y+2, z=pos.z}) @@ -1092,9 +1088,8 @@ minetest.register_node("scifi_nodes:itemholder", { end, on_destruct = function(pos) local meta = minetest.get_meta(pos) - local node = minetest.get_node(pos) if meta:get_string("item") ~= "" then - drop_item(pos, node) + minetest.add_item(pos, meta:get_string("item")) end end, }) @@ -1396,7 +1391,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end -- play sound at context position minetest.sound_play(sounds[sound_index], { - pos = context.pos, + pos = context.pos, max_hear_distance = 10 }) context[player:get_player_name()] = nil -- we don't need it anymore @@ -1463,7 +1458,10 @@ end local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) -- Some calling function don't send node param, but everybody sends a pos, so : - local node = minetest.get_node(pos) + if not node then + node = minetest.get_node(pos) + end + if node.name == "scifi_nodes:palm_scanner_off" then local meta = minetest.get_meta(pos) meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere diff --git a/nodes.lua b/nodes.lua index 8f8a407..d0e740b 100644 --- a/nodes.lua +++ b/nodes.lua @@ -333,7 +333,6 @@ minetest.register_node("scifi_nodes:octrng", { light_source = 10, groups = {cracky=2}, sounds = default.node_sound_glass_defaults(), - sounds = default.node_sound_glass_defaults(), }) minetest.register_node("scifi_nodes:octgrn", { @@ -364,7 +363,6 @@ minetest.register_node("scifi_nodes:octbl", { light_source = 10, groups = {cracky=2}, sounds = default.node_sound_glass_defaults(), - sounds = default.node_sound_glass_defaults(), }) minetest.register_node("scifi_nodes:octppl", { From 974c147b45863ee17481a72ff1b72b3b210d892d Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:23:50 +0200 Subject: [PATCH 4/8] move switches,palm-scanner and digicode to own file --- common.lua | 22 +++ digicode.lua | 152 ++++++++++++++++++++ init.lua | 7 + nodeboxes.lua | 357 ----------------------------------------------- palm_scanner.lua | 120 ++++++++++++++++ switches.lua | 62 ++++++++ 6 files changed, 363 insertions(+), 357 deletions(-) create mode 100644 common.lua create mode 100644 digicode.lua create mode 100644 palm_scanner.lua create mode 100644 switches.lua diff --git a/common.lua b/common.lua new file mode 100644 index 0000000..e8e9c6a --- /dev/null +++ b/common.lua @@ -0,0 +1,22 @@ + + +function scifi_nodes.get_switch_rules(param2) + + -- param2 = 2 + local rules = { + {x=1, y=-1, z=-1}, + {x=1, y=-1, z=1}, + {x=0, y=-1, z=-1}, + {x=0, y=-1, z=1}, + } + +-- Left and right when looking to +y ? + if param2 == 3 then + rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right (rules)) + elseif param2 == 4 then + rules = mesecon.rotate_rules_right(rules) + elseif param2 == 5 then + rules = mesecon.rotate_rules_left(rules) + end + return rules +end diff --git a/digicode.lua b/digicode.lua new file mode 100644 index 0000000..0d89183 --- /dev/null +++ b/digicode.lua @@ -0,0 +1,152 @@ + +-------------- +-- Digicode -- +-------------- + +local secret_code = "1234" +local allowed_chars = "0123456789" +local code_length = 4 +local digicode_context = {} + +-- after_place_node, use by digicode and palm_scanner +-- placer is a player object +local function set_owner(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name()) + meta:set_string("code", secret_code) +end + +local function toggle_digicode(pos) + local node = minetest.get_node(pos) + local name = node.name + if name == "scifi_nodes:digicode_off" then + minetest.swap_node(pos, {name="scifi_nodes:digicode_on", param2=node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + elseif name == "scifi_nodes:digicode_on" then + minetest.swap_node(pos, {name="scifi_nodes:digicode_off", param2=node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +local function code_is_valid(code) + local valid = false + if type(code) == "string" and #code == code_length then + valid = true + end + for i=1, #code do + if not string.find(allowed_chars, string.sub(code,i,i)) then + valid = false + end + end + return valid +end + +local function update_code(pos, code) + local meta = minetest.get_meta(pos) + meta:set_string("code", code) +end + +local function show_digicode_formspec(pos, node, player, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local current_code = meta:get_string("code") + local current_player = player:get_player_name() + + -- Gathering datas that will be used by callback function + digicode_context[current_player] = {code = current_code, pos = pos} + + if current_player == owner then + minetest.show_formspec(current_player, "digicode_formspec", + "size[6,3]".. + "field[1,1;3,1;code;Code;]".. -- type, position, size, name, label + "button_exit[1,2;2,1;change;Change code]".. + "button_exit[3,2;2,1;open;Open door]") + else + minetest.show_formspec(current_player, "digicode_formspec", + "size[6,3]".. + "field[2,1;3,1;code;Code;]".. + "button_exit[2,2;3,1;open;Open door]") + end +end + +-- Process datas from digicode_formspec +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "digicode_formspec" then + return false + end + + local sounds = {"scifi_nodes_scanner_granted","scifi_nodes_scanner_refused", + "scifi_nodes_digicode_granted","scifi_nodes_digicode_refused" + } + local sound_index + + -- We have the right formspec so we can proceed it. + -- Let's retrieve the datas we need : + local context = digicode_context[player:get_player_name()] + + if fields.change and code_is_valid(fields.code) then + update_code(context.pos, fields.code) + sound_index = 1 + elseif + fields.change and not code_is_valid(fields.code) then + sound_index = 2 + elseif + fields.open and fields.code == context.code then + toggle_digicode(context.pos) + sound_index = 3 + elseif + fields.open and fields.code ~= context.code then + sound_index = 4 + end + -- play sound at context position + minetest.sound_play(sounds[sound_index], { + pos = context.pos, + max_hear_distance = 10 + }) + context[player:get_player_name()] = nil -- we don't need it anymore +end) + +minetest.register_node("scifi_nodes:digicode_on", { + description = "Digicode", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_digicode_on.png",}, + inventory_image = "scifi_nodes_digicode_on.png", + wield_image = "scifi_nodes_digicode_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = {items = {"scifi_nodes:digicode_off"}}, + mesecons = {receptor = {state = mesecon.state.on,}}, + on_timer = toggle_digicode, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:digicode_off", { + description = "Digicode", + tiles = {"scifi_nodes_digicode_off.png",}, + inventory_image = "scifi_nodes_digicode_off.png", + wield_image = "scifi_nodes_digicode_off.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + after_place_node = set_owner, + on_rightclick = show_digicode_formspec, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_craft({ + output = "scifi_nodes:digicode_off 2", + recipe = {{"mesecons_switch:mesecon_switch_off", "scifi_nodes:grey", ""}} +}) diff --git a/init.lua b/init.lua index 86cc7fd..b1bba98 100644 --- a/init.lua +++ b/init.lua @@ -1,15 +1,22 @@ --scifi_nodes by D00Med + +scifi_nodes = {} + local MP = minetest.get_modpath("scifi_nodes") if minetest.get_modpath("xpanes") then dofile(MP.."/panes.lua") end +dofile(MP.."/common.lua") dofile(MP.."/builder.lua") dofile(MP.."/chest.lua") dofile(MP.."/plants.lua") dofile(MP.."/nodes.lua") dofile(MP.."/doors.lua") +dofile(MP.."/switches.lua") dofile(MP.."/nodeboxes.lua") +dofile(MP.."/palm_scanner.lua") +dofile(MP.."/digicode.lua") dofile(MP.."/models.lua") dofile(MP.."/crafts.lua") diff --git a/nodeboxes.lua b/nodeboxes.lua index 621e9ba..d6efcc2 100644 --- a/nodeboxes.lua +++ b/nodeboxes.lua @@ -1203,360 +1203,3 @@ minetest.register_node("scifi_nodes:windowpanel", { on_place = minetest.rotate_node, sounds = default.node_sound_glass_defaults(), }) - - --------------- --- Switches -- --------------- - -local function get_switch_rules(param2) - - -- param2 = 2 - local rules = { - {x=1, y=-1, z=-1}, - {x=1, y=-1, z=1}, - {x=0, y=-1, z=-1}, - {x=0, y=-1, z=1}, - } - --- Left and right when looking to +y ? - if param2 == 3 then - rules = mesecon.rotate_rules_right(mesecon.rotate_rules_right (rules)) - elseif param2 == 4 then - rules = mesecon.rotate_rules_right(rules) - elseif param2 == 5 then - rules = mesecon.rotate_rules_left(rules) - end - return rules -end - -local function toggle_switch(pos) - local node = minetest.get_node(pos) - local name = node.name - if name == "scifi_nodes:switch_on" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) - minetest.set_node(pos, {name = "scifi_nodes:switch_off", param2 = node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - elseif name == "scifi_nodes:switch_off" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) - minetest.set_node(pos, {name = "scifi_nodes:switch_on", param2 = node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - end -end - -minetest.register_node("scifi_nodes:switch_on", { - description = "Wall switch", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_switch_on.png",}, - inventory_image = "scifi_nodes_switch_on.png", - wield_image = "scifi_nodes_switch_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.on,}}, - sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch, - on_timer = toggle_switch -}) - -minetest.register_node("scifi_nodes:switch_off", { - description = "Wall switch", - tiles = {"scifi_nodes_switch_off.png",}, - inventory_image = "scifi_nodes_switch_on.png", - wield_image = "scifi_nodes_switch_on.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch -}) - -minetest.register_craft({ - output = "scifi_nodes:switch_off 2", - recipe = {{"mesecons_button:button_off", "scifi_nodes:grey", ""}} -}) - - --------------- --- Digicode -- --------------- - -local secret_code = "1234" -local allowed_chars = "0123456789" -local code_length = 4 -local digicode_context = {} - --- after_place_node, use by digicode and palm_scanner --- placer is a player object -local function set_owner(pos, placer, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) - meta:set_string("code", secret_code) -end - -local function toggle_digicode(pos) - local node = minetest.get_node(pos) - local name = node.name - if name == "scifi_nodes:digicode_off" then - minetest.swap_node(pos, {name="scifi_nodes:digicode_on", param2=node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - elseif name == "scifi_nodes:digicode_on" then - minetest.swap_node(pos, {name="scifi_nodes:digicode_off", param2=node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - end -end - -local function code_is_valid(code) - local valid = false - if type(code) == "string" and #code == code_length then - valid = true - end - for i=1, #code do - if not string.find(allowed_chars, string.sub(code,i,i)) then - valid = false - end - end - return valid -end - -local function update_code(pos, code) - local meta = minetest.get_meta(pos) - meta:set_string("code", code) -end - -local function show_digicode_formspec(pos, node, player, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local current_code = meta:get_string("code") - local current_player = player:get_player_name() - - -- Gathering datas that will be used by callback function - digicode_context[current_player] = {code = current_code, pos = pos} - - if current_player == owner then - minetest.show_formspec(current_player, "digicode_formspec", - "size[6,3]".. - "field[1,1;3,1;code;Code;]".. -- type, position, size, name, label - "button_exit[1,2;2,1;change;Change code]".. - "button_exit[3,2;2,1;open;Open door]") - else - minetest.show_formspec(current_player, "digicode_formspec", - "size[6,3]".. - "field[2,1;3,1;code;Code;]".. - "button_exit[2,2;3,1;open;Open door]") - end -end - --- Process datas from digicode_formspec -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "digicode_formspec" then - return false - end - - local sounds = {"scifi_nodes_scanner_granted","scifi_nodes_scanner_refused", - "scifi_nodes_digicode_granted","scifi_nodes_digicode_refused" - } - local sound_index - - -- We have the right formspec so we can proceed it. - -- Let's retrieve the datas we need : - local context = digicode_context[player:get_player_name()] - - if fields.change and code_is_valid(fields.code) then - update_code(context.pos, fields.code) - sound_index = 1 - elseif - fields.change and not code_is_valid(fields.code) then - sound_index = 2 - elseif - fields.open and fields.code == context.code then - toggle_digicode(context.pos) - sound_index = 3 - elseif - fields.open and fields.code ~= context.code then - sound_index = 4 - end - -- play sound at context position - minetest.sound_play(sounds[sound_index], { - pos = context.pos, - max_hear_distance = 10 - }) - context[player:get_player_name()] = nil -- we don't need it anymore -end) - -minetest.register_node("scifi_nodes:digicode_on", { - description = "Digicode", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_digicode_on.png",}, - inventory_image = "scifi_nodes_digicode_on.png", - wield_image = "scifi_nodes_digicode_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = {items = {"scifi_nodes:digicode_off"}}, - mesecons = {receptor = {state = mesecon.state.on,}}, - on_timer = toggle_digicode, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:digicode_off", { - description = "Digicode", - tiles = {"scifi_nodes_digicode_off.png",}, - inventory_image = "scifi_nodes_digicode_off.png", - wield_image = "scifi_nodes_digicode_off.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - after_place_node = set_owner, - on_rightclick = show_digicode_formspec, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_craft({ - output = "scifi_nodes:digicode_off 2", - recipe = {{"mesecons_switch:mesecon_switch_off", "scifi_nodes:grey", ""}} -}) - - ------------------------------------------------ --- Palm scanner -- ------------------------------------------------ --- /!\ When "overriding" a callback function -- --- re-use all the parameters in same order ! -- ------------------------------------------------ - --- after_place_node --- placer is a player object -local function set_scanner_owner(pos, placer, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) -end - -local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) - -- Some calling function don't send node param, but everybody sends a pos, so : - if not node then - node = minetest.get_node(pos) - end - - if node.name == "scifi_nodes:palm_scanner_off" then - local meta = minetest.get_meta(pos) - meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2}) - minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(player:get_player_name(), "Checking : please wait.") - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_checking" then - minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2}) - mesecon.receptor_on(pos, get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_on" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off (pos, get_switch_rules(node.param2)) - end -end - --- palm_scanner_checking.on_timer -local function check_owner(pos, elapsed) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local clicker = meta:get_string("clicker") - local node = minetest.get_node(pos) - if clicker == owner then - minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(clicker, "Access granted !") - toggle_palm_scanner (pos) - else - minetest.chat_send_player(clicker, "Access refused !") - minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off(pos, get_switch_rules(node.param2)) - end -end - -minetest.register_node("scifi_nodes:palm_scanner_off", { - description = "Palm scanner", - tiles = {"scifi_nodes_palm_scanner_off.png",}, - inventory_image = "scifi_nodes_palm_scanner_off.png", - wield_image = "scifi_nodes_palm_scanner_on.png", - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, - after_place_node = set_scanner_owner, - on_rightclick = toggle_palm_scanner, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_node("scifi_nodes:palm_scanner_checking", { - description = "Palm scanner", - tiles = {{ - name = "scifi_nodes_palm_scanner_checking.png", - animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5} - }}, - drawtype = "signlike", - sunlight_propagates = true, - buildable_to = false, - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = "scifi_nodes:palm_scanner_off", - sounds = default.node_sound_glass_defaults(), - on_timer = check_owner, -}) - -minetest.register_node("scifi_nodes:palm_scanner_on", { - description = "Palm scanner", - sunlight_propagates = true, - buildable_to = false, - tiles = {"scifi_nodes_palm_scanner_on.png",}, - inventory_image = "scifi_nodes_palm_scanner_on.png", - wield_image = "scifi_nodes_palm_scanner_on.png", - drawtype = "signlike", - node_box = {type = "wallmounted",}, - selection_box = {type = "wallmounted",}, - paramtype = "light", - paramtype2 = "wallmounted", - light_source = 5, - groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - drop = "scifi_nodes:palm_scanner_off", - mesecons = {receptor = {state = mesecon.state.on,}}, - on_timer = toggle_palm_scanner, - sounds = default.node_sound_glass_defaults(), -}) - -minetest.register_craft({ - output = "scifi_nodes:palm_scanner_off 2", - recipe = {{"mesecons_powerplant:power_plant", "scifi_nodes:grey", ""}} -}) diff --git a/palm_scanner.lua b/palm_scanner.lua new file mode 100644 index 0000000..da17cbc --- /dev/null +++ b/palm_scanner.lua @@ -0,0 +1,120 @@ + + +----------------------------------------------- +-- Palm scanner -- +----------------------------------------------- +-- /!\ When "overriding" a callback function -- +-- re-use all the parameters in same order ! -- +----------------------------------------------- + +-- after_place_node +-- placer is a player object +local function set_scanner_owner(pos, placer, itemstack, pointed_thing) + local meta = minetest.get_meta(pos) + meta:set_string("owner", placer:get_player_name()) +end + +local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) + -- Some calling function don't send node param, but everybody sends a pos, so : + if not node then + node = minetest.get_node(pos) + end + + if node.name == "scifi_nodes:palm_scanner_off" then + local meta = minetest.get_meta(pos) + meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2}) + minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.chat_send_player(player:get_player_name(), "Checking : please wait.") + minetest.get_node_timer(pos):start(2) + elseif node.name == "scifi_nodes:palm_scanner_checking" then + minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + elseif node.name == "scifi_nodes:palm_scanner_on" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) + mesecon.receptor_off (pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +-- palm_scanner_checking.on_timer +local function check_owner(pos, elapsed) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local clicker = meta:get_string("clicker") + local node = minetest.get_node(pos) + if clicker == owner then + minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.chat_send_player(clicker, "Access granted !") + toggle_palm_scanner (pos) + else + minetest.chat_send_player(clicker, "Access refused !") + minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + end +end + +minetest.register_node("scifi_nodes:palm_scanner_off", { + description = "Palm scanner", + tiles = {"scifi_nodes_palm_scanner_off.png",}, + inventory_image = "scifi_nodes_palm_scanner_off.png", + wield_image = "scifi_nodes_palm_scanner_on.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + after_place_node = set_scanner_owner, + on_rightclick = toggle_palm_scanner, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_node("scifi_nodes:palm_scanner_checking", { + description = "Palm scanner", + tiles = {{ + name = "scifi_nodes_palm_scanner_checking.png", + animation = {type = "vertical_frames",aspect_w = 16,aspect_h = 16,length = 1.5} + }}, + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = "scifi_nodes:palm_scanner_off", + sounds = default.node_sound_glass_defaults(), + on_timer = check_owner, +}) + +minetest.register_node("scifi_nodes:palm_scanner_on", { + description = "Palm scanner", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_palm_scanner_on.png",}, + inventory_image = "scifi_nodes_palm_scanner_on.png", + wield_image = "scifi_nodes_palm_scanner_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + drop = "scifi_nodes:palm_scanner_off", + mesecons = {receptor = {state = mesecon.state.on,}}, + on_timer = toggle_palm_scanner, + sounds = default.node_sound_glass_defaults(), +}) + +minetest.register_craft({ + output = "scifi_nodes:palm_scanner_off 2", + recipe = {{"mesecons_powerplant:power_plant", "scifi_nodes:grey", ""}} +}) diff --git a/switches.lua b/switches.lua new file mode 100644 index 0000000..eb79053 --- /dev/null +++ b/switches.lua @@ -0,0 +1,62 @@ + +-------------- +-- Switches -- +-------------- + +local function toggle_switch(pos) + local node = minetest.get_node(pos) + local name = node.name + if name == "scifi_nodes:switch_on" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) + minetest.set_node(pos, {name = "scifi_nodes:switch_off", param2 = node.param2}) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + elseif name == "scifi_nodes:switch_off" then + minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos}) + minetest.set_node(pos, {name = "scifi_nodes:switch_on", param2 = node.param2}) + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + minetest.get_node_timer(pos):start(2) + end +end + +minetest.register_node("scifi_nodes:switch_on", { + description = "Wall switch", + sunlight_propagates = true, + buildable_to = false, + tiles = {"scifi_nodes_switch_on.png",}, + inventory_image = "scifi_nodes_switch_on.png", + wield_image = "scifi_nodes_switch_on.png", + drawtype = "signlike", + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + light_source = 5, + groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.on,}}, + sounds = default.node_sound_glass_defaults(), + on_rightclick = toggle_switch, + on_timer = toggle_switch +}) + +minetest.register_node("scifi_nodes:switch_off", { + description = "Wall switch", + tiles = {"scifi_nodes_switch_off.png",}, + inventory_image = "scifi_nodes_switch_on.png", + wield_image = "scifi_nodes_switch_on.png", + drawtype = "signlike", + sunlight_propagates = true, + buildable_to = false, + node_box = {type = "wallmounted",}, + selection_box = {type = "wallmounted",}, + paramtype = "light", + paramtype2 = "wallmounted", + groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, + mesecons = {receptor = {state = mesecon.state.off,}}, + sounds = default.node_sound_glass_defaults(), + on_rightclick = toggle_switch +}) + +minetest.register_craft({ + output = "scifi_nodes:switch_off 2", + recipe = {{"mesecons_button:button_off", "scifi_nodes:grey", ""}} +}) From 45d275eecf3062df8e984e56ecea2caa74a645b9 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:27:58 +0200 Subject: [PATCH 5/8] proper mod title --- mod.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.conf b/mod.conf index 798a21b..aa27b70 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = scifi_nodes -description = A mod which the vegan kitchen to Minetest. +description = Minetest mod that adds scifi themed blocks, doors, materials, plants and other assets. depends = default,dye,basic_materials, mesecons optional_depends = xpanes,moreblocks,mesecons_microcontroller,mesecons_button,mesecons_torch,mesecons_receiver From d803f17ba555eeda826c137cdca51af608a07381 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:39:54 +0200 Subject: [PATCH 6/8] optional mesecons dependency --- digicode.lua | 13 +++++++++++-- mod.conf | 4 ++-- palm_scanner.lua | 20 +++++++++++++++----- switches.lua | 20 +++++++++++++++----- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/digicode.lua b/digicode.lua index 0d89183..174b9b7 100644 --- a/digicode.lua +++ b/digicode.lua @@ -2,6 +2,7 @@ -------------- -- Digicode -- -------------- +local has_mesecons = minetest.get_modpath("mesecons") local secret_code = "1234" local allowed_chars = "0123456789" @@ -122,7 +123,11 @@ minetest.register_node("scifi_nodes:digicode_on", { light_source = 5, groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, drop = {items = {"scifi_nodes:digicode_off"}}, - mesecons = {receptor = {state = mesecon.state.on,}}, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.on) + } + }, on_timer = toggle_digicode, sounds = default.node_sound_glass_defaults(), }) @@ -140,7 +145,11 @@ minetest.register_node("scifi_nodes:digicode_off", { paramtype = "light", paramtype2 = "wallmounted", groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.off) + } + }, after_place_node = set_owner, on_rightclick = show_digicode_formspec, sounds = default.node_sound_glass_defaults(), diff --git a/mod.conf b/mod.conf index aa27b70..f05a2c8 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = scifi_nodes description = Minetest mod that adds scifi themed blocks, doors, materials, plants and other assets. -depends = default,dye,basic_materials, mesecons -optional_depends = xpanes,moreblocks,mesecons_microcontroller,mesecons_button,mesecons_torch,mesecons_receiver +depends = default,dye +optional_depends = xpanes,mesecons,moreblocks,mesecons_microcontroller,mesecons_button,mesecons_torch,mesecons_receiver,basic_materials diff --git a/palm_scanner.lua b/palm_scanner.lua index da17cbc..5f07ea7 100644 --- a/palm_scanner.lua +++ b/palm_scanner.lua @@ -7,6 +7,8 @@ -- re-use all the parameters in same order ! -- ----------------------------------------------- +local has_mesecons = minetest.get_modpath("mesecons") + -- after_place_node -- placer is a player object local function set_scanner_owner(pos, placer, itemstack, pointed_thing) @@ -47,7 +49,7 @@ local function check_owner(pos, elapsed) if clicker == owner then minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) minetest.chat_send_player(clicker, "Access granted !") - toggle_palm_scanner (pos) + toggle_palm_scanner(pos) else minetest.chat_send_player(clicker, "Access refused !") minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) @@ -69,9 +71,13 @@ minetest.register_node("scifi_nodes:palm_scanner_off", { paramtype = "light", paramtype2 = "wallmounted", groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.off) + } + }, after_place_node = set_scanner_owner, - on_rightclick = toggle_palm_scanner, + on_rightclick = (has_mesecons and toggle_palm_scanner), sounds = default.node_sound_glass_defaults(), }) @@ -109,8 +115,12 @@ minetest.register_node("scifi_nodes:palm_scanner_on", { light_source = 5, groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, drop = "scifi_nodes:palm_scanner_off", - mesecons = {receptor = {state = mesecon.state.on,}}, - on_timer = toggle_palm_scanner, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.on) + } + }, + on_timer = (has_mesecons and toggle_palm_scanner), sounds = default.node_sound_glass_defaults(), }) diff --git a/switches.lua b/switches.lua index eb79053..a1bdef0 100644 --- a/switches.lua +++ b/switches.lua @@ -3,6 +3,8 @@ -- Switches -- -------------- +local has_mesecons = minetest.get_modpath("mesecons") + local function toggle_switch(pos) local node = minetest.get_node(pos) local name = node.name @@ -32,10 +34,14 @@ minetest.register_node("scifi_nodes:switch_on", { paramtype2 = "wallmounted", light_source = 5, groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.on,}}, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.on) + } + }, sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch, - on_timer = toggle_switch + on_rightclick = (has_mesecons and toggle_switch), + on_timer = (has_mesecons and toggle_switch) }) minetest.register_node("scifi_nodes:switch_off", { @@ -51,9 +57,13 @@ minetest.register_node("scifi_nodes:switch_off", { paramtype = "light", paramtype2 = "wallmounted", groups = {cracky=1, oddly_breakable_by_hand=1, mesecon_needs_receiver = 1}, - mesecons = {receptor = {state = mesecon.state.off,}}, + mesecons = { + receptor = { + state = (has_mesecons and mesecon.state.off) + } + }, sounds = default.node_sound_glass_defaults(), - on_rightclick = toggle_switch + on_rightclick = (has_mesecons and toggle_switch) }) minetest.register_craft({ From f007240c211eb8e9abc9a47886171251a7a02e00 Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:46:26 +0200 Subject: [PATCH 7/8] fix duplicate scifi_nodes declaration --- common.lua | 2 +- doors.lua | 1 - models.lua | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/common.lua b/common.lua index e8e9c6a..8bb7a3d 100644 --- a/common.lua +++ b/common.lua @@ -1,6 +1,6 @@ -function scifi_nodes.get_switch_rules(param2) +scifi_nodes.get_switch_rules = function(param2) -- param2 = 2 local rules = { diff --git a/doors.lua b/doors.lua index 61f7dac..fcda20a 100644 --- a/doors.lua +++ b/doors.lua @@ -15,7 +15,6 @@ -- Retrieving mod settings -local scifi_nodes = {} scifi_nodes.doors_open_with_mesecon_only = minetest.settings:get_bool("scifi_nodes.doors_open_with_mesecon_only", false) -- Some aliases to deal with old namming policy -- diff --git a/models.lua b/models.lua index 25b6ce7..e1ec8e0 100644 --- a/models.lua +++ b/models.lua @@ -2,8 +2,6 @@ --Copyright (c) 2011-2015 Calinou and contributors. --Licensed under the zlib license. -scifi_nodes = {} - function scifi_nodes.register_slope(name, desc, texture, light) minetest.register_node("scifi_nodes:slope_"..name, { description = desc.." Slope", @@ -174,4 +172,3 @@ if minetest.global_exists("stairsplus") then }) end end - From e8fa4ae05da7d37f959cb82db294796755c8dc5e Mon Sep 17 00:00:00 2001 From: Thomas Rudin Date: Mon, 9 Sep 2019 18:59:48 +0200 Subject: [PATCH 8/8] working palm scanner --- palm_scanner.lua | 80 +++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 49 deletions(-) diff --git a/palm_scanner.lua b/palm_scanner.lua index 5f07ea7..9fb8a53 100644 --- a/palm_scanner.lua +++ b/palm_scanner.lua @@ -9,53 +9,38 @@ local has_mesecons = minetest.get_modpath("mesecons") --- after_place_node --- placer is a player object -local function set_scanner_owner(pos, placer, itemstack, pointed_thing) - local meta = minetest.get_meta(pos) - meta:set_string("owner", placer:get_player_name()) -end -local function toggle_palm_scanner(pos, node, player, itemstack, pointed_thing) - -- Some calling function don't send node param, but everybody sends a pos, so : - if not node then - node = minetest.get_node(pos) - end +function activate_palm_scanner(pos, node, player) + local name = player and player:get_player_name() + name = name or "" - if node.name == "scifi_nodes:palm_scanner_off" then - local meta = minetest.get_meta(pos) - meta:set_string("clicker", player:get_player_name()) -- need to keep it somewhere - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_checking", param2 = node.param2}) - minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(player:get_player_name(), "Checking : please wait.") - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_checking" then - minetest.swap_node(pos,{name = "scifi_nodes:palm_scanner_on", param2 = node.param2}) - mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) - minetest.get_node_timer(pos):start(2) - elseif node.name == "scifi_nodes:palm_scanner_on" then - minetest.sound_play("scifi_nodes_switch", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off (pos, scifi_nodes.get_switch_rules(node.param2)) - end -end + node.name = "scifi_nodes:palm_scanner_checking" + minetest.swap_node(pos, node) --- palm_scanner_checking.on_timer -local function check_owner(pos, elapsed) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local clicker = meta:get_string("clicker") - local node = minetest.get_node(pos) - if clicker == owner then - minetest.sound_play("scifi_nodes_scanner_granted", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.chat_send_player(clicker, "Access granted !") - toggle_palm_scanner(pos) - else - minetest.chat_send_player(clicker, "Access refused !") - minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) - minetest.swap_node(pos, {name = "scifi_nodes:palm_scanner_off", param2 = node.param2}) - mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) - end + minetest.sound_play("scifi_nodes_palm_scanner", {max_hear_distance = 8, pos = pos, gain = 1.0}) + minetest.chat_send_player(name, "Checking : please wait.") + + -- check protection + minetest.after(2, function() + if minetest.is_protected(pos, name or "") then + -- clicker has no access to area + minetest.chat_send_player(name, "Access denied !") + minetest.sound_play("scifi_nodes_scanner_refused", {max_hear_distance = 8, pos = pos, gain = 1.0}) + + else + -- clicker can build here + minetest.chat_send_player(name, "Access granted !") + mesecon.receptor_on(pos, scifi_nodes.get_switch_rules(node.param2)) + + end + + -- reset state + minetest.after(1, function() + node.name = "scifi_nodes:palm_scanner_off" + minetest.swap_node(pos, node) + mesecon.receptor_off(pos, scifi_nodes.get_switch_rules(node.param2)) + end) + end) end minetest.register_node("scifi_nodes:palm_scanner_off", { @@ -76,8 +61,7 @@ minetest.register_node("scifi_nodes:palm_scanner_off", { state = (has_mesecons and mesecon.state.off) } }, - after_place_node = set_scanner_owner, - on_rightclick = (has_mesecons and toggle_palm_scanner), + on_rightclick = (has_mesecons and activate_palm_scanner), sounds = default.node_sound_glass_defaults(), }) @@ -96,8 +80,7 @@ minetest.register_node("scifi_nodes:palm_scanner_checking", { paramtype2 = "wallmounted", groups = {cracky=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1, mesecon_needs_receiver = 1}, drop = "scifi_nodes:palm_scanner_off", - sounds = default.node_sound_glass_defaults(), - on_timer = check_owner, + sounds = default.node_sound_glass_defaults() }) minetest.register_node("scifi_nodes:palm_scanner_on", { @@ -120,7 +103,6 @@ minetest.register_node("scifi_nodes:palm_scanner_on", { state = (has_mesecons and mesecon.state.on) } }, - on_timer = (has_mesecons and toggle_palm_scanner), sounds = default.node_sound_glass_defaults(), })