mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 23:11:49 +00:00
add ladder block rotation
This commit is contained in:
parent
e00038327f
commit
e2806fb19c
5 changed files with 32 additions and 1 deletions
|
|
@ -151,6 +151,8 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
||||||
def.rotations = BlockRotProfile::PANE;
|
def.rotations = BlockRotProfile::PANE;
|
||||||
} else if (profile == BlockRotProfile::STAIRS_NAME) {
|
} else if (profile == BlockRotProfile::STAIRS_NAME) {
|
||||||
def.rotations = BlockRotProfile::STAIRS;
|
def.rotations = BlockRotProfile::STAIRS;
|
||||||
|
} else if (profile == BlockRotProfile::LADDER_NAME) {
|
||||||
|
def.rotations = BlockRotProfile::LADDER;
|
||||||
} else if (profile != "none") {
|
} else if (profile != "none") {
|
||||||
logger.error() << "unknown rotation profile " << profile;
|
logger.error() << "unknown rotation profile " << profile;
|
||||||
def.rotatable = false;
|
def.rotatable = false;
|
||||||
|
|
|
||||||
|
|
@ -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_SOUTH | verticalBit;
|
||||||
if (camDir.z < 0.0f) return BLOCK_DIR_NORTH | 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;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,17 @@ const BlockRotProfile BlockRotProfile::STAIRS {
|
||||||
8
|
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)
|
Block::Block(const std::string& name)
|
||||||
: name(name), caption(util::id_to_caption(name)) {
|
: name(name), caption(util::id_to_caption(name)) {
|
||||||
for (int i = 0; i < defaults.textureFaces.size(); i++) {
|
for (int i = 0; i < defaults.textureFaces.size(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -90,9 +90,13 @@ struct BlockRotProfile {
|
||||||
/// @brief Stairs, stairs and stairs
|
/// @brief Stairs, stairs and stairs
|
||||||
static const BlockRotProfile 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 PIPE_NAME = "pipe";
|
||||||
static inline std::string PANE_NAME = "pane";
|
static inline std::string PANE_NAME = "pane";
|
||||||
static inline std::string STAIRS_NAME = "stairs";
|
static inline std::string STAIRS_NAME = "stairs";
|
||||||
|
static inline std::string LADDER_NAME = "ladder";
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BlockModelType {
|
enum class BlockModelType {
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,8 @@ std::unique_ptr<VoxelFragment> VoxelFragment::rotated(const Content& content) co
|
||||||
| ((voxel.state.segment & 0b100) >> 2);
|
| ((voxel.state.segment & 0b100) >> 2);
|
||||||
auto& def = content.blocks.require(blockNames[voxel.id]);
|
auto& def = content.blocks.require(blockNames[voxel.id]);
|
||||||
if (def.rotations.name == BlockRotProfile::PANE_NAME ||
|
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) {
|
if (voxel.state.rotation < 4) {
|
||||||
voxel.state.rotation = (voxel.state.rotation + 3) & 0b11;
|
voxel.state.rotation = (voxel.state.rotation + 3) & 0b11;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue