From ee77b8cf96525f0db007b170b6e96f055cba4d33 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 14 Sep 2015 09:11:32 +0200 Subject: [PATCH] fix block placement --- src/ui/ui.cpp | 8 ++++---- src/world/BlockLookup.hpp | 1 + src/world/WorldCollision.hpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 3994298..02f372e 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -396,9 +396,9 @@ void Interface::PickBlock() { void Interface::PlaceBlock() { if (!aim_world) return; - glm::vec3 next_pos = aim_world.BlockCoords() + aim_world.normal; - BlockLookup next_block(&aim_world.GetChunk(), next_pos); - if (next_block) { + BlockLookup next_block(aim_world.chunk, aim_world.BlockPos(), Block::NormalFace(aim_world.normal)); + if (!next_block) { + return; } next_block.SetBlock(selection); @@ -406,7 +406,7 @@ void Interface::PlaceBlock() { const Entity &player = ctrl.Controlled(); env.audio.Play( place_sound, - aim_world.GetChunk().ToSceneCoords(player.ChunkCoords(), next_pos) + next_block.GetChunk().ToSceneCoords(player.ChunkCoords(), next_block.GetBlockCoords()) ); } diff --git a/src/world/BlockLookup.hpp b/src/world/BlockLookup.hpp index 122b3c7..e861b24 100644 --- a/src/world/BlockLookup.hpp +++ b/src/world/BlockLookup.hpp @@ -22,6 +22,7 @@ public: // only valid if lookup was successful Chunk &GetChunk() const noexcept { return *chunk; } const Chunk::Pos &GetBlockPos() const noexcept { return pos; } + Block::Pos GetBlockCoords() const noexcept { return Chunk::ToCoords(pos); } const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); } const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); } int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); } diff --git a/src/world/WorldCollision.hpp b/src/world/WorldCollision.hpp index 3c81595..dd3f332 100644 --- a/src/world/WorldCollision.hpp +++ b/src/world/WorldCollision.hpp @@ -35,7 +35,7 @@ struct WorldCollision { bool Blocks() const noexcept { return chunk->Type(block).collide_block; } - glm::vec3 BlockPos() const noexcept { return Chunk::ToPos(block); } + glm::ivec3 BlockPos() const noexcept { return Chunk::ToPos(block); } glm::vec3 BlockCoords() const noexcept { return Chunk::ToCoords(block); } glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); } -- 2.39.2