diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..7a5f3b6 --- /dev/null +++ b/TODO.txt @@ -0,0 +1,3 @@ +this file was added by farooghkz. +TODO list: +- better images for eggs diff --git a/api.lua b/api.lua index 71b55e5..23db89b 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,17 @@ mobs = {} + +function mobs:is_in_tbl(a_tbl, a_val) + if not a_tbl then + return false + end + for key, val in ipairs(a_tbl) do + if val == a_val then + return true + end + end + return false +end + function mobs:register_mob(name, def) minetest.register_entity(name, { hp_max = def.hp_max, @@ -117,6 +130,10 @@ function mobs:register_mob(name, def) self.object:remove() end + if self.hp_max == 5 and self.type == "animal" then + -- TODO: if its sheep, it will eat grass! + end + self.lifetimer = self.lifetimer - dtime if self.lifetimer <= 0 and not self.tamed then local player_count = 0 @@ -248,7 +265,8 @@ function mobs:register_mob(name, def) end if self.following and self.following:is_player() then - if self.following:get_wielded_item():get_name() ~= self.follow then + item_name = self.following:get_wielded_item():get_name() + if not mobs:is_in_tbl(self.follow, item_name) then self.following = nil self.v_start = false else diff --git a/init.lua b/init.lua index 0bf5f26..4856c6f 100644 --- a/init.lua +++ b/init.lua @@ -199,12 +199,12 @@ mobs:register_mob("mobs:sheep", { walk_start = 81, walk_end = 100, }, - follow = "farming:wheat", + follow = {"farming:wheat", "farming:bread"}, view_range = 5, on_rightclick = function(self, clicker) local item = clicker:get_wielded_item() - if item:get_name() == "farming:wheat" then + if mobs:is_in_tbl({"farming:wheat", "farming:bread"}, item:get_name()) then if not self.tamed then if not minetest.setting_getbool("creative_mode") then item:take_item() @@ -242,6 +242,7 @@ mobs:register_mob("mobs:sheep", { }) mobs:register_spawn("mobs:sheep", {"default:dirt_with_grass"}, 20, 8, 9000, 1, 31000) + minetest.register_craftitem("mobs:meat_raw", { description = "Raw Meat", inventory_image = "mobs_meat_raw.png", @@ -275,6 +276,7 @@ mobs:register_mob("mobs:rat", { water_damage = 0, lava_damage = 1, light_damage = 0, + view_range = 3, on_rightclick = function(self, clicker) if clicker:is_player() and clicker:get_inventory() then @@ -297,6 +299,87 @@ minetest.register_craftitem("mobs:rat", { return itemstack end, }) + +minetest.register_craftitem("mobs:sheep_egg", { + description = "Sheep Egg", + inventory_image = "mobs_sheep_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:sheep") + itemstack:take_item() + end + return itemstack + end, +}) + +minetest.register_craftitem("mobs:dirt_monster_egg", { + description = "Dirt Monster Egg", + inventory_image = "mobs_dirt_monster_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:dirt_monster") + itemstack:take_item() + end + return itemstack + end, +}) + + +minetest.register_craftitem("mobs:sand_monster_egg", { + description = "Sand Monster Egg", + inventory_image = "mobs_sand_monster_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:sand_monster") + itemstack:take_item() + end + return itemstack + end, +}) + +minetest.register_craftitem("mobs:stone_monster_egg", { + description = "Stone Monster Egg", + inventory_image = "mobs_stone_monster_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:stone_monster") + itemstack:take_item() + end + return itemstack + end, +}) + + +minetest.register_craftitem("mobs:dungeon_master_egg", { + description = "Dungeon Master Egg", + inventory_image = "mobs_dungeon_master_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:dungeon_master") + itemstack:take_item() + end + return itemstack + end, +}) + +minetest.register_craftitem("mobs:oerkki_egg", { + description = "Oerkki Egg", + inventory_image = "mobs_oerkki_egg.png", + + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.above then + minetest.env:add_entity(pointed_thing.above, "mobs:oerkki") + itemstack:take_item() + end + return itemstack + end, +}) + minetest.register_craftitem("mobs:rat_cooked", { description = "Cooked Rat",