parent
52e8924a1b
commit
61b0ffaa9e
1 changed files with 22 additions and 46 deletions
@ -1,68 +1,44 @@ |
|||||||
local ipairs |
local ipairs |
||||||
= ipairs |
= ipairs |
||||||
|
|
||||||
local minetest, vector |
local minetest, nodecore |
||||||
= minetest, vector |
= minetest, nodecore |
||||||
|
|
||||||
local rotate = include("rotate") |
local rotate = include("rotate") |
||||||
|
|
||||||
|
local LABEL_ROTATION_HINT = "rotation hint" |
||||||
|
|
||||||
local TEX_ROTATE_CLOCKWISE = "nc_extended_rotating_hud_rotate_clockwise.png" |
local TEX_ROTATE_CLOCKWISE = "nc_extended_rotating_hud_rotate_clockwise.png" |
||||||
local TEX_ROTATE_COUNTER_CLOCKWISE = "nc_extended_rotating_hud_rotate_counter_clockwise.png" |
local TEX_ROTATE_COUNTER_CLOCKWISE = "nc_extended_rotating_hud_rotate_counter_clockwise.png" |
||||||
|
|
||||||
local player_huds = {} |
local function do_player_rotating_checks(player, data) |
||||||
|
local pt = data.raycast() |
||||||
local function do_player_rotating_checks(player) |
local node = pt and pt.type == "node" and minetest.get_node(pt.under) |
||||||
local name = player:get_player_name() |
|
||||||
|
|
||||||
local hud_index = player_huds[name] |
|
||||||
if hud_index then |
|
||||||
-- FIXME: Only remove / update HUD elements when necessary. |
|
||||||
player:hud_remove(hud_index) |
|
||||||
player_huds[name] = nil |
|
||||||
end |
|
||||||
|
|
||||||
local look_dir = player:get_look_dir() |
|
||||||
local player_pos = vector.copy(player:get_pos()) |
|
||||||
local eye_offset = vector.divide(player:get_eye_offset(), 10) |
|
||||||
local eye_height = player:get_properties().eye_height; |
|
||||||
local eye_pos = player_pos + eye_offset + vector.new(0, eye_height, 0) |
|
||||||
|
|
||||||
local default_reach = minetest.registered_items[""].range or 4 |
|
||||||
local wielded_reach = player:get_wielded_item():get_definition().reach |
|
||||||
local reach = wielded_reach or default_reach |
|
||||||
|
|
||||||
local node = nil |
|
||||||
local ray = minetest.raycast(eye_pos, eye_pos + look_dir * reach, false, false) |
|
||||||
for pointed_thing in ray do |
|
||||||
if pointed_thing.type == "node" then |
|
||||||
node = minetest.get_node(pointed_thing.under) |
|
||||||
break |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
if node and rotate.is_rotatable(node) then |
if node and rotate.is_rotatable(node) then |
||||||
local is_sneaking = player:get_player_control().sneak |
local is_sneaking = player:get_player_control().sneak |
||||||
local texture = is_sneaking and TEX_ROTATE_COUNTER_CLOCKWISE or TEX_ROTATE_CLOCKWISE |
local texture = is_sneaking and TEX_ROTATE_COUNTER_CLOCKWISE or TEX_ROTATE_CLOCKWISE |
||||||
hud_index = player:hud_add({ |
|
||||||
|
nodecore.hud_set(player, { |
||||||
|
label = LABEL_ROTATION_HINT, |
||||||
hud_elem_type = "image", |
hud_elem_type = "image", |
||||||
name = "rotation hint", |
text = texture .. "^[opacity:" .. 192, |
||||||
text = texture, |
|
||||||
position = { x = 0.5, y = 0.5 }, |
position = { x = 0.5, y = 0.5 }, |
||||||
offset = { x = 0, y = 0 }, |
offset = { x = 0, y = 0 }, |
||||||
alignment = { x = 0, y = 0 }, |
alignment = { x = 0, y = 0 }, |
||||||
scale = { x = 1, y = 1 }, |
scale = { x = 1, y = 1 }, |
||||||
|
quick = true |
||||||
|
}) |
||||||
|
else |
||||||
|
nodecore.hud_set(player, { |
||||||
|
label = LABEL_ROTATION_HINT, |
||||||
|
ttl = 0 |
||||||
}) |
}) |
||||||
player_huds[name] = hud_index |
|
||||||
end |
|
||||||
end |
end |
||||||
|
|
||||||
minetest.register_globalstep(function(delta_time) |
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do |
|
||||||
do_player_rotating_checks(player) |
|
||||||
end |
end |
||||||
end) |
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player) |
nodecore.register_playerstep({ |
||||||
local name = player:get_player_name() |
label = "crosshair", |
||||||
player_huds[name] = nil |
priority = -101, |
||||||
end) |
action = do_player_rotating_checks, |
||||||
|
}) |
||||||
|
Loading…
Reference in new issue