summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-02-15 15:06:23 +0100
committerMattes D <github@xoft.cz>2014-02-15 15:06:23 +0100
commit48eafee823cb979ded833b5311c0f5c37a8ca0f2 (patch)
treefad70a53bd337fa152f661e32422da5b9699096e /src/BlockEntities
parentMerge pull request #677 from mc-server/BroadcastParticleEffect (diff)
parentFixed typographical error (diff)
downloadcuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar.gz
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar.bz2
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar.lz
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar.xz
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.tar.zst
cuberite-48eafee823cb979ded833b5311c0f5c37a8ca0f2.zip
Diffstat (limited to 'src/BlockEntities')
-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/NoteEntity.h2
-rw-r--r--src/BlockEntities/SignEntity.h3
11 files changed, 101 insertions, 25 deletions
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/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: