File tree 4 files changed +17
-3
lines changed
4 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ class LuaEntitySAO : public UnitSAO
42
42
void step (float dtime, bool send_recommended);
43
43
std::string getClientInitializationData (u16 protocol_version);
44
44
bool isStaticAllowed () const { return m_prop.static_save ; }
45
+ bool shouldUnload () const { return true ; }
45
46
void getStaticData (std::string *result) const ;
46
47
u16 punch (v3f dir, const ToolCapabilities *toolcap = nullptr ,
47
48
ServerActiveObject *puncher = nullptr ,
Original file line number Diff line number Diff line change @@ -83,6 +83,7 @@ class PlayerSAO : public UnitSAO
83
83
void addedToEnvironment (u32 dtime_s);
84
84
void removingFromEnvironment ();
85
85
bool isStaticAllowed () const { return false ; }
86
+ bool shouldUnload () const { return false ; }
86
87
std::string getClientInitializationData (u16 protocol_version);
87
88
void getStaticData (std::string *result) const ;
88
89
void step (float dtime, bool send_recommended);
Original file line number Diff line number Diff line change @@ -125,13 +125,22 @@ class ServerActiveObject : public ActiveObject
125
125
assert (isStaticAllowed ());
126
126
*result = " " ;
127
127
}
128
+
128
129
/*
129
130
Return false in here to never save and instead remove object
130
131
on unload. getStaticData() will not be called in that case.
131
132
*/
132
133
virtual bool isStaticAllowed () const
133
134
{return true ;}
134
135
136
+ /*
137
+ Return false here to never unload the object.
138
+ isStaticAllowed && shouldUnload -> unload when out of active block range
139
+ !isStaticAllowed && shouldUnload -> unload when block is unloaded
140
+ */
141
+ virtual bool shouldUnload () const
142
+ { return true ; }
143
+
135
144
// Returns tool wear
136
145
virtual u16 punch (v3f dir,
137
146
const ToolCapabilities *toolcap = nullptr ,
Original file line number Diff line number Diff line change @@ -1972,8 +1972,8 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
1972
1972
// force_delete might be overriden per object
1973
1973
bool force_delete = _force_delete;
1974
1974
1975
- // Do not deactivate if static data creation not allowed
1976
- if (!force_delete && !obj->isStaticAllowed ())
1975
+ // Do not deactivate if disallowed
1976
+ if (!force_delete && !obj->shouldUnload ())
1977
1977
return false ;
1978
1978
1979
1979
// removeRemovedObjects() is responsible for these
@@ -2002,7 +2002,10 @@ void ServerEnvironment::deactivateFarObjects(bool _force_delete)
2002
2002
}
2003
2003
2004
2004
// If block is still active, don't remove
2005
- if (!force_delete && m_active_blocks.contains (blockpos_o))
2005
+ bool still_active = obj->isStaticAllowed () ?
2006
+ m_active_blocks.contains (blockpos_o) :
2007
+ getMap ().getBlockNoCreateNoEx (blockpos_o) != nullptr ;
2008
+ if (!force_delete && still_active)
2006
2009
return false ;
2007
2010
2008
2011
verbosestream << " ServerEnvironment::deactivateFarObjects(): "
You can’t perform that action at this time.
0 commit comments