provide info about inhabitants on rightclick of spawner

This commit is contained in:
Sokomine 2017-06-27 16:04:46 +02:00
parent 4bbf96d6e7
commit 6908f93787
2 changed files with 31 additions and 0 deletions

View File

@ -643,6 +643,18 @@ mg_villages.inhabitants.assign_jobs_to_houses = function( village_to_add_data_bp
end
-- get the information mg_villages has about a mob (useful for mg_villages:mob_spawner)
mg_villages.inhabitants.get_mob_data = function( village_id, plot_nr, bed_nr )
if( not( village_id ) or not( plot_nr ) or not( bed_nr )
or not( mg_villages.all_villages[ village_id ] )
or not( mg_villages.all_villages[ village_id ].to_add_data.bpos[ plot_nr ])
or not( mg_villages.all_villages[ village_id ].to_add_data.bpos[ plot_nr ].beds )) then
return;
end
return mg_villages.all_villages[ village_id ].to_add_data.bpos[ plot_nr ].beds[ bed_nr ];
end
-- mob mods are expected to override this function! mobf_trader mobs are supported directly
mg_villages.inhabitants.spawn_one_mob = function( bed, village_id, plot_nr, bed_nr, bpos )

View File

@ -114,6 +114,25 @@ minetest.register_node("mg_villages:mob_spawner", {
tiles = {"wool_cyan.png^beds_bed_fancy.png","wool_blue.png^doors_door_wood.png"},
is_ground_content = false,
groups = {not_in_creative_inventory = 1 }, -- cannot be digged by players
on_rightclick = function( pos, node, clicker, itemstack, pointed_thing)
if( not( clicker )) then
return;
end
local meta = minetest.get_meta( pos );
if( not( meta )) then
return;
end
local village_id = meta:get_string( "village_id" );
local plot_nr = meta:get_int( "plot_nr" );
local bed_nr = meta:get_int( "bed_nr" );
-- direction for the mob to look at
local yaw = meta:get_int( "yaw" );
local mob_info = mg_villages.inhabitants.get_mob_data( village_id, plot_nr, bed_nr );
-- TODO: also of intrest: position next to bed, place to stand, path between both, front door
minetest.chat_send_player( clicker:get_player_name(), "Mob data: "..minetest.serialize(mob_info));
end
})