mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-11-14 06:20:18 +01:00
add on_sound node support and example.
This commit is contained in:
parent
1dd81eb008
commit
f4861ced2a
22
api.lua
22
api.lua
|
@ -18,7 +18,7 @@ end
|
|||
|
||||
mobs = {
|
||||
mod = "redo",
|
||||
version = "20241001",
|
||||
version = "20241002",
|
||||
spawning_mobs = {},
|
||||
translate = S,
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||
|
@ -4794,13 +4794,27 @@ if settings:get_bool("mobs_can_hear") ~= false then
|
|||
def.loudness = def.gain - (bit * def.distance)
|
||||
|
||||
-- run custom on_sound function if heard
|
||||
if def.loudness > 0 then
|
||||
ent.on_sound(ent, def)
|
||||
end
|
||||
if def.loudness > 0 then ent.on_sound(ent, def) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- find nodes that can hear up to 8 blocks away
|
||||
local dist = min(def.max_hear_distance, 8)
|
||||
local ps = minetest.find_nodes_in_area(
|
||||
vector.subtract(def.pos, dist),
|
||||
vector.add(def.pos, dist), {"group:on_sound"})
|
||||
|
||||
if #ps > 0 then
|
||||
|
||||
for n = 1, #ps do
|
||||
|
||||
local ndef = minetest.registered_nodes[minetest.get_node(ps[n]).name]
|
||||
|
||||
if ndef and ndef.on_sound then ndef.on_sound(ps[n], def) end
|
||||
end
|
||||
end
|
||||
|
||||
return old_sound_play(spec, param, eph)
|
||||
end
|
||||
end
|
||||
|
|
8
api.txt
8
api.txt
|
@ -357,6 +357,14 @@ enhance mob functionality and have them do many interesting things:
|
|||
'max_hear_distance' max distance sound can be heard from source.
|
||||
|
||||
|
||||
Hearing Nodes
|
||||
-------------
|
||||
|
||||
If a node has the {on_sound = 1} group and an on_sound() function set as above then
|
||||
nodes within 8 blocks of a sound will be activated and the function run. Check the
|
||||
"mobs:hearing_vines" node as an example which has mesecons support when active.
|
||||
|
||||
|
||||
Internal Variables
|
||||
------------------
|
||||
|
||||
|
|
54
crafts.lua
54
crafts.lua
|
@ -421,3 +421,57 @@ minetest.register_craft({
|
|||
recipe = "mobs:meatblock_raw",
|
||||
cooktime = 30
|
||||
})
|
||||
|
||||
-- hearing vines (if mesecons active it acts like blinkyplant)
|
||||
|
||||
local mod_mese = minetest.get_modpath("mesecons")
|
||||
|
||||
minetest.register_node("mobs:hearing_vines", {
|
||||
description = S("Hearing Vines"),
|
||||
drawtype = "firelike",
|
||||
waving = 1,
|
||||
tiles = {"mobs_hearing_vines.png"},
|
||||
inventory_image = "mobs_hearing_vines.png",
|
||||
wield_image = "mobs_hearing_vines.png",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
groups = {snappy = 3, flammable = 3, attached_node = 1, on_sound = 1},
|
||||
sounds = mobs.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed", fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, -0.25, 6 / 16},
|
||||
},
|
||||
on_sound = function(pos, def)
|
||||
minetest.set_node(pos, {name = "mobs:hearing_vines_active"})
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("mobs:hearing_vines_active", {
|
||||
description = S("Active Hearing Vines"),
|
||||
drawtype = "firelike",
|
||||
waving = 1,
|
||||
tiles = {"mobs_hearing_vines_active.png"},
|
||||
inventory_image = "mobs_hearing_vines_active.png",
|
||||
wield_image = "mobs_hearing_vines_active.png",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
buildable_to = true,
|
||||
light_source = 1,
|
||||
damage_per_second = 4,
|
||||
drop = "mobs:hearing_vines",
|
||||
groups = {snappy = 3, flammable = 3, attached_node = 1, not_in_creative_inventory = 1},
|
||||
sounds = mobs.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed", fixed = {-6 / 16, -0.5, -6 / 16, 6 / 16, -0.25, 6 / 16},
|
||||
},
|
||||
on_construct = function(pos)
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
if mod_mese then mesecon.receptor_on(pos) end
|
||||
end,
|
||||
on_timer = function(pos)
|
||||
minetest.set_node(pos, {name = "mobs:hearing_vines"})
|
||||
if mod_mese then mesecon.receptor_off(pos) end
|
||||
end
|
||||
})
|
||||
|
|
2
mod.conf
2
mod.conf
|
@ -1,4 +1,4 @@
|
|||
name = mobs
|
||||
description = Adds a mob api for mods to add animals or monsters etc.
|
||||
optional_depends = default, tnt, invisibility, lucky_block, cmi, toolranks, pathfinder, player_api, mtobjid, visual_harm_1ndicators, mcl_sounds
|
||||
optional_depends = default, tnt, invisibility, lucky_block, cmi, toolranks, pathfinder, player_api, mtobjid, visual_harm_1ndicators, mcl_sounds, mesecons
|
||||
min_minetest_version = 5.0
|
||||
|
|
BIN
textures/mobs_hearing_vines.png
Normal file
BIN
textures/mobs_hearing_vines.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 114 B |
BIN
textures/mobs_hearing_vines_active.png
Normal file
BIN
textures/mobs_hearing_vines_active.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 126 B |
Loading…
Reference in New Issue
Block a user