forked from VoxeLibre/VoxeLibre
basic dyable armors
This commit is contained in:
parent
896b213f17
commit
2d585c9517
|
@ -3,6 +3,7 @@ local ARMOR_INIT_TIMES = 1
|
|||
local ARMOR_BONES_DELAY = 1
|
||||
|
||||
local skin_mod = nil
|
||||
local has_shield = minetest.get_modpath("shields") --avoid multiple calls to minetest.get_modpath()
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
|
@ -147,10 +148,23 @@ armor.set_player_armor = function(self, player)
|
|||
if v == false then
|
||||
local level = def.groups["armor_"..k]
|
||||
if level then
|
||||
local texture = def.texture or item:gsub("%:", "_")
|
||||
local texture
|
||||
if def.texture then
|
||||
texture = def.texture
|
||||
--minetest.chat_send_all("if "..texture)
|
||||
elseif def.groups.enchanted == 1 then
|
||||
texture = minetest.registered_items[def._mcl_enchanting_enchanted_tool].texture or def._mcl_enchanting_enchanted_tool:gsub("_enchanted", "")..".png"
|
||||
--minetest.chat_send_all(def._mcl_enchanting_enchanted_tool..".png") --DEBUG
|
||||
--minetest.chat_send_all("elseif "..texture)
|
||||
else
|
||||
texture = item:gsub("%:", "_")..".png"
|
||||
--minetest.chat_send_all("else "..texture)
|
||||
end
|
||||
--minetest.chat_send_all(texture) --DEBUG
|
||||
local enchanted_addition = (mcl_enchanting.is_enchanted(item) and mcl_enchanting.overlay or "")
|
||||
table.insert(textures, "("..texture..".png"..enchanted_addition..")")
|
||||
preview = "(player.png^[opacity:0^"..texture.."_preview.png"..enchanted_addition..")"..(preview and "^"..preview or "")
|
||||
table.insert(textures, texture..enchanted_addition)
|
||||
--minetest.chat_send_all(texture..enchanted_addition) --DEBUG
|
||||
preview = "(player.png^[opacity:0^"..(def.preview or item:gsub("%:", "_").."_preview.png")..enchanted_addition..")"..(preview and "^"..preview or "")
|
||||
armor_level = armor_level + level
|
||||
items = items + 1
|
||||
mcl_armor_points = mcl_armor_points + (def.groups["mcl_armor_points"] or 0)
|
||||
|
@ -175,7 +189,7 @@ armor.set_player_armor = function(self, player)
|
|||
end
|
||||
end
|
||||
preview = (armor:get_preview(name) or "character_preview.png")..(preview and "^"..preview or "")
|
||||
if minetest.get_modpath("shields") then
|
||||
if has_shield then
|
||||
armor_level = armor_level * 0.9
|
||||
end
|
||||
if material.type and material.count == #self.elements then
|
||||
|
|
|
@ -391,4 +391,5 @@ for k, v in pairs(craft_ingreds) do
|
|||
end
|
||||
end
|
||||
|
||||
dofile(modpath.."/leather.lua")
|
||||
dofile(modpath.."/alias.lua")
|
|
@ -0,0 +1,264 @@
|
|||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
local colorize_value = 50
|
||||
|
||||
local longdesc = S("This is a piece of equippable armor which reduces the amount of damage you receive.")
|
||||
local usage = S("To equip it, put it on the corresponding armor slot in your inventory menu.")
|
||||
|
||||
local colors = {
|
||||
-- { ID, decription, wool, dye }
|
||||
{ "red", "Red", "mcl_dye:red" },
|
||||
{ "blue", "Blue", "mcl_dye:blue" },
|
||||
{ "cyan", "Cyan", "mcl_dye:cyan" },
|
||||
{ "grey", "Grey", "mcl_dye:dark_grey" },
|
||||
{ "silver", "Light Grey", "mcl_dye:grey" },
|
||||
{ "black", "Black", "mcl_dye:black" },
|
||||
{ "yellow", "Yellow", "mcl_dye:yellow" },
|
||||
{ "green", "Green", "mcl_dye:dark_green" },
|
||||
{ "magenta", "Magenta", "mcl_dye:magenta" },
|
||||
{ "orange", "Orange", "mcl_dye:orange" },
|
||||
{ "purple", "Purple", "mcl_dye:violet" },
|
||||
{ "brown", "Brown", "mcl_dye:brown" },
|
||||
{ "pink", "Pink", "mcl_dye:pink" },
|
||||
{ "lime", "Lime", "mcl_dye:green" },
|
||||
{ "light_blue", "Light Blue", "mcl_dye:lightblue" },
|
||||
{ "white", "White", "mcl_dye:white" },
|
||||
}
|
||||
local function get_on_armor_leather_use(itemname, raw)
|
||||
local function on_armor_leather_use(itemstack, user, pointed_thing)
|
||||
if not user or user:is_player() == false then
|
||||
return itemstack
|
||||
end
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
if pointed_thing.type == "node" then
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if minetest.get_item_group(node.name, "cauldron") ~= 0 then
|
||||
itemstack:set_name(raw)
|
||||
return itemstack
|
||||
end
|
||||
if user and not user:get_player_control().sneak then
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local name, player_inv, armor_inv = armor:get_valid_player(user, "[on_armor_use]")
|
||||
if not name then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local def = itemstack:get_definition()
|
||||
local slot
|
||||
if def.groups and def.groups.armor_head then
|
||||
slot = 2
|
||||
elseif def.groups and def.groups.armor_torso then
|
||||
slot = 3
|
||||
elseif def.groups and def.groups.armor_legs then
|
||||
slot = 4
|
||||
elseif def.groups and def.groups.armor_feet then
|
||||
slot = 5
|
||||
end
|
||||
|
||||
if slot then
|
||||
local itemstack_single = ItemStack(itemstack)
|
||||
itemstack_single:set_count(1)
|
||||
local itemstack_slot = armor_inv:get_stack("armor", slot)
|
||||
if itemstack_slot:is_empty() then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(itemstack_single, user)
|
||||
itemstack:take_item()
|
||||
elseif itemstack:get_count() <= 1 and not mcl_enchanting.has_enchantment(itemstack_slot, "curse_of_binding") then
|
||||
armor_inv:set_stack("armor", slot, itemstack_single)
|
||||
player_inv:set_stack("armor", slot, itemstack_single)
|
||||
armor:set_player_armor(user)
|
||||
armor:update_inventory(user)
|
||||
armor:play_equip_sound(itemstack_single, user)
|
||||
itemstack = ItemStack(itemstack_slot)
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
return on_armor_leather_use
|
||||
end
|
||||
|
||||
local itemcount = 0
|
||||
for _,first_color in ipairs(colors) do
|
||||
local itemname = "mcl_armor:helmet_leather_"..first_color[1]
|
||||
minetest.register_tool(itemname, {
|
||||
description = S("Leather Cap "..first_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_helmet_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
texture = "mcl_armor_helmet_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
groups = {armor_head=1, mcl_armor_points=1, mcl_armor_uses=56, enchantability=15}, --TODO: add not_in_creative_inventory=1
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:helmet_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:helmet_leather"),
|
||||
})
|
||||
local itemname = "mcl_armor:chestplate_leather_"..first_color[1]
|
||||
minetest.register_tool(itemname, {
|
||||
description = S("Leather Tunic "..first_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_chestplate_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
texture = "mcl_armor_chestplate_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
groups = {armor_torso=1, mcl_armor_points=3, mcl_armor_uses=81, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:chestplate_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:chestplate_leather"),
|
||||
})
|
||||
local itemname = "mcl_armor:leggings_leather_"..first_color[1]
|
||||
minetest.register_tool(itemname, {
|
||||
description = S("Leather Pants "..first_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_leggings_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
texture = "mcl_armor_leggings_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
groups = {armor_legs=1, mcl_armor_points=2, mcl_armor_uses=76, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:leggings_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:leggings_leather"),
|
||||
})
|
||||
local itemname = "mcl_armor:boots_leather_"..first_color[1]
|
||||
minetest.register_tool(itemname, {
|
||||
description = S("Leather Boots "..first_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_boots_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
texture = "mcl_armor_boots_leather.png^[colorize:"..first_color[1]..":"..colorize_value,
|
||||
groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=66, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:boots_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:boots_leather"),
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:helmet_leather_"..first_color[1],
|
||||
recipe = {"mcl_armor:helmet_leather", first_color[1]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:chestplate_leather_"..first_color[1],
|
||||
recipe = {"mcl_armor:chestplate_leather", first_color[3]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:leggings_leather_"..first_color[1],
|
||||
recipe = {"mcl_armor:leggings_leather", first_color[3]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:boots_leather_"..first_color[1],
|
||||
recipe = {"mcl_armor:boots_leather", first_color[3]},
|
||||
})
|
||||
itemcount = itemcount + 4
|
||||
for _,second_color in ipairs(colors) do
|
||||
minetest.register_tool("mcl_armor:helmet_leather_"..first_color[1].."_"..second_color[1], {
|
||||
description = S("Leather Cap "..first_color[2].." "..second_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_helmet_leather.png",
|
||||
texture = "mcl_armor_helmet_leather.png",
|
||||
groups = {armor_head=1, mcl_armor_points=1, mcl_armor_uses=56, enchantability=15},
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:helmet_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:helmet_leather"),
|
||||
})
|
||||
minetest.register_tool("mcl_armor:chestplate_leather_"..first_color[1].."_"..second_color[1], {
|
||||
description = S("Leather Tunic "..first_color[2].." "..second_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_chestplate_leather.png",
|
||||
texture = "mcl_armor_chestplate_leather.png",
|
||||
groups = {armor_torso=1, mcl_armor_points=3, mcl_armor_uses=81, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:chestplate_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:chestplate_leather"),
|
||||
})
|
||||
minetest.register_tool("mcl_armor:leggings_leather_"..first_color[1].."_"..second_color[1], {
|
||||
description = S("Leather Pants "..first_color[2].." "..second_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_leggings_leather.png",
|
||||
texture = "mcl_armor_leggings_leather.png",
|
||||
groups = {armor_legs=1, mcl_armor_points=2, mcl_armor_uses=76, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:leggings_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:leggings_leather"),
|
||||
})
|
||||
minetest.register_tool("mcl_armor:boots_leather_"..first_color[1].."_"..second_color[1], {
|
||||
description = S("Leather Boots "..first_color[2].." "..second_color[2]),
|
||||
_doc_items_longdesc = longdesc,
|
||||
_doc_items_usagehelp = usage,
|
||||
inventory_image = "mcl_armor_inv_boots_leather.png",
|
||||
texture = "mcl_armor_leggins_leather.png",
|
||||
groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=66, enchantability=15 },
|
||||
_repair_material = "mcl_mobitems:leather",
|
||||
sounds = {
|
||||
_mcl_armor_equip = "mcl_armor_equip_leather",
|
||||
_mcl_armor_unequip = "mcl_armor_unequip_leather",
|
||||
},
|
||||
on_place = get_on_armor_leather_use(itemname, "mcl_armor:boots_leather"),
|
||||
on_secondary_use = get_on_armor_leather_use(itemname, "mcl_armor:boots_leather"),
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:helmet_leather_"..first_color[1].."_"..second_color[1],
|
||||
recipe = {"mcl_armor:helmet_leather_"..first_color[1], second_color[3]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:chestplate_leather_"..first_color[1].."_"..second_color[1],
|
||||
recipe = {"mcl_armor:chestplate_leather_"..first_color[1], second_color[3]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:leggings_leather_"..first_color[1].."_"..second_color[1],
|
||||
recipe = {"mcl_armor:leggings_leather_"..first_color[1], second_color[3]},
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "mcl_armor:boots_leather_"..first_color[1].."_"..second_color[1],
|
||||
recipe = {"mcl_armor:boots_leather_"..first_color[1], second_color[3]},
|
||||
})
|
||||
itemcount = itemcount + 4
|
||||
end
|
||||
end
|
||||
|
||||
--minetest.register_on_joinplayer(function()
|
||||
-- minetest.chat_send_all(itemcount)
|
||||
--end)
|
||||
|
||||
minetest.log("info", "[mcl_armor] "..itemcount.." leather armor pieces have been registered")
|
|
@ -266,7 +266,7 @@ function mcl_enchanting.initialize()
|
|||
new_def.groups.not_in_creative_inventory = 1
|
||||
new_def.groups.not_in_craft_guide = 1
|
||||
new_def.groups.enchanted = 1
|
||||
new_def.texture = itemdef.texture or itemname:gsub("%:", "_")
|
||||
new_def.texture = itemdef.texture or itemname:gsub("%:", "_")..".png"
|
||||
new_def._mcl_enchanting_enchanted_tool = new_name
|
||||
new_def.after_use = get_after_use_callback(itemdef)
|
||||
local register_list = register_item_list
|
||||
|
|
Loading…
Reference in New Issue