Skip to content

Commit

Permalink
Meta-set nodedef: Part 4
Browse files Browse the repository at this point in the history
Mainly a refactor of parts of minetest#1118
  • Loading branch information
Thomas--S committed Jun 9, 2017
1 parent 03a12d4 commit f149938
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 57 deletions.
23 changes: 11 additions & 12 deletions builtin/common/misc_helpers.lua
Expand Up @@ -373,32 +373,31 @@ if INIT == "game" then
infinitestacks, orient_flags)
orient_flags = orient_flags or {}

local unode = core.get_node_or_nil(pointed_thing.under)
local above = pointed_thing.above
local under = pointed_thing.under

local unode = core.get_node_or_nil(under)
if not unode then
return
end
local undef = core.registered_nodes[unode.name]
end
local undef = core.get_nodedef(under)
if undef and undef.on_rightclick then
undef.on_rightclick(pointed_thing.under, unode, placer,
itemstack, pointed_thing)
undef.on_rightclick(under, unode, placer, itemstack, pointed_thing)
return
end
end
local fdir = core.dir_to_facedir(placer:get_look_dir())
local wield_name = itemstack:get_name()

local above = pointed_thing.above
local under = pointed_thing.under
local iswall = (above.y == under.y)
local isceiling = not iswall and (above.y < under.y)
local anode = core.get_node_or_nil(above)
if not anode then
return
end
local pos = pointed_thing.above
local pos = above
local node = anode

if undef and undef.buildable_to then
pos = pointed_thing.under
pos = under
node = unode
iswall = false
end
Expand All @@ -409,7 +408,7 @@ if INIT == "game" then
return
end

