mirror of
https://github.com/pyrollo/display_modpack.git
synced 2024-11-27 16:43:45 +01:00
Improve on_rotate functions (#21)
Fixed bugs and improve on_rotate and support color- paramtype2s
This commit is contained in:
parent
d22362a4ac
commit
44b911be9e
@ -26,55 +26,30 @@ display_api.entity_spacing = 0.002
|
||||
|
||||
-- Miscelaneous values depending on wallmounted param2
|
||||
local wallmounted_values = {
|
||||
[0]={dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=0}, -- Should never be used
|
||||
{dx=0, dz=0, rx=0, rz=0, yaw=0, rotate=1}, -- Should never be used
|
||||
{dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2, rotate=5},
|
||||
{dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2, rotate=4},
|
||||
{dx=0, dz=-1, rx=1, rz=0, yaw=0, rotate=2},
|
||||
{dx=0, dz=1, rx=-1, rz=0, yaw=math.pi, rotate=3}
|
||||
[2]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2},
|
||||
[3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 },
|
||||
[4]={dx=0, dz=-1, rx=1, rz=0, yaw=0 },
|
||||
[5]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi }
|
||||
}
|
||||
|
||||
-- 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=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},
|
||||
}
|
||||
[0]={dx=0, dz=-1, rx=1, rz=0, yaw=0 },
|
||||
[1]={dx=-1, dz=0, rx=0, rz=-1, yaw=-math.pi/2},
|
||||
[2]={dx=0, dz=1, rx=-1, rz=0, yaw=math.pi },
|
||||
[3]={dx=1, dz=0, rx=0, rz=1, yaw=math.pi/2 }
|
||||
}
|
||||
|
||||
-- dx/dy = depth vector, rx/ly = right vector, yaw = yaw of entity,
|
||||
-- rotate = next facedir/wallmount on rotate
|
||||
|
||||
local function get_values(node)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" then
|
||||
return wallmounted_values[node.param2]
|
||||
end
|
||||
if ndef.paramtype2 == "facedir" then
|
||||
return facedir_values[node.param2]
|
||||
local paramtype2 = ndef.paramtype2
|
||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||
return wallmounted_values[node.param2 % 8]
|
||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||
return facedir_values[node.param2 % 32]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -186,7 +161,7 @@ end
|
||||
|
||||
--- On_place callback for display_api items. Does nothing more than preventing item
|
||||
--- from being placed on ceiling or ground
|
||||
function display_api.on_place(itemstack, placer, pointed_thing)
|
||||
function display_api.on_place(itemstack, placer, pointed_thing, override_param2)
|
||||
local ndef = itemstack:get_definition()
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
@ -200,15 +175,16 @@ function display_api.on_place(itemstack, placer, pointed_thing)
|
||||
dir.y = 0
|
||||
end
|
||||
|
||||
local param2
|
||||
local param2 = 0
|
||||
if ndef then
|
||||
if ndef.paramtype2 == "wallmounted" then
|
||||
local paramtype2 = ndef.paramtype2
|
||||
if paramtype2 == "wallmounted" or paramtype2 == "colorwallmounted" then
|
||||
param2 = minetest.dir_to_wallmounted(dir)
|
||||
elseif ndef.paramtype2 == "facedir" then
|
||||
elseif paramtype2 == "facedir" or paramtype2 == "colorfacedir" then
|
||||
param2 = minetest.dir_to_facedir(dir)
|
||||
end
|
||||
end
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2)
|
||||
return minetest.item_place(itemstack, placer, pointed_thing, param2 + (override_param2 or 0))
|
||||
end
|
||||
|
||||
--- On_construct callback for display_api items. Creates entities and update them.
|
||||
@ -225,14 +201,11 @@ function display_api.on_destruct(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-- On_rotate (screwdriver) callback for display_api items. Prevents axis rotation and reorients entities.
|
||||
function display_api.on_rotate(pos, node, user, mode, new_param2)
|
||||
if mode ~= 1 then return false end
|
||||
|
||||
local values = get_values(node)
|
||||
|
||||
if values then
|
||||
minetest.swap_node(pos, {name = node.name, param1 = node.param1, param2 = values.rotate})
|
||||
-- On_rotate (screwdriver) callback for display_api items. Prevents invalid rotations and reorients entities.
|
||||
function display_api.on_rotate(pos, node, user, _, new_param2)
|
||||
node.param2 = new_param2
|
||||
if get_values(node) then
|
||||
minetest.swap_node(pos, node)
|
||||
place_entities(pos)
|
||||
return true
|
||||
else
|
||||
|
@ -132,6 +132,8 @@ function signs_api.on_place_direction(itemstack, placer, pointed_thing)
|
||||
end
|
||||
|
||||
-- Handles screwdriver rotation. Direction is affected for direction signs
|
||||
-- If rotation mode is 2 and sign is directional, swap direction.
|
||||
-- Otherwise use display_api's on_rotate function.
|
||||
function signs_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
if mode == 2 then
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
@ -139,11 +141,10 @@ function signs_api.on_rotate(pos, node, player, mode, new_param2)
|
||||
minetest.swap_node(pos, {name = ndef.signs_other_dir,
|
||||
param1 = node.param1, param2 = node.param2})
|
||||
display_api.update_entities(pos)
|
||||
return true
|
||||
end
|
||||
else
|
||||
display_api.on_rotate(pos, node, user, mode, new_param2)
|
||||
end
|
||||
return false;
|
||||
return display_api.on_rotate(pos, node, user, mode, new_param2)
|
||||
end
|
||||
|
||||
function signs_api.register_sign(mod, name, model)
|
||||
|
Loading…
Reference in New Issue
Block a user