1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-09-28 23:40:34 +02:00

Updated mob mod

- Slightly changed API
- Added textures, and sounds
- Removed .env calls
This commit is contained in:
LeMagnesium 2015-03-02 22:29:17 +01:00
parent 911f49faa4
commit 66104e5ff6
26 changed files with 82 additions and 85 deletions

View File

@ -28,6 +28,7 @@ This mod contains the following additions:
Changelog: Changelog:
1.01- Mobs that suffer fall damage or die in water/lava/sunlight will now drop items
1.0 - more work on Api so that certain mobs can float in water while some sink like a brick :) 1.0 - more work on Api so that certain mobs can float in water while some sink like a brick :)
0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked 0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked
0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound 0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound

View File

@ -1,9 +1,10 @@
-- Mobs Api (1st March 2015)
mobs = {} mobs = {}
-- Set global for other mod checks (e.g. Better HUD uses this) -- Set global for other mod checks (e.g. Better HUD uses this)
mobs.mod = "redo" mobs.mod = "redo"
-- Do mobs spawn in protected areas (0=no, 1=yes) -- Do mobs spawn in protected areas (0=yes, 1=no)
mobs.protected = 0 mobs.protected = 0
-- Initial check to see if damage is enabled -- Initial check to see if damage is enabled
@ -40,7 +41,7 @@ function mobs:register_mob(name, def)
attack_type = def.attack_type, attack_type = def.attack_type,
arrow = def.arrow, arrow = def.arrow,
shoot_interval = def.shoot_interval, shoot_interval = def.shoot_interval,
sounds = def.sounds, sounds = def.sounds or {},
animation = def.animation, animation = def.animation,
follow = def.follow, follow = def.follow,
jump = def.jump or true, jump = def.jump or true,
@ -49,15 +50,13 @@ function mobs:register_mob(name, def)
walk_chance = def.walk_chance or 50, walk_chance = def.walk_chance or 50,
attacks_monsters = def.attacks_monsters or false, attacks_monsters = def.attacks_monsters or false,
group_attack = def.group_attack or false, group_attack = def.group_attack or false,
step = def.step or 0, --fov = def.fov or 120,
fov = def.fov or 120,
passive = def.passive or false, passive = def.passive or false,
recovery_time = def.recovery_time or 0.5, recovery_time = def.recovery_time or 0.5,
knock_back = def.knock_back or 1, --knock_back = def.knock_back or 3, knock_back = def.knock_back or 1, --knock_back = def.knock_back or 3,
blood_offset = def.blood_offset or 0, blood_offset = def.blood_offset or 0,
blood_amount = def.blood_amount or 5, blood_amount = def.blood_amount or 5,
blood_texture = def.blood_texture or "mobs_blood.png", blood_texture = def.blood_texture or "mobs_blood.png",
rewards = def.rewards or nil,
shoot_offset = def.shoot_offset or 0, shoot_offset = def.shoot_offset or 0,
floats = def.floats or 1, -- floats in water by default floats = def.floats or 1, -- floats in water by default
@ -75,9 +74,9 @@ function mobs:register_mob(name, def)
do_attack = function(self, player, dist) do_attack = function(self, player, dist)
if self.state ~= "attack" then if self.state ~= "attack" then
-- if math.random(0,100) < 90 and self.sounds.war_cry then if math.random(0,100) < 90 and self.sounds.war_cry then
-- minetest.sound_play(self.sounds.war_cry,{ object = self.object }) minetest.sound_play(self.sounds.war_cry,{ object = self.object })
-- end end
self.state = "attack" self.state = "attack"
self.attack.player = player self.attack.player = player
self.attack.dist = dist self.attack.dist = dist
@ -218,9 +217,7 @@ function mobs:register_mob(name, def)
if d > 5 then if d > 5 then
local damage = d-5 local damage = d-5
self.object:set_hp(self.object:get_hp()-damage) self.object:set_hp(self.object:get_hp()-damage)
if self.object:get_hp() == 0 then check_for_death(self)
self.object:remove()
end
end end
self.old_y = self.object:getpos().y self.old_y = self.object:getpos().y
end end
@ -230,7 +227,7 @@ function mobs:register_mob(name, def)
-- pause is only set after a monster is hit -- pause is only set after a monster is hit
if self.pause_timer > 0 then if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime self.pause_timer = self.pause_timer - dtime
if self.pause_timer <= 0 then if self.pause_timer < 1 then
self.pause_timer = 0 self.pause_timer = 0
end end
return return
@ -272,10 +269,7 @@ function mobs:register_mob(name, def)
self.object:set_hp(self.object:get_hp()-self.lava_damage) ; --print ("lava damage") self.object:set_hp(self.object:get_hp()-self.lava_damage) ; --print ("lava damage")
end end
if self.object:get_hp() < 1 then check_for_death(self)
self.object:remove()
end
end end
self.env_damage_timer = self.env_damage_timer + dtime self.env_damage_timer = self.env_damage_timer + dtime
@ -590,8 +584,7 @@ function mobs:register_mob(name, def)
on_activate = function(self, staticdata, dtime_s) on_activate = function(self, staticdata, dtime_s)
local pos = self.object:getpos() local pos = self.object:getpos()
-- reset HP self.object:set_hp( math.random(self.hp_min, self.hp_max) ) -- reset HP
self.object:set_hp( math.random(self.hp_min, self.hp_max) )
self.object:set_armor_groups({fleshy=self.armor}) self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y=-10, z=0}) self.object:setacceleration({x=0, y=-10, z=0})
self.state = "stand" self.state = "stand"
@ -640,54 +633,30 @@ function mobs:register_mob(name, def)
on_punch = function(self, hitter, tflp, tool_capabilities, dir) on_punch = function(self, hitter, tflp, tool_capabilities, dir)
process_weapon(hitter,tflp,tool_capabilities) process_weapon(hitter,tflp,tool_capabilities)
local pos = self.object:getpos() local pos = self.object:getpos()
if self.object:get_hp() < 1 then check_for_death(self)
if hitter and hitter:is_player() then -- and hitter:get_inventory() then
for _,drop in ipairs(self.drops) do
if math.random(1, drop.chance) == 1 then
local d = ItemStack(drop.name.." "..math.random(drop.min, drop.max))
local pos2 = pos
pos2.y = pos2.y + 0.5 -- drop items half block higher
local obj = minetest.add_item(pos2, d)
if obj then
obj:setvelocity({x=math.random(-1,1), y=5, z=math.random(-1,1)})
end
end
end
-- if self.sounds.death ~= nil then
-- minetest.sound_play(self.sounds.death,{object = self.object,})
-- end
end
end
--blood_particles --blood_particles
--[[
if self.blood_amount > 0 and pos then if self.blood_amount > 0 and pos then
local p = pos local p = pos
p.y = p.y + self.blood_offset p.y = p.y + self.blood_offset
minetest.add_particlespawner({
minetest.add_particlespawner( amount = self.blood_amount,
5, --blood_amount, --amount time = 0.25,
0.25, --time minpos = {x=p.x-0.2, y=p.y-0.2, z=p.z-0.2},
{x=p.x-0.2, y=p.y-0.2, z=p.z-0.2}, --minpos maxpos = {x=p.x+0.2, y=p.y+0.2, z=p.z+0.2},
{x=p.x+0.2, y=p.y+0.2, z=p.z+0.2}, --maxpos minvel = {x=-0, y=-2, z=-0},
{x=0, y=-2, z=0}, --minvel maxvel = {x=2, y=2, z=2},
{x=2, y=2, z=2}, --maxvel minacc = {x=-4, y=-4, z=-4},
{x=-4,y=-4,z=-4}, --minacc maxacc = {x=4, y=4, z=4},
{x=4,y=-4,z=4}, --maxacc minexptime = 0.1,
0.1, --minexptime maxexptime = 1,
1, --maxexptime minsize = 0.5,
0.5, --minsize maxsize = 1,
1, --maxsize texture = self.blood_texture,
false, --collisiondetection })
self.blood_texture --texture
)
end end
]]--
-- knock back effect, adapted from blockmen's pyramids mod -- knock back effect, adapted from blockmen's pyramids mod
-- https://github.com/BlockMen/pyramids -- https://github.com/BlockMen/pyramids
local kb = self.knock_back local kb = self.knock_back
@ -741,7 +710,8 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
-- do not spawn if too many in one active area -- do not spawn if too many in one active area
if active_object_count_wider > active_object_count if active_object_count_wider > active_object_count
or not mobs.spawning_mobs[name] then or not mobs.spawning_mobs[name]
or not pos then
return return
end end
@ -762,16 +732,20 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
end end
-- are we spawning inside a node? -- are we spawning inside a node?
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end local nod = minetest.get_node_or_nil(pos)
if not nod then return end
if minetest.registered_nodes[nod.name].walkable == true then return end
pos.y = pos.y + 1 pos.y = pos.y + 1
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end nod = minetest.get_node_or_nil(pos)
pos.y = pos.y - 1 if not nod then return end
if minetest.registered_nodes[nod.name].walkable == true then return end
if minetest.setting_getbool("display_mob_spawn") then if minetest.setting_getbool("display_mob_spawn") then
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos)) minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
end end
-- spawn mob -- spawn mob half block higher
pos.y = pos.y - 0.5
local mob = minetest.add_entity(pos, name) local mob = minetest.add_entity(pos, name)
-- set mob health (randomly between min and max) -- set mob health (randomly between min and max)
@ -783,6 +757,29 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
}) })
end end
-- on mob death drop items
function check_for_death(self)
if self.object:get_hp() < 1 then
local pos = self.object:getpos()
pos.y = pos.y + 0.5 -- drop items half a block higher
self.object:remove()
for _,drop in ipairs(self.drops) do
if math.random(1, drop.chance) == 1 then
local d = ItemStack(drop.name.." "..math.random(drop.min, drop.max))
local obj = minetest.add_item(pos, d)
if obj then
obj:setvelocity({x=math.random(-1,1), y=5, z=math.random(-1,1)})
end
end
end
if self.sounds.death ~= nil then
minetest.sound_play(self.sounds.death,{object = self.object,})
end
end
end
function mobs:register_arrow(name, def) function mobs:register_arrow(name, def)
minetest.register_entity(name, { minetest.register_entity(name, {
physical = false, physical = false,
@ -843,7 +840,7 @@ minetest.register_craftitem(mob, {
local pos = pointed_thing.above local pos = pointed_thing.above
if pointed_thing.above and not minetest.is_protected(pos, placer:get_player_name()) then if pointed_thing.above and not minetest.is_protected(pos, placer:get_player_name()) then
pos.y = pos.y + 0.5 pos.y = pos.y + 0.5
minetest.env:add_entity(pos, mob) minetest.add_entity(pos, mob)
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack

View File

@ -82,7 +82,7 @@ minetest.register_node("mobs:beehive", {
after_place_node = function(pos, placer, itemstack) after_place_node = function(pos, placer, itemstack)
if placer:is_player() then if placer:is_player() then
minetest.set_node(pos, {name="mobs:beehive", param2=1}) minetest.set_node(pos, {name="mobs:beehive", param2=1})
minetest.env:add_entity(pos, "mobs:bee") minetest.add_entity(pos, "mobs:bee")
end end
end, end,

View File

@ -62,16 +62,11 @@ mobs:register_mob("mobs:cow", {
end, end,
animation = { animation = {
speed_normal = 15, speed_normal = 15, speed_run = 15,
speed_run = 15, stand_start = 0, stand_end = 30,
stand_start = 0, walk_start = 35, walk_end = 65,
stand_end = 30, run_start = 105, run_end = 135,
walk_start = 35, punch_start = 70, punch_end = 100,
walk_end = 65,
run_start = 105,
run_end = 135,
punch_start = 70,
punch_end = 100,
}, },
jump = true, jump = true,

View File

@ -110,7 +110,7 @@ mobs:register_arrow("mobs:fireball", {
for dy=-1,1 do for dy=-1,1 do
for dz=-1,1 do for dz=-1,1 do
local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz} local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz}
local n = minetest.env:get_node(p).name local n = minetest.get_node(p).name
local excluding = minetest.registered_nodes[n].groups["unbreakable"] ~= nil local excluding = minetest.registered_nodes[n].groups["unbreakable"] ~= nil
or n:split(":")[1] == "nether" or n:split(":")[1] == "nether"
for _,i in ipairs(excluded) do for _,i in ipairs(excluded) do
@ -121,11 +121,13 @@ mobs:register_arrow("mobs:fireball", {
if excluding then if excluding then
return return
end end
if n ~= "default:obsidian" and n ~= "ethereal:obsidian_brick" then if n ~= "default:obsidian"
and n ~= "default:obsidianbrick"
and not n:find("protector:") then
if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30 then if minetest.registered_nodes[n].groups.flammable or math.random(1, 100) <= 30 then
minetest.env:set_node(p, {name="fire:basic_flame"}) minetest.set_node(p, {name="fire:basic_flame"})
else else
minetest.env:set_node(p, {name="air"}) minetest.set_node(p, {name="air"})
end end
end end
end end

View File

@ -1,4 +1,4 @@
-- Mob Api (20th Feb 2015) -- Mob Api
dofile(minetest.get_modpath("mobs").."/api.lua") dofile(minetest.get_modpath("mobs").."/api.lua")

View File

@ -55,6 +55,8 @@ mobs:register_mob("mobs:lava_flan", {
}, },
sounds = { sounds = {
random = "mobs_lavaflan", random = "mobs_lavaflan",
war_cry = "mobs_lavaflan",
death = nil,
}, },
jump = true, jump = true,
step = 2, step = 2,

BIN
mods/mobs/models/mobs_dirt_monster.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
mods/mobs/models/mobs_pumba.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

BIN
mods/mobs/models/mobs_sheep.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
mods/mobs/models/mobs_sheep_shaved.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -103,8 +103,8 @@ minetest.register_node("mobs:cobweb", {
minetest.register_craft({ minetest.register_craft({
output = "mobs:cobweb", output = "mobs:cobweb",
recipe = { recipe = {
{"farming:string", "farming:string", "farming:string"}, {"farming:string", "", "farming:string"},
{"farming:string", "farming:string", "farming:string"}, {"", "farming:string", ""},
{"farming:string", "farming:string", "farming:string"}, {"farming:string", "", "farming:string"},
} }
}) })

View File

@ -60,7 +60,7 @@ mobs:register_mob("mobs:pumba", {
end, end,
}) })
mobs:register_spawn("mobs:pumba", {"default:dirt_with_grass", "default:dirt"}, 20, 8, 9000, 1, 31000) mobs:register_spawn("mobs:pumba", {"ethereal:mushroom_dirt", "default:dirt_with_grass", "default:dirt"}, 20, 8, 9000, 1, 31000)
mobs:register_egg("mobs:pumba", "Warthog", "wool_pink.png", 1) mobs:register_egg("mobs:pumba", "Warthog", "wool_pink.png", 1)
-- Porkchops -- Porkchops