diff options
Diffstat (limited to 'src/BlockEntities')
-rw-r--r-- | src/BlockEntities/BeaconEntity.cpp | 116 | ||||
-rw-r--r-- | src/BlockEntities/BeaconEntity.h | 44 | ||||
-rw-r--r-- | src/BlockEntities/BlockEntity.cpp | 2 | ||||
-rw-r--r-- | src/BlockEntities/DispenserEntity.cpp | 9 | ||||
-rw-r--r-- | src/BlockEntities/FurnaceEntity.cpp | 7 | ||||
-rw-r--r-- | src/BlockEntities/HopperEntity.cpp | 11 |
6 files changed, 178 insertions, 11 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp new file mode 100644 index 000000000..0914353eb --- /dev/null +++ b/src/BlockEntities/BeaconEntity.cpp @@ -0,0 +1,116 @@ + +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BeaconEntity.h" +#include "../BlockArea.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) +{ +} + + + + + +int cBeaconEntity::GetPyramidLevel(void) +{ + cBlockArea Area; + int MinY = GetPosY() - 4; + if (MinY < 0) + { + MinY = 0; + } + int MaxY = GetPosY() - 1; + if (MaxY < 0) + { + MaxY = 0; + } + + Area.Read( + m_World, + GetPosX() - 4, GetPosX() + 4, + MinY, MaxY, + GetPosZ() - 4, GetPosZ() + 4, + cBlockArea::baTypes + ); + + int Layer = 1; + int MiddleXZ = 4; + + for (int Y = Area.GetSizeY() - 1; Y > 0; Y--) + { + for (int X = MiddleXZ - Layer; X <= (MiddleXZ + Layer); X++) + { + for (int Z = MiddleXZ - Layer; Z <= (MiddleXZ + Layer); Z++) + { + if (!IsMineralBlock(Area.GetRelBlockType(X, Y, Z))) + { + return Layer - 1; + } + } + } + Layer++; + } + + return Layer - 1; +} + + + + + +bool cBeaconEntity::IsMineralBlock(BLOCKTYPE a_BlockType) +{ + switch(a_BlockType) + { + case E_BLOCK_DIAMOND_BLOCK: + case E_BLOCK_GOLD_BLOCK: + case E_BLOCK_IRON_BLOCK: + case E_BLOCK_EMERALD_BLOCK: + { + return true; + } + } + return false; +} + + + + + +bool cBeaconEntity::Tick(float a_Dt, cChunk & a_Chunk) +{ + return false; +} + + + + + +void cBeaconEntity::SaveToJson(Json::Value& a_Value) +{ +} + + + + +void cBeaconEntity::SendTo(cClientHandle & a_Client) +{ +} + + + + + +void cBeaconEntity::UsedBy(cPlayer * a_Player) +{ +} + + + + diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h new file mode 100644 index 000000000..b1df68bc4 --- /dev/null +++ b/src/BlockEntities/BeaconEntity.h @@ -0,0 +1,44 @@ + +#pragma once + +#include "BlockEntity.h" + + + + + +namespace Json +{ + class Value; +} + + + + + +class cBeaconEntity : + public cBlockEntity +{ + typedef cBlockEntity super; + +public: + + /** The initial constructor */ + 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); + + /** 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; +} ; + + + + diff --git a/src/BlockEntities/BlockEntity.cpp b/src/BlockEntities/BlockEntity.cpp index b42318c2f..430f04551 100644 --- a/src/BlockEntities/BlockEntity.cpp +++ b/src/BlockEntities/BlockEntity.cpp @@ -4,6 +4,7 @@ // Implements the cBlockEntity class that is the common ancestor for all block entities #include "Globals.h" +#include "BeaconEntity.h" #include "BlockEntity.h" #include "ChestEntity.h" #include "CommandBlockEntity.h" @@ -26,6 +27,7 @@ cBlockEntity * cBlockEntity::CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE { switch (a_BlockType) { + case E_BLOCK_BEACON: return new cBeaconEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_CHEST: return new cChestEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_COMMAND_BLOCK: return new cCommandBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_World); case E_BLOCK_DISPENSER: return new cDispenserEntity (a_BlockX, a_BlockY, a_BlockZ, a_World); diff --git a/src/BlockEntities/DispenserEntity.cpp b/src/BlockEntities/DispenserEntity.cpp index e03bf776d..2a32f69d9 100644 --- a/src/BlockEntities/DispenserEntity.cpp +++ b/src/BlockEntities/DispenserEntity.cpp @@ -128,10 +128,11 @@ void cDispenserEntity::DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) if (DispChunk->GetBlock(DispX, DispY, DispZ) == E_BLOCK_AIR) { DispChunk->SetBlock(DispX, DispY, DispZ, E_BLOCK_FIRE, 0); - m_Contents.SetSlot(a_SlotNum, m_Contents.GetSlot(a_SlotNum).m_ItemType, m_Contents.GetSlot(a_SlotNum).m_ItemCount, m_Contents.GetSlot(a_SlotNum).m_ItemDamage + 1); - // If the durability has run out destroy the item. - if (m_Contents.GetSlot(a_SlotNum).m_ItemDamage > 64) - { + + bool ItemBroke = m_Contents.DamageItem(a_SlotNum, 1); + + if (ItemBroke) + { m_Contents.ChangeSlotCount(a_SlotNum, -1); } } diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index 7d6d1f89e..1b1741713 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -413,19 +413,20 @@ bool cFurnaceEntity::CanCookInputToOutput(void) const return false; } - if (m_Contents.GetSlot(fsOutput).IsEmpty()) + const cItem & Slot = m_Contents.GetSlot(fsOutput); + if (Slot.IsEmpty()) { // The output is empty, can cook return true; } - if (!m_Contents.GetSlot(fsOutput).IsEqual(*m_CurrentRecipe->Out)) + if (!Slot.IsEqual(*m_CurrentRecipe->Out)) { // The output slot is blocked with something that cannot be stacked with the recipe's output return false; } - if (m_Contents.GetSlot(fsOutput).IsFullStack()) + if (Slot.IsFullStack()) { // Cannot add any more items to the output slot return false; diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 41fb9f811..7f001c739 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -234,24 +234,27 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick) bool TrySuckPickupIn(cPickup * a_Pickup) { + cItem & Item = a_Pickup->GetItem(); + for (int i = 0; i < ContentsWidth * ContentsHeight; i++) { if (m_Contents.IsSlotEmpty(i)) { m_bFoundPickupsAbove = true; - m_Contents.SetSlot(i, a_Pickup->GetItem()); + m_Contents.SetSlot(i, Item); a_Pickup->Destroy(); // Kill pickup return true; } - else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack()) + else if (m_Contents.GetSlot(i).IsEqual(Item) && !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()) + Item.m_ItemCount -= m_Contents.ChangeSlotCount(i, Item.m_ItemCount) - PreviousCount; // Set count to however many items were added + + if (Item.IsEmpty()) { a_Pickup->Destroy(); // Kill pickup if all items were added } |