Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mapserver_mod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Minetest
mapserver_mod
Commits
d6b6cb8b
Commit
d6b6cb8b
authored
4 years ago
by
Peter Nerlich
Browse files
Options
Downloads
Patches
Plain Diff
refactor for after_place_node instead of on_construct, [NOT TESTED]
parent
84e5477e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
train.lua
+19
-41
19 additions, 41 deletions
train.lua
with
19 additions
and
41 deletions
train.lua
+
19
−
41
View file @
d6b6cb8b
...
...
@@ -34,42 +34,16 @@ minetest.register_node("mapserver:train", {
groups
=
{
cracky
=
3
,
oddly_breakable_by_hand
=
3
},
sounds
=
moditems
.
sound_glass
(),
can_dig
=
mapserver
.
can_interact
,
after_place_node
=
mapserver
.
after_place_node
,
on_construct
=
function
(
pos
)
after_place_node
=
function
(
pos
,
placer
,
itemstack
,
pointed_thing
)
local
meta
=
minetest
.
get_meta
(
pos
)
local
find_nearest_player
=
function
(
block_pos
,
radius
)
-- adapted from https://forum.minetest.net/viewtopic.php?t=23319
local
closest_d
=
radius
+
1
local
closest_name
for
i
,
obj
in
ipairs
(
minetest
.
get_objects_inside_radius
(
block_pos
,
radius
))
do
-- 0.4.x compatibility:
--if obj:get_player_name() ~= "" then
-- 5.0.0+ method:
if
minetest
.
is_player
(
obj
)
then
local
distance
=
vector
.
distance
(
obj
:
get_pos
(),
block_pos
)
if
distance
<
closest_d
then
closest_d
=
distance
closest_name
=
obj
:
get_player_name
()
end
end
end
-- if 'closest_name' is nil, there's no player inside that radius
return
closest_name
end
-- 10 should be the max possible interaction distance
local
name
=
find_nearest_player
(
pos
,
10
)
local
last_index
=
0
local
last_line
=
""
local
last_color
=
""
if
minetest
.
is_player
(
placer
)
then
local
name
=
placer
:
get_player_name
()
if
name
~=
nil
then
name
=
string.lower
(
name
)
if
last_set_by
[
name
]
~=
nil
then
...
...
@@ -84,6 +58,7 @@ minetest.register_node("mapserver:train", {
last_set_by
[
name
].
line
=
last_line
last_set_by
[
name
].
color
=
last_color
end
end
meta
:
set_string
(
"station"
,
""
)
meta
:
set_string
(
"line"
,
last_line
)
...
...
@@ -91,6 +66,9 @@ minetest.register_node("mapserver:train", {
meta
:
set_string
(
"color"
,
last_color
)
update_formspec
(
meta
)
return
mapserver
.
after_place_node
(
pos
,
placer
,
itemstack
,
pointed_thing
)
end
,
on_receive_fields
=
function
(
pos
,
formname
,
fields
,
sender
)
...
...
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