Nahrát soubory do 'mobs'

This commit is contained in:
Milan2018 2019-12-28 15:54:27 +01:00
parent cd70363710
commit 8ad7ab887e
4 changed files with 569 additions and 0 deletions

5
mobs/mod.conf Normal file
View File

@ -0,0 +1,5 @@
name = mobs
release = 1920
author = TenPlus1
description = Adds a mob api for mods to add animals or monsters etc.
title = Mobs Redo

449
mobs/mount.lua Normal file
View File

@ -0,0 +1,449 @@
-- lib_mount by Blert2112 (edited by TenPlus1)
local enable_crash = false
local crash_threshold = 6.5 -- ignored if enable_crash=false
------------------------------------------------------------------------------
--
-- Helper functions
--
local node_ok = function(pos, fallback)
fallback = fallback or mobs.fallback_node
local node = minetest.get_node_or_nil(pos)
if node and minetest.registered_nodes[node.name] then
return node
end
return {name = fallback}
end
local function node_is(pos)
local node = node_ok(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.registered_nodes[node.name].walkable == true 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()
default.player_attached[player:get_player_name()] = false
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
default.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)
default.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()
default.player_set_animation(player, "sit" , 30)
end)
--player:set_look_yaw(entity.object:get_yaw() - rot_view)
player:set_look_horizontal(entity.object:get_yaw() - rot_view)
end
function mobs.detach(player, offset)
force_detach(player)
default.player_set_animation(player, "stand" , 30)
local pos = player:get_pos()
pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
minetest.after(0.1, function()
player:set_pos(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:get_velocity()
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
local horz = entity.driver:get_look_horizontal() or 0
entity.object:set_yaw(horz - 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
mobs:set_animation(entity, stand_anim)
end
return
end
-- set moving animation
if moving_anim then
mobs: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:set_velocity({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:get_pos()
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:get_pos()
pos.y = math.floor(pos.y) + 0.5
entity.object:set_pos(pos)
velo.y = 0
end
end
else
v = v * 0.25
end
end
new_velo = get_velocity(v, entity.object:get_yaw() - rot_view, velo.y)
new_acce.y = new_acce.y + acce_y
entity.object:set_velocity(new_velo)
entity.object:set_acceleration(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:get_velocity()
local dir = entity.driver:get_look_dir()
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:set_velocity({
x = dir.x * speed,
y = dir.y * speed + 2,
z = dir.z * speed
})
elseif ctrl.down then
entity.object:set_velocity({
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:set_velocity({x = 0, y = -2, z = 0})
end
entity.object:set_yaw(yaw + math.pi + math.pi / 2 - entity.rotate)
-- firing arrows
if ctrl.LMB and ctrl.sneak and shoots then
local pos = entity.object:get_pos()
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_horizontal()
obj:set_yaw(yaw + math.pi / 2)
obj:set_velocity(vec)
else
obj:remove()
end
end
-- change animation if stopped
if velo.x == 0 and velo.y == 0 and velo.z == 0 then
mobs:set_animation(entity, stand_anim)
else
-- moving animation
mobs:set_animation(entity, moving_anim)
end
end

86
mobs/readme.MD Normal file
View File

@ -0,0 +1,86 @@
MOBS REDO for MINETEST
Built from PilzAdam's original Simple Mobs with additional mobs by KrupnoPavel, Zeg9, ExeterDad and AspireMint.
This mod contains the API only for adding your own mobs into the world, so please use the additional modpacks to add animals, monsters etc.
https://forum.minetest.net/viewtopic.php?f=11&t=9917
Crafts:
- Nametag (paper, black dye, string) can be used right-click on a tamed mob to give them a name.
- Nets can be used to right-click tamed mobs to pick them up and place inside inventory as a spawn egg.
- Magic Lasso is similar to nets but with a better chance of picking up larger mobs.
- Shears are used to right-click sheep and return 1-3 wool.
- Protection Rune lets you protect tamed mobs from harm by other players
- Mob Fence and Fence Top (to stop mobs escaping/glitching through fences)
Lucky Blocks: 9
Changelog:
- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods)
- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07
- 1.48- Add mobs:set_velocity(self, velocity) global function
- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage
- 1.46- Mobs only drop rare items when killed by player (drops.min = 0 makes them rare), code tweak, pathfinding no longer sees through walkable nodes
- 1.45- Added Fence Top to add on top of any fence to stop mobs escaping, new line_of_sight tweaked by Astrobe
- 1.44- Added ToolRanks support for swords when attacking mobs
- 1.43- Better 0.4.16 compatibility, added general attack function and settings
- 1.42- Added "all" option to immune_to table, tidied floating mobs to be less intensive
- 1.41- Mob pathfinding has been updated thanks to Elkien3
- 1.40- Updated to use newer functions, requires Minetest 0.4.16+ to work.
- 1.39- Added 'on_breed', 'on_grown' and 'do_punch' custom functions per mob
- 1.38- Better entity checking, nametag setting and on_spawn function added to mob registry, tweaked light damage
- 1.37- Added support for Raymoo's CMI (common mob interface) mod: https://forum.minetest.net/viewtopic.php?f=9&t=15448
- 1.36- Death check added, if mob dies in fire/lava/with lava pick then drops are cooked
- 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
- 1.29- Split original Mobs Redo into a modpack to make it easier to disable mob sets (animal, monster, npc) or simply use the Api itself for your own mod
- 1.28- New damage system added with ability for mob to be immune to weapons or healed by them :)
- 1.27- Added new sheep, lava flan and spawn egg textures. New Lava Pick tool smelts what you dig. New atan checking function.
- 1.26- Pathfinding feature added thanks to rnd, when monsters attack they become scary smart in finding you :) also, beehive produces honey now :)
- 1.25- Mobs no longer spawn within 12 blocks of player or despawn within same range, spawners now have player detection, Code tidy and tweak.
- 1.24- Added feature where certain animals run away when punched (runaway = true in mob definition)
- 1.23- Added mob spawner block for admin to setup spawners in-game (place and right click to enter settings)
- 1.22- Added ability to name tamed animals and npc using nametags, also npc will attack anyone who punches them apart from owner
- 1.21- Added some more error checking to reduce serialize.h error and added height checks for falling off cliffs (thanks cmdskp)
- 1.20- Error checking added to remove bad mobs, out of map limit mobs and stop serialize.h error
- 1.19- Chickens now drop egg items instead of placing the egg, also throwing eggs result in 1/8 chance of spawning chick
- 1.18- Added docile_by_day flag so that monsters will not attack automatically during daylight hours unless hit first
- 1.17- Added 'dogshoot' attack type, shoots when out of reach, melee attack when in reach, also api tweaks and self.reach added
- 1.16- Mobs follow multiple items now, Npc's can breed
- 1.15- Added Feeding/Taming/Breeding function, right-click to pick up any sheep with X mark on them and replace with new one to fix compatibility.
- 1.14- All .self variables saved in staticdata, Fixed self.health bug
- 1.13- Added capture function (thanks blert2112) chance of picking up mob with hand; net; magic lasso, replaced some .x models with newer .b3d one's
- 1.12- Added animal ownership so that players cannot steal your tamed animals
- 1.11- Added flying mobs (and swimming), fly=true and fly_in="air" or "deafult:water_source" for fishy
- 1,10- Footstep removed (use replace), explosion routine added for exploding mobs.
- 1.09- reworked breeding routine, added mob rotation value, added footstep feature, added jumping mobs with sounds feature, added magic lasso for picking up animals
- 1.08- Mob throwing attack has been rehauled so that they can damage one another, also drops and on_die function added
- 1.07- Npc's can now be set to follow player or stand by using self.order and self.owner variables
- beta- Npc mob added, kills monsters, attacks player when punched, right click with food to heal or gold lump for drop
- 1.06- Changed recovery times after breeding, and time taken to grow up (can be sped up by feeding baby animal)
- 1.05- Added ExeterDad's bunny's which can be picked up and tamed with 4 carrots from farming redo or farming_plus, also shears added to get wool from sheep and lastly Jordach/BSD's kitten
- 1.04- Added mating for sheep, cows and hogs... feed animals to make horny and hope for a baby which is half size, will grow up quick though :)
- 1.03- Added mob drop/replace feature so that chickens can drop eggs, cow/sheep can eat grass/wheat etc.
- 1.02- Sheared sheep are remembered and spawn shaven, Warthogs will attack when threatened, Api additions
- 1.01- Mobs that suffer fall damage or die in water/lava/sunlight will now drop items
- 1.0 - more work on Api so that certain mobs can float in water while some sink like a brick :)
- 0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked
- 0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound
- 0.7 - mobs.protected switch added to api.lua, when set to 1 mobs no longer spawn in protected areas, also bug fixes
- 0.6 - Api now supports multi-textured mobs, e.g oerkki, dungeon master, rats and chickens have random skins when spawning (sheep fix TODO), also new Honey block
- 0.5 - Mobs now float in water, die from falling, and some code improvements
- 0.4 - Dungeon Masters and Mese Monsters have much better aim due to shoot_offset, also they can both shoot through nodes that aren't walkable (flowers, grass etc) plus new sheep sound :)
- 0.3 - Added LOTT's Spider mob, made Cobwebs, added KPavel's Bee with Honey and Beehives (made texture), Warthogs now have sound and can be tamed, taming of shaved sheep or milked cow with 8 wheat so it will not despawn, many bug fixes :)
- 0.2 - Cooking bucket of milk into cheese now returns empty bucket
- 0.1 - Initial Release

29
mobs/settingtypes.txt Normal file
View File

@ -0,0 +1,29 @@
# If false then mobs no longer spawn in world without spawner or spawn egg
mobs_spawn (Spawn Mobs) bool true
# If enabled then monsters no longer spawn in world
only_peaceful_mobs (Only spawn peaceful Mobs) bool false
# If enabled then punching mobs no longer shows blood effects
mobs_disable_blood (Disable Mob blood) bool false
# If disabled then Mobs no longer destroy world blocks
mobs_griefing (Griefing Mobs) bool true
# If false then Mobs no longer spawn inside player protected areas
mobs_spawn_protected (Spawn Mobs in protected areas) bool true
# If true Mobs will be removed once a map chunk is out of view
remove_far_mobs (Remove far Mobs) bool true
# Sets Mob difficulty level by multiplying punch damage
mob_difficulty (Mob difficulty) float 1.0
# If disabled health status no longer appears above Mob when punched
mob_show_health (Show Mob health) bool true
# Contains a value used to multiply Mob spawn values
mob_chance_multiplier (Mob chance multiplier) float 1.0
# When false Mob no longer drop items when killed
mobs_drop_items (Mob drops) bool true