1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 01:30:38 +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
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
local S = unified_inventory.gettext
-- Create detached creative inventory after loading all mods
minetest.after(0.01, function()
@ -74,43 +68,36 @@ end)
-- load_home
local function load_home()
local input = io.open(unified_inventory.home_filename, "r")
if 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
if not input then
unified_inventory.home_pos = {}
return
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
load_home()
function unified_inventory.set_home(player, pos)
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
local output = io.open(unified_inventory.home_filename, "w")
for k, v in pairs(unified_inventory.home_pos) do
if v ~= nil then
output:write(math.floor(v.x).." "
..math.floor(v.y).." "
..math.floor(v.z).." "
..k.."\n")
end
output:write(v.x.." "..v.y.." "..v.z.." "..k.."\n")
end
io.close(output)
end
function unified_inventory.go_home(player)
local pos = unified_inventory.home_pos[player:get_player_name()]
if pos ~= nil then
if pos then
player:setpos(pos)
end
end
@ -158,6 +145,7 @@ end
unified_inventory.register_craft_type("normal", {
description = "Crafting",
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
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", {
description = "Mixing",
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
dynamic_display_size = function (craft)
@ -187,6 +176,7 @@ unified_inventory.register_craft_type("shapeless", {
unified_inventory.register_craft_type("cooking", {
description = "Cooking",
icon = "default_furnace_front.png",
width = 1,
height = 1,
})
@ -194,6 +184,7 @@ unified_inventory.register_craft_type("cooking", {
unified_inventory.register_craft_type("digging", {
description = "Digging",
icon = "default_tool_steelpick.png",
width = 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 huds = {}
local dtimes = {}
local dlimit = 3 -- hud will be hidden after this much seconds
local airhudmod = minetest.get_modpath("4air")
local dlimit = 3 -- HUD element will be hidden after this many seconds
local air_hud_mod = minetest.get_modpath("4air")
local hud_mod = minetest.get_modpath("hud")
local function get_desc(item)
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 function set_hud(player)
local player_name = player:get_player_name()
local off = {x=0, y=-70}
if airhudmod then
off.y=off.y-20
if air_hud_mod or hud_mod then
off.y = off.y - 20
end
huds[player_name] = player:hud_add({
hud_elem_type = "text",
@ -29,13 +21,14 @@ minetest.register_on_joinplayer(function(player)
number = 0xFFFFFF ,
text = "",
})
--print(dump("item hud id: "..huds[player_name]))
end)
end
minetest.register_on_joinplayer(function(player)
minetest.after(0, set_hud, player)
end)
minetest.register_globalstep(function(dtime)
local players = minetest.get_connected_players()
for i,player in ipairs(players) do
for _, player in pairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local wstack = player:get_wielded_item():get_name()
@ -48,11 +41,13 @@ minetest.register_globalstep(function(dtime)
if wstack ~= wield[player_name] then
wield[player_name] = wstack
local desc = get_desc(wstack)
dtimes[player_name] = 0
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)
end
end
end
end)