Page Menu
Home
1F616EMO Bugtracker
Search
Configure Global Search
Log In
Files
F154864
init.lua
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
init.lua
View Options
-- twi_mods/formspec_key_workaround/init.lua
-- Fix ${key} in formspecs
--[[
Copyright © 2024 1F616EMO
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local
RADIUS
=
10
local
INTERVAL
=
0.5
local
F
=
core
.
formspec_escape
local
function
replace_formspec
(
formspec
,
meta
)
return
string.gsub
(
formspec
,
"%${(%C+)}"
,
function
(
key
)
local
value
=
meta
:
get_string
(
key
)
if
value
==
"${"
..
key
..
"}"
then
return
""
end
return
value
end
)
end
local
function
fix_node
(
pos
)
local
meta
=
core
.
get_meta
(
pos
)
local
formspec
=
meta
:
get_string
(
"formspec"
)
if
formspec
==
""
then
return
end
local
work_formspec
local
old_formspec
=
meta
:
get_string
(
"old_formspec"
)
if
old_formspec
==
formspec
then
-- Mod did not modify the formspec, work on the original formspec
work_formspec
=
meta
:
get_string
(
"orig_formspec"
)
else
-- Mod modified the formspec, work on the normal fomrpsec
meta
:
set_string
(
"orig_formspec"
,
formspec
)
work_formspec
=
formspec
end
local
new_formspec
=
replace_formspec
(
work_formspec
,
meta
)
meta
:
set_string
(
"formspec"
,
new_formspec
)
meta
:
set_string
(
"old_formspec"
,
new_formspec
)
end
local
dtime_total
=
0
core
.
register_globalstep
(
function
(
dtime
)
dtime_total
=
dtime_total
+
dtime
if
dtime_total
<
INTERVAL
then
return
end
dtime_total
=
0
local
processed
=
{}
for
_
,
player
in
ipairs
(
core
.
get_connected_players
())
do
local
pos
=
vector
.
round
(
player
:
get_pos
())
for
x
=
pos
.
x
-
RADIUS
,
pos
.
x
+
RADIUS
do
for
y
=
pos
.
y
-
RADIUS
,
pos
.
y
+
RADIUS
do
for
z
=
pos
.
z
-
RADIUS
,
pos
.
z
+
RADIUS
do
local
work_pos
=
vector
.
new
(
x
,
y
,
z
)
local
hash
=
core
.
hash_node_position
(
work_pos
)
if
not
processed
[
hash
]
then
processed
[
hash
]
=
true
fix_node
(
work_pos
)
end
end
end
end
end
end
)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 20, 4:16 PM (1 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
dd/43/bbd62d8bd2f8644eea2f508b1ba9
Default Alt Text
init.lua (3 KB)
Attached To
Mode
rTWIMODS Survival Server Custom Modifications
Attached
Detach File
Event Timeline
Log In to Comment