refactor Content
This commit is contained in:
@@ -83,7 +83,7 @@ void BlocksController::updateBlock(int x, int y, int z) {
|
||||
voxel* vox = chunks->get(x, y, z);
|
||||
if (vox == nullptr)
|
||||
return;
|
||||
const Block* def = level->content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (def->grounded && !chunks->isSolidBlock(x, y-1, z)) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
@@ -109,10 +109,10 @@ void BlocksController::onBlocksTick(int tickid, int parts) {
|
||||
auto content = level->content;
|
||||
auto indices = content->getIndices();
|
||||
int tickRate = blocksTickClock.getTickRate();
|
||||
for (size_t id = 0; id < indices->countBlockDefs(); id++) {
|
||||
for (size_t id = 0; id < indices->blocks.count(); id++) {
|
||||
if ((id + tickid) % parts != 0)
|
||||
continue;
|
||||
auto def = indices->getBlockDef(id);
|
||||
auto def = indices->blocks.get(id);
|
||||
auto interval = def->tickInterval;
|
||||
if (def->rt.funcsset.onblockstick && tickid / parts % interval == 0) {
|
||||
scripting::on_blocks_tick(def, tickRate / interval);
|
||||
@@ -143,7 +143,7 @@ void BlocksController::randomTick(int tickid, int parts) {
|
||||
int by = random.rand() % segheight + s * segheight;
|
||||
int bz = random.rand() % CHUNK_D;
|
||||
const voxel& vox = chunk->voxels[(by * CHUNK_D + bz) * CHUNK_W + bx];
|
||||
Block* block = indices->getBlockDef(vox.id);
|
||||
Block* block = indices->blocks.get(vox.id);
|
||||
if (block->rt.funcsset.randupdate) {
|
||||
scripting::random_update_block(
|
||||
block,
|
||||
@@ -167,7 +167,7 @@ int64_t BlocksController::createBlockInventory(int x, int y, int z) {
|
||||
auto inv = chunk->getBlockInventory(lx, y, lz);
|
||||
if (inv == nullptr) {
|
||||
auto indices = level->content->getIndices();
|
||||
auto def = indices->getBlockDef(chunk->voxels[vox_index(lx, y, lz)].id);
|
||||
auto def = indices->blocks.get(chunk->voxels[vox_index(lx, y, lz)].id);
|
||||
int invsize = def->inventorySize;
|
||||
if (invsize == 0) {
|
||||
return 0;
|
||||
|
||||
@@ -203,7 +203,7 @@ void PlayerController::onFootstep() {
|
||||
int z = std::floor(pos.z+half.z*offsetZ);
|
||||
auto vox = level->chunks->get(x, y, z);
|
||||
if (vox) {
|
||||
auto def = level->content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (!def->obstacle)
|
||||
continue;
|
||||
onBlockInteraction(
|
||||
@@ -317,7 +317,7 @@ static int determine_rotation(Block* def, const glm::ivec3& norm, glm::vec3& cam
|
||||
}
|
||||
|
||||
static void pick_block(ContentIndices* indices, Chunks* chunks, Player* player, int x, int y, int z) {
|
||||
Block* block = indices->getBlockDef(chunks->get(x,y,z)->id);
|
||||
auto block = indices->blocks.get(chunks->get(x,y,z)->id);
|
||||
itemid_t id = block->rt.pickingItem;
|
||||
auto inventory = player->getInventory();
|
||||
size_t slotid = inventory->findSlotByItem(id, 0, 10);
|
||||
@@ -356,7 +356,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
||||
selection.actualPosition = iend;
|
||||
if (selectedState.segment) {
|
||||
selection.position = chunks->seekOrigin(
|
||||
iend, indices->getBlockDef(selection.vox.id), selectedState
|
||||
iend, indices->blocks.get(selection.vox.id), selectedState
|
||||
);
|
||||
auto origin = chunks->get(iend);
|
||||
if (origin && origin->id != vox->id) {
|
||||
@@ -430,7 +430,7 @@ void PlayerController::updateInteraction() {
|
||||
|
||||
auto inventory = player->getInventory();
|
||||
const ItemStack& stack = inventory->getSlot(player->getChosenSlot());
|
||||
ItemDef* item = indices->getItemDef(stack.getItemId());
|
||||
ItemDef* item = indices->items.get(stack.getItemId());
|
||||
|
||||
auto vox = updateSelection(maxDistance);
|
||||
if (vox == nullptr) {
|
||||
@@ -446,7 +446,7 @@ void PlayerController::updateInteraction() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto target = indices->getBlockDef(vox->id);
|
||||
auto target = indices->blocks.get(vox->id);
|
||||
if (lclick && target->breakable){
|
||||
onBlockInteraction(
|
||||
iend, target,
|
||||
@@ -467,7 +467,7 @@ void PlayerController::updateInteraction() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto def = indices->getBlockDef(item->rt.placingBlock);
|
||||
auto def = indices->blocks.get(item->rt.placingBlock);
|
||||
if (def && rclick) {
|
||||
processRightClick(def, target);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ using namespace scripting;
|
||||
static Block* require_block(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
if (static_cast<size_t>(id) >= indices->blocks.count()) {
|
||||
return nullptr;
|
||||
}
|
||||
return indices->getBlockDef(id);
|
||||
return indices->blocks.get(id);
|
||||
}
|
||||
|
||||
static int l_name(lua::State* L) {
|
||||
@@ -43,12 +43,12 @@ static int l_is_solid_at(lua::State* L) {
|
||||
}
|
||||
|
||||
static int l_count(lua::State* L) {
|
||||
return lua::pushinteger(L, indices->countBlockDefs());
|
||||
return lua::pushinteger(L, indices->blocks.count());
|
||||
}
|
||||
|
||||
static int l_index(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, content->requireBlock(name).rt.id);
|
||||
return lua::pushinteger(L, content->blocks.require(name).rt.id);
|
||||
}
|
||||
|
||||
static int l_is_extended(lua::State* L) {
|
||||
@@ -78,7 +78,7 @@ static int l_seek_origin(lua::State* L) {
|
||||
auto y = lua::tointeger(L, 2);
|
||||
auto z = lua::tointeger(L, 3);
|
||||
auto vox = level->chunks->get(x, y, z);
|
||||
auto def = indices->getBlockDef(vox->id);
|
||||
auto def = indices->blocks.get(vox->id);
|
||||
return lua::pushivec3(L, level->chunks->seekOrigin({x, y, z}, def, vox->state));
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ static int l_set(lua::State* L) {
|
||||
auto id = lua::tointeger(L, 4);
|
||||
auto state = lua::tointeger(L, 5);
|
||||
bool noupdate = lua::toboolean(L, 6);
|
||||
if (static_cast<size_t>(id) >= indices->countBlockDefs()) {
|
||||
if (static_cast<size_t>(id) >= indices->blocks.count()) {
|
||||
return 0;
|
||||
}
|
||||
if (!level->chunks->get(x, y, z)) {
|
||||
@@ -120,7 +120,7 @@ static int l_get_x(lua::State* L) {
|
||||
if (vox == nullptr) {
|
||||
return lua::pushivec3(L, 1, 0, 0);
|
||||
}
|
||||
auto def = level->content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 1, 0, 0);
|
||||
} else {
|
||||
@@ -137,7 +137,7 @@ static int l_get_y(lua::State* L) {
|
||||
if (vox == nullptr) {
|
||||
return lua::pushivec3(L, 0, 1, 0);
|
||||
}
|
||||
auto def = level->content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 0, 1, 0);
|
||||
} else {
|
||||
@@ -154,7 +154,7 @@ static int l_get_z(lua::State* L) {
|
||||
if (vox == nullptr) {
|
||||
return lua::pushivec3(L, 0, 0, 1);
|
||||
}
|
||||
auto def = level->content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = level->content->getIndices()->blocks.get(vox->id);
|
||||
if (!def->rotatable) {
|
||||
return lua::pushivec3(L, 0, 0, 1);
|
||||
} else {
|
||||
|
||||
@@ -49,7 +49,7 @@ static int l_hud_open_block(lua::State* L) {
|
||||
std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z)
|
||||
);
|
||||
}
|
||||
auto def = content->getIndices()->getBlockDef(vox->id);
|
||||
auto def = content->getIndices()->blocks.get(vox->id);
|
||||
auto assets = engine->getAssets();
|
||||
auto layout = assets->get<UiDocument>(def->uiLayout);
|
||||
if (layout == nullptr) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
using namespace scripting;
|
||||
|
||||
static void validate_itemid(itemid_t id) {
|
||||
if (id >= indices->countItemDefs()) {
|
||||
if (id >= indices->items.count()) {
|
||||
throw std::runtime_error("invalid item id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,30 +8,30 @@ using namespace scripting;
|
||||
static int l_item_name(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countItemDefs()) {
|
||||
if (static_cast<size_t>(id) >= indices->items.count()) {
|
||||
return 0;
|
||||
}
|
||||
auto def = indices->getItemDef(id);
|
||||
auto def = indices->items.get(id);
|
||||
return lua::pushstring(L, def->name);
|
||||
}
|
||||
|
||||
static int l_item_index(lua::State* L) {
|
||||
auto name = lua::require_string(L, 1);
|
||||
return lua::pushinteger(L, content->requireItem(name).rt.id);
|
||||
return lua::pushinteger(L, content->items.require(name).rt.id);
|
||||
}
|
||||
|
||||
static int l_item_stack_size(lua::State* L) {
|
||||
auto indices = content->getIndices();
|
||||
auto id = lua::tointeger(L, 1);
|
||||
if (static_cast<size_t>(id) >= indices->countItemDefs()) {
|
||||
if (static_cast<size_t>(id) >= indices->items.count()) {
|
||||
return 0;
|
||||
}
|
||||
auto def = indices->getItemDef(id);
|
||||
auto def = indices->items.get(id);
|
||||
return lua::pushinteger(L, def->stackSize);
|
||||
}
|
||||
|
||||
static int l_item_defs_count(lua::State* L) {
|
||||
return lua::pushinteger(L, indices->countItemDefs());
|
||||
return lua::pushinteger(L, indices->items.count());
|
||||
}
|
||||
|
||||
const luaL_Reg itemlib [] = {
|
||||
|
||||
Reference in New Issue
Block a user