Thieving goblins!

master
FreeLikeGNU 2015-08-14 21:59:09 -07:00
parent 18062d09db
commit 748094d597
4 changed files with 186 additions and 34 deletions

View File

@ -8,6 +8,8 @@ based on MOBS-MOD by PilzAdam, KrupnovPavel, Zeg9, TenPlus1
https://forum.minetest.net/viewtopic.php?f=9&t=9917
This mod adds several Goblins to Minetest that should spawn near ore deposits underground.
v0.04 Thieving goblins!
v0.03 This is a test version that adds a goblin king! Thanks to Napiophelios! Some more texture refinement and fixed naming of textures.
v0.02 This is a test version and some the goblins will not attack unless attacked. Variety varies with ore...

167
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (4th August 2015) -- Modified by FreeLikeGNU for Goblins
-- Mobs Api (13th August 2015)
mobs_goblins = {}
mobs_goblins.mod = "redo"
@ -13,6 +13,7 @@ function mobs_goblins:register_mob(name, def)
minetest.register_entity(name, {
stepheight = def.stepheight or 0.6,
name = name,
description = def.description or name,
fly = def.fly,
fly_in = def.fly_in or "air",
owner = def.owner or "",
@ -49,7 +50,7 @@ function mobs_goblins:register_mob(name, def)
shoot_interval = def.shoot_interval,
sounds = def.sounds or {},
animation = def.animation,
follow = def.follow or "",
follow = def.follow, -- or "",
jump = def.jump or true,
walk_chance = def.walk_chance or 50,
attacks_monsters = def.attacks_monsters or false,
@ -198,7 +199,7 @@ function mobs_goblins:register_mob(name, def)
self.lifetimer = self.lifetimer - dtime
if self.lifetimer <= 0
and self.state ~= "attack" then
minetest.log("action","lifetimer expired, removed "..self.name)
minetest.log("action","lifetimer expired, removed "..self.description)
effect(self.object:getpos(), 15, "tnt_smoke.png")
self.object:remove()
return
@ -209,14 +210,23 @@ function mobs_goblins:register_mob(name, def)
if self.replace_rate
and self.child == false
and math.random(1,self.replace_rate) == 1 then
local pos = self.object:getpos()
pos.y = pos.y + self.replace_offset
-- print ("replace node = ".. minetest.get_node(pos).name, pos.y)
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)
local nodelist = minetest.find_nodes_in_area(pos1, pos2, self.replace_what)
if self.replace_what
and self.object:getvelocity().y == 0
and #minetest.find_nodes_in_area(pos, pos, self.replace_what) > 0 then
--and self.state == "stand" then
minetest.set_node(pos, {name = self.replace_with})
and #nodelist > 0 then
print (#nodelist.." nodes found by "..self.description.." !!!")
for key,value in pairs(nodelist) do print(minetest.get_node(value).name.. " stolen!!") end
for key,value in pairs(nodelist) do minetest.set_node(value, {name = self.replace_with}) end
end
end
@ -508,13 +518,26 @@ function mobs_goblins:register_mob(name, def)
for i,obj in ipairs(ents) do
ent = obj:get_luaentity()
-- quick fix for racist sheep
if ent
and string.find(ent.name, "mobs_goblins:sheep_") then
ent.name = "mobs_goblins:sheep"
-- check for same animal with different colour
local canmate = false
if ent then
if ent.name == self.name then
canmate = true
else
local entname = string.split(ent.name,":")
local selfname = string.split(self.name,":")
if entname[1] == selfname[1] then
entname = string.split(entname[2],"_")
selfname = string.split(selfname[2],"_")
if entname[1] == selfname[1] then
canmate = true
end
end
end
end
if ent
and ent.name == self.name
and canmate == true
and ent.horny == true
and ent.hornytimer <= 40 then
num = num + 1
@ -590,7 +613,8 @@ function mobs_goblins:register_mob(name, def)
-- stop following player if not holding specific item
if self.following
and self.following.is_player
and self.following:get_wielded_item():get_name() ~= self.follow then
--and self.following:get_wielded_item():get_name() ~= self.follow then
and follow_holding(self, self.following) == false then
self.following = nil
end
end
@ -778,7 +802,7 @@ end
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
yaw = math.atan(vec.z / vec.x) + math.pi / 2 - self.rotate
if p.x > s.x then
yaw = yaw+math.pi
yaw = yaw + math.pi
end
self.object:setyaw(yaw)
if self.attack.dist > 3 then
@ -1099,7 +1123,7 @@ end
-- remove mob when out of range unless tamed
if mobs_goblins.remove == true and self.remove_ok and not self.tamed then
print ("REMOVED", self.remove_ok, self.name)
print ("REMOVED", self.remove_ok, self.description)
self.object:remove()
end
self.remove_ok = true
@ -1247,14 +1271,14 @@ function mobs_goblins:spawn_specific(name, nodes, neighbors, min_light, max_ligh
end
if minetest.setting_getbool("display_mob_spawn") then
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
minetest.chat_send_all("[mobs_goblins] Spawned "..name.." at "..minetest.pos_to_string(pos))
end
-- spawn mob half block higher
pos.y = pos.y - 0.5
minetest.add_entity(pos, name)
--print ("Spawned "..name.." at "..minetest.pos_to_string(pos).." on "..node.name.." near "..neighbors[1])
minetest.log("action", "Spawned " .. name .. " at " .. minetest.pos_to_string(pos) .. ".")
print ("Spawned "..description.." at "..minetest.pos_to_string(pos).." on "..node.name.." near "..neighbors[1])
end
})
end
@ -1285,7 +1309,7 @@ end
-- explosion
function mobs_goblins:explosion(pos, radius, fire, smoke, sound)
-- node hit, bursts into flame (cannot blast through obsidian or protection redo mod items)
-- node hit, bursts into flame (cannot blast through unbreakable/specific nodes)
if not fire then fire = 0 end
if not smoke then smoke = 0 end
local pos = vector.round(pos)
@ -1566,3 +1590,102 @@ function mobs_goblins:capture_mob(self, clicker, chance_hand, chance_net, chance
end
end
end
-- follow what I'm holding ?
function follow_holding(self, clicker)
local item = clicker:get_wielded_item()
local follow_item = false
local t = type(self.follow)
-- single item
if t == "string"
and item:get_name() == self.follow then
follow_item = true
-- multiple items
elseif t == "table" then
for no = 1, #self.follow do
if self.follow[no] == item:get_name() then
follow_item = true
end
end
end
-- true if can eat/tame with item
if follow_item == true then
return true
end
return false
end
-- feeding, taming and breeding (thanks blert2112)
function mobs_goblins:feed_tame(self, clicker, feed_count, breed)
if not self.follow then return false end
local item = clicker:get_wielded_item()
local follow_item = false
local t = type(self.follow)
-- single item
if t == "string"
and item:get_name() == self.follow then
follow_item = true
-- multiple items
elseif t == "table" then
for no = 1, #self.follow do
if self.follow[no] == item:get_name() then
follow_item = true
end
end
end
-- can eat/tame with item in hand
if follow_holding(self, clicker) then
--print ("mmm, tasty")
-- take item
if not minetest.setting_getbool("creative_mode") then
item:take_item()
clicker:set_wielded_item(item)
end
-- heal health
local hp = self.object:get_hp()
hp = math.min(hp + 4, self.hp_max)
self.object:set_hp(hp)
self.health = hp
-- make children grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 20
return true
end
-- feed and tame
self.food = (self.food or 0) + 1
if self.food == feed_count then
self.food = 0
if breed and self.hornytimer == 0 then
self.horny = true
end
self.gotten = false
self.tamed = true
if not self.owner or self.owner == "" then
self.owner = clicker:get_player_name()
end
-- make sound when fed so many times
if self.sounds.random then
minetest.sound_play(self.sounds.random, {
object = self.object,
max_hear_distance = self.sounds.distance
})
end
end
return true
else
return false
end
end

View File

@ -7,7 +7,8 @@ mobs_goblins.goblin_drops = {
}
mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
type = "npc",
description = "Coal Goblin",
type = "animal",
passive = false,
damage = 1,
attack_type = "dogfight",
@ -36,13 +37,17 @@ mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
chance = 1, min = 1, max = 3},
{name = "default:apple",
chance = 2, min = 1, max = 2},
{name = "default:axe_stone",
chance = 5, min = 1, max = 1},
{name = "default:torch",
chance = 3, min = 1, max = 10},
},
water_damage = 0,
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
follow = {"default:diamond"},
replace_rate = 50,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
view_range = 15,
owner = "",
order = "follow",
@ -109,6 +114,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
})
mobs_goblins:register_mob("mobs_goblins:goblin_iron", {
description = "Iron Goblin",
type = "animal",
passive = false,
damage = 2,
@ -145,6 +151,10 @@ mobs_goblins:register_mob("mobs_goblins:goblin_iron", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 50,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
view_range = 15,
owner = "",
order = "follow",
@ -211,6 +221,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_iron", {
})
mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
description = "Gold Goblin",
type = "monster",
passive = false,
damage = 3,
@ -247,6 +258,10 @@ mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 50,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
view_range = 15,
owner = "",
order = "follow",
@ -313,6 +328,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_gold", {
})
mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
description = "Diamond Goblin",
type = "animal",
passive = false,
damage = 3,
@ -349,6 +365,10 @@ mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 50,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = 2,
view_range = 15,
owner = "",
order = "follow",
@ -415,6 +435,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_diamond", {
})
mobs_goblins:register_mob("mobs_goblins:goblin_king", {
description = "Goblin King",
type = "monster",
passive = false,
damage = 4,
@ -450,6 +471,10 @@ mobs_goblins:register_mob("mobs_goblins:goblin_king", {
lava_damage = 2,
light_damage = 0,
follow = "default:diamond",
replace_rate = 50,
replace_what = {"default:torch",},
replace_with = "air",
replace_offset = -1,
view_range = 15,
owner = "",
order = "follow",
@ -515,10 +540,12 @@ mobs_goblins:register_mob("mobs_goblins:goblin_king", {
end,
})
-- spawn like stone monster, but for ores
mobs_goblins:register_spawn("mobs_goblins:goblin_coal", {"default:stone_with_coal" }, 20, 0, 100, 2, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_iron", {"default:stone_with_iron"}, 20, 0, 100, 2, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_gold", {"default:stone_with_gold" }, 20, 0, 100, 2, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_diamond", {"default:stone_with_diamond" }, 20, 0, 100, 2, 1)
mobs_goblins:register_spawn("mobs_goblins:goblin_king", {"default:stone_with_mese" }, 20, 0, 100, 2, 1)
-- spawn underground near ore and dungeons
--function mobs_goblins:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height)
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_egg("mobs_goblins:goblin_coal", "goblin egg", "default:stone_with_coal", 1)

View File

@ -8,6 +8,6 @@ dofile(path.."/api.lua")
dofile(path.."/goblins.lua") -- TenPlus1 and FreeLikeGNU
if minetest.setting_get("log_mods") then
--if minetest.setting_get("log_mods") then
minetest.log("action", "GOBLINS is lowdids!")
end
--end