- Closes #8
This commit is contained in:
Leslie Krause 2020-05-03 19:39:00 -04:00
parent ce9f06d38e
commit 5b26333f0c
3 changed files with 67 additions and 17 deletions

View File

@ -36,9 +36,12 @@ Here are some of the other highlights of the Mobs Lite engine:
* Mobs can be randomly spawned in the vicinity of players, thus relieving the overhead of
costly ABM-based spawners.
* Timekeeper helper class ensures efficient dispatching of mob-related callbacks for the
* Timekeeper helper class ensures efficient dispatching of mob-related callbacks at the
appropriate server cycle.
* Animals can be programmed to follow players or to grab items that are wielded by or
dropped by nearby players.
* And of course, much much more!
Since Mobs Lite is still in early beta, there is the likelihood of lingering bugs. The API

View File

@ -48,21 +48,19 @@ mobs.register_mob( "mobs:kitten", {
run_velocity = 1.2,
escape_range = 3.0,
follow_range = 2.0,
pickup_range = 2.0,
can_jump = false,
can_walk = true,
enable_fall_damage = true,
watch_wielditems = {
["mobs:meat_raw"] = "follow",
["mobs:meat"] = "follow",
["mobs:meat_raw"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 8, wait_chance = 1 },
},
watch_spawnitems = {
["mobs:meat_raw"] = "follow",
["mobs:meat"] = "follow",
["mobs:meat_raw"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 1, wait_chance = 2 },
},
watch_players = { },
hunger = 5,
hp_max = 4,
hp_low = 3,
armor = 100,
@ -145,17 +143,16 @@ mobs.register_mob( "mobs:rat", {
run_velocity = 1.2,
escape_range = 0.0,
follow_range = 2.0,
pickup_range = 2.0,
can_jump = false,
can_walk = true,
enable_fall_damage = true,
watch_wielditems = {
["mobs:meat_raw"] = "follow",
["mobs:meat"] = "follow",
},
watch_spawnitems = {
["mobs:meat_raw"] = "follow",
["mobs:meat"] = "follow",
["mobs:meat"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 2, wait_chance = 4 },
},
watch_players = { },
@ -229,15 +226,17 @@ mobs.register_mob( "mobs:hare", {
run_velocity = 3.5,
escape_range = 3.0,
follow_range = 3.0,
pickup_range = 2.0,
can_jump = true,
can_walk = true,
enable_fall_damage = true,
watch_wielditems = {
["default:apple"] = "follow",
["default:orange"] = "follow",
["default:apple"] = "follow",
},
watch_spawnitems = {
["default:apple"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 2, wait_chance = 5 },
},
watch_spawnitems = { },
watch_players = { },
hp_max = 4,
@ -320,19 +319,20 @@ mobs.register_mob( "mobs:chicken", {
recoil_velocity = 2.0,
run_velocity = 2.0,
follow_range = 3.0,
pickup_range = 2.0,
escape_range = 3.0,
can_jump = true,
can_walk = true,
enable_fall_damage = true,
watch_wielditems = {
["default:apple"] = "follow",
["default:orange"] = "follow",
["farming:seed_wheat"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 1, wait_chance = 1 },
},
watch_spawnitems = {
["farming:seed_wheat"] = mobs.presets.grab_handout { can_eat = true, grab_chance = 2, wait_chance = 4 },
},
watch_spawnitems = { },
watch_players = { },
hunger = 10,
hp_max = 10,
hp_low = 9,
armor = 100,

View File

@ -1389,6 +1389,53 @@ end
--------------------
mobs.presets = {
grab_handout = function ( def )
local grab_chance = def.grab_chance
local wait_chance = def.wait_chance
local can_eat = def.can_eat
return function ( self, target, elapsed )
if random( grab_chance ) == 1 then
local target_pos = vector.offset_y( target:get_pos( ) )
local dist = vector.distance( self.pos, target_pos )
if self:get_target_yaw_delta( target_pos ) < rad_30 and dist <= self.pickup_range then
if target:is_player( ) then
target:get_wielded_item( ):take_item( )
target:set_wielded_item( "" )
elseif target:get_entity_name( ) == "__builtin:item" then
target:remove( )
end
if can_eat then
-- minetest.sound_play( "hbhunger_eat_generic", {
-- object = self.object,
-- max_hear_distance = 10,
-- gain = 1.0
-- } )
minetest.add_particle( {
pos = vector.offset_y( self.pos, 0.5 ),
velocity = { x = 0, y = 0.8, z = 0 },
acceleration = { x = 0, y = 0, z = 0 },
exptime = 4.0,
size = 3,
collisiondetection = false,
vertical = true,
texture = "heart.png",
} )
end
return nil
end
end
return random( wait_chance ) == 1 and "follow" or nil
end
end,
}
--------------------
dofile( minetest.get_modpath( "mobs" ) .. "/extras.lua" )
dofile( minetest.get_modpath( "mobs" ) .. "/monsters.lua" )
dofile( minetest.get_modpath( "mobs" ) .. "/animals.lua" )
@ -1397,5 +1444,5 @@ dofile( minetest.get_modpath( "mobs" ) .. "/weapons.lua" )
-- compatibility for Minetest S3 engine
if not vector.origin then
dofile( minetest.get_modpath( "mobs" ) .. "/compatibility.lua" )
dofile( minetest.get_modpath( "mobs" ) .. "/compatibility.lua" )
end