From 9a9b51a5134d8afd8f089d247c59668bd7da695d Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 15:16:47 +0200 Subject: Basic command block implementation --- src/BlockEntities/CommandBlockEntity.h | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/BlockEntities/CommandBlockEntity.h (limited to 'src/BlockEntities/CommandBlockEntity.h') diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h new file mode 100644 index 000000000..266a3c33d --- /dev/null +++ b/src/BlockEntities/CommandBlockEntity.h @@ -0,0 +1,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 + + + + -- cgit v1.2.3 From be5299350a3b808ade39df7e9654eda47732e96e Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 15:40:47 +0200 Subject: Command block (de)serialization --- src/BlockEntities/CommandBlockEntity.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities/CommandBlockEntity.h') diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index 266a3c33d..c4529a1e6 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -48,6 +48,10 @@ public: virtual void SendTo(cClientHandle & a_Client) override; virtual void UsedBy(cPlayer * a_Player) override; + void SetLastOutput(const AString & a_LastOut); + + void SetResult(const NIBBLETYPE a_Result); + // tolua_begin /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate @@ -64,6 +68,9 @@ public: /// Retrieves the last line of output generated by the command block const AString & GetLastOutput(void) const; + + /// Retrieves the result (signal strength) of the last operation + NIBBLETYPE GetResult(void) const; // tolua_end @@ -75,9 +82,11 @@ private: bool m_ShouldExecute; bool m_IsPowered; - AString m_Command; + AString m_Command; + + AString m_LastOutput; - AString m_LastOutput; + NIBBLETYPE m_Result; } ; // tolua_export -- cgit v1.2.3 From a037172465932de7d0d7d725c3c8ec5b2fa44029 Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 21:27:54 +0200 Subject: Command block fixes --- src/BlockEntities/CommandBlockEntity.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/BlockEntities/CommandBlockEntity.h') diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index c4529a1e6..12157670f 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -9,8 +9,7 @@ #pragma once -#include "BlockEntityWithItems.h" -#include "../UI/WindowOwner.h" +#include "BlockEntity.h" @@ -28,8 +27,7 @@ namespace Json // tolua_begin class cCommandBlockEntity : - public cBlockEntity, - public cBlockEntityWindowOwner + public cBlockEntity { typedef cBlockEntity super; @@ -39,7 +37,6 @@ public: /// 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; -- cgit v1.2.3