Add bronze armor and add an API for item drop on death
@ -1,3 +1,4 @@
|
|||||||
default
|
default
|
||||||
|
drop_items_on_die
|
||||||
crafting
|
crafting
|
||||||
achievements
|
achievements
|
||||||
|
@ -5,22 +5,21 @@
|
|||||||
|
|
||||||
armor = {}
|
armor = {}
|
||||||
|
|
||||||
armor.player_skin = "character.png"
|
-- Wear is wear per HP of damage taken
|
||||||
|
|
||||||
armor.materials = {
|
armor.materials = {
|
||||||
-- material craftitem % description
|
-- material craftitem description %
|
||||||
{"wood", "group:planks", 15, "Wooden"},
|
{"wood", "group:planks", "Wooden", 10},
|
||||||
{"steel", "default:ingot_steel", 30, "Steel"},
|
{"steel", "default:ingot_steel", "Steel", 20},
|
||||||
{"chainmail", "armor:chainmail_sheet", 45, "Chainmail"},
|
{"chainmail", "armor:chainmail_sheet", "Chainmail", 30},
|
||||||
{"carbon_steel", "default:ingot_carbon_steel", 60, "Carbon Steel"},
|
{"carbon_steel", "default:ingot_carbon_steel", "Carbon Steel", 40},
|
||||||
|
{"bronze", "default:ingot_bronze", "Bronze", 60},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Usable slots
|
-- Usable slots
|
||||||
|
|
||||||
armor.slots = {"helmet", "chestplate", "boots"}
|
armor.slots = {"helmet", "chestplate", "boots"}
|
||||||
|
|
||||||
local enable_drop = minetest.setting_getbool("drop_items_on_die") or false
|
|
||||||
|
|
||||||
-- Timer
|
-- Timer
|
||||||
|
|
||||||
local timer_interval = 1
|
local timer_interval = 1
|
||||||
@ -166,36 +165,6 @@ local function on_joinplayer(player)
|
|||||||
armor.init(player)
|
armor.init(player)
|
||||||
end
|
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)
|
local function on_globalstep(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
|
|
||||||
@ -210,8 +179,8 @@ local function on_globalstep(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if enable_drop then
|
if minetest.get_modpath("drop_items_on_die") ~= nil then
|
||||||
minetest.register_on_dieplayer(on_dieplayer)
|
drop_items_on_die.register_listname("armor")
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_newplayer(on_newplayer)
|
minetest.register_on_newplayer(on_newplayer)
|
||||||
@ -245,7 +214,7 @@ crafting.register_craft(
|
|||||||
for mat_index, matdef in ipairs(armor.materials) do
|
for mat_index, matdef in ipairs(armor.materials) do
|
||||||
local mat = matdef[1]
|
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)
|
-- print("Material " .. mat .. ": " .. armor_def)
|
||||||
|
|
||||||
for _, slot in ipairs(armor.slots) do
|
for _, slot in ipairs(armor.slots) do
|
||||||
@ -259,7 +228,7 @@ for mat_index, matdef in ipairs(armor.materials) do
|
|||||||
minetest.register_craftitem(
|
minetest.register_craftitem(
|
||||||
"armor:" .. slot .. "_" .. mat,
|
"armor:" .. slot .. "_" .. mat,
|
||||||
{
|
{
|
||||||
description = matdef[4] .. " " .. prettystring,
|
description = matdef[3] .. " " .. prettystring,
|
||||||
|
|
||||||
inventory_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
inventory_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
||||||
wield_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
|
||||||
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_joinplayer(on_joinplayer)
|
||||||
minetest.register_on_player_receive_fields(on_player_receive_fields)
|
minetest.register_on_player_receive_fields(on_player_receive_fields)
|
||||||
|
|
||||||
|
@ -1 +1,2 @@
|
|||||||
default
|
default
|
||||||
|
drop_items_on_die
|
||||||
|
@ -3,15 +3,24 @@
|
|||||||
-- By Kaadmy, for Pixture
|
-- 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
|
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 function on_die(player)
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
|
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
for i = 1, inv:get_size("main") do
|
for _, listname in ipairs(drop_items_on_die.registered_listnames) do
|
||||||
local item = inv:get_stack("main", i)
|
for i = 1, inv:get_size(listname) do
|
||||||
|
local item = inv:get_stack(listname, i)
|
||||||
|
|
||||||
local rpos = {
|
local rpos = {
|
||||||
x = pos.x + math.random(-0.3, 0.3),
|
x = pos.x + math.random(-0.3, 0.3),
|
||||||
@ -30,16 +39,21 @@ local function on_die(player)
|
|||||||
if math.random(1, 2) == 1 then
|
if math.random(1, 2) == 1 then
|
||||||
z = -z
|
z = -z
|
||||||
end
|
end
|
||||||
|
|
||||||
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
|
drop:setvelocity({x = 1 / x, y = drop:getvelocity().y, z = 1 / z})
|
||||||
end
|
end
|
||||||
|
|
||||||
item:clear()
|
item:clear()
|
||||||
inv:set_stack("main", i, item)
|
|
||||||
|
inv:set_stack(listname, i, item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if enable_drop then
|
if enable_drop then
|
||||||
minetest.register_on_dieplayer(on_die)
|
minetest.register_on_dieplayer(on_die)
|
||||||
|
|
||||||
|
drop_items_on_die.register_listname("main")
|
||||||
end
|
end
|
||||||
|
|
||||||
default.log("mod:drop_items_on_die", "loaded")
|
default.log("mod:drop_items_on_die", "loaded")
|