Merge pull request #12 from farooqkz/master

Add eggs and replace follow strings with tables
farooqkz-eggs-and-follow-tables
Jacob Gustafson 2020-02-22 02:16:48 -05:00 committed by GitHub
commit bc2a1839dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 107 additions and 3 deletions

3
TODO.txt Normal file
View File

@ -0,0 +1,3 @@
this file was added by farooghkz.
TODO list:
- better images for eggs

20
api.lua
View File

@ -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

View File

@ -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",

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

BIN
textures/mobs_sheep_egg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B