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
a468acce
Commit
a468acce
authored
8 years ago
by
tenplus1
Committed by
paramat
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Builtin/../falling.lua: Code optimisation
parent
0ad40fd4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
builtin/game/falling.lua
+15
-15
15 additions, 15 deletions
builtin/game/falling.lua
with
15 additions
and
15 deletions
builtin/game/falling.lua
+
15
−
15
View file @
a468acce
...
...
@@ -41,7 +41,7 @@ core.register_entity(":__builtin:falling_node", {
end
,
on_step
=
function
(
self
,
dtime
)
-- Set gravity
-- Set gravity
local
acceleration
=
self
.
object
:
getacceleration
()
if
not
vector
.
equals
(
acceleration
,
{
x
=
0
,
y
=
-
10
,
z
=
0
})
then
self
.
object
:
setacceleration
({
x
=
0
,
y
=
-
10
,
z
=
0
})
...
...
@@ -52,10 +52,9 @@ core.register_entity(":__builtin:falling_node", {
local
bcn
=
core
.
get_node
(
bcp
)
local
bcd
=
core
.
registered_nodes
[
bcn
.
name
]
-- Note: walkable is in the node definition, not in item groups
if
not
bcd
or
(
bcd
.
walkable
or
if
not
bcd
or
bcd
.
walkable
or
(
core
.
get_item_group
(
self
.
node
.
name
,
"float"
)
~=
0
and
bcd
.
liquidtype
~=
"none"
)
)
then
bcd
.
liquidtype
~=
"none"
)
then
if
bcd
and
bcd
.
leveled
and
bcn
.
name
==
self
.
node
.
name
then
local
addlevel
=
self
.
node
.
level
...
...
@@ -75,20 +74,20 @@ core.register_entity(":__builtin:falling_node", {
local
np
=
{
x
=
bcp
.
x
,
y
=
bcp
.
y
+
1
,
z
=
bcp
.
z
}
-- Check what's here
local
n2
=
core
.
get_node
(
np
)
local
nd
=
core
.
registered_nodes
[
n2
.
name
]
-- If it's not air or liquid, remove node and replace it with
-- it's drops
if
n2
.
name
~=
"air"
and
(
not
core
.
registered_nodes
[
n2
.
name
]
or
core
.
registered_nodes
[
n2
.
name
].
liquidtype
==
"none"
)
then
if
n2
.
name
~=
"air"
and
(
not
nd
or
nd
.
liquidtype
==
"none"
)
then
core
.
remove_node
(
np
)
if
core
.
registered_nodes
[
n2
.
name
]
.
buildable_to
==
false
then
if
nd
.
buildable_to
==
false
then
-- Add dropped items
local
drops
=
core
.
get_node_drops
(
n2
.
name
,
""
)
for
_
,
dropped_item
in
i
pairs
(
drops
)
do
for
_
,
dropped_item
in
pairs
(
drops
)
do
core
.
add_item
(
np
,
dropped_item
)
end
end
-- Run script hook
for
_
,
callback
in
i
pairs
(
core
.
registered_on_dignodes
)
do
for
_
,
callback
in
pairs
(
core
.
registered_on_dignodes
)
do
callback
(
np
,
n2
)
end
end
...
...
@@ -116,7 +115,7 @@ end
function
drop_attached_node
(
p
)
local
nn
=
core
.
get_node
(
p
).
name
core
.
remove_node
(
p
)
for
_
,
item
in
i
pairs
(
core
.
get_node_drops
(
nn
,
""
))
do
for
_
,
item
in
pairs
(
core
.
get_node_drops
(
nn
,
""
))
do
local
pos
=
{
x
=
p
.
x
+
math.random
()
/
2
-
0
.
25
,
y
=
p
.
y
+
math.random
()
/
2
-
0
.
25
,
...
...
@@ -156,14 +155,15 @@ function nodeupdate_single(p)
if
core
.
get_item_group
(
n
.
name
,
"falling_node"
)
~=
0
then
local
p_bottom
=
{
x
=
p
.
x
,
y
=
p
.
y
-
1
,
z
=
p
.
z
}
local
n_bottom
=
core
.
get_node
(
p_bottom
)
local
d_bottom
=
core
.
registered_nodes
[
n_bottom
.
name
]
-- Note: walkable is in the node definition, not in item groups
if
core
.
registered_nodes
[
n_bottom
.
name
]
and
if
d_bottom
and
(
core
.
get_item_group
(
n
.
name
,
"float"
)
==
0
or
core
.
registered_nodes
[
n_bottom
.
name
]
.
liquidtype
==
"none"
)
and
(
n
.
name
~=
n_bottom
.
name
or
(
core
.
registered_nodes
[
n_bottom
.
name
]
.
leveled
and
d_bottom
.
liquidtype
==
"none"
)
and
(
n
.
name
~=
n_bottom
.
name
or
(
d_bottom
.
leveled
and
core
.
get_node_level
(
p_bottom
)
<
core
.
get_node_max_level
(
p_bottom
)))
and
(
not
core
.
registered_nodes
[
n_bottom
.
name
]
.
walkable
or
core
.
registered_nodes
[
n_bottom
.
name
]
.
buildable_to
)
then
(
not
d_bottom
.
walkable
or
d_bottom
.
buildable_to
)
then
n
.
level
=
core
.
get_node_level
(
p
)
core
.
remove_node
(
p
)
spawn_falling_node
(
p
,
n
)
...
...
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