mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
Refactor CSM restriction code a bit
This also fixes find_node_near restrictions being ineffective.
This commit is contained in:
parent
4d668f32a6
commit
b0260b5ec8
4 changed files with 27 additions and 32 deletions
|
@ -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()");
|
||||
|
|
|
@ -261,14 +261,10 @@ public:
|
|||
// Causes urgent mesh updates (unlike Map::add/removeNodeWithEvent)
|
||||
void removeNode(v3s16 p);
|
||||
|
||||
/**
|
||||
* Helper function for Client Side Modding
|
||||
* CSM restrictions are applied there, this should not be used for core engine
|
||||
* @param p
|
||||
* @param is_valid_position
|
||||
* @return
|
||||
*/
|
||||
MapNode getNode(v3s16 p, bool *is_valid_position);
|
||||
// helpers to enforce CSM restrictions
|
||||
MapNode CSMGetNode(v3s16 p, bool *is_valid_position);
|
||||
int CSMClampRadius(v3s16 pos, int radius);
|
||||
|
||||
void addNode(v3s16 p, MapNode n, bool remove_metadata = true);
|
||||
|
||||
void setPlayerControl(PlayerControl &control);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue