summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/CommandBlockEntity.h
blob: 266a3c33dc0cc735b4eacdfa669e9a63b45b6e52 (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

// CommandBlockEntity.h

// Declares the cCommandBlockEntity class representing a single command block in the world





#pragma once

#include "BlockEntityWithItems.h"
#include "../UI/WindowOwner.h"





namespace Json
{
	class Value;
}





// tolua_begin

class cCommandBlockEntity : 
	public cBlockEntity,
	public cBlockEntityWindowOwner
{
	typedef cBlockEntity super;
	
public:

	// tolua_end
	
	/// Creates a new empty command block entity
	cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
	virtual ~cCommandBlockEntity();

	bool LoadFromJson( const Json::Value& a_Value );
	virtual void SaveToJson(Json::Value& a_Value ) override;

	virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
	virtual void SendTo(cClientHandle & a_Client) override;
	virtual void UsedBy(cPlayer * a_Player) override;

	// tolua_begin

	/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
	void SetRedstonePower(bool a_IsPowered);

	/// Sets the command block to execute a command in the next tick
	void Activate(void);
	
	/// Sets the command
	void SetCommand(const AString & a_Cmd);

	/// Retrieves stored command
	const AString & GetCommand(void) const;

	/// Retrieves the last line of output generated by the command block
	const AString & GetLastOutput(void) const;
	
	// tolua_end
	
private:

	/// Executes the associated command
	void Execute();

	bool m_ShouldExecute;
	bool m_IsPowered;

	AString  m_Command;

	AString  m_LastOutput;
} ;  // tolua_export