Skip to content

Commit 80cec47

Browse files
sofarparamat
authored andcommittedMar 21, 2016
Fix connected nodes' selection boxes.
This allows the player to more easily target and punch connected nodeboxes, especially if they have a fixed nodebox that is very small, like technic cabling, or xpanes. Tried it on fences and my xpane conversion, and happy with the result.
1 parent 493a298 commit 80cec47

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed
 

Diff for: ‎src/game.cpp

+47-3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,49 @@ inline bool isPointableNode(const MapNode &n,
273273
(liquids_pointable && features.isLiquid());
274274
}
275275

276+
static inline void getNeighborConnectingFace(v3s16 p, INodeDefManager *nodedef,
277+
ClientMap *map, MapNode n, u8 bitmask, u8 *neighbors)
278+
{
279+
MapNode n2 = map->getNodeNoEx(p);
280+
if (nodedef->nodeboxConnects(n, n2, bitmask))
281+
*neighbors |= bitmask;
282+
}
283+
284+
static inline u8 getNeighbors(v3s16 p, INodeDefManager *nodedef, ClientMap *map, MapNode n)
285+
{
286+
u8 neighbors = 0;
287+
const ContentFeatures &f = nodedef->get(n);
288+
// locate possible neighboring nodes to connect to
289+
if (f.drawtype == NDT_NODEBOX && f.node_box.type == NODEBOX_CONNECTED) {
290+
v3s16 p2 = p;
291+
292+
p2.Y++;
293+
getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
294+
295+
p2 = p;
296+
p2.Y--;
297+
getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
298+
299+
p2 = p;
300+
p2.Z--;
301+
getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
302+
303+
p2 = p;
304+
p2.X--;
305+
getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
306+
307+
p2 = p;
308+
p2.Z++;
309+
getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
310+
311+
p2 = p;
312+
p2.X++;
313+
getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
314+
}
315+
316+
return neighbors;
317+
}
318+
276319
/*
277320
Find what the player is pointing at
278321
*/
@@ -350,8 +393,9 @@ PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_positio
350393
for (s16 x = xstart; x <= xend; x++) {
351394
MapNode n;
352395
bool is_valid_position;
396+
v3s16 p(x, y, z);
353397

354-
n = map.getNodeNoEx(v3s16(x, y, z), &is_valid_position);
398+
n = map.getNodeNoEx(p, &is_valid_position);
355399
if (!is_valid_position) {
356400
continue;
357401
}
@@ -360,7 +404,7 @@ PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_positio
360404
}
361405

362406
std::vector<aabb3f> boxes;
363-
n.getSelectionBoxes(nodedef, &boxes);
407+
n.getSelectionBoxes(nodedef, &boxes, getNeighbors(p, nodedef, &map, n));
364408

365409
v3s16 np(x, y, z);
366410
v3f npf = intToFloat(np, BS);
@@ -392,7 +436,7 @@ PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_positio
392436
MapNode n = map.getNodeNoEx(pointed_pos);
393437
v3f npf = intToFloat(pointed_pos, BS);
394438
std::vector<aabb3f> boxes;
395-
n.getSelectionBoxes(nodedef, &boxes);
439+
n.getSelectionBoxes(nodedef, &boxes, getNeighbors(pointed_pos, nodedef, &map, n));
396440
f32 face_min_distance = 1000 * BS;
397441
for (std::vector<aabb3f>::const_iterator
398442
i = boxes.begin();

Diff for: ‎src/mapnode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,10 @@ void MapNode::getCollisionBoxes(INodeDefManager *nodemgr, std::vector<aabb3f> *b
456456
transformNodeBox(*this, f.collision_box, nodemgr, boxes, neighbors);
457457
}
458458

459-
void MapNode::getSelectionBoxes(INodeDefManager *nodemgr, std::vector<aabb3f> *boxes)
459+
void MapNode::getSelectionBoxes(INodeDefManager *nodemgr, std::vector<aabb3f> *boxes, u8 neighbors)
460460
{
461461
const ContentFeatures &f = nodemgr->get(*this);
462-
transformNodeBox(*this, f.selection_box, nodemgr, boxes);
462+
transformNodeBox(*this, f.selection_box, nodemgr, boxes, neighbors);
463463
}
464464

465465
u8 MapNode::getMaxLevel(INodeDefManager *nodemgr) const

Diff for: ‎src/mapnode.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct MapNode
245245
/*
246246
Gets list of selection boxes
247247
*/
248-
void getSelectionBoxes(INodeDefManager *nodemg, std::vector<aabb3f> *boxes);
248+
void getSelectionBoxes(INodeDefManager *nodemg, std::vector<aabb3f> *boxes, u8 neighbors = 0);
249249

250250
/*
251251
Gets list of collision boxes

0 commit comments

Comments
 (0)
Please sign in to comment.