Skip to content

Commit

Permalink
finetuning chests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeb187 committed Jul 3, 2018
1 parent 6791032 commit e59dfa2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
20 changes: 12 additions & 8 deletions buildings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"]}
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion const.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
2 changes: 1 addition & 1 deletion init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e59dfa2

Please sign in to comment.