sorcery  Diff

Differences From Artifact [a0d38cfe10]:

To Artifact [ea0569acf8]:


            1  +local ofs = {
            2  +	neighbors = {
            3  +		{x =  1, y =  0, z =  0};
            4  +		{x = -1, y =  0, z =  0};
            5  +		{x =  0, y =  1, z =  0};
            6  +		{x =  0, y = -1, z =  0};
            7  +		{x =  0, y =  0, z =  1};
            8  +		{x =  0, y =  0, z = -1};
            9  +	};
           10  +	planecorners = {
           11  +		{x =  1, y =  0, z =  1};
           12  +		{x = -1, y =  0, z =  1};
           13  +		{x = -1, y =  0, z = -1};
           14  +		{x =  1, y =  0, z = -1};
           15  +
           16  +		{x =  1, y =  1, z =  0};
           17  +		{x = -1, y =  1, z =  0};
           18  +		{x = -1, y = -1, z =  0};
           19  +		{x =  1, y = -1, z =  0};
           20  +	};
           21  +	cubecorners = {
           22  +		{x =  1, y =  1, z =  1};
           23  +		{x = -1, y =  1, z =  1};
           24  +		{x = -1, y = -1, z =  1};
           25  +		{x = -1, y = -1, z = -1};
           26  +		{x =  1, y = -1, z = -1};
           27  +		{x =  1, y =  1, z = -1};
           28  +		{x =  1, y = -1, z =  1};
           29  +		{x = -1, y =  1, z = -1};
           30  +	};
           31  +	nextto = {
           32  +		{x =  1, y =  0, z =  0};
           33  +		{x = -1, y =  0, z =  0};
           34  +		{x =  0, y =  0, z =  1};
           35  +		{x =  0, y =  0, z = -1};
           36  +	};
           37  +}
           38  +
           39  +ofs.adjoining = sorcery.lib.tbl.append(sorcery.lib.tbl.append(
           40  +	ofs.neighbors,ofs.planecorners),ofs.cubecorners)
           41  +
     1     42   return {
           43  +	offsets = ofs;
     2     44   	purge_container = function(pos,node,meta,user)
     3     45   		local offset = function(pos,range)
     4     46   			local r = function(min,max)
     5     47   				return (math.random() * (max - min)) + min
     6     48   			end
     7     49   			return {
     8     50   				x = pos.x + r(0 - range, range);
................................................................................
    14     56   			for _, item in pairs(inv) do
    15     57   				if not item:is_empty() then
    16     58   					minetest.add_item(offset(pos,0.4), item)
    17     59   				end
    18     60   			end
    19     61   		end
    20     62   	end;
           63  +
           64  +	amass = function(startpoint,names,directions)
           65  +		if not directions then directions = ofs.neighbors end
           66  +		local nodes, positions, checked = {},{},{}
           67  +		local checkedp = function(pos)
           68  +			for _,v in pairs(checked) do
           69  +				if vector.equals(pos,v) then return true end
           70  +			end
           71  +			return false
           72  +		end
           73  +		local i,stack = 1,{startpoint} repeat
           74  +			local pos = stack[i]
           75  +			local n = minetest.get_node(pos).name
           76  +			if sorcery.lib.tbl.has(names, n) then -- match found
           77  +				-- record the find
           78  +				nodes[pos] = n
           79  +				if positions[n] then positions[n][#positions[n]] = pos
           80  +				else positions[n] = {pos} end
           81  +
           82  +				-- check selected neighbors to see if any need scanning
           83  +				for _,d in pairs(directions) do
           84  +					local sum = vector.add(pos, d)
           85  +					if not checkedp(sum) then
           86  +						stack[#stack + 1] = sum
           87  +					end
           88  +				end
           89  +			end
           90  +			checked[#checked+1] = pos
           91  +			i = i + 1
           92  +		until i > #stack
           93  +		return nodes, positions
           94  +	end;
    21     95   }