mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-07-21 17:40:29 +02:00
Compare commits
9 Commits
65e369e5fc
...
ca34cc2274
Author | SHA1 | Date | |
---|---|---|---|
ca34cc2274 | |||
168014b86f | |||
6f8b6fe3f5 | |||
dd16d63e8e | |||
7bb5e2b382 | |||
7b429df9e9 | |||
0e72f0ca81 | |||
fb42be6b28 | |||
f54c3da9d7 |
70
api.lua
70
api.lua
@ -28,7 +28,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20220205",
|
version = "20220514",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||||
}
|
}
|
||||||
@ -274,9 +274,9 @@ local check_for = function(look_for, look_inside)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if str:find("group:") then
|
if str and str:find("group:") then
|
||||||
|
|
||||||
local group = str:split(":")[2]
|
local group = str:split(":")[2] or ""
|
||||||
|
|
||||||
if minetest.get_item_group(look_for, group) ~= 0 then
|
if minetest.get_item_group(look_for, group) ~= 0 then
|
||||||
return true
|
return true
|
||||||
@ -546,6 +546,7 @@ local new_line_of_sight = function(self, pos1, pos2, stepsize)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- check line of sight using raycasting (thanks Astrobe)
|
-- check line of sight using raycasting (thanks Astrobe)
|
||||||
local ray_line_of_sight = function(self, pos1, pos2)
|
local ray_line_of_sight = function(self, pos1, pos2)
|
||||||
|
|
||||||
@ -914,18 +915,7 @@ function mob_class:check_for_death(cmi_cause)
|
|||||||
self.health = self.hp_max
|
self.health = self.hp_max
|
||||||
end
|
end
|
||||||
|
|
||||||
-- backup nametag so we can show health stats
|
self:update_tag()
|
||||||
-- if not self.nametag2 then
|
|
||||||
-- self.nametag2 = self.nametag or ""
|
|
||||||
-- end
|
|
||||||
|
|
||||||
-- if show_health
|
|
||||||
-- and (cmi_cause and cmi_cause.type == "punch") then
|
|
||||||
|
|
||||||
-- self.htimer = 2
|
|
||||||
-- self.nametag = "♥ " .. self.health .. " / " .. self.hp_max
|
|
||||||
self:update_tag()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -1054,7 +1044,7 @@ end
|
|||||||
-- is mob facing a cliff
|
-- is mob facing a cliff
|
||||||
function mob_class:is_at_cliff()
|
function mob_class:is_at_cliff()
|
||||||
|
|
||||||
if self.fear_height == 0 then -- 0 for no falling protection!
|
if self.driver or self.fear_height == 0 then -- 0 for no falling protection!
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1098,14 +1088,7 @@ function mob_class:do_env_damage()
|
|||||||
self.htimer = self.htimer - 1
|
self.htimer = self.htimer - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset nametag after showing health stats
|
self:update_tag()
|
||||||
-- if self.htimer < 1 and self.nametag2 then
|
|
||||||
|
|
||||||
-- self.nametag = self.nametag2
|
|
||||||
-- self.nametag2 = nil
|
|
||||||
|
|
||||||
self:update_tag()
|
|
||||||
-- end
|
|
||||||
|
|
||||||
local pos = self.object:get_pos() ; if not pos then return end
|
local pos = self.object:get_pos() ; if not pos then return end
|
||||||
|
|
||||||
@ -1704,6 +1687,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local pathfinder_mod = minetest.get_modpath("pathfinder")
|
local pathfinder_mod = minetest.get_modpath("pathfinder")
|
||||||
|
|
||||||
-- path finding and smart mob routine by rnd,
|
-- path finding and smart mob routine by rnd,
|
||||||
-- line_of_sight and other edits by Elkien3
|
-- line_of_sight and other edits by Elkien3
|
||||||
function mob_class:smart_mobs(s, p, dist, dtime)
|
function mob_class:smart_mobs(s, p, dist, dtime)
|
||||||
@ -2132,7 +2116,7 @@ function mob_class:follow_flop()
|
|||||||
|
|
||||||
for n = 1, #players do
|
for n = 1, #players do
|
||||||
|
|
||||||
if get_distance(players[n]:get_pos(), s) < self.view_range
|
if players[n] and get_distance(players[n]:get_pos(), s) < self.view_range
|
||||||
and not is_invisible(self, players[n]:get_player_name()) then
|
and not is_invisible(self, players[n]:get_player_name()) then
|
||||||
|
|
||||||
self.following = players[n]
|
self.following = players[n]
|
||||||
@ -2389,11 +2373,22 @@ function mob_class:do_states(dtime)
|
|||||||
else
|
else
|
||||||
self:set_velocity(self.walk_velocity)
|
self:set_velocity(self.walk_velocity)
|
||||||
|
|
||||||
|
-- figure out which animation to use while in motion
|
||||||
if self:flight_check()
|
if self:flight_check()
|
||||||
and self.animation
|
and self.animation
|
||||||
and self.animation.fly_start
|
and self.animation.fly_start
|
||||||
and self.animation.fly_end then
|
and self.animation.fly_end then
|
||||||
self:set_animation("fly")
|
|
||||||
|
local on_ground = minetest.registered_nodes[self.standing_on].walkable
|
||||||
|
local in_water = minetest.registered_nodes[self.standing_in].groups.water
|
||||||
|
|
||||||
|
if on_ground and in_water then
|
||||||
|
self:set_animation("fly")
|
||||||
|
elseif on_ground then
|
||||||
|
self:set_animation("walk")
|
||||||
|
else
|
||||||
|
self:set_animation("fly")
|
||||||
|
end
|
||||||
else
|
else
|
||||||
self:set_animation("walk")
|
self:set_animation("walk")
|
||||||
end
|
end
|
||||||
@ -3013,7 +3008,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir, damage)
|
|||||||
if self:check_for_death({type = "punch", puncher = hitter, hot = hot}) then
|
if self:check_for_death({type = "punch", puncher = hitter, hot = hot}) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end -- END if damage
|
end
|
||||||
|
|
||||||
-- knock back effect (only on full punch)
|
-- knock back effect (only on full punch)
|
||||||
if self.knock_back and tflp >= punch_interval then
|
if self.knock_back and tflp >= punch_interval then
|
||||||
@ -3156,8 +3151,6 @@ function mob_class:mob_staticdata()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--print('===== '..self.name..'\n'.. dump(tmp)..'\n=====\n')
|
|
||||||
|
|
||||||
return minetest.serialize(tmp)
|
return minetest.serialize(tmp)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -3368,8 +3361,7 @@ function mob_class:mob_expire(pos, dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- minetest.log("action",
|
-- minetest.log("action", S("lifetimer expired, removed @1", self.name))
|
||||||
-- S("lifetimer expired, removed @1", self.name))
|
|
||||||
|
|
||||||
effect(pos, 15, "tnt_smoke.png", 2, 4, 2, 0)
|
effect(pos, 15, "tnt_smoke.png", 2, 4, 2, 0)
|
||||||
|
|
||||||
@ -3396,9 +3388,9 @@ function mob_class:on_step(dtime, moveresult)
|
|||||||
-- early warning check, if no yaw then no entity, skip rest of function
|
-- early warning check, if no yaw then no entity, skip rest of function
|
||||||
if not yaw then return end
|
if not yaw then return end
|
||||||
|
|
||||||
-- get node at foot level every quarter second
|
|
||||||
self.node_timer = (self.node_timer or 0) + dtime
|
self.node_timer = (self.node_timer or 0) + dtime
|
||||||
|
|
||||||
|
-- get nodes above and below foot level every 1/4 second
|
||||||
if self.node_timer > 0.25 then
|
if self.node_timer > 0.25 then
|
||||||
|
|
||||||
self.node_timer = 0
|
self.node_timer = 0
|
||||||
@ -3696,7 +3688,7 @@ minetest.register_entity(name, setmetatable({
|
|||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
return self:mob_staticdata(self)
|
return self:mob_staticdata(self)
|
||||||
end,
|
end
|
||||||
|
|
||||||
}, mob_class_meta))
|
}, mob_class_meta))
|
||||||
|
|
||||||
@ -4498,7 +4490,7 @@ end
|
|||||||
function mobs:capture_mob(self, clicker, chance_hand, chance_net,
|
function mobs:capture_mob(self, clicker, chance_hand, chance_net,
|
||||||
chance_lasso, force_take, replacewith)
|
chance_lasso, force_take, replacewith)
|
||||||
|
|
||||||
if not self --self.child
|
if not self
|
||||||
or not clicker:is_player()
|
or not clicker:is_player()
|
||||||
or not clicker:get_inventory() then
|
or not clicker:get_inventory() then
|
||||||
return false
|
return false
|
||||||
@ -4702,15 +4694,6 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||||||
if self.health >= self.hp_max then
|
if self.health >= self.hp_max then
|
||||||
|
|
||||||
self.health = self.hp_max
|
self.health = self.hp_max
|
||||||
|
|
||||||
-- if self.htimer < 1 then
|
|
||||||
|
|
||||||
-- minetest.chat_send_player(clicker:get_player_name(),
|
|
||||||
-- S("@1 at full health (@2)",
|
|
||||||
-- self.name:split(":")[2], tostring(self.health)))
|
|
||||||
|
|
||||||
-- self.htimer = 5
|
|
||||||
-- end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:set_hp(self.health)
|
self.object:set_hp(self.health)
|
||||||
@ -4718,7 +4701,6 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
|||||||
-- make children grow quicker
|
-- make children grow quicker
|
||||||
if self.child == true then
|
if self.child == true then
|
||||||
|
|
||||||
-- self.hornytimer = self.hornytimer + 20
|
|
||||||
-- deduct 10% of the time to adulthood
|
-- deduct 10% of the time to adulthood
|
||||||
self.hornytimer = math.floor(self.hornytimer + (
|
self.hornytimer = math.floor(self.hornytimer + (
|
||||||
(CHILD_GROW_TIME - self.hornytimer) * 0.1))
|
(CHILD_GROW_TIME - self.hornytimer) * 0.1))
|
||||||
|
2
api.txt
2
api.txt
@ -415,7 +415,7 @@ the mobs:spawn, so it is recommended to use the above instead.
|
|||||||
mobs:register_spawn(name, nodes, max_light, min_light, chance,
|
mobs:register_spawn(name, nodes, max_light, min_light, chance,
|
||||||
active_object_count, max_height, day_toggle)
|
active_object_count, max_height, day_toggle)
|
||||||
|
|
||||||
mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval,
|
mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval,
|
||||||
chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
|
chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
|
||||||
|
|
||||||
A simpler way to handle mob spawns has been added with the mobs:spawn(def)
|
A simpler way to handle mob spawns has been added with the mobs:spawn(def)
|
||||||
|
22
mount.lua
22
mount.lua
@ -254,7 +254,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
-- move forwards
|
-- move forwards
|
||||||
if ctrl.up then
|
if ctrl.up then
|
||||||
|
|
||||||
entity.v = entity.v + entity.accel / 10
|
entity.v = entity.v + entity.accel * dtime
|
||||||
|
|
||||||
-- move backwards
|
-- move backwards
|
||||||
elseif ctrl.down then
|
elseif ctrl.down then
|
||||||
@ -263,7 +263,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
entity.v = entity.v - entity.accel / 10
|
entity.v = entity.v - entity.accel * dtime
|
||||||
end
|
end
|
||||||
|
|
||||||
-- mob rotation
|
-- mob rotation
|
||||||
@ -296,7 +296,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
|
|
||||||
elseif velo.y > 0 then
|
elseif velo.y > 0 then
|
||||||
|
|
||||||
velo.y = velo.y - 0.1
|
velo.y = velo.y - dtime
|
||||||
|
|
||||||
if velo.y < 0 then velo.y = 0 end
|
if velo.y < 0 then velo.y = 0 end
|
||||||
end
|
end
|
||||||
@ -310,7 +310,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
|
|
||||||
elseif velo.y < 0 then
|
elseif velo.y < 0 then
|
||||||
|
|
||||||
velo.y = velo.y + 0.1
|
velo.y = velo.y + dtime
|
||||||
|
|
||||||
if velo.y > 0 then velo.y = 0 end
|
if velo.y > 0 then velo.y = 0 end
|
||||||
end
|
end
|
||||||
@ -355,14 +355,10 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- enforce speed limit forward and reverse
|
-- enforce speed limit forward and reverse
|
||||||
local max_spd = entity.max_speed_reverse
|
if entity.v > entity.max_speed_forward then
|
||||||
|
entity.v = entity.max_speed_forward
|
||||||
if get_sign(entity.v) >= 0 then
|
elseif entity.v < -entity.max_speed_reverse then
|
||||||
max_spd = entity.max_speed_forward
|
entity.v = -entity.max_speed_reverse
|
||||||
end
|
|
||||||
|
|
||||||
if abs(entity.v) > max_spd then
|
|
||||||
entity.v = entity.v - get_sign(entity.v)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set position, velocity and acceleration
|
-- Set position, velocity and acceleration
|
||||||
@ -370,7 +366,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
|||||||
|
|
||||||
if not p then return end
|
if not p then return end
|
||||||
|
|
||||||
local new_acce = {x = 0, y = -9.81, z = 0}
|
local new_acce = {x = 0, y = entity.fall_speed, z = 0}
|
||||||
|
|
||||||
p.y = p.y - 0.5
|
p.y = p.y - 0.5
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user