Part 1 of skins rewrite
This commit is contained in:
parent
36f8560514
commit
a81f2425af
@ -1,13 +1,15 @@
|
||||
local minetest,math,skins_pointer = minetest,math,skins_pointer
|
||||
local minetest,math = minetest,math
|
||||
armor_class = {} --the armor class
|
||||
|
||||
function armor_class.recalculate_armor(player)
|
||||
function recalculate_armor(player)
|
||||
if not player or (player and not player:is_player()) then return end
|
||||
local inv = player:get_inventory()
|
||||
|
||||
local player_skin = skins_pointer.get_skin(player)
|
||||
local player_skin = get_skin(player)
|
||||
local armor_skin = "blank_skin.png"
|
||||
|
||||
print(dump(player_skin))
|
||||
|
||||
local stack = inv:get_stack("armor_head",1):get_name()
|
||||
if stack ~= "" and minetest.get_item_group(stack,"helmet") > 0 then
|
||||
local skin_element = minetest.get_itemdef(stack, "wearing_texture")
|
||||
@ -34,7 +36,7 @@ function armor_class.recalculate_armor(player)
|
||||
player:set_properties({textures = {player_skin,armor_skin}})
|
||||
end
|
||||
|
||||
function armor_class.calculate_armor_absorbtion(player)
|
||||
function calculate_armor_absorbtion(player)
|
||||
if not player or (player and not player:is_player()) then return end
|
||||
|
||||
local inv = player:get_inventory()
|
||||
@ -73,17 +75,17 @@ function armor_class.calculate_armor_absorbtion(player)
|
||||
return(armor_absorbtion)
|
||||
end
|
||||
|
||||
function armor_class.set_armor_gui(player)
|
||||
function set_armor_gui(player)
|
||||
if not player or (player and not player:is_player()) then return end
|
||||
local meta = player:get_meta()
|
||||
local level = armor_class.calculate_armor_absorbtion(player)
|
||||
local level = calculate_armor_absorbtion(player)
|
||||
local hud = meta:get_int("armor_bar")
|
||||
player:hud_change(hud, "number", level)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function armor_class.damage_armor(player,damage)
|
||||
function damage_armor(player,damage)
|
||||
if not player or (player and not player:is_player()) then return end
|
||||
|
||||
local inv = player:get_inventory()
|
||||
@ -140,8 +142,8 @@ function armor_class.damage_armor(player,damage)
|
||||
|
||||
if recalc == true then
|
||||
minetest.sound_play("armor_break",{to_player=player:get_player_name(),gain=1,pitch=math.random(80,100)/100})
|
||||
armor_class.recalculate_armor(player)
|
||||
armor_class.set_armor_gui(player)
|
||||
recalculate_armor(player)
|
||||
set_armor_gui(player)
|
||||
--do particles too
|
||||
end
|
||||
end
|
||||
@ -162,7 +164,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
hud_elem_type = "statbar",
|
||||
position = {x = 0.5, y = 1},
|
||||
text = "armor_icon.png",
|
||||
number = armor_class.calculate_armor_absorbtion(player),--meta:get_int("hunger"),
|
||||
number = calculate_armor_absorbtion(player),--meta:get_int("hunger"),
|
||||
--direction = 1,
|
||||
size = {x = 24, y = 24},
|
||||
offset = {x = (-10 * 24) - 25, y = -(48 + 50 + 39)},
|
||||
@ -177,15 +179,15 @@ minetest.register_on_joinplayer(function(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
armor_class.set_armor_gui(player)
|
||||
set_armor_gui(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
if inventory_info.from_list == "armor_head" or inventory_info.from_list == "armor_torso" or inventory_info.from_list == "armor_legs" or inventory_info.from_list == "armor_feet" or
|
||||
inventory_info.to_list == "armor_head" or inventory_info.to_list == "armor_torso" or inventory_info.to_list == "armor_legs" or inventory_info.to_list == "armor_feet" then
|
||||
minetest.after(0,function()
|
||||
armor_class.recalculate_armor(player)
|
||||
armor_class.set_armor_gui(player)
|
||||
recalculate_armor(player)
|
||||
set_armor_gui(player)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
@ -67,8 +67,8 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
|
||||
if inv:get_stack("armor_torso",1):get_name() == "" then
|
||||
armor_class.recalculate_armor(player)
|
||||
armor_class.set_armor_gui(player)
|
||||
recalculate_armor(player)
|
||||
set_armor_gui(player)
|
||||
player:set_physics_override({gravity=1.25})
|
||||
if sound_handling_loop[player_name] then
|
||||
--minetest.sound_play("armor_break",{to_player=player:get_player_name(),gain=1,pitch=math.random(80,100)/100})
|
||||
|
@ -69,8 +69,8 @@ local function calc_fall_damage(player,hp_change,velocity)
|
||||
|
||||
if new_stack == "" then
|
||||
minetest.sound_play("armor_break",{to_player=player:get_player_name(),gain=1,pitch=math.random(80,100)/100})
|
||||
armor_class.recalculate_armor(player)
|
||||
armor_class.set_armor_gui(player)
|
||||
recalculate_armor(player)
|
||||
set_armor_gui(player)
|
||||
--do particles too
|
||||
elseif minetest.get_item_group(new_stack,"boots") > 0 then
|
||||
local pos = player:get_pos()
|
||||
@ -190,7 +190,7 @@ minetest.register_on_dieplayer(function(player, reason)
|
||||
end
|
||||
|
||||
|
||||
armor_class.recalculate_armor(player)
|
||||
recalculate_armor(player)
|
||||
end)
|
||||
|
||||
|
||||
@ -330,9 +330,9 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
|
||||
dir.y = 7
|
||||
end
|
||||
|
||||
local hp_modifier = math.ceil(armor_class.calculate_armor_absorbtion(player)/3)
|
||||
local hp_modifier = math.ceil(calculate_armor_absorbtion(player)/3)
|
||||
--print("hp_modifier:",hp_modifier)
|
||||
armor_class.damage_armor(player,math.abs(hurt))
|
||||
damage_armor(player,math.abs(hurt))
|
||||
|
||||
--print("hurt:",hurt,"|","hp_modifier:",hp_modifier)
|
||||
local modify_output = (hurt == 0)
|
||||
|
@ -1,4 +1,7 @@
|
||||
local minetest,math,io,vector,table,pairs = minetest,math,io,vector,table,pairs
|
||||
local
|
||||
minetest,math,io,vector,table,pairs
|
||||
=
|
||||
minetest,math,io,vector,table,pairs
|
||||
|
||||
local http = minetest.request_http_api()
|
||||
local id = "Lua Skins Updater"
|
||||
@ -19,49 +22,13 @@ if not http then
|
||||
end
|
||||
|
||||
-- only create classes if requirements are met
|
||||
local pool = {}
|
||||
local temppath = minetest.get_worldpath()
|
||||
|
||||
local skins = {} -- skins class
|
||||
skins.new_temp_path = nil
|
||||
skins.name = nil
|
||||
skins.player = nil
|
||||
skins.file = nil
|
||||
skins.temppath = minetest.get_worldpath()
|
||||
skins.get_player = minetest.get_player_by_name
|
||||
skins.open = io.open
|
||||
local player_skin_table = {}
|
||||
skins_pointer = {}
|
||||
|
||||
-- sets skin texture
|
||||
skins.set_skin = function(player,skin)
|
||||
skins.name = player:get_player_name()
|
||||
player_skin_table[skins.name] = skin
|
||||
end
|
||||
|
||||
-- gets skin texture
|
||||
skins.get_skin = function(player)
|
||||
skins.name = player:get_player_name()
|
||||
if player_skin_table[skins.name] then
|
||||
return(player_skin_table[skins.name])
|
||||
else
|
||||
return("player.png")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- sets skin texture
|
||||
skins_pointer.set_skin = function(player,skin)
|
||||
skins.name = player:get_player_name()
|
||||
player_skin_table[skins.name] = skin
|
||||
end
|
||||
|
||||
-- gets skin texture
|
||||
skins_pointer.get_skin = function(player)
|
||||
skins.name = player:get_player_name()
|
||||
if player_skin_table[skins.name] then
|
||||
return(player_skin_table[skins.name])
|
||||
else
|
||||
return("player.png")
|
||||
end
|
||||
local name
|
||||
function get_skin(player)
|
||||
name = player:get_player_name()
|
||||
return(pool[name] or "player.png")
|
||||
end
|
||||
|
||||
-- Fancy debug wrapper to download an URL
|
||||
@ -86,27 +53,30 @@ local function fetch_url(url, callback)
|
||||
end
|
||||
|
||||
-- gets github raw data of skin
|
||||
fetch_function = function(name)
|
||||
local new_temp_path
|
||||
local file
|
||||
local player
|
||||
local fetch_function = function(name)
|
||||
fetch_url("https://raw.githubusercontent.com/"..name.."/crafter_skindex/master/skin.png", function(data)
|
||||
if data then
|
||||
skins.new_temp_path = skins.temppath .. "/skin_"..name..".png"
|
||||
new_temp_path = temppath .. DIR_DELIM .. "/skin_"..name..".png"
|
||||
|
||||
skins.file = skins.open(skins.new_temp_path, "wb")
|
||||
skins.file:write(data)
|
||||
skins.file:close()
|
||||
|
||||
-- set the player's skin
|
||||
skins.player = skins.get_player(name)
|
||||
file = io.open(new_temp_path, "wb")
|
||||
file:write(data)
|
||||
file:close()
|
||||
|
||||
minetest.dynamic_add_media(skins.new_temp_path)
|
||||
|
||||
skins.file = "skin_"..name..".png" -- reuse the data
|
||||
|
||||
skins.player:set_properties({textures = {skins.file, "blank_skin.png"}})
|
||||
|
||||
skins.set_skin(skins.player,skins.file)
|
||||
minetest.dynamic_add_media(new_temp_path)
|
||||
|
||||
armor_class.recalculate_armor(skins.player) --redundancy
|
||||
file = "skin_"..name..".png" -- reuse the data
|
||||
|
||||
player = minetest.get_player_by_name(name)
|
||||
|
||||
player:set_properties({textures = {file, "blank_skin.png"}})
|
||||
|
||||
pool[name] = file
|
||||
|
||||
recalculate_armor(player)
|
||||
|
||||
end
|
||||
end)
|
||||
@ -366,12 +336,12 @@ minetest.register_on_mods_loaded(function()
|
||||
end)
|
||||
|
||||
|
||||
local name
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
|
||||
cape_handler.add_cape(player)
|
||||
|
||||
minetest.after(0,function()
|
||||
fetch_function(player:get_player_name())
|
||||
armor_class.recalculate_armor(player)
|
||||
recalculate_armor(player)
|
||||
end)
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user