summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
Diffstat (limited to 'src/BlockEntities')
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp46
1 files changed, 35 insertions, 11 deletions
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index ca617b04d..0bc6ca359 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -7,6 +7,7 @@
#include "json/json.h"
#include "CommandBlockEntity.h"
#include "../Entities/Player.h"
+#include "../WorldStorage/FastNBT.h"
#include "../CommandOutput.h"
#include "../Root.h"
@@ -40,6 +41,15 @@ void cCommandBlockEntity::UsedBy(cPlayer * a_Player)
void cCommandBlockEntity::SetCommand(const AString & a_Cmd)
{
m_Command = a_Cmd;
+
+ /*
+ Vanilla requires that the server send a Block Entity Update after a command has been set
+ Therefore, command blocks don't support on-the-fly (when window is open) updating of a command and therefore...
+ ...the following code can't be put in UsedBy just before the window opens
+
+ Just documenting my experience in getting this to work :P
+ */
+ m_World->BroadcastBlockEntity(GetPosX(), GetPosY(), GetPosZ());
}
@@ -48,6 +58,7 @@ void cCommandBlockEntity::SetCommand(const AString & a_Cmd)
void cCommandBlockEntity::SetLastOutput(const AString & a_LastOut)
{
+ m_World->BroadcastBlockEntity(GetPosX(), GetPosY(), GetPosZ());
m_LastOutput = a_LastOut;
}
@@ -131,8 +142,7 @@ bool cCommandBlockEntity::Tick(float a_Dt, cChunk & a_Chunk)
void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
{
- // Nothing needs to be sent
- UNUSED(a_Client);
+ a_Client.SendUpdateBlockEntity(*this);
}
@@ -141,9 +151,13 @@ void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
{
- m_Command = a_Value.get("Command", "").asString();
+ m_PosX = a_Value.get("x", 0).asInt();
+ m_PosY = a_Value.get("y", 0).asInt();
+ m_PosZ = a_Value.get("z", 0).asInt();
- m_LastOutput = a_Value.get("LastOutput", "").asString();
+ m_Command = a_Value.get("Command", "").asString();
+ m_LastOutput = a_Value.get("LastOutput", "").asString();
+ m_Result = a_Value.get("SuccessCount", 0).asInt();
return true;
}
@@ -154,9 +168,13 @@ bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
{
- a_Value["Command"] = m_Command;
+ a_Value["x"] = m_PosX;
+ a_Value["y"] = m_PosY;
+ a_Value["z"] = m_PosZ;
- a_Value["LastOutput"] = m_LastOutput;
+ a_Value["Command"] = m_Command;
+ a_Value["LastOutput"] = m_LastOutput;
+ a_Value["SuccessCount"] = m_Result;
}
@@ -165,18 +183,24 @@ void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
void cCommandBlockEntity::Execute()
{
+ if (m_World != NULL)
+ {
+ if (!m_World->AreCommandBlocksEnabled())
+ {
+ return;
+ }
+ }
+
class CommandBlockOutCb :
public cCommandOutputCallback
{
- cCommandBlockEntity* m_CmdBlock;
+ cCommandBlockEntity * m_CmdBlock;
public:
- CommandBlockOutCb(cCommandBlockEntity* a_CmdBlock) : m_CmdBlock(a_CmdBlock) {}
+ CommandBlockOutCb(cCommandBlockEntity * a_CmdBlock) : m_CmdBlock(a_CmdBlock) {}
virtual void Out(const AString & a_Text)
{
- ASSERT(m_CmdBlock != NULL);
-
// Overwrite field
m_CmdBlock->SetLastOutput(a_Text);
}
@@ -184,7 +208,7 @@ void cCommandBlockEntity::Execute()
LOGD("cCommandBlockEntity: Executing command %s", m_Command.c_str());
- cServer* Server = cRoot::Get()->GetServer();
+ cServer * Server = cRoot::Get()->GetServer();
Server->ExecuteConsoleCommand(m_Command, CmdBlockOutCb);