87 lines
2.9 KiB
C++
Raw Normal View History

2014-12-18 07:02:48 +01:00
/*
* =====================================================================================
*
* OpenMiner
*
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <openminer@unarelith.net>
* Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md)
*
* This file is part of OpenMiner.
2014-12-18 07:02:48 +01:00
*
* OpenMiner is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
2014-12-18 07:02:48 +01:00
*
* OpenMiner is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2014-12-18 07:02:48 +01:00
*
* You should have received a copy of the GNU Lesser General Public License
* along with OpenMiner; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2014-12-18 07:02:48 +01:00
*
* =====================================================================================
*/
#include <glm/gtc/matrix_transform.hpp>
2018-12-29 02:23:23 +01:00
#include <gk/resource/ResourceHandler.hpp>
#include "EngineConfig.hpp"
2014-12-18 07:02:48 +01:00
#include "World.hpp"
bool World::isReloadRequested = false;
Chunk *World::getChunkAtBlockPos(int x, int y, int z) const {
return getChunk(
(x & -CHUNK_WIDTH) / CHUNK_WIDTH,
(y & -CHUNK_DEPTH) / CHUNK_DEPTH,
(z & -CHUNK_HEIGHT) / CHUNK_HEIGHT
);
}
BlockData *World::getBlockData(int x, int y, int z) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
return chunk->getBlockData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1));
return nullptr;
}
2020-02-07 23:15:44 +09:00
BlockData *World::addBlockData(int x, int y, int z, int inventoryWidth, int inventoryHeight) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
return chunk->addBlockData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), inventoryWidth, inventoryHeight);
2020-02-07 23:15:44 +09:00
return nullptr;
}
u16 World::getBlock(int x, int y, int z) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
return chunk->getBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1));
return 0;
}
void World::setBlock(int x, int y, int z, u16 id) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
chunk->setBlock(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), id);
}
u16 World::getData(int x, int y, int z) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
return chunk->getData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1));
return 0;
}
void World::setData(int x, int y, int z, u16 data) const {
Chunk *chunk = getChunkAtBlockPos(x, y, z);
if (chunk)
chunk->setData(x & (CHUNK_WIDTH - 1), y & (CHUNK_DEPTH - 1), z & (CHUNK_HEIGHT - 1), data);
}