1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-01-11 18:40:25 +01:00

merge 3 commit

Commits on Apr 18, 2015
    Round home positions
    Remove unneeded and slow get_desc function
Commits on Mar 12, 2015
    Add item_names support for Better "HUD"
This commit is contained in:
crabman77 2015-04-19 23:21:20 +02:00
parent 5d5f871c63
commit ce5605e836
2 changed files with 34 additions and 48 deletions

View File

@ -1,10 +1,4 @@
local S local S = unified_inventory.gettext
if (minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function(s) return s end
end
-- Create detached creative inventory after loading all mods -- Create detached creative inventory after loading all mods
minetest.after(0.01, function() minetest.after(0.01, function()
@ -74,43 +68,36 @@ end)
-- load_home -- load_home
local function load_home() local function load_home()
local input = io.open(unified_inventory.home_filename, "r") local input = io.open(unified_inventory.home_filename, "r")
if input then if not input then
while true do
local x = input:read("*n")
if x == nil then
break
end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*l")
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
end
io.close(input)
else
unified_inventory.home_pos = {} unified_inventory.home_pos = {}
return
end end
while true do
local x = input:read("*n")
if not x then break end
local y = input:read("*n")
local z = input:read("*n")
local name = input:read("*l")
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
end
io.close(input)
end end
load_home() load_home()
function unified_inventory.set_home(player, pos) function unified_inventory.set_home(player, pos)
local player_name = player:get_player_name() local player_name = player:get_player_name()
unified_inventory.home_pos[player_name] = pos unified_inventory.home_pos[player_name] = vector.round(pos)
-- save the home data from the table to the file -- save the home data from the table to the file
local output = io.open(unified_inventory.home_filename, "w") local output = io.open(unified_inventory.home_filename, "w")
for k, v in pairs(unified_inventory.home_pos) do for k, v in pairs(unified_inventory.home_pos) do
if v ~= nil then output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
output:write(math.floor(v.x).." "
..math.floor(v.y).." "
..math.floor(v.z).." "
..k.."\n")
end
end end
io.close(output) io.close(output)
end end
function unified_inventory.go_home(player) function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()] local pos = unified_inventory.home_pos[player:get_player_name()]
if pos ~= nil then if pos then
player:setpos(pos) player:setpos(pos)
end end
end end
@ -158,6 +145,7 @@ end
unified_inventory.register_craft_type("normal", { unified_inventory.register_craft_type("normal", {
description = "Crafting", description = "Crafting",
icon = "ui_craftgrid_icon.png",
width = 3, width = 3,
height = 3, height = 3,
get_shaped_craft_width = function (craft) return craft.width end, get_shaped_craft_width = function (craft) return craft.width end,
@ -173,6 +161,7 @@ unified_inventory.register_craft_type("normal", {
unified_inventory.register_craft_type("shapeless", { unified_inventory.register_craft_type("shapeless", {
description = "Mixing", description = "Mixing",
icon = "ui_craftgrid_icon.png",
width = 3, width = 3,
height = 3, height = 3,
dynamic_display_size = function (craft) dynamic_display_size = function (craft)
@ -187,6 +176,7 @@ unified_inventory.register_craft_type("shapeless", {
unified_inventory.register_craft_type("cooking", { unified_inventory.register_craft_type("cooking", {
description = "Cooking", description = "Cooking",
icon = "default_furnace_front.png",
width = 1, width = 1,
height = 1, height = 1,
}) })
@ -194,6 +184,7 @@ unified_inventory.register_craft_type("cooking", {
unified_inventory.register_craft_type("digging", { unified_inventory.register_craft_type("digging", {
description = "Digging", description = "Digging",
icon = "default_tool_steelpick.png",
width = 1, width = 1,
height = 1, height = 1,
}) })

View File

@ -1,25 +1,17 @@
-- code based on 4itemnames mod by 4aiman -- Based on 4itemnames mod by 4aiman
local wield = {} local wield = {}
local huds = {} local huds = {}
local dtimes = {} local dtimes = {}
local dlimit = 3 -- hud will be hidden after this much seconds local dlimit = 3 -- HUD element will be hidden after this many seconds
local airhudmod = minetest.get_modpath("4air") local air_hud_mod = minetest.get_modpath("4air")
local hud_mod = minetest.get_modpath("hud")
local function get_desc(item) local function set_hud(player)
if minetest.registered_nodes[item] then return minetest.registered_nodes[item]["description"] end
if minetest.registered_items[item] then return minetest.registered_items[item]["description"] end
if minetest.registered_craftitems[item] then return minetest.registered_craftitems[item]["description"] end
if minetest.registered_tools[item] then return minetest.registered_tools[item]["description"] end
return ""
end
minetest.register_on_joinplayer(function(player)
minetest.after(0.0, function()
local player_name = player:get_player_name() local player_name = player:get_player_name()
local off = {x=0, y=-70} local off = {x=0, y=-70}
if airhudmod then if air_hud_mod or hud_mod then
off.y=off.y-20 off.y = off.y - 20
end end
huds[player_name] = player:hud_add({ huds[player_name] = player:hud_add({
hud_elem_type = "text", hud_elem_type = "text",
@ -29,13 +21,14 @@ minetest.register_on_joinplayer(function(player)
number = 0xFFFFFF , number = 0xFFFFFF ,
text = "", text = "",
}) })
--print(dump("item hud id: "..huds[player_name])) end
end)
minetest.register_on_joinplayer(function(player)
minetest.after(0, set_hud, player)
end) end)
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players() for _, player in pairs(minetest.get_connected_players()) do
for i,player in ipairs(players) do
local player_name = player:get_player_name() local player_name = player:get_player_name()
local wstack = player:get_wielded_item():get_name() local wstack = player:get_wielded_item():get_name()
@ -48,11 +41,13 @@ minetest.register_globalstep(function(dtime)
if wstack ~= wield[player_name] then if wstack ~= wield[player_name] then
wield[player_name] = wstack wield[player_name] = wstack
local desc = get_desc(wstack)
dtimes[player_name] = 0 dtimes[player_name] = 0
if huds[player_name] then if huds[player_name] then
local def = minetest.registered_items[wstack]
local desc = def and def.description or ""
player:hud_change(huds[player_name], 'text', desc) player:hud_change(huds[player_name], 'text', desc)
end end
end end
end end
end) end)