aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/GameRules/GameRule.h
blob: e35f13752a32732754998d5ebe542202fced3434 (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
55
56
57
58
59
60
61
62
#pragma once
using namespace std;

#include <unordered_map>

class CompoundTag;
class GameRuleDefinition;
class Connection;

// A game rule maintains the state for one particular definition
class GameRule
{
public:
	typedef struct _ValueType
	{
		union{
			int64_t				i64;
			int					i;
			char				c;
			bool				b;
			float				f;
			double				d;
			GameRule			*gr;
		};
		bool isPointer;

		_ValueType()
		{
			i64 = 0;
			isPointer = false;
		}
	} ValueType;

private:
	GameRuleDefinition *m_definition;
	Connection *m_connection;

public:
	typedef unordered_map<wstring,ValueType> stringValueMapType;
	stringValueMapType m_parameters; // These are the members of this rule that maintain it's state

public:
	GameRule(GameRuleDefinition *definition, Connection *connection = nullptr);
	virtual ~GameRule();

	Connection *getConnection() { return m_connection; }

	ValueType getParameter(const wstring &parameterName);
	void setParameter(const wstring &parameterName,ValueType value);
	GameRuleDefinition *getGameRuleDefinition();

	// All the hooks go here
	void onUseTile(int tileId, int x, int y, int z);
	void onCollectItem(shared_ptr<ItemInstance> item);

	// 4J-JEV: For saving.
	//CompoundTag *toTags(unordered_map<GameRuleDefinition *, int> *map);
	//static GameRule *fromTags(Connection *c, CompoundTag *cTag, vector<GameRuleDefinition *> *grds);

	void write(DataOutputStream *dos);
	void read(DataInputStream *dos);
};