-class MakeTreesFromSaplingsABM : public ActiveBlockModifier
-{
-private:
-public:
- virtual std::set<std::string> getTriggerContents()
- {
- std::set<std::string> s;
- s.insert("sapling");
- return s;
- }
- virtual float getTriggerInterval()
- { return 10.0; }
- virtual u32 getTriggerChance()
- { return 50; }
- virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n,
- u32 active_object_count, u32 active_object_count_wider)
- {
- INodeDefManager *ndef = env->getGameDef()->ndef();
- ServerMap *map = &env->getServerMap();
-
- actionstream<<"A sapling grows into a tree at "
- <<PP(p)<<std::endl;
-
- core::map<v3s16, MapBlock*> modified_blocks;
- v3s16 tree_p = p;
- ManualMapVoxelManipulator vmanip(map);
- v3s16 tree_blockp = getNodeBlockPos(tree_p);
- vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1));
- bool is_apple_tree = myrand()%4 == 0;
- treegen::make_tree(vmanip, tree_p, is_apple_tree, ndef, myrand());
- vmanip.blitBackAll(&modified_blocks);
-
- // update lighting
- core::map<v3s16, MapBlock*> lighting_modified_blocks;
- for(core::map<v3s16, MapBlock*>::Iterator
- i = modified_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- lighting_modified_blocks.insert(i.getNode()->getKey(), i.getNode()->getValue());
- }
- map->updateLighting(lighting_modified_blocks, modified_blocks);
-
- // Send a MEET_OTHER event
- MapEditEvent event;
- event.type = MEET_OTHER;
- for(core::map<v3s16, MapBlock*>::Iterator
- i = modified_blocks.getIterator();
- i.atEnd() == false; i++)
- {
- v3s16 p = i.getNode()->getKey();
- event.modified_blocks.insert(p, true);
- }
- map->dispatchEvent(&event);
- }
+class LiquidFreeze : public ActiveBlockModifier {
+ public:
+ LiquidFreeze(ServerEnvironment *env, INodeDefManager *nodemgr) { }
+ virtual std::set<std::string> getTriggerContents() {
+ std::set<std::string> s;
+ s.insert("group:freezes");
+ return s;
+ }
+ virtual std::set<std::string> getRequiredNeighbors() {
+ std::set<std::string> s;
+ s.insert("air");
+ s.insert("group:melts");
+ return s;
+ }
+ virtual float getTriggerInterval()
+ { return 10.0; }
+ virtual u32 getTriggerChance()
+ { return 20; }
+ virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
+ ServerMap *map = &env->getServerMap();
+ INodeDefManager *ndef = env->getGameDef()->ndef();
+
+ float heat = map->updateBlockHeat(env, p);
+ //heater = rare
+ content_t c = map->getNodeNoEx(p - v3s16(0, -1, 0 )).getContent(); // top
+ //more chance to freeze if air at top
+ if (heat <= -1 && (heat <= -50 || (myrand_range(-50, heat) <= (c == CONTENT_AIR ? -10 : -40)))) {
+ content_t c_self = n.getContent();
+ // making freeze not annoying, do not freeze random blocks in center of ocean
+ // todo: any block not water (dont freeze _source near _flowing)
+ bool allow = heat < -40;
+ // todo: make for(...)
+ if (!allow) {
+ c = map->getNodeNoEx(p - v3s16(0, 1, 0 )).getContent(); // below
+ if (c == CONTENT_AIR || c == CONTENT_IGNORE)
+ return; // do not freeze when falling
+ if (c != c_self && c != CONTENT_IGNORE) allow = 1;
+ if (!allow) {
+ c = map->getNodeNoEx(p - v3s16(1, 0, 0 )).getContent(); // right
+ if (c != c_self && c != CONTENT_IGNORE) allow = 1;
+ if (!allow) {
+ c = map->getNodeNoEx(p - v3s16(-1, 0, 0 )).getContent(); // left
+ if (c != c_self && c != CONTENT_IGNORE) allow = 1;
+ if (!allow) {
+ c = map->getNodeNoEx(p - v3s16(0, 0, 1 )).getContent(); // back
+ if (c != c_self && c != CONTENT_IGNORE) allow = 1;
+ if (!allow) {
+ c = map->getNodeNoEx(p - v3s16(0, 0, -1)).getContent(); // front
+ if (c != c_self && c != CONTENT_IGNORE) allow = 1;
+ }
+ }
+ }
+ }
+ }
+ if (allow) {
+ n.freezeMelt(ndef);
+ map->addNodeWithEvent(p, n);
+ }
+ }
+ }