Update to Mobs Redo 1.35

This commit is contained in:
Wuzzy 2017-05-25 10:33:19 +02:00
parent 0d6b57c9c4
commit 8d1ffbe2cd
11 changed files with 1635 additions and 727 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
MOB API (28th September 2016)
MOB API (12th May 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -12,7 +12,7 @@ The mob api is a function that can be called on by other mods to add new animals
'remove_far_mobs' if true then mobs that are outside players visual range will be removed (default is false)
'mobname' can change specific mob chance rate (0 to disable) and spawn number e.g. mobs_animal:cow = 1000,5
'mob_difficulty' sets difficulty level (health and hit damage multiplied by this number), defaults to 1.0.
'mob_show_health' if false then punching mob will not show health status (true by default)
mobs:register_mob(name, definition)
@ -25,8 +25,9 @@ This functions registers a new mob as a Minetest entity.
'docile_by_day' when true, mob will not attack during daylight hours unless provoked
'attacks_monsters' usually for npc's to attack monsters in area
'group_attack' true to defend same kind of mobs from attack in area
'owner_loyal' when true owned mobs will attack any monsters you punch
'attack_animals' true for monster to attack animals as well as player and npc's
'attack_specific' has a table of entity names that monsters can attack {"player", "mobs_animal:chicken"}
'specific_attack' has a table of entity names that monsters can attack {"player", "mobs_animal:chicken"}
'hp_min' minimum health
'hp_max' maximum health (mob health is randomly selected between both)
'physical' same is in minetest.register_entity()
@ -42,14 +43,13 @@ This functions registers a new mob as a Minetest entity.
'makes_footstep_sound' same is in minetest.register_entity()
'follow' item when held will cause mob to follow player, can be single string "default:apple" or table {"default:apple", "default:diamond"}
'view_range' the range in that the monster will see the playerand follow him
'walk_chance' chance of mob walking around
'jump_chance' chance of mob jumping around, set above to 0 for jumping mob only
'walk_chance' chance of mob walking around, set above to 0 for jumping mob only
'walk_velocity' the velocity when the monster is walking around
'run_velocity' the velocity when the monster is attacking a player
'runaway' when true mob will turn and run away when punched
'stepheight' minimum node height mob can walk onto without jumping (default: 0.6)
'jump' can mob jump, true or false
'jump_height' height mob can jump, default is 6
'jump_height' height mob can jump, default is 6 (0 to disable jump)
'fly' can mob fly, true or false (used for swimming mobs also)
'fly_in' node name that mob flys inside, e.g "air", "default:water_source" for fish
'damage' the damage per second
@ -82,8 +82,9 @@ This functions registers a new mob as a Minetest entity.
'shoot' shoots defined arrows when player is within range
'explode' follows player in range and will flash and explode when in reach
'dogshoot' shoots arrows when in range and one on one attack when in reach
'dogshoot_switch' allows switching between shoot and dogfight modes inside dogshoot using timer (1 = shoot, 2 = dogfight)
'dogshoot_count_max' number of seconds before switching above modes.
'dogshoot_switch' allows switching between shoot and dogfight modes inside dogshoot using timer (1 = shoot, 2 = dogfight)
'dogshoot_count_max' number of seconds before switching to dogfight mode.
'dogshoot_count2_max' number of seconds before switching back to shoot mode.
'custom_attack' is a function that is called when mob is in range to attack player, parameters are (self, to_attack)
'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations
'on_blast' is called when TNT explodes near mob, function uses (object, damage) and returns (do_damage, do_knockback, drops)
@ -102,29 +103,31 @@ This functions registers a new mob as a Minetest entity.
'jump' sound when jumping
'explode' sound when exploding
'distance' maximum distance sounds are heard from (default is 10)
'animation' a table with the animation ranges and speed of the model
'stand_start' start frame of stand animation
'stand_end' end frame of stand animation
'walk_start' start frame of walk animation
'walk_end' end frame of walk animation
'run_start' start frame of run animation
'run_end' end frame of run animation
'punch_start' start frame of punch animation
'punch_end' end frame of punch animation
'punch2_start' start frame of alt.punch animation
'punch2_end' end frame of alt.punch animation
'shoot_start' start frame of shoot animation
'shoot_end' end frame of shoot animation
'speed_normal' normal animation speed
'speed_run' running animation speed
'speed_punch' punching animation speed
'speed_punch2' alternative punching animation speed
'speed_shoot' shooting animation speed
Mobs can look for specific nodes as they walk and replace them to mimic eating
'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"}
'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
The 'replace_what' has been updated to use tables for what, with and y_offset e.g.
replace_what = { {"group:grass", "air", 0}, {"default:dirt_with_grass", "default:dirt", -1} }
Mob animation comes in three parts, start_frame, end_frame and frame_speed which
can be added to the mob definition under pre-defined mob animation names like:
'animation' a table with the animation ranges and speed of the model
'stand_start', 'stand_end', 'stand_speed' when mob stands still
'walk_start', 'walk_end', 'walk_speed' when mob walks
'run_start', 'run_end', 'run_speed' when mob runs
'fly_start', 'fly_end', 'fly_speed' when mob flies
'punch_start', 'punch_end', 'punch_speed' when mob attacks
'punch2_start', 'punch2_end', 'punch2_speed' when mob attacks (alternative)
'die_start', 'die_end', 'die_speed' when mob dies
also 'speed_normal' for compatibility with older mobs for animation speed (deprecated)
The mob api also has some preset variables and functions that it will remember for each mob
@ -133,8 +136,9 @@ The mob api also has some preset variables and functions that it will remember f
'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.nametag' contains the name of the mob which it can show above
'on_die' a function that is called when mob is killed
'do_custom' a custom function that is called 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.
'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.
mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
@ -151,7 +155,7 @@ These functions register a spawn algorithm for the mob. Without this function th
'interval' is same as in register_abm() (default is 30 for mobs:register_spawn)
'chance' is same as in register_abm()
'active_object_count' mob is only spawned if active_object_count_wider of ABM is <= this
'min_height' is the maximum height the mob can spawn
'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.
@ -191,6 +195,9 @@ This function registers a arrow for mobs with the attack type shoot.
'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, no glow)
'rotate' integer value in degrees to rotate arrow
'on_step' is a custom function when arrow is active, nil for default.
@ -226,12 +233,12 @@ This function is generally called inside the on_rightclick section of the mob ap
'chance_net' chance of capturing mob using net (1 to 100) 0 to disable
'chance_lasso' chance of capturing mob using magic lasso (1 to 100) 0 to disable
'force_take' take mob by force, even if tamed (true or false)
'replacewith' once captured replace mob with this item instead
'replacewith' once captured replace mob with this item instead (overrides new mob eggs with saved information)
mobs:feed_tame(self, clicker, feed_count, breed)
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.
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
@ -242,7 +249,7 @@ This function allows the mob to be fed the item inside self.follow be it apple,
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.
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.
'self' mob information
'clicker' player information
@ -257,3 +264,184 @@ Useful Internal Variables
'self.gotten' true when sheep have been sheared or cows have been milked, a toggle switch which can be used for many functions
'self.child' true when mob is currently a child (when two mobs have bred and current mob is the outcome)
'self.hornytimer' background timer that controls breeding functions and mob childhood timings
Mobs can now be ridden by players and the following shows the functions and usage:
mobs:attach(self, player)
This function attaches a player to the mob so it can be ridden.
'self' mob information
'player' player information
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
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
mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
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 movement animation e.g. "walk"
'stand_animation' string containing movement animation e.g. "stand"
Certain variables need to be set before using the above functions:
'self.v2' toggle switch
'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}
Here is an example mob to show how the above functions work:
-- rideable horse
mobs:register_mob("mob_horse:horse", {
type = "animal",
visual = "mesh",
visual_size = {x = 1.20, y = 1.20},
mesh = "mobs_horse.x",
collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
animation = {
speed_normal = 15,
speed_run = 30,
stand_start = 25,
stand_end = 75,
walk_start = 75,
walk_end = 100,
run_start = 75,
run_end = 100,
},
textures = {
{"mobs_horse.png"},
{"mobs_horsepeg.png"},
{"mobs_horseara.png"}
},
fear_height = 3,
runaway = true,
fly = false,
walk_chance = 60,
view_range = 5,
follow = {"farming:wheat"},
passive = true,
hp_min = 12,
hp_max = 16,
armor = 200,
lava_damage = 5,
fall_damage = 5,
water_damage = 1,
makes_footstep_sound = true,
drops = {
{name = "mobs:meat_raw", chance = 1, min = 2, max = 3}
},
do_custom = function(self, dtime)
-- set needed values if not already present
if not self.v2 then
self.v2 = 0
self.max_speed_forward = 6
self.max_speed_reverse = 2
self.accel = 6
self.terrain_type = 3
self.driver_attach_at = {x = 0, y = 20, z = -2}
self.driver_eye_offset = {x = 0, y = 3, z = 0}
self.driver_scale = {x = 1, y = 1}
end
-- if driver present allow control of horse
if self.driver then
mobs.drive(self, "walk", "stand", false, dtime)
return false -- skip rest of mob functions
end
return true
end,
on_die = function(self, pos)
-- drop saddle when horse is killed while riding
-- also detach from horse properly
if self.driver then
minetest.add_item(pos, "mobs:saddle")
mobs.detach(self.driver, {x = 1, y = 0, z = 1})
end
end,
on_rightclick = function(self, clicker)
-- make sure player is clicking
if not clicker or not clicker:is_player() then
return
end
-- feed, tame or heal horse
if mobs:feed_tame(self, clicker, 10, true, true) then
return
end
-- make sure tamed horse is being clicked by owner only
if self.tamed and self.owner == clicker:get_player_name() then
local inv = clicker:get_inventory()
-- detatch player already riding horse
if self.driver and clicker == self.driver then
mobs.detach(clicker, {x = 1, y = 0, z = 1})
-- add saddle back to inventory
if inv:room_for_item("main", "mobs:saddle") then
inv:add_item("main", "mobs:saddle")
else
minetest.add_item(clicker.getpos(), "mobs:saddle")
end
-- attach player to horse
elseif not self.driver
and clicker:get_wielded_item():get_name() == "mobs:saddle" then
self.object:set_properties({stepheight = 1.1})
mobs.attach(self, clicker)
-- take saddle from inventory
inv:remove_item("main", "mobs:saddle")
end
end
-- used to capture horse with magic lasso
mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
end
})

View File

@ -1,6 +1,6 @@
mcl_core
mcl_sounds
mcl_hunger
mcl_sounds
invisibility?
intllib?
lucky_block?

View File

@ -4,11 +4,14 @@ local path = minetest.get_modpath("mobs")
-- Mob API
dofile(path .. "/api.lua")
-- Rideable Mobs
dofile(path .. "/mount.lua")
-- Mob Items
dofile(path .. "/crafts.lua")
-- Mob Spawner
-- moved into other mod (MCL2 change)
-- MCL2 has its own spawners in mcl_mobspawners
-- Lucky Blocks
dofile(path .. "/lucky_block.lua")

View File

@ -21,7 +21,7 @@ Enter name: = Namen eingeben:
Rename = Umbenennen
#crafts.lua
Name Tag = Namensschild
Nametag = Namensschild
Leather = Leder
Raw Meat = Rohes Fleisch
Meat = Fleisch
@ -30,9 +30,9 @@ Net (right-click animal to put in inventory) = Netz (Rechtsklick auf Tier,\num e
Steel Shears (right-click to shear) = Stahlschere (Rechtsklick zum Scheren)
#spawner.lua
Monster Spawner = Monsterspawner
Mob Spawner = Mobspawner
Mob MinLight MaxLight Amount PlayerDist = Mob MinLicht MaxLicht Menge SpielerEntfng
Spawner Not Active (enter settings) = Spawner nicht aktiv (Einstellungen eintragen)
Spawner Active (@1) = Spawner aktiv (@1)
Mob Spawner settings failed! = Mobspawnereinstellungen gescheitert!
> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] = Name min. Licht[0-14] max. Licht[0-14] max. Mobs in Gebiet[0 zum deaktivieren] Entfernung zum Spieler[1-20] Höhe[-10 bis 10]
> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] = Name min. Licht[0-14] max. Licht[0-14] max. Mobs in Gebiet[0 zum deaktivieren] Entfernung zum Spieler[1-20] Höhe[-10 bis 10]

