aboutsummaryrefslogtreecommitdiff
path: root/src/itemstackmetadata.h
blob: a7f1349553ed71ff3b8ec81fdabd811f8d4902dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Minetest
Copyright (C) 2017-8 rubenwardy <rw@rubenwardy.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include "metadata.h"
#include "tool.h"

class Inventory;
class IItemDefManager;

class ItemStackMetadata : public Metadata
{
public:
	ItemStackMetadata() : toolcaps_overridden(false) {}

	// Overrides
	void clear() override;
	bool setString(const std::string &name, const std::string &var) override;

	void serialize(std::ostream &os) const;
	void deSerialize(std::istream &is);

	const ToolCapabilities &getToolCapabilities(
			const ToolCapabilities &default_caps) const
	{
		return toolcaps_overridden ? toolcaps_override : default_caps;
	}

	void setToolCapabilities(const ToolCapabilities &caps);
	void clearToolCapabilities();

private:
	void updateToolCapabilities();

	bool toolcaps_overridden;
	ToolCapabilities toolcaps_override;
};
n> player_hud[name] then generatehud(player) end local hud = player_hud[name] if hud and text ~= hud.text then player:hud_change(hud.id, "text", text) hud.text = text end end local function removehud(player) local name = player:get_player_name() if player_hud[name] then player:hud_remove(player_hud[name].id) end end minetest.register_on_joinplayer(function(player) minetest.after(0,generatehud,player) end) minetest.register_on_leaveplayer(function(player) minetest.after(1,removehud,player) end) -- time -- from https://gitlab.com/Rochambeau/mthudclock/blob/master/init.lua local function floormod ( x, y ) return (math.floor(x) % y); end local function get_time() local secs = (60*60*24*minetest.get_timeofday()); local s = floormod(secs, 60); local m = floormod(secs/60, 60); local h = floormod(secs/3600, 60); return ("%02d:%02d"):format(h, m); end -- Lag counters -- adaption weights for averages local w_avg1, w_avg2 = 0.001, 0.001 local dec_max = 0.99995 local ow_avg1, ow_avg2 = 1-w_avg1, 1-w_avg2 local l_avg1, l_avg2, l_max = 0.1, 0.1, 0.1 local h_text = "Initializing..." local h_int = 2 local h_tmr = 0 minetest.register_globalstep(function (dtime) -- make a lag sample l_avg1 = w_avg1*dtime + ow_avg1*l_avg1 l_avg2 = w_avg2*l_avg1 + ow_avg2*l_avg2 l_max = math.max(l_max*dec_max, dtime) -- update hud text when necessary if h_tmr <= 0 then -- Update hud text that is the same for all players local s_lag = string.format("Lag: avg: %.2f (%.2f) max: %.2f", l_avg1, l_avg2, l_max) local s_time = "Time: "..get_time() h_text = s_time .. "\n" .. s_lag h_tmr = h_int else h_tmr = h_tmr - dtime end for _,player in ipairs(minetest.get_connected_players()) do local posi = player:get_pos() local posistr = math.floor(posi.x+0.5).." "..math.floor(posi.y+0.5).." "..math.floor(posi.z+0.5) updatehud(player, h_text.."\nPos: "..posistr) end end);