summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BeaconEntity.cpp237
-rw-r--r--src/BlockEntities/BeaconEntity.h77
-rw-r--r--src/BlockEntities/BlockEntity.h7
-rw-r--r--src/BlockEntities/BlockEntityWithItems.h11
-rw-r--r--src/BlockEntities/ChestEntity.cpp44
-rw-r--r--src/BlockEntities/ChestEntity.h5
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp73
-rw-r--r--src/BlockEntities/CommandBlockEntity.h10
-rw-r--r--src/BlockEntities/DispenserEntity.cpp8
-rw-r--r--src/BlockEntities/DropSpenserEntity.cpp50
-rw-r--r--src/BlockEntities/DropSpenserEntity.h15
-rw-r--r--src/BlockEntities/DropperEntity.cpp3
-rw-r--r--src/BlockEntities/EnderChestEntity.cpp4
-rw-r--r--src/BlockEntities/EnderChestEntity.h2
-rw-r--r--src/BlockEntities/FlowerPotEntity.cpp34
-rw-r--r--src/BlockEntities/FlowerPotEntity.h5
-rw-r--r--src/BlockEntities/FurnaceEntity.cpp57
-rw-r--r--src/BlockEntities/FurnaceEntity.h6
-rw-r--r--src/BlockEntities/HopperEntity.cpp24
-rw-r--r--src/BlockEntities/HopperEntity.h1
-rw-r--r--src/BlockEntities/JukeboxEntity.cpp32
-rw-r--r--src/BlockEntities/JukeboxEntity.h4
-rw-r--r--src/BlockEntities/MobHeadEntity.cpp33
-rw-r--r--src/BlockEntities/MobHeadEntity.h5
-rw-r--r--src/BlockEntities/NoteEntity.cpp31
-rw-r--r--src/BlockEntities/NoteEntity.h16
-rw-r--r--src/BlockEntities/RedstonePoweredEntity.h13
-rw-r--r--src/BlockEntities/SignEntity.cpp40
-rw-r--r--src/BlockEntities/SignEntity.h3
29 files changed, 368 insertions, 482 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp
index 4b9662797..02f45a097 100644
--- a/src/BlockEntities/BeaconEntity.cpp
+++ b/src/BlockEntities/BeaconEntity.cpp
@@ -3,33 +3,31 @@
#include "BeaconEntity.h"
#include "../BlockArea.h"
+#include "../Entities/Player.h"
-cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, a_World)
+cBeaconEntity::cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World)
+ : super(E_BLOCK_BEACON, a_BlockX, a_BlockY, a_BlockZ, 1, 1, a_World)
+ , m_IsActive(false)
+ , m_BeaconLevel(0)
+ , m_PrimaryEffect(cEntityEffect::effNoEffect)
+ , m_SecondaryEffect(cEntityEffect::effNoEffect)
{
+ UpdateBeacon();
}
-int cBeaconEntity::GetPyramidLevel(void)
+char cBeaconEntity::CalculatePyramidLevel(void)
{
cBlockArea Area;
- int MinY = GetPosY() - 4;
- if (MinY < 0)
- {
- MinY = 0;
- }
- int MaxY = GetPosY() - 1;
- if (MaxY < 0)
- {
- MaxY = 0;
- }
+ int MinY = std::max(GetPosY() - 4, 0);
+ int MaxY = std::max(GetPosY() - 1, 0);
Area.Read(
m_World,
@@ -42,7 +40,7 @@ int cBeaconEntity::GetPyramidLevel(void)
int Layer = 1;
int MiddleXZ = 4;
- for (int Y = Area.GetSizeY() - 1; Y > 0; Y--)
+ for (int Y = (Area.GetSizeY() - 1); Y >= 0; Y--)
{
for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++)
{
@@ -50,14 +48,99 @@ int cBeaconEntity::GetPyramidLevel(void)
{
if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z)))
{
- return Layer - 1;
+ return (Layer - 1);
}
}
}
Layer++;
}
- return Layer - 1;
+ return (Layer - 1);
+}
+
+
+
+
+
+bool cBeaconEntity::IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel)
+{
+ switch (a_Effect)
+ {
+ case cEntityEffect::effRegeneration: return (a_BeaconLevel >= 4);
+ case cEntityEffect::effStrength: return (a_BeaconLevel >= 3);
+ case cEntityEffect::effResistance: return (a_BeaconLevel >= 2);
+ case cEntityEffect::effJumpBoost: return (a_BeaconLevel >= 2);
+ case cEntityEffect::effSpeed: return (a_BeaconLevel >= 1);
+ case cEntityEffect::effHaste: return (a_BeaconLevel >= 1);
+ case cEntityEffect::effNoEffect: return true;
+
+ default:
+ {
+ LOGD("%s: Invalid beacon effect: %d", __FUNCTION__, (int)a_Effect);
+ return false;
+ }
+ }
+}
+
+
+
+
+
+bool cBeaconEntity::SetPrimaryEffect(cEntityEffect::eType a_Effect)
+{
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
+ {
+ m_PrimaryEffect = cEntityEffect::effNoEffect;
+ return false;
+ }
+
+ m_PrimaryEffect = a_Effect;
+
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(1, m_PrimaryEffect);
+ }
+ return true;
+}
+
+
+
+
+
+bool cBeaconEntity::SetSecondaryEffect(cEntityEffect::eType a_Effect)
+{
+ if (!IsValidEffect(a_Effect, m_BeaconLevel))
+ {
+ m_SecondaryEffect = cEntityEffect::effNoEffect;
+ return false;
+ }
+
+ m_SecondaryEffect = a_Effect;
+
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(2, m_SecondaryEffect);
+ }
+ return true;
+}
+
+
+
+
+
+bool cBeaconEntity::IsBeaconBlocked(void)
+{
+ for (int Y = m_PosY; Y < cChunkDef::Height; ++Y)
+ {
+ BLOCKTYPE Block = m_World->GetBlock(m_PosX, Y, m_PosZ);
+ if (!cBlockInfo::IsTransparent(Block))
+ {
+ return true;
+ }
+ }
+ return false;
}
@@ -83,24 +166,114 @@ bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType)
-bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk)
+void cBeaconEntity::UpdateBeacon(void)
{
- return false;
+ int OldBeaconLevel = m_BeaconLevel;
+
+ if (IsBeaconBlocked())
+ {
+ m_IsActive = false;
+ m_BeaconLevel = 0;
+ }
+ else
+ {
+ m_BeaconLevel = CalculatePyramidLevel();
+ m_IsActive = (m_BeaconLevel > 0);
+ }
+
+ if (m_BeaconLevel != OldBeaconLevel)
+ {
+ // Send window update:
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->SetProperty(0, m_BeaconLevel);
+ }
+ }
+
+ // TODO: Add achievement
}
-void cBeaconEntity::SaveToJson(Json::Value& a_Value)
+void cBeaconEntity::GiveEffects(void)
{
+ if (!m_IsActive || (m_BeaconLevel < 0))
+ {
+ return;
+ }
+
+ int Radius = m_BeaconLevel * 10 + 10;
+ short EffectLevel = 0;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect == m_SecondaryEffect))
+ {
+ EffectLevel = 1;
+ }
+
+ cEntityEffect::eType SecondaryEffect = cEntityEffect::effNoEffect;
+ if ((m_BeaconLevel >= 4) && (m_PrimaryEffect != m_SecondaryEffect) && (m_SecondaryEffect > 0))
+ {
+ SecondaryEffect = m_SecondaryEffect;
+ }
+
+ class cPlayerCallback : public cPlayerListCallback
+ {
+ int m_Radius;
+ int m_PosX, m_PosY, m_PosZ;
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
+ short m_EffectLevel;
+
+ virtual bool Item(cPlayer * a_Player)
+ {
+ Vector3d PlayerPosition = Vector3d(a_Player->GetPosition());
+ if (PlayerPosition.y > (double)m_PosY)
+ {
+ PlayerPosition.y = (double)m_PosY;
+ }
+
+ // TODO: Vanilla minecraft uses an AABB check instead of a radius one
+ Vector3d BeaconPosition = Vector3d(m_PosX, m_PosY, m_PosZ);
+ if ((PlayerPosition - BeaconPosition).Length() <= m_Radius)
+ {
+ a_Player->AddEntityEffect(m_PrimaryEffect, 180, m_EffectLevel);
+
+ if (m_SecondaryEffect != cEntityEffect::effNoEffect)
+ {
+ a_Player->AddEntityEffect(m_SecondaryEffect, 180, 0);
+ }
+ }
+ return false;
+ }
+
+ public:
+ cPlayerCallback(int a_Radius, int a_PosX, int a_PosY, int a_PosZ, cEntityEffect::eType a_PrimaryEffect, cEntityEffect::eType a_SecondaryEffect, short a_EffectLevel)
+ : m_Radius(a_Radius)
+ , m_PosX(a_PosX)
+ , m_PosY(a_PosY)
+ , m_PosZ(a_PosZ)
+ , m_PrimaryEffect(a_PrimaryEffect)
+ , m_SecondaryEffect(a_SecondaryEffect)
+ , m_EffectLevel(a_EffectLevel)
+ {};
+
+ } PlayerCallback(Radius, m_PosX, m_PosY, m_PosZ, m_PrimaryEffect, SecondaryEffect, EffectLevel);
+ GetWorld()->ForEachPlayer(PlayerCallback);
}
-void cBeaconEntity::SendTo(cClientHandle & a_Client)
+
+bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk)
{
+ // Update the beacon every 4 seconds
+ if ((GetWorld()->GetWorldAge() % 80) == 0)
+ {
+ UpdateBeacon();
+ GiveEffects();
+ }
+ return false;
}
@@ -109,6 +282,30 @@ void cBeaconEntity::SendTo(cClientHandle & a_Client)
void cBeaconEntity::UsedBy(cPlayer * a_Player)
{
+ cWindow * Window = GetWindow();
+ if (Window == NULL)
+ {
+ OpenWindow(new cBeaconWindow(m_PosX, m_PosY, m_PosZ, this));
+ Window = GetWindow();
+ }
+
+ if (Window != NULL)
+ {
+ // if (a_Player->GetWindow() != Window)
+ // -> Because mojang doesn't send a 'close window' packet when you click the cancel button in the beacon inventory ...
+ {
+ a_Player->OpenWindow(Window);
+ }
+ }
+}
+
+
+
+
+
+void cBeaconEntity::SendTo(cClientHandle & a_Client)
+{
+ a_Client.SendUpdateBlockEntity(*this);
}
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index ee1eda391..8c2dad254 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -1,7 +1,14 @@
+// BeaconEntity.h
+
+// Declares the cBeaconEntity class representing a single beacon in the world
+
+
+
+
#pragma once
-#include "BlockEntity.h"
+#include "BlockEntityWithItems.h"
@@ -16,28 +23,68 @@ namespace Json
+// tolua_begin
class cBeaconEntity :
- public cBlockEntity
+ public cBlockEntityWithItems
{
- typedef cBlockEntity super;
+ typedef cBlockEntityWithItems super;
public:
-
- /** The initial constructor */
+ // tolua_end
+
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
-
- /** Returns the amount of layers the pyramid below the beacon has. */
- int GetPyramidLevel(void);
+
+ // cBlockEntity overrides:
+ virtual void SendTo(cClientHandle & a_Client) override;
+ virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void UsedBy(cPlayer * a_Player) override;
+
+ /** Modify the beacon level. (It is needed to load the beacon corectly) */
+ void SetBeaconLevel(char a_Level) { m_BeaconLevel = a_Level; }
+
+ // tolua_begin
+
+ /** Is the beacon active? */
+ bool IsActive(void) const { return m_IsActive; }
+
+ /** Returns the beacon level. (0 - 4) */
+ char GetBeaconLevel(void) const { return m_BeaconLevel; }
+
+ cEntityEffect::eType GetPrimaryEffect(void) const { return m_PrimaryEffect; }
+ cEntityEffect::eType GetSecondaryEffect(void) const { return m_SecondaryEffect; }
+
+ /** Sets the primary effect. Returns false when the effect is invalid. */
+ bool SetPrimaryEffect(cEntityEffect::eType a_Effect);
+
+ /** Sets the secondary effect. Returns false when the effect is invalid. */
+ bool SetSecondaryEffect(cEntityEffect::eType a_Effect);
+
+ /** Calculate the amount of layers the pyramid below the beacon has. */
+ char CalculatePyramidLevel(void);
+
+ /** Is the beacon blocked by non-transparent blocks that are higher than the beacon? */
+ bool IsBeaconBlocked(void);
+
+ /** Update the beacon. */
+ void UpdateBeacon(void);
+
+ /** Give the near-players the effects. */
+ void GiveEffects(void);
/** Returns true if the block is a diamond block, a golden block, an iron block or an emerald block. */
static bool IsMineralBlock(BLOCKTYPE a_BlockType);
-
- // cBlockEntity overrides:
- virtual void SaveToJson(Json::Value& a_Value) override;
- virtual void SendTo(cClientHandle & a_Client) override;
- virtual void UsedBy(cPlayer * a_Player) override;
- virtual bool Tick(float a_Dt, cChunk & /* a_Chunk */) override;
-} ;
+
+ /** Returns true if the effect can be used. */
+ static bool IsValidEffect(cEntityEffect::eType a_Effect, char a_BeaconLevel);
+
+ // tolua_end
+
+protected:
+ bool m_IsActive;
+ char m_BeaconLevel;
+
+ cEntityEffect::eType m_PrimaryEffect, m_SecondaryEffect;
+} ; // tolua_export
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index 5710f8543..54ab40f3e 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -1,8 +1,6 @@
#pragma once
-#include "../ClientHandle.h"
-#include "../World.h"
@@ -13,8 +11,9 @@ namespace Json
class Value;
};
+class cChunk;
class cPlayer;
-class cPacket;
+class cWorld;
@@ -75,8 +74,6 @@ public:
int GetRelZ(void) const { return m_RelZ; }
// tolua_end
-
- virtual void SaveToJson (Json::Value & a_Value) = 0;
/// Called when a player uses this entity; should open the UI window
virtual void UsedBy( cPlayer * a_Player) = 0;
diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h
index 5f1639d45..00173cbcb 100644
--- a/src/BlockEntities/BlockEntityWithItems.h
+++ b/src/BlockEntities/BlockEntityWithItems.h
@@ -12,6 +12,7 @@
#include "BlockEntity.h"
#include "../ItemGrid.h"
#include "../UI/WindowOwner.h"
+#include "World.h"
@@ -19,12 +20,9 @@
// tolua_begin
class cBlockEntityWithItems :
- public cBlockEntity
- // tolua_end
- // tolua doesn't seem to support multiple inheritance?
- , public cItemGrid::cListener
- , public cBlockEntityWindowOwner
- // tolua_begin
+ public cBlockEntity,
+ public cItemGrid::cListener,
+ public cBlockEntityWindowOwner
{
typedef cBlockEntity super;
@@ -38,6 +36,7 @@ public:
cWorld * a_World // Optional world to assign to the entity
) :
super(a_BlockType, a_BlockX, a_BlockY, a_BlockZ, a_World),
+ cBlockEntityWindowOwner(this),
m_Contents(a_ItemGridWidth, a_ItemGridHeight)
{
m_Contents.AddListener(*this);
diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp
index 21e1f6ba2..19d88b646 100644
--- a/src/BlockEntities/ChestEntity.cpp
+++ b/src/BlockEntities/ChestEntity.cpp
@@ -5,7 +5,6 @@
#include "../Item.h"
#include "../Entities/Player.h"
#include "../UI/Window.h"
-#include "json/json.h"
@@ -15,7 +14,6 @@ cChestEntity::cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_
super(a_Type, a_BlockX, a_BlockY, a_BlockZ, ContentsWidth, ContentsHeight, a_World),
m_NumActivePlayers(0)
{
- cBlockEntityWindowOwner::SetBlockEntity(this);
}
@@ -35,48 +33,6 @@ cChestEntity::~cChestEntity()
-bool cChestEntity::LoadFromJson(const Json::Value & a_Value)
-{
- m_PosX = a_Value.get("x", 0).asInt();
- m_PosY = a_Value.get("y", 0).asInt();
- m_PosZ = a_Value.get("z", 0).asInt();
-
- Json::Value AllSlots = a_Value.get("Slots", 0);
- int SlotIdx = 0;
- for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr)
- {
- cItem Item;
- Item.FromJson(*itr);
- SetSlot(SlotIdx, Item);
- SlotIdx++;
- }
- return true;
-}
-
-
-
-
-
-void cChestEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- Json::Value AllSlots;
- for (int i = m_Contents.GetNumSlots() - 1; i >= 0; i--)
- {
- Json::Value Slot;
- m_Contents.GetSlot(i).GetJson(Slot);
- AllSlots.append(Slot);
- }
- a_Value["Slots"] = AllSlots;
-}
-
-
-
-
-
void cChestEntity::SendTo(cClientHandle & a_Client)
{
// The chest entity doesn't need anything sent to the client when it's created / gets in the viewdistance
diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h
index cd06b3e2c..af5d851a8 100644
--- a/src/BlockEntities/ChestEntity.h
+++ b/src/BlockEntities/ChestEntity.h
@@ -13,8 +13,6 @@ namespace Json
};
class cClientHandle;
-class cServer;
-class cNBTData;
@@ -41,11 +39,8 @@ public:
virtual ~cChestEntity();
static const char * GetClassStatic(void) { return "cChestEntity"; }
-
- bool LoadFromJson(const Json::Value & a_Value);
// cBlockEntity overrides:
- virtual void SaveToJson(Json::Value & a_Value) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index 45f8a3e4d..1a5a3f01e 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -4,15 +4,14 @@
// Implements the cCommandBlockEntity class representing a single command block in the world
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "json/json.h"
#include "CommandBlockEntity.h"
-#include "../Entities/Player.h"
-#include "../WorldStorage/FastNBT.h"
#include "../CommandOutput.h"
#include "../Root.h"
#include "../Server.h" // ExecuteConsoleCommand()
-#include "../Chunk.h"
+#include "../ChatColor.h"
+#include "../World.h"
+#include "../ClientHandle.h"
@@ -153,46 +152,13 @@ void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
-bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
-{
- 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_Command = a_Value.get("Command", "").asString();
- m_LastOutput = a_Value.get("LastOutput", "").asString();
- m_Result = (NIBBLETYPE)a_Value.get("SuccessCount", 0).asInt();
-
- return true;
-}
-
-
-
-
-
-void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- a_Value["Command"] = m_Command;
- a_Value["LastOutput"] = m_LastOutput;
- a_Value["SuccessCount"] = m_Result;
-}
-
-
-
-
-
void cCommandBlockEntity::Execute()
{
- if (m_World != NULL)
+ ASSERT(m_World != NULL); // Execute should not be called before the command block is attached to a world
+
+ if (!m_World->AreCommandBlocksEnabled())
{
- if (!m_World->AreCommandBlocksEnabled())
- {
- return;
- }
+ return;
}
class CommandBlockOutCb :
@@ -206,15 +172,28 @@ void cCommandBlockEntity::Execute()
virtual void Out(const AString & a_Text)
{
// Overwrite field
- m_CmdBlock->SetLastOutput(a_Text);
+ m_CmdBlock->SetLastOutput(cClientHandle::FormatChatPrefix(m_CmdBlock->GetWorld()->ShouldUseChatPrefixes(), "SUCCESS", cChatColor::Green, cChatColor::White) + a_Text);
}
} CmdBlockOutCb(this);
- LOGD("cCommandBlockEntity: Executing command %s", m_Command.c_str());
-
- cServer * Server = cRoot::Get()->GetServer();
-
- Server->ExecuteConsoleCommand(m_Command, CmdBlockOutCb);
+ // Administrator commands are not executable by command blocks:
+ if (
+ (m_Command != "stop") &&
+ (m_Command != "restart") &&
+ (m_Command != "kick") &&
+ (m_Command != "ban") &&
+ (m_Command != "ipban")
+ )
+ {
+ cServer * Server = cRoot::Get()->GetServer();
+ LOGD("cCommandBlockEntity: Executing command %s", m_Command.c_str());
+ Server->ExecuteConsoleCommand(m_Command, CmdBlockOutCb);
+ }
+ else
+ {
+ SetLastOutput(cClientHandle::FormatChatPrefix(GetWorld()->ShouldUseChatPrefixes(), "FAILURE", cChatColor::Rose, cChatColor::White) + "Adminstration commands can not be executed");
+ LOGD("cCommandBlockEntity: Prevented execution of administration command %s", m_Command.c_str());
+ }
// TODO 2014-01-18 xdot: Update the signal strength.
m_Result = 0;
diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h
index d02bf7d7b..939f38610 100644
--- a/src/BlockEntities/CommandBlockEntity.h
+++ b/src/BlockEntities/CommandBlockEntity.h
@@ -10,7 +10,7 @@
#pragma once
#include "BlockEntity.h"
-
+#include "RedstonePoweredEntity.h"
@@ -27,7 +27,8 @@ namespace Json
// tolua_begin
class cCommandBlockEntity :
- public cBlockEntity
+ public cBlockEntity,
+ public cRedstonePoweredEntity
{
typedef cBlockEntity super;
@@ -38,9 +39,6 @@ public:
/// Creates a new empty command block entity
cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
- 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;
@@ -52,7 +50,7 @@ public:
// 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);
+ virtual void SetRedstonePower(bool a_IsPowered) override;
/// Sets the command block to execute a command in the next tick
void Activate(void);
diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp
index c02c68afa..aea854dc2 100644
--- a/src/BlockEntities/DispenserEntity.cpp
+++ b/src/BlockEntities/DispenserEntity.cpp
@@ -2,13 +2,10 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "DispenserEntity.h"
-#include "../Entities/Player.h"
#include "../Simulator/FluidSimulator.h"
#include "../Chunk.h"
#include "../World.h"
-#include "../Entities/ArrowEntity.h"
-#include "../Entities/FireChargeEntity.h"
#include "../Entities/ProjectileEntity.h"
@@ -17,7 +14,6 @@
cDispenserEntity::cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
super(E_BLOCK_DISPENSER, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
- SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -109,7 +105,7 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum)
{
double MobX = 0.5 + (DispX + DispChunk->GetPosX() * cChunkDef::Width);
double MobZ = 0.5 + (DispZ + DispChunk->GetPosZ() * cChunkDef::Width);
- if (m_World->SpawnMob(MobX, DispY, MobZ, (cMonster::eType)m_Contents.GetSlot(a_SlotNum).m_ItemDamage) >= 0)
+ if (m_World->SpawnMob(MobX, DispY, MobZ, (eMonsterType)m_Contents.GetSlot(a_SlotNum).m_ItemDamage) >= 0)
{
m_Contents.ChangeSlotCount(a_SlotNum, -1);
}
@@ -203,7 +199,7 @@ void cDispenserEntity::SpawnProjectileFromDispenser(int a_BlockX, int a_BlockY,
Vector3d cDispenserEntity::GetShootVector(NIBBLETYPE a_Meta)
{
- switch (a_Meta)
+ switch (a_Meta & 0x7)
{
case E_META_DROPSPENSER_FACING_YP: return Vector3d( 0, 1, 0);
case E_META_DROPSPENSER_FACING_YM: return Vector3d( 0, -1, 0);
diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp
index dc38e3e9b..dac951b27 100644
--- a/src/BlockEntities/DropSpenserEntity.cpp
+++ b/src/BlockEntities/DropSpenserEntity.cpp
@@ -8,7 +8,6 @@
#include "DropSpenserEntity.h"
#include "../Entities/Player.h"
#include "../Chunk.h"
-#include "json/json.h"
@@ -19,7 +18,6 @@ cDropSpenserEntity::cDropSpenserEntity(BLOCKTYPE a_BlockType, int a_BlockX, int
m_ShouldDropSpense(false),
m_IsPowered(false)
{
- SetBlockEntity(this); // cBlockEntityWindowOwner
}
@@ -144,54 +142,6 @@ bool cDropSpenserEntity::Tick(float a_Dt, cChunk & a_Chunk)
-bool cDropSpenserEntity::LoadFromJson(const Json::Value & a_Value)
-{
- m_PosX = a_Value.get("x", 0).asInt();
- m_PosY = a_Value.get("y", 0).asInt();
- m_PosZ = a_Value.get("z", 0).asInt();
-
- Json::Value AllSlots = a_Value.get("Slots", 0);
- int SlotIdx = 0;
- for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr)
- {
- cItem Contents;
- Contents.FromJson(*itr);
- m_Contents.SetSlot(SlotIdx, Contents);
- SlotIdx++;
- if (SlotIdx >= m_Contents.GetNumSlots())
- {
- return true;
- }
- }
-
- return true;
-}
-
-
-
-
-
-void cDropSpenserEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- Json::Value AllSlots;
- int NumSlots = m_Contents.GetNumSlots();
- for (int i = 0; i < NumSlots; i++)
- {
- Json::Value Slot;
- m_Contents.GetSlot(i).GetJson(Slot);
- AllSlots.append(Slot);
- }
- a_Value["Slots"] = AllSlots;
-}
-
-
-
-
-
void cDropSpenserEntity::SendTo(cClientHandle & a_Client)
{
// Nothing needs to be sent
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index 9f58d0b07..23f0ae89a 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -11,7 +11,7 @@
#pragma once
#include "BlockEntityWithItems.h"
-
+#include "RedstonePoweredEntity.h"
@@ -22,7 +22,6 @@ namespace Json
}
class cClientHandle;
-class cServer;
@@ -31,6 +30,9 @@ class cServer;
// tolua_begin
class cDropSpenserEntity :
public cBlockEntityWithItems
+ // tolua_end
+ , public cRedstonePoweredEntity
+ // tolua_begin
{
typedef cBlockEntityWithItems super;
@@ -47,11 +49,8 @@ public:
virtual ~cDropSpenserEntity();
static const char * GetClassStatic(void) { return "cDropSpenserEntity"; }
-
- bool LoadFromJson(const Json::Value & a_Value);
// cBlockEntity overrides:
- 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;
@@ -64,10 +63,10 @@ public:
/// Sets the dropspenser to dropspense an item in the next tick
void Activate(void);
- /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
- void SetRedstonePower(bool a_IsPowered);
-
// tolua_end
+
+ /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ virtual void SetRedstonePower(bool a_IsPowered) override;
protected:
bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick
diff --git a/src/BlockEntities/DropperEntity.cpp b/src/BlockEntities/DropperEntity.cpp
index 5d4a8ad97..38d1aa988 100644
--- a/src/BlockEntities/DropperEntity.cpp
+++ b/src/BlockEntities/DropperEntity.cpp
@@ -5,8 +5,6 @@
#include "Globals.h"
#include "DropperEntity.h"
-#include "../Entities/Player.h"
-#include "../Simulator/FluidSimulator.h"
@@ -15,7 +13,6 @@
cDropperEntity::cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
super(E_BLOCK_DROPPER, a_BlockX, a_BlockY, a_BlockZ, a_World)
{
- SetBlockEntity(this); // cBlockEntityWindowOwner
}
diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp
index 17816d63e..0654d97dd 100644
--- a/src/BlockEntities/EnderChestEntity.cpp
+++ b/src/BlockEntities/EnderChestEntity.cpp
@@ -5,14 +5,14 @@
#include "../Item.h"
#include "../Entities/Player.h"
#include "../UI/Window.h"
-#include "json/json.h"
cEnderChestEntity::cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
- super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World)
+ super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World),
+ cBlockEntityWindowOwner(this)
{
}
diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h
index ed178f6fc..2719eb5e4 100644
--- a/src/BlockEntities/EnderChestEntity.h
+++ b/src/BlockEntities/EnderChestEntity.h
@@ -3,7 +3,6 @@
#include "BlockEntity.h"
#include "UI/WindowOwner.h"
-#include "json/json.h"
@@ -26,7 +25,6 @@ public:
// cBlockEntity overrides:
virtual void UsedBy(cPlayer * a_Player) override;
- virtual void SaveToJson(Json::Value & a_Value) override { UNUSED(a_Value); }
virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); }
static void LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid);
diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp
index 87bf8b921..01560f814 100644
--- a/src/BlockEntities/FlowerPotEntity.cpp
+++ b/src/BlockEntities/FlowerPotEntity.cpp
@@ -1,10 +1,9 @@
// FlowerPotEntity.cpp
-// Implements the cFlowerPotEntity class representing a single sign in the world
+// Implements the cFlowerPotEntity class representing a single flower pot in the world
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "json/json.h"
#include "FlowerPotEntity.h"
#include "../Entities/Player.h"
#include "../Item.h"
@@ -73,37 +72,6 @@ void cFlowerPotEntity::Destroy(void)
-bool cFlowerPotEntity::LoadFromJson(const Json::Value & a_Value)
-{
- 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_Item = cItem();
- m_Item.FromJson(a_Value.get("Item", 0));
-
- return true;
-}
-
-
-
-
-
-void cFlowerPotEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- Json::Value Item;
- m_Item.GetJson(Item);
- a_Value["Item"] = Item;
-}
-
-
-
-
-
bool cFlowerPotEntity::IsFlower(short m_ItemType, short m_ItemData)
{
switch (m_ItemType)
diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h
index 89901cf2d..b68d3b118 100644
--- a/src/BlockEntities/FlowerPotEntity.h
+++ b/src/BlockEntities/FlowerPotEntity.h
@@ -9,8 +9,8 @@
#pragma once
#include "BlockEntity.h"
+#include "Item.h"
-class cItem;
@@ -38,9 +38,6 @@ public:
/** Creates a new flowerpot entity at the specified block coords. a_World may be NULL */
cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World);
-
- bool LoadFromJson( const Json::Value& a_Value);
- virtual void SaveToJson(Json::Value& a_Value) override;
virtual void Destroy(void) override;
diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp
index 72fd7f2b3..4452fc00a 100644
--- a/src/BlockEntities/FurnaceEntity.cpp
+++ b/src/BlockEntities/FurnaceEntity.cpp
@@ -5,8 +5,6 @@
#include "../UI/Window.h"
#include "../Entities/Player.h"
#include "../Root.h"
-#include "../Chunk.h"
-#include "json/json.h"
@@ -36,7 +34,6 @@ cFurnaceEntity::cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY
m_LastProgressFuel(0),
m_LastProgressCook(0)
{
- cBlockEntityWindowOwner::SetBlockEntity(this);
m_Contents.AddListener(*this);
}
@@ -132,60 +129,6 @@ bool cFurnaceEntity::Tick(float a_Dt, cChunk & a_Chunk)
-bool cFurnaceEntity::LoadFromJson(const Json::Value & a_Value)
-{
- m_PosX = a_Value.get("x", 0).asInt();
- m_PosY = a_Value.get("y", 0).asInt();
- m_PosZ = a_Value.get("z", 0).asInt();
-
- Json::Value AllSlots = a_Value.get("Slots", 0);
- int SlotIdx = 0;
- for (Json::Value::iterator itr = AllSlots.begin(); itr != AllSlots.end(); ++itr)
- {
- cItem Item;
- Item.FromJson(*itr);
- SetSlot(SlotIdx, Item);
- SlotIdx++;
- }
-
- m_NeedCookTime = (int)(a_Value.get("CookTime", 0).asDouble() / 50);
- m_TimeCooked = (int)(a_Value.get("TimeCooked", 0).asDouble() / 50);
- m_FuelBurnTime = (int)(a_Value.get("BurnTime", 0).asDouble() / 50);
- m_TimeBurned = (int)(a_Value.get("TimeBurned", 0).asDouble() / 50);
-
- return true;
-}
-
-
-
-
-
-void cFurnaceEntity::SaveToJson( Json::Value& a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- Json::Value AllSlots;
- int NumSlots = m_Contents.GetNumSlots();
- for (int i = 0; i < NumSlots; i++)
- {
- Json::Value Slot;
- m_Contents.GetSlot(i).GetJson(Slot);
- AllSlots.append(Slot);
- }
- a_Value["Slots"] = AllSlots;
-
- a_Value["CookTime"] = m_NeedCookTime * 50;
- a_Value["TimeCooked"] = m_TimeCooked * 50;
- a_Value["BurnTime"] = m_FuelBurnTime * 50;
- a_Value["TimeBurned"] = m_TimeBurned * 50;
-}
-
-
-
-
-
void cFurnaceEntity::SendTo(cClientHandle & a_Client)
{
// Nothing needs to be sent
diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h
index 4f935a74b..ed3317af6 100644
--- a/src/BlockEntities/FurnaceEntity.h
+++ b/src/BlockEntities/FurnaceEntity.h
@@ -14,7 +14,6 @@ namespace Json
}
class cClientHandle;
-class cServer;
@@ -45,11 +44,8 @@ public:
virtual ~cFurnaceEntity();
static const char * GetClassStatic() { return "cFurnaceEntity"; }
-
- bool LoadFromJson(const Json::Value & a_Value);
// cBlockEntity overrides:
- virtual void SaveToJson(Json::Value & a_Value) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void UsedBy(cPlayer * a_Player) override;
@@ -105,7 +101,7 @@ protected:
NIBBLETYPE m_BlockMeta;
/// The recipe for the current input slot
- const cFurnaceRecipe::Recipe * m_CurrentRecipe;
+ const cFurnaceRecipe::cRecipe * m_CurrentRecipe;
/// The item that is being smelted
cItem m_LastInput;
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 48d3b8dcc..103f516fc 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -10,10 +10,7 @@
#include "../Entities/Pickup.h"
#include "../Bindings/PluginManager.h"
#include "ChestEntity.h"
-#include "DropSpenserEntity.h"
#include "FurnaceEntity.h"
-#include "../BoundingBox.h"
-#include "json/json.h"
@@ -73,17 +70,6 @@ bool cHopperEntity::Tick(float a_Dt, cChunk & a_Chunk)
-void cHopperEntity::SaveToJson(Json::Value & a_Value)
-{
- UNUSED(a_Value);
- // TODO
- LOGWARNING("%s: Not implemented yet", __FUNCTION__);
-}
-
-
-
-
-
void cHopperEntity::SendTo(cClientHandle & a_Client)
{
// The hopper entity doesn't need anything sent to the client when it's created / gets in the viewdistance
@@ -549,13 +535,13 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl
bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ)
{
// Try the chest directly connected to the hopper:
- cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
- if (Chest == NULL)
+ cChestEntity * ConnectedChest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ);
+ if (ConnectedChest == NULL)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ);
return false;
}
- if (MoveItemsToGrid(*Chest))
+ if (MoveItemsToGrid(*ConnectedChest))
{
// Chest block directly connected was not full
return true;
@@ -586,13 +572,13 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block
}
BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z);
- if (Block != Chest->GetBlockType())
+ if (Block != ConnectedChest->GetBlockType())
{
// Not the same kind of chest
continue;
}
- Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z);
+ cChestEntity * Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z);
if (Chest == NULL)
{
LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z);
diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h
index 8e856fcda..5d06581c2 100644
--- a/src/BlockEntities/HopperEntity.h
+++ b/src/BlockEntities/HopperEntity.h
@@ -49,7 +49,6 @@ protected:
// cBlockEntity overrides:
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
- virtual void SaveToJson(Json::Value & a_Value) override;
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp
index c96253b11..bb9b335e0 100644
--- a/src/BlockEntities/JukeboxEntity.cpp
+++ b/src/BlockEntities/JukeboxEntity.cpp
@@ -3,8 +3,8 @@
#include "JukeboxEntity.h"
#include "../World.h"
-#include "json/json.h"
-
+#include "json/value.h"
+#include "Entities/Player.h"
@@ -117,31 +117,3 @@ void cJukeboxEntity::SetRecord(int a_Record)
-
-bool cJukeboxEntity::LoadFromJson(const Json::Value & a_Value)
-{
- 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_Record = a_Value.get("Record", 0).asInt();
-
- return true;
-}
-
-
-
-
-
-void cJukeboxEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- a_Value["Record"] = m_Record;
-}
-
-
-
-
diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h
index d677d340f..49d2faa89 100644
--- a/src/BlockEntities/JukeboxEntity.h
+++ b/src/BlockEntities/JukeboxEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntity.h"
-#include "../Entities/Player.h"
@@ -30,9 +29,6 @@ public:
cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cJukeboxEntity();
- bool LoadFromJson(const Json::Value & a_Value);
- virtual void SaveToJson(Json::Value & a_Value) override;
-
// tolua_begin
int GetRecord(void);
diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp
index ce895eb6f..67e13ffb2 100644
--- a/src/BlockEntities/MobHeadEntity.cpp
+++ b/src/BlockEntities/MobHeadEntity.cpp
@@ -4,7 +4,6 @@
// Implements the cMobHeadEntity class representing a single skull/head in the world
#include "Globals.h"
-#include "json/json.h"
#include "MobHeadEntity.h"
#include "../Entities/Player.h"
@@ -78,35 +77,3 @@ void cMobHeadEntity::SendTo(cClientHandle & a_Client)
-
-bool cMobHeadEntity::LoadFromJson(const Json::Value & a_Value)
-{
- 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_Type = static_cast<eMobHeadType>(a_Value.get("Type", 0).asInt());
- m_Rotation = static_cast<eMobHeadRotation>(a_Value.get("Rotation", 0).asInt());
- m_Owner = a_Value.get("Owner", "").asString();
-
- return true;
-}
-
-
-
-
-
-void cMobHeadEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- a_Value["Type"] = m_Type;
- a_Value["Rotation"] = m_Rotation;
- a_Value["Owner"] = m_Owner;
-}
-
-
-
-
diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h
index f91a3cc9e..fcdeaa8a6 100644
--- a/src/BlockEntities/MobHeadEntity.h
+++ b/src/BlockEntities/MobHeadEntity.h
@@ -9,7 +9,7 @@
#pragma once
#include "BlockEntity.h"
-
+#include "Defines.h"
@@ -37,9 +37,6 @@ public:
/** Creates a new mob head entity at the specified block coords. a_World may be NULL */
cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
- bool LoadFromJson( const Json::Value& a_Value);
- virtual void SaveToJson(Json::Value& a_Value) override;
-
// tolua_begin
/** Set the Type */
diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp
index 95145c117..a9af13c55 100644
--- a/src/BlockEntities/NoteEntity.cpp
+++ b/src/BlockEntities/NoteEntity.cpp
@@ -3,7 +3,7 @@
#include "NoteEntity.h"
#include "../World.h"
-#include "json/json.h"
+#include "json/value.h"
@@ -124,32 +124,3 @@ void cNoteEntity::IncrementPitch(void)
-
-bool cNoteEntity::LoadFromJson(const Json::Value & a_Value)
-{
-
- 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_Pitch = (char)a_Value.get("p", 0).asInt();
-
- return true;
-}
-
-
-
-
-
-void cNoteEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- a_Value["p"] = m_Pitch;
-}
-
-
-
-
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index e8497da3e..d1ffa126a 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -2,6 +2,7 @@
#pragma once
#include "BlockEntity.h"
+#include "RedstonePoweredEntity.h"
namespace Json
@@ -30,6 +31,9 @@ enum ENUM_NOTE_INSTRUMENTS
class cNoteEntity :
public cBlockEntity
+ // tolua_end
+ , public cRedstonePoweredEntity
+ // tolua_begin
{
typedef cBlockEntity super;
public:
@@ -38,9 +42,7 @@ public:
/// Creates a new note entity. a_World may be NULL
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
-
- bool LoadFromJson(const Json::Value & a_Value);
- virtual void SaveToJson(Json::Value & a_Value) override;
+ virtual ~cNoteEntity() {}
// tolua_begin
@@ -53,6 +55,14 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}
+
+ virtual void SetRedstonePower(bool a_Value)
+ {
+ if (a_Value)
+ {
+ MakeSound();
+ }
+ }
static const char * GetClassStatic(void) { return "cNoteEntity"; }
diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h
new file mode 100644
index 000000000..eac4e35d4
--- /dev/null
+++ b/src/BlockEntities/RedstonePoweredEntity.h
@@ -0,0 +1,13 @@
+
+#pragma once
+
+// Interface class representing a blockEntity that responds to redstone
+class cRedstonePoweredEntity
+{
+public:
+
+ virtual ~cRedstonePoweredEntity() {}
+
+ /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate
+ virtual void SetRedstonePower(bool a_IsPowered) = 0;
+};
diff --git a/src/BlockEntities/SignEntity.cpp b/src/BlockEntities/SignEntity.cpp
index 97fed0f04..d048d0218 100644
--- a/src/BlockEntities/SignEntity.cpp
+++ b/src/BlockEntities/SignEntity.cpp
@@ -4,9 +4,9 @@
// Implements the cSignEntity class representing a single sign in the world
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "json/json.h"
+#include "json/value.h"
#include "SignEntity.h"
-#include "../Entities/Player.h"
+#include "../ClientHandle.h"
@@ -15,13 +15,13 @@
cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World) :
super(a_BlockType, a_X, a_Y, a_Z, a_World)
{
+ ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height));
}
-// It don't do anything when 'used'
void cSignEntity::UsedBy(cPlayer * a_Player)
{
UNUSED(a_Player);
@@ -79,37 +79,3 @@ void cSignEntity::SendTo(cClientHandle & a_Client)
-
-bool cSignEntity::LoadFromJson(const Json::Value & a_Value)
-{
- 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_Line[0] = a_Value.get("Line1", "").asString();
- m_Line[1] = a_Value.get("Line2", "").asString();
- m_Line[2] = a_Value.get("Line3", "").asString();
- m_Line[3] = a_Value.get("Line4", "").asString();
-
- return true;
-}
-
-
-
-
-
-void cSignEntity::SaveToJson(Json::Value & a_Value)
-{
- a_Value["x"] = m_PosX;
- a_Value["y"] = m_PosY;
- a_Value["z"] = m_PosZ;
-
- a_Value["Line1"] = m_Line[0];
- a_Value["Line2"] = m_Line[1];
- a_Value["Line3"] = m_Line[2];
- a_Value["Line4"] = m_Line[3];
-}
-
-
-
-
diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h
index 33af100a4..53c43b758 100644
--- a/src/BlockEntities/SignEntity.h
+++ b/src/BlockEntities/SignEntity.h
@@ -37,9 +37,6 @@ public:
/// Creates a new empty sign entity at the specified block coords and block type (wall or standing). a_World may be NULL
cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World);
- bool LoadFromJson( const Json::Value& a_Value);
- virtual void SaveToJson(Json::Value& a_Value) override;
-
// tolua_begin
/// Sets all the sign's lines