minetest-mm/mods/mob_horse/init.lua

343 lines
8.2 KiB
Lua
Raw Normal View History

2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
-- translation and get mod path
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
local S = minetest.get_translator("mob_horse")
local MP = minetest.get_modpath(minetest.get_current_modname()) .. "/"
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
-- horse shoes (speed, jump, brake/reverse speed, overlay texture)
2021-10-25 14:38:22 +02:00
2020-10-26 17:38:53 +01:00
local shoes = {
["mobs:horseshoe_steel"] = {7, 4, 2, "mobs_horseshoe_steelo.png"},
["mobs:horseshoe_bronze"] = {7, 4, 4, "mobs_horseshoe_bronzeo.png"},
["mobs:horseshoe_mese"] = {9, 5, 8, "mobs_horseshoe_meseo.png"},
2021-05-16 11:33:49 +02:00
["mobs:horseshoe_diamond"] = {10, 6, 6, "mobs_horseshoe_diamondo.png"},
["mobs:horseshoe_crystal"] = {11, 6, 9, "mobs_horseshoe_crystalo.png"}
2020-10-26 17:38:53 +01:00
}
-- rideable horse
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
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 = {
2024-12-19 12:55:40 +01:00
speed_normal = 15, speed_run = 30,
stand_start = 25, stand_end = 50, -- 75
stand2_start = 25, stand2_end = 25,
stand3_start = 55, stand3_end = 75, stand3_loop = false,
walk_start = 75, walk_end = 100,
run_start = 75, run_end = 100
2020-10-26 17:38:53 +01:00
},
textures = {
{"mobs_horse.png"}, -- textures by Mjollna
{"mobs_horsepeg.png"},
{"mobs_horseara.png"}
},
fear_height = 3,
runaway = true,
fly = false,
walk_chance = 60,
view_range = 5,
follow = {
"farming:wheat", "default:apple", "farming:oat",
2024-12-19 12:55:40 +01:00
"farming:barley", "farming:corn"
},
2020-10-26 17:38:53 +01:00
passive = true,
hp_min = 12,
hp_max = 16,
armor = 200,
lava_damage = 5,
2024-12-19 12:55:40 +01:00
fall_damage = 1,
water_damage = 0,
2020-10-26 17:38:53 +01:00
makes_footstep_sound = true,
drops = {
{name = "mobs:leather", chance = 1, min = 0, max = 2}
},
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
2024-12-19 12:55:40 +01:00
self.driver_attach_at = {x = 0, y = 10, z = -2}
self.driver_eye_offset = {x = 0, y = 10 + 3, z = 0}
2021-06-12 20:20:04 +02:00
self.driver_scale = {x = 0.8, y = 0.8} -- shrink driver to fit model
2020-10-26 17:38:53 +01: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)
2021-06-12 20:20:04 +02:00
-- detach player from horse properly
2020-10-26 17:38:53 +01:00
if self.driver then
mobs.detach(self.driver, {x = 1, y = 0, z = 1})
2021-06-12 20:20:04 +02:00
end
2020-10-26 17:38:53 +01:00
2021-06-12 20:20:04 +02:00
-- drop saddle if found
if self.saddle then
minetest.add_item(pos, "mobs:saddle")
2020-10-26 17:38:53 +01:00
end
-- drop any horseshoes added
if self.shoed then
minetest.add_item(pos, self.shoed)
end
end,
2020-12-14 15:12:06 +01:00
do_punch = function(self, hitter)
-- don't cut the branch you're... ah, that's not about that
if hitter ~= self.driver then
return true
end
end,
2020-10-26 17:38:53 +01:00
on_rightclick = function(self, clicker)
-- make sure player is clicking
2024-12-19 12:55:40 +01:00
if not clicker or not clicker:is_player() then return end
2020-10-26 17:38:53 +01:00
-- feed, tame or heal horse
2024-12-19 12:55:40 +01:00
if mobs:feed_tame(self, clicker, 10, true, true) then return end
2020-10-26 17:38:53 +01:00
-- applying protection rune
2024-12-19 12:55:40 +01:00
if mobs:protect(self, clicker) then return end
2020-10-26 17:38:53 +01:00
2020-12-14 15:12:06 +01:00
local player_name = clicker:get_player_name()
2020-10-26 17:38:53 +01:00
-- make sure tamed horse is being clicked by owner only
2020-12-14 15:12:06 +01:00
if self.tamed and self.owner == player_name then
2020-10-26 17:38:53 +01:00
local inv = clicker:get_inventory()
local tool = clicker:get_wielded_item()
local item = tool:get_name()
-- detatch player already riding horse
if self.driver and clicker == self.driver then
mobs.detach(clicker, {x = 1, y = 0, z = 1})
2021-06-12 20:20:04 +02:00
return
end
2020-10-26 17:38:53 +01:00
2021-06-12 20:20:04 +02:00
-- attach saddle to horse
2024-12-19 12:55:40 +01:00
if not self.driver and not self.child
2021-06-12 20:20:04 +02:00
and clicker:get_wielded_item():get_name() == "mobs:saddle"
and not self.saddle then
2020-10-26 17:38:53 +01:00
2021-06-12 20:20:04 +02:00
self.saddle = true
self.order = "stand"
2024-12-19 12:55:40 +01:00
self.object:set_properties({stepheight = 1.2})
2020-10-26 17:38:53 +01:00
-- take saddle from inventory
2021-06-12 20:20:04 +02:00
inv:remove_item("main", "mobs:saddle")
2020-10-26 17:38:53 +01:00
2021-06-12 20:20:04 +02:00
self.texture_mods = self.texture_mods .. "^mobs_saddle_overlay.png"
self.object:set_texture_mod(self.texture_mods)
return
2020-10-26 17:38:53 +01:00
end
-- apply horseshoes
if item:find("mobs:horseshoe") then
-- drop any existing shoes
if self.shoed then
minetest.add_item(self.object:get_pos(), self.shoed)
end
local speed = shoes[item][1]
local jump = shoes[item][2]
local reverse = shoes[item][3]
local overlay = shoes[item][4]
self.max_speed_forward = speed
self.jump_height = jump
self.max_speed_reverse = reverse
self.accel = speed
self.shoed = item
-- apply horseshoe overlay to current horse texture
if overlay then
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
self.texture_mods = "^" .. overlay
2021-06-12 20:20:04 +02:00
if self.saddle then
self.texture_mods = self.texture_mods
.. "^mobs_saddle_overlay.png"
end
2020-10-26 17:38:53 +01:00
self.object:set_texture_mod(self.texture_mods)
end
-- show horse speed and jump stats with shoes fitted
2020-12-14 15:12:06 +01:00
minetest.chat_send_player(player_name,
2020-10-26 17:38:53 +01:00
S("Horse shoes fitted -")
.. S(" speed: ") .. speed
.. S(" , jump height: ") .. jump
.. S(" , stop speed: ") .. reverse)
2020-12-14 15:12:06 +01:00
tool:take_item()
clicker:set_wielded_item(tool)
2020-10-26 17:38:53 +01:00
return
end
end
-- used to capture horse with magic lasso
2021-06-12 20:20:04 +02:00
if mobs:capture_mob(self, clicker, nil, nil, 100, false, nil) then return end
-- ride horse if saddled
if self.saddle and self.owner == player_name then
mobs.attach(self, clicker)
end
2024-12-19 12:55:40 +01:00
end,
--[[
on_sound = function(self, def)
if def.loudness > 0.8 then -- if loud enough startle horse into jumping
self.object:set_velocity({x = 0, y = 5, z = 0})
end
2021-06-12 20:20:04 +02:00
end
2024-12-19 12:55:40 +01:00
]]
2020-10-26 17:38:53 +01:00
})
2021-10-25 14:38:22 +02:00
-- check for custom spawn.lua
local input = io.open(MP .. "spawn.lua", "r")
if input then
input:close()
input = nil
dofile(MP .. "spawn.lua")
else
mobs:spawn({
name = "mob_horse:horse",
nodes = {"default:dirt_with_grass", "ethereal:dry_dirt"},
min_light = 14,
interval = 60,
chance = 16000,
min_height = 10,
max_height = 31000,
day_toggle = true
})
end
2024-12-19 12:55:40 +01:00
-- spawn egg
2020-10-26 17:38:53 +01:00
mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1)
-- steel horseshoes
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
minetest.register_craftitem(":mobs:horseshoe_steel", {
description = S("Steel HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_steel.png",
})
minetest.register_craft({
output = "mobs:horseshoe_steel",
recipe = {
{"", "default:steelblock", ""},
{"default:steel_ingot", "", "default:steel_ingot"},
2021-10-25 14:38:22 +02:00
{"default:steel_ingot", "", "default:steel_ingot"}
2020-10-26 17:38:53 +01:00
}
})
-- bronze horseshoes
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
minetest.register_craftitem(":mobs:horseshoe_bronze", {
description = S("Bronze HorseShoes (use on horse to apply)"),
2021-10-25 14:38:22 +02:00
inventory_image = "mobs_horseshoe_bronze.png"
2020-10-26 17:38:53 +01:00
})
minetest.register_craft({
output = "mobs:horseshoe_bronze",
recipe = {
{"", "default:bronzeblock", ""},
{"default:bronze_ingot", "", "default:bronze_ingot"},
2021-10-25 14:38:22 +02:00
{"default:bronze_ingot", "", "default:bronze_ingot"}
2020-10-26 17:38:53 +01:00
}
})
-- mese horseshoes
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
minetest.register_craftitem(":mobs:horseshoe_mese", {
description = S("Mese HorseShoes (use on horse to apply)"),
2021-10-25 14:38:22 +02:00
inventory_image = "mobs_horseshoe_mese.png"
2020-10-26 17:38:53 +01:00
})
minetest.register_craft({
output = "mobs:horseshoe_mese",
recipe = {
{"", "default:mese", ""},
{"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"},
2021-10-25 14:38:22 +02:00
{"default:mese_crystal_fragment", "", "default:mese_crystal_fragment"}
2020-10-26 17:38:53 +01:00
}
})
-- diamond horseshoes
2024-12-19 12:55:40 +01:00
2020-10-26 17:38:53 +01:00
minetest.register_craftitem(":mobs:horseshoe_diamond", {
description = S("Diamond HorseShoes (use on horse to apply)"),
2021-10-25 14:38:22 +02:00
inventory_image = "mobs_horseshoe_diamond.png"
2020-10-26 17:38:53 +01:00
})
minetest.register_craft({
output = "mobs:horseshoe_diamond",
recipe = {
{"", "default:diamondblock", ""},
{"default:diamond", "", "default:diamond"},
2021-10-25 14:38:22 +02:00
{"default:diamond", "", "default:diamond"}
2020-10-26 17:38:53 +01:00
}
})
2021-05-16 11:33:49 +02:00
-- crystal horseshoes
2024-12-19 12:55:40 +01:00
if minetest.get_modpath("ethereal") then
2021-05-16 11:33:49 +02:00
2024-12-19 12:55:40 +01:00
minetest.register_craftitem(":mobs:horseshoe_crystal", {
description = S("Crystal HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_crystal.png"
})
2021-05-16 11:33:49 +02:00
2024-12-19 12:55:40 +01:00
minetest.register_craft({
output = "mobs:horseshoe_crystal",
recipe = {
{"", "ethereal:crystal_block", ""},
{"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"},
{"ethereal:crystal_ingot", "", "ethereal:crystal_ingot"}
}
})
2021-05-16 11:33:49 +02:00
end
2020-10-26 17:38:53 +01:00
-- lucky blocks
2024-12-19 12:55:40 +01:00
if minetest.get_modpath("lucky_block") then
2020-10-26 17:38:53 +01:00
2024-12-19 12:55:40 +01:00
lucky_block:add_blocks({
{"dro", {"mobs:horseshoe_steel"}},
{"dro", {"mobs:horseshoe_bronze"}},
{"dro", {"mobs:horseshoe_mese"}},
{"dro", {"mobs:horseshoe_diamond"}},
{"dro", {"mobs:horseshoe_crystal"}}
})
2020-10-26 17:38:53 +01:00
end
2024-12-19 12:55:40 +01:00
print("[MOD] Mobs Redo Horse loaded")