Skip to content

Commit cba90d4

Browse files
PilzAdamRealBadAngel
authored andcommittedJul 20, 2013
Make range of tools configureable
1 parent d19c8b8 commit cba90d4

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed
 

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,7 @@ Item definition (register_node, register_craftitem, register_tool)
18681868
wield_image = "",
18691869
wield_scale = {x=1,y=1,z=1},
18701870
stack_max = 99,
1871+
range = 4.0,
18711872
liquids_pointable = false,
18721873
tool_capabilities = {
18731874
full_punch_interval = 1.0,

‎src/game.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -2488,7 +2488,12 @@ void the_game(
24882488

24892489
//u32 t1 = device->getTimer()->getRealTime();
24902490

2491-
f32 d = 4; // max. distance
2491+
f32 d = playeritem_def.range; // max. distance
2492+
f32 d_hand = itemdef->get("").range;
2493+
if(d < 0 && d_hand >= 0)
2494+
d = d_hand;
2495+
else if(d < 0)
2496+
d = 4.0;
24922497
core::line3d<f32> shootline(camera_position,
24932498
camera_position + camera_direction * BS * (d+1));
24942499

‎src/itemdef.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
7676
groups = def.groups;
7777
node_placement_prediction = def.node_placement_prediction;
7878
sound_place = def.sound_place;
79+
range = def.range;
7980
return *this;
8081
}
8182

@@ -109,6 +110,7 @@ void ItemDefinition::reset()
109110
}
110111
groups.clear();
111112
sound_place = SimpleSoundSpec();
113+
range = -1;
112114

113115
node_placement_prediction = "";
114116
}
@@ -146,6 +148,7 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
146148
//serializeSimpleSoundSpec(sound_place, os);
147149
os<<serializeString(sound_place.name);
148150
writeF1000(os, sound_place.gain);
151+
writeF1000(os, range);
149152
}
150153
}
151154

@@ -198,7 +201,7 @@ void ItemDefinition::deSerialize(std::istream &is)
198201
// If you add anything here, insert it primarily inside the try-catch
199202
// block to not need to increase the version.
200203
try{
201-
204+
range = readF1000(is);
202205
}catch(SerializationError &e) {};
203206
}
204207

‎src/itemdef.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct ItemDefinition
6868
ToolCapabilities *tool_capabilities;
6969
ItemGroupList groups;
7070
SimpleSoundSpec sound_place;
71+
f32 range;
7172

7273
// Client shall immediately place this node when player places the item.
7374
// Server will update the precise end result a moment later.

‎src/script/common/c_content.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ ItemDefinition read_item_definition(lua_State* L,int index,
100100
}
101101
lua_pop(L, 1);
102102

103+
def.range = getfloatfield_default(L, index, "range", def.range);
104+
103105
// Client shall immediately place this node when player places the item.
104106
// Server will update the precise end result a moment later.
105107
// "" = no prediction

0 commit comments

Comments
 (0)
Please sign in to comment.