Make range of tools configureable
authorPilzAdam <pilzadam@minetest.net>
Sat, 20 Jul 2013 12:50:19 +0000 (14:50 +0200)
committerRealBadAngel <mk@realbadangel.pl>
Sat, 20 Jul 2013 18:37:59 +0000 (20:37 +0200)
doc/lua_api.txt
src/game.cpp
src/itemdef.cpp
src/itemdef.h
src/script/common/c_content.cpp

index 6a4d198386aa149df60b246975ed19e6c5d230dd..891a807c524c5e02916e7632b7f55648085ff0a9 100644 (file)
@@ -1868,6 +1868,7 @@ Item definition (register_node, register_craftitem, register_tool)
     wield_image = "",
     wield_scale = {x=1,y=1,z=1},
     stack_max = 99,
+    range = 4.0,
     liquids_pointable = false,
     tool_capabilities = {
         full_punch_interval = 1.0,
index ff694d12e7cac8d97c79eecf143520d6b38e1c5d..3f14f09d42403ac4c6df666e9898d70ac312e66a 100644 (file)
@@ -2488,7 +2488,12 @@ void the_game(
                
                //u32 t1 = device->getTimer()->getRealTime();
                
-               f32 d = 4; // max. distance
+               f32 d = playeritem_def.range; // max. distance
+               f32 d_hand = itemdef->get("").range;
+               if(d < 0 && d_hand >= 0)
+                       d = d_hand;
+               else if(d < 0)
+                       d = 4.0;
                core::line3d<f32> shootline(camera_position,
                                camera_position + camera_direction * BS * (d+1));
 
index e7498ce55de580dbd4fcb7f95d717c01457284b8..4ac23d0fc86e056caa0d3b7daf19891fb1e69e6f 100644 (file)
@@ -76,6 +76,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
        groups = def.groups;
        node_placement_prediction = def.node_placement_prediction;
        sound_place = def.sound_place;
+       range = def.range;
        return *this;
 }
 
@@ -109,6 +110,7 @@ void ItemDefinition::reset()
        }
        groups.clear();
        sound_place = SimpleSoundSpec();
+       range = -1;
 
        node_placement_prediction = "";
 }
@@ -146,6 +148,7 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
                //serializeSimpleSoundSpec(sound_place, os);
                os<<serializeString(sound_place.name);
                writeF1000(os, sound_place.gain);
+               writeF1000(os, range);
        }
 }
 
@@ -198,7 +201,7 @@ void ItemDefinition::deSerialize(std::istream &is)
        // If you add anything here, insert it primarily inside the try-catch
        // block to not need to increase the version.
        try{
-               
+               range = readF1000(is);
        }catch(SerializationError &e) {};
 }
 
index 08c9c835870b111254f8e43a5dbebb520e78d94f..f993fdbac490181ab7627ea00f680e91f145bb4e 100644 (file)
@@ -68,6 +68,7 @@ struct ItemDefinition
        ToolCapabilities *tool_capabilities;
        ItemGroupList groups;
        SimpleSoundSpec sound_place;
+       f32 range;
 
        // Client shall immediately place this node when player places the item.
        // Server will update the precise end result a moment later.
index 11f74916013960a12ac2ad273d50bf4880d4fb4a..7b80cc5ee9086c0a9c87a14002bd6ab5fa7dfd45 100644 (file)
@@ -100,6 +100,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
        }
        lua_pop(L, 1);
 
+       def.range = getfloatfield_default(L, index, "range", def.range);
+
        // Client shall immediately place this node when player places the item.
        // Server will update the precise end result a moment later.
        // "" = no prediction