code tweaks and new settings

main
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.mod = "redo"
mobs.version = "20170707"
mobs.version = "20170708"
-- 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_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
local mob_sound = function(self, sound)
@ -242,9 +249,10 @@ end
local flight_check = function(self, pos_w)
local nod = self.standing_in
local def = minetest.registered_nodes[nod]
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
@ -252,7 +260,7 @@ local flight_check = function(self, pos_w)
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
end
@ -507,7 +515,7 @@ end
-- get node but use fallback for nil or unknown
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)
@ -598,8 +606,8 @@ local do_env_damage = function(self)
-- lava or fire
elseif self.lava_damage
and (nodef.groups.lava
or self.standing_in == "fire:basic_flame"
or self.standing_in == "fire:permanent_flame") then
or self.standing_in == node_fire
or self.standing_in == node_permanent_flame) 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
if nod.name == "default:snow" then
if nod.name == node_snow then
return false
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
minetest.set_node(s, {name = "default:dirt"})
minetest.set_node(s, {name = mobs.fallback_node})
end
end
@ -1511,7 +1519,7 @@ local do_states = function(self, dtime)
and minetest.registered_nodes[self.standing_in].groups.water) then
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?
if lp then
@ -1675,6 +1683,8 @@ local do_states = function(self, dtime)
local pos = self.object:getpos()
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
if minetest.find_node_near(pos, 1, {"group:water"})
@ -1695,7 +1705,7 @@ local do_states = function(self, dtime)
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()
@ -2622,6 +2632,8 @@ minetest.register_entity(name, {
pathfinding = def.pathfinding,
immune_to = def.immune_to or {},
explosion_radius = def.explosion_radius,
explosion_fire = def.explosion_fire,
explosion_smoke = def.explosion_smoke,
custom_attack = def.custom_attack,
double_melee_attack = def.double_melee_attack,
dogshoot_switch = def.dogshoot_switch,
@ -2920,7 +2932,7 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
if on_blast then
return on_blast(p)
on_blast(p)
elseif minetest.registered_nodes[n].groups.unbreakable == 1 then
@ -2930,9 +2942,12 @@ function mobs:explosion(pos, radius, fire, smoke, sound)
-- after effects
if fire > 0
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
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.
@ -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
'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_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.
'shoot_interval' the minimum shoot interval
'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",
})
core.register_craft({
type = "shapeless",
output = "mobs:nametag",
recipe = {"default:paper", "dye:black", "farming:string"},
})
if minetest.get_modpath("dye") and minetest.get_modpath("farming") then
minetest.register_craft({
type = "shapeless",
output = "mobs:nametag",
recipe = {"default:paper", "dye:black", "farming:string"},
})
end
-- leather
minetest.register_craftitem("mobs:leather", {
@ -46,14 +48,16 @@ minetest.register_tool("mobs:lasso", {
inventory_image = "mobs_magic_lasso.png",
})
minetest.register_craft({
output = "mobs:lasso",
recipe = {
{"farming:string", "", "farming:string"},
{"", "default:diamond", ""},
{"farming:string", "", "farming:string"},
}
})
if minetest.get_modpath("farming") then
minetest.register_craft({
output = "mobs:lasso",
recipe = {
{"farming:string", "", "farming:string"},
{"", "default:diamond", ""},
{"farming:string", "", "farming:string"},
}
})
end
minetest.register_alias("mobs:magic_lasso", "mobs:lasso")
@ -63,14 +67,16 @@ minetest.register_tool("mobs:net", {
inventory_image = "mobs_net.png",
})
minetest.register_craft({
output = "mobs:net",
recipe = {
{"default:stick", "", "default:stick"},
{"default:stick", "", "default:stick"},
{"farming:string", "default:stick", "farming:string"},
}
})
if minetest.get_modpath("farming") then
minetest.register_craft({
output = "mobs:net",
recipe = {
{"group:stick", "", "group:stick"},
{"group:stick", "", "group:stick"},
{"farming:string", "group:stick", "farming:string"},
}
})
end
-- shears (right click to shear animal)
minetest.register_tool("mobs:shears", {

View File

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

View File

@ -12,7 +12,7 @@ local crash_threshold = 6.5 -- ignored if enable_crash=false
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)