This file is indexed.

/usr/share/games/minetest/mods/maidroid/maidroid_tool/api.lua is in minetest-mod-maidroid 0.1.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
------------------------------------------------------------
-- Copyright (c) 2016 tacigar. All rights reserved.
-- https://github.com/tacigar/maidroid
------------------------------------------------------------

-- maidroid_tool.shared.generate_writer is a shared
-- function called for registering egg writer and core writer.
function maidroid_tool.register_writer(nodename, options)
	local description                           = options.description
	local formspec                              = options.formspec
	local tiles                                 = options.tiles
	local node_box                              = options.node_box
	local selection_box                         = options.selection_box
	local duration                              = options.duration
	local on_activate                           = options.on_activate
	local on_deactivate                         = options.on_deactivate
	local empty_itemname                        = options.empty_itemname
	local dye_item_map                          = options.dye_item_map
	local is_mainitem                           = options.is_mainitem
	local on_metadata_inventory_put_to_main     = options.on_metadata_inventory_put_to_main
	local on_metadata_inventory_take_from_main  = options.on_metadata_inventory_take_from_main

	-- can_dig is a common callback.
	local function can_dig(pos, player)
		local meta = minetest.get_meta(pos)
		local inventory = meta:get_inventory()
		return (
			inventory:is_empty("main") and
			inventory:is_empty("fuel") and
			inventory:is_empty("dye")
		)
	end

	-- swap_node is a helper function that swap two nodes.
	local function swap_node(pos, name)
		local node = minetest.get_node(pos)
		node.name = name
		minetest.swap_node(pos, node)
	end

	-- on_timer is a common callback.
	local function on_timer(pos, elapsed)
		local meta = minetest.get_meta(pos)
		local inventory = meta:get_inventory()
		local main_list = inventory:get_list("main")
		local fuel_list = inventory:get_list("fuel")
		local dye_list = inventory:get_list("dye")

		local time = meta:get_float("time")
		local output = meta:get_string("output")

		-- if time is positive, this node is active.
		if time >= 0 then
			if time <= duration then
				meta:set_float("time", time + 1)
				meta:set_string("formspec", formspec.active(time))
			else
				meta:set_float("time", -1)
				meta:set_string("output", "")
				meta:set_string("formspec", formspec.inactive)
				inventory:set_stack("main", 1, ItemStack(output))

				swap_node(pos, nodename)

				if on_deactivate ~= nil then -- call on_deactivate callback.
					on_deactivate(pos, output)
				end
			end
		else
			local main_name = main_list[1]:get_name()

			if main_name == empty_itemname and (not fuel_list[1]:is_empty()) and (not dye_list[1]:is_empty()) then
				local output = dye_item_map[dye_list[1]:get_name()]

				meta:set_string("time", 0)
				meta:set_string("output", output)

				local fuel_stack = fuel_list[1]
				fuel_stack:take_item()
				inventory:set_stack("fuel", 1, fuel_stack)

				local dye_stack = dye_list[1]
				dye_stack:take_item()
				inventory:set_stack("dye", 1, dye_stack)

				swap_node(pos, nodename .. "_active")

				if on_activate ~= nil then -- call on_activate callback.
					on_activate(pos)
				end
			end
		end
		return true -- on_timer should return boolean value.
	end

	-- allow_metadata_inventory_put is a common callback.
	local function allow_metadata_inventory_put(pos, listname, index, stack, player)
		local meta = minetest.get_meta(pos)
		local inventory = meta:get_inventory()
		local itemname = stack:get_name()

		if (listname == "fuel" and itemname == "default:coal_lump") then
			return stack:get_count()
		elseif listname == "dye" and dye_item_map[itemname] ~= nil then
			return stack:get_count()
		elseif listname == "main" and itemname == empty_itemname then
			return stack:get_count()
		end
		return 0
	end

	-- allow_metadata_inventory_move is a common callback for the node.
	local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
		local meta = minetest.get_meta(pos)
		local inventory = meta:get_inventory()
		local stack = inventory:get_stack(from_list, from_index)
		return allow_metadata_inventory_put(pos, listname, to_index, stack, player)
	end

	do -- register a definition of an inactive node.
		local function on_construct(pos)
			local meta = minetest.get_meta(pos)
			meta:set_string("formspec", formspec.inactive)
			meta:set_string("output", "")
			meta:set_string("time", -1)

			local inventory = meta:get_inventory()
			inventory:set_size("main", 1)
			inventory:set_size("fuel", 1)
			inventory:set_size("dye", 1)
		end

		local function on_metadata_inventory_put(pos, listname, index, stack, player)
			local timer = minetest.get_node_timer(pos)
			timer:start(0.25)

			local meta = minetest.get_meta(pos)
			if listname == "main" then
				if on_metadata_inventory_put_to_main ~= nil then
					on_metadata_inventory_put_to_main(pos) -- call on_metadata_inventory_put_to_main callback.
				end
			end
		end

		local function on_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
			local meta = minetest.get_meta(pos)
			local inventory = meta:get_inventory()
			local stack = inventory:get_stack(from_list, from_index)

			on_metadata_inventory_put(pos, listname, to_index, stack, player)
		end

		local function on_metadata_inventory_take(pos, listname, index, stack, player)
			if listname == "main" then
				if on_metadata_inventory_take_from_main ~= nil then
					on_metadata_inventory_take_from_main(pos) -- call on_metadata_inventory_take_from_main callback.
				end
			end
		end

		local function allow_metadata_inventory_take(pos, listname, index, stack, player)
			return stack:get_count() -- maybe add more.
		end

		minetest.register_node(nodename, {
			description                    = description,
			drawtype                       = "nodebox",
			paramtype                      = "light",
			paramtype2                     = "facedir",
			groups                         = {cracky = 2},
			is_ground_content              = false,
			sounds                         = default.node_sound_stone_defaults(),
			node_box                       = node_box,
			selection_box                  = selection_box,
			tiles                          = tiles.inactive,
			can_dig                        = can_dig,
			on_timer                       = on_timer,
			on_construct                   = on_construct,
			on_metadata_inventory_put      = on_metadata_inventory_put,
			on_metadata_inventory_move     = on_metadata_inventory_move,
			on_metadata_inventory_take     = on_metadata_inventory_take,
			allow_metadata_inventory_put   = allow_metadata_inventory_put,
			allow_metadata_inventory_move  = allow_metadata_inventory_move,
			allow_metadata_inventory_take  = allow_metadata_inventory_take,
		})

	end -- end register inactive node.

	do -- register a definition of an active node.
		local function allow_metadata_inventory_take(pos, listname, index, stack, player)
			if listname == "main" then
				return 0
			end
			return stack:get_count()
		end

		minetest.register_node(nodename .. "_active", {
			drawtype                       = "nodebox",
			paramtype                      = "light",
			paramtype2                     = "facedir",
			groups                         = {cracky = 2},
			is_ground_content              = false,
			sounds                         = default.node_sound_stone_defaults(),
			node_box                       = node_box,
			selection_box                  = selection_box,
			tiles                          = tiles.active,
			can_dig                        = can_dig,
			on_timer                       = on_timer,
			allow_metadata_inventory_put   = allow_metadata_inventory_put,
			allow_metadata_inventory_move  = allow_metadata_inventory_move,
			allow_metadata_inventory_take  = allow_metadata_inventory_take,
		})
	end -- end register active node.
end