Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 1 contributor
Nov 16, 2011
Mark Holmquist + leaf decay 9ee3068
Mark Holmquist + falling saplings (from decaying leaves)
* modified sapling-growing so it only grows with mud (or grass) and enough space
04f6a15

Showing 1 changed file with 113 additions and 29 deletions. Show diff stats Hide diff stats

  1. +113 29 src/environment.cpp
142 src/environment.cpp
@@ -1099,39 +1099,123 @@ void ServerEnvironment::step(float dtime)
1099 1099 {
1100 1100 if(myrand()%50 == 0)
1101 1101 {
1102   - actionstream<<"A sapling grows into a tree at "
1103   - <<PP(p)<<std::endl;
1104   -
1105   - core::map<v3s16, MapBlock*> modified_blocks;
1106   - v3s16 tree_p = p;
1107   - ManualMapVoxelManipulator vmanip(m_map);
1108   - v3s16 tree_blockp = getNodeBlockPos(tree_p);
1109   - vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1));
1110   - bool is_apple_tree = myrand()%4 == 0;
1111   - mapgen::make_tree(vmanip, tree_p, is_apple_tree);
1112   - vmanip.blitBackAll(&modified_blocks);
1113   -
1114   - // update lighting
1115   - core::map<v3s16, MapBlock*> lighting_modified_blocks;
1116   - for(core::map<v3s16, MapBlock*>::Iterator
1117   - i = modified_blocks.getIterator();
1118   - i.atEnd() == false; i++)
  1102 + s16 max_y = 7;
  1103 + s16 max_o = 2;
  1104 + bool grow = true;
  1105 + content_t below = m_map->getNodeNoEx(p+v3s16(0,-1,0)).getContent();
  1106 + if (below != CONTENT_MUD && below != CONTENT_GRASS)
  1107 + grow = false;
  1108 + for (s16 y=1; grow && y < 2; y++) {
  1109 + v3s16 test_p = p+v3s16(0,y,0);
  1110 + }
  1111 + for (s16 z=-max_o; grow && z < max_o; z++) {
  1112 + for (s16 y=2; grow && y < max_y; y++) {
  1113 + for (s16 x=-max_o; grow && x < max_o; x++) {
  1114 + v3s16 test_p = p + v3s16(x,y,z);
  1115 + if (test_p != p) {
  1116 + content_t tcon = m_map->getNodeNoEx(test_p).getContent();
  1117 + if (tcon != CONTENT_AIR && tcon != CONTENT_IGNORE) {
  1118 + grow = false;
  1119 + }
  1120 + }
  1121 + }
  1122 + }
  1123 + }
  1124 +
  1125 + if (grow) {
  1126 + actionstream<<"A sapling grows into a tree at "
  1127 + <<PP(p)<<std::endl;
  1128 +
  1129 + core::map<v3s16, MapBlock*> modified_blocks;
  1130 + v3s16 tree_p = p;
  1131 + ManualMapVoxelManipulator vmanip(m_map);
  1132 + v3s16 tree_blockp = getNodeBlockPos(tree_p);
  1133 + vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1));
  1134 + bool is_apple_tree = myrand()%4 == 0;
  1135 + mapgen::make_tree(vmanip, tree_p, is_apple_tree);
  1136 + vmanip.blitBackAll(&modified_blocks);
  1137 +
  1138 + // update lighting
  1139 + core::map<v3s16, MapBlock*> lighting_modified_blocks;
  1140 + for(core::map<v3s16, MapBlock*>::Iterator
  1141 + i = modified_blocks.getIterator();
  1142 + i.atEnd() == false; i++)
  1143 + {
  1144 + lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
  1145 + }
  1146 + m_map->updateLighting(lighting_modified_blocks, modified_blocks);
  1147 +
  1148 + // Send a MEET_OTHER event
  1149 + MapEditEvent event;
  1150 + event.type = MEET_OTHER;
  1151 + for(core::map<v3s16, MapBlock*>::Iterator
  1152 + i = modified_blocks.getIterator();
  1153 + i.atEnd() == false; i++)
  1154 + {
  1155 + v3s16 p = i.getNode()->getKey();
  1156 + event.modified_blocks.insert(p, true);
  1157 + }
  1158 + m_map->dispatchEvent(&event);
  1159 + }
  1160 + }
  1161 + }
  1162 + if (n.getContent() == CONTENT_LEAVES) // leaf decay
  1163 + {
  1164 + if (myrand()%50 == 0)
  1165 + {
  1166 + s16 max_d = 3;
  1167 + v3s16 leaf_p = p;
  1168 + v3s16 test_p;
  1169 + MapNode treenode(CONTENT_TREE);
  1170 + MapNode airnode(CONTENT_AIR);
  1171 + MapNode jungnode(CONTENT_JUNGLETREE);
  1172 + MapNode testnode;
  1173 + bool found = false;
  1174 + for(s16 z=-max_d; z<=max_d; z++) {
  1175 + for(s16 y=-max_d; y<=max_d; y++) {
  1176 + for(s16 x=-max_d; x<=max_d; x++)
1119 1177 {
1120   - lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
  1178 + test_p = leaf_p + v3s16(x,y,z);
  1179 + testnode = m_map->getNodeNoEx(test_p);
  1180 + if (testnode.getContent() == treenode.getContent() ||
  1181 + testnode.getContent() == jungnode.getContent())
  1182 + {
  1183 + found = true;
  1184 + break;
  1185 + }
  1186 + }
  1187 + if (found)
  1188 + break;
1121 1189 }
1122   - m_map->updateLighting(lighting_modified_blocks, modified_blocks);
1123   -
1124   - // Send a MEET_OTHER event
1125   - MapEditEvent event;
1126   - event.type = MEET_OTHER;
1127   - for(core::map<v3s16, MapBlock*>::Iterator
1128   - i = modified_blocks.getIterator();
1129   - i.atEnd() == false; i++)
  1190 + if (found)
  1191 + break;
  1192 + }
  1193 + if (!found)
1130 1194 {
1131   - v3s16 p = i.getNode()->getKey();
1132   - event.modified_blocks.insert(p, true);
  1195 + m_map->removeNodeWithEvent(leaf_p);
  1196 + if (myrand()%20 == 0) {
  1197 + max_d = 7;
  1198 + s16 y;
  1199 + for (y=1; y<=max_d; y++) {
  1200 + test_p = leaf_p - v3s16(0,y,0);
  1201 + testnode = m_map->getNodeNoEx(test_p);
  1202 + if (testnode.getContent() == CONTENT_MUD ||
  1203 + testnode.getContent() == CONTENT_GRASS) {
  1204 + y--;
  1205 + break;
  1206 + }
  1207 + else if (testnode.getContent() != airnode.getContent()) {
  1208 + y = max_d;
  1209 + break;
  1210 + }
  1211 + }
  1212 + if (y != max_d) {
  1213 + actionstream<<"A sapling drops at "
  1214 + <<PP(p)<<std::endl;
  1215 + m_map->addNodeWithEvent(leaf_p-v3s16(0,y,0), MapNode(CONTENT_SAPLING));
  1216 + }
  1217 + }
1133 1218 }
1134   - m_map->dispatchEvent(&event);
1135 1219 }
1136 1220 }
1137 1221 }

No commit comments for this range

Something went wrong with that request. Please try again.