local ndef = core.registered_nodes[node.name]
local ndef = core.get_nodedef(pos)
if not ndef or not ndef.buildable_to then
return
end
Expand Down
6 changes: 3 additions & 3 deletions builtin/game/falling.lua
Expand Up @@ -62,7 +62,7 @@ core.register_entity(":__builtin:falling_node", {
local bcp = {x = pos.x, y = pos.y - 0.7, z = pos.z}
-- Avoid bugs caused by an unloaded node below
local bcn = core.get_node_or_nil(bcp)
local bcd = bcn and core.registered_nodes[bcn.name]
local bcd = bcn and core.get_nodedef(bcp)
if bcn and
(not bcd or bcd.walkable or
(core.get_item_group(self.node.name, "float") ~= 0 and
Expand All @@ -86,7 +86,7 @@ core.register_entity(":__builtin:falling_node", {
local np = {x = bcp.x, y = bcp.y + 1, z = bcp.z}
-- Check what's here
local n2 = core.get_node(np)
local nd = core.registered_nodes[n2.name]
local nd = core.get_nodedef(np)
-- If it's not air or liquid, remove node and replace it with
-- it's drops
if n2.name ~= "air" and (not nd or nd.liquidtype == "none") then
Expand Down Expand Up @@ -189,7 +189,7 @@ function core.check_single_for_falling(p)
local p_bottom = {x = p.x, y = p.y - 1, z = p.z}
-- Only spawn falling node if node below is loaded
local n_bottom = core.get_node_or_nil(p_bottom)
local d_bottom = n_bottom and core.registered_nodes[n_bottom.name]
local d_bottom = n_bottom and core.get_nodedef(p_bottom)
if d_bottom and

(core.get_item_group(n.name, "float") == 0 or
Expand Down
4 changes: 2 additions & 2 deletions builtin/game/item.lua
Expand Up @@ -223,9 +223,9 @@ function core.item_place_node(itemstack, placer, pointed_thing, param2)
return itemstack, false
end

local olddef_under = core.registered_nodes[oldnode_under.name]
local olddef_under = core.get_nodedef(under)
olddef_under = olddef_under or core.nodedef_default
local olddef_above = core.registered_nodes[oldnode_above.name]
local olddef_above = core.get_nodedef(above)
olddef_above = olddef_above or core.nodedef_default

if not olddef_above.buildable_to and not olddef_under.buildable_to then
Expand Down
24 changes: 12 additions & 12 deletions src/clientenvironment.cpp
Expand Up @@ -285,9 +285,9 @@ void ClientEnvironment::step(float dtime)

// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_client->ndef()->get(n);
u8 drowning_damage = c.drowning;
HybridPtr<const ContentFeatures> f_ptr = m_map->getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
u8 drowning_damage = f.drowning;
if (drowning_damage > 0 && lplayer->hp > 0) {
u16 breath = lplayer->getBreath();
if (breath > 10) {
Expand All @@ -309,11 +309,11 @@ void ClientEnvironment::step(float dtime)

// head
v3s16 p = floatToInt(pf + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_map->getNodeNoEx(p);
ContentFeatures c = m_client->ndef()->get(n);
HybridPtr<const ContentFeatures> f_ptr = m_map->getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
if (!lplayer->hp) {
lplayer->setBreath(11);
} else if (c.drowning == 0) {
} else if (f.drowning == 0) {
u16 breath = lplayer->getBreath();
if (breath <= 10) {
breath += 1;
Expand Down Expand Up @@ -669,12 +669,10 @@ ClientActiveObject * ClientEnvironment::getSelectedActiveObject(
/*
Check if a node is pointable
*/
static inline bool isPointableNode(const MapNode &n,
static inline bool isPointableNode(const ContentFeatures &f,
INodeDefManager *ndef, bool liquids_pointable)
{
const ContentFeatures &features = ndef->get(n);
return features.pointable ||
(liquids_pointable && features.isLiquid());
return f.pointable || (liquids_pointable && f.isLiquid());
}

PointedThing ClientEnvironment::getPointedThing(
Expand Down Expand Up @@ -769,12 +767,14 @@ PointedThing ClientEnvironment::getPointedThing(
bool is_valid_position;

n = m_map->getNodeNoEx(np, &is_valid_position);
HybridPtr<const ContentFeatures> f_ptr = m_map->getNodeDefNoEx(np);
const ContentFeatures &f = *f_ptr;
if (!(is_valid_position &&
isPointableNode(n, nodedef, liquids_pointable))) {
isPointableNode(f, nodedef, liquids_pointable))) {
continue;
}
std::vector<aabb3f> boxes;
n.getSelectionBoxes(nodedef, &boxes,
n.getSelectionBoxes(f, &boxes,
n.getNeighbors(np, m_map));

v3f npf = intToFloat(np, BS);
Expand Down
13 changes: 8 additions & 5 deletions src/clientmap.cpp
Expand Up @@ -706,14 +706,17 @@ void ClientMap::renderPostFx(CameraMode cam_mode)
// Sadly ISceneManager has no "post effects" render pass, in that case we
// could just register for that and handle it in renderMap().

MapNode n = getNodeNoEx(floatToInt(m_camera_position, BS));

// - If the player is in a solid node, make everything black.
// - If the player is in liquid, draw a semi-transparent overlay.
// - Do not if player is in third person mode
const ContentFeatures& features = m_nodedef->get(n);
video::SColor post_effect_color = features.post_effect_color;
if(features.solidness == 2 && !(g_settings->getBool("noclip") &&
v3s16 p = floatToInt(m_camera_position, BS);
bool is_valid_position;
HybridPtr<const ContentFeatures> f_ptr = getNodeDefNoEx(p, &is_valid_position);
if (!is_valid_position)
return;
const ContentFeatures& f = *f_ptr;
video::SColor post_effect_color = f.post_effect_color;
if(f.solidness == 2 && !(g_settings->getBool("noclip") &&
m_client->checkLocalPrivilege("noclip")) &&
cam_mode == CAMERA_MODE_FIRST)
{
Expand Down
5 changes: 3 additions & 2 deletions src/collision.cpp
Expand Up @@ -283,7 +283,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,

any_position_valid = true;
INodeDefManager *nodedef = gamedef->getNodeDefManager();
const ContentFeatures &f = nodedef->get(n);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
if(f.walkable == false)
continue;
int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
Expand Down Expand Up @@ -316,7 +317,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
}
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
n.getCollisionBoxes(f, &nodeboxes, neighbors);
for(std::vector<aabb3f>::iterator
i = nodeboxes.begin();
i != nodeboxes.end(); ++i)
Expand Down
14 changes: 7 additions & 7 deletions src/content_sao.cpp
Expand Up @@ -932,16 +932,16 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if (m_drowning_interval.step(dtime, 2.0)) {
// get head position
v3s16 p = floatToInt(m_base_position + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_env->getMap().getNodeNoEx(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
HybridPtr<const ContentFeatures> f_ptr = m_env->getMap().getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
// If node generates drown
if (c.drowning > 0 && m_hp > 0) {
if (f.drowning > 0 && m_hp > 0) {
if (m_breath > 0)
setBreath(m_breath - 1);

// No more breath, damage player
if (m_breath == 0) {
setHP(m_hp - c.drowning);
setHP(m_hp - f.drowning);
m_env->getGameDef()->SendPlayerHPOrDie(this);
}
}
Expand All @@ -950,10 +950,10 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if (m_breathing_interval.step(dtime, 0.5)) {
// get head position
v3s16 p = floatToInt(m_base_position + v3f(0, BS * 1.6, 0), BS);
MapNode n = m_env->getMap().getNodeNoEx(p);
const ContentFeatures &c = m_env->getGameDef()->ndef()->get(n);
HybridPtr<const ContentFeatures> f_ptr = m_env->getMap().getNodeDefNoEx(p);
const ContentFeatures &f = *f_ptr;
// If player is alive & no drowning, breath
if (m_hp > 0 && m_breath < PLAYER_MAX_BREATH && c.drowning == 0)
if (m_hp > 0 && m_breath < PLAYER_MAX_BREATH && f.drowning == 0)
setBreath(m_breath + 1);
}

Expand Down
13 changes: 9 additions & 4 deletions src/game.cpp
Expand Up @@ -794,14 +794,17 @@ bool nodePlacementPrediction(Client &client,
v3s16 p = neighbourpos;

// Place inside node itself if buildable_to
MapNode n_under = map.getNodeNoEx(nodepos, &is_valid_position);
HybridPtr<const ContentFeatures> f_ptr = map.getNodeDefNoEx(nodepos, &is_valid_position);
const ContentFeatures &f = *f_ptr;
if (is_valid_position)
{
if (nodedef->get(n_under).buildable_to)
if (f.buildable_to)
p = nodepos;
else {
node = map.getNodeNoEx(p, &is_valid_position);
if (is_valid_position &&!nodedef->get(node).buildable_to)
HybridPtr<const ContentFeatures> f_ptr2 = map.getNodeDefNoEx(p, &is_valid_position);
const ContentFeatures &f2 = *f_ptr2;
if (is_valid_position &&!f2.buildable_to)
return false;
}
}
Expand Down Expand Up @@ -3668,8 +3671,10 @@ PointedThing Game::updatePointedThing(
} else if (result.type == POINTEDTHING_NODE) {
// Update selection boxes
MapNode n = map.getNodeNoEx(result.node_undersurface);
HybridPtr<const ContentFeatures> f_ptr = map.getNodeDefNoEx(result.node_undersurface);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> boxes;
n.getSelectionBoxes(nodedef, &boxes,
n.getSelectionBoxes(f, &boxes,
n.getNeighbors(result.node_undersurface, &map));

f32 d = 0.002 * BS;
Expand Down
29 changes: 19 additions & 10 deletions src/localplayer.cpp
Expand Up @@ -270,13 +270,15 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
node = map->getNodeNoEx(pp, &is_valid_position);
bool is_valid_position2;
MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(pp);
HybridPtr<const ContentFeatures> f_ptr2 = map->getNodeDefNoEx(pp2, &is_valid_position2);

if (!(is_valid_position && is_valid_position2)) {
is_climbing = false;
} else {
is_climbing = (nodemgr->get(node.getContent()).climbable
|| nodemgr->get(node2.getContent()).climbable) && !free_move;
const ContentFeatures &f = *f_ptr;
const ContentFeatures &f2 = *f_ptr2;
is_climbing = (f.climbable || f2.climbable) && !free_move;
}


Expand Down Expand Up @@ -445,8 +447,10 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
if (sneak_node_found) {
// Update saved top bounding box of sneak node
MapNode n = map->getNodeNoEx(m_sneak_node);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(m_sneak_node);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(nodemgr, &nodeboxes);
n.getCollisionBoxes(f, &nodeboxes);
m_sneak_node_bb_top = getTopBoundingBox(nodeboxes);

m_sneak_ladder_detected = physics_override_sneak_glitch &&
Expand Down Expand Up @@ -908,13 +912,16 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
v3s16 pp2 = floatToInt(position + v3f(0, -0.2 * BS, 0), BS);
node = map->getNodeNoEx(pp, &is_valid_position);
bool is_valid_position2;
MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(pp);
HybridPtr<const ContentFeatures> f_ptr2 = map->getNodeDefNoEx(pp2, &is_valid_position2);

if (!(is_valid_position && is_valid_position2))
if (!(is_valid_position && is_valid_position2)) {
is_climbing = false;
else
is_climbing = (nodemgr->get(node.getContent()).climbable ||
nodemgr->get(node2.getContent()).climbable) && !free_move;
} else {
const ContentFeatures &f = *f_ptr;
const ContentFeatures &f2 = *f_ptr2;
is_climbing = (f.climbable || f2.climbable) && !free_move;
}

/*
Collision uncertainty radius
Expand Down Expand Up @@ -1049,8 +1056,10 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
if (sneak_node_found) {
f32 cb_max = 0;
MapNode n = map->getNodeNoEx(m_sneak_node);
HybridPtr<const ContentFeatures> f_ptr = map->getNodeDefNoEx(m_sneak_node);
const ContentFeatures &f = *f_ptr;
std::vector<aabb3f> nodeboxes;
n.getCollisionBoxes(nodemgr, &nodeboxes);
n.getCollisionBoxes(f, &nodeboxes);
for (std::vector<aabb3f>::iterator it = nodeboxes.begin();
it != nodeboxes.end(); ++it) {
aabb3f box = *it;
Expand Down

0 comments on commit f149938

Please sign in to comment.