right click horse to apply horseshoes

This commit is contained in:
TenPlus1 2020-03-27 22:21:15 +00:00
parent 5bf8ecbbf1
commit 5414d09a9b
2 changed files with 53 additions and 62 deletions

113
init.lua
View File

@ -10,6 +10,14 @@ if minetest.registered_nodes["default:permafrost"] then
y_off = 10
end
-- horse shoes (speed, jump, break, overlay texture)
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"},
["mobs:horseshoe_diamond"] = {10, 6, 6, "mobs_horseshoe_diamondo.png"}
}
-- rideable horse
@ -117,6 +125,8 @@ mobs:register_mob("mob_horse:horse", {
if self.tamed and self.owner == clicker:get_player_name() then
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
@ -147,11 +157,52 @@ mobs:register_mob("mob_horse:horse", {
self.saddle = true
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
local ov = self.base_texture
ov[1] = ov[1] .. "^" .. overlay
self.object:set_properties({textures = ov})
end
-- show horse speed and jump stats with shoes fitted
minetest.chat_send_player(clicker:get_player_name(),
S("Horse shoes fitted -")
.. S(" speed: ") .. speed
.. S(" , jump height: ") .. jump
.. S(" , stop speed: ") .. reverse)
tool:take_item() ; clicker:set_wielded_item(tool)
return
end
end
-- used to capture horse with magic lasso
mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
end
end,
})
mobs:spawn({
@ -168,58 +219,10 @@ mobs:spawn({
mobs:register_egg("mob_horse:horse", S("Horse"), "wool_brown.png", 1)
-- horseshoe helper function
local apply_shoes = function(name, itemstack, obj, shoes, speed, jump,
reverse, overlay)
if obj.type ~= "object" then return end
local mob = obj.ref
local ent = mob:get_luaentity()
if ent and ent.name and ent.name == "mob_horse:horse" then
if ent.shoed then
minetest.add_item(mob:get_pos(), ent.shoed)
end
ent.max_speed_forward = speed
ent.jump_height = jump
ent.max_speed_reverse = reverse
ent.accel = speed
ent.shoed = shoes
-- apply horseshoe overlay to current horse texture
if overlay then
local ov = ent.base_texture
ov[1] = ov[1] .. "^" .. overlay
mob:set_properties({textures = ov})
end
-- show horse speed and jump stats with shoes fitted
minetest.chat_send_player(name, S("Horse shoes fitted -")
.. S(" speed: ") .. speed
.. S(" , jump height: ") .. jump
.. S(" , stop speed: ") .. reverse)
itemstack:take_item() ; return itemstack
else
minetest.chat_send_player(name, S("Horse shoes only work on horses!"))
end
end
-- steel horseshoes
minetest.register_craftitem(":mobs:horseshoe_steel", {
description = S("Steel HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_steel.png",
on_use = function(itemstack, user, pointed_thing)
return apply_shoes(user:get_player_name(), itemstack, pointed_thing,
"mobs:horseshoe_steel", 7, 4, 2, "mobs_horseshoe_steelo.png")
end,
})
minetest.register_craft({
@ -235,10 +238,6 @@ minetest.register_craft({
minetest.register_craftitem(":mobs:horseshoe_bronze", {
description = S("Bronze HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_bronze.png",
on_use = function(itemstack, user, pointed_thing)
return apply_shoes(user:get_player_name(), itemstack, pointed_thing,
"mobs:horseshoe_bronze", 7, 4, 4, "mobs_horseshoe_bronzeo.png")
end,
})
minetest.register_craft({
@ -254,10 +253,6 @@ minetest.register_craft({
minetest.register_craftitem(":mobs:horseshoe_mese", {
description = S("Mese HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_mese.png",
on_use = function(itemstack, user, pointed_thing)
return apply_shoes(user:get_player_name(), itemstack, pointed_thing,
"mobs:horseshoe_mese", 9, 5, 8, "mobs_horseshoe_meseo.png")
end,
})
minetest.register_craft({
@ -273,10 +268,6 @@ minetest.register_craft({
minetest.register_craftitem(":mobs:horseshoe_diamond", {
description = S("Diamond HorseShoes (use on horse to apply)"),
inventory_image = "mobs_horseshoe_diamond.png",
on_use = function(itemstack, user, pointed_thing)
return apply_shoes(user:get_player_name(), itemstack, pointed_thing,
"mobs:horseshoe_diamond", 10, 6, 6, "mobs_horseshoe_diamondo.png")
end,
})
minetest.register_craft({

View File

@ -9,7 +9,7 @@ Horses can be tamed with 10x wheat or apples which then allows the player to pic
---
### Horseshoes
Horseshoes can be crafted using steel, bronze, mese and diamond (4x ingots - 2 down either side with 1x block top middle) and placed on a horse by punching with the item. These can make horses run faster or jump higher depending on tier.
Horseshoes can be crafted using steel, bronze, mese and diamond (4x ingots - 2 down either side with 1x block top middle) and placed on a horse by right clicking with the item. These can make horses run faster or jump higher while riding depending on tier.
---
### Dead Horse