mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-23 16:08:51 -05:00
Remove most exceptions from getNode() (and variants)
This commit is contained in:
parent
92815ad54b
commit
5b8855e83c
@ -251,9 +251,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
for(s16 z = min_z; z <= max_z; z++)
|
for(s16 z = min_z; z <= max_z; z++)
|
||||||
{
|
{
|
||||||
v3s16 p(x,y,z);
|
v3s16 p(x,y,z);
|
||||||
try{
|
|
||||||
|
bool is_position_valid;
|
||||||
|
MapNode n = map->getNodeNoEx(p, &is_position_valid);
|
||||||
|
|
||||||
|
if (is_position_valid) {
|
||||||
// Object collides into walkable nodes
|
// Object collides into walkable nodes
|
||||||
MapNode n = map->getNode(p);
|
|
||||||
const ContentFeatures &f = gamedef->getNodeDefManager()->get(n);
|
const ContentFeatures &f = gamedef->getNodeDefManager()->get(n);
|
||||||
if(f.walkable == false)
|
if(f.walkable == false)
|
||||||
continue;
|
continue;
|
||||||
@ -275,8 +279,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
is_object.push_back(false);
|
is_object.push_back(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
else {
|
||||||
{
|
|
||||||
// Collide with unloaded nodes
|
// Collide with unloaded nodes
|
||||||
aabb3f box = getNodeBox(p, BS);
|
aabb3f box = getNodeBox(p, BS);
|
||||||
cboxes.push_back(box);
|
cboxes.push_back(box);
|
||||||
|
@ -60,13 +60,12 @@ public:
|
|||||||
m_spritenode->setVisible(true);
|
m_spritenode->setVisible(true);
|
||||||
m_spritenode->setSize(size);
|
m_spritenode->setSize(size);
|
||||||
/* Update brightness */
|
/* Update brightness */
|
||||||
u8 light = 64;
|
u8 light;
|
||||||
try{
|
bool pos_ok;
|
||||||
MapNode n = env->getMap().getNode(floatToInt(pos, BS));
|
MapNode n = env->getMap().getNodeNoEx(floatToInt(pos, BS), &pos_ok);
|
||||||
light = decode_light(n.getLightBlend(env->getDayNightRatio(),
|
light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
|
||||||
env->getGameDef()->ndef()));
|
env->getGameDef()->ndef()))
|
||||||
}
|
: 64;
|
||||||
catch(InvalidPositionException &e){}
|
|
||||||
video::SColor color(255,light,light,light);
|
video::SColor color(255,light,light,light);
|
||||||
m_spritenode->setColor(color);
|
m_spritenode->setColor(color);
|
||||||
}
|
}
|
||||||
|
@ -2342,10 +2342,8 @@ void ClientEnvironment::step(float dtime)
|
|||||||
// (day: LIGHT_SUN, night: 0)
|
// (day: LIGHT_SUN, night: 0)
|
||||||
MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0);
|
MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0);
|
||||||
|
|
||||||
try {
|
|
||||||
v3s16 p = lplayer->getLightPosition();
|
v3s16 p = lplayer->getLightPosition();
|
||||||
node_at_lplayer = m_map->getNode(p);
|
node_at_lplayer = m_map->getNodeNoEx(p);
|
||||||
} catch (InvalidPositionException &e) {}
|
|
||||||
|
|
||||||
u16 light = getInteriorLight(node_at_lplayer, 0, m_gamedef->ndef());
|
u16 light = getInteriorLight(node_at_lplayer, 0, m_gamedef->ndef());
|
||||||
u8 day = light & 0xff;
|
u8 day = light & 0xff;
|
||||||
@ -2371,15 +2369,16 @@ void ClientEnvironment::step(float dtime)
|
|||||||
{
|
{
|
||||||
// Update lighting
|
// Update lighting
|
||||||
u8 light = 0;
|
u8 light = 0;
|
||||||
try{
|
bool pos_ok;
|
||||||
|
|
||||||
// Get node at head
|
// Get node at head
|
||||||
v3s16 p = obj->getLightPosition();
|
v3s16 p = obj->getLightPosition();
|
||||||
MapNode n = m_map->getNode(p);
|
MapNode n = m_map->getNodeNoEx(p, &pos_ok);
|
||||||
|
if (pos_ok)
|
||||||
light = n.getLightBlend(day_night_ratio, m_gamedef->ndef());
|
light = n.getLightBlend(day_night_ratio, m_gamedef->ndef());
|
||||||
}
|
else
|
||||||
catch(InvalidPositionException &e){
|
|
||||||
light = blend_light(day_night_ratio, LIGHT_SUN, 0);
|
light = blend_light(day_night_ratio, LIGHT_SUN, 0);
|
||||||
}
|
|
||||||
obj->updateLight(light);
|
obj->updateLight(light);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2470,15 +2469,16 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
|
|||||||
object->addToScene(m_smgr, m_texturesource, m_irr);
|
object->addToScene(m_smgr, m_texturesource, m_irr);
|
||||||
{ // Update lighting immediately
|
{ // Update lighting immediately
|
||||||
u8 light = 0;
|
u8 light = 0;
|
||||||
try{
|
bool pos_ok;
|
||||||
|
|
||||||
// Get node at head
|
// Get node at head
|
||||||
v3s16 p = object->getLightPosition();
|
v3s16 p = object->getLightPosition();
|
||||||
MapNode n = m_map->getNode(p);
|
MapNode n = m_map->getNodeNoEx(p, &pos_ok);
|
||||||
|
if (pos_ok)
|
||||||
light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef());
|
light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef());
|
||||||
}
|
else
|
||||||
catch(InvalidPositionException &e){
|
|
||||||
light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
|
light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
|
||||||
}
|
|
||||||
object->updateLight(light);
|
object->updateLight(light);
|
||||||
}
|
}
|
||||||
return object->getId();
|
return object->getId();
|
||||||
|
40
src/game.cpp
40
src/game.cpp
@ -360,12 +360,11 @@ PointedThing getPointedThing(Client *client, v3f player_position,
|
|||||||
for (s16 z = zstart; z <= zend; z++)
|
for (s16 z = zstart; z <= zend; z++)
|
||||||
for (s16 x = xstart; x <= xend; x++) {
|
for (s16 x = xstart; x <= xend; x++) {
|
||||||
MapNode n;
|
MapNode n;
|
||||||
|
bool is_valid_position;
|
||||||
|
|
||||||
try {
|
n = map.getNodeNoEx(v3s16(x, y, z), &is_valid_position);
|
||||||
n = map.getNode(v3s16(x, y, z));
|
if (!is_valid_position)
|
||||||
} catch (InvalidPositionException &e) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPointableNode(n, client, liquids_pointable))
|
if (!isPointableNode(n, client, liquids_pointable))
|
||||||
continue;
|
continue;
|
||||||
@ -873,22 +872,31 @@ bool nodePlacementPrediction(Client &client,
|
|||||||
std::string prediction = playeritem_def.node_placement_prediction;
|
std::string prediction = playeritem_def.node_placement_prediction;
|
||||||
INodeDefManager *nodedef = client.ndef();
|
INodeDefManager *nodedef = client.ndef();
|
||||||
ClientMap &map = client.getEnv().getClientMap();
|
ClientMap &map = client.getEnv().getClientMap();
|
||||||
|
MapNode node;
|
||||||
|
bool is_valid_position;
|
||||||
|
|
||||||
if (prediction != "" && !nodedef->get(map.getNode(nodepos)).rightclickable) {
|
node = map.getNodeNoEx(nodepos, &is_valid_position);
|
||||||
|
if (!is_valid_position)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (prediction != "" && !nodedef->get(node).rightclickable) {
|
||||||
verbosestream << "Node placement prediction for "
|
verbosestream << "Node placement prediction for "
|
||||||
<< playeritem_def.name << " is "
|
<< playeritem_def.name << " is "
|
||||||
<< prediction << std::endl;
|
<< prediction << std::endl;
|
||||||
v3s16 p = neighbourpos;
|
v3s16 p = neighbourpos;
|
||||||
|
|
||||||
// Place inside node itself if buildable_to
|
// Place inside node itself if buildable_to
|
||||||
try {
|
MapNode n_under = map.getNodeNoEx(nodepos, &is_valid_position);
|
||||||
MapNode n_under = map.getNode(nodepos);
|
if (is_valid_position)
|
||||||
|
{
|
||||||
if (nodedef->get(n_under).buildable_to)
|
if (nodedef->get(n_under).buildable_to)
|
||||||
p = nodepos;
|
p = nodepos;
|
||||||
else if (!nodedef->get(map.getNode(p)).buildable_to)
|
else {
|
||||||
|
node = map.getNodeNoEx(p, &is_valid_position);
|
||||||
|
if (is_valid_position &&!nodedef->get(node).buildable_to)
|
||||||
return false;
|
return false;
|
||||||
} catch (InvalidPositionException &e) {}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find id of predicted node
|
// Find id of predicted node
|
||||||
content_t id;
|
content_t id;
|
||||||
@ -946,7 +954,7 @@ bool nodePlacementPrediction(Client &client,
|
|||||||
else
|
else
|
||||||
pp = p + v3s16(0, -1, 0);
|
pp = p + v3s16(0, -1, 0);
|
||||||
|
|
||||||
if (!nodedef->get(map.getNode(pp)).walkable)
|
if (!nodedef->get(map.getNodeNoEx(pp)).walkable)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3431,7 +3439,7 @@ void Game::handlePointingAtNode(GameRunData *runData,
|
|||||||
if (meta) {
|
if (meta) {
|
||||||
infotext = narrow_to_wide(meta->getString("infotext"));
|
infotext = narrow_to_wide(meta->getString("infotext"));
|
||||||
} else {
|
} else {
|
||||||
MapNode n = map.getNode(nodepos);
|
MapNode n = map.getNodeNoEx(nodepos);
|
||||||
|
|
||||||
if (nodedef_manager->get(n).tiledef[0].name == "unknown_node.png") {
|
if (nodedef_manager->get(n).tiledef[0].name == "unknown_node.png") {
|
||||||
infotext = L"Unknown node: ";
|
infotext = L"Unknown node: ";
|
||||||
@ -3489,7 +3497,7 @@ void Game::handlePointingAtNode(GameRunData *runData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (playeritem_def.node_placement_prediction == "" ||
|
if (playeritem_def.node_placement_prediction == "" ||
|
||||||
nodedef_manager->get(map.getNode(nodepos)).rightclickable)
|
nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable)
|
||||||
client->interact(3, pointed); // Report to server
|
client->interact(3, pointed); // Report to server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3558,7 +3566,7 @@ void Game::handleDigging(GameRunData *runData,
|
|||||||
|
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
ClientMap &map = client->getEnv().getClientMap();
|
ClientMap &map = client->getEnv().getClientMap();
|
||||||
MapNode n = client->getEnv().getClientMap().getNode(nodepos);
|
MapNode n = client->getEnv().getClientMap().getNodeNoEx(nodepos);
|
||||||
|
|
||||||
// NOTE: Similar piece of code exists on the server side for
|
// NOTE: Similar piece of code exists on the server side for
|
||||||
// cheat detection.
|
// cheat detection.
|
||||||
@ -3623,7 +3631,9 @@ void Game::handleDigging(GameRunData *runData,
|
|||||||
infostream << "Digging completed" << std::endl;
|
infostream << "Digging completed" << std::endl;
|
||||||
client->interact(2, pointed);
|
client->interact(2, pointed);
|
||||||
client->setCrack(-1, v3s16(0, 0, 0));
|
client->setCrack(-1, v3s16(0, 0, 0));
|
||||||
MapNode wasnode = map.getNode(nodepos);
|
bool is_valid_position;
|
||||||
|
MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
|
||||||
|
if (is_valid_position)
|
||||||
client->removeNode(nodepos);
|
client->removeNode(nodepos);
|
||||||
|
|
||||||
if (g_settings->getBool("enable_particles")) {
|
if (g_settings->getBool("enable_particles")) {
|
||||||
|
@ -101,39 +101,48 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
Collision detection
|
Collision detection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool is_valid_position;
|
||||||
|
MapNode node;
|
||||||
|
v3s16 pp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if player is in liquid (the oscillating value)
|
Check if player is in liquid (the oscillating value)
|
||||||
*/
|
*/
|
||||||
try{
|
|
||||||
// If in liquid, the threshold of coming out is at higher y
|
// If in liquid, the threshold of coming out is at higher y
|
||||||
if (in_liquid)
|
if (in_liquid)
|
||||||
{
|
{
|
||||||
v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
|
pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
|
||||||
in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
|
node = map->getNodeNoEx(pp, &is_valid_position);
|
||||||
liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
|
if (is_valid_position) {
|
||||||
|
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||||
|
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||||
|
} else {
|
||||||
|
in_liquid = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If not in liquid, the threshold of going in is at lower y
|
// If not in liquid, the threshold of going in is at lower y
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
|
pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
|
||||||
in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
|
node = map->getNodeNoEx(pp, &is_valid_position);
|
||||||
liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
|
if (is_valid_position) {
|
||||||
}
|
in_liquid = nodemgr->get(node.getContent()).isLiquid();
|
||||||
}
|
liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
|
||||||
catch(InvalidPositionException &e)
|
} else {
|
||||||
{
|
|
||||||
in_liquid = false;
|
in_liquid = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Check if player is in liquid (the stable value)
|
Check if player is in liquid (the stable value)
|
||||||
*/
|
*/
|
||||||
try{
|
pp = floatToInt(position + v3f(0,0,0), BS);
|
||||||
v3s16 pp = floatToInt(position + v3f(0,0,0), BS);
|
node = map->getNodeNoEx(pp, &is_valid_position);
|
||||||
in_liquid_stable = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
|
if (is_valid_position) {
|
||||||
}
|
in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
|
||||||
catch(InvalidPositionException &e)
|
} else {
|
||||||
{
|
|
||||||
in_liquid_stable = false;
|
in_liquid_stable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,17 +150,21 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
Check if player is climbing
|
Check if player is climbing
|
||||||
*/
|
*/
|
||||||
|
|
||||||
try {
|
|
||||||
v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
|
pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
|
||||||
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
|
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
|
||||||
is_climbing = ((nodemgr->get(map->getNode(pp).getContent()).climbable ||
|
node = map->getNodeNoEx(pp, &is_valid_position);
|
||||||
nodemgr->get(map->getNode(pp2).getContent()).climbable) && !free_move);
|
bool is_valid_position2;
|
||||||
}
|
MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
if (!(is_valid_position && is_valid_position2)) {
|
||||||
is_climbing = false;
|
is_climbing = false;
|
||||||
|
} else {
|
||||||
|
is_climbing = (nodemgr->get(node.getContent()).climbable
|
||||||
|
|| nodemgr->get(node2.getContent()).climbable) && !free_move;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Collision uncertainty radius
|
Collision uncertainty radius
|
||||||
Make it a bit larger than the maximum distance of movement
|
Make it a bit larger than the maximum distance of movement
|
||||||
@ -264,21 +277,19 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
|
|||||||
max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
|
max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try{
|
|
||||||
// The node to be sneaked on has to be walkable
|
// The node to be sneaked on has to be walkable
|
||||||
if(nodemgr->get(map->getNode(p)).walkable == false)
|
node = map->getNodeNoEx(p, &is_valid_position);
|
||||||
|
if (!is_valid_position || nodemgr->get(node).walkable == false)
|
||||||
continue;
|
continue;
|
||||||
// And the node above it has to be nonwalkable
|
// And the node above it has to be nonwalkable
|
||||||
if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true) {
|
node = map->getNodeNoEx(p + v3s16(0,1,0), &is_valid_position);
|
||||||
|
if (!is_valid_position || nodemgr->get(node).walkable) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!physics_override_sneak_glitch) {
|
if (!physics_override_sneak_glitch) {
|
||||||
if (nodemgr->get(map->getNode(p+v3s16(0,2,0))).walkable)
|
node =map->getNodeNoEx(p + v3s16(0,2,0), &is_valid_position);
|
||||||
continue;
|
if (!is_valid_position || nodemgr->get(node).walkable)
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
174
src/map.cpp
174
src/map.cpp
@ -186,17 +186,28 @@ bool Map::isValidPosition(v3s16 p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns a CONTENT_IGNORE node if not found
|
// Returns a CONTENT_IGNORE node if not found
|
||||||
MapNode Map::getNodeNoEx(v3s16 p)
|
MapNode Map::getNodeNoEx(v3s16 p, bool *is_valid_position)
|
||||||
{
|
{
|
||||||
v3s16 blockpos = getNodeBlockPos(p);
|
v3s16 blockpos = getNodeBlockPos(p);
|
||||||
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
MapBlock *block = getBlockNoCreateNoEx(blockpos);
|
||||||
if(block == NULL)
|
if (block == NULL) {
|
||||||
|
if (is_valid_position != NULL)
|
||||||
|
*is_valid_position = false;
|
||||||
return MapNode(CONTENT_IGNORE);
|
return MapNode(CONTENT_IGNORE);
|
||||||
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
|
||||||
return block->getNodeNoCheck(relpos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
||||||
|
bool is_valid_p;
|
||||||
|
MapNode node = block->getNodeNoCheck(relpos, &is_valid_p);
|
||||||
|
if (is_valid_position != NULL)
|
||||||
|
*is_valid_position = is_valid_p;
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Deprecated
|
||||||
// throws InvalidPositionException if not found
|
// throws InvalidPositionException if not found
|
||||||
|
// TODO: Now this is deprecated, getNodeNoEx should be renamed
|
||||||
MapNode Map::getNode(v3s16 p)
|
MapNode Map::getNode(v3s16 p)
|
||||||
{
|
{
|
||||||
v3s16 blockpos = getNodeBlockPos(p);
|
v3s16 blockpos = getNodeBlockPos(p);
|
||||||
@ -204,8 +215,13 @@ MapNode Map::getNode(v3s16 p)
|
|||||||
if (block == NULL)
|
if (block == NULL)
|
||||||
throw InvalidPositionException();
|
throw InvalidPositionException();
|
||||||
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
||||||
return block->getNodeNoCheck(relpos);
|
bool is_valid_position;
|
||||||
|
MapNode node = block->getNodeNoCheck(relpos, &is_valid_position);
|
||||||
|
if (!is_valid_position)
|
||||||
|
throw InvalidPositionException();
|
||||||
|
return node;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// throws InvalidPositionException if not found
|
// throws InvalidPositionException if not found
|
||||||
void Map::setNode(v3s16 p, MapNode & n)
|
void Map::setNode(v3s16 p, MapNode & n)
|
||||||
@ -215,9 +231,10 @@ void Map::setNode(v3s16 p, MapNode & n)
|
|||||||
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
|
||||||
// Never allow placing CONTENT_IGNORE, it fucks up stuff
|
// Never allow placing CONTENT_IGNORE, it fucks up stuff
|
||||||
if(n.getContent() == CONTENT_IGNORE){
|
if(n.getContent() == CONTENT_IGNORE){
|
||||||
|
bool temp_bool;
|
||||||
errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE"
|
errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE"
|
||||||
<<" while trying to replace \""
|
<<" while trying to replace \""
|
||||||
<<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos)).name
|
<<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos, &temp_bool)).name
|
||||||
<<"\" at "<<PP(p)<<" (block "<<PP(blockpos)<<")"<<std::endl;
|
<<"\" at "<<PP(p)<<" (block "<<PP(blockpos)<<")"<<std::endl;
|
||||||
debug_stacks_print_to(infostream);
|
debug_stacks_print_to(infostream);
|
||||||
return;
|
return;
|
||||||
@ -315,8 +332,6 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
// Get the block where the node is located
|
// Get the block where the node is located
|
||||||
v3s16 blockpos = getNodeBlockPos(n2pos);
|
v3s16 blockpos = getNodeBlockPos(n2pos);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Only fetch a new block if the block position has changed
|
// Only fetch a new block if the block position has changed
|
||||||
try {
|
try {
|
||||||
if(block == NULL || blockpos != blockpos_last){
|
if(block == NULL || blockpos != blockpos_last){
|
||||||
@ -327,15 +342,17 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
blockchangecount++;
|
blockchangecount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
catch(InvalidPositionException &e) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate relative position in block
|
// Calculate relative position in block
|
||||||
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
|
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
|
||||||
// Get node straight from the block
|
// Get node straight from the block
|
||||||
MapNode n2 = block->getNode(relpos);
|
bool is_valid_position;
|
||||||
|
MapNode n2 = block->getNode(relpos, &is_valid_position);
|
||||||
|
if (!is_valid_position)
|
||||||
|
continue;
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
@ -394,11 +411,6 @@ void Map::unspreadLight(enum LightBank bank,
|
|||||||
block_checked_in_modified = true;
|
block_checked_in_modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*infostream<<"unspreadLight(): Changed block "
|
/*infostream<<"unspreadLight(): Changed block "
|
||||||
@ -474,8 +486,7 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
blockchangecount++;
|
blockchangecount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
catch(InvalidPositionException &e) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,9 +497,10 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
|
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
|
||||||
|
|
||||||
// Get node straight from the block
|
// Get node straight from the block
|
||||||
MapNode n = block->getNode(relpos);
|
bool is_valid_position;
|
||||||
|
MapNode n = block->getNode(relpos, &is_valid_position);
|
||||||
|
|
||||||
u8 oldlight = n.getLight(bank, nodemgr);
|
u8 oldlight = is_valid_position ? n.getLight(bank, nodemgr) : 0;
|
||||||
u8 newlight = diminish_light(oldlight);
|
u8 newlight = diminish_light(oldlight);
|
||||||
|
|
||||||
// Loop through 6 neighbors
|
// Loop through 6 neighbors
|
||||||
@ -499,8 +511,6 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
// Get the block where the node is located
|
// Get the block where the node is located
|
||||||
v3s16 blockpos = getNodeBlockPos(n2pos);
|
v3s16 blockpos = getNodeBlockPos(n2pos);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Only fetch a new block if the block position has changed
|
// Only fetch a new block if the block position has changed
|
||||||
try {
|
try {
|
||||||
if(block == NULL || blockpos != blockpos_last){
|
if(block == NULL || blockpos != blockpos_last){
|
||||||
@ -511,15 +521,16 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
blockchangecount++;
|
blockchangecount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
catch(InvalidPositionException &e) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate relative position in block
|
// Calculate relative position in block
|
||||||
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
|
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
|
||||||
// Get node straight from the block
|
// Get node straight from the block
|
||||||
MapNode n2 = block->getNode(relpos);
|
MapNode n2 = block->getNode(relpos, &is_valid_position);
|
||||||
|
if (!is_valid_position)
|
||||||
|
continue;
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
/*
|
/*
|
||||||
@ -557,11 +568,6 @@ void Map::spreadLight(enum LightBank bank,
|
|||||||
block_checked_in_modified = true;
|
block_checked_in_modified = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*infostream<<"spreadLight(): Changed block "
|
/*infostream<<"spreadLight(): Changed block "
|
||||||
@ -607,13 +613,11 @@ v3s16 Map::getBrightestNeighbour(enum LightBank bank, v3s16 p)
|
|||||||
// Get the position of the neighbor node
|
// Get the position of the neighbor node
|
||||||
v3s16 n2pos = p + dirs[i];
|
v3s16 n2pos = p + dirs[i];
|
||||||
MapNode n2;
|
MapNode n2;
|
||||||
try{
|
bool is_valid_position;
|
||||||
n2 = getNode(n2pos);
|
n2 = getNodeNoEx(n2pos, &is_valid_position);
|
||||||
}
|
if (!is_valid_position)
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if(n2.getLight(bank, nodemgr) > brightest_light || found_something == false){
|
if(n2.getLight(bank, nodemgr) > brightest_light || found_something == false){
|
||||||
brightest_light = n2.getLight(bank, nodemgr);
|
brightest_light = n2.getLight(bank, nodemgr);
|
||||||
brightest_pos = n2pos;
|
brightest_pos = n2pos;
|
||||||
@ -656,7 +660,10 @@ s16 Map::propagateSunlight(v3s16 start,
|
|||||||
}
|
}
|
||||||
|
|
||||||
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
|
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
|
||||||
MapNode n = block->getNode(relpos);
|
bool is_valid_position;
|
||||||
|
MapNode n = block->getNode(relpos, &is_valid_position);
|
||||||
|
if (!is_valid_position)
|
||||||
|
break;
|
||||||
|
|
||||||
if(nodemgr->get(n).sunlight_propagates)
|
if(nodemgr->get(n).sunlight_propagates)
|
||||||
{
|
{
|
||||||
@ -723,10 +730,17 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
|
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
|
||||||
for(s16 y=0; y<MAP_BLOCKSIZE; y++)
|
for(s16 y=0; y<MAP_BLOCKSIZE; y++)
|
||||||
{
|
{
|
||||||
|
|
||||||
try{
|
|
||||||
v3s16 p(x,y,z);
|
v3s16 p(x,y,z);
|
||||||
MapNode n = block->getNode(p);
|
bool is_valid_position;
|
||||||
|
MapNode n = block->getNode(p, &is_valid_position);
|
||||||
|
if (!is_valid_position) {
|
||||||
|
/* This would happen when dealing with a
|
||||||
|
dummy block.
|
||||||
|
*/
|
||||||
|
infostream<<"updateLighting(): InvalidPositionException"
|
||||||
|
<<std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
u8 oldlight = n.getLight(bank, nodemgr);
|
u8 oldlight = n.getLight(bank, nodemgr);
|
||||||
n.setLight(bank, 0, nodemgr);
|
n.setLight(bank, 0, nodemgr);
|
||||||
block->setNode(p, n);
|
block->setNode(p, n);
|
||||||
@ -745,17 +759,8 @@ void Map::updateLighting(enum LightBank bank,
|
|||||||
v3s16 p_map = p + posnodes;
|
v3s16 p_map = p + posnodes;
|
||||||
unlight_from[p_map] = oldlight;
|
unlight_from[p_map] = oldlight;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
This would happen when dealing with a
|
|
||||||
dummy block.
|
|
||||||
*/
|
|
||||||
//assert(0);
|
|
||||||
infostream<<"updateLighting(): InvalidPositionException"
|
|
||||||
<<std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bank == LIGHTBANK_DAY)
|
if(bank == LIGHTBANK_DAY)
|
||||||
@ -965,15 +970,12 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
|
|
||||||
Otherwise there probably is.
|
Otherwise there probably is.
|
||||||
*/
|
*/
|
||||||
try{
|
|
||||||
MapNode topnode = getNode(toppos);
|
|
||||||
|
|
||||||
if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
|
bool is_valid_position;
|
||||||
|
MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
|
||||||
|
|
||||||
|
if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
|
||||||
node_under_sunlight = false;
|
node_under_sunlight = false;
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Remove all light that has come out of this node
|
Remove all light that has come out of this node
|
||||||
@ -988,7 +990,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
{
|
{
|
||||||
enum LightBank bank = banks[i];
|
enum LightBank bank = banks[i];
|
||||||
|
|
||||||
u8 lightwas = getNode(p).getLight(bank, ndef);
|
u8 lightwas = getNodeNoEx(p).getLight(bank, ndef);
|
||||||
|
|
||||||
// Add the block of the added node to modified_blocks
|
// Add the block of the added node to modified_blocks
|
||||||
v3s16 blockpos = getNodeBlockPos(p);
|
v3s16 blockpos = getNodeBlockPos(p);
|
||||||
@ -1045,13 +1047,10 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
v3s16 n2pos(p.X, y, p.Z);
|
v3s16 n2pos(p.X, y, p.Z);
|
||||||
|
|
||||||
MapNode n2;
|
MapNode n2;
|
||||||
try{
|
|
||||||
n2 = getNode(n2pos);
|
n2 = getNodeNoEx(n2pos, &is_valid_position);
|
||||||
}
|
if (!is_valid_position)
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
if(n2.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
|
if(n2.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
|
||||||
{
|
{
|
||||||
@ -1112,20 +1111,14 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
|
|||||||
};
|
};
|
||||||
for(u16 i=0; i<7; i++)
|
for(u16 i=0; i<7; i++)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
v3s16 p2 = p + dirs[i];
|
v3s16 p2 = p + dirs[i];
|
||||||
|
|
||||||
MapNode n2 = getNode(p2);
|
MapNode n2 = getNodeNoEx(p2, &is_valid_position);
|
||||||
if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
|
if(is_valid_position
|
||||||
|
&& (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
|
||||||
{
|
{
|
||||||
m_transforming_liquid.push_back(p2);
|
m_transforming_liquid.push_back(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1156,15 +1149,11 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
If there is a node at top and it doesn't have sunlight,
|
If there is a node at top and it doesn't have sunlight,
|
||||||
there will be no sunlight going down.
|
there will be no sunlight going down.
|
||||||
*/
|
*/
|
||||||
try{
|
bool is_valid_position;
|
||||||
MapNode topnode = getNode(toppos);
|
MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
|
||||||
|
|
||||||
if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
|
if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
|
||||||
node_under_sunlight = false;
|
node_under_sunlight = false;
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::set<v3s16> light_sources;
|
std::set<v3s16> light_sources;
|
||||||
|
|
||||||
@ -1181,7 +1170,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
Unlight neighbors (in case the node is a light source)
|
Unlight neighbors (in case the node is a light source)
|
||||||
*/
|
*/
|
||||||
unLightNeighbors(bank, p,
|
unLightNeighbors(bank, p,
|
||||||
getNode(p).getLight(bank, ndef),
|
getNodeNoEx(p).getLight(bank, ndef),
|
||||||
light_sources, modified_blocks);
|
light_sources, modified_blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1241,13 +1230,11 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
{
|
{
|
||||||
// Set the lighting of this node to 0
|
// Set the lighting of this node to 0
|
||||||
// TODO: Is this needed? Lighting is cleared up there already.
|
// TODO: Is this needed? Lighting is cleared up there already.
|
||||||
try{
|
MapNode n = getNodeNoEx(p, &is_valid_position);
|
||||||
MapNode n = getNode(p);
|
if (is_valid_position) {
|
||||||
n.setLight(LIGHTBANK_DAY, 0, ndef);
|
n.setLight(LIGHTBANK_DAY, 0, ndef);
|
||||||
setNode(p, n);
|
setNode(p, n);
|
||||||
}
|
} else {
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1303,20 +1290,15 @@ void Map::removeNodeAndUpdate(v3s16 p,
|
|||||||
};
|
};
|
||||||
for(u16 i=0; i<7; i++)
|
for(u16 i=0; i<7; i++)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
v3s16 p2 = p + dirs[i];
|
v3s16 p2 = p + dirs[i];
|
||||||
|
|
||||||
MapNode n2 = getNode(p2);
|
bool is_position_valid;
|
||||||
if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
|
MapNode n2 = getNodeNoEx(p2, &is_position_valid);
|
||||||
|
if (is_position_valid
|
||||||
|
&& (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
|
||||||
{
|
{
|
||||||
m_transforming_liquid.push_back(p2);
|
m_transforming_liquid.push_back(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,14 +197,13 @@ public:
|
|||||||
|
|
||||||
bool isValidPosition(v3s16 p);
|
bool isValidPosition(v3s16 p);
|
||||||
|
|
||||||
// throws InvalidPositionException if not found
|
|
||||||
MapNode getNode(v3s16 p);
|
|
||||||
|
|
||||||
// throws InvalidPositionException if not found
|
// throws InvalidPositionException if not found
|
||||||
void setNode(v3s16 p, MapNode & n);
|
void setNode(v3s16 p, MapNode & n);
|
||||||
|
|
||||||
// Returns a CONTENT_IGNORE node if not found
|
// Returns a CONTENT_IGNORE node if not found
|
||||||
MapNode getNodeNoEx(v3s16 p);
|
// If is_valid_position is not NULL then this will be set to true if the
|
||||||
|
// position is valid, otherwise false
|
||||||
|
MapNode getNodeNoEx(v3s16 p, bool *is_valid_position = NULL);
|
||||||
|
|
||||||
void unspreadLight(enum LightBank bank,
|
void unspreadLight(enum LightBank bank,
|
||||||
std::map<v3s16, u8> & from_nodes,
|
std::map<v3s16, u8> & from_nodes,
|
||||||
|
@ -97,55 +97,20 @@ bool MapBlock::isValidPositionParent(v3s16 p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MapNode MapBlock::getNodeParent(v3s16 p)
|
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
|
||||||
{
|
{
|
||||||
if (isValidPosition(p) == false)
|
if (isValidPosition(p) == false)
|
||||||
{
|
return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
|
||||||
return m_parent->getNode(getPosRelative() + p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(data == NULL)
|
|
||||||
throw InvalidPositionException();
|
|
||||||
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MapBlock::setNodeParent(v3s16 p, MapNode & n)
|
if (data == NULL) {
|
||||||
{
|
if (is_valid_position)
|
||||||
if(isValidPosition(p) == false)
|
*is_valid_position = false;
|
||||||
{
|
|
||||||
m_parent->setNode(getPosRelative() + p, n);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(data == NULL)
|
|
||||||
throw InvalidPositionException();
|
|
||||||
data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X] = n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MapNode MapBlock::getNodeParentNoEx(v3s16 p)
|
|
||||||
{
|
|
||||||
if(isValidPosition(p) == false)
|
|
||||||
{
|
|
||||||
try{
|
|
||||||
return m_parent->getNode(getPosRelative() + p);
|
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
return MapNode(CONTENT_IGNORE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(data == NULL)
|
|
||||||
{
|
|
||||||
return MapNode(CONTENT_IGNORE);
|
return MapNode(CONTENT_IGNORE);
|
||||||
}
|
}
|
||||||
|
if (is_valid_position)
|
||||||
|
*is_valid_position = true;
|
||||||
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
|
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Propagates sunlight down through the block.
|
Propagates sunlight down through the block.
|
||||||
@ -183,9 +148,14 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
#if 1
|
#if 1
|
||||||
bool no_sunlight = false;
|
bool no_sunlight = false;
|
||||||
bool no_top_block = false;
|
bool no_top_block = false;
|
||||||
|
|
||||||
// Check if node above block has sunlight
|
// Check if node above block has sunlight
|
||||||
try{
|
|
||||||
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z));
|
bool is_valid_position;
|
||||||
|
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z),
|
||||||
|
&is_valid_position);
|
||||||
|
if (is_valid_position)
|
||||||
|
{
|
||||||
if(n.getContent() == CONTENT_IGNORE)
|
if(n.getContent() == CONTENT_IGNORE)
|
||||||
{
|
{
|
||||||
// Trust heuristics
|
// Trust heuristics
|
||||||
@ -196,7 +166,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
no_sunlight = true;
|
no_sunlight = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(InvalidPositionException &e)
|
else
|
||||||
{
|
{
|
||||||
no_top_block = true;
|
no_top_block = true;
|
||||||
|
|
||||||
@ -208,7 +178,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z));
|
MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
|
||||||
if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
|
if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
|
||||||
{
|
{
|
||||||
no_sunlight = true;
|
no_sunlight = true;
|
||||||
@ -308,11 +278,11 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
|
|
||||||
Ignore non-transparent nodes as they always have no light
|
Ignore non-transparent nodes as they always have no light
|
||||||
*/
|
*/
|
||||||
try
|
|
||||||
{
|
|
||||||
if(block_below_is_valid)
|
if(block_below_is_valid)
|
||||||
{
|
{
|
||||||
MapNode n = getNodeParent(v3s16(x, -1, z));
|
MapNode n = getNodeParent(v3s16(x, -1, z), &is_valid_position);
|
||||||
|
if (is_valid_position) {
|
||||||
if(nodemgr->get(n).light_propagates)
|
if(nodemgr->get(n).light_propagates)
|
||||||
{
|
{
|
||||||
if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
|
if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
|
||||||
@ -322,9 +292,8 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
&& sunlight_should_go_down == true)
|
&& sunlight_should_go_down == true)
|
||||||
block_below_is_valid = false;
|
block_below_is_valid = false;
|
||||||
}
|
}
|
||||||
}//if
|
}
|
||||||
}//try
|
else
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
{
|
||||||
/*std::cout<<"InvalidBlockException for bottom block node"
|
/*std::cout<<"InvalidBlockException for bottom block node"
|
||||||
<<std::endl;*/
|
<<std::endl;*/
|
||||||
@ -332,6 +301,7 @@ bool MapBlock::propagateSunlight(std::set<v3s16> & light_sources,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return block_below_is_valid;
|
return block_below_is_valid;
|
||||||
}
|
}
|
||||||
@ -1070,7 +1040,7 @@ std::string analyze_block(MapBlock *block)
|
|||||||
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
|
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
|
||||||
{
|
{
|
||||||
v3s16 p(x0,y0,z0);
|
v3s16 p(x0,y0,z0);
|
||||||
MapNode n = block->getNode(p);
|
MapNode n = block->getNodeNoEx(p);
|
||||||
content_t c = n.getContent();
|
content_t c = n.getContent();
|
||||||
if(c == CONTENT_IGNORE)
|
if(c == CONTENT_IGNORE)
|
||||||
some_ignore = true;
|
some_ignore = true;
|
||||||
|
@ -251,37 +251,39 @@ public:
|
|||||||
Regular MapNode get-setters
|
Regular MapNode get-setters
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool isValidPosition(v3s16 p)
|
bool isValidPosition(s16 x, s16 y, s16 z)
|
||||||
{
|
{
|
||||||
if(data == NULL)
|
return data != NULL
|
||||||
return false;
|
&& x >= 0 && x < MAP_BLOCKSIZE
|
||||||
return (p.X >= 0 && p.X < MAP_BLOCKSIZE
|
&& y >= 0 && y < MAP_BLOCKSIZE
|
||||||
&& p.Y >= 0 && p.Y < MAP_BLOCKSIZE
|
&& z >= 0 && z < MAP_BLOCKSIZE;
|
||||||
&& p.Z >= 0 && p.Z < MAP_BLOCKSIZE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapNode getNode(s16 x, s16 y, s16 z)
|
bool isValidPosition(v3s16 p)
|
||||||
{
|
{
|
||||||
if(data == NULL)
|
return isValidPosition(p.X, p.Y, p.Z);
|
||||||
throw InvalidPositionException();
|
}
|
||||||
if(x < 0 || x >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
|
||||||
if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
MapNode getNode(s16 x, s16 y, s16 z, bool *valid_position)
|
||||||
if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
|
{
|
||||||
|
*valid_position = isValidPosition(x, y, z);
|
||||||
|
|
||||||
|
if (!*valid_position)
|
||||||
|
return MapNode(CONTENT_IGNORE);
|
||||||
|
|
||||||
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
|
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
MapNode getNode(v3s16 p)
|
MapNode getNode(v3s16 p, bool *valid_position)
|
||||||
{
|
{
|
||||||
return getNode(p.X, p.Y, p.Z);
|
return getNode(p.X, p.Y, p.Z, valid_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
MapNode getNodeNoEx(v3s16 p)
|
MapNode getNodeNoEx(v3s16 p)
|
||||||
{
|
{
|
||||||
try{
|
bool is_valid;
|
||||||
return getNode(p.X, p.Y, p.Z);
|
MapNode node = getNode(p.X, p.Y, p.Z, &is_valid);
|
||||||
}catch(InvalidPositionException &e){
|
return is_valid ? node : MapNode(CONTENT_IGNORE);
|
||||||
return MapNode(CONTENT_IGNORE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNode(s16 x, s16 y, s16 z, MapNode & n)
|
void setNode(s16 x, s16 y, s16 z, MapNode & n)
|
||||||
@ -304,16 +306,18 @@ public:
|
|||||||
Non-checking variants of the above
|
Non-checking variants of the above
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MapNode getNodeNoCheck(s16 x, s16 y, s16 z)
|
MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
|
||||||
{
|
{
|
||||||
if(data == NULL)
|
*valid_position = data != NULL;
|
||||||
throw InvalidPositionException();
|
if(!valid_position)
|
||||||
|
return MapNode(CONTENT_IGNORE);
|
||||||
|
|
||||||
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
|
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
MapNode getNodeNoCheck(v3s16 p)
|
MapNode getNodeNoCheck(v3s16 p, bool *valid_position)
|
||||||
{
|
{
|
||||||
return getNodeNoCheck(p.X, p.Y, p.Z);
|
return getNodeNoCheck(p.X, p.Y, p.Z, valid_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
|
void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
|
||||||
@ -334,9 +338,8 @@ public:
|
|||||||
is not valid on this MapBlock.
|
is not valid on this MapBlock.
|
||||||
*/
|
*/
|
||||||
bool isValidPositionParent(v3s16 p);
|
bool isValidPositionParent(v3s16 p);
|
||||||
MapNode getNodeParent(v3s16 p);
|
MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL);
|
||||||
void setNodeParent(v3s16 p, MapNode & n);
|
void setNodeParent(v3s16 p, MapNode & n);
|
||||||
MapNode getNodeParentNoEx(v3s16 p);
|
|
||||||
|
|
||||||
void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
|
void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
|
||||||
{
|
{
|
||||||
|
@ -168,18 +168,19 @@ void Particle::step(float dtime)
|
|||||||
void Particle::updateLight()
|
void Particle::updateLight()
|
||||||
{
|
{
|
||||||
u8 light = 0;
|
u8 light = 0;
|
||||||
try{
|
bool pos_ok;
|
||||||
|
|
||||||
v3s16 p = v3s16(
|
v3s16 p = v3s16(
|
||||||
floor(m_pos.X+0.5),
|
floor(m_pos.X+0.5),
|
||||||
floor(m_pos.Y+0.5),
|
floor(m_pos.Y+0.5),
|
||||||
floor(m_pos.Z+0.5)
|
floor(m_pos.Z+0.5)
|
||||||
);
|
);
|
||||||
MapNode n = m_env->getClientMap().getNode(p);
|
MapNode n = m_env->getClientMap().getNodeNoEx(p, &pos_ok);
|
||||||
|
if (pos_ok)
|
||||||
light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
|
light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
|
||||||
}
|
else
|
||||||
catch(InvalidPositionException &e){
|
|
||||||
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
|
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
|
||||||
}
|
|
||||||
m_light = decode_light(light);
|
m_light = decode_light(light);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,16 +159,15 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L)
|
|||||||
// pos
|
// pos
|
||||||
v3s16 pos = read_v3s16(L, 1);
|
v3s16 pos = read_v3s16(L, 1);
|
||||||
// Do it
|
// Do it
|
||||||
try{
|
bool pos_ok;
|
||||||
MapNode n = env->getMap().getNode(pos);
|
MapNode n = env->getMap().getNodeNoEx(pos, &pos_ok);
|
||||||
|
if (pos_ok) {
|
||||||
// Return node
|
// Return node
|
||||||
pushnode(L, n, env->getGameDef()->ndef());
|
pushnode(L, n, env->getGameDef()->ndef());
|
||||||
return 1;
|
} else {
|
||||||
} catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_node_light(pos, timeofday)
|
// get_node_light(pos, timeofday)
|
||||||
@ -185,16 +184,16 @@ int ModApiEnvMod::l_get_node_light(lua_State *L)
|
|||||||
time_of_day = 24000.0 * lua_tonumber(L, 2);
|
time_of_day = 24000.0 * lua_tonumber(L, 2);
|
||||||
time_of_day %= 24000;
|
time_of_day %= 24000;
|
||||||
u32 dnr = time_to_daynight_ratio(time_of_day, true);
|
u32 dnr = time_to_daynight_ratio(time_of_day, true);
|
||||||
try{
|
|
||||||
MapNode n = env->getMap().getNode(pos);
|
bool is_position_ok;
|
||||||
|
MapNode n = env->getMap().getNodeNoEx(pos, &is_position_ok);
|
||||||
|
if (is_position_ok) {
|
||||||
INodeDefManager *ndef = env->getGameDef()->ndef();
|
INodeDefManager *ndef = env->getGameDef()->ndef();
|
||||||
lua_pushinteger(L, n.getLightBlend(dnr, ndef));
|
lua_pushinteger(L, n.getLightBlend(dnr, ndef));
|
||||||
return 1;
|
} else {
|
||||||
} catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// place_node(pos, node)
|
// place_node(pos, node)
|
||||||
|
@ -2424,17 +2424,18 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
somebody is cheating, by checking the timing.
|
somebody is cheating, by checking the timing.
|
||||||
*/
|
*/
|
||||||
MapNode n(CONTENT_IGNORE);
|
MapNode n(CONTENT_IGNORE);
|
||||||
try
|
bool pos_ok;
|
||||||
{
|
n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
|
||||||
n = m_env->getMap().getNode(p_under);
|
if (pos_ok)
|
||||||
}
|
n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
if (!pos_ok) {
|
||||||
infostream<<"Server: Not punching: Node not found."
|
infostream<<"Server: Not punching: Node not found."
|
||||||
<<" Adding block to emerge queue."
|
<<" Adding block to emerge queue."
|
||||||
<<std::endl;
|
<<std::endl;
|
||||||
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
|
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(n.getContent() != CONTENT_IGNORE)
|
if(n.getContent() != CONTENT_IGNORE)
|
||||||
m_script->node_on_punch(p_under, n, playersao, pointed);
|
m_script->node_on_punch(p_under, n, playersao, pointed);
|
||||||
// Cheat prevention
|
// Cheat prevention
|
||||||
@ -2479,13 +2480,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||||||
// Only digging of nodes
|
// Only digging of nodes
|
||||||
if(pointed.type == POINTEDTHING_NODE)
|
if(pointed.type == POINTEDTHING_NODE)
|
||||||
{
|
{
|
||||||
MapNode n(CONTENT_IGNORE);
|
bool pos_ok;
|
||||||
try
|
MapNode n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
|
||||||
{
|
if (!pos_ok) {
|
||||||
n = m_env->getMap().getNode(p_under);
|
|
||||||
}
|
|
||||||
catch(InvalidPositionException &e)
|
|
||||||
{
|
|
||||||
infostream << "Server: Not finishing digging: Node not found."
|
infostream << "Server: Not finishing digging: Node not found."
|
||||||
<< " Adding block to emerge queue."
|
<< " Adding block to emerge queue."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user