add one-time warnings to deprecated blocks-related functions

This commit is contained in:
MihailRis 2024-08-04 00:00:42 +03:00
parent 0f527c196c
commit 7bc96affbb

View File

@ -24,9 +24,19 @@ package = {
loaded={} loaded={}
} }
local __cached_scripts = {} local __cached_scripts = {}
local __warnings_hidden = {}
function on_deprecated_call(name) function on_deprecated_call(name, alternatives)
debug.warning("deprecated function called ("..name..")\n"..debug.traceback()) if __warnings_hidden[name] then
return
end
__warnings_hidden[name] = true
if alternatives then
debug.warning("deprecated function called ("..name.."), use "..
alternatives.." instead\n"..debug.traceback())
else
debug.warning("deprecated function called ("..name..")\n"..debug.traceback())
end
end end
-- Load script with caching -- Load script with caching
@ -427,32 +437,39 @@ function string.ends_with(str, endStr)
end end
-- --------- Deprecated functions ------ -- -- --------- Deprecated functions ------ --
block_index = block.index local function wrap_deprecated(func, name, alternatives)
block_name = block.name return function (...)
blocks_count = block.defs_count on_deprecated_call(name, alternatives)
is_solid_at = block.is_solid_at return func(...)
is_replaceable_at = block.is_replaceable_at end
set_block = block.set end
get_block = block.get
get_block_X = block.get_X block_index = wrap_deprecated(block.index, "block_index", "block.index")
get_block_Y = block.get_Y block_name = wrap_deprecated(block.name, "block_name", "block.name")
get_block_Z = block.get_Z blocks_count = wrap_deprecated(block.defs_count, "blocks_count", "block.defs_count")
get_block_states = block.get_states is_solid_at = wrap_deprecated(block.is_solid_at, "is_solid_at", "block.is_solid_at")
set_block_states = block.set_states is_replaceable_at = wrap_deprecated(block.is_replaceable_at, "is_replaceable_at", "block.is_replaceable_at")
get_block_rotation = block.get_rotation set_block = wrap_deprecated(block.set, "set_block", "block.set")
set_block_rotation = block.set_rotation get_block = wrap_deprecated(block.get, "get_block", "block.get")
get_block_user_bits = block.get_user_bits get_block_X = wrap_deprecated(block.get_X, "get_block_X", "block.get_X")
set_block_user_bits = block.set_user_bits get_block_Y = wrap_deprecated(block.get_Y, "get_block_Y", "block.get_Y")
get_block_Z = wrap_deprecated(block.get_Z, "get_block_Z", "block.get_Z")
get_block_states = wrap_deprecated(block.get_states, "get_block_states", "block.get_states")
set_block_states = wrap_deprecated(block.set_states, "set_block_states", "block.set_states")
get_block_rotation = wrap_deprecated(block.get_rotation, "get_block_rotation", "block.get_rotation")
set_block_rotation = wrap_deprecated(block.set_rotation, "set_block_rotation", "block.set_rotation")
get_block_user_bits = wrap_deprecated(block.get_user_bits, "get_block_user_bits", "block.get_user_bits")
set_block_user_bits = wrap_deprecated(block.set_user_bits, "set_block_user_bits", "block.set_user_bits")
function load_script(path, nocache) function load_script(path, nocache)
on_deprecated_call("load_script") on_deprecated_call("load_script", "require or loadstring")
return __load_script(path, nocache) return __load_script(path, nocache)
end end
_dofile = dofile _dofile = dofile
-- Replaces dofile('*/content/packid/*') with load_script('packid:*') -- Replaces dofile('*/content/packid/*') with load_script('packid:*')
function dofile(path) function dofile(path)
on_deprecated_call("dofile") on_deprecated_call("dofile", "require or loadstring")
local index = string.find(path, "/content/") local index = string.find(path, "/content/")
if index then if index then
local newpath = string.sub(path, index+9) local newpath = string.sub(path, index+9)