summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simulator/IncrementalRedstoneSimulator')
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h11
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h12
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h11
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h34
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h26
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h37
-rw-r--r--src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h21
7 files changed, 116 insertions, 36 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
index de0f23620..91fbe05ff 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
@@ -44,12 +44,17 @@ public:
return {};
}
- a_World.DoWithCommandBlockAt(a_Position.x, a_Position.y, a_Position.z, [](cCommandBlockEntity & a_CommandBlock)
+ class cSetPowerToCommandBlock : public cCommandBlockCallback
+ {
+ public:
+ virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
{
- a_CommandBlock.Activate();
+ a_CommandBlock->Activate();
return false;
}
- );
+ } CmdBlockSP;
+
+ a_World.DoWithCommandBlockAt(a_Position.x, a_Position.y, a_Position.z, CmdBlockSP);
return {};
}
diff --git a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
index 4974324a0..62b37eb1d 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
@@ -56,12 +56,18 @@ public:
bool WasPoweredPreviously = IsActivated(a_Meta);
if (IsPoweredNow && !WasPoweredPreviously)
{
- a_World.DoWithDropSpenserAt(a_Position.x, a_Position.y, a_Position.z, [](cDropSpenserEntity & a_DropSpenser)
+ class cSetPowerToDropSpenser :
+ public cDropSpenserCallback
+ {
+ public:
+ virtual bool Item(cDropSpenserEntity * a_DropSpenser) override
{
- a_DropSpenser.Activate();
+ a_DropSpenser->Activate();
return false;
}
- );
+ } DrSpSP;
+
+ a_World.DoWithDropSpenserAt(a_Position.x, a_Position.y, a_Position.z, DrSpSP);
}
// Update the internal dropspenser state if necessary
diff --git a/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h b/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h
index ba6c695d6..add608654 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h
@@ -45,12 +45,17 @@ public:
return {};
}
- a_World.DoWithNoteBlockAt(a_Position.x, a_Position.y, a_Position.z, [](cNoteEntity & a_NoteBlock)
+ class cSetPowerToNoteBlock : public cNoteBlockCallback
+ {
+ public:
+ virtual bool Item(cNoteEntity * a_NoteBlock) override
{
- a_NoteBlock.MakeSound();
+ a_NoteBlock->MakeSound();
return false;
}
- );
+ } NoteBlockSP;
+
+ a_World.DoWithNoteBlockAt(a_Position.x, a_Position.y, a_Position.z, NoteBlockSP);
return {};
}
diff --git a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
index 93759408d..14d7baf85 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
@@ -27,37 +27,49 @@ public:
{
UNUSED(a_Meta);
- unsigned int NumberOfEntities;
- bool FoundPlayer;
- a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + a_Position, 0.5, 0.5), [&](cEntity & a_Entity)
+ class cPressurePlateCallback :
+ public cEntityCallback
+ {
+ public:
+ cPressurePlateCallback(void) :
+ m_NumberOfEntities(0),
+ m_FoundPlayer(false)
{
- if (a_Entity.IsPlayer())
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ if (a_Entity->IsPlayer())
{
- FoundPlayer = true;
+ m_FoundPlayer = true;
}
- NumberOfEntities++;
+ m_NumberOfEntities++;
return false;
}
- );
+
+ unsigned int m_NumberOfEntities;
+ bool m_FoundPlayer;
+ } PressurePlateCallback;
+ a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + a_Position, 0.5, 0.5), PressurePlateCallback);
switch (a_BlockType)
{
case E_BLOCK_STONE_PRESSURE_PLATE:
{
- return (FoundPlayer ? 15 : 0);
+ return (PressurePlateCallback.m_FoundPlayer ? 15 : 0);
}
case E_BLOCK_WOODEN_PRESSURE_PLATE:
{
- return (NumberOfEntities != 0 ? 15 : 0);
+ return (PressurePlateCallback.m_NumberOfEntities != 0 ? 15 : 0);
}
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
{
- return std::min(static_cast<unsigned char>(CeilC(NumberOfEntities / 10.f)), static_cast<unsigned char>(15));
+ return std::min(static_cast<unsigned char>(CeilC(PressurePlateCallback.m_NumberOfEntities / 10.f)), static_cast<unsigned char>(15));
}
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE:
{
- return std::min(static_cast<unsigned char>(NumberOfEntities), static_cast<unsigned char>(15));
+ return std::min(static_cast<unsigned char>(PressurePlateCallback.m_NumberOfEntities), static_cast<unsigned char>(15));
}
default:
{
diff --git a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
index 6e3d080aa..55efee6b5 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/RedstoneComparatorHandler.h
@@ -44,12 +44,17 @@ public:
UNUSED(a_Position);
UNUSED(a_BlockType);
- UInt8 SignalStrength = 0;
- auto RearCoordinate = cBlockComparatorHandler::GetRearCoordinate(a_Position, a_Meta & 0x3);
- a_World.DoWithBlockEntityAt(RearCoordinate.x, RearCoordinate.y, RearCoordinate.z, [&](cBlockEntity & a_BlockEntity)
+ class cContainerCallback : public cBlockEntityCallback
+ {
+ public:
+ cContainerCallback() : m_SignalStrength(0)
+ {
+ }
+
+ virtual bool Item(cBlockEntity * a_BlockEntity) override
{
// 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;
@@ -63,18 +68,23 @@ public:
Fullness += static_cast<float>(Contents.GetSlot(Slot).m_ItemCount) / Contents.GetSlot(Slot).GetMaxStackSize();
}
- SignalStrength = (Fullness < 0.001 /* container empty? */) ? 0 : static_cast<UInt8>(1 + (Fullness / Contents.GetNumSlots()) * 14);
+ m_SignalStrength = (Fullness < 0.001 /* container empty? */) ? 0 : static_cast<unsigned char>(1 + (Fullness / Contents.GetNumSlots()) * 14);
return false;
}
- );
- auto RearPower = SignalStrength;
+
+ 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 RearType = a_World.GetBlock(RearCoordinate);
auto PotentialSourceHandler = cIncrementalRedstoneSimulator::GetComponentHandler(RearType);
if (PotentialSourceHandler != nullptr)
{
NIBBLETYPE RearMeta = a_World.GetBlockMeta(RearCoordinate);
- RearPower = std::max(SignalStrength, PotentialSourceHandler->GetPowerDeliveredToPosition(a_World, RearCoordinate, RearType, RearMeta, a_Position, a_BlockType));
+ RearPower = std::max(CCB.m_SignalStrength, PotentialSourceHandler->GetPowerDeliveredToPosition(a_World, RearCoordinate, RearType, RearMeta, a_Position, a_BlockType));
}
return RearPower;
diff --git a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
index d280f73e3..8b7b82d49 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
@@ -1,4 +1,4 @@
-
+
#pragma once
#include "RedstoneHandler.h"
@@ -28,15 +28,38 @@ public:
UNUSED(a_BlockType);
UNUSED(a_Meta);
- int NumberOfPlayers = 0;
- VERIFY(!a_World.DoWithChestAt(a_Position.x, a_Position.y, a_Position.z, [&](cChestEntity & a_Chest)
+ class cGetTrappedChestPlayers :
+ public cItemCallback<cChestEntity>
+ {
+ public:
+ cGetTrappedChestPlayers(void) :
+ m_NumberOfPlayers(0)
+ {
+ }
+
+ virtual ~cGetTrappedChestPlayers() override
+ {
+ }
+
+ virtual bool Item(cChestEntity * a_Chest) override
{
- ASSERT(a_Chest.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
- NumberOfPlayers = a_Chest.GetNumberOfPlayers();
+ ASSERT(a_Chest->GetBlockType() == E_BLOCK_TRAPPED_CHEST);
+ m_NumberOfPlayers = a_Chest->GetNumberOfPlayers();
return true;
}
- ));
- return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
+
+ unsigned char GetPowerLevel(void) const
+ {
+ return static_cast<unsigned char>(std::min(m_NumberOfPlayers, 15));
+ }
+
+ private:
+ int m_NumberOfPlayers;
+
+ } GTCP;
+
+ VERIFY(!a_World.DoWithChestAt(a_Position.x, a_Position.y, a_Position.z, GTCP));
+ return GTCP.GetPowerLevel();
}
virtual cVector3iArray Update(cWorld & a_World, const Vector3i & a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
diff --git a/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h b/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h
index 2fb85f58c..85c05430c 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h
@@ -39,7 +39,26 @@ public:
if (Type == E_BLOCK_TRIPWIRE)
{
- if (!a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + Position, 0.5, 0.5), [](cEntity &) { return true; }))
+ class cTripwireCallback :
+ public cEntityCallback
+ {
+ public:
+ cTripwireCallback(void) :
+ m_NumberOfEntities(0),
+ m_FoundPlayer(false)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ return true;
+ }
+
+ unsigned int m_NumberOfEntities;
+ bool m_FoundPlayer;
+ } TripwireCallback;
+
+ if (!a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + Position, 0.5, 0.5), TripwireCallback))
{
FoundActivated = true;
}