From 329c4fd360bf0967e716b33cccadad5841444fc8 Mon Sep 17 00:00:00 2001 From: wsor <24964441+wsor4035@users.noreply.github.com> Date: Wed, 30 Jun 2021 21:51:25 -0400 Subject: [PATCH] extreme proof of concept spawner --- mods/fl_wildlife/fl_mobs/sheep.lua | 1 + mods/fl_wildlife/init.lua | 4 +- mods/fl_wildlife/spawner.lua | 124 ++++++++++++++++++ .../fl_wildlife/textures/farlands_spawner.png | Bin 0 -> 881 bytes 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 mods/fl_wildlife/spawner.lua create mode 100644 mods/fl_wildlife/textures/farlands_spawner.png diff --git a/mods/fl_wildlife/fl_mobs/sheep.lua b/mods/fl_wildlife/fl_mobs/sheep.lua index 9b4066c..7928fbe 100644 --- a/mods/fl_wildlife/fl_mobs/sheep.lua +++ b/mods/fl_wildlife/fl_mobs/sheep.lua @@ -119,6 +119,7 @@ minetest.register_entity("fl_wildlife:sheep", { }, brainfunc = sheep_brain,--villager_brain, --function for the brain + _spawner = {}, --more mte properties on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir) diff --git a/mods/fl_wildlife/init.lua b/mods/fl_wildlife/init.lua index aa5a940..c85db60 100644 --- a/mods/fl_wildlife/init.lua +++ b/mods/fl_wildlife/init.lua @@ -40,4 +40,6 @@ for _, mob in pairs(mob_list) do if minetest.settings:get_bool(setting, true) == true then dofile(modpath .. "/fl_mobs/" .. mob .. ".lua") end -end \ No newline at end of file +end + +dofile(modpath .. "/spawner.lua") \ No newline at end of file diff --git a/mods/fl_wildlife/spawner.lua b/mods/fl_wildlife/spawner.lua new file mode 100644 index 0000000..f9934da --- /dev/null +++ b/mods/fl_wildlife/spawner.lua @@ -0,0 +1,124 @@ +local random = math.random +local get_node_light = minetest.get_node_light + +local sz = 2 --(sz*2+1, 3, sz*2*1) +local max_obj = 16--tonumber(minetest.settings:get("max_objects_per_block") or 64) +local spawner_mobs = {} +local sm_keys = {} + +minetest.register_on_mods_loaded(function() + for mob, def in pairs(minetest.registered_entities) do + if def._spawner then + spawner_mobs[mob] = def._spawner + table.insert(sm_keys, mob) + end + end +end) + +local function timer(pos, elapsed) + --minetest.chat_send_all("timmer activated, elapsed: " .. elapsed) + + local active = false + + local obj_in_rad = minetest.get_objects_inside_radius(pos, 16) + for _, obj in pairs(obj_in_rad) do + if obj:is_player() then + active = true + end + end + + local c_air = minetest.get_content_id("air") + local vm = minetest.get_voxel_manip() + local emin, emax = vm:read_from_map({x=pos.x-sz, y=pos.y-1, z=pos.z-sz}, {x=pos.x+sz, y=pos.y+1, z=pos.z+sz}) + local a = VoxelArea:new{MinEdge = emin, MaxEdge = emax} + local data = vm:get_data() + + local counter = 0 + local light_table = { + [1]={}, [2]={}, [3]={}, + [4]={}, [5]={}, [6]={}, + [7]={}, [8]={}, [9]={}, + [10]={}, [11]={}, [12]={}, + [13]={}, [14]={}, [15]={}, + } + local tod = minetest.get_timeofday() + + for z = pos.z-sz, pos.z+sz do + for y = pos.y-1, pos.y+1 do + for x = pos.x-sz, pos.x+sz do + -- vi, voxel index, is a common variable name here + local vi = a:index(x, y, z) + if data[vi] == c_air then + counter = counter+1 + local apos = {x=x, y=y,z=z} + table.insert(light_table[get_node_light(apos, tod)], apos) + end + end + end + end + + minetest.chat_send_all(counter) + + local meta = minetest.get_meta(pos) + local spawn_mob = meta:get("mob_spawn") or sm_keys[random(#sm_keys)] + if not minetest.registered_entities[spawn_mob] then + --when biome support added, factor it in here + spawn_mob = sm_keys[random(#sm_keys)] + meta:set_string("mob_spawn", spawn_mob) + end + + if active and #obj_in_rad < max_obj then --(max_obj - 10) then + minetest.chat_send_all("trigger") + local j = 0 + while j < random(2,4) do + local rand = random(spawner_mobs[spawn_mob].min_light or 1, spawner_mobs[spawn_mob].max_light or 15) + if #light_table[rand] >= 1 then + minetest.add_entity(light_table[rand][random(#light_table[rand])], spawn_mob) + minetest.chat_send_all("light: " .. rand) + j=j+1 + end + end + + minetest.add_particlespawner({ + amount = 5*10, + time = 5, + minpos = pos, + maxpos = pos, + minvel = {x = -1, y = -1.5, z = -1}, + maxvel = {x = 1, y = 1.5, z = 1}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = 0.5, + maxexptime = 1, + minsize = 1, + maxsize = 2, + texture = "farlands_explosion_small.png", + animation = {type="vertical_frames", aspect_w=32, aspect_h=32, frame_length=1}, + glow = 13, + }) + else + minetest.chat_send_all("to many mobs in area") + end + + --minetest.chat_send_all(minetest.pos_to_string(pos)) + --minetest.chat_send_all(minetest.pos_to_string({x=pos.x-10, y=pos.y-1, z=pos.z-10})) + --minetest.chat_send_all(minetest.pos_to_string({x=pos.x+10, y=pos.y+1, z=pos.z+10})) + + minetest.get_node_timer(pos):start(random(11, 30)) + return false +end + +minetest.register_node("fl_wildlife:spawner", { + description = "wildlife spawner", + paramtype = "light", + drawtype = "glasslike", + tiles = {"farlands_spawner.png"}, + on_construct = function(pos) + minetest.get_node_timer(pos):start(random(11, 30)) + --need to check pos for biome against def + local meta = minetest.get_meta(pos) + meta:set_string("mob_spawn", sm_keys[random(#sm_keys)]) + end, + on_timer = timer, + groups = {oddly_breakable_by_hand = 3}, +}) \ No newline at end of file diff --git a/mods/fl_wildlife/textures/farlands_spawner.png b/mods/fl_wildlife/textures/farlands_spawner.png new file mode 100644 index 0000000000000000000000000000000000000000..ba7e5fd834f3dc9454e3ed64affc682698727058 GIT binary patch literal 881 zcmV-%1CIQOP) z0J?-1i$DMX010qNS#tmY3ljhU3ljkVnw%H_000McNliru;R6^IFDU+nmMZ`N0{%%v zK~y-)U6NgFlXV!yf6u%6w#mkXYUcupNHyVNF<~YmEYYBji;kp0*wm01FGfO;YDgw( z0&CT-fX+>(8-$o?G!d>8HV1J-Wu?nN5ISIfTtFZ$4h7N=`flA@vOZq8y`i4F^FJrg z|2Zd*Ts%9dnM{`I>MF_%14Xf{X{M&8nXzpyoWH`lb*u4sJY=(Xn6Yghs`8OeXBiwi z3s=TZDRb!V>`;F&G*7v7Zcumbc+=7S!4NHPyzcN#O^s?y=kowWTX$*a@HOcR2Q~c8 z+X|4*WSOyT06uJs>Y>avBCgl5AqqExPCmzs!i9e+wuu3;>cvgFpDS6=$arCcS>a~0HFDVoX z@cYi#{paRw zPM%CkQ{!`5R#t{>+qk~`Y5=#}P0q4dP*K66h4<6fpWy$ntSQDXPXKV}@F3;o<)l(6 z7(ai)$++{a9VK@Vi-d_q!rXfY2f99X{DHOgY8ZwAz^@m6(8GV^rMcGY7*?)at_^`z z4&VAzwYL9wRpvjf^7(MN-6sBEh~fAp0D6-tiABQNn@q`)#nl`+8pj_D(Om1*13&*Q z07v^y;SYwGyfKa>&m7ld$4~S5Sh}RNS0Arbm&+vp#bQyvxR@!?U#Y3k$s3axm6Z$F z^?p>=FGT^itzN93ZLQNtY`3ggvqE#0rLEC68QSxrZh6wD02`MX`re+sa`V=0jQNS3 zpLR=gtyg