summaryrefslogtreecommitdiff
path: root/dirt.lua
blob: 250b9a2260a48e0117a80e27716fb731783b4691 (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
-- Override default Dirt (to stop caves cutting away dirt)
minetest.override_item("default:dirt", {is_ground_content = false})

-- Green Dirt
minetest.register_node("ethereal:green_dirt", {
	description = "Green Dirt",
	tiles = {"default_grass.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"},
	is_ground_content = false,
	groups = {crumbly=3,soil=1,ethereal_grass=1},
	drop = "default:dirt",
	sounds = default.node_sound_dirt_defaults()
})

-- Dry Dirt
minetest.register_node("ethereal:dry_dirt", {
	description = "Dried Dirt",
	tiles = {"ethereal_dry_dirt.png"},
	is_ground_content = false,
	groups = {crumbly=3},
	sounds = default.node_sound_dirt_defaults()
})

minetest.register_craft({
	type = "cooking",
	output = "ethereal:dry_dirt",
	recipe = "default:dirt",
	cooktime = 3,
})

local dirt = {}
dirt.type = {
	{"Bamboo"}, {"Jungle"}, {"Grove"}, {"Prairie"}, {"Cold"}, {"Crystal"}, {"Mushroom"}, {"Fiery"}, {"Gray"},
}

for _, row in ipairs(dirt.type) do

	local desc = row[1]
	local name = desc:lower()

	minetest.register_node("ethereal:"..name.."_dirt", {
		description = desc.." Dirt",
		tiles = {"ethereal_grass_"..name.."_top.png", "default_dirt.png",
				"default_dirt.png^ethereal_grass_"..name.."_side.png"},
		is_ground_content = false,
		groups = {crumbly=3,soil=1,ethereal_grass=1},
		drop = "default:dirt",
		sounds = default.node_sound_dirt_defaults()
	})

end

-- Compatibility with old maps
minetest.register_alias("ethereal:crystal_topped_dirt", "ethereal:crystal_dirt")
minetest.register_alias("ethereal:fiery_dirt_top", "ethereal:fiery_dirt")
minetest.register_alias("ethereal:gray_dirt_top", "ethereal:gray_dirt")
minetest.register_alias("ethereal:green_dirt_top", "ethereal:green_dirt")

-- Check surrounding grass and change dirt to Same colour (by Sokomine)
minetest.register_abm({
	nodenames = {"default:dirt_with_grass"},
	interval = 5,
	chance = 5,
	action = function(pos, node)
		local count_grasses = {}
		local curr_max  = 0
		local curr_type = "ethereal:green_dirt_top"; -- Fallback Colour
		local positions = minetest.find_nodes_in_area( {x=(pos.x-2), y=(pos.y-2), z=(pos.z-2)},
							       {x=(pos.x+2), y=(pos.y+2), z=(pos.z+2)},
								"group:ethereal_grass" )
		for _,p in ipairs(positions) do
			-- count the new grass node
			local n = minetest.get_node( p )
			if( n and n.name ) then
				if( not( count_grasses[ n.name ] )) then
					count_grasses[ n.name ] = 1
				else
					count_grasses[ n.name ] = count_grasses[ n.name ] + 1
				end
				-- we found a grass type of which there"s more than the current max
				if( count_grasses[ n.name ] > curr_max ) then
					curr_max  = count_grasses[ n.name ]
					curr_type = n.name
				end
			end
		end
		minetest.set_node(pos, {name = curr_type })
        end
})

-- If Grass devoid of light, change to Dirt
minetest.register_abm({
	nodenames = {"group:ethereal_grass"},
	interval = 5,
	chance = 20,
	action = function(pos, node)
		local name = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
		local nodedef = minetest.registered_nodes[name]
		if name ~= "ignore" and nodedef
				and not ((nodedef.sunlight_propagates or nodedef.paramtype == "light")
				and nodedef.liquidtype == "none") then
			minetest.set_node(pos, {name = "default:dirt"})
		end
	end
})

-- If Baked Clay mod not active, make Red and Orange nodes
if not minetest.get_modpath("bakedclay") then

	minetest.register_node(":bakedclay:red", {
		description = "Red Baked Clay",
		tiles = {"baked_clay_red.png"},
		groups = {cracky=3},
		is_ground_content = false,
		sounds = default.node_sound_stone_defaults(),
	})
	
	stairs.register_stair_and_slab("bakedclay_red", "bakedclay:red",
		{cracky=3, not_in_craft_guide=1},
		{"baked_clay_red.png"},
		"Baked Clay Red Stair",
		"Baked Clay Red Slab",
		default.node_sound_stone_defaults())

	minetest.register_node(":bakedclay:orange", {
		description = "Orange Baked Clay",
		tiles = {"baked_clay_orange.png"},
		groups = {cracky=3},
		is_ground_content = false,
		sounds = default.node_sound_stone_defaults(),
	})
	
	stairs.register_stair_and_slab("bakedclay_orange", "bakedclay:orange",
		{cracky=3, not_in_craft_guide=1},
		{"baked_clay_orange.png"},
		"Baked Clay Orange Stair",
		"Baked Clay Orange Slab",
		default.node_sound_stone_defaults())

end