1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

Add rotation support for wallmounted nodes in 'ceiling' or 'floor' mode (#11073)

This commit is contained in:
Wuzzy 2024-01-17 17:47:06 +01:00 committed by GitHub
parent e7dd9737bd
commit 08ee6d8d4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 375 additions and 33 deletions

View file

@ -1008,7 +1008,9 @@ void MapblockMeshGenerator::drawTorchlikeNode()
switch (wall) {
case DWM_YP: tileindex = 1; break; // ceiling
case DWM_YN: tileindex = 0; break; // floor
default: tileindex = 2; // side (or invalid—should we care?)
case DWM_S1: tileindex = 1; break; // ceiling, but rotated
case DWM_S2: tileindex = 0; break; // floor, but rotated
default: tileindex = 2; // side (or invalid, shouldn't happen)
}
useTile(tileindex, MATERIAL_FLAG_CRACK_OVERLAY, MATERIAL_FLAG_BACKFACE_CULLING);
@ -1044,6 +1046,17 @@ void MapblockMeshGenerator::drawTorchlikeNode()
case DWM_ZN:
vertex.X += -size + BS/2;
vertex.rotateXZBy(-90);
break;
case DWM_S1:
// same as DWM_YP, but rotated 90°
vertex.Y += -size + BS/2;
vertex.rotateXZBy(45);
break;
case DWM_S2:
// same as DWM_YN, but rotated -90°
vertex.Y += size - BS/2;
vertex.rotateXZBy(-45);
break;
}
}
drawQuad(vertices);
@ -1077,6 +1090,10 @@ void MapblockMeshGenerator::drawSignlikeNode()
vertex.rotateXZBy( 90); break;
case DWM_ZN:
vertex.rotateXZBy(-90); break;
case DWM_S1:
vertex.rotateXYBy( 90); vertex.rotateXZBy(90); break;
case DWM_S2:
vertex.rotateXYBy(-90); vertex.rotateXZBy(-90); break;
}
}
drawQuad(vertices);

View file

@ -3704,7 +3704,36 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
v3s16 dir = nodepos - neighborpos;
if (abs(dir.Y) > MYMAX(abs(dir.X), abs(dir.Z))) {
predicted_node.setParam2(dir.Y < 0 ? 1 : 0);
// If you change this code, also change builtin/game/item.lua
u8 predicted_param2 = dir.Y < 0 ? 1 : 0;
if (selected_def.wallmounted_rotate_vertical) {
bool rotate90 = false;
v3f fnodepos = v3f(neighborpos.X, neighborpos.Y, neighborpos.Z);
v3f ppos = client->getEnv().getLocalPlayer()->getPosition() / BS;
v3f pdir = fnodepos - ppos;
switch (predicted_f.drawtype) {
case NDT_TORCHLIKE: {
rotate90 = !((pdir.X < 0 && pdir.Z > 0) ||
(pdir.X > 0 && pdir.Z < 0));
if (dir.Y > 0) {
rotate90 = !rotate90;
}
break;
};
case NDT_SIGNLIKE: {
rotate90 = abs(pdir.X) < abs(pdir.Z);
break;
}
default: {
rotate90 = abs(pdir.X) > abs(pdir.Z);
break;
}
}
if (rotate90) {
predicted_param2 += 6;
}
}
predicted_node.setParam2(predicted_param2);
} else if (abs(dir.X) > abs(dir.Z)) {
predicted_node.setParam2(dir.X < 0 ? 3 : 2);
} else {