summaryrefslogtreecommitdiff
path: root/src/client/client.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2019-11-08 22:57:03 +0100
committersfan5 <sfan5@live.de>2019-11-11 14:06:48 +0100
commitb0260b5ec8e05e54928f9487bb39b4ff946951f9 (patch)
treed5e8c2e1c43507549da008dbac2eeba1d6ab059b /src/client/client.cpp
parent4d668f32a6d9a0d895a2385dec994d43bd084410 (diff)
downloadminetest-b0260b5ec8e05e54928f9487bb39b4ff946951f9.tar.gz
minetest-b0260b5ec8e05e54928f9487bb39b4ff946951f9.tar.bz2
minetest-b0260b5ec8e05e54928f9487bb39b4ff946951f9.zip
Refactor CSM restriction code a bit
This also fixes find_node_near restrictions being ineffective.
Diffstat (limited to 'src/client/client.cpp')
-rw-r--r--src/client/client.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 0908e52f9..89873ade3 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -1313,7 +1313,7 @@ void Client::removeNode(v3s16 p)
* @param is_valid_position
* @return
*/
-MapNode Client::getNode(v3s16 p, bool *is_valid_position)
+MapNode Client::CSMGetNode(v3s16 p, bool *is_valid_position)
{
if (checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) {
v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS);
@@ -1325,6 +1325,18 @@ MapNode Client::getNode(v3s16 p, bool *is_valid_position)
return m_env.getMap().getNode(p, is_valid_position);
}
+int Client::CSMClampRadius(v3s16 pos, int radius)
+{
+ if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES))
+ return radius;
+ // This is approximate and will cause some allowed nodes to be excluded
+ v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS);
+ u32 distance = ppos.getDistanceFrom(pos);
+ if (distance >= m_csm_restriction_noderange)
+ return 0;
+ return std::min<int>(radius, m_csm_restriction_noderange - distance);
+}
+
void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
{
//TimeTaker timer1("Client::addNode()");