aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu/tab_settings.lua
blob: adf6c58ce04a5badb31aeeadc6568ab3a90e96c9 (plain)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
--Minetest
--Copyright (C) 2013 sapier
--
--This program is free software; you can redistribute it and/or modify
--it under the terms of the GNU Lesser General Public License as published by
--the Free Software Foundation; either version 2.1 of the License, or
--(at your option) any later version.
--
--This program is distributed in the hope that it will be useful,
--but WITHOUT ANY WARRANTY; without even the implied warranty of
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--GNU Lesser General Public License for more details.
--
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

--------------------------------------------------------------------------------

local labels = {
	leaves = {
		fgettext("Opaque Leaves"),
		fgettext("Simple Leaves"),
		fgettext("Fancy Leaves")
	},
	node_highlighting = {
		fgettext("Node Outlining"),
		fgettext("Node Highlighting"),
		fgettext("None")
	},
	filters = {
		fgettext("No Filter"),
		fgettext("Bilinear Filter"),
		fgettext("Trilinear Filter")
	},
	mipmap = {
		fgettext("No Mipmap"),
		fgettext("Mipmap"),
		fgettext("Mipmap + Aniso. Filter")
	},
	antialiasing = {
		fgettext("None"),
		fgettext("2x"),
		fgettext("4x"),
		fgettext("8x")
	}
}

local dd_options = {
	leaves = {
		table.concat(labels.leaves, ","),
		{"opaque", "simple", "fancy"}
	},
	node_highlighting = {
		table.concat(labels.node_highlighting, ","),
		{"box", "halo", "none"}
	},
	filters = {
		table.concat(labels.filters, ","),
		{"", "bilinear_filter", "trilinear_filter"}
	},
	mipmap = {
		table.concat(labels.mipmap, ","),
		{"", "mip_map", "anisotropic_filter"}
	},
	antialiasing = {
		table.concat(labels.antialiasing, ","),
		{"0", "2", "4", "8"}
	}
}

local getSettingIndex = {
	Leaves = function()
		local style = core.settings:get("leaves_style")
		for idx, name in pairs(dd_options.leaves[2]) do
			if style == name then return idx end
		end
		return 1
	end,
	NodeHighlighting = function()
		local style = core.settings:get("node_highlighting")
		for idx, name in pairs(dd_options.node_highlighting[2]) do
			if style == name then return idx end
		end
		return 1
	end,
	Filter = function()
		if core.settings:get(dd_options.filters[2][3]) == "true" then
			return 3
		elseif core.settings:get(dd_options.filters[2][3]) == "false" and
				core.settings:get(dd_options.filters[2][2]) == "true" then
			return 2
		end
		return 1
	end,
	Mipmap = function()
		if core.settings:get(dd_options.mipmap[2][3]) == "true" then
			return 3
		elseif core.settings:get(dd_options.mipmap[2][3]) == "false" and
				core.settings:get(dd_options.mipmap[2][2]) == "true" then
			return 2
		end
		return 1
	end,
	Antialiasing = function()
		local antialiasing_setting = core.settings:get("fsaa")
		for i = 1, #dd_options.antialiasing[2] do
			if antialiasing_setting == dd_options.antialiasing[2][i] then
				return i
			end
		end
		return 1
	end
}

local function antialiasing_fname_to_name(fname)
	for i = 1, #labels.antialiasing do
		if fname == labels.antialiasing[i] then
			return dd_options.antialiasing[2][i]
		end
	end
	return 0
end

local function dlg_confirm_reset_formspec(data)
	return  "size[8,3]" ..
		"label[1,1;" .. fgettext("Are you sure to reset your singleplayer world?") .. "]" ..
		"button[1,2;2.6,0.5;dlg_reset_singleplayer_confirm;" .. fgettext("Yes") .. "]" ..
		"button[4,2;2.8,0.5;dlg_reset_singleplayer_cancel;" .. fgettext("No") .. "]"
end

