sorcery  Diff

Differences From Artifact [1c278a4b1d]:

To Artifact [f2e6b0cbe1]:


     4      4   		{x =  0, y =  1, z =  0};
     5      5   		{x =  0, y = -1, z =  0};
     6      6   		{x =  1, y =  0, z =  0};
     7      7   		{x = -1, y =  0, z =  0};
     8      8   		{x =  0, y =  0, z =  1};
     9      9   		{x =  0, y =  0, z = -1};
    10     10   	};
           11  +	corners = {
           12  +		{x =  1, y =  0, z =  1};
           13  +		{x = -1, y =  0, z =  1};
           14  +		{x = -1, y =  0, z = -1};
           15  +		{x =  1, y =  0, z = -1};
           16  +	};
    11     17   	planecorners = {
    12     18   		{x =  1, y =  0, z =  1};
    13     19   		{x = -1, y =  0, z =  1};
    14     20   		{x = -1, y =  0, z = -1};
    15     21   		{x =  1, y =  0, z = -1};
    16     22   
    17     23   		{x =  1, y =  1, z =  0};
................................................................................
   113    119   		end
   114    120   		checked[#checked+1] = pos
   115    121   		i = i + 1
   116    122   	until i > #stack
   117    123   	return nodes, positions
   118    124   end;
   119    125   
          126  +local is_air = function(pos)
          127  +	local n = force(pos)
          128  +	if n.name == 'air' then return true end
          129  +	local d = minetest.registered_nodes[n.name]
          130  +	if not d then return false end
          131  +	return (d.walkable == false) and (d.drawtype == 'airlike' or d.buildable_to == true)
          132  +end;
          133  +
          134  +local is_clear = function(pos)
          135  +	if not sorcery.lib.node.is_air(pos) then return false end
          136  +	local ents = minetest.get_objects_inside_radius(pos,0.5)
          137  +	if #ents > 0 then return false end
          138  +	return true
          139  +end;
   120    140   return {
   121    141   	offsets = ofs;
   122    142   	purge_container = function(...) return purge_container(nil, ...) end;
   123    143   	purge_only = function(lst)
   124    144   		return function(...)
   125    145   			return purge_container(lst, ...)
   126    146   		end
   127    147   	end; 
   128    148   
   129         -	is_air = function(pos)
   130         -		local n = force(pos)
   131         -		if n.name == 'air' then return true end
   132         -		local d = minetest.registered_nodes[n.name]
   133         -		if not d then return false end
   134         -		return (d.walkable == false) and (d.drawtype == 'airlike' or d.buildable_to == true)
   135         -	end;
   136         -
   137         -	is_clear = function(pos)
   138         -		if not sorcery.lib.node.is_air(pos) then return false end
   139         -		local ents = minetest.get_objects_inside_radius(pos,0.5)
   140         -		if #ents > 0 then return false end
   141         -		return true
   142         -	end;
          149  +	is_air = is_air;
          150  +	is_clear = is_clear;
   143    151   
   144    152   	insert = function(item, slot, npos, user, inv)
   145    153   		inv = inv or minetest.get_meta(npos):get_inventory()
   146    154   		if inv:room_for_item(slot,item) then
   147    155   			inv:add_item(slot,item)
   148    156   		else repeat
   149    157   			if user then
................................................................................
   152    160   					ui:add_item('main', item)
   153    161   					break
   154    162   				end
   155    163   			end
   156    164   			minetest.add_item(npos, item)
   157    165   		until true end
   158    166   	end;
          167  +
          168  +	install_bed = function(bed, where, dir)
          169  +		local bottom = bed .. '_bottom'
          170  +		local top = bed .. '_top'
          171  +		local d
          172  +		if type(dir) == 'number' then
          173  +			d = dir
          174  +			dir = minetest.facedir_to_dir(d)
          175  +		else
          176  +			d = minetest.dir_to_facedir(dir)
          177  +		end
          178  +		if not is_clear(where) and is_clear(where - dir) then return false end
          179  +		minetest.set_node(where,       {name = top, param2 = d})
          180  +		minetest.set_node(where - dir, {name = bottom, param2 = d})
          181  +		return true
          182  +	end;
   159    183   
   160    184   	tree_is_live = function(pos, checklight) -- VERY EXPENSIVE FUNCTION
   161    185   		-- this is going to require some explanation.
   162    186   		--
   163    187   		-- for various purposes, we want to be able to tell the difference between
   164    188   		-- a tree that has grown naturally from the grown vs. a couple of trunk nodes
   165    189   		-- that the player has jammed together, even if she's built her own counterfeit
................................................................................
   211    235   		-- or inserting it also when it comes into contact with another trunk node,
   212    236   		-- but pepole use these things to build with and that is just way way too many
   213    237   		-- meta keys for me to consider it an option.
   214    238   		--
   215    239   		-- verdict: not very good, but decent enough for most cases. mtg should have
   216    240   		--          done better than this, but now we're all stuck with their bullshit
   217    241   		--
   218         -		--  UPDATE: in pratice this is way too expensive to be functional, and causes servers to hang. we're replacing it with a simpler version
          242  +		--  UPDATE: in practice this was way too expensive to be functional, and causes
          243  +		--          servers to hang. ripped it out and replaced it with a simpler version
   219    244   
   220    245   		local treetype = force(pos).name
   221    246   		if minetest.get_item_group(treetype, 'tree') == 0 then -- sir this is not a tree
   222    247   			return nil -- 無
   223    248   		end
   224    249   		local treedef = sorcery.lib.tbl.select(sorcery.data.trees, function(ent)
   225    250   			return sorcery.lib.tbl.strmatch(ent.node, treetype)