diff options
| author | LNJ <git@lnj.li> | 2017-04-03 12:43:16 +0200 | 
|---|---|---|
| committer | LNJ <git@lnj.li> | 2017-04-05 14:53:16 +0200 | 
| commit | 69a974cb6be690ae71d011f5764472e4e0bccc54 (patch) | |
| tree | 7e768be5298808487136c05d8cede796687ee5f2 /lua | |
| parent | d3d29fb4979f720fc1eed793b74b18d5dd0d521f (diff) | |
Adapt drop function for 2x2 drawers to drop *all* items
Diffstat (limited to 'lua')
| -rwxr-xr-x | lua/api.lua | 45 | 
1 files changed, 29 insertions, 16 deletions
diff --git a/lua/api.lua b/lua/api.lua index 99b2813..bf8c8c8 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -77,26 +77,39 @@ end  -- drop all items  function drawers.drawer_on_dig(pos, node, player) -	local meta = core.get_meta(pos) -	local count = meta:get_int("count") -	local name = meta:get_string("name") - -	-- remove node -	core.node_dig(pos, node, player) +	local drawerType = 1 +	if core.registered_nodes[node.name] then +		drawerType = core.registered_nodes[node.name].groups.drawer +	end -	-- drop the items -	local stack_max = ItemStack(name):get_stack_max() +	local meta = core.get_meta(pos) -	local j = math.floor(count / stack_max) + 1 -	local i = 1 -	while i <= j do -		if not (i == j) then -			core.add_item(pos, name .. " " .. stack_max) -		else -			core.add_item(pos, name .. " " .. count % stack_max) +	k = 1 +	while k <= drawerType do +		-- don't add a number in meta fields for 1x1 drawers +		local vid = tostring(k) +		if drawerType == 1 then vid = "" end +		local count = meta:get_int("count"..vid) +		local name = meta:get_string("name"..vid) + +		-- drop the items +		local stack_max = ItemStack(name):get_stack_max() + +		local j = math.floor(count / stack_max) + 1 +		local i = 1 +		while i <= j do +			if not (i == j) then +				core.add_item(pos, name .. " " .. stack_max) +			else +				core.add_item(pos, name .. " " .. count % stack_max) +			end +			i = i + 1  		end -		i = i + 1 +		k = k + 1  	end + +	-- remove node +	core.node_dig(pos, node, player)  end  function drawers.drawer_insert_object(pos, node, stack, direction)  | 
