From 289e31ed981371fa05bd02488e38e2d0f0f5effe Mon Sep 17 00:00:00 2001
From: Nils Dagsson Moskopp <nils@dieweltistgarnichtso.net>
Date: Mon, 30 May 2011 14:42:08 +0200
Subject: [PATCH] + cactii

---
 data/cactus_side.png | Bin 0 -> 279 bytes
 data/cactus_top.png  | Bin 0 -> 236 bytes
 src/map.cpp          |  34 +++++++++++++++++++++++++++-------
 src/mapnode.cpp      |  10 ++++++++++
 src/mapnode.h        |   1 +
 src/materials.cpp    |   1 +
 src/server.cpp       |   1 +
 src/tile.cpp         |   2 ++
 8 files changed, 42 insertions(+), 7 deletions(-)
 create mode 100644 data/cactus_side.png
 create mode 100644 data/cactus_top.png

diff --git a/data/cactus_side.png b/data/cactus_side.png
new file mode 100644
index 0000000000000000000000000000000000000000..fc479fde6f9dc859180035ee3974c1ffb198136c
GIT binary patch
literal 279
zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`$AH
z5n0T@z%2~Ij105pNH8!ku$OrHy0YJ9m0?t7cjsOCj)8$;rKgKyh{frt!3TMn4LOv<
zt|(f$KYJm;Gu1G!@61I-zvXf9AtI9No{A>2A9uKQq3#}g%hBS!DoL~7eVVbIpO1e-
zN9FFEMpJ&S4cr@V%xX`_@DE*EvCM7@w^pe3xi^t~6Azp?Gw-PY=RX-;gYE<s<sbik
zOt0*Id*8OhV%5y_hm|X4rG8tL>a;Y)_QbR|*~0Z(1wU@;{P#G;;;&D5@)xn$9dl-$
gx+-CQ_bKnr;Ov7pP6=;iU|?YIboFyt=akR{0GtPEZ2$lO

literal 0
HcmV?d00001

diff --git a/data/cactus_top.png b/data/cactus_top.png
new file mode 100644
index 0000000000000000000000000000000000000000..f9e68df5114b04f48290dc277b9d73f49db941cc
GIT binary patch
literal 236
zcmeAS@N?(olHy`uVBq!ia0y~yU=RRd4mJh`2Kmqb6B!s77>k44ofy`glX=O&z`$AH
z5n0T@z%2~Ij105pNH8!ku$OrHy0YJ9m0^@LT~(|m&cMJ>=jq}YVsUzH@Ik=?3LM>)
z7W0xzG>*Th_<JKfTF>3J>giGrP8W@}*Be{j-fq11y7swOlj&?82G#=s>Bm-_JSD-j
z;_&KY%zJCTFfH1*wm;5cNvG<Mc$d^pm#5L0;sq*N`~Ns(2`Sg^IAl?+e={}6pz6fx
l$9Jk~8FJQd{(Ipw=id}(N$YE^aSRL$44$rjF6*2UngC7{RI&g7

literal 0
HcmV?d00001

diff --git a/src/map.cpp b/src/map.cpp
index a49de3c46..c48599d47 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -2045,6 +2045,20 @@ void make_tree(VoxelManipulator &vmanip, v3s16 p0)
 	}
 }
 
+void make_cactus(VoxelManipulator &vmanip, v3s16 p0)
+{
+	MapNode cactusnode(CONTENT_CACTUS);
+
+	s16 trunk_h = 3;
+	v3s16 p1 = p0;
+	for(s16 ii=0; ii<trunk_h; ii++)
+	{
+		if(vmanip.m_area.contains(p1))
+			vmanip.m_data[vmanip.m_area.index(p1)] = cactusnode;
+		p1.Y++;
+	}
+}
+
 /*
 	Noise functions. Make sure seed is mangled differently in each one.
 */
@@ -3207,18 +3221,24 @@ void makeChunk(ChunkMakeData *data)
 				if(y > y_nodes_max - 6)
 					continue;
 				v3s16 p(x,y,z);
-				/*
-					Trees grow only on mud and grass
-				*/
 				{
 					u32 i = data->vmanip.m_area.index(v3s16(p));
 					MapNode *n = &data->vmanip.m_data[i];
-					if(n->d != CONTENT_MUD && n->d != CONTENT_GRASS)
+					if(n->d != CONTENT_MUD && n->d != CONTENT_GRASS && n->d != CONTENT_SAND)
 						continue;
+					// Trees grow only on mud and grass
+					if(n->d == CONTENT_MUD || n->d == CONTENT_GRASS)
+					{
+						p.Y++;
+						make_tree(data->vmanip, p);
+					}
+					// Cactii grow only on sand
+					if(n->d == CONTENT_SAND)
+					{
+						p.Y++;
+						make_cactus(data->vmanip, p);
+					}
 				}
-				p.Y++;
-				// Make a tree
-				make_tree(data->vmanip, p);
 			}
 		}
 		/*u32 tree_max = relative_area / 60;
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index c006b8222..8ceeecfba 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -215,6 +215,16 @@ void init_mapnode()
 	}
 	f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
 
+	i = CONTENT_CACTUS;
+	f = &g_content_features[i];
+	f->setAllTextures("cactus_side.png");
+	f->setTexture(0, "cactus_top.png");
+	f->setTexture(1, "cactus_top.png");
+	f->setInventoryTextureCube("cactus_top.png", "cactus_side.png", "cactus_side.png");
+	f->param_type = CPT_MINERAL;
+	f->is_ground_content = true;
+	f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
+
 	i = CONTENT_GLASS;
 	f = &g_content_features[i];
 	f->light_propagates = true;
diff --git a/src/mapnode.h b/src/mapnode.h
index ad256585f..c4dcbfbe5 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -102,6 +102,7 @@ void init_content_inventory_texture_paths();
 #define CONTENT_GLASS 20
 #define CONTENT_FENCE 21
 #define CONTENT_SANDSTONE 22
+#define CONTENT_CACTUS 23
 
 /*
 	Content feature list
diff --git a/src/materials.cpp b/src/materials.cpp
index 60c1894bf..a1d419562 100644
--- a/src/materials.cpp
+++ b/src/materials.cpp
@@ -73,6 +73,7 @@ void initializeMaterialProperties()
 	
 	setWoodLikeDiggingProperties(CONTENT_TREE, 1.0);
 	setWoodLikeDiggingProperties(CONTENT_LEAVES, 0.15);
+	setWoodLikeDiggingProperties(CONTENT_CACTUS, 0.75);
 	setWoodLikeDiggingProperties(CONTENT_GLASS, 0.15);
 	setWoodLikeDiggingProperties(CONTENT_FENCE, 0.75);
 	setWoodLikeDiggingProperties(CONTENT_WOOD, 0.75);
diff --git a/src/server.cpp b/src/server.cpp
index c7b64f413..994e62eaf 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -4078,6 +4078,7 @@ void setCreativeInventory(Player *player)
 		CONTENT_SANDSTONE,
 		CONTENT_TREE,
 		CONTENT_LEAVES,
+		CONTENT_CACTUS,
 		CONTENT_GLASS,
 		CONTENT_FENCE,
 		CONTENT_MESE,
diff --git a/src/tile.cpp b/src/tile.cpp
index 8b0c3f2ea..2a2d2a70c 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -513,6 +513,8 @@ void TextureSource::buildMainAtlas()
 	sourcelist.push_back("tree_top.png");
 	sourcelist.push_back("water.png");
 	sourcelist.push_back("leaves.png");
+	sourcelist.push_back("cactus_side.png");
+	sourcelist.push_back("cactus_top.png");
 	sourcelist.push_back("glass.png");
 	sourcelist.push_back("mud.png^grass_side.png");
 	sourcelist.push_back("cobble.png");
-- 
GitLab