summaryrefslogtreecommitdiff
path: root/extranodes/antishroom.lua
blob: 38168ebdf269e42106086bc829765c8914e39e15 (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
-- a tool to convert a mushroom biome into green forest with thick trees and flowers

local S = rawget(_G, "intllib") and intllib.Getter() or function(s) return s end

minetest.register_craftitem(":technic:antishroom",{
	description = "Mushroom biome converter",
	inventory_image = "antishroom.png",
	wield_image = "antishroom_wield.png",
	on_use = function(itemstack, user, pointed_thing)
	
		if pointed_thing.type ~= "node" then
			return itemstack
		end
		
		local pos = pointed_thing.under
		local target = minetest.get_node_or_nil(pos)
		
		if target and target.name == "ethereal:mushroom_dirt" then
		
			local start_pos = {
				x = pos.x - 16,
				z = pos.z - 16,
				y = pos.y - 5 
			} 
			
			local end_pos = {
				x = pos.x + 16,
				z = pos.z + 16,
				y = pos.y + 15
			} 

			local rlist = {
						["ethereal:mushroom_dirt"]  = "default:dirt_with_grass",
						["ethereal:mushroom_trunk"] = "default:tree",
						["ethereal:mushroom"]       = "default:leaves",
						["ethereal:mushroom_pore"]  = "default:apple"
					}
					
			local mlist = {}
			for t,r in pairs(rlist) do
				table.insert(mlist, t)
			end
			
			local found_mushroom_parts = minetest.find_nodes_in_area(start_pos, end_pos, mlist)
			for _, f in ipairs(found_mushroom_parts) do
				local node = minetest.get_node(f)
				
				if not minetest.is_protected(f, user:get_player_name()) then
					
					minetest.swap_node(f, { name = rlist[node.name] } )
					
					if minetest.get_modpath("bonemeal") and node.name == "ethereal:mushroom_dirt" then
						if math.random(1,5) > 4 then
							bonemeal:on_use(f, 1, nil)
						end
					end
				
				end

			end
			
			itemstack:take_item()
			return itemstack
		else
			return itemstack
		end
		
		
	end,
})