[Block] Now possible to change grass into dirt.
This commit is contained in:
parent
b8239c2f22
commit
46fb26ab76
@ -18,10 +18,14 @@
|
||||
|
||||
#include "Types.hpp"
|
||||
|
||||
class Chunk;
|
||||
|
||||
class Block {
|
||||
public:
|
||||
Block(u32 id);
|
||||
|
||||
bool onClickEvent(Chunk *chunk);
|
||||
|
||||
glm::vec4 getTexCoords(int face) const;
|
||||
|
||||
u32 id() const { return m_id; }
|
||||
|
@ -99,6 +99,13 @@ void BlockCursor::onEvent(const SDL_Event &event) {
|
||||
m_world.setBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z, 0);
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_RIGHT) {
|
||||
Block *block = m_world.getBlock(m_selectedBlock.x, m_selectedBlock.y, m_selectedBlock.z);
|
||||
|
||||
Chunk *chunk = m_world.getChunk(m_selectedBlock.x / Chunk::width,
|
||||
m_selectedBlock.y / Chunk::height,
|
||||
m_selectedBlock.z / Chunk::depth);
|
||||
|
||||
if (block && !block->onClickEvent(chunk)) {
|
||||
int face = m_selectedBlock.w;
|
||||
|
||||
int x = m_selectedBlock.x;
|
||||
@ -116,6 +123,7 @@ void BlockCursor::onEvent(const SDL_Event &event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BlockCursor::update(bool useDepthBuffer) {
|
||||
m_selectedBlock = findSelectedBlock(useDepthBuffer);
|
||||
|
@ -17,6 +17,20 @@ Block::Block(u32 id) {
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
#include "Chunk.hpp"
|
||||
|
||||
bool Block::onClickEvent(Chunk *chunk) {
|
||||
if (m_id == 3) {
|
||||
m_id = 1;
|
||||
|
||||
chunk->setChanged(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
glm::vec4 Block::getTexCoords(int face) const {
|
||||
u32 id = m_id;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user