View File

@ -21,7 +21,7 @@ Enter name: = Insira um nome:
Rename = Renomear
#crafts.lua
Name Tag = Etiqueta
Nametag = Etiqueta
Leather = Couro
Raw Meat = Carne crua
Meat = Carne
@ -30,7 +30,7 @@ Net (right-click animal to put in inventory) = Net (clique-direito no animal par
Steel Shears (right-click to shear) = Tesoura de Aço (clique-direito para tosquiar)
#spawner.lua
Monster Spawner =
Mob Spawner = Spawnador de Mob
Mob MinLight MaxLight Amount PlayerDist = Mob LuzMinima LuzMaxima Valor DistJogador
Spawner Not Active (enter settings) = Spawnador Inativo (configurar)
Spawner Active (@1) = Spawnador Ativo (@1)

View File

@ -19,7 +19,7 @@ Enter name: =
Rename =
#crafts.lua
Name Tag =
Nametag =
Leather =
Raw Meat =
Meat =
@ -28,9 +28,9 @@ Net (right-click animal to put in inventory) =
Steel Shears (right-click to shear) =
#spawner.lua
Monster Spawner =
Mob Spawner =
Mob MinLight MaxLight Amount PlayerDist =
Spawner Not Active (enter settings) =
Spawner Active (@1) =
Mob Spawner settings failed! =
> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] =
> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] =

