From 21f5eaade052684d2694f6584496f8b5dc48d4ea Mon Sep 17 00:00:00 2001
From: Ezhh <owlecho@live.com>
Date: Thu, 15 Nov 2018 00:49:16 +0000
Subject: [PATCH] Add plantlike_rooted coral

---
 mods/default/README.txt                       |   5 +
 mods/default/mapgen.lua                       |  21 ++-
 mods/default/nodes.lua                        | 153 ++++++++++++++++++
 mods/default/schematics/corals.mts            | Bin 171 -> 0 bytes
 mods/default/textures/default_coral_cyan.png  | Bin 0 -> 202 bytes
 mods/default/textures/default_coral_green.png | Bin 0 -> 287 bytes
 mods/default/textures/default_coral_pink.png  | Bin 0 -> 242 bytes
 schematic_tables.txt                          |  38 -----
 8 files changed, 171 insertions(+), 46 deletions(-)
 delete mode 100644 mods/default/schematics/corals.mts
 create mode 100644 mods/default/textures/default_coral_cyan.png
 create mode 100644 mods/default/textures/default_coral_green.png
 create mode 100644 mods/default/textures/default_coral_pink.png

diff --git a/mods/default/README.txt b/mods/default/README.txt
index 486379be..a5346976 100644
--- a/mods/default/README.txt
+++ b/mods/default/README.txt
@@ -239,6 +239,11 @@ Krock (CC0 1.0):
   default_glass.png
   default_glass_detail.png
 
+Topywo (CC BY-SA 3.0)
+  default_coral_cyan.png
+  default_coral_green.png
+  default_coral_pink.png
+
 
 Sounds
 ------
diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua
index d53467d3..b92e12ef 100644
--- a/mods/default/mapgen.lua
+++ b/mods/default/mapgen.lua
@@ -2167,15 +2167,17 @@ function default.register_decorations()
 
 	minetest.register_decoration({
 		name = "default:corals",
-		deco_type = "schematic",
+		deco_type = "simple",
 		place_on = {"default:sand"},
+		place_offset_y = -1,
+		sidelen = 4,
 		noise_params = {
-			offset = -0.15,
-			scale = 0.1,
-			spread = {x = 100, y = 100, z = 100},
+			offset = -4,
+			scale = 4,
+			spread = {x = 50, y = 50, z = 50},
 			seed = 7013,
 			octaves = 3,
-			persist = 1,
+			persist = 0.7,
 		},
 		biomes = {
 			"desert_ocean",
@@ -2184,9 +2186,12 @@ function default.register_decorations()
 		},
 		y_max = -2,
 		y_min = -8,
-		schematic = minetest.get_modpath("default") .. "/schematics/corals.mts",
-		flags = "place_center_x, place_center_z",
-		rotation = "random",
+		flags = "force_placement",
+		decoration = {
+			"default:coral_green", "default:coral_pink",
+			"default:coral_cyan", "default:coral_brown",
+			"default:coral_orange", "default:coral_skeleton",
+		},
 	})
 
 	-- Kelp
diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua
index 4f186e1c..3c2836d9 100644
--- a/mods/default/nodes.lua
+++ b/mods/default/nodes.lua
@@ -1910,6 +1910,159 @@ minetest.register_node("default:sand_with_kelp", {
 -- Corals
 --
 
+minetest.register_node("default:coral_green", {
+	description = "Green Coral",
+	drawtype = "plantlike_rooted",
+	waving = 1,
+	paramtype = "light",
+	tiles = {"default_coral_skeleton.png"},
+	special_tiles = {{name = "default_coral_green.png", tileable_vertical = true}},
+	inventory_image = "default_coral_green.png",
+	groups = {snappy = 3},
+	selection_box = {
+		type = "fixed",
+		fixed = {
+				{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+				{-4/16, 0.5, -4/16, 4/16, 1.5, 4/16},
+		},
+	},
+	node_dig_prediction = "default:coral_skeleton",
+	node_placement_prediction = "",
+	on_place = function(itemstack, placer, pointed_thing)
+		if pointed_thing.type ~= "node" or not placer then
+			return itemstack
+		end
+
+		local player_name = placer:get_player_name()
+		local pos_under = pointed_thing.under
+		local pos_above = pointed_thing.above
+
+		if minetest.get_node(pos_under).name ~= "default:coral_skeleton" or
+				minetest.get_node(pos_above).name ~= "default:water_source" then
+			return itemstack
+		end
+
+		if minetest.is_protected(pos_under, player_name) or
+				minetest.is_protected(pos_above, player_name) then
+			minetest.chat_send_player(player_name, "Node is protected")
+			minetest.record_protection_violation(pos_under, player_name)
+			return itemstack
+		end
+
+		minetest.set_node(pos_under, {name = "default:coral_green"})
+		if not (creative and creative.is_enabled_for(player_name)) then
+			itemstack:take_item()
+		end
+
+		return itemstack
+	end,
+	after_destruct  = function(pos, oldnode)
+		minetest.set_node(pos, {name = "default:coral_skeleton"})
+	end,
+})
+
+minetest.register_node("default:coral_pink", {
+	description = "Pink Coral",
+	drawtype = "plantlike_rooted",
+	waving = 1,
+	paramtype = "light",
+	tiles = {"default_coral_skeleton.png"},
+	special_tiles = {{name = "default_coral_pink.png", tileable_vertical = true}},
+	inventory_image = "default_coral_pink.png",
+	groups = {snappy = 3},
+	selection_box = {
+		type = "fixed",
+		fixed = {
+				{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+				{-4/16, 0.5, -4/16, 4/16, 1.5, 4/16},
+		},
+	},
+	node_dig_prediction = "default:coral_skeleton",
+	node_placement_prediction = "",
+	on_place = function(itemstack, placer, pointed_thing)
+		if pointed_thing.type ~= "node" or not placer then
+			return itemstack
+		end
+
+		local player_name = placer:get_player_name()
+		local pos_under = pointed_thing.under
+		local pos_above = pointed_thing.above
+
+		if minetest.get_node(pos_under).name ~= "default:coral_skeleton" or
+				minetest.get_node(pos_above).name ~= "default:water_source" then
+			return itemstack
+		end
+
+		if minetest.is_protected(pos_under, player_name) or
+				minetest.is_protected(pos_above, player_name) then
+			minetest.chat_send_player(player_name, "Node is protected")
+			minetest.record_protection_violation(pos_under, player_name)
+			return itemstack
+		end
+
+		minetest.set_node(pos_under, {name = "default:coral_pink"})
+		if not (creative and creative.is_enabled_for(player_name)) then
+			itemstack:take_item()
+		end
+
+		return itemstack
+	end,
+	after_destruct  = function(pos, oldnode)
+		minetest.set_node(pos, {name = "default:coral_skeleton"})
+	end,
+})
+
+minetest.register_node("default:coral_cyan", {
+	description = "Cyan Coral",
+	drawtype = "plantlike_rooted",
+	waving = 1,
+	paramtype = "light",
+	tiles = {"default_coral_skeleton.png"},
+	special_tiles = {{name = "default_coral_cyan.png", tileable_vertical = true}},
+	inventory_image = "default_coral_cyan.png",
+	groups = {snappy = 3},
+	selection_box = {
+		type = "fixed",
+		fixed = {
+				{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+				{-4/16, 0.5, -4/16, 4/16, 1.5, 4/16},
+		},
+	},
+	node_dig_prediction = "default:coral_skeleton",
+	node_placement_prediction = "",
+	on_place = function(itemstack, placer, pointed_thing)
+		if pointed_thing.type ~= "node" or not placer then
+			return itemstack
+		end
+
+		local player_name = placer:get_player_name()
+		local pos_under = pointed_thing.under
+		local pos_above = pointed_thing.above
+
+		if minetest.get_node(pos_under).name ~= "default:coral_skeleton" or
+				minetest.get_node(pos_above).name ~= "default:water_source" then
+			return itemstack
+		end
+
+		if minetest.is_protected(pos_under, player_name) or
+				minetest.is_protected(pos_above, player_name) then
+			minetest.chat_send_player(player_name, "Node is protected")
+			minetest.record_protection_violation(pos_under, player_name)
+			return itemstack
+		end
+
+		minetest.set_node(pos_under, {name = "default:coral_cyan"})
+		if not (creative and creative.is_enabled_for(player_name)) then
+			itemstack:take_item()
+		end
+
+		return itemstack
+	end,
+	after_destruct  = function(pos, oldnode)
+		minetest.set_node(pos, {name = "default:coral_skeleton"})
+	end,
+})
+
 minetest.register_node("default:coral_brown", {
 	description = "Brown Coral",
 	tiles = {"default_coral_brown.png"},
diff --git a/mods/default/schematics/corals.mts b/mods/default/schematics/corals.mts
deleted file mode 100644
index e1bd7ded6c202e4ca9f308164806f53117606728..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 171
zcmeYb3HD`RVPIuoW?-$aw+Awr6Elk#L{d`I5=(PRtdjGK5_95#L|%F-gD|RSQc-?+
z9)lRFU~zV8PHIVhUd5cXJr{Wy6gix^-`F!RE)@~k)9~+pchcpcMz;l}!mV5L=PU0m
z+!C7hHEZ`~<JjH*wgu@InW`nTG=8|U@qAm#h2XTRgr)P0o(HS_OJPhrr0EI(t$agN

diff --git a/mods/default/textures/default_coral_cyan.png b/mods/default/textures/default_coral_cyan.png
new file mode 100644
index 0000000000000000000000000000000000000000..11cc7bfda317e5084feb4176e4647b86eadc5872
GIT binary patch
literal 202
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPE^4e$wZ1=0-LwlPed%i!tBke<(=
zqQY?d_OD$9uYux>B|(0{3=Yq3qyag}o-U3d9M`9w+Q{3WAmV!Qdviqn)ClfEh6x4?
z9&0>1xFsI{Q}%esbnlfI`~Fw+^YsoNnIWn5amC4u3kSYCRx;)!FJVZM(qUQ5xVLx7
v#Km5#jRep6-p$+WE^swmP-ltGrUys3_a}4Z?d!Ht0y)al)z4*}Q$iB}a$824

literal 0
HcmV?d00001

diff --git a/mods/default/textures/default_coral_green.png b/mods/default/textures/default_coral_green.png
new file mode 100644
index 0000000000000000000000000000000000000000..847c57216ae5b2a4236309db7459619db1bef2a0
GIT binary patch
literal 287
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!Yk*IPE0AWm&A^b$5Ob1&p@Bj7
z5<}q;1_m<*ztap1lNcDR7%VO@FgP%zA7$v=&meT2LFW>K{W%8bvkYm+7#KPk7z`K~
zbQzLA{hACkhp{BcFPOpM*^M+Hr^D05F+}3Btskclvmy`I$FjR`@BX*nnvgbY1vAgV
z8Igv~=k^QftK2b{OJdsayzN{x@1{AAqIW7Sz1*>uL*VYW94$-ra|TO~$A^FV%o<sh
zl2WlwGAC8zP`5l^+4Vk|GP6*x#is&gellhiSc-o7S0^=@&0*cDm1oV`Rl1|juG!lB
f+U4xlFKj;<HTN-X@?W5=4)Up|tDnm{r-UW|NM2!G

literal 0
HcmV?d00001

diff --git a/mods/default/textures/default_coral_pink.png b/mods/default/textures/default_coral_pink.png
new file mode 100644
index 0000000000000000000000000000000000000000..62d70c6e8ac4881f0cf852583d06e51f8b0bd74e
GIT binary patch
literal 242
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHF3h)VW1=6<}CY@lYKcQMbiNW&{
zL+3g1)@=;AM-{5~^Os&@=shdka+b4YziQdhg|;?8)r=)Ue!&b5&u*jvIc1(Mjv*Y^
zMNgmQJmeta`mp%^gY%#KgbIGMNON#JGBV`t5WUeO8_^(pqgnLEMCJRhboi{U6|f&M
zI9|jip)Sj_;pNSxEN^B%WU@+(GZt|d5}mT?E1TsOi-n(qC-W-v$DaKE_o?1u|Lo~5
mai*ePdBtaWpWM6pjNQ0{hkeuQ<M)6rVDNPHb6Mw<&;$UssaV_q

literal 0
HcmV?d00001

diff --git a/schematic_tables.txt b/schematic_tables.txt
index 261dcf19..bd101e71 100644
--- a/schematic_tables.txt
+++ b/schematic_tables.txt
@@ -2083,44 +2083,6 @@ mts_save("papyrus", {
 })
 
 
--- Corals
-
-local C = {name = "default:coral_brown", prob = 255, force_place = true}
-local c = {name = "default:coral_brown", prob = 191, force_place = true}
-local O = {name = "default:coral_orange", prob = 255, force_place = true}
-local o = {name = "default:coral_orange", prob = 191, force_place = true}
-local X = {name = "default:coral_skeleton", prob = 255, force_place = true}
-local x = {name = "default:coral_skeleton", prob = 63, force_place = true}
-
-mts_save("corals", {
-	size = {x = 5, y = 3, z = 5},
-	data = {
-		_, _, _, _, _,
-		o, C, O, c, _,
-		_, C, x, _, _,
-
-		_, _, X, _, _,
-		C, O, O, C, o,
-		c, c, O, o, x,
-
-		_, X, X, X, _,
-		c, C, C, O, O,
-		O, C, O, C, c,
-
-		_, _, X, _, _,
-		x, O, C, O, C,
-		_, x, C, O, _,
-
-		_, _, _, _, _,
-		_, o, O, C, c,
-		_, _, o, _, _,
-	},
-	yslice_prob = {
-		{ypos = 2, prob = 127},
-	}
-})
-
-
 -- Bush
 
 local L = {name = "default:bush_leaves", prob = 255}