diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-11 23:20:49 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:49 +0200 |
commit | e225b7f8262df48ad4d7094bc295add3007b0649 (patch) | |
tree | a42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h | |
parent | cBlockArea: change MakeIndex to return size_t (diff) | |
download | cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2 cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip |
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h')
-rw-r--r-- | src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h index cd43a4875..8c33ae266 100644 --- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h +++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h @@ -44,17 +44,12 @@ public: UNUSED(a_Position); UNUSED(a_BlockType); - class cContainerCallback : public cBlockEntityCallback - { - public: - cContainerCallback() : m_SignalStrength(0) - { - } - - virtual bool Item(cBlockEntity * a_BlockEntity) override + UInt8 SignalStrength = 0; + auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(a_Position, a_Meta & 0x3); + a_World.DoWithBlockEntityAt(RearCoordinate.x, RearCoordinate.y, RearCoordinate.z, [&](cBlockEntity & a_BlockEntity) { // Skip BlockEntities that don't have slots - auto BlockEntityWithItems = dynamic_cast<cBlockEntityWithItems *>(a_BlockEntity); + auto BlockEntityWithItems = dynamic_cast<cBlockEntityWithItems *>(&a_BlockEntity); if (BlockEntityWithItems == nullptr) { return false; @@ -68,23 +63,18 @@ public: Fullness += static_cast<float>(Contents.GetSlot(Slot).m_ItemCount) / Contents.GetSlot(Slot).GetMaxStackSize(); } - m_SignalStrength = (Fullness < 0.001 /* container empty? */) ? 0 : static_cast<unsigned char>(1 + (Fullness / Contents.GetNumSlots()) * 14); + SignalStrength = (Fullness < 0.001 /* container empty? */) ? 0 : static_cast<UInt8>(1 + (Fullness / Contents.GetNumSlots()) * 14); return false; } - - unsigned char m_SignalStrength; - } CCB; - - auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(a_Position, a_Meta & 0x3); - a_World.DoWithBlockEntityAt(RearCoordinate.x, RearCoordinate.y, RearCoordinate.z, CCB); - auto RearPower = CCB.m_SignalStrength; + ); + auto RearPower = SignalStrength; auto RearType = a_World.GetBlock(RearCoordinate); auto PotentialSourceHandler = cIncrementalRedstoneSimulator::GetComponentHandler(RearType); if (PotentialSourceHandler != nullptr) { NIBBLETYPE RearMeta = a_World.GetBlockMeta(RearCoordinate); - RearPower = std::max(CCB.m_SignalStrength, PotentialSourceHandler->GetPowerDeliveredToPosition(a_World, RearCoordinate, RearType, RearMeta, a_Position, a_BlockType)); + RearPower = std::max(SignalStrength, PotentialSourceHandler->GetPowerDeliveredToPosition(a_World, RearCoordinate, RearType, RearMeta, a_Position, a_BlockType)); } return RearPower; |