From e59dfa2c6704cf4fed805ca6d1f2998d6a1aa8a0 Mon Sep 17 00:00:00 2001 From: Rochambeau Date: Tue, 3 Jul 2018 21:12:34 +0200 Subject: [PATCH] finetuning chests --- buildings.lua | 20 ++++++++++++-------- const.lua | 2 +- init.lua | 2 +- utils.lua | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/buildings.lua b/buildings.lua index e11ffc1..f17ae76 100644 --- a/buildings.lua +++ b/buildings.lua @@ -17,7 +17,7 @@ local building_all_info local number_of_buildings local number_built -function settlements.build_schematic(pos, building, replace_wall) +function settlements.build_schematic(pos, building, replace_wall, name) -- get building node material for better integration to surrounding local balcony_material = minetest.get_node_or_nil(pos).name -- pick random material @@ -37,9 +37,13 @@ function settlements.build_schematic(pos, building, replace_wall) local height = schematic["size"]["y"] settlements.foundation(pos, width, depth, height) -- place schematic - minetest.after(2,minetest.place_schematic,pos, schematic, "random", nil, true) - --minetest.place_schematic(pos, schematic, "random", nil, true) - minetest.after(4,settlements.fill_chest,pos) + minetest.after(2, function() + minetest.place_schematic(pos, schematic, "random", nil, true) + -- fill chest + if name == "hut" then + minetest.after(2,settlements.fill_chest,pos) + end + end) end -- -- placing buildings in circles around center @@ -60,7 +64,7 @@ function settlements.place_settlement_circle(minp, maxp) settlements.initialize_settlement() -- build well in the center building_all_info = schematic_table["well"] - settlements.build_schematic(center_surface, building_all_info["mts"],building_all_info["rplc"]) + settlements.build_schematic(center_surface, building_all_info["mts"],building_all_info["rplc"], building_all_info["name"]) -- add to settlement info table local index = 1 settlement_info[index] = {pos = center_surface, name = building_all_info["name"], hsize = building_all_info["hsize"]} @@ -80,7 +84,7 @@ function settlements.place_settlement_circle(minp, maxp) local pos_surface = settlements.find_surface(pos1) if pos_surface then if settlements.pick_next_building(pos_surface) then - settlements.build_schematic(pos_surface, building_all_info["mts"],building_all_info["rplc"]) + settlements.build_schematic(pos_surface, building_all_info["mts"],building_all_info["rplc"], building_all_info["name"]) number_built = number_built + 1 settlement_info[index] = {pos = pos_surface, name = building_all_info["name"], hsize = building_all_info["hsize"]} index = index + 1 @@ -117,8 +121,8 @@ end -- everything necessary to pick a fitting next building -- function settlements.pick_next_building(pos_surface) - -- building_all_info = schematic_table[keyset[math.random(#keyset)]] - -- pick schematic based on chance + -- building_all_info = schematic_table[keyset[math.random(#keyset)]] + -- pick schematic based on chance local random_number = math.random(1,100) if random_number > 85 and count_buildings["garden"] < schematic_table["garden"]["max_num"]*number_of_buildings then building_all_info = schematic_table["garden"] diff --git a/const.lua b/const.lua index 537456d..ac7dc37 100644 --- a/const.lua +++ b/const.lua @@ -20,7 +20,7 @@ surface_mat = { "default:dirt_with_dry_grass", "default:dirt_with_coniferous_litter", "default:sand", - "default:snow" +-- "default:snow" } above_surface_mat = {"default:air","default:dirt_with_snow"} under_surface_mat = {"default:stone","default:dirt"} diff --git a/init.lua b/init.lua index 2c02a67..ddf03b8 100644 --- a/init.lua +++ b/init.lua @@ -40,7 +40,7 @@ minetest.register_craftitem("settlements:tool", { local center_surface = pointed_thing.under if center_surface then local building_all_info = {name = "hut", mts = schem_path.."hut.mts", hsize = 10, max_num = 0.9, rplc = "y"} - settlements.build_schematic(center_surface, building_all_info["mts"],building_all_info["rplc"]) + settlements.build_schematic(center_surface, building_all_info["mts"],building_all_info["rplc"], building_all_info["name"]) -- settlements.convert_mts_to_lua() -- settlements.mts_save() diff --git a/utils.lua b/utils.lua index ecf32cc..1fa2a1d 100644 --- a/utils.lua +++ b/utils.lua @@ -30,7 +30,7 @@ function settlements.find_surface(pos) s = minetest.get_node_or_nil(p6) if s == nil or s.name == "ignore" then return nil end for i, mats in ipairs(surface_mat) do - if s and s.name == mats then + if s and s.name == mats and not string.find(minetest.get_node_or_nil({ x=p6.x, y=p6.y+1, z=p6.z}).name,"water") then return p6 end end @@ -86,7 +86,7 @@ function settlements.fill_chest(pos) -- find chests within radius local chestpos = minetest.find_node_near(pos, 6, {"default:chest"}) -- initialize chest (mts chests don't have meta) - local meta = minetest.get_meta(pos) + local meta = minetest.get_meta(chestpos) if meta:get_string("infotext") ~= "Chest" then minetest.registered_nodes["default:chest"].on_construct(chestpos) end