Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
minetest_game
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
minetest_game
Commits
71ea0c65
Unverified
Commit
71ea0c65
authored
3 years ago
by
SmallJoker
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Attachments: Proper data cleanup in callbacks (#2865)
parent
642fde44
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mods/boats/init.lua
+13
-16
13 additions, 16 deletions
mods/boats/init.lua
mods/carts/cart_entity.lua
+3
-7
3 additions, 7 deletions
mods/carts/cart_entity.lua
mods/carts/functions.lua
+5
-1
5 additions, 1 deletion
mods/carts/functions.lua
with
21 additions
and
24 deletions
mods/boats/init.lua
+
13
−
16
View file @
71ea0c65
...
...
@@ -53,31 +53,24 @@ function boat.on_rightclick(self, clicker)
end
local
name
=
clicker
:
get_player_name
()
if
self
.
driver
and
name
==
self
.
driver
then
self
.
driver
=
nil
self
.
auto
=
false
-- Cleanup happens in boat.on_detach_child
clicker
:
set_detach
()
player_api
.
player_attached
[
name
]
=
false
player_api
.
set_animation
(
clicker
,
"stand"
,
30
)
player_api
.
set_animation
(
clicker
,
"stand"
,
30
)
local
pos
=
clicker
:
get_pos
()
pos
=
{
x
=
pos
.
x
,
y
=
pos
.
y
+
0
.
2
,
z
=
pos
.
z
}
minetest
.
after
(
0
.
1
,
function
()
clicker
:
set_pos
(
pos
)
end
)
elseif
not
self
.
driver
then
local
attach
=
clicker
:
get_attach
()
if
attach
and
attach
:
get_luaentity
()
then
local
luaentity
=
attach
:
get_luaentity
()
if
luaentity
.
driver
then
luaentity
.
driver
=
nil
end
clicker
:
set_detach
()
end
self
.
driver
=
name
clicker
:
set_attach
(
self
.
object
,
""
,
{
x
=
0
.
5
,
y
=
1
,
z
=
-
3
},
{
x
=
0
,
y
=
0
,
z
=
0
})
self
.
driver
=
name
player_api
.
player_attached
[
name
]
=
true
minetest
.
after
(
0
.
2
,
function
()
player_api
.
set_animation
(
clicker
,
"sit"
,
30
)
player_api
.
set_animation
(
clicker
,
"sit"
,
30
)
end
)
clicker
:
set_look_horizontal
(
self
.
object
:
get_yaw
())
end
...
...
@@ -86,8 +79,12 @@ end
-- If driver leaves server while driving boat
function
boat
.
on_detach_child
(
self
,
child
)
self
.
driver
=
nil
self
.
auto
=
false
if
child
and
child
:
get_player_name
()
==
self
.
driver
then
player_api
.
player_attached
[
child
:
get_player_name
()]
=
false
self
.
driver
=
nil
self
.
auto
=
false
end
end
...
...
This diff is collapsed.
Click to expand it.
mods/carts/cart_entity.lua
+
3
−
7
View file @
71ea0c65
...
...
@@ -29,15 +29,10 @@ function cart_entity:on_rightclick(clicker)
end
local
player_name
=
clicker
:
get_player_name
()
if
self
.
driver
and
player_name
==
self
.
driver
then
self
.
driver
=
nil
carts
:
manage_attachment
(
clicker
,
nil
)
elseif
not
self
.
driver
then
self
.
driver
=
player_name
carts
:
manage_attachment
(
clicker
,
self
.
object
)
-- player_api does not update the animation
-- when the player is attached, reset to default animation
player_api
.
set_animation
(
clicker
,
"stand"
)
self
.
driver
=
player_name
end
end
...
...
@@ -66,8 +61,9 @@ end
-- 0.5.x and later: When the driver leaves
function
cart_entity
:
on_detach_child
(
child
)
if
child
and
child
:
get_player_name
()
==
self
.
driver
then
self
.
driver
=
nil
-- Clean up eye height
carts
:
manage_attachment
(
child
,
nil
)
self
.
driver
=
nil
end
end
...
...
This diff is collapsed.
Click to expand it.
mods/carts/functions.lua
+
5
−
1
View file @
71ea0c65
...
...
@@ -12,7 +12,7 @@ function carts:manage_attachment(player, obj)
end
local
status
=
obj
~=
nil
local
player_name
=
player
:
get_player_name
()
if
player_api
.
player_attach
ed
[
player_name
]
==
status
then
if
obj
and
player
:
get
_attach
()
==
obj
then
return
end
player_api
.
player_attached
[
player_name
]
=
status
...
...
@@ -20,6 +20,10 @@ function carts:manage_attachment(player, obj)
if
status
then
player
:
set_attach
(
obj
,
""
,
{
x
=
0
,
y
=-
4
.
5
,
z
=
0
},
{
x
=
0
,
y
=
0
,
z
=
0
})
player
:
set_eye_offset
({
x
=
0
,
y
=-
4
,
z
=
0
},{
x
=
0
,
y
=-
4
,
z
=
0
})
-- player_api does not update the animation
-- when the player is attached, reset to default animation
player_api
.
set_animation
(
player
,
"stand"
)
else
player
:
set_detach
()
player
:
set_eye_offset
({
x
=
0
,
y
=
0
,
z
=
0
},{
x
=
0
,
y
=
0
,
z
=
0
})
...
...
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