diff --git a/api.lua b/api.lua index 8316021..b63689e 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,4 @@ --- Mobs Api (5th January 2016) +-- Mobs Api (6th January 2016) mobs = {} mobs.mod = "redo" @@ -2223,25 +2223,24 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) clicker:set_wielded_item(item) end - -- heal health - local hp = self.object:get_hp() + 4 + -- increase health + self.health = self.health + 4 - if hp >= self.hp_max then + if self.health >= self.hp_max then - hp = self.hp_max + self.health = self.hp_max if self.htimer < 1 then minetest.chat_send_player(clicker:get_player_name(), self.name:split(":")[2] - .. " at full health (" .. tostring(hp) .. ")") + .. " at full health (" .. tostring(self.health) .. ")") self.htimer = 5 end end - self.object:set_hp(hp) - self.health = hp + self.object:set_hp(self.health) update_tag(self) @@ -2255,7 +2254,7 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) -- feed and tame self.food = (self.food or 0) + 1 - if self.food == feed_count then + if self.food >= feed_count then self.food = 0 @@ -2267,6 +2266,12 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) if tame then + if self.tamed == false then + minetest.chat_send_player(clicker:get_player_name(), + self.name:split(":")[2] + .. " has been tamed!") + end + self.tamed = true if not self.owner or self.owner == "" then diff --git a/bee.lua b/bee.lua index 68c29c1..fd0d8bc 100644 --- a/bee.lua +++ b/bee.lua @@ -103,4 +103,4 @@ minetest.register_craft({ recipe = { {"mobs:honey_block"}, } -}) \ No newline at end of file +}) diff --git a/bunny.lua b/bunny.lua index 1e89c87..cf5c1fa 100644 --- a/bunny.lua +++ b/bunny.lua @@ -45,29 +45,39 @@ mobs:register_mob("mobs:bunny", { replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"}, replace_with = "air", on_rightclick = function(self, clicker) - if not mobs:feed_tame(self, clicker, 4, true, true) then - -- Monty Python tribute - local item = clicker:get_wielded_item() - if item:get_name() == "mobs:lava_orb" then - if not minetest.setting_getbool("creative_mode") then - item:take_item() - clicker:set_wielded_item(item) - end - self.object:set_properties({ - textures = {"mobs_bunny_evil.png"}, - }) - self.type = "monster" - self.object:set_hp(20) - return + + -- feed or tame + if mobs:feed_tame(self, clicker, 4, true, true) then + return + end + + -- Monty Python tribute + local item = clicker:get_wielded_item() + + if item:get_name() == "mobs:lava_orb" then + + if not minetest.setting_getbool("creative_mode") then + item:take_item() + clicker:set_wielded_item(item) end + + self.object:set_properties({ + textures = {"mobs_bunny_evil.png"}, + }) + + self.type = "monster" + self.object:set_hp(20) + + return end mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) end, + attack_type = "dogfight", damage = 5, }) mobs:register_spawn("mobs:bunny", {"default:dirt_with_grass", "ethereal:prairie_dirt"}, 20, 10, 15000, 2, 31000) -mobs:register_egg("mobs:bunny", "Bunny", "mobs_bunny_inv.png", 0) \ No newline at end of file +mobs:register_egg("mobs:bunny", "Bunny", "mobs_bunny_inv.png", 0) diff --git a/chicken.lua b/chicken.lua index c1efdd6..016397d 100644 --- a/chicken.lua +++ b/chicken.lua @@ -48,7 +48,9 @@ mobs:register_mob("mobs:chicken", { view_range = 5, on_rightclick = function(self, clicker) - mobs:feed_tame(self, clicker, 8, true, true) + if mobs:feed_tame(self, clicker, 8, true, true) then + return + end mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) end, @@ -127,12 +129,12 @@ mobs:register_arrow("mobs:egg_entity", { end }) --- snowball throwing item +-- egg throwing item local egg_GRAVITY = 9 local egg_VELOCITY = 19 --- shoot snowball +-- shoot egg local mobs_shoot_egg = function (item, player, pointed_thing) local playerpos = player:getpos() minetest.sound_play("default_place_node_hard", { diff --git a/cow.lua b/cow.lua index 03a2129..88ee435 100644 --- a/cow.lua +++ b/cow.lua @@ -51,28 +51,39 @@ mobs:register_mob("mobs:cow", { replace_with = "air", fear_height = 2, on_rightclick = function(self, clicker) - if not mobs:feed_tame(self, clicker, 8, true, true) then - local tool = clicker:get_wielded_item() - -- milk cow with empty bucket - if tool:get_name() == "bucket:bucket_empty" then - if self.gotten == true - or self.child == true then - return - end - local inv = clicker:get_inventory() - inv:remove_item("main", "bucket:bucket_empty") - if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then - clicker:get_inventory():add_item("main", "mobs:bucket_milk") - else - local pos = self.object:getpos() - pos.y = pos.y + 0.5 - minetest.add_item(pos, {name = "mobs:bucket_milk"}) - end - self.gotten = true -- milked + -- feed or tame + if mobs:feed_tame(self, clicker, 8, true, true) then + return + end + + local tool = clicker:get_wielded_item() + + -- milk cow with empty bucket + if tool:get_name() == "bucket:bucket_empty" then + + if self.gotten == true + or self.child == true then return end - end + + local inv = clicker:get_inventory() + + inv:remove_item("main", "bucket:bucket_empty") + + if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then + clicker:get_inventory():add_item("main", "mobs:bucket_milk") + else + local pos = self.object:getpos() + pos.y = pos.y + 0.5 + minetest.add_item(pos, {name = "mobs:bucket_milk"}) + end + + self.gotten = true -- milked + + return + end + mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end, }) diff --git a/kitten.lua b/kitten.lua index d9cc58f..94720ec 100644 --- a/kitten.lua +++ b/kitten.lua @@ -40,7 +40,9 @@ mobs:register_mob("mobs:kitten", { follow = {"mobs:rat", "ethereal:fish_raw"}, view_range = 8, on_rightclick = function(self, clicker) - mobs:feed_tame(self, clicker, 4, true, true) + if mobs:feed_tame(self, clicker, 4, true, true) then + return + end mobs:capture_mob(self, clicker, 50, 50, 90, false, nil) end }) diff --git a/npc.lua b/npc.lua index 5e36add..3fcda35 100644 --- a/npc.lua +++ b/npc.lua @@ -62,35 +62,43 @@ mobs:register_mob("mobs:npc", { on_rightclick = function(self, clicker) -- feed to heal npc - if not mobs:feed_tame(self, clicker, 8, true, true) then - local item = clicker:get_wielded_item() - local name = clicker:get_player_name() + if mobs:feed_tame(self, clicker, 8, true, true) then + return + end - -- 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)] - }) - return + local item = clicker:get_wielded_item() + + -- 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)] + }) + + return + end + + -- capture npc with net or lasso + mobs:capture_mob(self, clicker, 0, 5, 80, false, nil) + + -- by right-clicking owner can switch npc between follow and stand + if self.owner and self.owner == clicker:get_player_name() then + if self.order == "follow" then + self.order = "stand" 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 + self.order = "follow" end end - mobs:capture_mob(self, clicker, 0, 5, 80, false, nil) end, }) diff --git a/sheep.lua b/sheep.lua index 953d8f0..634c39a 100644 --- a/sheep.lua +++ b/sheep.lua @@ -104,7 +104,10 @@ for _, col in ipairs(all_colours) do --are we coloring? if itemname:find("dye:") then - if self.gotten == false and self.child == false and self.tamed == true and name == self.owner then + if self.gotten == false + and self.child == false + and self.tamed == true + and name == self.owner then local col = string.split(itemname,":")[2] for _,c in pairs(all_colours) do if c == col then diff --git a/warthog.lua b/warthog.lua index a212c3f..d30a0ed 100644 --- a/warthog.lua +++ b/warthog.lua @@ -45,7 +45,9 @@ mobs:register_mob("mobs:pumba", { punch_end = 100, }, on_rightclick = function(self, clicker) - mobs:feed_tame(self, clicker, 8, true, true) + if mobs:feed_tame(self, clicker, 8, true, true) then + return + end mobs:capture_mob(self, clicker, 0, 5, 50, false, nil) end, })