diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 6b2cff0e3..2a1981bf9 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2487,7 +2487,9 @@ local do_states = function(self, dtime) end if self.facing_fence == true or cliff_or_danger - or random(1, 100) <= 30 then + or random(1, 100) <= 30 + or ( (self.fly and not self.keep_flying) + or not self.fly ) then set_velocity(self, 0) self.state = "stand" @@ -3559,6 +3561,9 @@ local mob_activate = function(self, staticdata, def, dtime) -- run on_spawn function if found if self.on_spawn and not self.on_spawn_run then + if self.fly then + self.desired_altitude = self.desired_altitude + math.random(-5,10) + end if self.on_spawn(self) then self.on_spawn_run = true -- if true, set flag to run once only end @@ -3570,10 +3575,62 @@ local mob_activate = function(self, staticdata, def, dtime) end end +local function get_speed_over_ground(self) + local p = self.object:get_velocity() + return vector.length(vector.new(p.x,0,p.z)) +end + +local function check_ground(self) --return true if too close to the ground + local p = self.object:get_pos() + local n = minetest.find_nodes_in_area_under_air(vector.offset(p,0,-self.desired_altitude-1,0),vector.offset(p,0,0,0),{"group:solid"}) + if #n > 0 then + return true + end +end + +local function descend(self) + local v = self.object:get_velocity() + local gs = get_speed_over_ground(self) + local r = math.max(math.abs(self.fall_speed) - gs,1) + --minetest.log("descend "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r)) + if v.y > self.fall_speed then + self.object:set_velocity(vector.new(v.x,-r,v.z)) + end + +end + +local function climb(self) + local v = self.object:get_velocity() + local gs = get_speed_over_ground(self) + local r = self.run_velocity + gs + --minetest.log("climb "..tostring(r) .. " vel "..tostring(v.y).. " rate "..tostring(r)) + if v.y < self.walk_velocity then + self.object:add_velocity(vector.new(0,r/10,0)) + end +end +--self.floater +--self.desired altitude (above ground) +local function check_flight(self,dtime) + if self.floater or not self.fly then return end --floaters don't need altitdude adjustment + --self.state = "walk" + if not self.flap_timer and check_ground(self) then + climb(self) + self.flap_timer = 0 + elseif self.flap_timer then + if self.flap_timer > self.flap_time then + self.flap_timer = nil + else + self.flap_timer = self.flap_timer + dtime + end + else + descend(self) + end +end -- main mob function local mob_step = function(self, dtime) check_item_pickup(self) + check_flight(self,dtime) if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) end @@ -3904,7 +3961,7 @@ minetest.register_entity(name, { xp_max = def.xp_max or 0, xp_timestamp = 0, breath_max = def.breath_max or 15, - breathes_in_water = def.breathes_in_water or false, + breathes_in_water = def.breathes_in_water or false, physical = true, collisionbox = collisionbox, selectionbox = def.selectionbox or def.collisionbox, @@ -3915,6 +3972,9 @@ minetest.register_entity(name, { view_range = def.view_range or 16, walk_velocity = def.walk_velocity or 1, run_velocity = def.run_velocity or 2, + desired_altitude = def.desired_altitude or 12, --over ground + flap_time = def.flap_time or 2, --time between wing glap / climb events + keep_flying = def.keep_flying or false, damage = scale_difficulty(def.damage, 0, 0), light_damage = def.light_damage or 0, sunlight_damage = def.sunlight_damage or 0, diff --git a/mods/ENTITIES/mobs_mc/init.lua b/mods/ENTITIES/mobs_mc/init.lua index 02f5023a5..16225d9f8 100644 --- a/mods/ENTITIES/mobs_mc/init.lua +++ b/mods/ENTITIES/mobs_mc/init.lua @@ -142,3 +142,5 @@ dofile(path .. "/slime+magma_cube.lua") -- Wuzzy dofile(path .. "/spider.lua") -- Spider by AspireMint (fishyWET (CC-BY-SA 3.0 license for texture) dofile(path .. "/vex.lua") -- KrupnoPavel dofile(path .. "/wither.lua") -- Mesh and animation by toby109tt / https://github.com/22i + +dofile(path .. "/phantom.lua") -- Mesh and animation by toby109tt / https://github.com/22i diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_phantom.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_phantom.b3d new file mode 100644 index 000000000..b8f40ea51 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/models/mobs_mc_phantom.b3d differ diff --git a/mods/ENTITIES/mobs_mc/phantom.lua b/mods/ENTITIES/mobs_mc/phantom.lua new file mode 100644 index 000000000..b73e61aa7 --- /dev/null +++ b/mods/ENTITIES/mobs_mc/phantom.lua @@ -0,0 +1,62 @@ +--Phantom for mcl2 +--cora +--License for code WTFPL, cc0 + +local S = minetest.get_translator("mobs_mc") + +mcl_mobs:register_mob("mobs_mc:phantom", { + description = S("Phantom"), + type = "monster", + spawn_class = "passive", + pathfinding = 1, + hp_min = 6, + hp_max = 6, + xp_min = 1, + xp_max = 3, + collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.89, 0.25}, + visual = "mesh", + mesh = "mobs_mc_phantom.b3d", + textures = {{"mobs_mc_phantom.png","mobs_mc_phantom_e.png","mobs_mc_phantom_e_s.png"}}, + visual_size = {x=3, y=3}, + walk_velocity = 3, + run_velocity = 5, + desired_altitude = 19, + keep_flying = true, + sounds = { + random = "mobs_mc_phantom_random", + damage = {name="mobs_mc_phantom_hurt", gain=0.3}, + death = {name="mobs_mc_phantom_death", gain=0.6}, + eat = "mobs_mc_animal_eat_generic", + distance = 16, + }, + drops = { + {name = "mcl_mobitems:leather", --TODO: phantom membrane + chance = 1, + min = 1, + max = 2, + looting = "common",}, + }, + animation = { + stand_speed = 50, + walk_speed = 50, + fly_speed = 50, + stand_start = 0, + stand_end = 0, + fly_start = 0, + fly_end = 30, + walk_start = 0, + walk_end = 30, + }, + fall_damage = 0, + fall_speed = -2.25, + attack_type = "dogfight", + floats = 1, + physical = true, + fly = true, + makes_footstep_sound = false, + fear_height = 0, + view_range = 16, +}) + +-- spawn eggs +mcl_mobs:register_egg("mobs_mc:phantom", S("Phantom"), "mobs_mc_spawn_icon_phantom.png", 0) diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom.png new file mode 100644 index 000000000..4478dbcdb Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e.png new file mode 100644 index 000000000..504750d87 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e_s.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e_s.png new file mode 100644 index 000000000..67a84612a Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_e_s.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes.png new file mode 100644 index 000000000..91576c6ce Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes_s.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes_s.png new file mode 100644 index 000000000..3157e13f5 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_phantom_eyes_s.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_spawn_icon_phantom.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spawn_icon_phantom.png new file mode 100644 index 000000000..7b9dc99e3 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spawn_icon_phantom.png differ