Add bronze armor and add an API for item drop on death
@ -1,3 +1,4 @@
|
||||
default
|
||||
drop_items_on_die
|
||||
crafting
|
||||
achievements
|
||||
|
@ -5,22 +5,21 @@
|
||||
|
||||
armor = {}
|
||||
|
||||
armor.player_skin = "character.png"
|
||||
-- Wear is wear per HP of damage taken
|
||||
|
||||
armor.materials = {
|
||||
-- material craftitem % description
|
||||
{"wood", "group:planks", 15, "Wooden"},
|
||||
{"steel", "default:ingot_steel", 30, "Steel"},
|
||||
{"chainmail", "armor:chainmail_sheet", 45, "Chainmail"},
|
||||
{"carbon_steel", "default:ingot_carbon_steel", 60, "Carbon Steel"},
|
||||
-- material craftitem description %
|
||||
{"wood", "group:planks", "Wooden", 10},
|
||||
{"steel", "default:ingot_steel", "Steel", 20},
|
||||
{"chainmail", "armor:chainmail_sheet", "Chainmail", 30},
|
||||
{"carbon_steel", "default:ingot_carbon_steel", "Carbon Steel", 40},
|
||||
{"bronze", "default:ingot_bronze", "Bronze", 60},
|
||||
}
|
||||
|
||||
-- Usable slots
|
||||
|
||||
armor.slots = {"helmet", "chestplate", "boots"}
|
||||
|
||||
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
|
||||
|
||||
-- Timer
|
||||
|
||||
local timer_interval = 1
|
||||
@ -166,36 +165,6 @@ local function on_joinplayer(player)
|
||||
armor.init(player)
|
||||
end
|
||||
|
||||
local function on_dieplayer(player)
|
||||
local pos = player:getpos()
|
||||
|
||||
local inv = player:get_inventory()
|
||||
|
||||
for slot_index, slot in ipairs(armor.slots) do
|
||||
local item = inv:get_stack("armor", slot_index)
|
||||
|
||||
local rpos = {
|
||||
x = pos.x + math.random(-0.2, 0.2),
|
||||
y = pos.y,
|
||||
z = pos.z + math.random(-0.2, 0.2)
|
||||
}
|
||||
|
||||
local drop = minetest.add_item(rpos, item)
|
||||
|
||||
if drop then
|
||||
drop:setvelocity(
|
||||
{
|
||||
x = math.random(-0.3, 0.3),
|
||||
y = 3,
|
||||
z = math.random(-0.3, 0.3),
|
||||
})
|
||||
end
|
||||
|
||||
item:clear()
|
||||
inv:set_stack("armor_" .. slot, 1, item)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_globalstep(dtime)
|
||||
timer = timer + dtime
|
||||
|
||||
@ -210,8 +179,8 @@ local function on_globalstep(dtime)
|
||||
end
|
||||
end
|
||||
|
||||
if enable_drop then
|
||||
minetest.register_on_dieplayer(on_dieplayer)
|
||||
if minetest.get_modpath("drop_items_on_die") ~= nil then
|
||||
drop_items_on_die.register_listname("armor")
|
||||
end
|
||||
|
||||
minetest.register_on_newplayer(on_newplayer)
|
||||
@ -245,7 +214,7 @@ crafting.register_craft(
|
||||
for mat_index, matdef in ipairs(armor.materials) do
|
||||
local mat = matdef[1]
|
||||
|
||||
local armor_def = math.floor(matdef[3] / #armor.slots)
|
||||
local armor_def = math.floor(matdef[4] / #armor.slots)
|
||||
-- print("Material " .. mat .. ": " .. armor_def)
|
||||
|
||||
for _, slot in ipairs(armor.slots) do
|
||||
@ -259,7 +228,7 @@ for mat_index, matdef in ipairs(armor.materials) do
|
||||
minetest.register_craftitem(
|
||||
"armor:" .. slot .. "_" .. mat,
|
||||
{
|
||||
description = matdef[4] .. " " .. prettystring,
|
||||
description = matdef[3] .. " " .. prettystring,
|
||||
|
||||
inventory_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
||||
wield_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
||||
|
BIN
mods/armor/textures/armor_boots_bronze.png
Normal file
After Width: | Height: | Size: 273 B |
BIN
mods/armor/textures/armor_boots_bronze.xcf
Normal file
BIN
mods/armor/textures/armor_boots_bronze_inventory.png
Normal file
After Width: | Height: | Size: 423 B |
BIN
mods/armor/textures/armor_boots_bronze_inventory.xcf
Normal file
Before Width: | Height: | Size: 266 B After Width: | Height: | Size: 266 B |
BIN
mods/armor/textures/armor_chestplate_bronze.png
Normal file
After Width: | Height: | Size: 364 B |
BIN
mods/armor/textures/armor_chestplate_bronze.xcf
Normal file
BIN
mods/armor/textures/armor_chestplate_bronze_inventory.png
Normal file
After Width: | Height: | Size: 417 B |
BIN
mods/armor/textures/armor_chestplate_bronze_inventory.xcf
Normal file
BIN
mods/armor/textures/armor_helmet_bronze.png
Normal file
After Width: | Height: | Size: 292 B |
BIN
mods/armor/textures/armor_helmet_bronze.xcf
Normal file
BIN
mods/armor/textures/armor_helmet_bronze_inventory.png
Normal file
After Width: | Height: | Size: 441 B |
BIN
mods/armor/textures/armor_helmet_bronze_inventory.xcf
Normal file
Before Width: | Height: | Size: 436 B After Width: | Height: | Size: 440 B |
@ -400,6 +400,11 @@ local function on_joinplayer(player)
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.get_modpath("drop_items_on_die") ~= nil then
|
||||
drop_items_on_die.register_listname("craft_in")
|
||||
drop_items_on_die.register_listname("craft_out")
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(on_joinplayer)
|
||||
minetest.register_on_player_receive_fields(on_player_receive_fields)
|
||||
|
||||
|
@ -1 +1,2 @@
|
||||
default
|
||||
drop_items_on_die
|
||||
|
@ -3,43 +3,57 @@
|
||||
-- By Kaadmy, for Pixture
|
||||
--
|
||||
|
||||
drop_items_on_die = {}
|
||||
|
||||
drop_items_on_die.registered_listnames = {}
|
||||
|
||||
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
|
||||
|
||||
function drop_items_on_die.register_listname(listname)
|
||||
table.insert(drop_items_on_die.registered_listnames, listname)
|
||||
end
|
||||
|
||||
local function on_die(player)
|
||||
local pos = player:getpos()
|
||||
|
||||
local inv = player:get_inventory()
|
||||
|
||||
for i = 1, inv:get_size("main") do
|
||||
local item = inv:get_stack("main", i)
|
||||
for _, listname in ipairs(drop_items_on_die.registered_listnames) do
|
||||
for i = 1, inv:get_size(listname) do
|
||||
local item = inv:get_stack(listname, i)
|
||||
|
||||
local rpos = {
|
||||
x = pos.x + math.random(-0.3, 0.3),
|
||||
y = pos.y,
|
||||
z = pos.z + math.random(-0.3, 0.3)
|
||||
}
|
||||
local rpos = {
|
||||
x = pos.x + math.random(-0.3, 0.3),
|
||||
y = pos.y,
|
||||
z = pos.z + math.random(-0.3, 0.3)
|
||||
}
|
||||
|
||||
local drop = minetest.add_item(rpos, item)
|
||||
|
||||
if drop ~= nil then
|
||||
local x = math.random(1, 5)
|
||||
if math.random(1, 2) == 1 then
|
||||
x = -x
|
||||
end
|
||||
local z = math.random(1, 5)
|
||||
if math.random(1, 2) == 1 then
|
||||
z = -z
|
||||
end
|
||||
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
|
||||
local drop = minetest.add_item(rpos, item)
|
||||
|
||||
if drop ~= nil then
|
||||
local x = math.random(1, 5)
|
||||
if math.random(1, 2) == 1 then
|
||||
x = -x
|
||||
end
|
||||
local z = math.random(1, 5)
|
||||
if math.random(1, 2) == 1 then
|
||||
z = -z
|
||||
end
|
||||
|
||||
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
|
||||
end
|
||||
|
||||
item:clear()
|
||||
|
||||
inv:set_stack(listname, i, item)
|
||||
end
|
||||
|
||||
item:clear()
|
||||
inv:set_stack("main", i, item)
|
||||
end
|
||||
end
|
||||
|
||||
if enable_drop then
|
||||
minetest.register_on_dieplayer(on_die)
|
||||
|
||||
drop_items_on_die.register_listname("main")
|
||||
end
|
||||
|
||||
default.log("mod:drop_items_on_die", "loaded")
|
||||
default.log("mod:drop_items_on_die", "loaded")
|
||||
|