diff --git a/README.txt b/README.txt index 7e6d28b..43fb832 100644 --- a/README.txt +++ b/README.txt @@ -28,6 +28,7 @@ This mod contains the following additions: Changelog: +1.19- Chickens now drop egg items instead of placing the egg, also throwing eggs result in 1/8 chance of spawning chick 1.18- Added docile_by_day flag so that monsters will not attack automatically during daylight hours unless hit first 1.17- Added 'dogshoot' attack type, shoots when out of reach, melee attack when in reach, also api tweaks and self.reach added 1.16- Mobs follow multiple items now, Npc's can breed diff --git a/api.lua b/api.lua index d03f4e5..e408a2d 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,4 @@ --- Mobs Api (27th October 2015) +-- Mobs Api (30th October 2015) mobs = {} mobs.mod = "redo" @@ -250,8 +250,9 @@ do_env_damage = function(self) -- lava or fire if self.lava_damage ~= 0 and (nodef.groups.lava - or nod.name == "fire:basic_flame" - or nod.name == "fire:eternal_flame") then + or nod.name == "fire:basic_flame" + or nod.name == "fire:eternal_flame" + or nod.name == "fire:permanent_flame") then self.object:set_hp(self.object:get_hp() - self.lava_damage) effect(pos, 5, "fire_basic_flame.png") end @@ -263,7 +264,8 @@ end -- jump if facing a solid node (not fences) do_jump = function(self) - if self.fly then + if self.fly + or self.child then return end diff --git a/chicken.lua b/chicken.lua index f66edf9..d7e77ed 100644 --- a/chicken.lua +++ b/chicken.lua @@ -45,19 +45,120 @@ mobs:register_mob("mobs:chicken", { }, follow = {"farming:seed_wheat", "farming:seed_cotton"}, view_range = 5, - replace_rate = 8000, - replace_what = {"air"}, - replace_with = "mobs:egg", +-- replace_rate = 8000, +-- replace_what = {"air"}, +-- replace_with = "mobs:egg", + on_rightclick = function(self, clicker) mobs:feed_tame(self, clicker, 8, true, true) mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) end, + + do_custom = function(self) + if not self.child + and math.random(1, 100) == 1 then + local pos = self.object:getpos() + minetest.add_item(pos, "mobs:egg") + minetest.sound_play("default_place_node_hard", { + pos = pos, + gain = 1.0, + max_hear_distance = 5, + }) + end + end, }) mobs:register_spawn("mobs:chicken", {"default:dirt_with_grass", "ethereal:bamboo_dirt"}, 20, 10, 15000, 1, 31000) mobs:register_egg("mobs:chicken", "Chicken", "mobs_chicken_inv.png", 0) +-- egg entity + +mobs:register_arrow("mobs:egg_entity", { + visual = "sprite", + visual_size = {x=.5, y=.5}, + textures = {"mobs_chicken_egg.png"}, + velocity = 6, + + hit_player = function(self, player) + player:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 1}, + }, nil) + end, + + hit_mob = function(self, player) + player:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = 1}, + }, nil) + end, + + hit_node = function(self, pos, node) + + local num = math.random(1, 8) + if num == 1 then + pos.y = pos.y + 1 + local mob = minetest.add_entity(pos, "mobs:chicken") + local ent2 = mob:get_luaentity() + mob:set_properties({ + textures = ent2.child_texture[1], + visual_size = { + x = ent2.base_size.x / 2, + y = ent2.base_size.y / 2 + }, + collisionbox = { + ent2.base_colbox[1] / 2, + ent2.base_colbox[2] / 2, + ent2.base_colbox[3] / 2, + ent2.base_colbox[4] / 2, + ent2.base_colbox[5] / 2, + ent2.base_colbox[6] / 2 + }, + }) + ent2.child = true + ent2.tamed = true + ent2.owner = self.playername + end + end +}) + +-- snowball throwing item + +local egg_GRAVITY = 9 +local egg_VELOCITY = 19 + +-- shoot snowball +local mobs_shoot_egg = function (item, player, pointed_thing) + local playerpos = player:getpos() + minetest.sound_play("default_place_node_hard", { + pos = playerpos, + gain = 1.0, + max_hear_distance = 5, + }) + local obj = minetest.add_entity({ + x = playerpos.x, + y = playerpos.y +1.5, + z = playerpos.z + }, "mobs:egg_entity") + local dir = player:get_look_dir() + obj:get_luaentity().velocity = egg_VELOCITY -- needed for api internal timing + obj:setvelocity({ + x = dir.x * egg_VELOCITY, + y = dir.y * egg_VELOCITY, + z = dir.z * egg_VELOCITY + }) + obj:setacceleration({ + x = dir.x * -3, + y = -egg_GRAVITY, + z = dir.z * -3 + }) + local ent2 = obj:get_luaentity() + ent2.playername = player:get_player_name() + item:take_item() + return item +end + -- egg minetest.register_node("mobs:egg", { description = "Chicken Egg", @@ -74,12 +175,13 @@ minetest.register_node("mobs:egg", { type = "fixed", fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2} }, - groups = {snappy=2, dig_immediate=3}, + groups = {snappy = 2, dig_immediate = 3}, after_place_node = function(pos, placer, itemstack) if placer:is_player() then minetest.set_node(pos, {name = "mobs:egg", param2 = 1}) end - end + end, + on_use = mobs_shoot_egg }) -- fried egg