]> git.localhorst.tv Git - blank.git/commitdiff
fix block placement
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 14 Sep 2015 07:11:32 +0000 (09:11 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 14 Sep 2015 07:11:32 +0000 (09:11 +0200)
src/ui/ui.cpp
src/world/BlockLookup.hpp
src/world/WorldCollision.hpp

index 39942987f6375a243fd0412572cffbc8201bf3fe..02f372e5c66c57d7a827362814dc61c97aa66bc1 100644 (file)
@@ -396,9 +396,9 @@ void Interface::PickBlock() {
 void Interface::PlaceBlock() {
        if (!aim_world) return;
 
 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);
 
        }
        next_block.SetBlock(selection);
 
@@ -406,7 +406,7 @@ void Interface::PlaceBlock() {
        const Entity &player = ctrl.Controlled();
        env.audio.Play(
                place_sound,
        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())
        );
 }
 
        );
 }
 
index 122b3c76f7e76374eaf50aa264513d54564b43c6..e861b249efd628b8c4dc83b74ef792e2fab97cd3 100644 (file)
@@ -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; }
        // 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()); }
        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()); }
index 3c81595b714d9bd94104048633950a98da9a4a1a..dd3f332c8f94854c405a02ccb8803a62e4fe179c 100644 (file)
@@ -35,7 +35,7 @@ struct WorldCollision {
 
        bool Blocks() const noexcept { return chunk->Type(block).collide_block; }
 
 
        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); }
 
        glm::vec3 BlockCoords() const noexcept { return Chunk::ToCoords(block); }
        glm::mat4 BlockTransform() const noexcept { return GetChunk().ToTransform(BlockPos(), block); }