From 5c248c2d7de3db54e85f7c388743a2eb8e36fee4 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sat, 3 Sep 2022 22:05:07 -0400 Subject: Add callback on_mapblocks_changed --- builtin/game/misc_s.lua | 5 ++--- builtin/game/register.lua | 11 +++++++++++ builtin/profiler/instrumentation.lua | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/game/misc_s.lua b/builtin/game/misc_s.lua index 67a0ec684..93d2bafa8 100644 --- a/builtin/game/misc_s.lua +++ b/builtin/game/misc_s.lua @@ -8,10 +8,9 @@ -- Misc. API functions -- +-- This must match the implementation in src/script/common/c_converter.h function core.hash_node_position(pos) - return (pos.z + 32768) * 65536 * 65536 - + (pos.y + 32768) * 65536 - + pos.x + 32768 + return (pos.z + 0x8000) * 0x100000000 + (pos.y + 0x8000) * 0x10000 + (pos.x + 0x8000) end diff --git a/builtin/game/register.lua b/builtin/game/register.lua index f0a6cb49a..cc58cad31 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -633,6 +633,17 @@ core.registered_on_player_inventory_actions, core.register_on_player_inventory_a core.registered_allow_player_inventory_actions, core.register_allow_player_inventory_action = make_registration() core.registered_on_rightclickplayers, core.register_on_rightclickplayer = make_registration() core.registered_on_liquid_transformed, core.register_on_liquid_transformed = make_registration() +core.registered_on_mapblocks_changed, core.register_on_mapblocks_changed = make_registration() + +core.register_on_mods_loaded(function() + core.after(0, function() + setmetatable(core.registered_on_mapblocks_changed, { + __newindex = function() + error("on_mapblocks_changed callbacks must be registered at load time") + end, + }) + end) +end) -- -- Compatibility for on_mapgen_init() diff --git a/builtin/profiler/instrumentation.lua b/builtin/profiler/instrumentation.lua index f80314b32..80f1c66af 100644 --- a/builtin/profiler/instrumentation.lua +++ b/builtin/profiler/instrumentation.lua @@ -43,6 +43,7 @@ local register_functions = { register_on_item_eat = 0, register_on_punchplayer = 0, register_on_player_hpchange = 0, + register_on_mapblocks_changed = 0, } --- -- cgit v1.2.3