added ability for mobs to follow multiple items, npc's can breed also
This commit is contained in:
parent
4615b35a82
commit
0a748dfbd4
64
api.lua
64
api.lua
@ -1,4 +1,4 @@
|
|||||||
-- Mobs Api (9th August 2015)
|
-- Mobs Api (13th August 2015)
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ function mobs:register_mob(name, def)
|
|||||||
shoot_interval = def.shoot_interval,
|
shoot_interval = def.shoot_interval,
|
||||||
sounds = def.sounds or {},
|
sounds = def.sounds or {},
|
||||||
animation = def.animation,
|
animation = def.animation,
|
||||||
follow = def.follow or "",
|
follow = def.follow, -- or "",
|
||||||
jump = def.jump or true,
|
jump = def.jump or true,
|
||||||
walk_chance = def.walk_chance or 50,
|
walk_chance = def.walk_chance or 50,
|
||||||
attacks_monsters = def.attacks_monsters or false,
|
attacks_monsters = def.attacks_monsters or false,
|
||||||
@ -603,7 +603,8 @@ function mobs:register_mob(name, def)
|
|||||||
-- stop following player if not holding specific item
|
-- stop following player if not holding specific item
|
||||||
if self.following
|
if self.following
|
||||||
and self.following.is_player
|
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
|
self.following = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -791,7 +792,7 @@ end
|
|||||||
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
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
|
yaw = math.atan(vec.z / vec.x) + math.pi / 2 - self.rotate
|
||||||
if p.x > s.x then
|
if p.x > s.x then
|
||||||
yaw = yaw+math.pi
|
yaw = yaw + math.pi
|
||||||
end
|
end
|
||||||
self.object:setyaw(yaw)
|
self.object:setyaw(yaw)
|
||||||
if self.attack.dist > 3 then
|
if self.attack.dist > 3 then
|
||||||
@ -1298,7 +1299,7 @@ end
|
|||||||
|
|
||||||
-- explosion
|
-- explosion
|
||||||
function mobs:explosion(pos, radius, fire, smoke, sound)
|
function mobs: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 fire then fire = 0 end
|
||||||
if not smoke then smoke = 0 end
|
if not smoke then smoke = 0 end
|
||||||
local pos = vector.round(pos)
|
local pos = vector.round(pos)
|
||||||
@ -1580,11 +1581,60 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
|
|||||||
end
|
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)
|
-- feeding, taming and breeding (thanks blert2112)
|
||||||
function mobs:feed_tame(self, clicker, feed_count, breed)
|
function mobs:feed_tame(self, clicker, feed_count, breed)
|
||||||
local item = clicker:get_wielded_item()
|
|
||||||
if item:get_name() == self.follow then
|
|
||||||
|
|
||||||
|
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
|
-- take item
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
item:take_item()
|
item:take_item()
|
||||||
|
@ -37,8 +37,8 @@ mobs:register_mob("mobs:bunny", {
|
|||||||
punch_start = 16,
|
punch_start = 16,
|
||||||
punch_end = 24,
|
punch_end = 24,
|
||||||
},
|
},
|
||||||
follow = "farming:carrot",
|
follow = {"farming:carrot", "farming_plus:carrot_item"},
|
||||||
view_range = 5,
|
view_range = 10,
|
||||||
replace_rate = 80,
|
replace_rate = 80,
|
||||||
replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"},
|
replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"},
|
||||||
replace_with = "air",
|
replace_with = "air",
|
||||||
|
@ -43,7 +43,7 @@ mobs:register_mob("mobs:chicken", {
|
|||||||
walk_start = 20,
|
walk_start = 20,
|
||||||
walk_end = 40,
|
walk_end = 40,
|
||||||
},
|
},
|
||||||
follow = "farming:seed_wheat",
|
follow = {"farming:seed_wheat", "farming:seed_cotton"},
|
||||||
view_range = 5,
|
view_range = 5,
|
||||||
replace_rate = 8000,
|
replace_rate = 8000,
|
||||||
replace_what = {"air"},
|
replace_what = {"air"},
|
||||||
|
4
kitten.lua
Executable file → Normal file
4
kitten.lua
Executable file → Normal file
@ -36,8 +36,8 @@ mobs:register_mob("mobs:kitten", {
|
|||||||
walk_start = 0,
|
walk_start = 0,
|
||||||
walk_end = 96,
|
walk_end = 96,
|
||||||
},
|
},
|
||||||
follow = "mobs:rat",
|
follow = {"mobs:rat", "ethereal:fish_raw"},
|
||||||
view_range = 8,
|
view_range = 10,
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
mobs:feed_tame(self, clicker, 4, true)
|
mobs:feed_tame(self, clicker, 4, true)
|
||||||
mobs:capture_mob(self, clicker, 50, 50, 90, false, nil)
|
mobs:capture_mob(self, clicker, 50, 50, 90, false, nil)
|
||||||
|
66
npc.lua
66
npc.lua
@ -23,6 +23,9 @@ mobs:register_mob("mobs:npc", {
|
|||||||
{"mobs_npc.png"},
|
{"mobs_npc.png"},
|
||||||
{"mobs_npc2.png"}, -- female by nuttmeg20
|
{"mobs_npc2.png"}, -- female by nuttmeg20
|
||||||
},
|
},
|
||||||
|
child_texture = {
|
||||||
|
{"mobs_npc_baby.png"}, -- derpy baby by AmirDerAssassine
|
||||||
|
},
|
||||||
makes_footstep_sound = true,
|
makes_footstep_sound = true,
|
||||||
sounds = {},
|
sounds = {},
|
||||||
walk_velocity = 2,
|
walk_velocity = 2,
|
||||||
@ -39,7 +42,7 @@ mobs:register_mob("mobs:npc", {
|
|||||||
water_damage = 0,
|
water_damage = 0,
|
||||||
lava_damage = 2,
|
lava_damage = 2,
|
||||||
light_damage = 0,
|
light_damage = 0,
|
||||||
follow = "default:diamond",
|
follow = {"farming:bread", "mobs:meat", "default:diamond"},
|
||||||
view_range = 15,
|
view_range = 15,
|
||||||
owner = "",
|
owner = "",
|
||||||
order = "follow",
|
order = "follow",
|
||||||
@ -56,48 +59,33 @@ mobs:register_mob("mobs:npc", {
|
|||||||
punch_end = 219,
|
punch_end = 219,
|
||||||
},
|
},
|
||||||
on_rightclick = function(self, clicker)
|
on_rightclick = function(self, clicker)
|
||||||
local item = clicker:get_wielded_item()
|
|
||||||
local name = clicker:get_player_name()
|
|
||||||
|
|
||||||
-- feed to heal npc
|
-- feed to heal npc
|
||||||
if item:get_name() == "mobs:meat"
|
if not mobs:feed_tame(self, clicker, 8, true) then
|
||||||
or item:get_name() == "farming:bread" then
|
local item = clicker:get_wielded_item()
|
||||||
|
local name = clicker:get_player_name()
|
||||||
|
|
||||||
local hp = self.object:get_hp()
|
-- right clicking with gold lump drops random item from mobs.npc_drops
|
||||||
-- return if full health
|
if item:get_name() == "default:gold_lump" then
|
||||||
if hp >= self.hp_max then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
minetest.chat_send_player(name, "NPC at full health.")
|
item:take_item()
|
||||||
return
|
clicker:set_wielded_item(item)
|
||||||
end
|
end
|
||||||
hp = hp + 4
|
local pos = self.object:getpos()
|
||||||
if hp > self.hp_max then hp = self.hp_max end
|
pos.y = pos.y + 0.5
|
||||||
self.object:set_hp(hp)
|
minetest.add_item(pos, {
|
||||||
-- take item
|
name = mobs.npc_drops[math.random(1, #mobs.npc_drops)]
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
})
|
||||||
item:take_item()
|
|
||||||
clicker:set_wielded_item(item)
|
else
|
||||||
end
|
-- if owner switch between follow and stand
|
||||||
|
if self.owner and self.owner == clicker:get_player_name() then
|
||||||
-- right clicking with gold lump drops random item from mobs.npc_drops
|
if self.order == "follow" then
|
||||||
elseif item:get_name() == "default:gold_lump" then
|
self.order = "stand"
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
else
|
||||||
item:take_item()
|
self.order = "follow"
|
||||||
clicker:set_wielded_item(item)
|
end
|
||||||
end
|
|
||||||
local pos = self.object:getpos()
|
|
||||||
pos.y = pos.y + 0.5
|
|
||||||
minetest.add_item(pos, {name = mobs.npc_drops[math.random(1, #mobs.npc_drops)]})
|
|
||||||
|
|
||||||
else
|
|
||||||
-- if owner switch between follow and stand
|
|
||||||
if self.owner and self.owner == clicker:get_player_name() then
|
|
||||||
if self.order == "follow" then
|
|
||||||
self.order = "stand"
|
|
||||||
else
|
|
||||||
self.order = "follow"
|
|
||||||
end
|
end
|
||||||
-- else
|
|
||||||
-- self.owner = clicker:get_player_name()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ for _, col in ipairs(all_colours) do
|
|||||||
walk_start = 81,
|
walk_start = 81,
|
||||||
walk_end = 100,
|
walk_end = 100,
|
||||||
},
|
},
|
||||||
follow = "farming:wheat",
|
follow = {"farming:wheat", "default:grass_5"},
|
||||||
view_range = 5,
|
view_range = 5,
|
||||||
replace_rate = 50,
|
replace_rate = 50,
|
||||||
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
|
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
|
||||||
|
BIN
textures/mobs_npc_baby.png
Normal file
BIN
textures/mobs_npc_baby.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 684 B |
@ -23,7 +23,7 @@ mobs:register_mob("mobs:pumba", {
|
|||||||
walk_velocity = 2,
|
walk_velocity = 2,
|
||||||
run_velocity = 3,
|
run_velocity = 3,
|
||||||
jump = true,
|
jump = true,
|
||||||
follow = "default:apple",
|
follow = {"default:apple", "farming:potato"},
|
||||||
view_range = 10,
|
view_range = 10,
|
||||||
drops = {
|
drops = {
|
||||||
{name = "mobs:pork_raw",
|
{name = "mobs:pork_raw",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user