mobs_mc/horse.lua

166 lines
3.8 KiB
Lua
Raw Normal View History

2017-05-24 22:43:25 -04:00
--MCmobs v0.4
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
--dofile(minetest.get_modpath("mobs").."/api.lua")
--###################
--################### HORSE
--###################
2017-05-24 21:19:08 -04:00
2017-05-24 22:43:25 -04:00
-- Horse
mobs:register_mob("mobs_mc:horse", {
2017-05-24 21:19:08 -04:00
type = "animal",
visual = "mesh",
2017-05-24 22:43:25 -04:00
--visual_size = {x = 1.20, y = 1.20},
mesh = "mobs_mc_horse.b3d",
2017-05-24 22:43:25 -04:00
visual_size = {x=3, y=3},
rotate = -180,
2017-05-24 21:19:08 -04:00
collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
2017-05-24 22:51:30 -04:00
animation = {
speed_normal = 25, speed_run = 50,
stand_start = 0, stand_end = 0,
walk_start = 0, walk_end = 40,
run_start = 0, run_end = 40,
2017-05-24 21:19:08 -04:00
},
textures = {
2017-05-24 22:43:25 -04:00
{"horse.png"},
{"horse1.png"},
{"horse2.png"},
{"horse3.png"},
{"horse4.png"},
{"horse5.png"},
2017-05-24 21:19:08 -04:00
},
fear_height = 3,
runaway = true,
fly = false,
walk_chance = 60,
2017-06-14 19:47:33 -04:00
view_range = 16,
follow = mobs_mc.follow.horse,
2017-05-24 21:19:08 -04:00
passive = true,
2017-06-14 19:47:33 -04:00
hp_min = 15,
hp_max = 30,
2017-05-24 21:19:08 -04:00
lava_damage = 5,
fall_damage = 5,
water_damage = 1,
makes_footstep_sound = true,
drops = {
{name = mobs_mc.items.leather,
2017-05-28 23:16:44 -04:00
chance = 1,
min = 0,
max = 2,},
2017-05-24 21:19:08 -04:00
},
do_custom = function(self, dtime)
-- set needed values if not already present
if not self.v2 then
self.v2 = 0
2017-05-24 22:43:25 -04:00
self.max_speed_forward = 2 --swap due to -180 model
2017-05-25 20:39:12 -04:00
self.max_speed_reverse = 7 --swap due to -180 model
2017-05-24 21:19:08 -04:00
self.accel = 6
self.terrain_type = 3
2017-05-24 22:51:30 -04:00
self.driver_attach_at = {x = 0, y = 7.5, z = 0}
2017-05-25 20:39:12 -04:00
self.player_rotation = {x = 0, y = 180, z = 0}
2017-05-24 21:19:08 -04:00
self.driver_eye_offset = {x = 0, y = 3, z = 0}
2017-05-24 22:43:25 -04:00
self.driver_scale = {x = 0.3, y = 0.3}
2017-05-24 21:19:08 -04:00
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)
2017-05-24 21:19:08 -04:00
-- drop saddle when horse is killed while riding
-- also detach from horse properly
if self.driver then
minetest.add_item(pos, mobs_mc.items.saddle)
2017-05-24 21:19:08 -04:00
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_mc.items.saddle) then
inv:add_item("main", mobs_mc.items.saddle)
2017-05-24 21:19:08 -04:00
else
minetest.add_item(clicker.getpos(), mobs_mc.items.saddle)
2017-05-24 21:19:08 -04:00
end
-- attach player to horse
elseif not self.driver
and clicker:get_wielded_item():get_name() == mobs_mc.items.saddle then
2017-05-24 21:19:08 -04:00
self.object:set_properties({stepheight = 1.1})
mobs.attach(self, clicker)
-- take saddle from inventory
inv:remove_item("main", mobs_mc.items.saddle)
2017-05-24 21:19:08 -04:00
end
end
-- used to capture horse with magic lasso
mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
end
})
2017-05-24 22:43:25 -04:00
--===========================
--Spawn Function
2017-06-24 19:09:38 +02:00
mobs:register_spawn("mobs_mc:horse", mobs_mc.spawn.grassland_savanna, minetest.LIGHT_MAX+1, 0, 15000, 1, 12)
2017-05-24 22:43:25 -04:00
-- compatibility
mobs:alias_mob("mobs:horse", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse1", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse2", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse3", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse4", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse5", "mobs_mc:horse")
mobs:alias_mob("mobs_mc:horse6", "mobs_mc:horse")
2017-05-24 22:43:25 -04:00
-- spawn eggs
mobs:register_egg("mobs_mc:horse", "Horse", "horse_inv.png", 0)
2017-06-21 00:20:06 -04:00
if minetest.settings:get_bool("log_mods") then
minetest.log("action", "MC Horse loaded")
end