code tweaks and new settings

This commit is contained in:
TenPlus1 2017-07-08 09:08:23 +01:00
parent 27390b2e36
commit 1f800ff583
5 changed files with 62 additions and 37 deletions

43
api.lua
View File

@ -1,9 +1,9 @@
-- Mobs Api (7th July 2017) -- Mobs Api (8th July 2017)
mobs = {} mobs = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20170707" mobs.version = "20170708"
-- Intllib -- Intllib
@ -64,6 +64,13 @@ local enable_pathfinding = true
local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching
local stuck_path_timeout = 10 -- how long will mob follow path before giving up local stuck_path_timeout = 10 -- how long will mob follow path before giving up
-- default nodes
local node_fire = "fire:basic_flame"
local node_permanent_flame = "fire:permanent_flame"
local node_ice = "default:ice"
local node_snowblock = "default:snowblock"
local node_snow = "default:snow"
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt"
-- play sound -- play sound
local mob_sound = function(self, sound) local mob_sound = function(self, sound)
@ -242,9 +249,10 @@ end
local flight_check = function(self, pos_w) local flight_check = function(self, pos_w)
local nod = self.standing_in local nod = self.standing_in
local def = minetest.registered_nodes[nod]
if type(self.fly_in) == "string" if type(self.fly_in) == "string"
and (nod == self.fly_in or nod == self.fly_in:gsub("_source", "_flowing")) then and (nod == self.fly_in or def.liquid_alternative_flowing ~= "") then
return true return true
@ -252,7 +260,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 or nod == fly_in:gsub("_source", "_flowing") then if nod == fly_in or def.liquid_alternative_flowing ~= "" then
return true return true
end end
@ -507,7 +515,7 @@ end
-- get node but use fallback for nil or unknown -- get node but use fallback for nil or unknown
local node_ok = function(pos, fallback) local node_ok = function(pos, fallback)
fallback = fallback or "default:dirt" fallback = fallback or mobs.fallback_node
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)
@ -598,8 +606,8 @@ local do_env_damage = function(self)
-- lava or fire -- lava or fire
elseif self.lava_damage elseif self.lava_damage
and (nodef.groups.lava and (nodef.groups.lava
or self.standing_in == "fire:basic_flame" or self.standing_in == node_fire
or self.standing_in == "fire:permanent_flame") then or self.standing_in == node_permanent_flame) then
if self.lava_damage ~= 0 then if self.lava_damage ~= 0 then
@ -681,7 +689,7 @@ local do_jump = function(self)
}) })
-- thin blocks that do not need to be jumped -- thin blocks that do not need to be jumped
if nod.name == "default:snow" then if nod.name == node_snow then
return false return false
end end
@ -1049,7 +1057,7 @@ local smart_mobs = function(self, s, p, dist, dtime)
if ndef1 and (ndef1.buildable_to or ndef1.groups.liquid) then if ndef1 and (ndef1.buildable_to or ndef1.groups.liquid) then
minetest.set_node(s, {name = "default:dirt"}) minetest.set_node(s, {name = mobs.fallback_node})
end end
end end
@ -1511,7 +1519,7 @@ local do_states = function(self, dtime)
and minetest.registered_nodes[self.standing_in].groups.water) then and minetest.registered_nodes[self.standing_in].groups.water) then
lp = minetest.find_node_near(s, 5, {"group:soil", "group:stone", lp = minetest.find_node_near(s, 5, {"group:soil", "group:stone",
"group:sand", "default:ice", "default:snowblock"}) "group:sand", node_ice, node_snowblock})
-- did we find land? -- did we find land?
if lp then if lp then
@ -1675,6 +1683,8 @@ local do_states = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local radius = self.explosion_radius or 1 local radius = self.explosion_radius or 1
local fire = self.explosion_fire or 1
local smoke = self.explosion_smoke or 1
-- dont damage anything if area protected or next to water -- dont damage anything if area protected or next to water
if minetest.find_node_near(pos, 1, {"group:water"}) if minetest.find_node_near(pos, 1, {"group:water"})
@ -1695,7 +1705,7 @@ local do_states = function(self, dtime)
pos.y = pos.y - 1 pos.y = pos.y - 1
mobs:explosion(pos, radius, 1, 1, self.sounds.explode) mobs:explosion(pos, radius, fire, smoke, self.sounds.explode)
self.object:remove() self.object:remove()
@ -2622,6 +2632,8 @@ minetest.register_entity(name, {
pathfinding = def.pathfinding, pathfinding = def.pathfinding,
immune_to = def.immune_to or {}, immune_to = def.immune_to or {},
explosion_radius = def.explosion_radius, explosion_radius = def.explosion_radius,
explosion_fire = def.explosion_fire,
explosion_smoke = def.explosion_smoke,
custom_attack = def.custom_attack, custom_attack = def.custom_attack,
double_melee_attack = def.double_melee_attack, double_melee_attack = def.double_melee_attack,
dogshoot_switch = def.dogshoot_switch, dogshoot_switch = def.dogshoot_switch,
@ -2920,7 +2932,7 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
if on_blast then if on_blast then
return on_blast(p) on_blast(p)
elseif minetest.registered_nodes[n].groups.unbreakable == 1 then elseif minetest.registered_nodes[n].groups.unbreakable == 1 then
@ -2930,9 +2942,12 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
-- after effects -- after effects
if fire > 0 if fire > 0
and (minetest.registered_nodes[n].groups.flammable and (minetest.registered_nodes[n].groups.flammable
or random(1, 100) <= 30) then or random(1, 100) < 60) then
minetest.set_node(p, {name = "fire:basic_flame"}) -- Set fire (if node is present)
if minetest.registered_nodes[node_fire] then
minetest.set_node(p, {name = node_fire})
end
else else
minetest.set_node(p, {name = "air"}) minetest.set_node(p, {name = "air"})

View File

@ -1,5 +1,5 @@
MOB API (4th July 2017) MOB API (8th July 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest. The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -90,6 +90,8 @@ This functions registers a new mob as a Minetest entity.
'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations 'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations
'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops) 'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops)
'explosion_radius' radius of explosion attack (defaults to 1) 'explosion_radius' radius of explosion attack (defaults to 1)
'explosion_fire' if true, explosion will create lots of fire (default: true)
'explosion_smoke' if true, explosion creates smoke particles (default: true)
'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of a pre-defined arrow is required, see below for arrow definition. 'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of a pre-defined arrow is required, see below for arrow definition.
'shoot_interval' the minimum shoot interval 'shoot_interval' the minimum shoot interval
'shoot_offset' +/- value to position arrow/fireball when fired 'shoot_offset' +/- value to position arrow/fireball when fired

View File

@ -7,11 +7,13 @@ minetest.register_craftitem("mobs:nametag", {
inventory_image = "mobs_nametag.png", inventory_image = "mobs_nametag.png",
}) })
core.register_craft({ if minetest.get_modpath("dye") and minetest.get_modpath("farming") then
type = "shapeless", minetest.register_craft({
output = "mobs:nametag", type = "shapeless",
recipe = {"default:paper", "dye:black", "farming:string"}, output = "mobs:nametag",
}) recipe = {"default:paper", "dye:black", "farming:string"},
})
end
-- leather -- leather
minetest.register_craftitem("mobs:leather", { minetest.register_craftitem("mobs:leather", {
@ -46,14 +48,16 @@ minetest.register_tool("mobs:lasso", {
inventory_image = "mobs_magic_lasso.png", inventory_image = "mobs_magic_lasso.png",
}) })
minetest.register_craft({ if minetest.get_modpath("farming") then
output = "mobs:lasso", minetest.register_craft({
recipe = { output = "mobs:lasso",
{"farming:string", "", "farming:string"}, recipe = {
{"", "default:diamond", ""}, {"farming:string", "", "farming:string"},
{"farming:string", "", "farming:string"}, {"", "default:diamond", ""},
} {"farming:string", "", "farming:string"},
}) }
})
end
minetest.register_alias("mobs:magic_lasso", "mobs:lasso") minetest.register_alias("mobs:magic_lasso", "mobs:lasso")
@ -63,14 +67,16 @@ minetest.register_tool("mobs:net", {
inventory_image = "mobs_net.png", inventory_image = "mobs_net.png",
}) })
minetest.register_craft({ if minetest.get_modpath("farming") then
output = "mobs:net", minetest.register_craft({
recipe = { output = "mobs:net",
{"default:stick", "", "default:stick"}, recipe = {
{"default:stick", "", "default:stick"}, {"group:stick", "", "group:stick"},
{"farming:string", "default:stick", "farming:string"}, {"group:stick", "", "group:stick"},
} {"farming:string", "group:stick", "farming:string"},
}) }
})
end
-- shears (right click to shear animal) -- shears (right click to shear animal)
minetest.register_tool("mobs:shears", { minetest.register_tool("mobs:shears", {

View File

@ -1,4 +1,6 @@
default default
dye?
farming?
invisibility? invisibility?
intllib? intllib?
lucky_block? lucky_block?

View File

@ -12,7 +12,7 @@ local crash_threshold = 6.5 -- ignored if enable_crash=false
local node_ok = function(pos, fallback) local node_ok = function(pos, fallback)
fallback = fallback or "default:dirt" fallback = fallback or mobs.fallback_node
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node_or_nil(pos)