mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Allow group:groupname in ABM definition and implement minetest.hash_node_position()
This commit is contained in:
parent
1518b8f753
commit
280e1a2512
@ -861,6 +861,14 @@ function minetest.get_connected_players()
|
|||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function minetest.hash_node_position(pos)
|
||||||
|
return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
|
||||||
|
end
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Privileges
|
||||||
|
--
|
||||||
|
|
||||||
minetest.registered_privileges = {}
|
minetest.registered_privileges = {}
|
||||||
function minetest.register_privilege(name, description)
|
function minetest.register_privilege(name, description)
|
||||||
minetest.registered_privileges[name] = description
|
minetest.registered_privileges[name] = description
|
||||||
|
@ -542,6 +542,8 @@ minetest.after(time, func, param)
|
|||||||
|
|
||||||
Random:
|
Random:
|
||||||
minetest.get_connected_players() -> list of ObjectRefs
|
minetest.get_connected_players() -> list of ObjectRefs
|
||||||
|
minetest.hash_node_position({x=,y=,z=}) -> 48-bit integer
|
||||||
|
^ Gives a unique hash number for a node position (16+16+16=48bit)
|
||||||
|
|
||||||
Global objects:
|
Global objects:
|
||||||
minetest.env - environment reference
|
minetest.env - environment reference
|
||||||
@ -768,6 +770,7 @@ Entity definition (register_entity)
|
|||||||
|
|
||||||
ABM (ActiveBlockModifier) definition (register_abm)
|
ABM (ActiveBlockModifier) definition (register_abm)
|
||||||
{
|
{
|
||||||
|
-- In the following two fields, also group:groupname will work.
|
||||||
nodenames = {"default:lava_source"},
|
nodenames = {"default:lava_source"},
|
||||||
neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
|
neighbors = {"default:water_source", "default:water_flowing"}, -- (any of these)
|
||||||
^ If left out or empty, any neighbor will do
|
^ If left out or empty, any neighbor will do
|
||||||
|
@ -646,19 +646,21 @@ public:
|
|||||||
= abm->getRequiredNeighbors();
|
= abm->getRequiredNeighbors();
|
||||||
for(std::set<std::string>::iterator
|
for(std::set<std::string>::iterator
|
||||||
i = required_neighbors_s.begin();
|
i = required_neighbors_s.begin();
|
||||||
i != required_neighbors_s.end(); i++){
|
i != required_neighbors_s.end(); i++)
|
||||||
content_t c = ndef->getId(*i);
|
{
|
||||||
if(c == CONTENT_IGNORE)
|
ndef->getIds(*i, aabm.required_neighbors);
|
||||||
continue;
|
|
||||||
aabm.required_neighbors.insert(c);
|
|
||||||
}
|
}
|
||||||
// Trigger contents
|
// Trigger contents
|
||||||
std::set<std::string> contents_s = abm->getTriggerContents();
|
std::set<std::string> contents_s = abm->getTriggerContents();
|
||||||
for(std::set<std::string>::iterator
|
for(std::set<std::string>::iterator
|
||||||
i = contents_s.begin(); i != contents_s.end(); i++){
|
i = contents_s.begin(); i != contents_s.end(); i++)
|
||||||
content_t c = ndef->getId(*i);
|
{
|
||||||
if(c == CONTENT_IGNORE)
|
std::set<content_t> ids;
|
||||||
continue;
|
ndef->getIds(*i, ids);
|
||||||
|
for(std::set<content_t>::const_iterator k = ids.begin();
|
||||||
|
k != ids.end(); k++)
|
||||||
|
{
|
||||||
|
content_t c = *k;
|
||||||
std::map<content_t, std::list<ActiveABM> >::iterator j;
|
std::map<content_t, std::list<ActiveABM> >::iterator j;
|
||||||
j = m_aabms.find(c);
|
j = m_aabms.find(c);
|
||||||
if(j == m_aabms.end()){
|
if(j == m_aabms.end()){
|
||||||
@ -670,6 +672,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void apply(MapBlock *block)
|
void apply(MapBlock *block)
|
||||||
{
|
{
|
||||||
if(m_aabms.empty())
|
if(m_aabms.empty())
|
||||||
|
@ -380,6 +380,25 @@ public:
|
|||||||
getId(name, id);
|
getId(name, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
virtual void getIds(const std::string &name, std::set<content_t> &result)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
if(name.substr(0,6) != "group:"){
|
||||||
|
content_t id = CONTENT_IGNORE;
|
||||||
|
if(getId(name, id))
|
||||||
|
result.insert(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string group = name.substr(6);
|
||||||
|
for(u16 id=0; id<=MAX_CONTENT; id++)
|
||||||
|
{
|
||||||
|
const ContentFeatures &f = m_content_features[id];
|
||||||
|
if(f.name == "") // Quickly discard undefined nodes
|
||||||
|
continue;
|
||||||
|
if(itemgroup_get(f.groups, group) != 0)
|
||||||
|
result.insert(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
virtual const ContentFeatures& get(const std::string &name) const
|
virtual const ContentFeatures& get(const std::string &name) const
|
||||||
{
|
{
|
||||||
content_t id = CONTENT_IGNORE;
|
content_t id = CONTENT_IGNORE;
|
||||||
|
@ -238,6 +238,9 @@ public:
|
|||||||
virtual const ContentFeatures& get(const MapNode &n) const=0;
|
virtual const ContentFeatures& get(const MapNode &n) const=0;
|
||||||
virtual bool getId(const std::string &name, content_t &result) const=0;
|
virtual bool getId(const std::string &name, content_t &result) const=0;
|
||||||
virtual content_t getId(const std::string &name) const=0;
|
virtual content_t getId(const std::string &name) const=0;
|
||||||
|
// Allows "group:name" in addition to regular node names
|
||||||
|
virtual void getIds(const std::string &name, std::set<content_t> &result)
|
||||||
|
const=0;
|
||||||
virtual const ContentFeatures& get(const std::string &name) const=0;
|
virtual const ContentFeatures& get(const std::string &name) const=0;
|
||||||
|
|
||||||
virtual void serialize(std::ostream &os)=0;
|
virtual void serialize(std::ostream &os)=0;
|
||||||
@ -254,6 +257,9 @@ public:
|
|||||||
virtual const ContentFeatures& get(const MapNode &n) const=0;
|
virtual const ContentFeatures& get(const MapNode &n) const=0;
|
||||||
virtual bool getId(const std::string &name, content_t &result) const=0;
|
virtual bool getId(const std::string &name, content_t &result) const=0;
|
||||||
virtual content_t getId(const std::string &name) const=0;
|
virtual content_t getId(const std::string &name) const=0;
|
||||||
|
// Allows "group:name" in addition to regular node names
|
||||||
|
virtual void getIds(const std::string &name, std::set<content_t> &result)
|
||||||
|
const=0;
|
||||||
// If not found, returns the features of CONTENT_IGNORE
|
// If not found, returns the features of CONTENT_IGNORE
|
||||||
virtual const ContentFeatures& get(const std::string &name) const=0;
|
virtual const ContentFeatures& get(const std::string &name) const=0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user