commit f3b56cdd4dfe52897666342e2edd89c03f0a4704 Author: Sokomine Date: Sun Aug 5 03:47:06 2018 +0200 example code and ship blueprints added diff --git a/README.md b/README.md new file mode 100644 index 0000000..058fb8e --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +This is a mod for MineTest. + +It spawns pre-built ships and rafts at mapgen time on water. + +Depends on handle_schematics. diff --git a/depends.txt b/depends.txt new file mode 100644 index 0000000..61de9fb --- /dev/null +++ b/depends.txt @@ -0,0 +1 @@ +handle_schematics diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..14f25a1 --- /dev/null +++ b/init.lua @@ -0,0 +1,79 @@ + +ships_on_mapgen = {} + +-- if set to 100: place one ship in each mapchunk if possible; +-- if set to a lower value: percent chance of placing a ship +-- in a mapchunk +ships_on_mapgen.probability_per_mapchunk = 100; + +ships_on_mapgen.schematics = { + -- yoff: how deep is the ship burried in water? +-- {scm="boat", typ="ship", is_ship=true, yoff=-1, orients={0}}, +-- {scm="shipc_4_270", typ="ship", is_ship=true, orients={0}} + + -- big sailing ship + {scm="ship_sokomine_big_3_180", typ="ship", is_ship=true, orients={0}}, + -- some smaller rafts + -- raft for general transport purposes + {scm="raft_1_2_180", typ="ship", is_ship=true, orients={0}}, + -- raft with fences for transporting passagers or cattle + {scm="raft_2_2_180", typ="ship", is_ship=true, orients={0}}, + -- raft with hut on it + {scm="raft_3_2_180", typ="ship", is_ship=true, orients={0}}, +} + + +ships_on_mapgen.mts_path = minetest.get_modpath( minetest.get_current_modname() ).."/schems/"; + +-- determine the size of the given houses and other necessary values +for i,v in ipairs( ships_on_mapgen.schematics ) do + v.mts_path = ships_on_mapgen.mts_path; + v.is_ship = true; + v.typ = "ship"; + ships_on_mapgen.schematics[ i ] = handle_schematics.analyze_file( nil, nil, v.mts_path .. v.scm, v, false ); +end + + +minetest.register_on_generated(function(minp, maxp, seed) + -- no point in placing boats on mountains or deep below sealevel + if( minp.y < -64 or minp.y > 0) then + return; + end + + local heightmap = minetest.get_mapgen_object('heightmap'); + if( not( heightmap )) then + return; + end + + -- place a ship on water if possible; do this with the given probability + if( math.random(1,100)1) then + -- colored sails can make the ships more intresting + local colors = {"white", "white", "yellow", "grey", "black", "brown", "dark_green"}; + table.insert( replacements, {"cottages:wool", "wool:"..colors[math.random(1,#colors)]}); + else + -- not all ships have sails set + table.insert( replacements, {"cottages:wool", "air"}); + end + local success = handle_schematics.place_schematic_on_flat_land( heightmap, minp, maxp, + building.sizex, building.sizez, -100, building.yoff-1, + 3, 3, 0, 0, -- margin: front, back, right, left + ships_on_mapgen.mts_path..building.scm, --..".mts", + replacements, + building.yoff, + building.orients[1], + building + ); + end +end); diff --git a/schems/raft_1_2_180.mts b/schems/raft_1_2_180.mts new file mode 100644 index 0000000..f593bcd Binary files /dev/null and b/schems/raft_1_2_180.mts differ diff --git a/schems/raft_2_2_180.mts b/schems/raft_2_2_180.mts new file mode 100644 index 0000000..100e54b Binary files /dev/null and b/schems/raft_2_2_180.mts differ diff --git a/schems/raft_3_2_180.mts b/schems/raft_3_2_180.mts new file mode 100644 index 0000000..b1d2333 Binary files /dev/null and b/schems/raft_3_2_180.mts differ diff --git a/schems/ship_sokomine_big_3_180.mts b/schems/ship_sokomine_big_3_180.mts new file mode 100644 index 0000000..1f38cbf Binary files /dev/null and b/schems/ship_sokomine_big_3_180.mts differ