Merge pull request #1040 from MihailRis/world-logic-configuration

world logic configuration
This commit is contained in:
MihailRis 2026-10-15 12:12:33 +03:00 • committed by GitHub
commit 4354896008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 140 additions and 12 deletions

View file

@ -130,14 +130,26 @@ void BlocksController::updateBlock(int x, int y, int z) {
}
void BlocksController::update(float delta, uint padding) {
if (int parts = randTickClock.update(delta)) {
for (int i = 0; i < parts; i++) {
randomTick(randTickClock.convertPart(i), randTickClock.getParts(), padding);
auto& worldInfo = level.getWorld().getInfo();
if (worldInfo.getLogicFlag("random_ticks", true)) {
if (int parts = randTickClock.update(delta)) {
for (int i = 0; i < parts; i++) {
randomTick(
randTickClock.convertPart(i),
randTickClock.getParts(),
padding
);
}
}
}
if (int parts = blocksTickClock.update(delta)) {
for (int i = 0; i < parts; i++) {
onBlocksTick(blocksTickClock.convertPart(i), blocksTickClock.getParts());
if (worldInfo.getLogicFlag("block_ticks", true)) {
if (int parts = blocksTickClock.update(delta)) {
for (int i = 0; i < parts; i++) {
onBlocksTick(
blocksTickClock.convertPart(i), blocksTickClock.getParts()
);
}
}
}
if (worldTickClock.update(delta)) {

View file

@ -108,6 +108,17 @@ static int l_get_seed(lua::State* L) {
return lua::pushinteger(L, require_world_info().seed);
}
static int l_get_logic(lua::State* L) {
auto name = lua::require_string(L, 1);
return lua::pushvalue(L, require_world_info().getLogicValue(name));
}
static int l_set_logic(lua::State* L) {
auto name = lua::require_string(L, 1);
require_world_info().setLogicValue(name, lua::tovalue(L, 2));
return 0;
}
static int l_exists(lua::State* L) {
auto name = lua::require_string(L, 1);
auto worldsDir = engine->getPaths().getWorldFolderByName(name);
@ -250,6 +261,8 @@ const luaL_Reg worldlib[] = {
{"set_day_time_speed", lua::wrap<l_set_day_time_speed>},
{"get_day_time_speed", lua::wrap<l_get_day_time_speed>},
{"get_seed", lua::wrap<l_get_seed>},
{"get_logic", lua::wrap<l_get_logic>},
{"set_logic", lua::wrap<l_set_logic>},
{"get_generator", lua::wrap<l_get_generator>},
{"is_day", lua::wrap<l_is_day>},
{"is_night", lua::wrap<l_is_night>},