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.mod = "redo"
|
||||
|
||||
@ -49,7 +49,7 @@ function mobs: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,
|
||||
@ -603,7 +603,8 @@ function mobs: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
|
||||
@ -791,7 +792,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
|
||||
@ -1298,7 +1299,7 @@ end
|
||||
|
||||
-- explosion
|
||||
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 smoke then smoke = 0 end
|
||||
local pos = vector.round(pos)
|
||||
@ -1580,11 +1581,60 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
|
||||
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: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
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
item:take_item()
|
||||
|
@ -37,8 +37,8 @@ mobs:register_mob("mobs:bunny", {
|
||||
punch_start = 16,
|
||||
punch_end = 24,
|
||||
},
|
||||
follow = "farming:carrot",
|
||||
view_range = 5,
|
||||
follow = {"farming:carrot", "farming_plus:carrot_item"},
|
||||
view_range = 10,
|
||||
replace_rate = 80,
|
||||
replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"},
|
||||
replace_with = "air",
|
||||
|
@ -43,7 +43,7 @@ mobs:register_mob("mobs:chicken", {
|
||||
walk_start = 20,
|
||||
walk_end = 40,
|
||||
},
|
||||
follow = "farming:seed_wheat",
|
||||
follow = {"farming:seed_wheat", "farming:seed_cotton"},
|
||||
view_range = 5,
|
||||
replace_rate = 8000,
|
||||
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_end = 96,
|
||||
},
|
||||
follow = "mobs:rat",
|
||||
view_range = 8,
|
||||
follow = {"mobs:rat", "ethereal:fish_raw"},
|
||||
view_range = 10,
|
||||
on_rightclick = function(self, clicker)
|
||||
mobs:feed_tame(self, clicker, 4, true)
|
||||
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_npc2.png"}, -- female by nuttmeg20
|
||||
},
|
||||
child_texture = {
|
||||
{"mobs_npc_baby.png"}, -- derpy baby by AmirDerAssassine
|
||||
},
|
||||
makes_footstep_sound = true,
|
||||
sounds = {},
|
||||
walk_velocity = 2,
|
||||
@ -39,7 +42,7 @@ mobs:register_mob("mobs:npc", {
|
||||
water_damage = 0,
|
||||
lava_damage = 2,
|
||||
light_damage = 0,
|
||||
follow = "default:diamond",
|
||||
follow = {"farming:bread", "mobs:meat", "default:diamond"},
|
||||
view_range = 15,
|
||||
owner = "",
|
||||
order = "follow",
|
||||
@ -56,48 +59,33 @@ mobs:register_mob("mobs:npc", {
|
||||
punch_end = 219,
|
||||
},
|
||||
on_rightclick = function(self, clicker)
|
||||
local item = clicker:get_wielded_item()
|
||||
local name = clicker:get_player_name()
|
||||
|
||||
-- feed to heal npc
|
||||
if item:get_name() == "mobs:meat"
|
||||
or item:get_name() == "farming:bread" then
|
||||
if not mobs:feed_tame(self, clicker, 8, true) then
|
||||
local item = clicker:get_wielded_item()
|
||||
local name = clicker:get_player_name()
|
||||
|
||||
local hp = self.object:get_hp()
|
||||
-- return if full health
|
||||
if hp >= self.hp_max then
|
||||
minetest.chat_send_player(name, "NPC at full health.")
|
||||
return
|
||||
end
|
||||
hp = hp + 4
|
||||
if hp > self.hp_max then hp = self.hp_max end
|
||||
self.object:set_hp(hp)
|
||||
-- take item
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
item:take_item()
|
||||
clicker:set_wielded_item(item)
|
||||
end
|
||||
|
||||
-- right clicking with gold lump drops random item from mobs.npc_drops
|
||||
elseif item:get_name() == "default:gold_lump" then
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
item:take_item()
|
||||
clicker:set_wielded_item(item)
|
||||
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"
|
||||
-- right clicking with gold lump drops random item from mobs.npc_drops
|
||||
if item:get_name() == "default:gold_lump" then
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
item:take_item()
|
||||
clicker:set_wielded_item(item)
|
||||
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
|
||||
|
||||
|
@ -45,7 +45,7 @@ for _, col in ipairs(all_colours) do
|
||||
walk_start = 81,
|
||||
walk_end = 100,
|
||||
},
|
||||
follow = "farming:wheat",
|
||||
follow = {"farming:wheat", "default:grass_5"},
|
||||
view_range = 5,
|
||||
replace_rate = 50,
|
||||
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,
|
||||
run_velocity = 3,
|
||||
jump = true,
|
||||
follow = "default:apple",
|
||||
follow = {"default:apple", "farming:potato"},
|
||||
view_range = 10,
|
||||
drops = {
|
||||
{name = "mobs:pork_raw",
|
||||
|
Loading…
x
Reference in New Issue
Block a user