2017-07-05 01:15:46 +00:00
|
|
|
--MCmobs v0.4
|
|
|
|
--maikerumine
|
|
|
|
--made for MC like Survival game
|
|
|
|
--License for code WTFPL and otherwise stated in readmes
|
|
|
|
|
2022-02-13 20:40:12 +00:00
|
|
|
local S = minetest.get_translator("mobs_mc")
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
--###################
|
|
|
|
--################### HORSE
|
|
|
|
--###################
|
|
|
|
|
|
|
|
-- Return overlay texture for horse/donkey/mule, e.g. chest, saddle or horse armor
|
|
|
|
local horse_extra_texture = function(horse)
|
|
|
|
local base = horse._naked_texture
|
|
|
|
local saddle = horse._saddle
|
|
|
|
local chest = horse._chest
|
|
|
|
local armor = horse._horse_armor
|
2018-05-30 17:51:40 +00:00
|
|
|
local textures = {}
|
|
|
|
if armor and minetest.get_item_group(armor, "horse_armor") > 0 then
|
|
|
|
textures[2] = base .. "^" .. minetest.registered_items[armor]._horse_overlay_image
|
|
|
|
else
|
|
|
|
textures[2] = base
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
if saddle then
|
2018-05-30 17:51:40 +00:00
|
|
|
textures[3] = base
|
|
|
|
else
|
|
|
|
textures[3] = "blank.png"
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
if chest then
|
2018-05-30 17:51:40 +00:00
|
|
|
textures[1] = base
|
|
|
|
else
|
|
|
|
textures[1] = "blank.png"
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
2018-05-30 17:51:40 +00:00
|
|
|
return textures
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
|
2022-10-04 09:36:43 +00:00
|
|
|
|
|
|
|
local function get_drops(self)
|
|
|
|
self.drops = {}
|
|
|
|
table.insert(self.drops,
|
|
|
|
{name = "mcl_mobitems:leather",
|
|
|
|
chance = 1,
|
|
|
|
min = 0,
|
|
|
|
max = 2,
|
|
|
|
looting = "common",
|
|
|
|
})
|
|
|
|
if self._saddle then
|
|
|
|
table.insert(self.drops,{name = "mcl_mobitems:saddle",
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,})
|
|
|
|
end
|
|
|
|
if self._chest then
|
|
|
|
table.insert(self.drops,{name = "mcl_chests:chest",
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Helper functions to determine equipment rules
|
|
|
|
local can_equip_horse_armor = function(entity_id)
|
|
|
|
return entity_id == "mobs_mc:horse" or entity_id == "mobs_mc:skeleton_horse" or entity_id == "mobs_mc:zombie_horse"
|
|
|
|
end
|
2022-02-13 20:40:12 +00:00
|
|
|
local can_equip_chest = function(entity_id)
|
2017-07-05 01:15:46 +00:00
|
|
|
return entity_id == "mobs_mc:mule" or entity_id == "mobs_mc:donkey"
|
2022-02-13 20:40:12 +00:00
|
|
|
end
|
2017-07-05 01:15:46 +00:00
|
|
|
local can_breed = function(entity_id)
|
|
|
|
return entity_id == "mobs_mc:horse" or "mobs_mc:mule" or entity_id == "mobs_mc:donkey"
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[ Generate all possible horse textures.
|
|
|
|
Horse textures are a combination of a base texture and an optional marking overlay. ]]
|
2018-05-30 17:51:40 +00:00
|
|
|
-- The base horse textures (fur) (fur)
|
2017-07-05 01:15:46 +00:00
|
|
|
local horse_base = {
|
|
|
|
"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",
|
2018-06-10 13:51:03 +00:00
|
|
|
"mobs_mc_horse_creamy.png",
|
2017-07-05 01:15:46 +00:00
|
|
|
}
|
|
|
|
-- Horse marking texture overlay, to be appended to the base texture string
|
|
|
|
local horse_markings = {
|
|
|
|
"", -- no markings
|
2018-05-31 12:05:45 +00:00
|
|
|
"mobs_mc_horse_markings_whitedots.png", -- snowflake appaloosa
|
|
|
|
"mobs_mc_horse_markings_blackdots.png", -- sooty
|
|
|
|
"mobs_mc_horse_markings_whitefield.png", -- paint
|
|
|
|
"mobs_mc_horse_markings_white.png", -- stockings and blaze
|
2017-07-05 01:15:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local horse_textures = {}
|
|
|
|
for b=1, #horse_base do
|
|
|
|
for m=1, #horse_markings do
|
2018-05-31 12:05:45 +00:00
|
|
|
local fur = horse_base[b]
|
|
|
|
if horse_markings[m] ~= "" then
|
|
|
|
fur = fur .. "^" .. horse_markings[m]
|
|
|
|
end
|
2018-05-30 17:51:40 +00:00
|
|
|
table.insert(horse_textures, {
|
|
|
|
"blank.png", -- chest
|
2018-05-31 12:05:45 +00:00
|
|
|
fur, -- base texture + markings and optional armor
|
2018-05-30 17:51:40 +00:00
|
|
|
"blank.png", -- saddle
|
|
|
|
})
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-30 00:04:49 +00:00
|
|
|
-- in e7898352d890c2414af653eba624939df9c0b8b4 (0.76-dev) all items from mobs_mc were moved to mcl_mobitems
|
|
|
|
-- this results in existing horses wearing armor would still have the old texture filename in their
|
|
|
|
-- properties this function updates them. It should be removed some time in the future when we can be
|
|
|
|
-- reasonably sure all horses that want it get the new nexture.
|
|
|
|
local function update_textures(self)
|
|
|
|
local old = "mobs_mc_horse_armor_"
|
|
|
|
local txt = self.object:get_properties().textures
|
|
|
|
if txt[2]:find(old) then
|
|
|
|
txt[2] = txt[2]:gsub(old,"mcl_mobitems_horse_armor_")
|
|
|
|
self.object:set_properties({textures=txt})
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Horse
|
|
|
|
local horse = {
|
2021-04-25 15:30:15 +00:00
|
|
|
description = S("Horse"),
|
2017-07-05 01:15:46 +00:00
|
|
|
type = "animal",
|
2020-04-11 00:46:03 +00:00
|
|
|
spawn_class = "passive",
|
2022-07-17 00:20:51 +00:00
|
|
|
spawn_in_group_min = 2,
|
2023-01-28 00:44:48 +00:00
|
|
|
spawn_in_group = 4, -- was 6. nerfed until group size is a cap rather than per spawn cycle
|
2017-07-05 01:15:46 +00:00
|
|
|
visual = "mesh",
|
|
|
|
mesh = "mobs_mc_horse.b3d",
|
|
|
|
visual_size = {x=3.0, y=3.0},
|
|
|
|
collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825},
|
|
|
|
animation = {
|
2018-05-30 17:51:40 +00:00
|
|
|
stand_speed = 25,
|
|
|
|
stand_start = 0,
|
|
|
|
stand_end = 0,
|
|
|
|
walk_speed = 25,
|
|
|
|
walk_start = 0,
|
|
|
|
walk_end = 40,
|
2022-02-13 20:40:12 +00:00
|
|
|
run_speed = 60,
|
2018-05-30 17:51:40 +00:00
|
|
|
run_start = 0,
|
|
|
|
run_end = 40,
|
2017-07-05 01:15:46 +00:00
|
|
|
},
|
|
|
|
textures = horse_textures,
|
2018-09-18 12:23:11 +00:00
|
|
|
sounds = {
|
|
|
|
random = "mobs_mc_horse_random",
|
|
|
|
-- TODO: Separate damage sound
|
|
|
|
damage = "mobs_mc_horse_death",
|
|
|
|
death = "mobs_mc_horse_death",
|
2020-12-05 22:37:12 +00:00
|
|
|
eat = "mobs_mc_animal_eat_generic",
|
2018-09-18 12:23:11 +00:00
|
|
|
distance = 16,
|
|
|
|
},
|
2017-07-05 01:15:46 +00:00
|
|
|
fear_height = 4,
|
|
|
|
fly = false,
|
|
|
|
walk_chance = 60,
|
|
|
|
view_range = 16,
|
2022-05-25 21:25:15 +00:00
|
|
|
follow = {
|
|
|
|
"mcl_core:apple",
|
|
|
|
"mcl_core:sugar",
|
|
|
|
"mcl_farming:wheat_item",
|
|
|
|
"mcl_farming:hay_block",
|
|
|
|
"mcl_core:apple_gold",
|
|
|
|
"mcl_farming:carrot_item_gold",
|
|
|
|
},
|
2017-07-05 01:15:46 +00:00
|
|
|
passive = true,
|
|
|
|
hp_min = 15,
|
|
|
|
hp_max = 30,
|
2020-12-06 14:46:42 +00:00
|
|
|
xp_min = 1,
|
|
|
|
xp_max = 3,
|
2017-07-05 01:15:46 +00:00
|
|
|
floats = 1,
|
|
|
|
makes_footstep_sound = true,
|
|
|
|
jump = true,
|
|
|
|
jump_height = 5.75, -- can clear 2.5 blocks
|
|
|
|
drops = {
|
2022-05-25 21:25:15 +00:00
|
|
|
{name = "mcl_mobitems:leather",
|
2017-07-05 01:15:46 +00:00
|
|
|
chance = 1,
|
|
|
|
min = 0,
|
2020-12-23 16:41:42 +00:00
|
|
|
max = 2,
|
|
|
|
looting = "common",},
|
2017-07-05 01:15:46 +00:00
|
|
|
},
|
2022-05-30 00:04:49 +00:00
|
|
|
on_spawn = update_textures,
|
2017-07-05 01:15:46 +00:00
|
|
|
do_custom = function(self, dtime)
|
|
|
|
|
2022-10-28 01:57:15 +00:00
|
|
|
if not self._horse_speed then
|
|
|
|
self._horse_speed = math.random(486, 1457)/100
|
2022-10-28 02:00:39 +00:00
|
|
|
elseif self.run_velocity ~= self._horse_speed then
|
2022-10-28 01:57:15 +00:00
|
|
|
self.run_velocity = self._horse_speed
|
|
|
|
end
|
|
|
|
|
2017-07-05 01:15:46 +00:00
|
|
|
-- set needed values if not already present
|
|
|
|
if not self._regentimer then
|
|
|
|
self._regentimer = 0
|
|
|
|
end
|
|
|
|
if not self.v2 then
|
|
|
|
self.v2 = 0
|
|
|
|
self.max_speed_forward = 7
|
|
|
|
self.max_speed_reverse = 2
|
|
|
|
self.accel = 6
|
|
|
|
self.terrain_type = 3
|
2019-03-06 04:11:49 +00:00
|
|
|
self.driver_attach_at = {x = 0, y = 4.17, z = -1.75}
|
2017-07-05 01:15:46 +00:00
|
|
|
self.driver_eye_offset = {x = 0, y = 3, z = 0}
|
|
|
|
self.driver_scale = {x = 1/self.visual_size.x, y = 1/self.visual_size.y}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Slowly regenerate health
|
|
|
|
self._regentimer = self._regentimer + dtime
|
|
|
|
if self._regentimer >= 4 then
|
|
|
|
if self.health < self.hp_max then
|
|
|
|
self.health = self.health + 1
|
|
|
|
end
|
|
|
|
self._regentimer = 0
|
|
|
|
end
|
|
|
|
|
2021-04-04 20:24:28 +00:00
|
|
|
-- Some weird human is riding. Buck them off?
|
|
|
|
if self.driver and not self.tamed and self.buck_off_time <= 0 then
|
|
|
|
if math.random() < 0.2 then
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.detach(self.driver, {x = 1, y = 0, z = 1})
|
2021-04-04 20:24:28 +00:00
|
|
|
-- TODO bucking animation
|
|
|
|
else
|
|
|
|
-- Nah, can't be bothered. Think about it again in one second
|
|
|
|
self.buck_off_time = 20
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Tick the timer for trying to buck the player off
|
|
|
|
if self.buck_off_time then
|
|
|
|
if self.driver then
|
|
|
|
self.buck_off_time = self.buck_off_time - 1
|
|
|
|
else
|
|
|
|
-- Player isn't riding anymore so no need to count
|
|
|
|
self.buck_off_time = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- if driver present and horse has a saddle allow control of horse
|
|
|
|
if self.driver and self._saddle then
|
2017-07-05 01:15:46 +00:00
|
|
|
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.drive(self, "walk", "stand", false, dtime)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
return false -- skip rest of mob functions
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_die = function(self, pos)
|
|
|
|
|
|
|
|
-- drop saddle when horse is killed while riding
|
|
|
|
if self._saddle then
|
2022-05-25 21:25:15 +00:00
|
|
|
minetest.add_item(pos, "mcl_mobitems:saddle")
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
-- also detach from horse properly
|
|
|
|
if self.driver then
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.detach(self.driver, {x = 1, y = 0, z = 1})
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(self, clicker)
|
|
|
|
|
|
|
|
-- make sure player is clicking
|
|
|
|
if not clicker or not clicker:is_player() then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local item = clicker:get_wielded_item()
|
2020-02-23 16:13:52 +00:00
|
|
|
local iname = item:get_name()
|
|
|
|
local heal = 0
|
2021-04-04 20:24:28 +00:00
|
|
|
|
2022-10-01 02:27:58 +00:00
|
|
|
if self._inv_id then
|
2022-10-01 09:33:59 +00:00
|
|
|
if not self._chest and item:get_name() == "mcl_chests:chest" then
|
2022-10-01 02:27:58 +00:00
|
|
|
item:take_item()
|
|
|
|
clicker:set_wielded_item(item)
|
2022-10-01 09:33:59 +00:00
|
|
|
self._chest = true
|
|
|
|
-- Update texture
|
|
|
|
if not self._naked_texture then
|
|
|
|
-- Base horse texture without chest or saddle
|
|
|
|
self._naked_texture = self.base_texture[2]
|
|
|
|
end
|
|
|
|
local tex = horse_extra_texture(self)
|
|
|
|
self.base_texture = tex
|
|
|
|
self.object:set_properties({textures = self.base_texture})
|
2022-10-04 09:36:43 +00:00
|
|
|
get_drops(self)
|
2022-10-01 21:47:06 +00:00
|
|
|
return
|
2022-10-01 09:33:59 +00:00
|
|
|
elseif self._chest and clicker:get_player_control().sneak then
|
2022-10-01 21:47:06 +00:00
|
|
|
mcl_entity_invs.show_inv_form(self,clicker)
|
2022-10-01 02:27:58 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-04 20:24:28 +00:00
|
|
|
-- Taming
|
|
|
|
self.temper = self.temper or (math.random(1,100))
|
|
|
|
|
|
|
|
if not self.tamed then
|
|
|
|
local temper_increase = 0
|
|
|
|
|
|
|
|
-- Feeding, intentionally not using mobs:feed_tame because horse taming is
|
|
|
|
-- different and more complicated
|
2022-05-25 21:25:15 +00:00
|
|
|
if (iname == "mcl_core:sugar") then
|
2021-04-04 20:24:28 +00:00
|
|
|
temper_increase = 3
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_farming:wheat_item") then
|
2021-04-04 20:24:28 +00:00
|
|
|
temper_increase = 3
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_core:apple") then
|
2021-04-04 20:24:28 +00:00
|
|
|
temper_increase = 3
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_farming:carrot_item_gold") then
|
2021-04-04 20:24:28 +00:00
|
|
|
temper_increase = 5
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_core:apple_gold") then
|
2021-04-04 20:24:28 +00:00
|
|
|
temper_increase = 10
|
|
|
|
-- Trying to ride
|
|
|
|
elseif not self.driver then
|
|
|
|
self.object:set_properties({stepheight = 1.1})
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.attach(self, clicker)
|
2021-04-04 20:24:28 +00:00
|
|
|
self.buck_off_time = 40 -- TODO how long does it take in minecraft?
|
|
|
|
if self.temper > 100 then
|
|
|
|
self.tamed = true -- NOTE taming can only be finished by riding the horse
|
|
|
|
if not self.owner or self.owner == "" then
|
|
|
|
self.owner = clicker:get_player_name()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
temper_increase = 5
|
|
|
|
|
|
|
|
-- Clicking on the horse while riding ==> unmount
|
|
|
|
elseif self.driver and self.driver == clicker then
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.detach(clicker, {x = 1, y = 0, z = 1})
|
2021-04-04 20:24:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- If nothing happened temper_increase = 0 and addition does nothing
|
|
|
|
self.temper = self.temper + temper_increase
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-02-23 16:13:52 +00:00
|
|
|
if can_breed(self.name) then
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Breed horse with golden apple or golden carrot
|
2022-05-25 21:25:15 +00:00
|
|
|
if (iname == "mcl_core:apple_gold") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 10
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_farming:carrot_item_gold") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 4
|
|
|
|
end
|
2022-11-09 03:57:48 +00:00
|
|
|
if heal > 0 and self:feed_tame(clicker, heal, true, false) then
|
2020-02-23 16:13:52 +00:00
|
|
|
return
|
|
|
|
end
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
2021-04-04 20:24:28 +00:00
|
|
|
-- Feed with anything else
|
|
|
|
-- TODO heal amounts don't work
|
2022-05-25 21:25:15 +00:00
|
|
|
if (iname == "mcl_core:sugar") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 1
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_farming:wheat_item") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 2
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_core:apple") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 3
|
2022-05-25 21:25:15 +00:00
|
|
|
elseif (iname == "mcl_farming:hay_block") then
|
2020-02-23 16:13:52 +00:00
|
|
|
heal = 20
|
|
|
|
end
|
2022-11-09 03:57:48 +00:00
|
|
|
if heal > 0 and self:feed_tame(clicker, heal, false, false) then
|
2020-02-23 16:13:52 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-05-25 12:44:49 +00:00
|
|
|
if mcl_mobs:protect(self, clicker) then
|
2022-02-13 20:40:12 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Make sure tamed horse is mature and being clicked by owner only
|
|
|
|
if self.tamed and not self.child and self.owner == clicker:get_player_name() then
|
|
|
|
|
2022-02-13 20:40:12 +00:00
|
|
|
local inv = clicker:get_inventory()
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- detatch player already riding horse
|
|
|
|
if self.driver and clicker == self.driver then
|
|
|
|
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.detach(clicker, {x = 1, y = 0, z = 1})
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Put on saddle if tamed
|
|
|
|
elseif not self.driver and not self._saddle
|
2022-05-25 21:25:15 +00:00
|
|
|
and iname == "mcl_mobitems:saddle" then
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Put on saddle and take saddle from player's inventory
|
|
|
|
local w = clicker:get_wielded_item()
|
|
|
|
self._saddle = true
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2017-07-05 01:15:46 +00:00
|
|
|
w:take_item()
|
|
|
|
clicker:set_wielded_item(w)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Update texture
|
|
|
|
if not self._naked_texture then
|
|
|
|
-- Base horse texture without chest or saddle
|
2018-05-30 17:51:40 +00:00
|
|
|
self._naked_texture = self.base_texture[2]
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
local tex = horse_extra_texture(self)
|
2018-05-30 17:51:40 +00:00
|
|
|
self.base_texture = tex
|
2017-07-05 01:15:46 +00:00
|
|
|
self.object:set_properties({textures = self.base_texture})
|
2020-04-06 22:55:45 +00:00
|
|
|
minetest.sound_play({name = "mcl_armor_equip_leather"}, {gain=0.5, max_hear_distance=12, pos=self.object:get_pos()}, true)
|
2022-10-04 09:36:43 +00:00
|
|
|
get_drops(self)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Put on horse armor if tamed
|
|
|
|
elseif can_equip_horse_armor(self.name) and not self.driver and not self._horse_armor
|
2020-02-23 16:13:52 +00:00
|
|
|
and minetest.get_item_group(iname, "horse_armor") > 0 then
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- Put on armor and take armor from player's inventory
|
2020-02-23 16:13:52 +00:00
|
|
|
local armor = minetest.get_item_group(iname, "horse_armor")
|
|
|
|
self._horse_armor = iname
|
2020-04-08 00:29:12 +00:00
|
|
|
local w = clicker:get_wielded_item()
|
2020-07-10 14:08:40 +00:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2017-07-05 01:15:46 +00:00
|
|
|
w:take_item()
|
|
|
|
clicker:set_wielded_item(w)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Set horse armor strength
|
|
|
|
self.armor = armor
|
|
|
|
local agroups = self.object:get_armor_groups()
|
|
|
|
agroups.fleshy = self.armor
|
|
|
|
self.object:set_armor_groups(agroups)
|
|
|
|
|
|
|
|
-- Update texture
|
|
|
|
if not self._naked_texture then
|
|
|
|
-- Base horse texture without chest or saddle
|
2018-05-30 17:51:40 +00:00
|
|
|
self._naked_texture = self.base_texture[2]
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
local tex = horse_extra_texture(self)
|
2018-05-30 17:51:40 +00:00
|
|
|
self.base_texture = tex
|
2017-07-05 01:15:46 +00:00
|
|
|
self.object:set_properties({textures = self.base_texture})
|
2020-02-18 22:49:35 +00:00
|
|
|
local def = w:get_definition()
|
|
|
|
if def.sounds and def.sounds._mcl_armor_equip then
|
2020-04-06 22:55:45 +00:00
|
|
|
minetest.sound_play({name = def.sounds._mcl_armor_equip}, {gain=0.5, max_hear_distance=12, pos=self.object:get_pos()}, true)
|
2020-02-18 22:49:35 +00:00
|
|
|
end
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Mount horse
|
|
|
|
elseif not self.driver and self._saddle then
|
|
|
|
|
|
|
|
self.object:set_properties({stepheight = 1.1})
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs.attach(self, clicker)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
2022-02-13 20:40:12 +00:00
|
|
|
-- Used to capture horse
|
|
|
|
elseif not self.driver and iname ~= "" then
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
|
2017-07-05 01:15:46 +00:00
|
|
|
end
|
|
|
|
end
|
2018-05-30 10:34:16 +00:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_breed = function(parent1, parent2)
|
|
|
|
local pos = parent1.object:get_pos()
|
2022-11-27 20:14:19 +00:00
|
|
|
local child = mcl_mobs.spawn_child(pos, parent1.name)
|
2018-05-31 02:38:37 +00:00
|
|
|
if child then
|
|
|
|
local ent_c = child:get_luaentity()
|
|
|
|
local p = math.random(1, 2)
|
2018-05-31 12:05:45 +00:00
|
|
|
local child_texture
|
|
|
|
-- Randomly pick one of the parents for the child texture
|
2018-05-31 02:38:37 +00:00
|
|
|
if p == 1 then
|
2018-05-31 12:05:45 +00:00
|
|
|
if parent1._naked_texture then
|
|
|
|
child_texture = parent1._naked_texture
|
|
|
|
else
|
|
|
|
child_texture = parent1.base_texture[2]
|
|
|
|
end
|
2018-05-31 02:38:37 +00:00
|
|
|
else
|
2018-05-31 12:05:45 +00:00
|
|
|
if parent2._naked_texture then
|
|
|
|
child_texture = parent2._naked_texture
|
|
|
|
else
|
|
|
|
child_texture = parent2.base_texture[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local splt = string.split(child_texture, "^")
|
|
|
|
if #splt >= 2 then
|
|
|
|
-- Randomly mutate base texture (fur) and markings
|
|
|
|
-- with chance of 1/9 each
|
|
|
|
local base = splt[1]
|
|
|
|
local markings = splt[2]
|
|
|
|
local mutate_base = math.random(1, 9)
|
|
|
|
local mutate_markings = math.random(1, 9)
|
|
|
|
if mutate_base == 1 then
|
|
|
|
local b = math.random(1, #horse_base)
|
|
|
|
base = horse_base[b]
|
|
|
|
end
|
|
|
|
if mutate_markings == 1 then
|
|
|
|
local m = math.random(1, #horse_markings)
|
|
|
|
markings = horse_markings[m]
|
|
|
|
end
|
|
|
|
child_texture = base
|
|
|
|
if markings ~= "" then
|
|
|
|
child_texture = child_texture .. "^" .. markings
|
|
|
|
end
|
2018-05-31 02:38:37 +00:00
|
|
|
end
|
2018-05-31 12:05:45 +00:00
|
|
|
ent_c.base_texture = { "blank.png", child_texture, "blank.png" }
|
|
|
|
ent_c._naked_texture = child_texture
|
|
|
|
|
2018-05-31 02:38:37 +00:00
|
|
|
child:set_properties({textures = ent_c.base_texture})
|
2018-05-30 10:56:39 +00:00
|
|
|
return false
|
|
|
|
end
|
2018-05-30 10:34:16 +00:00
|
|
|
end,
|
2017-07-05 01:15:46 +00:00
|
|
|
}
|
|
|
|
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_mob("mobs_mc:horse", horse)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Skeleton horse
|
|
|
|
local skeleton_horse = table.copy(horse)
|
2021-04-25 15:30:15 +00:00
|
|
|
skeleton_horse.description = S("Skeleton Horse")
|
2019-10-02 16:31:16 +00:00
|
|
|
skeleton_horse.breath_max = -1
|
2020-11-09 17:59:08 +00:00
|
|
|
skeleton_horse.armor = {undead = 100, fleshy = 100}
|
2018-05-30 17:51:40 +00:00
|
|
|
skeleton_horse.textures = {{"blank.png", "mobs_mc_horse_skeleton.png", "blank.png"}}
|
2017-07-05 01:15:46 +00:00
|
|
|
skeleton_horse.drops = {
|
2022-05-25 21:25:15 +00:00
|
|
|
{name = "mcl_mobitems:bone",
|
2017-07-05 01:15:46 +00:00
|
|
|
chance = 1,
|
|
|
|
min = 0,
|
|
|
|
max = 2,},
|
|
|
|
}
|
|
|
|
skeleton_horse.sounds = {
|
2018-09-14 13:58:31 +00:00
|
|
|
random = "mobs_mc_skeleton_random",
|
|
|
|
death = "mobs_mc_skeleton_death",
|
|
|
|
damage = "mobs_mc_skeleton_hurt",
|
2020-12-05 22:37:12 +00:00
|
|
|
eat = "mobs_mc_animal_eat_generic",
|
2020-12-05 22:55:30 +00:00
|
|
|
base_pitch = 0.95,
|
2017-07-05 01:15:46 +00:00
|
|
|
distance = 16,
|
|
|
|
}
|
2020-07-12 20:56:41 +00:00
|
|
|
skeleton_horse.harmed_by_heal = true
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_mob("mobs_mc:skeleton_horse", skeleton_horse)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Zombie horse
|
|
|
|
local zombie_horse = table.copy(horse)
|
2021-04-25 15:30:15 +00:00
|
|
|
zombie_horse.description = S("Zombie Horse")
|
2019-10-02 16:31:16 +00:00
|
|
|
zombie_horse.breath_max = -1
|
2020-11-09 17:59:08 +00:00
|
|
|
zombie_horse.armor = {undead = 100, fleshy = 100}
|
2018-05-30 17:51:40 +00:00
|
|
|
zombie_horse.textures = {{"blank.png", "mobs_mc_horse_zombie.png", "blank.png"}}
|
2017-07-05 01:15:46 +00:00
|
|
|
zombie_horse.drops = {
|
2022-05-25 21:25:15 +00:00
|
|
|
{name = "mcl_mobitems:rotten_flesh",
|
2017-07-05 01:15:46 +00:00
|
|
|
chance = 1,
|
|
|
|
min = 0,
|
|
|
|
max = 2,},
|
|
|
|
}
|
|
|
|
zombie_horse.sounds = {
|
2020-12-05 22:55:30 +00:00
|
|
|
random = "mobs_mc_horse_random",
|
|
|
|
-- TODO: Separate damage sound
|
|
|
|
damage = "mobs_mc_horse_death",
|
|
|
|
death = "mobs_mc_horse_death",
|
2020-12-05 22:37:12 +00:00
|
|
|
eat = "mobs_mc_animal_eat_generic",
|
2020-12-05 22:55:30 +00:00
|
|
|
base_pitch = 0.5,
|
2017-07-05 01:15:46 +00:00
|
|
|
distance = 16,
|
|
|
|
}
|
2020-07-12 20:56:41 +00:00
|
|
|
zombie_horse.harmed_by_heal = true
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_mob("mobs_mc:zombie_horse", zombie_horse)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- Donkey
|
|
|
|
local d = 0.86 -- donkey scale
|
|
|
|
local donkey = table.copy(horse)
|
2021-04-25 15:30:15 +00:00
|
|
|
donkey.description = S("Donkey")
|
2018-05-30 17:51:40 +00:00
|
|
|
donkey.textures = {{"blank.png", "mobs_mc_donkey.png", "blank.png"}}
|
2022-07-17 00:20:51 +00:00
|
|
|
donkey.spawn_in_group = 3
|
|
|
|
donkey.spawn_in_group_min = 1
|
2017-07-05 01:15:46 +00:00
|
|
|
donkey.animation = {
|
|
|
|
speed_normal = 25,
|
|
|
|
stand_start = 0, stand_end = 0,
|
|
|
|
walk_start = 0, walk_end = 40,
|
|
|
|
}
|
2020-12-05 17:29:35 +00:00
|
|
|
donkey.sounds = {
|
|
|
|
random = "mobs_mc_donkey_random",
|
|
|
|
damage = "mobs_mc_donkey_hurt",
|
|
|
|
death = "mobs_mc_donkey_death",
|
2020-12-05 22:37:12 +00:00
|
|
|
eat = "mobs_mc_animal_eat_generic",
|
2020-12-05 17:29:35 +00:00
|
|
|
distance = 16,
|
|
|
|
}
|
2017-07-05 01:15:46 +00: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,
|
|
|
|
}
|
|
|
|
donkey.jump = true
|
|
|
|
donkey.jump_height = 3.75 -- can clear 1 block height
|
|
|
|
|
|
|
|
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_mob("mobs_mc:donkey", donkey)
|
2022-10-01 02:27:58 +00:00
|
|
|
mcl_entity_invs.register_inv("mobs_mc:donkey","Donkey",15,true)
|
2017-07-05 01:15:46 +00:00
|
|
|
-- Mule
|
|
|
|
local m = 0.94
|
|
|
|
local mule = table.copy(donkey)
|
2021-04-25 15:30:15 +00:00
|
|
|
mule.description = S("Mule")
|
2018-05-30 17:51:40 +00:00
|
|
|
mule.textures = {{"blank.png", "mobs_mc_mule.png", "blank.png"}}
|
2017-07-05 01:15:46 +00:00
|
|
|
mule.visual_size = { x=horse.visual_size.x*m, y=horse.visual_size.y*m }
|
2020-12-05 18:48:51 +00:00
|
|
|
mule.sounds = table.copy(donkey.sounds)
|
|
|
|
mule.sounds.base_pitch = 1.15
|
2017-07-05 01:15:46 +00:00
|
|
|
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,
|
|
|
|
}
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_mob("mobs_mc:mule", mule)
|
2022-10-01 21:47:06 +00:00
|
|
|
mcl_entity_invs.register_inv("mobs_mc:mule","Mule",15,true)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
--===========================
|
|
|
|
--Spawn Function
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs:spawn_specific(
|
2021-04-08 11:39:18 +00:00
|
|
|
"mobs_mc:horse",
|
|
|
|
"overworld",
|
|
|
|
"ground",
|
|
|
|
{
|
2022-03-22 14:16:48 +00:00
|
|
|
"flat",
|
|
|
|
"Plains",
|
|
|
|
"Plains_beach",
|
|
|
|
"SunflowerPlains",
|
|
|
|
"Savanna",
|
|
|
|
"Savanna_beach",
|
|
|
|
"SavannaM",
|
2022-06-14 10:32:08 +00:00
|
|
|
"Savanna_beach",
|
|
|
|
"Plains_beach",
|
2021-04-08 11:39:18 +00:00
|
|
|
},
|
2021-04-25 15:30:15 +00:00
|
|
|
0,
|
|
|
|
minetest.LIGHT_MAX+1,
|
|
|
|
30,
|
|
|
|
15000,
|
|
|
|
4,
|
2022-05-25 21:25:15 +00:00
|
|
|
mobs_mc.water_level+3,
|
|
|
|
mcl_vars.mg_overworld_max)
|
2021-04-08 11:39:18 +00:00
|
|
|
|
2022-05-25 12:44:49 +00:00
|
|
|
mcl_mobs:spawn_specific(
|
2021-04-25 15:30:15 +00:00
|
|
|
"mobs_mc:donkey",
|
|
|
|
"overworld",
|
2021-04-08 11:39:18 +00:00
|
|
|
"ground",
|
|
|
|
{
|
2022-06-14 10:32:08 +00:00
|
|
|
"flat",
|
|
|
|
"Plains",
|
|
|
|
"Plains_beach",
|
|
|
|
"SunflowerPlains",
|
|
|
|
"Savanna",
|
|
|
|
"Savanna_beach",
|
|
|
|
"SavannaM",
|
|
|
|
"Savanna_beach",
|
|
|
|
"Plains_beach",
|
2021-04-08 11:39:18 +00:00
|
|
|
},
|
2022-07-17 13:33:06 +00:00
|
|
|
9,
|
2021-04-25 15:30:15 +00:00
|
|
|
minetest.LIGHT_MAX+1,
|
|
|
|
30,
|
|
|
|
15000,
|
|
|
|
4,
|
2022-05-25 21:25:15 +00:00
|
|
|
mobs_mc.water_level+3,
|
|
|
|
mcl_vars.mg_overworld_max)
|
2017-07-05 01:15:46 +00:00
|
|
|
|
|
|
|
-- spawn eggs
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_egg("mobs_mc:horse", S("Horse"), "#c09e7d", "#eee500", 0)
|
|
|
|
mcl_mobs.register_egg("mobs_mc:skeleton_horse", S("Skeleton Horse"), "#68684f", "#e5e5d8", 0)
|
2022-10-03 17:52:22 +00:00
|
|
|
--mobs:register_egg("mobs_mc:zombie_horse", S("Zombie Horse"), "#2a5a37", "#84d080", 0)
|
2022-11-09 03:09:58 +00:00
|
|
|
mcl_mobs.register_egg("mobs_mc:donkey", S("Donkey"), "#534539", "#867566", 0)
|
|
|
|
mcl_mobs.register_egg("mobs_mc:mule", S("Mule"), "#1b0200", "#51331d", 0)
|