sorcery  Diff

Differences From Artifact [1c278a4b1d]:

To Artifact [f2e6b0cbe1]:


4
5
6
7
8
9
10






11
12
13
14
15
16
17
...
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
...
152
153
154
155
156
157
158
















159
160
161
162
163
164
165
...
211
212
213
214
215
216
217
218

219
220
221
222
223
224
225
		{x =  0, y =  1, z =  0};
		{x =  0, y = -1, z =  0};
		{x =  1, y =  0, z =  0};
		{x = -1, y =  0, z =  0};
		{x =  0, y =  0, z =  1};
		{x =  0, y =  0, z = -1};
	};






	planecorners = {
		{x =  1, y =  0, z =  1};
		{x = -1, y =  0, z =  1};
		{x = -1, y =  0, z = -1};
		{x =  1, y =  0, z = -1};

		{x =  1, y =  1, z =  0};
................................................................................
		end
		checked[#checked+1] = pos
		i = i + 1
	until i > #stack
	return nodes, positions
end;















return {
	offsets = ofs;
	purge_container = function(...) return purge_container(nil, ...) end;
	purge_only = function(lst)
		return function(...)
			return purge_container(lst, ...)
		end
	end; 

	is_air = function(pos)
		local n = force(pos)
		if n.name == 'air' then return true end
		local d = minetest.registered_nodes[n.name]
		if not d then return false end
		return (d.walkable == false) and (d.drawtype == 'airlike' or d.buildable_to == true)
	end;

	is_clear = function(pos)
		if not sorcery.lib.node.is_air(pos) then return false end
		local ents = minetest.get_objects_inside_radius(pos,0.5)
		if #ents > 0 then return false end
		return true
	end;

	insert = function(item, slot, npos, user, inv)
		inv = inv or minetest.get_meta(npos):get_inventory()
		if inv:room_for_item(slot,item) then
			inv:add_item(slot,item)
		else repeat
			if user then
................................................................................
					ui:add_item('main', item)
					break
				end
			end
			minetest.add_item(npos, item)
		until true end
	end;

















	tree_is_live = function(pos, checklight) -- VERY EXPENSIVE FUNCTION
		-- this is going to require some explanation.
		--
		-- for various purposes, we want to be able to tell the difference between
		-- a tree that has grown naturally from the grown vs. a couple of trunk nodes
		-- that the player has jammed together, even if she's built her own counterfeit
................................................................................
		-- or inserting it also when it comes into contact with another trunk node,
		-- but pepole use these things to build with and that is just way way too many
		-- meta keys for me to consider it an option.
		--
		-- verdict: not very good, but decent enough for most cases. mtg should have
		--          done better than this, but now we're all stuck with their bullshit
		--
		--  UPDATE: in pratice this is way too expensive to be functional, and causes servers to hang. we're replacing it with a simpler version


		local treetype = force(pos).name
		if minetest.get_item_group(treetype, 'tree') == 0 then -- sir this is not a tree
			return nil -- 無
		end
		local treedef = sorcery.lib.tbl.select(sorcery.data.trees, function(ent)
			return sorcery.lib.tbl.strmatch(ent.node, treetype)







>
>
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>









|
<
<
<
<
<
<
<
|
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
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
...
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
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
		{x =  0, y =  1, z =  0};
		{x =  0, y = -1, z =  0};
		{x =  1, y =  0, z =  0};
		{x = -1, y =  0, z =  0};
		{x =  0, y =  0, z =  1};
		{x =  0, y =  0, z = -1};
	};
	corners = {
		{x =  1, y =  0, z =  1};
		{x = -1, y =  0, z =  1};
		{x = -1, y =  0, z = -1};
		{x =  1, y =  0, z = -1};
	};
	planecorners = {
		{x =  1, y =  0, z =  1};
		{x = -1, y =  0, z =  1};
		{x = -1, y =  0, z = -1};
		{x =  1, y =  0, z = -1};

		{x =  1, y =  1, z =  0};
................................................................................
		end
		checked[#checked+1] = pos
		i = i + 1
	until i > #stack
	return nodes, positions
end;

local is_air = function(pos)
	local n = force(pos)
	if n.name == 'air' then return true end
	local d = minetest.registered_nodes[n.name]
	if not d then return false end
	return (d.walkable == false) and (d.drawtype == 'airlike' or d.buildable_to == true)
end;

local is_clear = function(pos)
	if not sorcery.lib.node.is_air(pos) then return false end
	local ents = minetest.get_objects_inside_radius(pos,0.5)
	if #ents > 0 then return false end
	return true
end;
return {
	offsets = ofs;
	purge_container = function(...) return purge_container(nil, ...) end;
	purge_only = function(lst)
		return function(...)
			return purge_container(lst, ...)
		end
	end; 

	is_air = is_air;







	is_clear = is_clear;






	insert = function(item, slot, npos, user, inv)
		inv = inv or minetest.get_meta(npos):get_inventory()
		if inv:room_for_item(slot,item) then
			inv:add_item(slot,item)
		else repeat
			if user then
................................................................................
					ui:add_item('main', item)
					break
				end
			end
			minetest.add_item(npos, item)
		until true end
	end;

	install_bed = function(bed, where, dir)
		local bottom = bed .. '_bottom'
		local top = bed .. '_top'
		local d
		if type(dir) == 'number' then
			d = dir
			dir = minetest.facedir_to_dir(d)
		else
			d = minetest.dir_to_facedir(dir)
		end
		if not is_clear(where) and is_clear(where - dir) then return false end
		minetest.set_node(where,       {name = top, param2 = d})
		minetest.set_node(where - dir, {name = bottom, param2 = d})
		return true
	end;

	tree_is_live = function(pos, checklight) -- VERY EXPENSIVE FUNCTION
		-- this is going to require some explanation.
		--
		-- for various purposes, we want to be able to tell the difference between
		-- a tree that has grown naturally from the grown vs. a couple of trunk nodes
		-- that the player has jammed together, even if she's built her own counterfeit
................................................................................
		-- or inserting it also when it comes into contact with another trunk node,
		-- but pepole use these things to build with and that is just way way too many
		-- meta keys for me to consider it an option.
		--
		-- verdict: not very good, but decent enough for most cases. mtg should have
		--          done better than this, but now we're all stuck with their bullshit
		--
		--  UPDATE: in practice this was way too expensive to be functional, and causes
		--          servers to hang. ripped it out and replaced it with a simpler version

		local treetype = force(pos).name
		if minetest.get_item_group(treetype, 'tree') == 0 then -- sir this is not a tree
			return nil -- 無
		end
		local treedef = sorcery.lib.tbl.select(sorcery.data.trees, function(ent)
			return sorcery.lib.tbl.strmatch(ent.node, treetype)