Better search and replace functions!

master
FreeLikeGNU 2015-09-04 14:35:15 -07:00
parent 30ac84c841
commit 00edb3cdc7
2 changed files with 130 additions and 58 deletions

51
api.lua
View File

@ -11,6 +11,7 @@ mobs_goblins.remove = minetest.setting_getbool("remove_far_mobs") or false
function mobs_goblins:register_mob(name, def)
minetest.register_entity(name, {
debugging_goblins = def.debugging_goblins or true,
stepheight = def.stepheight or 0.6,
name = name,
description = def.description or name,
@ -63,10 +64,19 @@ function mobs_goblins:register_mob(name, def)
blood_texture = def.blood_texture or "goblins_blood.png",
shoot_offset = def.shoot_offset or 0,
floats = def.floats or 1, -- floats in water by default
replace_rate = def.replace_rate,
search_rate = def.search_rate, --how often to we search for nodes?
-- how often do we lookfor nodes above or below? (relative to nodes around us, will be same if undefined)
search_rate_above = def.search_rate_above or 1,
search_rate_below = def.search_rate_below or 1,
-- how far away can we look for nodes?
search_offset = def.search_offset or 0,
search_offset_above = def.search_offset_above or 0,
search_offset_below = def.search_offset_below or 0,
replace_rate = def.replace_rate, -- how often do we replace nodes we find?
-- what nodes will be replaced?
replace_what = def.replace_what,
replace_with = def.replace_with,
replace_offset = def.replace_offset or 0,
timer = 0,
env_damage_timer = 0, -- only if state = "attack"
attack = {player=nil, dist=nil},
@ -209,26 +219,39 @@ function mobs_goblins:register_mob(name, def)
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
if self.replace_rate
and self.child == false
and math.random(1,self.replace_rate) == 1 then
and math.random(1,self.search_rate) == 1 then
--look for nodes
local pos1 = self.object:getpos()
local pos2 = self.object:getpos()
pos1.y = pos1.y - self.replace_offset
pos1.x = pos1.x - self.replace_offset
pos1.z = pos1.z - self.replace_offset
pos2.y = pos2.y + self.replace_offset
pos2.x = pos2.x + self.replace_offset
pos2.z = pos2.z + self.replace_offset
--print (self.name)
--print ("is searching between" .. pos1.x, pos1.y, pos1.z)
--print ("and " .. pos2.x, pos2.y, pos2.z)
-- if we are looking, will we look below and by how much?
if math.random(1,self.search_rate_below) == 1 then
pos1.y = pos1.y - self.search_offset_below
end
-- if we are looking, will we look above and by how much?
if math.random(1,self.search_rate_above) == 1 then
pos2.y = pos2.y + self.search_offset_above
end
pos1.x = pos1.x - self.search_offset
pos1.z = pos1.z - self.search_offset
pos2.x = pos2.x + self.search_offset
pos2.z = pos2.z + self.search_offset
if self.debugging_goblins == true then
print (self.name)
print ("at " .. self.object:getpos().x, self.object:getpos().y, self.object:getpos().z)
print ("is searching between" .. pos1.x, pos1.y, pos1.z)
print ("and " .. pos2.x, pos2.y, pos2.z)
end
local nodelist = minetest.find_nodes_in_area(pos1, pos2, self.replace_what)
if self.replace_what
and #nodelist > 0 then
print (#nodelist.." nodes found by "..self.description.." !!!")
--print (#nodelist.." nodes found by "..self.description.." !!!")
--for k,v in pairs(nodelist) do print(minetest.get_node(v).name.. " found!!") end
for key,value in pairs(nodelist) do
-- ok we see some nodes around us, are we going to replace them?
if math.random(1,self.replace_rate) == 1 then
print(self.replace_with.." placed")
if self.debugging_goblins == true then
print(self.replace_with.." placed")
end
minetest.set_node(value, {name = self.replace_with})
end
end

View File

@ -15,7 +15,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_cobble", {
hp_min = 5,
hp_max = 10,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -49,10 +49,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_cobble", {
light_damage = 0,
lifetimer = 360,
follow = {"default:diamond"},
replace_rate = 20,
replace_what = {"default:stone","default:desert_stone",},
replace_with = "default:mossycobble",
replace_offset = 1,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:stone","default:desert_stone","default:torch"},
replace_with = "default:mossycobble",
view_range = 15,
owner = "",
order = "follow",
@ -128,7 +135,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_digger", {
hp_min = 5,
hp_max = 10,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -160,10 +167,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_digger", {
light_damage = 0,
lifetimer = 360,
follow = {"default:diamond"},
replace_rate = 20,
replace_what = {"default:stone","default:desert_stone","default:torch"},
replace_with = "air",
replace_offset = 1,
-- updated node searching!
search_rate = 10,
search_rate_above = 10,
search_rate_below = 20,
search_offset = 1,
search_offset_below = 1,
search_offset_above = 1,
replace_rate = 4,
replace_what = {"default:dirt","default:gravel","default:stone","default:desert_stone","default:torch"},
replace_with = "air",
view_range = 15,
owner = "",
order = "follow",
@ -240,7 +254,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
hp_min = 5,
hp_max = 10,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -272,10 +286,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
lava_damage = 2,
light_damage = 0,
follow = {"default:diamond"},
replace_rate = 30,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:torch"},
replace_with = "default:air",
view_range = 15,
owner = "",
order = "follow",
@ -351,7 +372,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_iron", {
hp_min = 10,
hp_max = 20,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -383,10 +404,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_iron", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 40,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:torch"},
replace_with = "default:air",
view_range = 15,
owner = "",
order = "follow",
@ -462,7 +490,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
hp_min = 10,
hp_max = 30,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -494,10 +522,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 40,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 3,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:torch"},
replace_with = "default:air",
view_range = 15,
owner = "",
order = "follow",
@ -565,7 +600,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
})
mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
description = "Diamond Goblin",
type = "animal",
type = "monster",
passive = false,
damage = 3,
attack_type = "dogfight",
@ -573,7 +608,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
hp_min = 20,
hp_max = 30,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -605,10 +640,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 40,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 3,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:torch"},
replace_with = "default:air",
view_range = 15,
owner = "",
order = "follow",
@ -684,7 +726,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_king", {
hp_min = 20,
hp_max = 40,
armor = 100,
collisionbox = {-0.35,-1.0,-0.35, 0.35,0.0,0.35},
collisionbox = {-0.35,-1,-0.35, 0.35,-.1,0.35},
visual = "mesh",
mesh = "goblins_goblin.b3d",
drawtype = "front",
@ -715,10 +757,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_king", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 40,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 3,
-- updated node searching!
search_rate = 10,
search_rate_above = 1,
search_rate_below = 1,
search_offset = 2,
search_offset_below = 2,
search_offset_above = 2,
replace_rate = 5,
replace_what = {"default:torch"},
replace_with = "default:air",
view_range = 15,
owner = "",
order = "follow",
@ -784,13 +833,13 @@ mobs_goblins:register_mob("mobs_goblins:goblin_king", {
end,
})
-- spawn underground near ore and dungeons, except cobble goblins who create goblin lairs near stone.
-- spawn at or below 0 near ore and dungeons and goblin lairs (areas of mossy cobble), except diggers that will dig out caves from stone and cobble goblins who create goblin lairs near stone.
--function mobs_goblins:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height)
mobs_goblins:register_spawn("mobs_goblins:goblin_cobble", {"group:stone"}, 1000, 0, 50, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_digger", {"group:stone"}, 1000, 0, 50, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_coal", {"default:torch", "default:coal", "default:mossycobble"}, 1000, 0, 30, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_iron", {"default:stone_with_iron","default:mossycobble",}, 10, 0, 30, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_gold", {"default:stone_with_gold","default:mossycobble", }, 10, 0, 30, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_diamond", {"default:stone_with_diamond","default:mossycobble", }, 30, 0, 100, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_king", {"default:stone_with_mese","default:mossycobble", }, 10, 0, 300, 1, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_cobble", {"group:stone"}, 100, 0, 50, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_digger", {"group:stone"}, 100, 0, 50, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_coal", {"default:torch", "default:coal", "default:mossycobble"}, 30, 0, 5, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_iron", {"default:stone_with_iron","default:mossycobble",}, 30, 0, 5, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_gold", {"default:stone_with_gold","default:mossycobble", }, 30, 0, 5, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_diamond", {"default:stone_with_diamond","default:mossycobble", }, 5, 0, 100, 1, 0)
mobs_goblins:register_spawn("mobs_goblins:goblin_king", {"default:stone_with_mese","default:mossycobble", }, 30, 0, 5, 2, 0)
mobs_goblins:register_egg("mobs_goblins:goblin_cobble", "goblin egg", "default:mossycobble", 1)