View File

@ -0,0 +1,39 @@
# Türkçe çeviri by Admicos
# Turkish translation by Admicos
# Son düzenleme: 26 Nisan 2017
# Last edit: 26 April 2017
#init.lua
[MOD] Mobs Redo loaded = [MOD] Mobs Red yüklendi
#api.lua
[MOBS] mod profiling enabled, damage not enabled = [MOBS] profilleme açık, zarar kapalı
lifetimer expired, removed @1 = Can zamanlayıcısı bitti, @1 silindi
[Mobs Redo] @1 has spawning disabled = @1 yaratılması kapandı
[Mobs Redo] Chance setting for @1 is now @2 = [Mobs Redo] @1'in şans ayarı şimdi @2
[mobs] @1 failed to spawn at @2 = @1, @2'de yaratılamadı
Not tamed! = Evcil değil!
@1 is owner! = Sahibi @1!
Missed! = Kaçırdın!
@1 at full health (@2) = @1 tam canında (@2)
@1 has been tamed! = @1 tamamen evcilleştirilmiştir!
Enter name: = İsim gir:
Rename = Yeniden adlandır
#crafts.lua
Nametag = İsim etiketi
Leather = Deri
Raw Meat = Çiğ et
Meat = Et
Magic Lasso (right-click animal to put in inventory) = Sihirli kement (hayvana sağ tıklayarak envantere koy)
Net (right-click animal to put in inventory) = Ağ (hayvana sağ tıklayarak envantere koy)
Steel Shears (right-click to shear) = Çelik makas (sağ tıklayarak kes)
#spawner.lua
Mob Spawner = Canavar Yaratıcı
Mob MinLight MaxLight Amount PlayerDist = Mob MinIşık MaxIşık Miktar OyuncuMesafesi
Spawner Not Active (enter settings) = Yaratıcı aktif değil (ayarlara gir)
Spawner Active (@1) = Yaratıcı aktif (@1)
Mob Spawner settings failed! = Yaratıcı ayarları uygulanamadı.
> name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10] = > isim min_isik[0-14] max_isik[0-14] alandaki_max_canavar_sayisi[kapatmak icin 0] mesafe[1-20] y_cikinti[-10 ve 10 arası]

