aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre-Yves Rollo <dev@pyrollo.com>2018-09-21 17:07:11 +0200
committerGitHub <noreply@github.com>2018-09-21 17:07:11 +0200
commit30af909da5e18fb7ebef832154306b970c57dba2 (patch)
treec5f42874a141b41e6e37f0318d380ba5aee05942
parentc1f7b571b8a7592b79fd2f9d01507e642ed35597 (diff)
parentdfaf64cd619550df24bcc7f7e45901202eabd759 (diff)
downloaddisplay_modpack-30af909da5e18fb7ebef832154306b970c57dba2.tar.gz
display_modpack-30af909da5e18fb7ebef832154306b970c57dba2.tar.bz2
display_modpack-30af909da5e18fb7ebef832154306b970c57dba2.zip
Merge pull request #20 from 12Me21/master
Improved on_place
-rw-r--r--display_api/init.lua80
1 files changed, 39 insertions, 41 deletions
diff --git a/display_api/init.lua b/display_api/init.lua
index 2cd15a0..ca7b779 100644
--- a/display_api/init.lua
+++ b/display_api/init.lua
@@ -37,30 +37,30 @@ local wallmounted_values = {
-- Miscelaneous values depending on facedir param2
local facedir_values = {
[0]={dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=1},
- {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2},
- {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3},
+ {dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=2},
+ {dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3},
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=0},
- -- Forbiden values :
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
- {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ -- Forbiden values :
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
+ {dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0},
}
-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity,
@@ -103,7 +103,7 @@ local function get_entities(pos)
else
objrefs[entity.name] = objref
end
- end
+ end
end
end
return objrefs
@@ -160,7 +160,7 @@ function display_api.update_entities(pos)
for _, objref in pairs(objrefs) do
objref:get_luaentity().pos = minetest.hash_node_position(pos)
call_node_on_display_update(pos, objref)
- end
+ end
end
--- On_activate callback for display_api entities. Calls on_display_update callbacks
@@ -191,26 +191,24 @@ function display_api.on_place(itemstack, placer, pointed_thing)
local above = pointed_thing.above
local under = pointed_thing.under
local dir = {x = under.x - above.x,
- y = under.y - above.y,
- z = under.z - above.z}
-
+ y = 0,
+ z = under.z - above.z}
+
+ -- If item is not placed on a wall, use the player's view direction instead
+ if dir.x == 0 and dir.z == 0 then
+ dir = placer:get_look_dir()
+ dir.y = 0
+ end
+
+ local param2
if ndef then
if ndef.paramtype2 == "wallmounted" then
-
- local wdir = minetest.dir_to_wallmounted(dir)
-
- if wdir == 0 or wdir == 1 then
- dir = placer:get_look_dir()
- dir.y = 0
- wdir = minetest.dir_to_wallmounted(dir)
- end
-
- return minetest.item_place(itemstack, placer, pointed_thing, wdir)
- else
- return minetest.item_place(itemstack, placer, pointed_thing, minetest.dir_to_facedir(dir))
+ param2 = minetest.dir_to_wallmounted(dir)
+ elseif ndef.paramtype2 == "facedir" then
+ param2 = minetest.dir_to_facedir(dir)
end
end
-
+ return minetest.item_place(itemstack, placer, pointed_thing, param2)
end
--- On_construct callback for display_api items. Creates entities and update them.