local function dlg_confirm_reset_btnhandler(this, fields, dialogdata)

	if fields["dlg_reset_singleplayer_confirm"] ~= nil then
		local worldlist = core.get_worlds()
		local found_singleplayerworld = false

		for i = 1, #worldlist do
			if worldlist[i].name == "singleplayerworld" then
				found_singleplayerworld = true
				gamedata.worldindex = i
			end
		end

		if found_singleplayerworld then
			core.delete_world(gamedata.worldindex)
		end

		core.create_world("singleplayerworld", 1)
		worldlist = core.get_worlds()
		found_singleplayerworld = false

		for i = 1, #worldlist do
			if worldlist[i].name == "singleplayerworld" then
				found_singleplayerworld = true
				gamedata.worldindex = i
			end
		end
	end

	this.parent:show()
	this:hide()
	this:delete()
	return true
end

local function showconfirm_reset(tabview)
	local new_dlg = dialog_create("reset_spworld",
		dlg_confirm_reset_formspec,
		dlg_confirm_reset_btnhandler,
		nil)
	new_dlg:set_parent(tabview)
	tabview:hide()
	new_dlg:show()
end

local function formspec(tabview, name, tabdata)
	local tab_string =
		"box[0,0;3.75,4.5;#999999]" ..
		"checkbox[0.25,0;cb_smooth_lighting;" .. fgettext("Smooth Lighting") .. ";"
				.. dump(core.settings:get_bool("smooth_lighting")) .. "]" ..
		"checkbox[0.25,0.5;cb_particles;" .. fgettext("Particles") .. ";"
				.. dump(core.settings:get_bool("enable_particles")) .. "]" ..
		"checkbox[0.25,1;cb_3d_clouds;" .. fgettext("3D Clouds") .. ";"
				.. dump(core.settings:get_bool("enable_3d_clouds")) .. "]" ..
		"checkbox[0.25,1.5;cb_opaque_water;" .. fgettext("Opaque Water") .. ";"
				.. dump(core.settings:get_bool("opaque_water")) .. "]" ..
		"checkbox[0.25,2.0;cb_connected_glass;" .. fgettext("Connected Glass") .. ";"
				.. dump(core.settings:get_bool("connected_glass")) .. "]" ..
		"dropdown[0.25,2.8;3.5;dd_node_highlighting;" .. dd_options.node_highlighting[1] .. ";"
				.. getSettingIndex.NodeHighlighting() .. "]" ..
		"dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";"
				.. getSettingIndex.Leaves() .. "]" ..
		"box[4,0;3.75,4.5;#999999]" ..
		"label[4.25,0.1;" .. fgettext("Texturing:") .. "]" ..
		"dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";"
				.. getSettingIndex.Filter() .. "]" ..
		"dropdown[4.25,1.35;3.5;dd_mipmap;" .. dd_options.mipmap[1] .. ";"
				.. getSettingIndex.Mipmap() .. "]" ..
		"label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" ..
		"dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";"
				.. getSettingIndex.Antialiasing() .. "]" ..
		"label[4.25,3.45;" .. fgettext("Screen:") .. "]" ..
		"checkbox[4.25,3.6;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";"
				.. dump(core.settings:get_bool("autosave_screensize")) .. "]" ..
		"box[8,0;3.75,4.5;#999999]" ..
		"checkbox[8.25,0;cb_shaders;" .. fgettext("Shaders") .. ";"
				.. dump(core.settings:get_bool("enable_shaders")) .. "]"

	if PLATFORM == "Android" then
		tab_string = tab_string ..
			"button[8,4.75;3.95,1;btn_reset_singleplayer;"
			.. fgettext("Reset singleplayer world") .. "]"
	else
		tab_string = tab_string ..
			"button[8,4.75;3.95,1;btn_change_keys;"
			.. fgettext("Change Keys") .. "]"
	end

	tab_string = tab_string ..
		"button[0,4.75;3.95,1;btn_advanced_settings;"
		.. fgettext("Advanced Settings") .. "]"


	if core.settings:get("touchscreen_threshold") ~= nil then
		tab_string = tab_string ..
			"label[4.3,4.1;" .. fgettext("Touchthreshold (px)") .. "]" ..
			"dropdown[3.85,4.55;3.85;dd_touchthreshold;0,10,20,30,40,50;" ..
			((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. "]"
	end

	if core.settings:get_bool("enable_shaders") then
		tab_string = tab_string ..
			"checkbox[8.25,0.5;cb_bumpmapping;" .. fgettext("Bump Mapping") .. ";"
					.. dump(core.settings:get_bool("enable_bumpmapping")) .. "]" ..
			"checkbox[8.25,1;cb_tonemapping;" .. fgettext("Tone Mapping") .. ";"
					.. dump(core.settings:get_bool("tone_mapping")) .. "]" ..
			"checkbox[8.25,1.5;cb_generate_normalmaps;" .. fgettext("Generate Normal Maps") .. ";"
					.. dump(core.settings:get_bool("generate_normalmaps")) .. "]" ..
			"checkbox[8.25,2;cb_parallax;" .. fgettext("Parallax Occlusion") .. ";"
					.. dump(core.settings:get_bool("enable_parallax_occlusion")) .. "]" ..
			"checkbox[8.25,2.5;cb_waving_water;" .. fgettext("Waving Water") .. ";"
					.. dump(core.settings:get_bool("enable_waving_water")) .. "]" ..
			"checkbox[8.25,3;cb_waving_leaves;" .. fgettext("Waving Leaves") .. ";"
					.. dump(core.settings:get_bool("enable_waving_leaves")) .. "]" ..
			"checkbox[8.25,3.5;cb_waving_plants;" .. fgettext("Waving Plants") .. ";"
					.. dump(core.settings:get_bool("enable_waving_plants")) .. "]"
	else
		tab_string = tab_string ..
			"label[8.38,0.7;" .. core.colorize("#888888",
					fgettext("Bump Mapping")) .. "]" ..
			"label[8.38,1.2;" .. core.colorize("#888888",
					fgettext("Tone Mapping")) .. "]" ..
			"label[8.38,1.7;" .. core.colorize("#888888",
					fgettext("Generate Normal Maps")) .. "]" ..
			"label[8.38,2.2;" .. core.colorize("#888888",
					fgettext("Parallax Occlusion")) .. "]" ..
			"label[8.38,2.7;" .. core.colorize("#888888",
					fgettext("Waving Water")) .. "]" ..
			"label[8.38,3.2;" .. core.colorize("#888888",
					fgettext("Waving Leaves")) .. "]" ..
			"label[8.38,3.7;" .. core.colorize("#888888",
					fgettext("Waving Plants")) .. "]"
	end

	return tab_string
end

--------------------------------------------------------------------------------
local function handle_settings_buttons(this, fields, tabname, tabdata)

	if fields["btn_advanced_settings"] ~= nil then
		local adv_settings_dlg = create_adv_settings_dlg()
		adv_settings_dlg:set_parent(this)
		this:hide()
		adv_settings_dlg:show()
		--mm_texture.update("singleplayer", current_game())
		return true
	end
	if fields["cb_smooth_lighting"] then
		core.settings:set("smooth_lighting", fields["cb_smooth_lighting"])
		return true
	end
	if fields["cb_particles"] then
		core.settings:set("enable_particles", fields["cb_particles"])
		return true
	end
	if fields["cb_3d_clouds"] then
		core.settings:set("enable_3d_clouds", fields["cb_3d_clouds"])
		return true
	end
	if fields["cb_opaque_water"] then
		core.settings:set("opaque_water", fields["cb_opaque_water"])
		return true
	end
	if fields["cb_connected_glass"] then
		core.settings:set("connected_glass", fields["cb_connected_glass"])
		return true
	end
	if fields["cb_autosave_screensize"] then
		core.settings:set("autosave_screensize", fields["cb_autosave_screensize"])
		return true
	end
	if fields["cb_shaders"] then
		if (core.settings:get("video_driver") == "direct3d8" or
				core.settings:get("video_driver") == "direct3d9") then
			core.settings:set("enable_shaders", "false")
			gamedata.errormessage = fgettext("To enable shaders the OpenGL driver needs to be used.")
		else
			core.settings:set("enable_shaders", fields["cb_shaders"])
		end
		return true
	end
	if fields["cb_bumpmapping"] then
		core.settings:set("enable_bumpmapping", fields["cb_bumpmapping"])
		return true
	end
	if fields["cb_tonemapping"] then
		core.settings:set("tone_mapping", fields["cb_tonemapping"])
		return true
	end
	if fields["cb_generate_normalmaps"] then
		core.settings:set("generate_normalmaps", fields["cb_generate_normalmaps"])
		return true
	end
	if fields["cb_parallax"] then
		core.settings:set("enable_parallax_occlusion", fields["cb_parallax"])
		return true
	end
	if fields["cb_waving_water"] then
		core.settings:set("enable_waving_water", fields["cb_waving_water"])
		return true
	end
	if fields["cb_waving_leaves"] then
		core.settings:set("enable_waving_leaves", fields["cb_waving_leaves"])
	end
	if fields["cb_waving_plants"] then
		core.settings:set("enable_waving_plants", fields["cb_waving_plants"])
		return true
	end
	if fields["btn_change_keys"] then
		core.show_keys_menu()
		return true
	end
	if fields["cb_touchscreen_target"] then
		core.settings:set("touchtarget", fields["cb_touchscreen_target"])
		return true
	end
	if fields["btn_reset_singleplayer"] then
		showconfirm_reset(this)
		return true
	end

	--Note dropdowns have to be handled LAST!
	local ddhandled = false

	for i = 1, #labels.leaves do
		if fields["dd_leaves_style"] == labels.leaves[i] then
			core.settings:set("leaves_style", dd_options.leaves[2][i])
			ddhandled = true
		end
	end
	for i = 1, #labels.node_highlighting do
		if fields["dd_node_highlighting"] == labels.node_highlighting[i] then
			core.settings:set("node_highlighting", dd_options.node_highlighting[2][i])
			ddhandled = true
		end
	end
	if fields["dd_filters"] == labels.filters[1] then
		core.settings:set("bilinear_filter", "false")
		core.settings:set("trilinear_filter", "false")
		ddhandled = true
	elseif fields["dd_filters"] == labels.filters[2] then
		core.settings:set("bilinear_filter", "true")
		core.settings:set("trilinear_filter", "false")
		ddhandled = true
	elseif fields["dd_filters"] == labels.filters[3] then
		core.settings:set("bilinear_filter", "false")
		core.settings:set("trilinear_filter", "true")
		ddhandled = true
	end
	if fields["dd_mipmap"] == labels.mipmap[1] then
		core.settings:set("mip_map", "false")
		core.settings:set("anisotropic_filter", "false")
		ddhandled = true
	elseif fields["dd_mipmap"] == labels.mipmap[2] then
		core.settings:set("mip_map", "true")
		core.settings:set("anisotropic_filter", "false")
		ddhandled = true
	elseif fields["dd_mipmap"] == labels.mipmap[3] then
		core.settings:set("mip_map", "true")
		core.settings:set("anisotropic_filter", "true")
		ddhandled = true
	end
	if fields["dd_antialiasing"] then
		core.settings:set("fsaa",
			antialiasing_fname_to_name(fields["dd_antialiasing"]))
		ddhandled = true
	end
	if fields["dd_touchthreshold"] then
		core.settings:set("touchscreen_threshold", fields["dd_touchthreshold"])
		ddhandled = true
	end

	return ddhandled
end

return {
	name = "settings",
	caption = fgettext("Settings"),
	cbf_formspec = formspec,
	cbf_button_handler = handle_settings_buttons
}
class="hl kwa">end end if take_item then itemstack:take_item() end return itemstack, place_to end -- deprecated, item_place does not call this function core.item_place_object(itemstack, placer, pointed_thing) local pos = core.get_pointed_thing_position(pointed_thing, true) if pos ~= nil then local item = itemstack:take_item() core.add_item(pos, item) end return itemstack end function core.item_place(itemstack, placer, pointed_thing, param2) -- Call on_rightclick if the pointed node defines it if pointed_thing.type == "node" and placer and not placer:get_player_control().sneak then local n = core.get_node(pointed_thing.under) local nn = n.name if core.registered_nodes[nn] and core.registered_nodes[nn].on_rightclick then return core.registered_nodes[nn].on_rightclick(pointed_thing.under, n, placer, itemstack, pointed_thing) or itemstack, nil end end -- Place if node, otherwise do nothing if itemstack:get_definition().type == "node" then return core.item_place_node(itemstack, placer, pointed_thing, param2) end return itemstack, nil end function core.item_secondary_use(itemstack, placer) return itemstack end function core.item_drop(itemstack, dropper, pos) local dropper_is_player = dropper and dropper:is_player() local p = table.copy(pos) local cnt = itemstack:get_count() if dropper_is_player then p.y = p.y + 1.2 end local item = itemstack:take_item(cnt) local obj = core.add_item(p, item) if obj then if dropper_is_player then local dir = dropper:get_look_dir() dir.x = dir.x * 2.9 dir.y = dir.y * 2.9 + 2 dir.z = dir.z * 2.9 obj:set_velocity(dir) obj:get_luaentity().dropped_by = dropper:get_player_name() end return itemstack end -- If we reach this, adding the object to the -- environment failed end function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing) for _, callback in pairs(core.registered_on_item_eats) do local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing) if result then return result end end local def = itemstack:get_definition() if itemstack:take_item() ~= nil then user:set_hp(user:get_hp() + hp_change) if def and def.sound and def.sound.eat then core.sound_play(def.sound.eat, { pos = user:get_pos(), max_hear_distance = 16 }, true) end if replace_with_item then if itemstack:is_empty() then itemstack:add_item(replace_with_item) else local inv = user:get_inventory() -- Check if inv is null, since non-players don't have one if inv and inv:room_for_item("main", {name=replace_with_item}) then inv:add_item("main", replace_with_item) else local pos = user:get_pos() pos.y = math.floor(pos.y + 0.5) core.add_item(pos, replace_with_item) end end end end return itemstack end function core.item_eat(hp_change, replace_with_item) return function(itemstack, user, pointed_thing) -- closure if user then return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing) end end end function core.node_punch(pos, node, puncher, pointed_thing) -- Run script hook for _, callback in ipairs(core.registered_on_punchnodes) do -- Copy pos and node because callback can modify them local pos_copy = vector.new(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} local pointed_thing_copy = pointed_thing and copy_pointed_thing(pointed_thing) or nil callback(pos_copy, node_copy, puncher, pointed_thing_copy) end end function core.handle_node_drops(pos, drops, digger) -- Add dropped items to object's inventory local inv = digger and digger:get_inventory() local give_item if inv then give_item = function(item) return inv:add_item("main", item) end else give_item = function(item) -- itemstring to ItemStack for left:is_empty() return ItemStack(item) end end for _, dropped_item in pairs(drops) do local left = give_item(dropped_item) if not left:is_empty() then local p = vector.offset(pos, math.random()/2-0.25, math.random()/2-0.25, math.random()/2-0.25 ) core.add_item(p, left) end end end function core.node_dig(pos, node, digger) local diggername = user_name(digger) local log = make_log(diggername) local def = core.registered_nodes[node.name] -- Copy pos because the callback could modify it if def and (not def.diggable or (def.can_dig and not def.can_dig(vector.new(pos), digger))) then log("info", diggername .. " tried to dig " .. node.name .. " which is not diggable " .. core.pos_to_string(pos)) return false end if core.is_protected(pos, diggername) then log("action", diggername .. " tried to dig " .. node.name .. " at protected position " .. core.pos_to_string(pos)) core.record_protection_violation(pos, diggername) return false end log('action', diggername .. " digs " .. node.name .. " at " .. core.pos_to_string(pos)) local wielded = digger and digger:get_wielded_item() local drops = core.get_node_drops(node, wielded and wielded:get_name()) if wielded then local wdef = wielded:get_definition() local tp = wielded:get_tool_capabilities() local dp = core.get_dig_params(def and def.groups, tp) if wdef and wdef.after_use then wielded = wdef.after_use(wielded, digger, node, dp) or wielded else -- Wear out tool if not core.is_creative_enabled(diggername) then wielded:add_wear(dp.wear) if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then core.sound_play(wdef.sound.breaks, { pos = pos, gain = 0.5 }, true) end end end digger:set_wielded_item(wielded) end -- Check to see if metadata should be preserved. if def and def.preserve_metadata then local oldmeta = core.get_meta(pos):to_table().fields -- Copy pos and node because the callback can modify them. local pos_copy = vector.new(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} local drop_stacks = {} for k, v in pairs(drops) do drop_stacks[k] = ItemStack(v) end drops = drop_stacks def.preserve_metadata(pos_copy, node_copy, oldmeta, drops) end -- Handle drops core.handle_node_drops(pos, drops, digger) local oldmetadata = nil if def and def.after_dig_node then oldmetadata = core.get_meta(pos):to_table() end -- Remove node and update core.remove_node(pos) -- Play sound if it was done by a player if diggername ~= "" and def and def.sounds and def.sounds.dug then core.sound_play(def.sounds.dug, { pos = pos, exclude_player = diggername, }, true) end -- Run callback if def and def.after_dig_node then -- Copy pos and node because callback can modify them local pos_copy = vector.new(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} def.after_dig_node(pos_copy, node_copy, oldmetadata, digger) end -- Run script hook for _, callback in ipairs(core.registered_on_dignodes) do local origin = core.callback_origins[callback] if origin then core.set_last_run_mod(origin.mod) end -- Copy pos and node because callback can modify them local pos_copy = vector.new(pos) local node_copy = {name=node.name, param1=node.param1, param2=node.param2} callback(pos_copy, node_copy, digger) end return true end function core.itemstring_with_palette(item, palette_index) local stack = ItemStack(item) -- convert to ItemStack stack:get_meta():set_int("palette_index", palette_index) return stack:to_string() end function core.itemstring_with_color(item, colorstring) local stack = ItemStack(item) -- convert to ItemStack stack:get_meta():set_string("color", colorstring) return stack:to_string() end -- This is used to allow mods to redefine core.item_place and so on -- NOTE: This is not the preferred way. Preferred way is to provide enough -- callbacks to not require redefining global functions. -celeron55 local function redef_wrapper(table, name) return function(...) return table[name](...) end end -- -- Item definition defaults -- local default_stack_max = tonumber(core.settings:get("default_stack_max")) or 99 core.nodedef_default = { -- Item properties type="node", -- name intentionally not defined here description = "", groups = {}, inventory_image = "", wield_image = "", wield_scale = vector.new(1, 1, 1), stack_max = default_stack_max, usable = false, liquids_pointable = false, tool_capabilities = nil, node_placement_prediction = nil, -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), -- core.item_place on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, can_dig = nil, on_punch = redef_wrapper(core, 'node_punch'), -- core.node_punch on_rightclick = nil, on_dig = redef_wrapper(core, 'node_dig'), -- core.node_dig on_receive_fields = nil, -- Node properties drawtype = "normal", visual_scale = 1.0, -- Don't define these because otherwise the old tile_images and -- special_materials wouldn't be read --tiles ={""}, --special_tiles = { -- {name="", backface_culling=true}, -- {name="", backface_culling=true}, --}, post_effect_color = {a=0, r=0, g=0, b=0}, paramtype = "none", paramtype2 = "none", is_ground_content = true, sunlight_propagates = false, walkable = true, pointable = true, diggable = true, climbable = false, buildable_to = false, floodable = false, liquidtype = "none", liquid_alternative_flowing = "", liquid_alternative_source = "", liquid_viscosity = 0, drowning = 0, light_source = 0, damage_per_second = 0, selection_box = {type="regular"}, legacy_facedir_simple = false, legacy_wallmounted = false, } core.craftitemdef_default = { type="craft", -- name intentionally not defined here description = "", groups = {}, inventory_image = "", wield_image = "", wield_scale = vector.new(1, 1, 1), stack_max = default_stack_max, liquids_pointable = false, tool_capabilities = nil, -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), -- core.item_place on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_use = nil, } core.tooldef_default = { type="tool", -- name intentionally not defined here description = "", groups = {}, inventory_image = "", wield_image = "", wield_scale = vector.new(1, 1, 1), stack_max = 1, liquids_pointable = false, tool_capabilities = nil, -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), -- core.item_place on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_drop = redef_wrapper(core, 'item_drop'), -- core.item_drop on_use = nil, } core.noneitemdef_default = { -- This is used for the hand and unknown items type="none", -- name intentionally not defined here description = "", groups = {}, inventory_image = "", wield_image = "", wield_scale = vector.new(1, 1, 1), stack_max = default_stack_max, liquids_pointable = false, tool_capabilities = nil, -- Interaction callbacks on_place = redef_wrapper(core, 'item_place'), on_secondary_use = redef_wrapper(core, 'item_secondary_use'), on_drop = nil, on_use = nil, }