From 4e182429eedb2d0b34ccf938eae234435bdb8621 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Thu, 11 Jan 2018 17:49:46 +0100 Subject: [PATCH] configurable lava in give_initial_stuff --- give_initial_stuff/init.lua | 71 +++++++++++++++++++++++++++---------- water/init.lua | 6 ++-- water/settingtypes.txt | 2 ++ 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 water/settingtypes.txt diff --git a/give_initial_stuff/init.lua b/give_initial_stuff/init.lua index ba0567a..8271699 100644 --- a/give_initial_stuff/init.lua +++ b/give_initial_stuff/init.lua @@ -10,39 +10,68 @@ local chest_formspec = "listring[current_player;main]" .. default.get_hotbar_bg(0,4.85) -local function fill_chest(blockpos) +local initial_stuff = { + ["all"] = { + 'default:cobble 12', + 'default:dirt 2', + 'default:sapling 2', + }, + ["air"] = { + 'bucket:bucket_water 6', + }, + ["default:water_source"] = { + 'nodetest:papyrus_roots 6', + }, + ["default:lava_source"] = { + 'bucket:bucket_water 6', + }, + } + +local function fill_chest(blockpos, water_node) local meta = minetest.get_meta(blockpos) meta:set_string("formspec", chest_formspec) local inv = meta:get_inventory() inv:set_size("main", 8*4) -- Fill with stuff - inv:set_stack("main", 1, 'default:cobble 12') - if minetest.get_modpath("water") then - inv:set_stack("main", 2, 'nodetest:papyrus_roots 6') - else - inv:set_stack("main", 2, 'bucket:bucket_water 6') + for _, stack in ipairs(initial_stuff["all"]) do + inv:add_item("main", stack) + end + if initial_stuff[water_node] then + for _, stack in ipairs(initial_stuff[water_node]) do + inv:add_item("main", stack) + end end - inv:set_stack("main", 3, 'default:dirt 2') - inv:set_stack("main", 4, 'default:sapling 2') end if minetest.global_exists("startanode") then minetest.log("Undernull startup player chests handeled by startanode mod") - if minetest.get_modpath("water") then - -- start-a-node will be the chest. Trough papyrus_roots the player can start at each place on water surface - local water_level = minetest.setting_get("water_level") or 0 - startanode.min_pos.y = water_level -1 - startanode.max_pos.y = water_level -1 - startanode.node_name = "default:chest" - startanode.after_place_func = function(player, pos) - fill_chest(pos) + if minetest.global_exists("water") then + local water_node = water.node or "air" + if water_node == "air" then + startanode.after_place_func = function(player, pos) + local chestpos = {x=pos.x, y=pos.y+1,z=pos.z} + minetest.set_node(chestpos, {name="default:chest"}) + fill_chest(chestpos, water_node) + end + else + startanode.node_name = "default:chest" + if water_node == "default:water_source" then + startanode.min_pos.y = 0 + startanode.max_pos.y = 0 + else + startanode.min_pos.y = 1 + startanode.max_pos.y = 1 + end + startanode.after_place_func = function(player, pos) + fill_chest(pos, water_node) + end end else -- keep the start-a-node as stone and place the chest above without water startanode.after_place_func = function(player, pos) - chestpos = {x=pos.x, y=pos.y+1,z=pos.z} + local chestpos = {x=pos.x, y=pos.y+1,z=pos.z} minetest.set_node(chestpos, {name="default:chest"}) - fill_chest(chestpos) + fill_chest(chestpos, "air") end end return @@ -58,7 +87,11 @@ minetest.register_on_generated(function(minp, maxp, seed) end -- Create chest minetest.set_node(blockpos, {name="default:chest"}) - fill_chest(blockpos) + local water_node + if minetest.global_exists("water") then + water_node = water.node or "air" + end + fill_chest(blockpos, water_node) local filepath = minetest.get_worldpath().."/origin.mt" local file = io.open(filepath, "w") file:write(minetest.pos_to_string(blockpos)) diff --git a/water/init.lua b/water/init.lua index 4d9ced5..ab2bd8e 100644 --- a/water/init.lua +++ b/water/init.lua @@ -1,6 +1,6 @@ -local water = {} +water = {} water.node = minetest.settings:get("water_node") or "default:water_source" - +print("---------------------", water.node) minetest.register_on_mapgen_init(function(mgparams) minetest.set_mapgen_params({mgname="singlenode"}) end) @@ -8,7 +8,7 @@ end) -- [[ minetest.register_on_generated(function(minp, maxp, seed) -- local t1 = os.clock() - if minp.y > 1 or not water.node then + if minp.y > 1 or not water.node or water.node == "air" then return end local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") diff --git a/water/settingtypes.txt b/water/settingtypes.txt new file mode 100644 index 0000000..e1d1555 --- /dev/null +++ b/water/settingtypes.txt @@ -0,0 +1,2 @@ + +water_node (Used water node, by default "default:water_source" ) string default:water_source