summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-02-20 14:37:15 +0100
committerandrew <xdotftw@gmail.com>2014-02-20 14:37:15 +0100
commit83d3a2eedf88a3a180b9dfc4c706838d7f99382a (patch)
treed96970727615c681efe3bf76793015cead438394 /src/BlockEntities
parentcMapDecorator: Implemented random rotations (diff)
parentAPIDump: Fixed cBlockArea:GetRelBlockType() return types. (diff)
downloadcuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar.gz
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar.bz2
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar.lz
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar.xz
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.tar.zst
cuberite-83d3a2eedf88a3a180b9dfc4c706838d7f99382a.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BlockEntity.cpp2
-rw-r--r--src/BlockEntities/BlockEntityWithItems.h7
-rw-r--r--src/BlockEntities/ChestEntity.h4
-rw-r--r--src/BlockEntities/DropSpenserEntity.cpp7
-rw-r--r--src/BlockEntities/DropSpenserEntity.h4
-rw-r--r--src/BlockEntities/EnderChestEntity.h4
-rw-r--r--src/BlockEntities/FurnaceEntity.h4
-rw-r--r--src/BlockEntities/HopperEntity.cpp85
-rw-r--r--src/BlockEntities/HopperEntity.h4
-rw-r--r--src/BlockEntities/JukeboxEntity.h2
-rw-r--r--src/BlockEntities/MobHeadEntity.cpp108
-rw-r--r--src/BlockEntities/MobHeadEntity.h79
-rw-r--r--src/BlockEntities/NoteEntity.h2
-rw-r--r--src/BlockEntities/SignEntity.h3
14 files changed, 290 insertions, 25 deletions
diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp
index 97b5c1a66..57ad83de9 100644
--- a/src/BlockEntities/BlockEntity.cpp
+++ b/src/BlockEntities/BlockEntity.cpp
@@ -15,6 +15,7 @@
#include "JukeboxEntity.h"
#include "NoteEntity.h"
#include "SignEntity.h"
+#include "MobHeadEntity.h"
@@ -29,6 +30,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE
case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_DROPPER: return new cDropperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_ENDER_CHEST: return new cEnderChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
+ case E_BLOCK_HEAD: return new cMobHeadEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
case E_BLOCK_LIT_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World);
case E_BLOCK_FURNACE: return new cFurnaceEntity (a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_World);
case E_BLOCK_HOPPER: return new cHopperEntity (a_BlockX, a_BlockY, a_BlockZ, a_World);
diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h
index bf6289a2f..918781a00 100644
--- a/src/BlockEntities/BlockEntityWithItems.h
+++ b/src/BlockEntities/BlockEntityWithItems.h
@@ -11,6 +11,7 @@
#include "BlockEntity.h"
#include "../ItemGrid.h"
+#include "../UI/WindowOwner.h"
@@ -22,6 +23,7 @@ class cBlockEntityWithItems :
// tolua_end
// tolua doesn't seem to support multiple inheritance?
, public cItemGrid::cListener
+ , public cBlockEntityWindowOwner
// tolua_begin
{
typedef cBlockEntity super;
@@ -77,6 +79,11 @@ protected:
ASSERT(a_Grid == &m_Contents);
if (m_World != NULL)
{
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->BroadcastWholeWindow();
+ }
+
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
}
}
diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h
index 4110de1f3..ce16f84d7 100644
--- a/src/BlockEntities/ChestEntity.h
+++ b/src/BlockEntities/ChestEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -23,8 +22,7 @@ class cNBTData;
// tolua_begin
class cChestEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp
index 7c9a40ce6..81df0fc8c 100644
--- a/src/BlockEntities/DropSpenserEntity.cpp
+++ b/src/BlockEntities/DropSpenserEntity.cpp
@@ -99,13 +99,6 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk)
}
m_World->BroadcastSoundParticleEffect(2000, m_PosX, m_PosY, m_PosZ, SmokeDir);
m_World->BroadcastSoundEffect("random.click", m_PosX * 8, m_PosY * 8, m_PosZ * 8, 1.0f, 1.0f);
-
- // Update the UI window, if open:
- cWindow * Window = GetWindow();
- if (Window != NULL)
- {
- Window->BroadcastWholeWindow();
- }
}
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index f2f1eba36..47d3bd492 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -11,7 +11,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -31,8 +30,7 @@ class cServer;
// tolua_begin
class cDropSpenserEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h
index 0ee3cab3b..45beee45f 100644
--- a/src/BlockEntities/EnderChestEntity.h
+++ b/src/BlockEntities/EnderChestEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -23,8 +22,7 @@ class cNBTData;
// tolua_begin
class cEnderChestEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h
index b08187300..5e08ae37a 100644
--- a/src/BlockEntities/FurnaceEntity.h
+++ b/src/BlockEntities/FurnaceEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
#include "../FurnaceRecipe.h"
@@ -23,8 +22,7 @@ class cServer;
// tolua_begin
class cFurnaceEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 2255cad64..31b23ac99 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -7,10 +7,12 @@
#include "HopperEntity.h"
#include "../Chunk.h"
#include "../Entities/Player.h"
+#include "../Entities/Pickup.h"
#include "../Bindings/PluginManager.h"
#include "ChestEntity.h"
#include "DropSpenserEntity.h"
#include "FurnaceEntity.h"
+#include "../BoundingBox.h"
@@ -190,8 +192,87 @@ bool cHopperEntity::MoveItemsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
/// Moves pickups from above this hopper into it. Returns true if the contents have changed.
bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
{
- // TODO
- return false;
+ UNUSED(a_CurrentTick);
+
+ class cHopperPickupSearchCallback :
+ public cEntityCallback
+ {
+ public:
+ cHopperPickupSearchCallback(const Vector3i & a_Pos, cItemGrid & a_Contents) :
+ m_Pos(a_Pos),
+ m_bFoundPickupsAbove(false),
+ m_Contents(a_Contents)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ ASSERT(a_Entity != NULL);
+
+ if (!a_Entity->IsPickup() || a_Entity->IsDestroyed())
+ {
+ return false;
+ }
+
+ Vector3f EntityPos = a_Entity->GetPosition();
+ Vector3f BlockPos(m_Pos.x + 0.5f, (float)m_Pos.y + 1, m_Pos.z + 0.5f); // One block above hopper, and search from center outwards
+ float Distance = (EntityPos - BlockPos).Length();
+
+ if (Distance < 0.5)
+ {
+ if (TrySuckPickupIn((cPickup *)a_Entity))
+ {
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+ bool TrySuckPickupIn(cPickup * a_Pickup)
+ {
+ for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
+ {
+ if (m_Contents.IsSlotEmpty(i))
+ {
+ m_bFoundPickupsAbove = true;
+ m_Contents.SetSlot(i, a_Pickup->GetItem());
+ a_Pickup->Destroy(); // Kill pickup
+
+ return true;
+ }
+ else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack())
+ {
+ m_bFoundPickupsAbove = true;
+
+ int PreviousCount = m_Contents.GetSlot(i).m_ItemCount;
+ a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added
+
+ if (a_Pickup->GetItem().IsEmpty())
+ {
+ a_Pickup->Destroy(); // Kill pickup if all items were added
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool FoundPickupsAbove(void) const
+ {
+ return m_bFoundPickupsAbove;
+ }
+
+ protected:
+ Vector3i m_Pos;
+ bool m_bFoundPickupsAbove;
+ cItemGrid & m_Contents;
+ };
+
+ cHopperPickupSearchCallback HopperPickupSearchCallback(Vector3i(GetPosX(), GetPosY(), GetPosZ()), m_Contents);
+ a_Chunk.ForEachEntity(HopperPickupSearchCallback);
+
+ return HopperPickupSearchCallback.FoundPickupsAbove();
}
diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h
index 2c8b301fe..6ef98f43a 100644
--- a/src/BlockEntities/HopperEntity.h
+++ b/src/BlockEntities/HopperEntity.h
@@ -10,7 +10,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -18,8 +17,7 @@
// tolua_begin
class cHopperEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h
index 996de965b..734d7bb66 100644
--- a/src/BlockEntities/JukeboxEntity.h
+++ b/src/BlockEntities/JukeboxEntity.h
@@ -43,6 +43,8 @@ public:
void EjectRecord(void);
// tolua_end
+
+ static const char * GetClassStatic(void) { return "cJukeboxEntity"; }
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override { };
diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp
new file mode 100644
index 000000000..c0a1781f6
--- /dev/null
+++ b/src/BlockEntities/MobHeadEntity.cpp
@@ -0,0 +1,108 @@
+
+// MobHeadEntity.cpp
+
+// 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"
+
+
+
+
+
+cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
+ super(E_BLOCK_HEAD, a_BlockX, a_BlockY, a_BlockZ, a_World),
+ m_Owner("")
+{
+}
+
+
+
+
+
+void cMobHeadEntity::UsedBy(cPlayer * a_Player)
+{
+ UNUSED(a_Player);
+}
+
+
+
+
+
+void cMobHeadEntity::SetType(const eMobHeadType & a_Type)
+{
+ if ((!m_Owner.empty()) && (a_Type != SKULL_TYPE_PLAYER))
+ {
+ m_Owner = "";
+ }
+ m_Type = a_Type;
+}
+
+
+
+
+
+void cMobHeadEntity::SetRotation(eMobHeadRotation a_Rotation)
+{
+ m_Rotation = a_Rotation;
+}
+
+
+
+
+
+void cMobHeadEntity::SetOwner(const AString & a_Owner)
+{
+ if ((a_Owner.length() > 16) || (m_Type != SKULL_TYPE_PLAYER))
+ {
+ return;
+ }
+ m_Owner = a_Owner;
+}
+
+
+
+
+
+void cMobHeadEntity::SendTo(cClientHandle & a_Client)
+{
+ a_Client.SendUpdateBlockEntity(*this);
+}
+
+
+
+
+
+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
new file mode 100644
index 000000000..367eb15e7
--- /dev/null
+++ b/src/BlockEntities/MobHeadEntity.h
@@ -0,0 +1,79 @@
+// MobHeadEntity.h
+
+// Declares the cMobHeadEntity class representing a single skull/head in the world
+
+
+
+
+
+#pragma once
+
+#include "BlockEntity.h"
+
+
+
+
+
+namespace Json
+{
+ class Value;
+}
+
+
+
+
+
+// tolua_begin
+
+class cMobHeadEntity :
+ public cBlockEntity
+{
+ typedef cBlockEntity super;
+
+public:
+
+ // tolua_end
+
+ /** 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 */
+ void SetType(const eMobHeadType & a_SkullType);
+
+ /** Set the Rotation */
+ void SetRotation(eMobHeadRotation a_Rotation);
+
+ /** Set the Player Name for Mobheads with Player type */
+ void SetOwner(const AString & a_Owner);
+
+ /** Get the Type */
+ eMobHeadType GetType(void) const { return m_Type; }
+
+ /** Get the Rotation */
+ eMobHeadRotation GetRotation(void) const { return m_Rotation; }
+
+ /** Get the setted Player Name */
+ AString GetOwner(void) const { return m_Owner; }
+
+ // tolua_end
+
+ virtual void UsedBy(cPlayer * a_Player) override;
+ virtual void SendTo(cClientHandle & a_Client) override;
+
+ static const char * GetClassStatic(void) { return "cMobHeadEntity"; }
+
+private:
+
+ eMobHeadType m_Type;
+ eMobHeadRotation m_Rotation;
+ AString m_Owner;
+} ; // tolua_export
+
+
+
+
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index cf78aeac6..b698899c0 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -54,6 +54,8 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override { };
+ static const char * GetClassStatic(void) { return "cNoteEntity"; }
+
private:
char m_Pitch;
} ; // tolua_export
diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h
index d998ff1e8..80c7bbfdf 100644
--- a/src/BlockEntities/SignEntity.h
+++ b/src/BlockEntities/SignEntity.h
@@ -1,4 +1,3 @@
-
// SignEntity.h
// Declares the cSignEntity class representing a single sign in the world
@@ -56,6 +55,8 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
+
+ static const char * GetClassStatic(void) { return "cSignEntity"; }
private: