2017-05-24 22:43:25 -04:00
|
|
|
--MCmobs v0.4
|
2016-05-19 19:24:06 -04:00
|
|
|
--maikerumine
|
|
|
|
--made for MC like Survival game
|
|
|
|
--License for code WTFPL and otherwise stated in readmes
|
|
|
|
|
|
|
|
|
|
|
|
--dofile(minetest.get_modpath("mobs").."/api.lua")
|
|
|
|
|
2017-05-22 22:27:00 -04:00
|
|
|
--###################
|
|
|
|
--################### HORSE
|
|
|
|
--###################
|
|
|
|
|
2017-06-29 17:38:08 +02:00
|
|
|
local horse_extra_texture = function(base, saddle, chest)
|
|
|
|
if saddle then
|
|
|
|
base = base .. "^mobs_mc_horse_saddle.png"
|
|
|
|
end
|
|
|
|
if chest then
|
|
|
|
base = base .. "^mobs_mc_horse_chest.png"
|
|
|
|
end
|
|
|
|
return base
|
|
|
|
end
|
2017-05-24 21:19:08 -04:00
|
|
|
|
2017-05-24 22:43:25 -04:00
|
|
|
-- Horse
|
2017-06-27 03:25:42 +02:00
|
|
|
local horse = {
|
2017-05-24 21:19:08 -04:00
|
|
|
type = "animal",
|
|
|
|
visual = "mesh",
|
2017-06-27 00:32:05 +02:00
|
|
|
mesh = "mobs_mc_horse.b3d",
|
2017-06-27 03:30:42 +02:00
|
|
|
visual_size = {x=3.0, y=3.0},
|
|
|
|
collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825},
|
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-06-27 03:59:03 +02:00
|
|
|
{"mobs_mc_horse_brown.png"},
|
|
|
|
{"mobs_mc_horse_darkbrown.png"},
|
|
|
|
{"mobs_mc_horse_white.png"},
|
|
|
|
{"mobs_mc_horse_gray.png"},
|
|
|
|
{"mobs_mc_horse_black.png"},
|
|
|
|
{"mobs_mc_horse_chestnut.png"},
|
2017-05-24 21:19:08 -04:00
|
|
|
},
|
2017-06-27 03:37:49 +02:00
|
|
|
fear_height = 4,
|
2017-05-24 21:19:08 -04:00
|
|
|
fly = false,
|
|
|
|
walk_chance = 60,
|
2017-06-14 19:47:33 -04:00
|
|
|
view_range = 16,
|
2017-06-23 18:26:00 +02:00
|
|
|
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-06-27 03:37:49 +02:00
|
|
|
floats = 1,
|
|
|
|
lava_damage = 4,
|
2017-05-24 21:19:08 -04:00
|
|
|
water_damage = 1,
|
|
|
|
makes_footstep_sound = true,
|
|
|
|
drops = {
|
2017-06-23 18:26:00 +02:00
|
|
|
{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-06-29 17:19:48 +02:00
|
|
|
self.max_speed_forward = 7
|
|
|
|
self.max_speed_reverse = 2
|
2017-05-24 21:19:08 -04:00
|
|
|
self.accel = 6
|
|
|
|
self.terrain_type = 3
|
2017-06-29 17:19:48 +02:00
|
|
|
self.driver_attach_at = {x = 0, y = 7.5, z = -1.75}
|
2017-05-24 21:19:08 -04:00
|
|
|
self.driver_eye_offset = {x = 0, y = 3, z = 0}
|
2017-06-27 04:49:07 +02:00
|
|
|
self.driver_scale = {x = 1/self.visual_size.x, y = 1/self.visual_size.y}
|
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-22 22:27:00 -04:00
|
|
|
|
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
|
2017-06-23 18:26:00 +02:00
|
|
|
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
|
2017-06-27 04:49:07 +02:00
|
|
|
if mobs:feed_tame(self, clicker, 1, true, true) then
|
2017-05-24 21:19:08 -04:00
|
|
|
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
|
2017-06-23 18:26:00 +02:00
|
|
|
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
|
2017-06-23 18:26:00 +02:00
|
|
|
minetest.add_item(clicker.getpos(), mobs_mc.items.saddle)
|
2017-05-24 21:19:08 -04:00
|
|
|
end
|
|
|
|
|
2017-06-29 17:38:08 +02:00
|
|
|
-- Update texture
|
|
|
|
local tex = horse_extra_texture(self._naked_texture, false)
|
|
|
|
self.base_texture = { tex }
|
|
|
|
self.object:set_properties({textures = self.base_texture})
|
|
|
|
|
2017-05-24 21:19:08 -04:00
|
|
|
-- attach player to horse
|
|
|
|
elseif not self.driver
|
2017-06-23 18:26:00 +02:00
|
|
|
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
|
2017-06-23 18:26:00 +02:00
|
|
|
inv:remove_item("main", mobs_mc.items.saddle)
|
2017-06-29 17:38:08 +02:00
|
|
|
|
|
|
|
-- Update texture
|
|
|
|
if not self._naked_texture then
|
|
|
|
-- Base horse texture without chest or saddle
|
|
|
|
self._naked_texture = self.base_texture[1]
|
|
|
|
end
|
|
|
|
local tex = horse_extra_texture(self._naked_texture, true)
|
|
|
|
self.base_texture = { tex }
|
|
|
|
self.object:set_properties({textures = self.base_texture})
|
|
|
|
|
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-06-27 03:25:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mobs:register_mob("mobs_mc:horse", horse)
|
|
|
|
|
|
|
|
-- Skeleton horse
|
|
|
|
local skeleton_horse = table.copy(horse)
|
2017-06-27 03:59:03 +02:00
|
|
|
skeleton_horse.textures = {{"mobs_mc_horse_skeleton.png"}}
|
2017-06-27 03:25:42 +02:00
|
|
|
skeleton_horse.drops = {
|
|
|
|
{name = mobs_mc.items.bone,
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,},
|
|
|
|
}
|
|
|
|
skeleton_horse.sounds = {
|
|
|
|
random = "skeleton1",
|
|
|
|
death = "skeletondeath",
|
|
|
|
damage = "skeletonhurt1",
|
2017-06-29 22:01:05 +02:00
|
|
|
distance = 16,
|
2017-06-27 03:25:42 +02:00
|
|
|
}
|
|
|
|
mobs:register_mob("mobs_mc:skeleton_horse", skeleton_horse)
|
|
|
|
|
|
|
|
-- Zombie horse
|
|
|
|
local zombie_horse = table.copy(horse)
|
2017-06-27 03:59:03 +02:00
|
|
|
zombie_horse.textures = {{"mobs_mc_horse_zombie.png"}}
|
2017-06-27 03:25:42 +02:00
|
|
|
zombie_horse.drops = {
|
|
|
|
{name = mobs_mc.items.rotten_flesh,
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,},
|
|
|
|
}
|
|
|
|
zombie_horse.sounds = {
|
|
|
|
random = "zombie1",
|
|
|
|
death = "zombiedeath",
|
|
|
|
damage = "zombiehurt1",
|
2017-06-29 22:01:05 +02:00
|
|
|
distance = 16,
|
2017-06-27 03:25:42 +02:00
|
|
|
}
|
|
|
|
mobs:register_mob("mobs_mc:zombie_horse", zombie_horse)
|
|
|
|
|
2017-06-27 04:16:57 +02:00
|
|
|
-- Donkey
|
|
|
|
local d = 0.86 -- donkey scale
|
|
|
|
local donkey = table.copy(horse)
|
2017-06-29 17:19:48 +02:00
|
|
|
donkey.mesh = "mobs_mc_horse.b3d"
|
2017-06-27 04:16:57 +02:00
|
|
|
donkey.textures = {{"mobs_mc_horse_creamy.png"}}
|
|
|
|
donkey.animation = {
|
2017-06-27 03:25:42 +02:00
|
|
|
speed_normal = 25,
|
|
|
|
stand_start = 0, stand_end = 0,
|
|
|
|
walk_start = 0, walk_end = 40,
|
|
|
|
}
|
2017-06-27 04:16:57 +02:00
|
|
|
donkey.visual_size = { x=horse.visual_size.x*d, y=horse.visual_size.y*d }
|
|
|
|
donkey.collisionbox = {
|
|
|
|
horse.collisionbox[1] * d,
|
|
|
|
horse.collisionbox[2] * d,
|
|
|
|
horse.collisionbox[3] * d,
|
|
|
|
horse.collisionbox[4] * d,
|
|
|
|
horse.collisionbox[5] * d,
|
|
|
|
horse.collisionbox[6] * d,
|
|
|
|
}
|
|
|
|
mobs:register_mob("mobs_mc:donkey", donkey)
|
2017-05-24 21:19:08 -04:00
|
|
|
|
2017-06-27 04:16:57 +02:00
|
|
|
-- Mule
|
|
|
|
local m = 0.94
|
|
|
|
local mule = table.copy(donkey)
|
|
|
|
mule.textures = {{"mobs_mc_mule.png"}}
|
|
|
|
mule.visual_size = { x=horse.visual_size.x*m, y=horse.visual_size.y*m }
|
|
|
|
mule.collisionbox = {
|
|
|
|
horse.collisionbox[1] * m,
|
|
|
|
horse.collisionbox[2] * m,
|
|
|
|
horse.collisionbox[3] * m,
|
|
|
|
horse.collisionbox[4] * m,
|
|
|
|
horse.collisionbox[5] * m,
|
|
|
|
horse.collisionbox[6] * m,
|
|
|
|
}
|
|
|
|
mobs:register_mob("mobs_mc:mule", mule)
|
2016-05-19 19:24:06 -04:00
|
|
|
|
2017-05-24 22:43:25 -04:00
|
|
|
--===========================
|
|
|
|
--Spawn Function
|
2017-06-27 04:16:57 +02:00
|
|
|
mobs:register_spawn("mobs_mc:horse", mobs_mc.spawn.grassland_savanna, minetest.LIGHT_MAX+1, 0, 15000, 12, 31000)
|
|
|
|
mobs:register_spawn("mobs_mc:donkey", mobs_mc.spawn.grassland_savanna, minetest.LIGHT_MAX+1, 0, 15000, 12, 31000)
|
2017-05-24 19:42:03 -04:00
|
|
|
|
|
|
|
|
2017-05-24 22:43:25 -04:00
|
|
|
-- compatibility
|
|
|
|
mobs:alias_mob("mobs:horse", "mobs_mc:horse")
|
2017-05-24 19:42:03 -04:00
|
|
|
|
2017-05-24 22:43:25 -04:00
|
|
|
-- spawn eggs
|
2017-06-27 03:59:03 +02:00
|
|
|
mobs:register_egg("mobs_mc:horse", "Horse", "mobs_mc_spawn_icon_horse.png", 0)
|
|
|
|
mobs:register_egg("mobs_mc:skeleton_horse", "Skeleton Horse", "mobs_mc_spawn_icon_horse_skeleton.png", 0)
|
|
|
|
mobs:register_egg("mobs_mc:zombie_horse", "Zombie Horse", "mobs_mc_spawn_icon_horse_zombie.png", 0)
|
2017-06-27 04:16:57 +02:00
|
|
|
mobs:register_egg("mobs_mc:donkey", "Donkey", "mobs_mc_spawn_icon_donkey.png", 0)
|
2017-06-27 03:59:03 +02:00
|
|
|
mobs:register_egg("mobs_mc:mule", "Mule", "mobs_mc_spawn_icon_mule.png", 0)
|
2016-05-19 19:24:06 -04:00
|
|
|
|
|
|
|
|
2017-06-21 00:20:06 -04:00
|
|
|
if minetest.settings:get_bool("log_mods") then
|
2016-05-19 19:24:06 -04:00
|
|
|
minetest.log("action", "MC Horse loaded")
|
2017-06-06 19:13:16 -04:00
|
|
|
end
|