Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
2f170a63
Commit
2f170a63
authored
10 years ago
by
ShadowNinja
Browse files
Options
Downloads
Patches
Plain Diff
Simplify and optimize schematic replacements
parent
b8ba6318
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/lua_api.txt
+2
-2
2 additions, 2 deletions
doc/lua_api.txt
src/script/lua_api/l_mapgen.cpp
+27
-27
27 additions, 27 deletions
src/script/lua_api/l_mapgen.cpp
with
29 additions
and
29 deletions
doc/lua_api.txt
+
2
−
2
View file @
2f170a63
...
@@ -1719,7 +1719,7 @@ minetest.place_schematic(pos, schematic, rotation, replacements, force_placement
...
@@ -1719,7 +1719,7 @@ minetest.place_schematic(pos, schematic, rotation, replacements, force_placement
^ Place the schematic specified by schematic (see: Schematic specifier) at pos.
^ Place the schematic specified by schematic (see: Schematic specifier) at pos.
^ Rotation can be "0", "90", "180", "270", or "random".
^ Rotation can be "0", "90", "180", "270", or "random".
^ If the rotation parameter is omitted, the schematic is not rotated.
^ If the rotation parameter is omitted, the schematic is not rotated.
^ replacements = {
{
"oldname"
,
"convert_to"
}
, ...}
^ replacements = {
[
"old
_
name"
] =
"convert_to", ...}
^ force_placement is a boolean indicating whether nodes other than air and
^ force_placement is a boolean indicating whether nodes other than air and
^ ignore are replaced by the schematic
^ ignore are replaced by the schematic
...
@@ -2634,7 +2634,7 @@ Decoration definition (register_decoration)
...
@@ -2634,7 +2634,7 @@ Decoration definition (register_decoration)
},
},
},
},
^ See 'Schematic specifier' for details.
^ See 'Schematic specifier' for details.
replacements = {
{
"oldname"
,
"convert_to"
}
, ...},
replacements = {
[
"oldname"
] =
"convert_to", ...},
flags = "place_center_x, place_center_z",
flags = "place_center_x, place_center_z",
^ Flags for schematic decorations. See 'Schematic attributes'.
^ Flags for schematic decorations. See 'Schematic attributes'.
rotation = "90" -- rotate schematic 90 degrees on placement
rotation = "90" -- rotate schematic 90 degrees on placement
...
...
This diff is collapsed.
Click to expand it.
src/script/lua_api/l_mapgen.cpp
+
27
−
27
View file @
2f170a63
...
@@ -78,6 +78,31 @@ struct EnumString ModApiMapgen::es_Rotation[] =
...
@@ -78,6 +78,31 @@ struct EnumString ModApiMapgen::es_Rotation[] =
};
};
static
void
read_schematic_replacements
(
lua_State
*
L
,
DecoSchematic
*
dschem
,
int
index
)
{
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
index
))
{
// key at index -2 and value at index -1
std
::
string
replace_from
;
std
::
string
replace_to
;
if
(
lua_istable
(
L
,
-
1
))
{
// Old {{"x", "y"}, ...} format
lua_rawgeti
(
L
,
-
1
,
1
);
replace_from
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
lua_rawgeti
(
L
,
-
1
,
2
);
replace_to
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
}
else
{
// New {x = "y", ...} format
replace_from
=
lua_tostring
(
L
,
-
2
);
replace_to
=
lua_tostring
(
L
,
-
1
);
}
dschem
->
replacements
[
replace_from
]
=
replace_to
;
// removes value, keeps key for next iteration
lua_pop
(
L
,
1
);
}
}
// get_mapgen_object(objectname)
// get_mapgen_object(objectname)
// returns the requested object used during map generation
// returns the requested object used during map generation
int
ModApiMapgen
::
l_get_mapgen_object
(
lua_State
*
L
)
int
ModApiMapgen
::
l_get_mapgen_object
(
lua_State
*
L
)
...
@@ -414,20 +439,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
...
@@ -414,20 +439,7 @@ int ModApiMapgen::l_register_decoration(lua_State *L)
lua_getfield
(
L
,
index
,
"replacements"
);
lua_getfield
(
L
,
index
,
"replacements"
);
if
(
lua_istable
(
L
,
-
1
))
{
if
(
lua_istable
(
L
,
-
1
))
{
int
i
=
lua_gettop
(
L
);
read_schematic_replacements
(
L
,
dschem
,
lua_gettop
(
L
));
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
i
)
!=
0
)
{
// key at index -2 and value at index -1
lua_rawgeti
(
L
,
-
1
,
1
);
std
::
string
replace_from
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
lua_rawgeti
(
L
,
-
1
,
2
);
std
::
string
replace_to
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
dschem
->
replacements
[
replace_from
]
=
replace_to
;
// removes value, keeps key for next iteration
lua_pop
(
L
,
1
);
}
}
}
lua_pop
(
L
,
1
);
lua_pop
(
L
,
1
);
...
@@ -602,19 +614,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
...
@@ -602,19 +614,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
dschem
.
rotation
=
(
Rotation
)
rot
;
dschem
.
rotation
=
(
Rotation
)
rot
;
if
(
lua_istable
(
L
,
4
))
{
if
(
lua_istable
(
L
,
4
))
{
lua_pushnil
(
L
);
read_schematic_replacements
(
L
,
&
dschem
,
4
);
while
(
lua_next
(
L
,
4
)
!=
0
)
{
// key at index -2 and value at index -1
lua_rawgeti
(
L
,
-
1
,
1
);
std
::
string
replace_from
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
lua_rawgeti
(
L
,
-
1
,
2
);
std
::
string
replace_to
=
lua_tostring
(
L
,
-
1
);
lua_pop
(
L
,
1
);
dschem
.
replacements
[
replace_from
]
=
replace_to
;
// removes value, keeps key for next iteration
lua_pop
(
L
,
1
);
}
}
}
bool
force_placement
=
true
;
bool
force_placement
=
true
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment