add ladder block rotation

This commit is contained in:
neveix 2026-08-10 16:00:02 +05:00
parent e00038327f
commit e2806fb19c
5 changed files with 32 additions and 1 deletions

View file

@ -151,6 +151,8 @@ template<> void ContentUnitLoader<Block>::loadUnit(
def.rotations = BlockRotProfile::PANE;
} else if (profile == BlockRotProfile::STAIRS_NAME) {
def.rotations = BlockRotProfile::STAIRS;
} else if (profile == BlockRotProfile::LADDER_NAME) {
def.rotations = BlockRotProfile::LADDER;
} else if (profile != "none") {
logger.error() << "unknown rotation profile " << profile;
def.rotatable = false;

View file

@ -340,6 +340,19 @@ static int determine_rotation(
if (camDir.z > 0.0f) return BLOCK_DIR_SOUTH | verticalBit;
if (camDir.z < 0.0f) return BLOCK_DIR_NORTH | verticalBit;
}
} else if (name == "ladder") {
if (norm.x < 0.0f) return BLOCK_DIR_EAST;
if (norm.x > 0.0f) return BLOCK_DIR_WEST;
if (norm.z > 0.0f) return BLOCK_DIR_NORTH;
if (norm.z < 0.0f) return BLOCK_DIR_SOUTH;
if (abs(camDir.x) > abs(camDir.z)) {
if (camDir.x > 0.0f) return BLOCK_DIR_EAST;
if (camDir.x < 0.0f) return BLOCK_DIR_WEST;
}
if (abs(camDir.x) < abs(camDir.z)) {
if (camDir.z > 0.0f) return BLOCK_DIR_SOUTH;
if (camDir.z < 0.0f) return BLOCK_DIR_NORTH;
}
}
}
return 0;

View file

@ -109,6 +109,17 @@ const BlockRotProfile BlockRotProfile::STAIRS {
8
};
const BlockRotProfile BlockRotProfile::LADDER {
"ladder",
{
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // North
{{0, 0, -1}, {0, 1, 0}, {1, 0, 0}}, // East
{{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, // South
{{0, 0, 1}, {0, 1, 0}, {-1, 0, 0}}, // West
},
4
};
Block::Block(const std::string& name)
: name(name), caption(util::id_to_caption(name)) {
for (int i = 0; i < defaults.textureFaces.size(); i++) {

View file

@ -90,9 +90,13 @@ struct BlockRotProfile {
/// @brief Stairs, stairs and stairs
static const BlockRotProfile STAIRS;
/// @brief Ladders, wall signs, paintings
static const BlockRotProfile LADDER;
static inline std::string PIPE_NAME = "pipe";
static inline std::string PANE_NAME = "pane";
static inline std::string STAIRS_NAME = "stairs";
static inline std::string LADDER_NAME = "ladder";
};
enum class BlockModelType {

View file

@ -219,7 +219,8 @@ std::unique_ptr<VoxelFragment> VoxelFragment::rotated(const Content& content) co
| ((voxel.state.segment & 0b100) >> 2);
auto& def = content.blocks.require(blockNames[voxel.id]);
if (def.rotations.name == BlockRotProfile::PANE_NAME ||
def.rotations.name == BlockRotProfile::PIPE_NAME) {
def.rotations.name == BlockRotProfile::PIPE_NAME ||
def.rotations.name == BlockRotProfile::LADDER_NAME) {
if (voxel.state.rotation < 4) {
voxel.state.rotation = (voxel.state.rotation + 3) & 0b11;
}