From b57dc70769873e00ca7a7642862eb209a5528ce2 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 9 Nov 2019 00:22:42 +0100 Subject: [CSM] Expose more env functions --- clientmods/preview/init.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'clientmods/preview') diff --git a/clientmods/preview/init.lua b/clientmods/preview/init.lua index c1358b1c1..96deae074 100644 --- a/clientmods/preview/init.lua +++ b/clientmods/preview/init.lua @@ -65,6 +65,22 @@ core.register_on_item_use(function(itemstack, pointed_thing) print("The local player used an item!") print("pointed_thing :" .. dump(pointed_thing)) print("item = " .. itemstack:get_name()) + + local pos = vector.add(core.localplayer:get_pos(), core.camera:get_offset()) + local pos2 = vector.add(pos, vector.multiply(core.camera:get_look_dir(), 100)) + + local rc = core.raycast(pos, pos2) + local i = rc:next() + print("[PREVIEW] raycast next: " .. dump(i)) + if i then + print("[PREVIEW] line of sight: " .. (core.line_of_sight(pos, i.above) and "yes" or "no")) + + local n1 = core.find_nodes_in_area(pos, i.under, {"default:stone"}) + local n2 = core.find_nodes_in_area_under_air(pos, i.under, {"default:stone"}) + print(("[PREVIEW] found %s nodes, %s nodes under air"):format( + n1 and #n1 or "?", n2 and #n2 or "?")) + end + return false end) @@ -90,11 +106,6 @@ core.register_on_damage_taken(function(hp) print("[PREVIEW] Damage taken " .. hp) end) --- This is an example function to ensure it's working properly, should be removed before merge -core.register_globalstep(function(dtime) - -- print("[PREVIEW] globalstep " .. dtime) -end) - -- This is an example function to ensure it's working properly, should be removed before merge core.register_chatcommand("dump", { func = function(param) -- cgit v1.2.3