View File

@ -2,7 +2,14 @@
if minetest.get_modpath("lucky_block") then
lucky_block:add_blocks({
{"dro", {"mobs:meat_raw"}, 5},
{"dro", {"mobs:meat"}, 5},
{"dro", {"mobs:nametag"}, 1},
{"dro", {"mobs:leather"}, 5},
{"dro", {"mobs:net"}, 1},
{"dro", {"mobs:magic_lasso"}, 1},
{"dro", {"mobs:shears"}, 1},
{"dro", {"mobs:protector"}, 1},
{"lig"},
})
end

View File

@ -0,0 +1,437 @@
-- lib_mount by Blert2112 (edited by TenPlus1)
local enable_crash = true
local crash_threshold = 6.5 -- ignored if enable_crash=false
------------------------------------------------------------------------------
--
-- Helper functions
--
local function node_is(pos)
local node = minetest.get_node(pos)
if node.name == "air" then
return "air"
end
if minetest.get_item_group(node.name, "lava") ~= 0 then
return "lava"
end
if minetest.get_item_group(node.name, "liquid") ~= 0 then
return "liquid"
end
if minetest.get_item_group(node.name, "walkable") ~= 0 then
return "walkable"
end
return "other"
end
local function get_sign(i)
i = i or 0
if i == 0 then
return 0
else
return i / math.abs(i)
end
end
local function get_velocity(v, yaw, y)
local x = -math.sin(yaw) * v
local z = math.cos(yaw) * v
return {x = x, y = y, z = z}
end
local function get_v(v)
return math.sqrt(v.x * v.x + v.z * v.z)
end
local function force_detach(player)
local attached_to = player:get_attach()
if not attached_to then
return
end
local entity = attached_to:get_luaentity()
if entity.driver
and entity.driver == player then
entity.driver = nil
end
player:set_detach()
mcl_player.player_attached[player:get_player_name()] = false
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
mcl_player.player_set_animation(player, "stand" , 30)
player:set_properties({visual_size = {x = 1, y = 1} })
end
-------------------------------------------------------------------------------
minetest.register_on_leaveplayer(function(player)
force_detach(player)
end)
minetest.register_on_shutdown(function()
local players = minetest.get_connected_players()
for i = 1, #players do
force_detach(players[i])
end
end)
minetest.register_on_dieplayer(function(player)
force_detach(player)
return true
end)
-------------------------------------------------------------------------------
function mobs.attach(entity, player)
local attach_at, eye_offset = {}, {}
entity.player_rotation = entity.player_rotation or {x = 0, y = 0, z = 0}
entity.driver_attach_at = entity.driver_attach_at or {x = 0, y = 0, z = 0}
entity.driver_eye_offset = entity.driver_eye_offset or {x = 0, y = 0, z = 0}
entity.driver_scale = entity.driver_scale or {x = 1, y = 1}
local rot_view = 0
if entity.player_rotation.y == 90 then
rot_view = math.pi/2
end
attach_at = entity.driver_attach_at
eye_offset = entity.driver_eye_offset
entity.driver = player
force_detach(player)
player:set_attach(entity.object, "", attach_at, entity.player_rotation)
mcl_player.player_attached[player:get_player_name()] = true
player:set_eye_offset(eye_offset, {x = 0, y = 0, z = 0})
player:set_properties({
visual_size = {
x = entity.driver_scale.x,
y = entity.driver_scale.y
}
})
minetest.after(0.2, function()
mcl_player.player_set_animation(player, "sit" , 30)
end)
--player:set_look_yaw(entity.object:getyaw() - rot_view)
player:set_look_horizontal(entity.object:getyaw() - rot_view)
end
function mobs.detach(player, offset)
force_detach(player)
mcl_player.player_set_animation(player, "stand" , 30)
local pos = player:getpos()
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
minetest.after(0.1, function()
player:setpos(pos)
end)
end
function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
local rot_steer, rot_view = math.pi/2, 0
if entity.player_rotation.y == 90 then
rot_steer, rot_view = 0, math.pi/2
end
local acce_y = 0
local velo = entity.object:getvelocity()
entity.v = get_v(velo) * get_sign(entity.v)
-- process controls
if entity.driver then
--print ("---velo", get_v(velo))
local ctrl = entity.driver:get_player_control()
-- move forwards
if ctrl.up then
entity.v = entity.v + entity.accel / 10
-- move backwards
elseif ctrl.down then
if entity.max_speed_reverse == 0 and entity.v == 0 then
return
end
entity.v = entity.v - entity.accel / 10
end
-- fix mob rotation
-- entity.object:setyaw(entity.driver:get_look_yaw() - entity.rotate)
entity.object:setyaw(entity.driver:get_look_horizontal() - entity.rotate)
if can_fly then
-- fly up
if ctrl.jump then
velo.y = velo.y + 1
if velo.y > entity.accel then velo.y = entity.accel end
elseif velo.y > 0 then
velo.y = velo.y - 0.1
if velo.y < 0 then velo.y = 0 end
end
-- fly down
if ctrl.sneak then
velo.y = velo.y - 1
if velo.y < -entity.accel then velo.y = -entity.accel end
elseif velo.y < 0 then
velo.y = velo.y + 0.1
if velo.y > 0 then velo.y = 0 end
end
else
-- jump
if ctrl.jump then
if velo.y == 0 then
velo.y = velo.y + entity.jump_height
acce_y = acce_y + (acce_y * 3) + 1
end
end
end
end
-- if not moving then set animation and return
if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
if stand_anim then
set_animation(entity, stand_anim)
end
return
end
-- set moving animation
if moving_anim then
set_animation(entity, moving_anim)
end
-- Stop!
local s = get_sign(entity.v)
entity.v = entity.v - 0.02 * s
if s ~= get_sign(entity.v) then
entity.object:setvelocity({x = 0, y = 0, z = 0})
entity.v = 0
return
end
-- enforce speed limit forward and reverse
local max_spd = entity.max_speed_reverse
if get_sign(entity.v) >= 0 then
max_spd = entity.max_speed_forward
end
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
-- Set position, velocity and acceleration
local p = entity.object:getpos()
local new_velo = {x = 0, y = 0, z = 0}
local new_acce = {x = 0, y = -9.8, z = 0}
p.y = p.y - 0.5
local ni = node_is(p)
local v = entity.v
if ni == "air" then
if can_fly == true then
new_acce.y = 0
end
elseif ni == "liquid" or ni == "lava" then
if ni == "lava" and entity.lava_damage ~= 0 then
entity.lava_counter = (entity.lava_counter or 0) + dtime
if entity.lava_counter > 1 then
minetest.sound_play("default_punch", {
object = entity.object,
max_hear_distance = 5
})
entity.object:punch(entity.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = entity.lava_damage}
}, nil)
entity.lava_counter = 0
end
end
if entity.terrain_type == 2
or entity.terrain_type == 3 then
new_acce.y = 0
p.y = p.y + 1
if node_is(p) == "liquid" then
if velo.y >= 5 then
velo.y = 5
elseif velo.y < 0 then
new_acce.y = 20
else
new_acce.y = 5
end
else
if math.abs(velo.y) < 1 then
local pos = entity.object:getpos()
pos.y = math.floor(pos.y) + 0.5
entity.object:setpos(pos)
velo.y = 0
end
end
else
v = v * 0.25
end
end
new_velo = get_velocity(v, entity.object:getyaw() - rot_view, velo.y)
new_acce.y = new_acce.y + acce_y
entity.object:setvelocity(new_velo)
entity.object:setacceleration(new_acce)
-- CRASH!
if enable_crash then
local intensity = entity.v2 - v
if intensity >= crash_threshold then
--print("----------- crash", intensity)
entity.object:punch(entity.object, 1.0, {
full_punch_interval = 1.0,
damage_groups = {fleshy = intensity}
}, nil)
end
end
entity.v2 = v
end
-- directional flying routine by D00Med (edited by TenPlus1)
function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
local ctrl = entity.driver:get_player_control()
local velo = entity.object:getvelocity()
local dir = entity.driver:get_look_dir()
-- local yaw = entity.driver:get_look_yaw()
local yaw = entity.driver:get_look_horizontal() + 1.57 -- offset fix between old and new commands
local rot_steer, rot_view = math.pi / 2, 0
if entity.player_rotation.y == 90 then
rot_steer, rot_view = 0, math.pi / 2
end
if ctrl.up then
entity.object:setvelocity({
x = dir.x * speed,
y = dir.y * speed + 2,
z = dir.z * speed
})
elseif ctrl.down then
entity.object:setvelocity({
x = -dir.x * speed,
y = dir.y * speed + 2,
z = -dir.z * speed
})
elseif not ctrl.down or ctrl.up or ctrl.jump then
entity.object:setvelocity({x = 0, y = -2, z = 0})
end
entity.object:setyaw(yaw + math.pi + math.pi / 2 - entity.rotate)
-- firing arrows
if ctrl.LMB and ctrl.sneak and shoots then
local pos = entity.object:getpos()
local obj = minetest.add_entity({
x = pos.x + 0 + dir.x * 2.5,
y = pos.y + 1.5 + dir.y,
z = pos.z + 0 + dir.z * 2.5}, arrow)
local ent = obj:get_luaentity()
if ent then
ent.switch = 1 -- for mob specific arrows
ent.owner_id = tostring(entity.object) -- so arrows dont hurt entity you are riding
local vec = {x = dir.x * 6, y = dir.y * 6, z = dir.z * 6}
-- local yaw = entity.driver:get_look_yaw()
local yaw = entity.driver:get_look_horizontal()
obj:setyaw(yaw + math.pi / 2)
obj:setvelocity(vec)
else
obj:remove()
end
end
-- change animation if stopped
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
set_animation(entity, stand_anim)
else
-- moving animation
set_animation(entity, moving_anim)
end
end

View File

@ -22,7 +22,9 @@ Lucky Blocks: 9
Changelog:
- 1.35- Added owner_loyal flag for owned mobs to attack player enemies, also fixed group_attack
- 1.34- Added function to fly mob using directional movement (thanks D00Med for flying code)
- 1.33- Added functions to mount ride mobs (mobs.attach, mobs.detach, mobs.drive) many thanks to Blert2112
- 1.32- Added new spawn check to count specific mobs AND new minetest.conf setting to chance spawn chance and numbers, added ability to protect tamed mobs
- 1.31- Added 'attack_animals' and 'specific_attack' flags for custom monster attacks, also 'mob_difficulty' .conf setting to make mobs harder.
- 1.30- Added support for invisibility mod (mobs cant attack what they cant see), tweaked and tidied code