From 5db839407009a04dc56e4313550ddf40b9ac7c06 Mon Sep 17 00:00:00 2001 From: Juraj Vajda Date: Sat, 23 Dec 2023 14:36:17 -0500 Subject: [PATCH] Improve illuminating pickaxe crystals placement --- nodes.lua | 74 +++++++++++++++++- .../everness_floating_crystal_animated.png | Bin 340 -> 333 bytes 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/nodes.lua b/nodes.lua index 62740b9..3957f2d 100644 --- a/nodes.lua +++ b/nodes.lua @@ -9350,20 +9350,86 @@ Everness:register_node('everness:floating_crystal', { meta:set_int('activated', 1) - local position = { x = pos.x, y = pos.y, z = pos.z } - local position_prev = { x = pos.x, y = pos.y, z = pos.z } + minetest.sound_play( + 'everness_thin_glass_footstep', + { + gain = 1.0, + max_hear_distance = 16, + pos = pos + }, + true + ) + -- Initial values + local position = vector.new(pos.x, pos.y, pos.z) + local position_prev = vector.new(pos.x, pos.y, pos.z) + + -- For "number" of crystals do.. for i = 1, math.random(2, 6), 1 do + -- Only air positions local positions = minetest.find_nodes_in_area( { x = position.x - 3, y = position.y - 1, z = position.z - 3 }, { x = position.x + 3, y = position.y + 1, z = position.z + 3 }, { 'air' } ) + if #positions == 0 then + -- No positions available/found + break + end + + -- Get light for `positions` + local positions_with_light = {} + + for k, v in ipairs(positions) do + table.insert(positions_with_light, { + pos = v, + light = minetest.get_node_light(v) + }) + end + + table.shuffle(positions_with_light) + + -- Sort with the lowest light first + table.sort(positions_with_light, function(a, b) + return a.light < b.light + end) + local temp_pos - while not temp_pos or vector.distance(position_prev, temp_pos) < 2 do - temp_pos = positions[math.random(1, #positions)] + -- Find next position + for j, v in ipairs(positions_with_light) do + temp_pos = v.pos + local blocking_sight = false + local ray = minetest.raycast(position_prev, temp_pos, false, false) + + for pt in ray do + if pt.type == 'node' then + local node_under = minetest.get_node(pt.under) + local node_def = minetest.registered_nodes[node_under.name] + + if node_def then + if node_def.walkable then + blocking_sight = node_def.walkable + break + end + end + end + end + + if vector.distance(position_prev, temp_pos) > 1 + and not vector.equals(position_prev, temp_pos) + and not blocking_sight + then + break + else + temp_pos = nil + end + end + + if not temp_pos then + -- No suitable next position found + break end position_prev = position diff --git a/textures/everness_floating_crystal_animated.png b/textures/everness_floating_crystal_animated.png index 58626ecc63e55674e1479e6cbdaed146c9a4a1a3..00665ac7e7984e59504b7237e676bbe4af0b03a3 100644 GIT binary patch delta 319 zcmV-F0l@y$0?h)D7k_XF0{{R3AlU#30000*P)t-sM{rE!#6SG?p77gO^yGp3_sI9@ zZ2tV){rI;3{_X$&|Ns5u>d#B-({J|ap!4E@`trU1{_p<$=j+m4^yZlP@V5T^zOU12GIk>tp7-|9}6~6(TkBc(o{g3L6m& zNrTM!91;mZf#`igX;ZYX>M9ag-?WV-5L=XW+qHFB2%-$>(W@Rjh4DrtYWl&0RW=u34INz RT&Ms5002ovPDHLkV1m98q;3EJ literal 340 zcmeAS@N?(olHy`uVBq!ia0vp^0ziC#gAF8d_OTxW1EaL3i(^Q}y|+{By_g*(-0!Q1 z-HPB;nsh4RDKE=&u_}iCN4_~M|DSN2V*A4IEo-BWBg;Xz<_x>;sR}cC^Q7;skJ=Yo zcjnER>J2w`+MEu&_hiO*-{milUUltzD_6qQw*0eq-BO7s9Yyw!-da5Rsj=wH#So)n z*1x3<)UxoL{@(F)nT(-^?KU$ z6CIl^x>1l*paz%gLW$Nz0U}*sriKWZ?PLfP)(|NaOGiO*Gin$+H>b$Oz7duNh8BaT LtDnm{r-UW|H}#9-