Add support for enchanting kititems
parent
9d06e4560d
commit
c13a312b31
37
api.lua
37
api.lua
|
@ -22,6 +22,26 @@ function kitpvp.api.get_kit_definition(kitname)
|
|||
return kitpvp.kits[kitname]
|
||||
end
|
||||
|
||||
function kitpvp.api.add_enchantments(itemstring, enchantments)
|
||||
if enchantments == {} then return end
|
||||
|
||||
local itemObj = ItemStack(itemstring)
|
||||
|
||||
mcl_enchanting.set_enchanted_itemstring(itemObj)
|
||||
mcl_enchanting.set_enchantments(itemObj, enchantments)
|
||||
|
||||
return itemObj
|
||||
end
|
||||
|
||||
function kitpvp.api.get_tool_obj(itemstring, enchantments)
|
||||
local obj = {}
|
||||
|
||||
obj.itemstring = itemstring
|
||||
obj.enchantments = enchantments
|
||||
|
||||
return obj
|
||||
end
|
||||
|
||||
function kitpvp.api.register_kit(def)
|
||||
local name = def.name
|
||||
local items = def.items
|
||||
|
@ -69,15 +89,24 @@ function kitpvp.api.give_kit(player, kitname)
|
|||
local components = {"helmet", "chestplate", "leggings", "boots"}
|
||||
|
||||
for i, component in pairs(components) do
|
||||
i = i + 1
|
||||
|
||||
local item_name = "mcl_armor:" .. component .. "_" .. def.armor
|
||||
|
||||
kitpvp.api.give_to_player(player, item_name)
|
||||
end
|
||||
|
||||
-- ITEMS
|
||||
for i, item in pairs(def.items) do
|
||||
kitpvp.api.give_to_player(player, item)
|
||||
for _, itemobj in pairs(def.items) do
|
||||
local item = itemobj.itemstring
|
||||
local itemstack = ItemStack(item)
|
||||
local enchantments = itemobj.enchantments
|
||||
local final_item_obj
|
||||
|
||||
if enchantments ~= nil then
|
||||
final_item_obj = kitpvp.api.add_enchantments(itemstack, enchantments)
|
||||
else
|
||||
final_item_obj = itemstack
|
||||
end
|
||||
|
||||
kitpvp.api.give_to_player(player, final_item_obj)
|
||||
end
|
||||
end
|
||||
|
|
18
kits.lua
18
kits.lua
|
@ -8,23 +8,35 @@ kitpvp.api.register_kit({
|
|||
})
|
||||
]]
|
||||
|
||||
-- To make the item converter function a bit shorter
|
||||
item = kitpvp.api.get_tool_obj
|
||||
|
||||
kitpvp.api.register_kit({
|
||||
name = "tank",
|
||||
items = {"mcl_tools:sword_iron"},
|
||||
items = {
|
||||
item("mcl_tools:sword_iron", {sharpness = 1})
|
||||
},
|
||||
default_items = true,
|
||||
armor = "iron"
|
||||
})
|
||||
|
||||
kitpvp.api.register_kit({
|
||||
name = "archer",
|
||||
items = {"mcl_tools:sword_stone", "mcl_bows:bow", "mcl_bows:arrow 10000"},
|
||||
items = {
|
||||
item("mcl_tools:sword_stone", {sharpness = 1}),
|
||||
item("mcl_bows:bow", {infinity = 1}),
|
||||
item("mcl_bows:arrow 1")
|
||||
},
|
||||
default_items = true,
|
||||
armor = "gold"
|
||||
})
|
||||
|
||||
kitpvp.api.register_kit({
|
||||
name = "speedrunner",
|
||||
items = {"mcl_tools:sword_stone", "mcl_potions:swiftness_2"},
|
||||
items = {
|
||||
item("mcl_tools:sword_stone", {sharpness = 1}),
|
||||
item("mcl_potions:swiftness_2"),
|
||||
},
|
||||
default_items = true,
|
||||
armor = "gold"
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue