Disable placement prediction for nodes that use on_rightclick
authorJeija <norrepli@gmail.com>
Sun, 27 Jan 2013 09:33:25 +0000 (10:33 +0100)
committerPilzAdam <PilzAdam@gmx.de>
Tue, 19 Feb 2013 19:02:40 +0000 (20:02 +0100)
src/game.cpp
src/itemdef.cpp
src/itemdef.h
src/nodedef.cpp
src/nodedef.h
src/scriptapi.cpp

index 5693c5c1275114302087c85b7020df96938efd45..c77754b5fddb0ec0c83ee3564f52ec7ca0ceec3e 100644 (file)
@@ -2531,7 +2531,8 @@ void the_game(
                                        // make that happen
                                        const ItemDefinition &def =
                                                        playeritem.getDefinition(itemdef);
-                                       if(def.node_placement_prediction != "")
+                                       if(def.node_placement_prediction != ""
+                                                       && !nodedef->get(map.getNode(nodepos)).rightclickable)
                                        do{ // breakable
                                                verbosestream<<"Node placement prediction for "
                                                                <<playeritem.name<<" is "
index 260baadc0ff67bdabd35cec29ebf528b5431bdee..a4f3895e018ac04c4a17899292d6988a764fc07a 100644 (file)
@@ -100,6 +100,7 @@ void ItemDefinition::reset()
        wield_scale = v3f(1.0, 1.0, 1.0);
        stack_max = 99;
        usable = false;
+       rightclickable = false;
        liquids_pointable = false;
        if(tool_capabilities)
        {
index 699d727bde4a60334073f854b64aa6717d413322..ae36008687737ee0ceb1e5af9c7509bc81a9a919 100644 (file)
@@ -62,6 +62,8 @@ struct ItemDefinition
        */
        s16 stack_max;
        bool usable;
+       // If true, don't use node placement prediction
+       bool rightclickable;
        bool liquids_pointable;
        // May be NULL. If non-NULL, deleted by destructor
        ToolCapabilities *tool_capabilities;
index 729c69c9273e9739a5188df5c33658c3f17a0170..12d9238ad877d43dba8aa095b9fe11e2f3cd01fb 100644 (file)
@@ -199,6 +199,7 @@ void ContentFeatures::reset()
        diggable = true;
        climbable = false;
        buildable_to = false;
+       rightclickable = true;
        liquid_type = LIQUID_NONE;
        liquid_alternative_flowing = "";
        liquid_alternative_source = "";
@@ -271,6 +272,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
        serializeSimpleSoundSpec(sound_dug, os);
        // Stuff below should be moved to correct place in a version that otherwise changes
        // the protocol version
+       writeU8(os, rightclickable);
 }
 
 void ContentFeatures::deSerialize(std::istream &is)
@@ -334,6 +336,7 @@ void ContentFeatures::deSerialize(std::istream &is)
        try{
                // Stuff below should be moved to correct place in a version that
                // otherwise changes the protocol version
+               rightclickable = readU8(is);
        }catch(SerializationError &e) {};
 }
 
index 8588caeabfe2eefba69c4be9d337b06d9433792d..fa0c1f2e848bf7d3b5fcf5e80c9ef57e96dd504d 100644 (file)
@@ -199,6 +199,8 @@ struct ContentFeatures
        bool climbable;
        // Player can build on these
        bool buildable_to;
+       // Player cannot build to these (placement prediction disabled)
+       bool rightclickable;
        // Whether the node is non-liquid, source liquid or flowing liquid
        enum LiquidType liquid_type;
        // If the content is liquid, this is the flowing version of the liquid.
index 020709cab1cf9966db99710108d9effb0fca6000..66654813e3c905642747d946c0fbc65fa8a3c08f 100644 (file)
@@ -1063,6 +1063,10 @@ static ItemDefinition read_item_definition(lua_State *L, int index,
        def.usable = lua_isfunction(L, -1);
        lua_pop(L, 1);
 
+       lua_getfield(L, index, "on_rightclick");
+       def.rightclickable = lua_isfunction(L, -1);
+       lua_pop(L, 1);
+
        getboolfield(L, index, "liquids_pointable", def.liquids_pointable);
 
        warn_if_field_exists(L, index, "tool_digging_properties",
@@ -4746,7 +4750,7 @@ static int l_register_item_raw(lua_State *L)
        // Default to having client-side placement prediction for nodes
        // ("" in item definition sets it off)
        if(def.node_placement_prediction == "__default"){
-               if(def.type == ITEM_NODE)
+               if(def.type == ITEM_NODE && !def.rightclickable)
                        def.node_placement_prediction = name;
                else
                        def.node_placement_prediction = "";