1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-24 09:40:21 +01:00

add "all" to immune_to table, optimized floating code

This commit is contained in:
TenPlus1 2018-05-30 10:55:39 +01:00
parent 82c8386eb3
commit 12a3c8975f
5 changed files with 43 additions and 10 deletions

43
api.lua
View File

@ -3,7 +3,7 @@
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20180523" mobs.version = "20180530"
-- Intllib -- Intllib
@ -289,13 +289,12 @@ end
-- are we flying in what we are suppose to? (taikedz) -- are we flying in what we are suppose to? (taikedz)
local flight_check = function(self, pos_w) local flight_check = function(self, pos_w)
local nod = self.standing_in local def = minetest.registered_nodes[self.standing_in]
local def = minetest.registered_nodes[nod]
if not def then return false end -- nil check if not def then return false end -- nil check
if type(self.fly_in) == "string" if type(self.fly_in) == "string"
and nod == self.fly_in then and self.standing_in == self.fly_in then
return true return true
@ -303,7 +302,7 @@ local flight_check = function(self, pos_w)
for _,fly_in in pairs(self.fly_in) do for _,fly_in in pairs(self.fly_in) do
if nod == fly_in then if self.standing_in == fly_in then
return true return true
end end
@ -626,7 +625,7 @@ local do_env_damage = function(self)
if check_for_death(self, "light", {type = "light"}) then return end if check_for_death(self, "light", {type = "light"}) then return end
end end
--[[
local y_level = self.collisionbox[2] local y_level = self.collisionbox[2]
if self.child then if self.child then
@ -637,7 +636,7 @@ local do_env_damage = function(self)
pos.y = pos.y + y_level + 0.25 -- foot level pos.y = pos.y + y_level + 0.25 -- foot level
self.standing_in = node_ok(pos, "air").name self.standing_in = node_ok(pos, "air").name
-- print ("standing in " .. self.standing_in) -- print ("standing in " .. self.standing_in)
]]
-- don't fall when on ignore, just stand still -- don't fall when on ignore, just stand still
if self.standing_in == "ignore" then if self.standing_in == "ignore" then
self.object:setvelocity({x = 0, y = 0, z = 0}) self.object:setvelocity({x = 0, y = 0, z = 0})
@ -2289,13 +2288,13 @@ local falling = function(self, pos)
end end
-- in water then float up -- in water then float up
if minetest.registered_nodes[node_ok(pos).name].groups.water then if minetest.registered_nodes[self.standing_in].groups.water then
if self.floats == 1 then if self.floats == 1 then
self.object:setacceleration({ self.object:setacceleration({
x = 0, x = 0,
y = -self.fall_speed / (max(1, v.y) ^ 2), y = -self.fall_speed / (max(1, v.y) ^ 8), -- 8 was 2
z = 0 z = 0
}) })
end end
@ -2395,6 +2394,10 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
damage = self.immune_to[n][2] or 0 damage = self.immune_to[n][2] or 0
break break
-- if "all" then no tool does damage unless it's specified in list
elseif self.immune_to[n][1] == "all" then
damage = self.immune_to[n][2] or 0
end end
end end
@ -2751,7 +2754,7 @@ local mob_activate = function(self, staticdata, def, dtime)
self.collisionbox = colbox self.collisionbox = colbox
self.selectionbox = selbox self.selectionbox = selbox
self.visual_size = vis_size self.visual_size = vis_size
self.standing_in = "" self.standing_in = "air"
-- check existing nametag -- check existing nametag
if not self.nametag then if not self.nametag then
@ -2828,6 +2831,26 @@ local mob_step = function(self, dtime)
end end
end end
-- get node at foot level every quarter second
self.node_timer = (self.node_timer or 0) + dtime
if self.node_timer > 0.25 then
self.node_timer = 0
local y_level = self.collisionbox[2]
if self.child then
y_level = self.collisionbox[2] * 0.5
end
-- what is mob standing in?
self.standing_in = node_ok({
x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name
-- print ("standing in " .. self.standing_in)
end
-- check if falling, flying, floating
falling(self, pos) falling(self, pos)
-- smooth rotation by ThomasMonroe314 -- smooth rotation by ThomasMonroe314

View File

@ -126,6 +126,7 @@ functions needed for the mob to work properly which contains the following:
{"default:sword_wood", 0} -- causes no damage. {"default:sword_wood", 0} -- causes no damage.
{"default:gold_lump", -10} -- heals by 10 health points. {"default:gold_lump", -10} -- heals by 10 health points.
{"default:coal_block", 20} -- 20 damage when hit on head with coal blocks. {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks.
{"all"} -- stops all weapons causing damage apart from those on list.
'makes_footstep_sound' when true you can hear mobs walking. 'makes_footstep_sound' when true you can hear mobs walking.
'sounds' this is a table with sounds of the mob 'sounds' this is a table with sounds of the mob

View File

@ -176,3 +176,9 @@ minetest.register_craft({
recipe = "mobs:saddle", recipe = "mobs:saddle",
burntime = 7, burntime = 7,
}) })
minetest.register_craft({
type = "fuel",
recipe = "mobs:fence_wood",
burntime = 7,
})

View File

@ -6,10 +6,12 @@ if minetest.get_modpath("lucky_block") then
{"dro", {"mobs:meat"}, 5}, {"dro", {"mobs:meat"}, 5},
{"dro", {"mobs:nametag"}, 1}, {"dro", {"mobs:nametag"}, 1},
{"dro", {"mobs:leather"}, 5}, {"dro", {"mobs:leather"}, 5},
{"dro", {"default:stick"}, 10},
{"dro", {"mobs:net"}, 1}, {"dro", {"mobs:net"}, 1},
{"dro", {"mobs:lasso"}, 1}, {"dro", {"mobs:lasso"}, 1},
{"dro", {"mobs:shears"}, 1}, {"dro", {"mobs:shears"}, 1},
{"dro", {"mobs:protector"}, 1}, {"dro", {"mobs:protector"}, 1},
{"dro", {"mobs:fence_wood"}, 10},
{"lig"}, {"lig"},
}) })
end end

View File

@ -22,6 +22,7 @@ Lucky Blocks: 9
Changelog: Changelog:
- 1.42- Added "all" option to immune_to table, tidied floating mobs to be less intensive
- 1.41- Mob pathfinding has been updated thanks to Elkien3 - 1.41- Mob pathfinding has been updated thanks to Elkien3
- 1.40- Updated to use newer functions, requires Minetest 0.4.16+ to work. - 1.40- Updated to use newer functions, requires Minetest 0.4.16+ to work.
- 1.39- Added 'on_breed', 'on_grown' and 'do_punch' custom functions per mob - 1.39- Added 'on_breed', 'on_grown' and 'do_punch' custom functions per mob