From ea386eaab12206e585e01720808dc37585569535 Mon Sep 17 00:00:00 2001 From: Bond-009 Date: Fri, 27 Mar 2020 13:03:28 +0100 Subject: Lock hopper when powered by redstone (#4347) * Lock hopper when powered by redstone * Add to manual bindings * Add hopper API documentation Co-authored-by: Mat --- src/BlockEntities/HopperEntity.cpp | 21 +++++++++++++++++---- src/BlockEntities/HopperEntity.h | 8 ++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index e85cfb952..aadca8311 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -20,7 +20,8 @@ cHopperEntity::cHopperEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World): super(a_BlockType, a_BlockMeta, a_Pos, ContentsWidth, ContentsHeight, a_World), m_LastMoveItemsInTick(0), - m_LastMoveItemsOutTick(0) + m_LastMoveItemsOutTick(0), + m_Locked(false) { ASSERT(a_BlockType == E_BLOCK_HOPPER); } @@ -29,6 +30,15 @@ cHopperEntity::cHopperEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vect +void cHopperEntity::SetLocked(bool a_Value) +{ + m_Locked = a_Value; +} + + + + + std::pair cHopperEntity::GetOutputBlockPos(NIBBLETYPE a_BlockMeta) { auto pos = GetPos(); @@ -69,9 +79,12 @@ bool cHopperEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Int64 CurrentTick = a_Chunk.GetWorld()->GetWorldAge(); bool isDirty = false; - isDirty = MoveItemsIn (a_Chunk, CurrentTick) || isDirty; - isDirty = MovePickupsIn(a_Chunk, CurrentTick) || isDirty; - isDirty = MoveItemsOut (a_Chunk, CurrentTick) || isDirty; + if (!m_Locked) + { + isDirty = MoveItemsIn (a_Chunk, CurrentTick) || isDirty; + isDirty = MovePickupsIn(a_Chunk, CurrentTick) || isDirty; + isDirty = MoveItemsOut (a_Chunk, CurrentTick) || isDirty; + } return isDirty; } diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h index c57dce672..ef86a36bb 100644 --- a/src/BlockEntities/HopperEntity.h +++ b/src/BlockEntities/HopperEntity.h @@ -33,6 +33,8 @@ public: TICKS_PER_TRANSFER = 8, ///< How many ticks at minimum between two item transfers to or from the hopper } ; + + // tolua_end BLOCKENTITY_PROTODEF(cHopperEntity) @@ -45,6 +47,8 @@ public: Exported in ManualBindings.cpp. */ std::pair GetOutputBlockPos(NIBBLETYPE a_BlockMeta); + void SetLocked(bool a_Value); + protected: Int64 m_LastMoveItemsInTick; @@ -91,6 +95,10 @@ protected: /** Moves one piece to the specified entity's contents' slot. Returns true if contents have changed. */ bool MoveItemsToSlot(cBlockEntityWithItems & a_Entity, int a_DstSlotNum); + +private: + + bool m_Locked; } ; // tolua_export -- cgit v1.2.3