forked from luanti-org/minetest_game
		
	Add give_initial_items API
This commit is contained in:
		
							
								
								
									
										43
									
								
								game_api.txt
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								game_api.txt
									
									
									
									
									
								
							| @@ -87,7 +87,7 @@ The doors mod allows modders to register custom doors and trapdoors. | |||||||
| `doors.get(pos)` | `doors.get(pos)` | ||||||
|  |  | ||||||
|  * `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}` |  * `pos` A position as a table, e.g `{x = 1, y = 1, z = 1}` | ||||||
|  * Returns an ObjecRef to a door, or nil if the position does not contain a door |  * Returns an ObjectRef to a door, or nil if the position does not contain a door | ||||||
|  |  | ||||||
|     ### Methods |     ### Methods | ||||||
|  |  | ||||||
| @@ -135,6 +135,7 @@ The doors mod allows modders to register custom doors and trapdoors. | |||||||
|  |  | ||||||
| Fence API | Fence API | ||||||
| --------- | --------- | ||||||
|  |  | ||||||
| Allows creation of new fences with "fencelike" drawtype. | Allows creation of new fences with "fencelike" drawtype. | ||||||
|  |  | ||||||
| `default.register_fence(name, item definition)` | `default.register_fence(name, item definition)` | ||||||
| @@ -153,8 +154,9 @@ Allows creation of new fences with "fencelike" drawtype. | |||||||
| 	groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, | 	groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, | ||||||
| 	sounds = default.node_sound_wood_defaults(), | 	sounds = default.node_sound_wood_defaults(), | ||||||
|  |  | ||||||
| #Walls API | Walls API | ||||||
| --------- | --------- | ||||||
|  |  | ||||||
| The walls API allows easy addition of stone auto-connecting wall nodes. | The walls API allows easy addition of stone auto-connecting wall nodes. | ||||||
|  |  | ||||||
| walls.register(name, desc, texture, mat, sounds) | walls.register(name, desc, texture, mat, sounds) | ||||||
| @@ -204,16 +206,49 @@ The farming API allows you to easily register plants and hoes. | |||||||
| Fire API | Fire API | ||||||
| -------- | -------- | ||||||
|  |  | ||||||
|  | New node def property: | ||||||
|  |  | ||||||
| `on_burn(pos)` | `on_burn(pos)` | ||||||
|  |  | ||||||
|  * Called when fire attempts to remove a burning node. |  * Called when fire attempts to remove a burning node. | ||||||
|  * `pos` Position of the burning node. |  * `pos` Position of the burning node. | ||||||
|  |  | ||||||
|  | Give Initial Stuff API | ||||||
|  | ---------------------- | ||||||
|  |  | ||||||
| #TNT API | `give_initial_stuff.give(player)` | ||||||
|  |  | ||||||
|  | ^ Give initial stuff to "player" | ||||||
|  |  | ||||||
|  | `give_initial_stuff.add(stack)` | ||||||
|  |  | ||||||
|  | ^ Add item to the initial stuff | ||||||
|  | ^ Stack can be an ItemStack or a item name eg: "default:dirt 99" | ||||||
|  | ^ Can be called after the game has loaded | ||||||
|  |  | ||||||
|  | `give_initial_stuff.clear()` | ||||||
|  |  | ||||||
|  | ^ Removes all items from the initial stuff | ||||||
|  | ^ Can be called after the game has loaded | ||||||
|  |  | ||||||
|  | `give_initial_stuff.get_list()` | ||||||
|  |  | ||||||
|  | ^ returns list of item stacks | ||||||
|  |  | ||||||
|  | `give_initial_stuff.set_list(list)` | ||||||
|  |  | ||||||
|  | ^ List of initial items with numeric indices. | ||||||
|  |  | ||||||
|  | `give_initial_stuff.add_from_csv(str)` | ||||||
|  |  | ||||||
|  | ^ str is a comma separated list of initial stuff | ||||||
|  | ^ Adds items to the list of items to be given | ||||||
|  |  | ||||||
|  |  | ||||||
|  | TNT API | ||||||
| ---------- | ---------- | ||||||
|  |  | ||||||
| tnt.register_tnt(definition) | `tnt.register_tnt(definition)` | ||||||
|  |  | ||||||
| ^ Register a new type of tnt. | ^ Register a new type of tnt. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,8 +18,9 @@ | |||||||
| # 'permanent flame' nodes will remain with either setting | # 'permanent flame' nodes will remain with either setting | ||||||
| #disable_fire = false | #disable_fire = false | ||||||
|  |  | ||||||
| # Whether steel tools, torches and cobblestone should be given to new players | # Whether the stuff in initial_stuff should be given to new players | ||||||
| #give_initial_stuff = false | #give_initial_stuff = false | ||||||
|  | #initial_stuff = default:pick_steel,default:axe_steel,default:shovel_steel,default:torch 99,default:cobble 99 | ||||||
|  |  | ||||||
| # Whether the TNT mod should be enabled | # Whether the TNT mod should be enabled | ||||||
| #enable_tnt = <true in singleplayer, false in multiplayer> | #enable_tnt = <true in singleplayer, false in multiplayer> | ||||||
|   | |||||||
| @@ -1,12 +1,44 @@ | |||||||
| minetest.register_on_newplayer(function(player) | local stuff_string = minetest.setting_get("initial_stuff") or | ||||||
| 	--print("on_newplayer") | 		"default:pick_steel,default:axe_steel,default:shovel_steel," .. | ||||||
| 	if minetest.setting_getbool("give_initial_stuff") then | 		"default:torch 99,default:cobble 99" | ||||||
| 		minetest.log("action", "Giving initial stuff to player "..player:get_player_name()) |  | ||||||
| 		player:get_inventory():add_item('main', 'default:pick_steel') |  | ||||||
| 		player:get_inventory():add_item('main', 'default:torch 99') |  | ||||||
| 		player:get_inventory():add_item('main', 'default:axe_steel') |  | ||||||
| 		player:get_inventory():add_item('main', 'default:shovel_steel') |  | ||||||
| 		player:get_inventory():add_item('main', 'default:cobble 99') |  | ||||||
| 	end |  | ||||||
| end) |  | ||||||
|  |  | ||||||
|  | give_initial_stuff = { | ||||||
|  | 	items = {} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function give_initial_stuff.give(player) | ||||||
|  | 	minetest.log("action", | ||||||
|  | 			"Giving initial stuff to player " .. player:get_player_name()) | ||||||
|  | 	local inv = player:get_inventory() | ||||||
|  | 	for _, stack in ipairs(give_initial_stuff.items) do | ||||||
|  | 		inv:add_item("main", stack) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function give_initial_stuff.add(stack) | ||||||
|  | 	give_initial_stuff.items[#give_initial_stuff.items + 1] = ItemStack(stack) | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function give_initial_stuff.clear() | ||||||
|  | 	give_initial_stuff.items = {} | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function give_initial_stuff.add_from_csv(str) | ||||||
|  | 	local items = str:split(",") | ||||||
|  | 	for _, itemname in ipairs(items) do | ||||||
|  | 		give_initial_stuff.add(itemname) | ||||||
|  | 	end | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function give_initial_stuff.set_list(list) | ||||||
|  | 	give_initial_stuff.items = list | ||||||
|  | end | ||||||
|  |  | ||||||
|  | function give_initial_stuff.get_list() | ||||||
|  | 	return give_initial_stuff.items | ||||||
|  | end | ||||||
|  |  | ||||||
|  | give_initial_stuff.add_from_csv(stuff_string) | ||||||
|  | if minetest.setting_getbool("give_initial_stuff") then | ||||||
|  | 	minetest.register_on_newplayer(give_initial_stuff.give) | ||||||
|  | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user