diff --git a/res/content/base/blocks/glass.json b/res/content/base/blocks/glass.json index c782c0c8f..c56bdd558 100644 --- a/res/content/base/blocks/glass.json +++ b/res/content/base/blocks/glass.json @@ -1,5 +1,6 @@ { "texture": "glass", "draw-group": 2, - "light-passing": true -} \ No newline at end of file + "light-passing": true, + "sky-light-passing": true +} diff --git a/src/lighting/LightSolver.cpp b/src/lighting/LightSolver.cpp index d103b65b2..12e09d5da 100644 --- a/src/lighting/LightSolver.cpp +++ b/src/lighting/LightSolver.cpp @@ -58,9 +58,11 @@ void LightSolver::solve(){ remqueue.pop(); for (int i = 0; i < 6; i++) { - int x = entry.x+coords[i*3+0]; - int y = entry.y+coords[i*3+1]; - int z = entry.z+coords[i*3+2]; + int imul3 = i*3; + int x = entry.x+coords[imul3]; + int y = entry.y+coords[imul3+1]; + int z = entry.z+coords[imul3+2]; + Chunk* chunk = chunks->getChunkByVoxel(x,y,z); if (chunk) { int lx = x - chunk->x * CHUNK_W; @@ -85,9 +87,11 @@ void LightSolver::solve(){ addqueue.pop(); for (int i = 0; i < 6; i++) { - int x = entry.x+coords[i*3+0]; - int y = entry.y+coords[i*3+1]; - int z = entry.z+coords[i*3+2]; + int imul3 = i*3; + int x = entry.x+coords[imul3]; + int y = entry.y+coords[imul3+1]; + int z = entry.z+coords[imul3+2]; + Chunk* chunk = chunks->getChunkByVoxel(x,y,z); if (chunk) { int lx = x - chunk->x * CHUNK_W; diff --git a/src/lighting/Lighting.cpp b/src/lighting/Lighting.cpp index 6433db4f1..a79b066d7 100644 --- a/src/lighting/Lighting.cpp +++ b/src/lighting/Lighting.cpp @@ -152,10 +152,11 @@ void Lighting::onChunkLoaded(int cx, int cz, bool expand){ void Lighting::onBlockSet(int x, int y, int z, blockid_t id){ Block* block = content->getIndices()->getBlockDef(id); + solverR->remove(x,y,z); + solverG->remove(x,y,z); + solverB->remove(x,y,z); + if (id == 0){ - solverR->remove(x,y,z); - solverG->remove(x,y,z); - solverB->remove(x,y,z); solverR->solve(); solverG->solve(); solverB->solve(); @@ -178,9 +179,6 @@ void Lighting::onBlockSet(int x, int y, int z, blockid_t id){ solverB->solve(); solverS->solve(); } else { - solverR->remove(x,y,z); - solverG->remove(x,y,z); - solverB->remove(x,y,z); if (!block->skyLightPassing){ solverS->remove(x,y,z); for (int i = y-1; i >= 0; i--){ diff --git a/src/logic/scripting/lua/api_lua.cpp b/src/logic/scripting/lua/api_lua.cpp index dd47dab44..54ef69097 100644 --- a/src/logic/scripting/lua/api_lua.cpp +++ b/src/logic/scripting/lua/api_lua.cpp @@ -90,6 +90,78 @@ int l_file_mkdir(lua_State* L) { return 1; } +int l_file_mkdirs(lua_State* L) { + fs::path path = resolve_path(L, lua_tostring(L, 1)); + lua_pushboolean(L, fs::create_directories(path)); + return 1; +} + +int l_file_read_bytes(lua_State* L) { + fs::path path = resolve_path(L, lua_tostring(L, 1)); + if (fs::is_regular_file(path)) { + size_t length = (size_t) fs::file_size(path); + + ubyte* bytes = files::read_bytes(path, length); + + lua_createtable(L, length, 0); + int newTable = lua_gettop(L); + + for(int i = 0;i < length;i++) { + lua_pushnumber(L, bytes[i]); + lua_rawseti(L, newTable, i+1); + } + return 1; + } + return luaL_error(L, "file does not exists '%s'", path.u8string().c_str()); +} + +int l_file_write_bytes(lua_State* L) { + int pathIndex = 1; + + if(!lua_isstring(L, pathIndex)) { + return luaL_error(L, "string expected"); + } + + fs::path path = resolve_path(L, lua_tostring(L, pathIndex)); + + std::vector bytes; + + size_t len = lua_objlen(L, 2); + + int bytesIndex = -1; + + if(!lua_istable(L, bytesIndex)) { + return luaL_error(L, "table expected"); + } else { + lua_pushnil(L); + + bytesIndex--; + + int i = 1; + + while(lua_next(L, bytesIndex) != 0) { + if(lua_isnumber(L, -1)) { + const int byte = lua_tointeger(L, -1); + + if(byte < 0 || byte > 255) { + return luaL_error(L, "byte '%i' at index '%i' is less than 0 or greater than 255", byte, i); + } + + bytes.push_back(byte); + + lua_pop(L, 1); + + i++; + } else { + return luaL_error(L, "number expected at index '%i'", i); + } + } + + lua_pushboolean(L, files::write_bytes(path, &bytes[0], len)); + return 1; + } +} + /* == time library == */ int l_time_uptime(lua_State* L) { lua_pushnumber(L, Window::time()); diff --git a/src/logic/scripting/lua/api_lua.h b/src/logic/scripting/lua/api_lua.h index 27fd4c855..aecadf06e 100644 --- a/src/logic/scripting/lua/api_lua.h +++ b/src/logic/scripting/lua/api_lua.h @@ -13,6 +13,9 @@ extern int l_file_isfile(lua_State* L); extern int l_file_isdir(lua_State* L); extern int l_file_length(lua_State* L); extern int l_file_mkdir(lua_State* L); +extern int l_file_mkdirs(lua_State* L); +extern int l_file_read_bytes(lua_State* L); +extern int l_file_write_bytes(lua_State* L); static const luaL_Reg filelib [] = { {"resolve", lua_wrap_errors}, @@ -23,6 +26,9 @@ static const luaL_Reg filelib [] = { {"isdir", lua_wrap_errors}, {"length", lua_wrap_errors}, {"mkdir", lua_wrap_errors}, + {"mkdirs", lua_wrap_errors}, + {"read_bytes", lua_wrap_errors}, + {"write_bytes", lua_wrap_errors}, {NULL, NULL} };