block tick interval

This commit is contained in:
MihailRis 2024-05-31 18:14:50 +03:00
parent e969d4fea2
commit 7b0e31951b
3 changed files with 10 additions and 2 deletions

View File

@ -212,6 +212,10 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
root->str("script-name", def.scriptName);
root->str("ui-layout", def.uiLayout);
root->num("inventory-size", def.inventorySize);
root->num("tick-interval", def.tickInterval);
if (def.tickInterval == 0) {
def.tickInterval = 1;
}
if (def.hidden && def.pickingItem == def.name+BLOCK_ITEM_SUFFIX) {
def.pickingItem = CORE_EMPTY;

View File

@ -113,8 +113,9 @@ void BlocksController::onBlocksTick(int tickid, int parts) {
if ((id + tickid) % parts != 0)
continue;
auto def = indices->getBlockDef(id);
if (def->rt.funcsset.onblockstick) {
scripting::on_blocks_tick(def, tickRate);
auto interval = def->tickInterval;
if (def->rt.funcsset.onblockstick && tickid / parts % interval == 0) {
scripting::on_blocks_tick(def, tickRate / interval);
}
}
}

View File

@ -162,6 +162,9 @@ public:
/// @brief Block inventory size. 0 - no inventory
uint inventorySize = 0;
// @brief Block tick interval (1 - 20tps, 2 - 10tps)
uint tickInterval = 1;
/// @brief Runtime indices (content indexing results)
struct {
/// @brief block runtime integer id