From de707d0c64a62a665229afd63f579360ac0cba89 Mon Sep 17 00:00:00 2001
From: tchncs <tchncs@vivaldi.net>
Date: Thu, 2 Sep 2021 21:43:32 +0200
Subject: [PATCH] [PATCH (from upstream)] added sponges to coral reefs

---
 sealife.lua                      |  97 +++++++++++++++++++++++++++++--
 textures/ethereal_sponge.png     | Bin 0 -> 272 bytes
 textures/ethereal_sponge_wet.png | Bin 0 -> 272 bytes
 3 files changed, 92 insertions(+), 5 deletions(-)
 create mode 100644 textures/ethereal_sponge.png
 create mode 100644 textures/ethereal_sponge_wet.png

diff --git a/sealife.lua b/sealife.lua
index 08d2f0c..7c81f24 100644
--- a/sealife.lua
+++ b/sealife.lua
@@ -146,19 +146,24 @@ minetest.register_abm({
 	catch_up = false,
 	action = function(pos, node)
 
-		local sel = math.random(1, 5)
+		local sel = math.random(1, 6)
 
 		pos.y = pos.y + 1
 
 		local nod = minetest.get_node(pos).name
 
 		if nod == "default:water_source"
-		and sel > 1 then
+		and sel == 6 then
 
-			if minetest.get_node(pos).name == "default:water_source" then
+			minetest.swap_node(pos, {name = "ethereal:sponge_wet"})
 
-				minetest.swap_node(pos, {name = "ethereal:coral" .. sel})
-			end
+			return
+		end
+
+		if nod == "default:water_source"
+		and sel > 1 then
+
+			minetest.swap_node(pos, {name = "ethereal:coral" .. sel})
 
 			return
 		end
@@ -187,3 +192,85 @@ minetest.register_abm({
 	end,
 })
 end
+
+-- sponges
+
+minetest.register_node("ethereal:sponge_air", {
+	drawtype = "airlike",
+	paramtype = "light",
+	walkable = false,
+	buildable_to = true,
+	sunlight_propagates = true,
+	pointable = false,
+	drop = "",
+	groups = {not_in_creative_inventory = 1},
+})
+
+
+minetest.register_node("ethereal:sponge", {
+	description = S("Sponge"),
+	tiles = {"ethereal_sponge.png"},
+	groups = {crumbly = 3},
+	sounds = default.node_sound_sand_defaults(),
+
+	after_place_node = function(pos, placer, itemstack, pointed_thing)
+
+		-- get player name
+		local name = placer:get_player_name()
+
+		-- is area protected
+		if minetest.is_protected(pos, name) then
+			return
+		end
+
+		-- get water nodes within range
+		local num = minetest.find_nodes_in_area(
+			{x = pos.x - 3, y = pos.y - 3, z = pos.z - 3},
+			{x = pos.x + 3, y = pos.y + 3, z = pos.z + 3},
+			{"group:water"})
+
+		-- no water
+		if #num == 0 then return end
+
+		-- replace water nodes with sponge air
+		for _, w in pairs(num) do
+
+			if not minetest.is_protected(pos, name) then
+				minetest.swap_node(w, {name = "ethereal:sponge_air"})
+			end
+		end
+
+		-- replace dry sponge with wet sponge
+		minetest.swap_node(pos, {name="ethereal:sponge_wet"})
+	end
+})
+
+
+minetest.register_node("ethereal:sponge_wet", {
+	description = S("Wet sponge"),
+	tiles = {"ethereal_sponge_wet.png"},
+	groups = {crumbly = 3},
+	sounds = default.node_sound_sand_defaults(),
+})
+
+-- cook wet sponge into dry sponge
+minetest.register_craft({
+	type = "cooking",
+	recipe = "ethereal:sponge_wet",
+	output = "ethereal:sponge",
+	cooktime = 3,
+})
+
+-- use leaf decay to remove sponge air nodes
+default.register_leafdecay({
+	trunks = {"ethereal:sponge_wet"},
+	leaves = {"ethereal:sponge_air"},
+	radius = 3
+})
+
+-- dry sponges can be used as fuel
+minetest.register_craft({
+	type = "fuel",
+	recipe = "ethereal:sponge",
+	burntime = 5,
+})
diff --git a/textures/ethereal_sponge.png b/textures/ethereal_sponge.png
new file mode 100644
index 0000000000000000000000000000000000000000..e739ec4c80fbf710b4e112a85f36e253435b722f
GIT binary patch
literal 272
zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd7G?$phPQVgfdmW!d_r8;=gJ?gR=M7$b!&p<
z-I-nw7e+l?k@|F9!Luz@FLt)RIym9ovDt4<&3$)n`NzwfKHc8O_=Vvy0|UcsPZ!4!
zj_ZsQ81nx!yq>YF_KNSj_Y7}uZ&~Z+a`zF#t+Ts#w|Z|>Vpt%}wfoN9OLh#xs~J63
z-?{saVbyMtirE_kbr~9^j(2apne4|PUcPNh=9%<+4C>W)Z|vT?=PrY3*WIquckk9R
zc<#NsdhhMKcNzAqyu0`A*}Zoetg`mrU3>2xBZK$dyBT-i-4kZGz54FldvD);V|cOi
g_T6{y{{R29KA8RL^o@5I7#J8lUHx3vIVCg!0N}oem;e9(

literal 0
HcmV?d00001

diff --git a/textures/ethereal_sponge_wet.png b/textures/ethereal_sponge_wet.png
new file mode 100644
index 0000000000000000000000000000000000000000..ddf1aac3436458f087c0278264f48526ed3184c4
GIT binary patch
literal 272
zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd7G?$phPQVgfdmW!d_r7{J;Zt=q?e@1Z7)zf
zQmK5oQSD~0>7A)A_h$P)T%PoFUBS~WRj+ooKHJmw^1y_5Cl}84-q_5*z%bj>#W95A
zI^zU}{QnF;Ot!>4(tH1(;oq)JJ<3YQ6B%yqUcD;Vs!)hwf;7kOJ7*s0F)(%ssdnEv
z_l{xaZe?SeL&|atg;JZX4_|fCV-OVDyvgiL=sN}>sk28?*Okp<5Y*UXnsM%J9D~O0
zGwE}V-8sXsXZo2r@7nUtGKi?HJzMww9|MEfxwC0A|Ic@2xKsJ2viDp4SB7t?r%%26
c|Ns9U1$Tqb)%njE7#J8lUHx3vIVCg!0QJsyXaE2J

literal 0
HcmV?d00001

-- 
GitLab