]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_abm.cpp
FIx wrong error message on invalid use of the formspec element image_button
[dragonfireclient.git] / src / content_abm.cpp
index 110ac1eea919d641591be89ff1635c4266f887bf..ada20a27c4471e530aced061403de14c63fdfb97 100644 (file)
@@ -28,7 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "treegen.h" // For treegen::make_tree
 #include "main.h" // for g_settings
 #include "map.h"
-#include "cpp_api/scriptapi.h"
+#include "scripting_game.h"
 #include "log.h"
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@@ -209,7 +209,7 @@ class LiquidDropABM : public ActiveBlockModifier {
                { return contents; }
                virtual std::set<std::string> getRequiredNeighbors() {
                        std::set<std::string> neighbors;
-                       neighbors.insert("mapgen_air");
+                       neighbors.insert("air");
                        return neighbors;
                }
                virtual float getTriggerInterval()
@@ -241,7 +241,7 @@ class LiquidFreeze : public ActiveBlockModifier {
                }
                virtual std::set<std::string> getRequiredNeighbors() {
                        std::set<std::string> s;
-                       s.insert("mapgen_air");
+                       s.insert("air");
                        s.insert("group:melts");
                        return s;
                }
@@ -253,13 +253,14 @@ class LiquidFreeze : public ActiveBlockModifier {
                        ServerMap *map = &env->getServerMap();
                        INodeDefManager *ndef = env->getGameDef()->ndef();
 
-                       float heat = map->getHeat(env, p);
+                       float heat = map->updateBlockHeat(env, p);
                        //heater = rare
-                       if (heat <= -1 && (heat <= -50 || ((myrand_range(-50, heat)) <= -30))) {
+                       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)
-                               content_t c;
                                bool allow = heat < -40;
                                // todo: make for(...)
                                if (!allow) {
@@ -285,7 +286,7 @@ class LiquidFreeze : public ActiveBlockModifier {
                                 }
                                }
                                if (allow) {
-                                       n.setContent(ndef->getId(ndef->get(n).freezemelt));
+                                       n.freezeMelt(ndef);
                                        map->addNodeWithEvent(p, n);
                                }
                        }
@@ -302,7 +303,7 @@ class LiquidMeltWeather : public ActiveBlockModifier {
                }
                virtual std::set<std::string> getRequiredNeighbors() {
                        std::set<std::string> s;
-                       s.insert("mapgen_air");
+                       s.insert("air");
                        s.insert("group:freezes");
                        return s;
                }
@@ -314,11 +315,10 @@ class LiquidMeltWeather : public ActiveBlockModifier {
                        ServerMap *map = &env->getServerMap();
                        INodeDefManager *ndef = env->getGameDef()->ndef();
 
-                       float heat = map->getHeat(env, p);
-                       if (heat >= 1 && (heat >= 40 || ((myrand_range(heat, 40)) >= 20))) {
-                               n.setContent(ndef->getId(ndef->get(n).freezemelt));
-                               if (!n.getLevel(ndef))
-                                       n.addLevel(ndef);
+                       float heat = map->updateBlockHeat(env, p);
+                       content_t c = map->getNodeNoEx(p - v3s16(0,  -1, 0 )).getContent(); // top
+                       if (heat >= 1 && (heat >= 40 || ((myrand_range(heat, 40)) >= (c == CONTENT_AIR ? 10 : 20)))) {
+                               n.freezeMelt(ndef);
                                map->addNodeWithEvent(p, n);
                                env->getScriptIface()->node_falling_update(p);
                        }
@@ -346,14 +346,13 @@ class LiquidMeltHot : public ActiveBlockModifier {
                virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
                        ServerMap *map = &env->getServerMap();
                        INodeDefManager *ndef = env->getGameDef()->ndef();
-                       n.setContent(ndef->getId(ndef->get(n).freezemelt));
-                       if (!n.getLevel(ndef))
-                               n.addLevel(ndef);
+                       n.freezeMelt(ndef);
                        map->addNodeWithEvent(p, n);
                        env->getScriptIface()->node_falling_update(p);
                }
 };
 
+/* too buggy, later via liquid flow code
 class LiquidMeltAround : public LiquidMeltHot {
        public:
                LiquidMeltAround(ServerEnvironment *env, INodeDefManager *nodemgr) 
@@ -368,7 +367,7 @@ class LiquidMeltAround : public LiquidMeltHot {
                virtual u32 getTriggerChance()
                { return 60; }
 };
-
+*/
 
 void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
        env->addActiveBlockModifier(new GrowGrassABM());
@@ -378,8 +377,8 @@ void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
                env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
                env->addActiveBlockModifier(new LiquidDropABM(env, nodedef));
                env->addActiveBlockModifier(new LiquidMeltHot(env, nodedef));
-               env->addActiveBlockModifier(new LiquidMeltAround(env, nodedef));
-               if (g_settings->getBool("weather")) {
+               //env->addActiveBlockModifier(new LiquidMeltAround(env, nodedef));
+               if (env->m_use_weather) {
                        env->addActiveBlockModifier(new LiquidFreeze(env, nodedef));
                        env->addActiveBlockModifier(new LiquidMeltWeather(env, nodedef));
                }