diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a046a1205e..7fb4e6a321 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1438,7 +1438,8 @@ end -- should mob follow what I'm holding ? local follow_holding = function(self, clicker) - + if self.nofollow then return false end + if mobs.invis[clicker:get_player_name()] then return false end @@ -2317,17 +2318,50 @@ local dogswitch = function(self, dtime) return self.dogshoot_switch end +local function go_to_pos(entity,b) + if not entity then return end + local s=entity.object:get_pos() + if vector.distance(b,s) < 1 then + --set_velocity(entity,0) + return true + end + local v = { x = b.x - s.x, z = b.z - s.z } + local yaw = (math.atan(v.z / v.x) + math.pi / 2) - entity.rotate + if b.x > s.x then yaw = yaw + math.pi end + entity.object:set_yaw(yaw) + set_velocity(entity,entity.follow_velocity) + mobs:set_animation(entity, "walk") +end + +local function check_doors(self) + local p = self.object:get_pos() + local t = minetest.get_timeofday() + local dd = minetest.find_nodes_in_area(vector.offset(p,-1,-1,-1),vector.offset(p,1,1,1),{"group:door"}) + for _,d in pairs(dd) do + local n = minetest.get_node(d) + if n.name:find("_b_") then + local def = minetest.registered_nodes[n.name] + local closed = n.name:find("_b_1") + if t < 0.3 or t > 0.8 then + if not closed then def.on_rightclick(d,n,self) end + else + if closed then def.on_rightclick(d,n,self) end + end + + end + end +end + -- execute current state (stand, walk, run, attacks) -- returns true if mob has died local do_states = function(self, dtime) - + if self.can_open_doors then check_doors(self) end + local yaw = self.object:get_yaw() or 0 if self.state == "stand" then - if random(1, 4) == 1 then - local lp = nil local s = self.object:get_pos() local objs = minetest.get_objects_inside_radius(s, 3) @@ -2340,7 +2374,7 @@ local do_states = function(self, dtime) end -- look at any players nearby, otherwise turn randomly - if lp then + if self.look_at_players then local vec = { x = lp.x - s.x, @@ -2375,8 +2409,35 @@ local do_states = function(self, dtime) end end - elseif self.state == "walk" then + elseif self.state == "gowp" then + local p = self.object:get_pos() + if not p or not self._target then return end + if vector.distance(p,self._target) < 2 or ( self.waypoints and #self.waypoints == 0 ) then + self.waypoints = nil + self._target = nil + self.current_target = nil + self.state = "walk" + if self.callback_arrived then return self.callback_arrived(self) end + return true + end + if self.waypoints and ( not self.current_target or vector.distance(p,self.current_target) < 1.5 ) then + self.current_target = table.remove(self.waypoints, 1) + --minetest.log("nextwp:".. tostring(self.current_target) ) + elseif self.current_target then + go_to_pos(self,self.current_target) + end + + if self.current_target and not minetest.line_of_sight(self.object:get_pos(),self.current_target) then + self.waypoints=minetest.find_path(p,self._target,150,1,4) + self.current_target = nil + return + end + if not self.current_target then + --minetest.log("no path") + self.state = "walk" + end + elseif self.state == "walk" then local s = self.object:get_pos() local lp = nil @@ -2880,6 +2941,62 @@ local do_states = function(self, dtime) end end +local plane_adjacents = { + vector.new(1,0,0), + vector.new(-1,0,0), + vector.new(0,0,1), + vector.new(0,0,-1), +} + +function mobs:gopath(self,target,callback_arrived) + local p = self.object:get_pos() + local t = vector.offset(target,0,1,0) + local wp = minetest.find_path(p,t,150,1,4) + if not wp then + local d = minetest.find_node_near(target,16,{"group:door"}) + if d then + for _,v in pairs(plane_adjacents) do + local pos = vector.add(d,v) + local n = minetest.get_node(pos) + if n.name == "air" then + wp = minetest.find_path(p,pos,150,1,4) + if wp then break end + end + end + end + end + if wp and #wp > 0 then + self._target = t + self.callback_arrived = callback_arrived + self.waypoints = wp + self.state = "gowp" + return true + else + --minetest.log("no path found") + end +end + +local function player_near(pos) + for _,o in pairs(minetest.get_objects_inside_radius(pos,2)) do + if o:is_player() then return true end + end +end + +local function check_item_pickup(self) + if self.pick_up and #self.pick_up > 0 then + local p = self.object:get_pos() + for _,o in pairs(minetest.get_objects_inside_radius(p,2)) do + local l=o:get_luaentity() + if l and l.name == "__builtin:item" then + for k,v in pairs(self.pick_up) do + if not player_near(p) and self.on_pick_up and l.itemstring:find(v) then + if self.on_pick_up(self,l) == nil then o:remove() end + end + end + end + end + end +end -- falling and fall damage -- returns true if mob died @@ -3481,7 +3598,7 @@ end -- main mob function local mob_step = function(self, dtime) - + check_item_pickup(self) if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) end @@ -3576,8 +3693,7 @@ local mob_step = function(self, dtime) -- attack timer self.timer = self.timer + dtime - if self.state ~= "attack" then - + if self.state ~= "attack" and self.state ~= "gowp" then if self.timer < 1 then return end @@ -3845,6 +3961,8 @@ minetest.register_entity(name, { sounds = def.sounds or {}, animation = def.animation, follow = def.follow, + nofollow = def.nofollow, + can_open_doors = def.can_open_doors, jump = def.jump ~= false, walk_chance = def.walk_chance or 50, attacks_monsters = def.attacks_monsters or false, @@ -3910,7 +4028,8 @@ minetest.register_entity(name, { child = def.child or false, texture_mods = {}, shoot_arrow = def.shoot_arrow, - sounds_child = def.sounds_child, + sounds_child = def.sounds_child, + pick_up = def.pick_up, explosion_strength = def.explosion_strength, suffocation_timer = 0, follow_velocity = def.follow_velocity or 2.4, @@ -3934,6 +4053,8 @@ minetest.register_entity(name, { on_grown = def.on_grown, + on_pick_up = def.on_pick_up, + on_detach_child = mob_detach_child, on_activate = function(self, staticdata, dtime) @@ -4250,7 +4371,7 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame) end -- can eat/tame with item in hand - if follow_holding(self, clicker) then + if self.nofollow or follow_holding(self, clicker) then -- if not in creative then take item if not mobs.is_creative(clicker:get_player_name()) then diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index eda74aeb42..b9b6613b6a 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -12,247 +12,255 @@ Registering Mobs To register a mob and have it ready for use requires the following function: - mobs:register_mob(name, definition) + mobs:register_mob(name, definition) The 'name' of a mob usually starts with the mod name it's running from followed by it's own name e.g. - "mobs_monster:sand_monster" or "mymod:totally_awesome_beast" + "mobs_monster:sand_monster" or "mymod:totally_awesome_beast" ... and the 'definition' is a table which holds all of the settings and functions needed for the mob to work properly which contains the following: - 'nametag' contains the name which is shown above mob. - 'type' holds the type of mob that inhabits your world e.g. - "animal" usually docile and walking around. - "monster" attacks player or npc on sight. - "npc" walk around and will defend themselves if hit first, they - kill monsters. - 'hp_min' the minimum health value the mob can spawn with. - 'hp_max' the maximum health value the mob can spawn with. - 'breath_max' The maximum breath value the mob can spawn with and can have. - If -1 (default), mob does not take drowning damage. - 'breathes_in_water' If true, mob loses breath when not in water. Otherwise, - mob loses breath when inside a node with `drowning` attribute - set (default: false). - 'armor' entity armor groups (see lua_api.txt). If table, a list of - armor groups like for entities. If number, set value of - 'fleshy' armor group only. - Note: The 'immortal=1' armor group will automatically be added - since this mod handles health and damage manually. - Default: 100 (mob will take full dmg from 'fleshy' hits) - 'passive' when true allows animals to defend themselves when hit, - otherwise they amble onwards. - 'walk_velocity' is the speed that your mob can walk around. - 'run_velocity' is the speed your mob can run with, usually when attacking. - 'walk_chance' has a 0-100 chance value your mob will walk from standing, - set to 0 for jumping mobs only. - 'jump' when true allows your mob to jump updwards. - 'jump_height' holds the height your mob can jump, 0 to disable jumping. - 'stepheight' height of a block that your mob can easily walk up onto, - defaults to 0.6. - 'fly' when true allows your mob to fly around instead of walking. - 'fly_in' holds the node name or a table of node names in which the - mob flies (or swims) around in. The special name - '__airlike' stands for all nodes with 'walkable=false' - that are not liquids - 'runaway' if true causes animals to turn and run away when hit. - 'view_range' how many nodes in distance the mob can see a player. - 'damage' how many health points the mob does to a player or another - mob when melee attacking. - 'knock_back' when true has mobs falling backwards when hit, the greater - the damage the more they move back. - 'fear_height' is how high a cliff or edge has to be before the mob stops - walking, 0 to turn off height fear. - 'fall_speed' has the maximum speed the mob can fall at, default is -10. - 'fall_damage' when true causes falling to inflict damage. - 'water_damage' holds the damage per second infliced to mobs when standing in - water (default: 0). - 'lava_damage' holds the damage per second inflicted to mobs when standing - in lava (default: 8). - 'fire_damage' holds the damage per second inflicted to mobs when standing - in fire (default: 1). - 'light_damage' holds the damage per second inflicted to mobs when it's too - bright (above 13 light). - 'suffocation' when true causes mobs to suffocate inside solid blocks (2 damage per second). - 'floats' when set to 1 mob will float in water, 0 has them sink. - 'follow' mobs follow player when holding any of the items which appear - on this table, the same items can be fed to a mob to tame or - breed e.g. {"farming:wheat", "default:apple"} + 'nametag' contains the name which is shown above mob. + 'type' holds the type of mob that inhabits your world e.g. + "animal" usually docile and walking around. + "monster" attacks player or npc on sight. + "npc" walk around and will defend themselves if hit first, they + kill monsters. + 'hp_min' the minimum health value the mob can spawn with. + 'hp_max' the maximum health value the mob can spawn with. + 'breath_max' The maximum breath value the mob can spawn with and can have. + If -1 (default), mob does not take drowning damage. + 'breathes_in_water' If true, mob loses breath when not in water. Otherwise, + mob loses breath when inside a node with `drowning` attribute + set (default: false). + 'armor' entity armor groups (see lua_api.txt). If table, a list of + armor groups like for entities. If number, set value of + 'fleshy' armor group only. + Note: The 'immortal=1' armor group will automatically be added + since this mod handles health and damage manually. + Default: 100 (mob will take full dmg from 'fleshy' hits) + 'passive' when true allows animals to defend themselves when hit, + otherwise they amble onwards. + 'walk_velocity' is the speed that your mob can walk around. + 'run_velocity'is the speed your mob can run with, usually when attacking. + 'walk_chance' has a 0-100 chance value your mob will walk from standing, + set to 0 for jumping mobs only. + 'jump' when true allows your mob to jump updwards. + 'jump_height' holds the height your mob can jump, 0 to disable jumping. + 'stepheight' height of a block that your mob can easily walk up onto, + defaults to 0.6. + 'fly' when true allows your mob to fly around instead of walking. + 'fly_in' holds the node name or a table of node names in which the + mob flies (or swims) around in. The special name + '__airlike' stands for all nodes with 'walkable=false' + that are not liquids + 'runaway' if true causes animals to turn and run away when hit. + 'view_range' how many nodes in distance the mob can see a player. + 'damage' how many health points the mob does to a player or another + mob when melee attacking. + 'knock_back' when true has mobs falling backwards when hit, the greater + the damage the more they move back. + 'fear_height' is how high a cliff or edge has to be before the mob stops + walking, 0 to turn off height fear. + 'fall_speed' has the maximum speed the mob can fall at, default is -10. + 'fall_damage' when true causes falling to inflict damage. + 'water_damage'holds the damage per second infliced to mobs when standing in + water (default: 0). + 'lava_damage' holds the damage per second inflicted to mobs when standing + in lava (default: 8). + 'fire_damage' holds the damage per second inflicted to mobs when standing + in fire (default: 1). + 'light_damage'holds the damage per second inflicted to mobs when it's too + bright (above 13 light). + 'suffocation' when true causes mobs to suffocate inside solid blocks (2 damage per second). + 'floats' when set to 1 mob will float in water, 0 has them sink. + 'follow' mobs follow player when holding any of the items which appear + on this table, the same items can be fed to a mob to tame or + breed e.g. {"farming:wheat", "default:apple"} - 'reach' is how far the mob can attack player when standing - nearby, default is 3 nodes. - 'docile_by_day' when true has mobs wandering around during daylight - hours and only attacking player at night or when - provoked. - 'attacks_monsters' when true has npc's attacking monsters or not. - 'attack_animals' when true will have monsters attacking animals. - 'owner_loyal' when true will have tamed mobs attack anything player - punches when nearby. - 'group_attack' when true has same mob type grouping together to attack - offender. - [MCL2 extension:] When a table, this is a list of - mob types that will get alerted as well (besides same mob type) - 'attack_type' tells the api what a mob does when attacking the player - or another mob: - 'dogfight' is a melee attack when player is within mob reach. - 'shoot' has mob shoot pre-defined arrows at player when inside - view_range. - 'dogshoot' has melee attack when inside reach and shoot attack - when inside view_range. - 'explode' causes mob to stop and explode when inside reach. - 'explosion_radius' the radius of explosion node destruction, - defaults to 1 - 'explosion_damage_radius' the radius of explosion entity & player damage, - defaults to explosion_radius * 2 - 'explosion_timer' number of seconds before mob explodes while its target - is still inside reach or explosion_damage_radius, - defaults to 3. - 'explosiontimer_reset_radius' The distance you must travel before the timer will be reset. - 'allow_fuse_reset' Allow 'explode' attack_type to reset fuse and resume - chasing if target leaves the blast radius or line of - sight. Defaults to true. - 'stop_to_explode' When set to true (default), mob must stop and wait for - explosion_timer in order to explode. If false, mob will - continue chasing. - 'arrow' holds the pre-defined arrow object to shoot when - attacking. - 'dogshoot_switch' allows switching between attack types by using timers - (1 for shoot, 2 for dogfight) - 'dogshoot_count_max' contains how many seconds before switching from - dogfight to shoot. - 'dogshoot_count2_max' contains how many seconds before switching from shoot - to dogfight. - 'shoot_interval' has the number of seconds between shots. - 'shoot_offset' holds the y position added as to where the - arrow/fireball appears on mob. - 'specific_attack' has a table of entity names that mob can also attack - e.g. {"player", "mobs_animal:chicken"}. - 'runaway_from' contains a table with mob names to run away from, add - "player" to list to runaway from player also. - 'pathfinding' set to 1 for mobs to use pathfinder feature to locate - player, set to 2 so they can build/break also (only - works with dogfight attack and when 'mobs_griefing' - in minetest.conf is not false). - 'immune_to' is a table that holds specific damage when being hit by - certain items e.g. - {"default:sword_wood", 0} -- causes no damage. - {"default:gold_lump", -10} -- heals by 10 health points. - {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks. + 'reach' is how far the mob can attack player when standing + nearby, default is 3 nodes. + 'docile_by_day' when true has mobs wandering around during daylight + hours and only attacking player at night or when + provoked. + 'attacks_monsters' when true has npc's attacking monsters or not. + 'attack_animals' when true will have monsters attacking animals. + 'owner_loyal' when true will have tamed mobs attack anything player + punches when nearby. + 'group_attack' when true has same mob type grouping together to attack + offender. + [MCL2 extension:] When a table, this is a list of + mob types that will get alerted as well (besides same mob type) + 'attack_type' tells the api what a mob does when attacking the player + or another mob: + 'dogfight' is a melee attack when player is within mob reach. + 'shoot' has mob shoot pre-defined arrows at player when inside + view_range. + 'dogshoot' has melee attack when inside reach and shoot attack + when inside view_range. + 'explode' causes mob to stop and explode when inside reach. + 'explosion_radius' the radius of explosion node destruction, + defaults to 1 + 'explosion_damage_radius' the radius of explosion entity & player damage, + defaults to explosion_radius * 2 + 'explosion_timer' number of seconds before mob explodes while its target + is still inside reach or explosion_damage_radius, + defaults to 3. + 'explosiontimer_reset_radius' The distance you must travel before the timer will be reset. + 'allow_fuse_reset' Allow 'explode' attack_type to reset fuse and resume + chasing if target leaves the blast radius or line of + sight. Defaults to true. + 'stop_to_explode' When set to true (default), mob must stop and wait for + explosion_timer in order to explode. If false, mob will + continue chasing. + 'arrow' holds the pre-defined arrow object to shoot when + attacking. + 'dogshoot_switch' allows switching between attack types by using timers + (1 for shoot, 2 for dogfight) + 'dogshoot_count_max'contains how many seconds before switching from + dogfight to shoot. + 'dogshoot_count2_max' contains how many seconds before switching from shoot + to dogfight. + 'shoot_interval' has the number of seconds between shots. + 'shoot_offset' holds the y position added as to where the + arrow/fireball appears on mob. + 'specific_attack' has a table of entity names that mob can also attack + e.g. {"player", "mobs_animal:chicken"}. + 'runaway_from' contains a table with mob names to run away from, add + "player" to list to runaway from player also. + 'pathfinding' set to 1 for mobs to use pathfinder feature to locate + player, set to 2 so they can build/break also (only + works with dogfight attack and when 'mobs_griefing' + in minetest.conf is not false). + 'immune_to' is a table that holds specific damage when being hit by + certain items e.g. + {"default:sword_wood",0} -- causes no damage. + {"default:gold_lump", -10} -- heals by 10 health points. + {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks. - 'makes_footstep_sound' when true you can hear mobs walking. - 'sounds' this is a table with sounds of the mob - 'distance' maximum distance sounds can be heard, default is 10. - 'base_pitch' base pitch to use adult mobs, default is 1.0 (MCL2 extension) - 'random' played randomly from time to time. - also played for overfeeding animal. - 'eat' played when mob eats something - 'war_cry' what you hear when mob starts to attack player. (currently disabled) - 'attack' what you hear when being attacked. - 'shoot_attack' sound played when mob shoots. - 'damage' sound heard when mob is hurt. - 'death' played when mob is killed. - 'jump' played when mob jumps. There's a built-in cooloff timer to avoid sound spam - 'flop' played when mob flops (like a stranded fish) - 'fuse' sound played when mob explode timer starts. - 'explode' sound played when mob explodes. + 'makes_footstep_sound' when true you can hear mobs walking. + 'sounds' this is a table with sounds of the mob + 'distance' maximum distance sounds can be heard, default is 10. + 'base_pitch' base pitch to use adult mobs, default is 1.0 (MCL2 extension) + 'random' played randomly from time to time. + also played for overfeeding animal. + 'eat' played when mob eats something + 'war_cry' what you hear when mob starts to attack player. (currently disabled) + 'attack' what you hear when being attacked. + 'shoot_attack' sound played when mob shoots. + 'damage' sound heard when mob is hurt. + 'death' played when mob is killed. + 'jump' played when mob jumps. There's a built-in cooloff timer to avoid sound spam + 'flop' played when mob flops (like a stranded fish) + 'fuse' sound played when mob explode timer starts. + 'explode' sound played when mob explodes. - Note: For all sounds except fuse and explode, the pitch is slightly randomized from the base pitch - The pitch of children is 50% higher. + Note: For all sounds except fuse and explode, the pitch is slightly randomized from the base pitch + The pitch of children is 50% higher. - 'drops' table of items that are dropped when mob is killed, fields are: - 'name' name of item to drop. - 'chance' chance of drop, 1 for always, 2 for 1-in-2 chance etc. - 'min' minimum number of items dropped. - 'max' maximum number of items dropped. + 'drops' table of items that are dropped when mob is killed, fields are: + 'name' name of item to drop. + 'chance' chance of drop, 1 for always, 2 for 1-in-2 chance etc. + 'min' minimum number of items dropped. + 'max' maximum number of items dropped. - 'visual' holds the look of the mob you wish to create: - 'cube' looks like a normal node - 'sprite' sprite which looks same from all angles. - 'upright_sprite' flat model standing upright. - 'wielditem' how it looks when player holds it in hand. - 'mesh' uses separate object file to define mob. - 'visual_size' has the size of the mob, defaults to {x = 1, y = 1} - 'collisionbox' has the box in which mob can be interacted with the - world e.g. {-0.5, -0.5, -0.5, 0.5, 0.8, 0.5}. - NOTE: Due to a workaround, the upper Y coordinate will be forced - to a minimum value of 0.79. - 'selectionbox' has the box in which player can interact with mob - 'textures' holds a table list of textures to be used for mob, or you - could use multiple lists inside another table for random - selection e.g. { {"texture1.png"}, {"texture2.png"} } - 'child_texture' holds the texture table for when baby mobs are used. - 'gotten_texture' holds the texture table for when self.gotten value is - true, used for milking cows or shearing sheep. - 'mesh' holds the name of the external object used for mob model - e.g. "mobs_cow.b3d" - 'gotten_mesh" holds the name of the external object used for when - self.gotten is true for mobs. - 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back, - 270 = other side. - 'double_melee_attack' when true has the api choose between 'punch' and - 'punch2' animations. + 'visual' holds the look of the mob you wish to create: + 'cube' looks like a normal node + 'sprite' sprite which looks same from all angles. + 'upright_sprite' flat model standing upright. + 'wielditem' how it looks when player holds it in hand. + 'mesh' uses separate object file to define mob. + 'visual_size' has the size of the mob, defaults to {x = 1, y = 1} + 'collisionbox' has the box in which mob can be interacted with the + world e.g. {-0.5, -0.5, -0.5, 0.5, 0.8, 0.5}. + NOTE: Due to a workaround, the upper Y coordinate will be forced + to a minimum value of 0.79. + 'selectionbox' has the box in which player can interact with mob + 'textures' holds a table list of textures to be used for mob, or you + could use multiple lists inside another table for random + selection e.g. { {"texture1.png"}, {"texture2.png"} } + 'child_texture' holds the texture table for when baby mobs are used. + 'gotten_texture' holds the texture table for when self.gotten value is + true, used for milking cows or shearing sheep. + 'mesh' holds the name of the external object used for mob model + e.g. "mobs_cow.b3d" + 'gotten_mesh" holds the name of the external object used for when + self.gotten is true for mobs. + 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back, + 270 = other side. + 'double_melee_attack' when true has the api choose between 'punch' and + 'punch2' animations. - 'animation' holds a table containing animation names and settings for use with mesh models: - 'stand_start' start frame for when mob stands still. - 'stand_end' end frame of stand animation. - 'stand_speed' speed of animation in frames per second. - 'walk_start' when mob is walking around. - 'walk_end' - 'walk_speed' - 'run_start' when a mob runs or attacks. - 'run_end' - 'run_speed' - 'fly_start' when a mob is flying. - 'fly_end' - 'fly_speed' - 'punch_start' when a mob melee attacks. - 'punch_end' - 'punch_speed' - 'punch2_start' alternative melee attack animation. - 'punch2_end' - 'punch2_speed' - 'shoot_start' shooting animation. - 'shoot_end' - 'shoot_speed' - 'die_start' death animation - 'die_end' - 'die_speed' - 'die_loop' when set to false stops the animation looping. + 'animation' holds a table containing animation names and settings for use with mesh models: + { + 'stand_start'start frame for when mob stands still. + 'stand_end' end frame of stand animation. + 'stand_speed'speed of animation in frames per second. + 'walk_start' when mob is walking around. + 'walk_end' + 'walk_speed' + 'run_start' when a mob runs or attacks. + 'run_end' + 'run_speed' + 'fly_start' when a mob is flying. + 'fly_end' + 'fly_speed' + 'punch_start'when a mob melee attacks. + 'punch_end' + 'punch_speed' + 'punch2_start' alternative melee attack animation. + 'punch2_end' + 'punch2_speed' + 'shoot_start'shooting animation. + 'shoot_end' + 'shoot_speed' + 'die_start' death animation + 'die_end' + 'die_speed' + 'die_loop' when set to false stops the animation looping. + } - Using '_loop = false' setting will stop any of the above animations from - looping. + Using '_loop = false' setting will stop any of the above animations from + looping. - 'speed_normal' is used for animation speed for compatibility with some - older mobs. - 'pushable' Allows players, & other mobs to push the mob. + 'speed_normal' is used for animation speed for compatibility with some + older mobs. + 'pushable' Allows players, & other mobs to push the mob. - MineClone 2 extensions: + MineClone 2 extensions: - 'spawn_class' Classification of mod for the spawning algorithm: - "hostile", "passive", "ambient" or "water" - 'ignores_nametag' if true, mob cannot be named by nametag - 'rain_damage' damage per second if mob is standing in rain (default: 0) - 'sunlight_damage' holds the damage per second inflicted to mobs when they - are in direct sunlight - 'spawn_small_alternative': name of a smaller mob to use as replacement if - spawning fails due to space requirements - 'glow' same as in entity definition - 'child' if true, spawn mob as child - 'shoot_arrow(self, pos, dir)' function that is called when mob wants to shoot an arrow. - You can spawn your own arrow here. pos is mob position, - dir is mob's aiming direction - 'sounds_child' same as sounds, but for childs. If not defined, childs will use same - sound as adults but with higher pitch - 'follow_velocity' The speed at which a mob moves toward the player when they're holding the appropriate follow item. - 'instant_death' If true, mob dies instantly (no death animation or delay) (default: false) - 'xp_min' the minimum XP it drops on death (default: 0) - 'xp_max' the maximum XP it drops on death (default: 0) - 'fire_resistant' If true, the mob can't burn - 'fire_damage_resistant' If true the mob will not take damage when burning - 'ignited_by_sunlight' If true the mod will burn at daytime. (Takes sunlight_damage per second) + 'spawn_class' Classification of mod for the spawning algorithm: + "hostile", "passive", "ambient" or "water" + 'ignores_nametag' if true, mob cannot be named by nametag + 'rain_damage' damage per second if mob is standing in rain (default: 0) + 'sunlight_damage' holds the damage per second inflicted to mobs when they + are in direct sunlight + 'spawn_small_alternative' name of a smaller mob to use as replacement if + spawning fails due to space requirements + 'glow' same as in entity definition + 'child' if true, spawn mob as child + 'shoot_arrow(self, pos, dir)' function that is called when mob wants to shoot an arrow. + You can spawn your own arrow here. pos is mob position, + dir is mob's aiming direction + 'sounds_child' same as sounds, but for childs. If not defined, childs will use same + sound as adults but with higher pitch + 'follow_velocity' The speed at which a mob moves toward the player when they're holding the appropriate follow item. + 'instant_death' If true, mob dies instantly (no death animation or delay) (default: false) + 'xp_min' the minimum XP it drops on death (default: 0) + 'xp_max' the maximum XP it drops on death (default: 0) + 'fire_resistant' If true, the mob can't burn + 'fire_damage_resistant' If true the mob will not take damage when burning + 'ignited_by_sunlight' If true the mod will burn at daytime. (Takes sunlight_damage per second) + 'nofollow' Do not follow players when they wield the "follow" item. For mobs (like villagers) + that are bred in a different way. + 'pick_up' table of itemstrings the mob will pick up (e.g. for breeding) + 'on_pick_up' function that will be called on item pickup - return true to not pickup the item + + mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival @@ -262,30 +270,30 @@ Node Replacement Mobs can look around for specific nodes as they walk and replace them to mimic eating. - 'replace_what' group of items to replace e.g. - {"farming:wheat_8", "farming:carrot_8"} - or you can use the specific options of what, with and - y offset by using this instead: - { - {"group:grass", "air", 0}, - {"default:dirt_with_grass", "default:dirt", -1} - } - 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg" - 'replace_rate' how random should the replace rate be (typically 10) - 'replace_offset' +/- value to check specific node to replace + 'replace_what' group of items to replace e.g. + {"farming:wheat_8", "farming:carrot_8"} + or you can use the specific options of what, with and + y offset by using this instead: + { + {"group:grass", "air", 0}, + {"default:dirt_with_grass", "default:dirt", -1} + } + 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg" + 'replace_rate' how random should the replace rate be (typically 10) + 'replace_offset' +/- value to check specific node to replace - 'on_replace(self, pos, oldnode, newnode)' - is called when mob is about to replace a node. Also called - when not actually replacing due to mobs_griefing setting being false. - 'self' ObjectRef of mob - 'pos' Position of node to replace - 'oldnode' Current node - 'newnode' What the node will become after replacing + 'on_replace(self, pos, oldnode, newnode)' + is called when mob is about to replace a node. Also called + when not actually replacing due to mobs_griefing setting being false. + 'self' ObjectRef of mob + 'pos' Position of node to replace + 'oldnode' Current node + 'newnode' What the node will become after replacing - If false is returned, the mob will not replace the node. + If false is returned, the mob will not replace the node. - By default, replacing sets self.gotten to true and resets the object - properties. + By default, replacing sets self.gotten to true and resets the object + properties. Custom Definition Functions @@ -294,33 +302,33 @@ Custom Definition Functions Along with the above mob registry settings we can also use custom functions to enhance mob functionality and have them do many interesting things: - 'on_die' a function that is called when the mob is killed; the - parameters are (self, pos). Return true to skip the builtin - death animation and death effects - 'on_rightclick' its same as in minetest.register_entity() - 'on_blast' is called when an explosion happens near mob when using TNT - functions, parameters are (object, damage) and returns - (do_damage, do_knockback, drops) - 'on_spawn' is a custom function that runs on mob spawn with 'self' as - variable, return true at end of function to run only once. - 'after_activate' is a custom function that runs once mob has been activated - with these paramaters (self, staticdata, def, dtime) - 'on_breed' called when two similar mobs breed, paramaters are - (parent1, parent2) objects, return false to stop child from - being resized and owner/tamed flags and child textures being - applied. Function itself must spawn new child mob. - 'on_grown' is called when a child mob has grown up, only paramater is - (self). - 'do_punch' called when mob is punched with paramaters (self, hitter, - time_from_last_punch, tool_capabilities, direction), return - false to stop punch damage and knockback from taking place. - 'custom_attack' when set this function is called instead of the normal mob - melee attack, parameters are (self, to_attack). - 'on_die' a function that is called when mob is killed (self, pos) - 'do_custom' a custom function that is called every tick while mob is - active and which has access to all of the self.* variables - e.g. (self.health for health or self.standing_in for node - status), return with 'false' to skip remainder of mob API. + 'on_die' a function that is called when the mob is killed; the + parameters are (self, pos). Return true to skip the builtin + death animation and death effects + 'on_rightclick'its same as in minetest.register_entity() + 'on_blast' is called when an explosion happens near mob when using TNT + functions, parameters are (object, damage) and returns + (do_damage, do_knockback, drops) + 'on_spawn' is a custom function that runs on mob spawn with 'self' as + variable, return true at end of function to run only once. + 'after_activate' is a custom function that runs once mob has been activated + with these paramaters (self, staticdata, def, dtime) + 'on_breed' called when two similar mobs breed, paramaters are + (parent1, parent2) objects, return false to stop child from + being resized and owner/tamed flags and child textures being + applied.Function itself must spawn new child mob. + 'on_grown' is called when a child mob has grown up, only paramater is + (self). + 'do_punch' called when mob is punched with paramaters (self, hitter, + time_from_last_punch, tool_capabilities, direction), return + false to stop punch damage and knockback from taking place. + 'custom_attack'when set this function is called instead of the normal mob + melee attack, parameters are (self, to_attack). + 'on_die' a function that is called when mob is killed (self, pos) + 'do_custom' a custom function that is called every tick while mob is + active and which has access to all of the self.* variables + e.g. (self.health for health or self.standing_in for node + status), return with 'false' to skip remainder of mob API. Internal Variables @@ -329,84 +337,84 @@ Internal Variables The mob api also has some preset variables and functions that it will remember for each mob. - 'self.health' contains current health of mob (cannot exceed - self.hp_max) - 'self.breath' contains current breath of mob, if mob takes drowning - damage at all (cannot exceed self.breath_max). Breath - decreases by 1 each second while in a node with drowning - damage and increases by 1 each second otherwise. - 'self.texture_list' contains list of all mob textures - 'self.child_texture' contains mob child texture when growing up - 'self.base_texture' contains current skin texture which was randomly - selected from textures list - 'self.gotten' this is used to track whether some special item has been - gotten from the mob, for example, wool from sheep. - Initialized as false, and the mob must set this value - manually. - 'self.horny' when animal fed enough it is set to true and animal can - breed with same animal - 'self.hornytimer' background timer that controls breeding functions and - mob childhood timings - 'self.child' used for when breeding animals have child, will use - child_texture and be half size - 'self.owner' string used to set owner of npc mobs, typically used for - dogs - 'self.order' set to "follow" or "stand" so that npc will follow owner - or stand it's ground - 'self.state' Current mob state. - "stand": no movement (except turning around) - "walk": walk or move around aimlessly - "attack": chase and attack enemy - "runaway": flee from target - "flop": bounce around aimlessly - (for swimming mobs that have stranded) - "die": during death - 'self.nametag' contains the name of the mob which it can show above + 'self.health' contains current health of mob (cannot exceed + self.hp_max) + 'self.breath' contains current breath of mob, if mob takes drowning + damage at all (cannot exceed self.breath_max). Breath + decreases by 1 each second while in a node with drowning + damage and increases by 1 each second otherwise. + 'self.texture_list'contains list of all mob textures + 'self.child_texture' contains mob child texture when growing up + 'self.base_texture'contains current skin texture which was randomly + selected from textures list + 'self.gotten' this is used to track whether some special item has been + gotten from the mob, for example, wool from sheep. + Initialized as false, and the mob must set this value + manually. + 'self.horny' when animal fed enough it is set to true and animal can + breed with same animal + 'self.hornytimer' background timer that controls breeding functions and + mob childhood timings + 'self.child' used for when breeding animals have child, will use + child_texture and be half size + 'self.owner' string used to set owner of npc mobs, typically used for + dogs + 'self.order' set to "follow" or "stand" so that npc will follow owner + or stand it's ground + 'self.state' Current mob state. + "stand": no movement (except turning around) + "walk": walk or move around aimlessly + "attack": chase and attack enemy + "runaway": flee from target + "flop": bounce around aimlessly + (for swimming mobs that have stranded) + "die": during death + 'self.nametag' contains the name of the mob which it can show above Spawning Mobs in World ---------------------- mobs:register_spawn(name, nodes, max_light, min_light, chance, - active_object_count, max_height, day_toggle) + active_object_count, max_height, day_toggle) mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, - chance, active_object_count, min_height, max_height, day_toggle, on_spawn) + chance, active_object_count, min_height, max_height, day_toggle, on_spawn) These functions register a spawn algorithm for the mob. Without this function the call the mobs won't spawn. - 'name' is the name of the animal/monster - 'nodes' is a list of nodenames on that the animal/monster can - spawn on top of - 'neighbors' is a list of nodenames on that the animal/monster will - spawn beside (default is {"air"} for - mobs:register_spawn) - 'max_light' is the maximum of light - 'min_light' is the minimum of light - 'interval' is same as in register_abm() (default is 30 for - mobs:register_spawn) - 'chance' is same as in register_abm() - 'active_object_count' number of this type of mob to spawn at one time inside - map area - 'min_height' is the minimum height the mob can spawn - 'max_height' is the maximum height the mob can spawn - 'day_toggle' true for day spawning, false for night or nil for - anytime - 'on_spawn' is a custom function which runs after mob has spawned - and gives self and pos values. + 'name' is the name of the animal/monster + 'nodes' is a list of nodenames on that the animal/monster can + spawn on top of + 'neighbors' is a list of nodenames on that the animal/monster will + spawn beside (default is {"air"} for + mobs:register_spawn) + 'max_light' is the maximum of light + 'min_light' is the minimum of light + 'interval' is same as in register_abm() (default is 30 for + mobs:register_spawn) + 'chance' is same as in register_abm() + 'active_object_count' number of this type of mob to spawn at one time inside + map area + 'min_height' is the minimum height the mob can spawn + 'max_height' is the maximum height the mob can spawn + 'day_toggle' true for day spawning, false for night or nil for + anytime + 'on_spawn' is a custom function which runs after mob has spawned + and gives self and pos values. A simpler way to handle mob spawns has been added with the mobs:spawn(def) command which uses above names to make settings clearer: - mobs:spawn({name = "mobs_monster:tree_monster", - nodes = {"group:leaves"}, - max_light = 7, - }) + mobs:spawn({name = "mobs_monster:tree_monster", + nodes = {"group:leaves"}, + max_light = 7, + }) For each mob that spawns with this function is a field in mobs.spawning_mobs. -It tells if the mob should spawn or not. Default is true. So other mods can +It tells if the mob should spawn or not.Default is true.So other mods can only use the API of this mod by disabling the spawning of the default mobs in this mod. @@ -414,12 +422,12 @@ this mod. mobs:spawn_abm_check(pos, node, name) This global function can be changed to contain additional checks for mobs to -spawn e.g. mobs that spawn only in specific areas and the like. By returning +spawn e.g. mobs that spawn only in specific areas and the like.By returning true the mob will not spawn. - 'pos' holds the position of the spawning mob - 'node' contains the node the mob is spawning on top of - 'name' is the name of the animal/monster + 'pos' holds the position of the spawning mob + 'node' contains the node the mob is spawning on top of + 'name' is the name of the animal/monster MineClone 2 extensions @@ -443,34 +451,34 @@ mobs:register_arrow(name, definition) This function registers a arrow for mobs with the attack type shoot. - 'name' is the name of the arrow - 'definition' is a table with the following values: - 'visual' same is in minetest.register_entity() - 'visual_size' same is in minetest.register_entity() - 'textures' same is in minetest.register_entity() - 'velocity' the velocity of the arrow - 'drop' if set to true any arrows hitting a node will drop as item - 'hit_player' a function that is called when the arrow hits a player; - this function should hurt the player, the parameters are - (self, player) - 'hit_mob' a function that is called when the arrow hits a mob; - this function should hurt the mob, the parameters are - (self, mob) - 'hit_object' a function that is called when the arrow hits an object - that is neither a player nor a mob. this function should - hurt the object, the parameters are (self, object) - 'hit_node' a function that is called when the arrow hits a node, the - parameters are (self, pos, node) - 'tail' when set to 1 adds a trail or tail to mob arrows - 'tail_texture' texture string used for above effect - 'tail_size' has size for above texture (defaults to between 5 and 10) - 'expire' contains float value for how long tail appears for - (defaults to 0.25) - 'glow' has value for how brightly tail glows 1 to 10 (default is - 0 for no glow) - 'rotate' integer value in degrees to rotate arrow - 'on_step' is a custom function when arrow is active, nil for - default. + 'name' is the name of the arrow + 'definition' is a table with the following values: + 'visual' same is in minetest.register_entity() + 'visual_size'same is in minetest.register_entity() + 'textures' same is in minetest.register_entity() + 'velocity' the velocity of the arrow + 'drop' if set to true any arrows hitting a node will drop as item + 'hit_player' a function that is called when the arrow hits a player; + this function should hurt the player, the parameters are + (self, player) + 'hit_mob' a function that is called when the arrow hits a mob; + this function should hurt the mob, the parameters are + (self, mob) + 'hit_object' a function that is called when the arrow hits an object + that is neither a player nor a mob. this function should + hurt the object, the parameters are (self, object) + 'hit_node' a function that is called when the arrow hits a node, the + parameters are (self, pos, node) + 'tail' when set to 1 adds a trail or tail to mob arrows + 'tail_texture' texture string used for above effect + 'tail_size' has size for above texture (defaults to between 5 and 10) + 'expire' contains float value for how long tail appears for + (defaults to 0.25) + 'glow' has value for how brightly tail glows 1 to 10 (default is + 0 for no glow) + 'rotate' integer value in degrees to rotate arrow + 'on_step' is a custom function when arrow is active, nil for + default. Spawn Eggs @@ -480,25 +488,25 @@ mobs:register_egg(name, description, background, addegg, no_creative) This function registers a spawn egg which can be used by admin to properly spawn in a mob. - 'name' this is the name of your new mob to spawn e.g. "mob:sheep" - 'description' the name of the new egg you are creating e.g. "Spawn Sheep" - 'background' the texture displayed for the egg in inventory - 'addegg' would you like an egg image in front of your texture (1 = yes, - 0 = no) - 'no_creative' when set to true this stops spawn egg appearing in creative - mode for destructive mobs like Dungeon Masters. + 'name' this is the name of your new mob to spawn e.g. "mob:sheep" + 'description' the name of the new egg you are creating e.g. "Spawn Sheep" + 'background'the texture displayed for the egg in inventory + 'addegg' would you like an egg image in front of your texture (1 = yes, + 0 = no) + 'no_creative' when set to true this stops spawn egg appearing in creative + mode for destructive mobs like Dungeon Masters. Explosion Function ------------------ mobs:boom(self, pos, radius) - 'self' mob entity - 'pos' centre position of explosion - 'radius' radius of explosion (typically set to 3) + 'self' mob entity + 'pos' centre position of explosion + 'radius' radius of explosion (typically set to 3) This function generates an explosion which removes nodes in a specific radius -and damages any entity caught inside the blast radius. Protection will limit +and damages any entity caught inside the blast radius.Protection will limit node destruction but not entity damage. @@ -526,13 +534,13 @@ This function allows the mob to be fed the item inside self.follow be it apple, wheat or whatever a set number of times and be tamed or bred as a result. Will return true when mob is fed with item it likes. - 'self' mob information - 'clicker' player information - 'feed_count' number of times mob must be fed to tame or breed - 'breed' true or false stating if mob can be bred and a child created - afterwards - 'tame' true or false stating if mob can be tamed so player can pick - them up + 'self' mob information + 'clicker' player information + 'feed_count' number of times mob must be fed to tame or breed + 'breed' true or false stating if mob can be bred and a child created + afterwards + 'tame' true or false stating if mob can be tamed so player can pick + them up Protecting Mobs @@ -542,10 +550,10 @@ mobs:protect(self, clicker) This function can be used to right-click any tamed mob with mobs:protector item, this will protect the mob from harm inside of a protected area from other -players. Will return true when mob right-clicked with mobs:protector item. +players.Will return true when mob right-clicked with mobs:protector item. - 'self' mob information - 'clicker' player information + 'self' mob information + 'clicker' player information Riding Mobs @@ -559,8 +567,8 @@ mobs:attach(self, player) This function attaches a player to the mob so it can be ridden. - 'self' mob information - 'player' player information + 'self' mob information + 'player' player information mobs:detach(player, offset) @@ -568,8 +576,8 @@ mobs:detach(player, offset) This function will detach the player currently riding a mob to an offset position. - 'player' player information - 'offset' position table containing offset values + 'player' player information + 'offset' position table containing offset values mobs:drive(self, move_animation, stand_animation, can_fly, dtime) @@ -577,12 +585,12 @@ mobs:drive(self, move_animation, stand_animation, can_fly, dtime) This function allows an attached player to move the mob around and animate it at same time. - 'self' mob information - 'move_animation' string containing movement animation e.g. "walk" - 'stand_animation' string containing standing animation e.g. "stand" - 'can_fly' if true then jump and sneak controls will allow mob to fly - up and down - 'dtime' tick time used inside drive function + 'self' mob information + 'move_animation'string containing movement animation e.g. "walk" + 'stand_animation' string containing standing animation e.g. "stand" + 'can_fly' if true then jump and sneak controls will allow mob to fly + up and down + 'dtime' tick time used inside drive function mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation) @@ -590,16 +598,16 @@ mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_anim This function allows an attached player to fly the mob around using directional controls. - 'self' mob information - 'dtime' tick time used inside fly function - 'speed' speed of flight - 'can_shoot' true if mob can fire arrow (sneak and left mouse button - fires) - 'arrow_entity' name of arrow entity used for firing - 'move_animation' string containing name of pre-defined animation e.g. "walk" - or "fly" etc. - 'stand_animation' string containing name of pre-defined animation e.g. - "stand" or "blink" etc. + 'self' mob information + 'dtime' tick time used inside fly function + 'speed' speed of flight + 'can_shoot' true if mob can fire arrow (sneak and left mouse button + fires) + 'arrow_entity' name of arrow entity used for firing + 'move_animation'string containing name of pre-defined animation e.g. "walk" + or "fly" etc. + 'stand_animation' string containing name of pre-defined animation e.g. + "stand" or "blink" etc. Note: animation names above are from the pre-defined animation lists inside mob registry without extensions. @@ -610,46 +618,46 @@ mobs:set_animation(self, name) This function sets the current animation for mob, defaulting to "stand" if not found. - 'self' mob information - 'name' name of animation + 'self' mob information + 'name' name of animation Certain variables need to be set before using the above functions: - 'self.v2' toggle switch used to define below values for the - first time - 'self.max_speed_forward' max speed mob can move forward - 'self.max_speed_reverse' max speed mob can move backwards - 'self.accel' acceleration speed - 'self.terrain_type' integer containing terrain mob can walk on - (1 = water, 2 or 3 = land) - 'self.driver_attach_at' position offset for attaching player to mob - 'self.driver_eye_offset' position offset for attached player view - 'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1} + 'self.v2' toggle switch used to define below values for the + first time + 'self.max_speed_forward' max speed mob can move forward + 'self.max_speed_reverse' max speed mob can move backwards + 'self.accel' acceleration speed + 'self.terrain_type' integer containing terrain mob can walk on + (1 = water, 2 or 3 = land) + 'self.driver_attach_at'position offset for attaching player to mob + 'self.driver_eye_offset' position offset for attached player view + 'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1} External Settings for "minetest.conf" ------------------------------------ - 'enable_damage' if true monsters will attack players (default is true) - 'only_peaceful_mobs' if true only animals will spawn in game (default is - false) - 'mobs_disable_blood' if false, damage effects appear when mob is hit (default - is false) - 'mobs_spawn_protected' if set to false then mobs will not spawn in protected - areas (default is true) - 'mob_difficulty' sets difficulty level (health and hit damage - multiplied by this number), defaults to 1.0. - 'mob_spawn_chance' multiplies chance of all mobs spawning and can be set - to 0.5 to have mobs spawn more or 2.0 to spawn less. - e.g. 1 in 7000 * 0.5 = 1 in 3500 so better odds of - spawning. - 'mobs_spawn' if false then mobs no longer spawn without spawner or - spawn egg. - 'mobs_drop_items' when false mobs no longer drop items when they die. - 'mobs_griefing' when false mobs cannot break blocks when using either - pathfinding level 2, replace functions or mobs:boom - function. + 'enable_damage' if true monsters will attack players (default is true) + 'only_peaceful_mobs' if true only animals will spawn in game (default is + false) + 'mobs_disable_blood' if false, damage effects appear when mob is hit (default + is false) + 'mobs_spawn_protected' if set to false then mobs will not spawn in protected + areas (default is true) + 'mob_difficulty' sets difficulty level (health and hit damage + multiplied by this number), defaults to 1.0. + 'mob_spawn_chance' multiplies chance of all mobs spawning and can be set + to 0.5 to have mobs spawn more or 2.0 to spawn less. + e.g.1 in 7000 * 0.5 = 1 in 3500 so better odds of + spawning. + 'mobs_spawn' if false then mobs no longer spawn without spawner or + spawn egg. + 'mobs_drop_items' when false mobs no longer drop items when they die. + 'mobs_griefing' when false mobs cannot break blocks when using either + pathfinding level 2, replace functions or mobs:boom + function. Players can override the spawn chance for each mob registered by adding a line to their minetest.conf file with a new value, the lower the value the more each diff --git a/mods/ENTITIES/mobs_mc/0_gameconfig.lua b/mods/ENTITIES/mobs_mc/0_gameconfig.lua index 17451aeb66..c36b884755 100644 --- a/mods/ENTITIES/mobs_mc/0_gameconfig.lua +++ b/mods/ENTITIES/mobs_mc/0_gameconfig.lua @@ -169,7 +169,7 @@ mobs_mc.follow = { dog = { mobs_mc.items.rabbit_raw, mobs_mc.items.rabbit_cooked, mobs_mc.items.mutton_raw, mobs_mc.items.mutton_cooked, mobs_mc.items.beef_raw, mobs_mc.items.beef_cooked, mobs_mc.items.chicken_raw, mobs_mc.items.chicken_cooked, mobs_mc.items.rotten_flesh, -- Mobs Redo items "mobs:meat", "mobs:meat_raw" }, - villager = { "mcl_farming:bread" }, + villager = { "mcl_farming:bread", "mcl_farming:carrot_item", "mcl_farming:beetroot_item" , "mcl_farming:potato_item" }, } -- Contents for replace_what diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 0d3e74645f..51c69ac5e5 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -9,7 +9,7 @@ local S = minetest.get_translator("mobs_mc") --################### IRON GOLEM --################### - +local etime = 0 mobs:register_mob("mobs_mc:iron_golem", { description = S("Iron Golem"), @@ -41,6 +41,26 @@ mobs:register_mob("mobs_mc:iron_golem", { group_attack = true, attacks_monsters = true, attack_type = "dogfight", + _got_poppy = false, + pick_up = {"mcl_flowers:poppy"}, + on_pick_up = function(self,n) + if n.itemstring:find("mcl_flowers:poppy") then + if not self._got_poppy then + self._got_poppy=true + return + end + return true + end + end, + replace_what = {"mcl_flowers:poppy"}, + replace_with = {"air"}, + on_replace = function(self, pos, oldnode, newnode) + if not self.got_poppy and oldnode.name == "mcl_flowers:poppy" then + self._got_poppy=true + return + end + return false + end, drops = { {name = mobs_mc.items.iron_ingot, chance = 1, @@ -60,6 +80,14 @@ mobs:register_mob("mobs_mc:iron_golem", { punch_start = 40, punch_end = 50, }, jump = true, + on_step = function(self,dtime) + etime = etime + dtime + if etime > 10 then + if self._home and vector.distance(self._home,self.object:get_pos()) > 50 then + mobs:gopath(self,self._home) + end + end + end, }) diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_armorer.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_armorer.png new file mode 100644 index 0000000000..6d0eb39b16 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_armorer.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_butcher.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_butcher.png index e8529c4596..025600ff2f 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_butcher.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_butcher.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_cartographer.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_cartographer.png new file mode 100644 index 0000000000..7ab66072eb Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_cartographer.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_farmer.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_farmer.png index 62c98bcdaa..851f3a59d1 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_farmer.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_farmer.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fisherman.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fisherman.png new file mode 100644 index 0000000000..c394f2e6e4 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fisherman.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fletcher.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fletcher.png new file mode 100644 index 0000000000..d9875ec10c Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_fletcher.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_leatherworker.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_leatherworker.png new file mode 100644 index 0000000000..ea491713eb Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_leatherworker.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_librarian.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_librarian.png index 66b5c29290..f4a90d6fbe 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_librarian.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_librarian.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_nitwit.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_nitwit.png new file mode 100644 index 0000000000..8009f03261 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_nitwit.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_priest.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_priest.png index 79682c2c89..38318d4a93 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_priest.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_priest.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_sheperd.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_sheperd.png new file mode 100644 index 0000000000..db32269697 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_sheperd.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_smith.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_smith.png index 53a0e3888b..8afdc6b29f 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_smith.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_smith.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_toolsmith.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_toolsmith.png new file mode 100644 index 0000000000..538a64b992 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_toolsmith.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_weaponsmith.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_weaponsmith.png new file mode 100644 index 0000000000..07157a553f Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_villager_weaponsmith.png differ diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index c7049919e5..669ef5cf5e 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -10,14 +10,10 @@ -- TODO: Particles -- TODO: 4s Regeneration I after trade unlock --- TODO: Breeding --- TODO: Baby villagers --- TODO: Spawning in villages -- TODO: Behaviour: --- TODO: Walk around village, but do not leave it intentionally --- TODO: Run into house on rain or danger, open doors --- TODO: Internal inventory, pick up items, trade with other villagers --- TODO: Farm stuff +-- TODO: Run into house on rain or danger, open doors +-- TODO: Internal inventory, trade with other villagers +-- TODO: Schedule stuff (work,sleep,father) local S = minetest.get_translator("mobs_mc") local N = function(s) return s end @@ -61,15 +57,37 @@ if minetest.get_mapgen_setting("mg_name") == "v6" then TRADE_V6_BIRCH_SAPLING = { { "mcl_core:emerald", 8, 11 }, { "mcl_core:birchsapling", 1, 1 } } end +local tiernames = { + "Novice", + "Apprentice", + "Journeyman", + "Expert", + "Master", +} + +local badges = { + "default_wood.png", + "default_steel_block.png", + "default_gold_block.png", + "mcl_core_emerald_block.png", + "default_diamond_block.png", +} + local professions = { unemployed = { name = N("Unemployed"), - texture = "mobs_mc_villager.png", + textures = { + "mobs_mc_villager.png", + "mobs_mc_villager.png", + }, trades = nil, }, farmer = { name = N("Farmer"), - texture = "mobs_mc_villager_farmer.png", + textures = { + "mobs_mc_villager_farmer.png", + "mobs_mc_villager_farmer.png", + }, jobsite = "mcl_composters:composter", trades = { { @@ -103,7 +121,10 @@ local professions = { }, fisherman = { name = N("Fisherman"), - texture = "mobs_mc_villager_farmer.png", + textures = { + "mobs_mc_villager_fisherman.png", + "mobs_mc_villager_fisherman.png", + }, jobsite = "mcl_barrels:barrel_closed", trades = { { @@ -138,7 +159,10 @@ local professions = { }, fletcher = { name = N("Fletcher"), - texture = "mobs_mc_villager_farmer.png", + textures = { + "mobs_mc_villager_fletcher.png", + "mobs_mc_villager_fletcher.png", + }, jobsite = "mcl_fletching_table:fletching_table", trades = { { @@ -177,7 +201,10 @@ local professions = { }, shepherd ={ name = N("Shepherd"), - texture = "mobs_mc_villager_farmer.png", + textures = { + "mobs_mc_villager_sheperd.png", + "mobs_mc_villager_sheperd.png", + }, jobsite = "mcl_loom:loom", trades = { { @@ -207,8 +234,11 @@ local professions = { }, librarian = { name = N("Librarian"), - texture = "mobs_mc_villager_librarian.png", - jobsite = "mcl_villages:stonebrickcarved", --FIXME: lectern + textures = { + "mobs_mc_villager_librarian.png", + "mobs_mc_villager_librarian.png", + }, + jobsite = "mcl_books:bookshelf", --FIXME: lectern trades = { { { { "mcl_core:paper", 24, 36 }, E1 }, @@ -242,7 +272,10 @@ local professions = { }, cartographer = { name = N("Cartographer"), - texture = "mobs_mc_villager_librarian.png", + textures = { + "mobs_mc_villager_cartographer.png", + "mobs_mc_villager_cartographer.png", + }, jobsite = "mcl_cartography_table:cartography_table", trades = { { @@ -285,7 +318,10 @@ local professions = { }, armorer = { name = N("Armorer"), - texture = "mobs_mc_villager_smith.png", + textures = { + "mobs_mc_villager_armorer.png", + "mobs_mc_villager_armorer.png", + }, jobsite = "mcl_blast_furnace:blast_furnace", trades = { { @@ -298,7 +334,7 @@ local professions = { { { { "mcl_core:iron_ingot", 4, 4 }, E1 }, - --{ { "mcl_core:emerald", 36, 36 }, { "FIXME: Bell", 1, 1 } }, + { { "mcl_core:emerald", 36, 36 }, { "mcl_bells:bell", 1, 1 } }, { { "mcl_core:emerald", 3, 3 }, { "mcl_armor:leggings_chain", 1, 1 } }, { { "mcl_core:emerald", 1, 1 }, { "mcl_armor:boots_chain", 1, 1 } }, }, @@ -322,7 +358,10 @@ local professions = { }, leatherworker = { name = N("Leatherworker"), - texture = "mobs_mc_villager_butcher.png", + textures = { + "mobs_mc_villager_leatherworker.png", + "mobs_mc_villager_leatherworker.png", + }, jobsite = "mcl_cauldrons:cauldron", trades = { { @@ -351,7 +390,10 @@ local professions = { }, butcher = { name = N("Butcher"), - texture = "mobs_mc_villager_butcher.png", + textures = { + "mobs_mc_villager_butcher.png", + "mobs_mc_villager_butcher.png", + }, jobsite = "mcl_smoker:smoker", trades = { { @@ -381,8 +423,11 @@ local professions = { }, weapon_smith = { name = N("Weapon Smith"), - texture = "mobs_mc_villager_smith.png", - jobsite = "mcl_villages:stonebrickcarved", --FIXME: grindstone + textures = { + "mobs_mc_villager_weaponsmith.png", + "mobs_mc_villager_weaponsmith.png", + }, + jobsite = "mcl_furnaces:furnace", --FIXME: grindstone trades = { { { { "mcl_core:coal_lump", 15, 15 }, E1 }, @@ -392,7 +437,7 @@ local professions = { { { { "mcl_core:iron_ingot", 4, 4 }, E1 }, - --{ { "mcl_core:emerald", 36, 36 }, { "FIXME: Bell", 1, 1 } }, + { { "mcl_core:emerald", 36, 36 }, { "mcl_bells:bell", 1, 1 } }, }, { { { "mcl_core:flint", 7, 9 }, E1 }, @@ -409,8 +454,11 @@ local professions = { }, tool_smith = { name = N("Tool Smith"), - texture = "mobs_mc_villager_smith.png", - jobsite = "mcl_villages:stonebrickcarved", --FIXME: smithing table + textures = { + "mobs_mc_villager_toolsmith.png", + "mobs_mc_villager_toolsmith.png", + }, + jobsite = "mcl_anvils:anvil", --FIXME: smithing table trades = { { { { "mcl_core:coal_lump", 15, 15 }, E1 }, @@ -422,7 +470,7 @@ local professions = { { { { "mcl_core:iron_ingot", 4, 4 }, E1 }, - --{ { "mcl_core:emerald", 36, 36 }, { "FIXME: Bell", 1, 1 } }, + { { "mcl_core:emerald", 36, 36 }, { "mcl_bells:bell", 1, 1 } }, }, { { { "mcl_core:flint", 30, 30 }, E1 }, @@ -443,8 +491,11 @@ local professions = { }, cleric = { name = N("Cleric"), - texture = "mobs_mc_villager_priest.png", - jobsite = "mcl_brewing:stand", + textures = { + "mobs_mc_villager_priest.png", + "mobs_mc_villager_priest.png", + }, + jobsite = "mcl_brewing:stand_000", trades = { { { { "mcl_mobitems:rotten_flesh", 32, 32 }, E1 }, @@ -472,7 +523,10 @@ local professions = { }, nitwit = { name = N("Nitwit"), - texture = "mobs_mc_villager.png", + textures = { + "mobs_mc_villager_nitwit.png", + "mobs_mc_villager_nitwit.png", + }, -- No trades for nitwit trades = nil, } @@ -483,48 +537,106 @@ for id, _ in pairs(professions) do table.insert(profession_names, id) end -local stand_still = function(self) +local jobsites={} +for _,n in pairs(profession_names) do + table.insert(jobsites,professions[n].jobsite) +end + +local function stand_still(self) self.walk_chance = 0 self.jump = false end -local function set_velocity(self, v) - local yaw = (self.object:get_yaw() or 0) + self.rotate - self.object:set_velocity({ - x = (math.sin(yaw) * -v), - y = self.object:get_velocity().y, - z = (math.cos(yaw) * v), - }) +local function init_trader_vars(self) + if not self._max_trade_tier then + self._max_trade_tier = 1 + end + if not self._locked_trades then + self._locked_trades = 0 + end + if not self._trading_players then + self._trading_players = {} + end end -local function go_to_pos(entity,b) - local s=entity.object:get_pos() - local v = { x = b.x - s.x, z = b.z - s.z } - local yaw = (math.atan(v.z / v.x) + math.pi / 2) - entity.rotate - if b.x > s.x then yaw = yaw + math.pi end - entity.object:set_yaw(yaw) - set_velocity(entity,entity.follow_velocity) - if vector.distance(b,s) < 5 then - return true - end +local function get_badge_textures(self) + local t = professions[self._profession].textures + if self._profession == "unemployed" or self._profession == "nitwit" then return t end + local tier = self._max_trade_tier or 1 + return { + "[combine:64x64:0,0="..t[1]..":11,55=".. badges[tier].."\\^[resize\\:2x2", + t[2] + } +end + +local function set_textures(self) + self.object:set_properties({textures=get_badge_textures(self)}) end local function go_home(entity) entity.state = "go_home" - local b=entity.bed + local b=entity._bed if not b then return end - if go_to_pos(entity,b) then - entity.state = "stand" - set_velocity(entity,0) - entity.object:set_pos(b) - local n=minetest.get_node(b) - if n and n.name ~= "mcl_beds:bed_red_bottom" then - entity.bed=nil --the stormtroopers have killed uncle owen + mobs:gopath(entity,b,function(entity,b) + if vector.distance(entity.object:get_pos(),b) < 2 then + entity.state = "stand" + set_velocity(entity,0) + entity.object:set_pos(b) + local n=minetest.get_node(b) + if n and n.name ~= "mcl_beds:bed_red_bottom" then + entity._bed=nil --the stormtroopers have killed uncle owen + return false + end + return true end - end + end) end -local update_max_tradenum = function(self) +----- JOBSITE LOGIC +local function get_profession_by_jobsite(js) + for k,v in pairs(professions) do + if v.jobsite == js then return k end + end +end + +local function employ(self,jobsite_pos) + local n = minetest.get_node(jobsite_pos) + local m = minetest.get_meta(jobsite_pos) + local p = get_profession_by_jobsite(n.name) + if p and m:get_string("villager") == "" then + self._profession=p + m:set_string("villager",self._id) + self._jobsite = jobsite_pos + set_textures(self) + return true + end +end + +local function look_for_job(self) + local p = self.object:get_pos() + local nn = minetest.find_nodes_in_area(vector.offset(p,-48,-48,-48),vector.offset(p,48,48,48),jobsites) + for _,n in pairs(nn) do + local m=minetest.get_meta(n) + if m:get_string("villager") == "" then + --minetest.log("goingt to jobsite "..minetest.pos_to_string(n) ) + local gp = mobs:gopath(self,n,function() + --minetest.log("arrived jobsite "..minetest.pos_to_string(n) ) + end) + if gp then return end + end + end +end + +local function get_a_job(self) + local p = self.object:get_pos() + local nn = minetest.find_nodes_in_area(vector.offset(p,-8,-8,-8),vector.offset(p,8,8,8),jobsites) + for _,n in pairs(nn) do + if n and employ(self,n) then return true end + end + if self.state ~= "gowp" then look_for_job(self) end +end + +local function update_max_tradenum(self) if not self._trades then return end @@ -539,31 +651,7 @@ local update_max_tradenum = function(self) self._max_tradenum = #trades end -local init_trader_vars = function(self) - if not self._profession then - -- Select random profession from all professions with matching clothing - local texture = self.base_texture[1] - local matches = {} - for prof_id, prof in pairs(professions) do - if texture == prof.texture then - table.insert(matches, prof_id) - end - end - local p = math.random(1, #matches) - self._profession = matches[p] - end - if not self._max_trade_tier then - self._max_trade_tier = 1 - end - if not self._locked_trades then - self._locked_trades = 0 - end - if not self._trading_players then - self._trading_players = {} - end -end - -local init_trades = function(self, inv) +local function init_trades(self, inv) local profession = professions[self._profession] local trade_tiers = profession.trades if trade_tiers == nil then @@ -614,7 +702,7 @@ local init_trades = function(self, inv) minetest.deserialize(self._trades) end -local set_trade = function(trader, player, inv, concrete_tradenum) +local function set_trade(trader, player, inv, concrete_tradenum) local trades = minetest.deserialize(trader._trades) if not trades then init_trades(trader) @@ -688,12 +776,17 @@ local function show_trade_formspec(playername, trader, tradenum) w2_formspec = "item_image[3,1;1,1;"..wanted2:to_string().."]" .."tooltip[3,1;0.8,0.8;"..F(wanted2:get_description()).."]" end - + local tiername = tiernames[trader._max_trade_tier] + if tiername then + tiername = S(tiername) + else + tiername = S("Master") + end local formspec = "size[9,8.75]" .."background[-0.19,-0.25;9.41,9.49;mobs_mc_trading_formspec_bg.png]" ..disabled_img - .."label[4,0;"..F(minetest.colorize("#313131", S(profession))).."]" +.."label[3,0;"..F(minetest.colorize("#313131", S(profession).." - "..tiername)) .."]" .."list[current_player;main;0,4.5;9,3;9]" .."list[current_player;main;0,7.74;9,1;]" ..b_prev..b_next @@ -713,7 +806,7 @@ local function show_trade_formspec(playername, trader, tradenum) minetest.show_formspec(playername, tradeinv_name, formspec) end -local update_offer = function(inv, player, sound) +local function update_offer(inv, player, sound) local name = player:get_player_name() local trader = player_trading_with[name] local tradenum = player_tradenum[name] @@ -737,12 +830,12 @@ local update_offer = function(inv, player, sound) -- compass. -- TODO: Remove these check functions when compass and clock are implemented -- as single items. - local check_special = function(special_item, group, wanted1, wanted2, input1, input2) + local function check_special(special_item, group, wanted1, wanted2, input1, input2) if minetest.registered_aliases[special_item] then special_item = minetest.registered_aliases[special_item] end if wanted1:get_name() == special_item then - local check_input = function(input, wanted, group) + local function check_input(input, wanted, group) return minetest.get_item_group(input:get_name(), group) ~= 0 and input:get_count() >= wanted:get_count() end if check_input(input1, wanted1, group) then @@ -757,7 +850,7 @@ local update_offer = function(inv, player, sound) end -- Apply above function to all items which we consider special. -- This function succeeds if ANY item check succeeds. - local check_specials = function(wanted1, wanted2, input1, input2) + local function check_specials(wanted1, wanted2, input1, input2) return check_special(COMPASS, "compass", wanted1, wanted2, input1, input2) end -- END OF SPECIAL HANDLING OF COMPASS @@ -811,7 +904,7 @@ local function return_item(itemstack, dropper, pos, inv_p) return itemstack end -local return_fields = function(player) +local function return_fields(player) local name = player:get_player_name() local inv_t = minetest.get_inventory({type="detached", name = "mobs_mc:trade_"..name}) local inv_p = player:get_inventory() @@ -877,7 +970,7 @@ minetest.register_on_leaveplayer(function(player) end) -- Return true if player is trading with villager, and the villager entity exists -local trader_exists = function(playername) +local function trader_exists(playername) local trader = player_trading_with[playername] return trader ~= nil and trader.object:get_luaentity() ~= nil end @@ -904,7 +997,7 @@ local trade_inventory = { wanted1:set_count(wanted1:get_count()*2) wanted2:set_count(wanted2:get_count()*2) -- BEGIN OF SPECIAL HANDLING FOR COMPASS - local special_checks = function(wanted1, input1, input2) + local function special_checks(wanted1, input1, input2) if wanted1:get_name() == COMPASS then local compasses = 0 if (minetest.get_item_group(input1:get_name(), "compass") ~= 0) then @@ -1021,6 +1114,10 @@ local trade_inventory = { -- First-time trade unlock all trades and unlock next trade tier if trade.tier + 1 > trader._max_trade_tier then trader._max_trade_tier = trader._max_trade_tier + 1 + if trader._max_trade_tier > 5 then + trader._max_trade_tier = 5 + end + set_textures(trader) update_max_tradenum(trader) update_formspec = true end @@ -1113,31 +1210,9 @@ mobs:register_mob("mobs_mc:villager", { visual = "mesh", mesh = "mobs_mc_villager.b3d", textures = { - { "mobs_mc_villager.png", "mobs_mc_villager.png", --hat }, - { - "mobs_mc_villager_farmer.png", - "mobs_mc_villager_farmer.png", --hat - }, - { - "mobs_mc_villager_priest.png", - "mobs_mc_villager_priest.png", --hat - }, - { - "mobs_mc_villager_librarian.png", - "mobs_mc_villager_librarian.png", --hat - }, - { - "mobs_mc_villager_butcher.png", - "mobs_mc_villager_butcher.png", --hat - }, - { - "mobs_mc_villager_smith.png", - "mobs_mc_villager_smith.png", --hat - }, - }, visual_size = {x=2.75, y=2.75}, makes_footstep_sound = true, walk_velocity = 1.2, @@ -1165,23 +1240,45 @@ mobs:register_mob("mobs_mc:villager", { die_loop = false, }, follow = mobs_mc.follow.villager, + nofollow = true, view_range = 16, fear_height = 4, jump = true, walk_chance = DEFAULT_WALK_CHANCE, - on_rightclick = function(self, clicker) - if clicker:get_wielded_item():get_name() == "mcl_farming:bread" then - if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end + _bed = nil, + _id = nil, + _profession = "unemployed", + look_at_player = true, + pick_up = mobs_mc.follow.villager, + can_open_doors = true, + on_pick_up = function(self,itementity) + local clicker + for _,p in pairs(minetest.get_connected_players()) do + if vector.distance(p:get_pos(),self.object:get_pos()) < 10 then + clicker = p + end end - if self.child then + if clicker then + mobs:feed_tame(self, clicker, 1, true, false) + return + end + return true --do not pick up + end, + on_rightclick = function(self, clicker) + local trg=vector.new(0,9,0) + if self._jobsite then + mobs:gopath(self,self._jobsite,function() + --minetest.log("arrived at jobsite") + end) + end + if self.child or self._profession == "unemployed" then return end -- Initiate trading + init_trader_vars(self) local name = clicker:get_player_name() self._trading_players[name] = true - init_trader_vars(self) if self._trades == nil then init_trades(self) end @@ -1219,10 +1316,6 @@ mobs:register_mob("mobs_mc:villager", { self._player_scan_timer = 0 end - if self.bed and ( self.state == "go_home" or vector.distance(self.object:get_pos(),self.bed) > 50 ) then - go_home(self) - end - self._player_scan_timer = self._player_scan_timer + dtime -- Check infrequently to keep CPU load low if self._player_scan_timer > PLAYER_SCAN_INTERVAL then @@ -1244,20 +1337,37 @@ mobs:register_mob("mobs_mc:villager", { self.walk_chance = DEFAULT_WALK_CHANCE self.jump = true end + if self._bed and ( self.state ~= "go_home" and vector.distance(self.object:get_pos(),self._bed) > 50 ) then + go_home(self) + end + if self._profession == "unemployed" then + get_a_job(self) + end end end, on_spawn = function(self) - init_trader_vars(self) + if self._id then + set_textures(self) + return + end + self._id=minetest.sha1(minetest.get_gametime()..minetest.pos_to_string(self.object:get_pos())..tostring(math.random())) + self._profession = "unemployed" + if math.random(100) == 1 then + self._profession = "nitwit" + end + set_textures(self) end, on_die = function(self, pos) -- Close open trade formspecs and give input back to players local trading_players = self._trading_players - for name, _ in pairs(trading_players) do - minetest.close_formspec(name, "mobs_mc:trade_"..name) - local player = minetest.get_player_by_name(name) - if player then - return_fields(player) + if trading_players then + for name, _ in pairs(trading_players) do + minetest.close_formspec(name, "mobs_mc:trade_"..name) + local player = minetest.get_player_by_name(name) + if player then + return_fields(player) + end end end end, diff --git a/mods/ITEMS/mcl_bells/init.lua b/mods/ITEMS/mcl_bells/init.lua index d4bbe6325b..e2f4fe6674 100644 --- a/mods/ITEMS/mcl_bells/init.lua +++ b/mods/ITEMS/mcl_bells/init.lua @@ -5,7 +5,13 @@ mcl_bells = {} local has_mcl_wip = minetest.get_modpath("mcl_wip") function mcl_bells.ring_once(pos) - minetest.sound_play( "mcl_bells_bell_stroke", { pos = pos, gain = 1.5, max_hear_distance = 300,}); + minetest.sound_play( "mcl_bells_bell_stroke", { pos = pos, gain = 1.5, max_hear_distance = 150,}) + local vv=minetest.get_objects_inside_radius(pos,150) + for _,o in pairs(vv) do + if o.type == "npc" then + mobs:gopath(o:get_luaentity(),pos,function() end) + end + end end minetest.register_node("mcl_bells:bell", { diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index c014bb07af..9038769fde 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -188,11 +188,41 @@ local function construct_node(p1, p2, name) end minetest.log("warning", "[mcl_villages] Attempt to 'construct' inexistant nodes: " .. name) end + +local function spawn_iron_golem(pos) + local p = minetest.find_node_near(pos,50,"mcl_core:grass_path") + if p then + local l=minetest.add_entity(p,"mobs_mc:iron_golem"):get_luaentity() + if l then + l._home = p + end + end +end + +local function spawn_villagers(minp,maxp) + local beds=minetest.find_nodes_in_area(vector.offset(minp,-20,-20,-20),vector.offset(maxp,20,20,20),{"mcl_beds:bed_red_bottom"}) + for _,bed in pairs(beds) do + local m = minetest.get_meta(bed) + if m:get_string("villager") == "" then + local v=minetest.add_entity(bed,"mobs_mc:villager") + if v then + local l=v:get_luaentity() + l._bed = bed + m:set_string("villager",l._id) + end + end + end +end + local function init_nodes(p1, p2, size, rotation, pr) construct_node(p1, p2, "mcl_itemframes:item_frame") construct_node(p1, p2, "mcl_furnaces:furnace") construct_node(p1, p2, "mcl_anvils:anvil") + construct_node(p1, p2, "mcl_smoker:smoker") + construct_node(p1, p2, "mcl_barrels:barrel_closed") + construct_node(p1, p2, "mcl_blast_furnace:blast_furnace") + construct_node(p1, p2, "mcl_brewing:stand_000") local nodes = construct_node(p1, p2, "mcl_chests:chest") if nodes and #nodes > 0 then for p=1, #nodes do @@ -201,9 +231,30 @@ local function init_nodes(p1, p2, size, rotation, pr) end end end + function settlements.place_schematics(settlement_info, pr) local building_all_info + + --attempt to place one belltower in the center of the village - this doesn't always work out great but it's a lot better than doing it first or last. + local belltower = table.remove(settlement_info,math.floor(#settlement_info/2)) + if belltower then + mcl_structures.place_schematic( + vector.offset(belltower["pos"],0,0,0), + settlements.modpath.."/schematics/belltower.mts", + belltower["rotation"], + nil, + true, + nil, + function(p1, p2, size, rotation, pr) + spawn_iron_golem(p1) + end, + pr + ) + end + for i, built_house in ipairs(settlement_info) do + local is_last = i == #settlement_info + for j, schem in ipairs(settlements.schematic_table) do if settlement_info[i]["name"] == schem["name"] then building_all_info = schem @@ -271,7 +322,10 @@ function settlements.place_schematics(settlement_info, pr) nil, true, nil, - init_nodes, + function(p1, p2, size, rotation, pr) + init_nodes(p1, p2, size, rotation, pr) + spawn_villagers(p1,p2) + end, pr ) end diff --git a/mods/MAPGEN/mcl_villages/init.lua b/mods/MAPGEN/mcl_villages/init.lua index 3eed2cbbb3..9eb9bfba8b 100644 --- a/mods/MAPGEN/mcl_villages/init.lua +++ b/mods/MAPGEN/mcl_villages/init.lua @@ -21,7 +21,6 @@ minetest.register_node("mcl_villages:stonebrickcarved", { description = ("Chiseled Stone Village Bricks"), _doc_items_longdesc = doc.sub.items.temp.build, tiles = {"mcl_core_stonebrick_carved.png"}, - stack_max = 64, drop = "mcl_core:stonebrickcarved", groups = {pickaxey=1, stone=1, stonebrick=1, building_block=1, material_stone=1}, sounds = mcl_sounds.node_sound_stone_defaults(), @@ -50,17 +49,6 @@ if minetest.get_modpath("mobs_mc") then end --]] -local function spawn_villagers(minp,maxp) - local beds=minetest.find_nodes_in_area(minp,maxp,{"mcl_beds:bed_red_bottom"}) - for _,bed in pairs(beds) do - minetest.get_meta(bed):set_string("villagebed","true") - local v=minetest.add_entity(bed,"mobs_mc:villager") - if v then - v:get_luaentity().bed = bed - end - end -end - -- -- on map generation, try to build a settlement -- @@ -79,10 +67,6 @@ local function build_a_settlement(minp, maxp, blockseed) -- evaluate settlement_info and place schematics settlements.place_schematics(settlement_info, pr) - - minetest.after(60,function() - spawn_villagers(minp,maxp) - end) --give the village some time to fully generate end local function ecb_village(blockpos, action, calls_remaining, param) diff --git a/mods/MAPGEN/mcl_villages/schematics/belltower.mts b/mods/MAPGEN/mcl_villages/schematics/belltower.mts new file mode 100644 index 0000000000..8eb524312c Binary files /dev/null and b/mods/MAPGEN/mcl_villages/schematics/belltower.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/blacksmith.mts b/mods/MAPGEN/mcl_villages/schematics/blacksmith.mts index d7fb66593d..dab65afa47 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/blacksmith.mts and b/mods/MAPGEN/mcl_villages/schematics/blacksmith.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/butcher.mts b/mods/MAPGEN/mcl_villages/schematics/butcher.mts index 251033b1ec..1786599dcc 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/butcher.mts and b/mods/MAPGEN/mcl_villages/schematics/butcher.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/church.mts b/mods/MAPGEN/mcl_villages/schematics/church.mts index dbf022cb46..e59f90f1f8 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/church.mts and b/mods/MAPGEN/mcl_villages/schematics/church.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/farm.mts b/mods/MAPGEN/mcl_villages/schematics/farm.mts index 9094c8681f..b45ff1d6f3 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/farm.mts and b/mods/MAPGEN/mcl_villages/schematics/farm.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/lamp.mts b/mods/MAPGEN/mcl_villages/schematics/lamp.mts index c8d907ebad..8da0e83557 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/lamp.mts and b/mods/MAPGEN/mcl_villages/schematics/lamp.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/large_house.mts b/mods/MAPGEN/mcl_villages/schematics/large_house.mts index 36be603f44..3939a2c434 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/large_house.mts and b/mods/MAPGEN/mcl_villages/schematics/large_house.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/library.mts b/mods/MAPGEN/mcl_villages/schematics/library.mts index b47e0b4138..521ee9fb60 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/library.mts and b/mods/MAPGEN/mcl_villages/schematics/library.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/medium_house.mts b/mods/MAPGEN/mcl_villages/schematics/medium_house.mts index 43ce2391b9..fa859ac484 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/medium_house.mts and b/mods/MAPGEN/mcl_villages/schematics/medium_house.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/small_house.mts b/mods/MAPGEN/mcl_villages/schematics/small_house.mts index d7b62529cb..a3789504ee 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/small_house.mts and b/mods/MAPGEN/mcl_villages/schematics/small_house.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/tavern.mts b/mods/MAPGEN/mcl_villages/schematics/tavern.mts index 5eae8ae237..c26c14dbcc 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/tavern.mts and b/mods/MAPGEN/mcl_villages/schematics/tavern.mts differ diff --git a/mods/MAPGEN/mcl_villages/schematics/well.mts b/mods/MAPGEN/mcl_villages/schematics/well.mts index 6ea47fea43..ff8785fdee 100644 Binary files a/mods/MAPGEN/mcl_villages/schematics/well.mts and b/mods/MAPGEN/mcl_villages/schematics/well.mts differ