forked from minetest-mods/item_drop
		
	Dont drop items in creative mode when player already has it
This commit is contained in:
		
							
								
								
									
										42
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								init.lua
									
									
									
									
									
								
							| @@ -61,6 +61,10 @@ minetest.register_globalstep(function(dtime) | |||||||
| end) | end) | ||||||
|  |  | ||||||
| function minetest.handle_node_drops(pos, drops, digger) | function minetest.handle_node_drops(pos, drops, digger) | ||||||
|  | 	local inv | ||||||
|  | 	if minetest.setting_getbool("creative_mode") and digger and digger:is_player() then | ||||||
|  | 		inv = digger:get_inventory() | ||||||
|  | 	end | ||||||
| 	for _,item in ipairs(drops) do | 	for _,item in ipairs(drops) do | ||||||
| 		local count, name | 		local count, name | ||||||
| 		if type(item) == "string" then | 		if type(item) == "string" then | ||||||
| @@ -70,25 +74,27 @@ function minetest.handle_node_drops(pos, drops, digger) | |||||||
| 			count = item:get_count() | 			count = item:get_count() | ||||||
| 			name = item:get_name() | 			name = item:get_name() | ||||||
| 		end | 		end | ||||||
| 		for i=1,count do | 		if not inv or not inv:contains_item("main", ItemStack(name)) then | ||||||
| 			local obj = minetest.env:add_item(pos, name) | 			for i=1,count do | ||||||
| 			if obj ~= nil then | 				local obj = minetest.env:add_item(pos, name) | ||||||
| 				obj:get_luaentity().collect = true | 				if obj ~= nil then | ||||||
| 				local x = math.random(1, 5) | 					obj:get_luaentity().collect = true | ||||||
| 				if math.random(1,2) == 1 then | 					local x = math.random(1, 5) | ||||||
| 					x = -x | 					if math.random(1,2) == 1 then | ||||||
| 				end | 						x = -x | ||||||
| 				local z = math.random(1, 5) | 					end | ||||||
| 				if math.random(1,2) == 1 then | 					local z = math.random(1, 5) | ||||||
| 					z = -z | 					if math.random(1,2) == 1 then | ||||||
| 				end | 						z = -z | ||||||
| 				obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) | 					end | ||||||
|  | 					obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) | ||||||
| 					 | 					 | ||||||
| 				-- FIXME this doesnt work for deactiveted objects | 					-- FIXME this doesnt work for deactiveted objects | ||||||
| 				if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then | 					if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then | ||||||
| 					minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) | 						minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj) | ||||||
| 						obj:remove() | 							obj:remove() | ||||||
| 					end, obj) | 						end, obj) | ||||||
|  | 					end | ||||||
| 				end | 				end | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user