mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Add minetest.clear_registered_decorations() and clear_registered_ores()
This commit is contained in:
parent
cec141adc1
commit
cf8213ea82
@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "mapgen.h"
|
||||
#include "voxel.h"
|
||||
#include "noise.h"
|
||||
#include "gamedef.h"
|
||||
#include "mg_biome.h"
|
||||
#include "mapblock.h"
|
||||
#include "mapnode.h"
|
||||
@ -381,6 +382,12 @@ void GenerateNotifier::getEvents(
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
GenElementManager::GenElementManager(IGameDef *gamedef)
|
||||
{
|
||||
m_resolver = gamedef->getNodeDefManager()->getResolver();
|
||||
}
|
||||
|
||||
|
||||
GenElementManager::~GenElementManager()
|
||||
{
|
||||
for (size_t i = 0; i != m_elements.size(); i++)
|
||||
|
@ -178,7 +178,7 @@ public:
|
||||
static const char *ELEMENT_TITLE;
|
||||
static const size_t ELEMENT_LIMIT = -1;
|
||||
|
||||
GenElementManager() {}
|
||||
GenElementManager(IGameDef *gamedef);
|
||||
virtual ~GenElementManager();
|
||||
|
||||
virtual GenElement *create(int type) = 0;
|
||||
@ -192,6 +192,7 @@ public:
|
||||
virtual GenElement *getByName(const std::string &name);
|
||||
|
||||
protected:
|
||||
NodeResolver *m_resolver;
|
||||
std::vector<GenElement *> m_elements;
|
||||
};
|
||||
|
||||
|
@ -32,10 +32,9 @@ const char *BiomeManager::ELEMENT_TITLE = "biome";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BiomeManager::BiomeManager(IGameDef *gamedef)
|
||||
BiomeManager::BiomeManager(IGameDef *gamedef) :
|
||||
GenElementManager(gamedef)
|
||||
{
|
||||
m_resolver = gamedef->getNodeDefManager()->getResolver();
|
||||
|
||||
// Create default biome to be used in case none exist
|
||||
Biome *b = new Biome;
|
||||
|
||||
|
@ -71,9 +71,6 @@ public:
|
||||
void calcBiomes(s16 sx, s16 sy, float *heat_map, float *humidity_map,
|
||||
s16 *height_map, u8 *biomeid_map);
|
||||
Biome *getBiome(float heat, float humidity, s16 y);
|
||||
|
||||
private:
|
||||
NodeResolver *m_resolver;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -38,6 +38,12 @@ FlagDesc flagdesc_deco[] = {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
DecorationManager::DecorationManager(IGameDef *gamedef) :
|
||||
GenElementManager(gamedef)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
|
||||
{
|
||||
size_t nplaced = 0;
|
||||
@ -55,6 +61,19 @@ size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16
|
||||
}
|
||||
|
||||
|
||||
void DecorationManager::clear()
|
||||
{
|
||||
for (size_t i = 0; i < m_elements.size(); i++) {
|
||||
Decoration *deco = (Decoration *)m_elements[i];
|
||||
if (!deco)
|
||||
continue;
|
||||
|
||||
deco->dropResolverEntries(m_resolver);
|
||||
}
|
||||
m_elements.clear();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -291,6 +310,13 @@ int DecoSimple::getHeight()
|
||||
}
|
||||
|
||||
|
||||
void DecoSimple::dropResolverEntries(NodeResolver *resolver)
|
||||
{
|
||||
resolver->cancelNodeList(&c_decos);
|
||||
resolver->cancelNodeList(&c_spawnby);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
|
||||
virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p) = 0;
|
||||
virtual int getHeight() = 0;
|
||||
virtual void dropResolverEntries(NodeResolver *resolver) {}
|
||||
};
|
||||
|
||||
class DecoSimple : public Decoration {
|
||||
@ -96,6 +97,7 @@ public:
|
||||
bool canPlaceDecoration(ManualMapVoxelManipulator *vm, v3s16 p);
|
||||
virtual size_t generate(Mapgen *mg, PseudoRandom *pr, s16 max_y, v3s16 p);
|
||||
virtual int getHeight();
|
||||
virtual void dropResolverEntries(NodeResolver *resolver);
|
||||
};
|
||||
|
||||
class DecoSchematic : public Decoration {
|
||||
@ -123,7 +125,7 @@ public:
|
||||
static const char *ELEMENT_TITLE;
|
||||
static const size_t ELEMENT_LIMIT = 0x10000;
|
||||
|
||||
DecorationManager(IGameDef *gamedef) {}
|
||||
DecorationManager(IGameDef *gamedef);
|
||||
~DecorationManager() {}
|
||||
|
||||
Decoration *create(int type)
|
||||
@ -140,6 +142,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
size_t placeAllDecos(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
|
||||
};
|
||||
|
||||
|
@ -37,6 +37,12 @@ FlagDesc flagdesc_ore[] = {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
OreManager::OreManager(IGameDef *gamedef) :
|
||||
GenElementManager(gamedef)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
|
||||
{
|
||||
size_t nplaced = 0;
|
||||
@ -54,6 +60,20 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)
|
||||
}
|
||||
|
||||
|
||||
void OreManager::clear()
|
||||
{
|
||||
for (size_t i = 0; i < m_elements.size(); i++) {
|
||||
Ore *ore = (Ore *)m_elements[i];
|
||||
if (!ore)
|
||||
continue;
|
||||
|
||||
m_resolver->cancelNodeList(&ore->c_wherein);
|
||||
m_resolver->cancelNode(&ore->c_ore);
|
||||
}
|
||||
m_elements.clear();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@ -169,4 +189,3 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public:
|
||||
static const char *ELEMENT_TITLE;
|
||||
static const size_t ELEMENT_LIMIT = 0x10000;
|
||||
|
||||
OreManager(IGameDef *gamedef) {}
|
||||
OreManager(IGameDef *gamedef);
|
||||
~OreManager() {}
|
||||
|
||||
Ore *create(int type)
|
||||
@ -116,6 +116,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
size_t placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax);
|
||||
};
|
||||
|
||||
|
@ -30,6 +30,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
const char *SchematicManager::ELEMENT_TITLE = "schematic";
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
SchematicManager::SchematicManager(IGameDef *gamedef) :
|
||||
GenElementManager(gamedef)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -76,7 +76,7 @@ public:
|
||||
static const char *ELEMENT_TITLE;
|
||||
static const size_t ELEMENT_LIMIT = 0x10000;
|
||||
|
||||
SchematicManager(IGameDef *gamedef) {}
|
||||
SchematicManager(IGameDef *gamedef);
|
||||
~SchematicManager() {}
|
||||
|
||||
Schematic *create(int type)
|
||||
|
@ -464,6 +464,20 @@ int ModApiMapgen::l_clear_registered_biomes(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ModApiMapgen::l_clear_registered_decorations(lua_State *L)
|
||||
{
|
||||
DecorationManager *dmgr = getServer(L)->getEmergeManager()->decomgr;
|
||||
dmgr->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ModApiMapgen::l_clear_registered_ores(lua_State *L)
|
||||
{
|
||||
OreManager *omgr = getServer(L)->getEmergeManager()->oremgr;
|
||||
omgr->clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// register_decoration({lots of stuff})
|
||||
int ModApiMapgen::l_register_decoration(lua_State *L)
|
||||
{
|
||||
@ -789,7 +803,10 @@ void ModApiMapgen::Initialize(lua_State *L, int top)
|
||||
API_FCT(register_biome);
|
||||
API_FCT(register_decoration);
|
||||
API_FCT(register_ore);
|
||||
|
||||
API_FCT(clear_registered_biomes);
|
||||
API_FCT(clear_registered_decorations);
|
||||
API_FCT(clear_registered_ores);
|
||||
|
||||
API_FCT(create_schematic);
|
||||
API_FCT(place_schematic);
|
||||
|
@ -55,6 +55,12 @@ private:
|
||||
// clear_registered_biomes()
|
||||
static int l_clear_registered_biomes(lua_State *L);
|
||||
|
||||
// clear_registered_decorations()
|
||||
static int l_clear_registered_decorations(lua_State *L);
|
||||
|
||||
// clear_registered_ores
|
||||
static int l_clear_registered_ores(lua_State *L);
|
||||
|
||||
// create_schematic(p1, p2, probability_list, filename)
|
||||
static int l_create_schematic(lua_State *L);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user