Skip to content

Commit

Permalink
Make range of tools configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
PilzAdam authored and RealBadAngel committed Jul 20, 2013
1 parent d19c8b8 commit cba90d4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/lua_api.txt
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/game.cpp
Expand Up @@ -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));

Expand Down
5 changes: 4 additions & 1 deletion src/itemdef.cpp
Expand Up @@ -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;
}

Expand Down Expand Up @@ -109,6 +110,7 @@ void ItemDefinition::reset()
}
groups.clear();
sound_place = SimpleSoundSpec();
range = -1;

node_placement_prediction = "";
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {};
}

Expand Down
1 change: 1 addition & 0 deletions src/itemdef.h
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/script/common/c_content.cpp
Expand Up @@ -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
Expand Down

0 comments on commit cba90d4

Please sign in to comment.