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, 36 insertions, 116 deletions
diff --git a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
index 2e7150080..672a4927b 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/CommandBlockHandler.h
@@ -44,17 +44,12 @@ public:
return {};
}
- class cSetPowerToCommandBlock : public cCommandBlockCallback
- {
- public:
- virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
+ a_World.DoWithCommandBlockAt(a_Position.x, a_Position.y, a_Position.z, [](cCommandBlockEntity & a_CommandBlock)
{
- 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 42598f519..295afd34e 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/DropSpenserHandler.h
@@ -56,18 +56,12 @@ public:
bool WasPoweredPreviously = IsActivated(a_Meta);
if (IsPoweredNow && !WasPoweredPreviously)
{
- class cSetPowerToDropSpenser :
- public cDropSpenserCallback
- {
- public:
- virtual bool Item(cDropSpenserEntity * a_DropSpenser) override
+ a_World.DoWithDropSpenserAt(a_Position.x, a_Position.y, a_Position.z, [](cDropSpenserEntity & a_DropSpenser)
{
- 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 7ecc64c72..46fcd6716 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/NoteBlockHandler.h
@@ -45,17 +45,12 @@ public:
return {};
}
- class cSetPowerToNoteBlock : public cNoteBlockCallback
- {
- public:
- virtual bool Item(cNoteEntity * a_NoteBlock) override
+ a_World.DoWithNoteBlockAt(a_Position.x, a_Position.y, a_Position.z, [](cNoteEntity & a_NoteBlock)
{
- 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 944543460..63add8982 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/PressurePlateHandler.h
@@ -27,49 +27,37 @@ public:
{
UNUSED(a_Meta);
- class cPressurePlateCallback :
- public cEntityCallback
- {
- public:
- cPressurePlateCallback(void) :
- m_NumberOfEntities(0),
- m_FoundPlayer(false)
+ unsigned int NumberOfEntities;
+ bool FoundPlayer;
+ a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + a_Position, 0.5, 0.5), [&](cEntity & a_Entity)
{
- }
-
- virtual bool Item(cEntity * a_Entity) override
- {
- if (a_Entity->IsPlayer())
+ if (a_Entity.IsPlayer())
{
- m_FoundPlayer = true;
+ FoundPlayer = true;
}
- m_NumberOfEntities++;
+ 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 (PressurePlateCallback.m_FoundPlayer ? 15 : 0);
+ return (FoundPlayer ? 15 : 0);
}
case E_BLOCK_WOODEN_PRESSURE_PLATE:
{
- return (PressurePlateCallback.m_NumberOfEntities != 0 ? 15 : 0);
+ return (NumberOfEntities != 0 ? 15 : 0);
}
case E_BLOCK_HEAVY_WEIGHTED_PRESSURE_PLATE:
{
- return std::min(static_cast<unsigned char>(CeilC(PressurePlateCallback.m_NumberOfEntities / 10.f)), static_cast<unsigned char>(15));
+ return std::min(static_cast<unsigned char>(CeilC(NumberOfEntities / 10.f)), static_cast<unsigned char>(15));
}
case E_BLOCK_LIGHT_WEIGHTED_PRESSURE_PLATE:
{
- return std::min(static_cast<unsigned char>(PressurePlateCallback.m_NumberOfEntities), static_cast<unsigned char>(15));
+ return std::min(static_cast<unsigned char>(NumberOfEntities), static_cast<unsigned char>(15));
}
default:
{
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;
diff --git a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
index 4ae4aff3d..80e55faec 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/TrappedChestHandler.h
@@ -1,4 +1,4 @@
-
+
#pragma once
#include "RedstoneHandler.h"
@@ -28,38 +28,15 @@ public:
UNUSED(a_BlockType);
UNUSED(a_Meta);
- class cGetTrappedChestPlayers :
- public cItemCallback<cChestEntity>
- {
- public:
- cGetTrappedChestPlayers(void) :
- m_NumberOfPlayers(0)
- {
- }
-
- virtual ~cGetTrappedChestPlayers() override
- {
- }
-
- virtual bool Item(cChestEntity * a_Chest) override
+ int NumberOfPlayers = 0;
+ VERIFY(!a_World.DoWithChestAt(a_Position.x, a_Position.y, a_Position.z, [&](cChestEntity & a_Chest)
{
- ASSERT(a_Chest->GetBlockType() == E_BLOCK_TRAPPED_CHEST);
- m_NumberOfPlayers = a_Chest->GetNumberOfPlayers();
+ ASSERT(a_Chest.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
+ NumberOfPlayers = a_Chest.GetNumberOfPlayers();
return true;
}
-
- 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();
+ ));
+ return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
}
virtual cVector3iArray Update(cWorld & a_World, 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 609db932d..47225715f 100644
--- a/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h
+++ b/src/Simulator/IncrementalRedstoneSimulator/TripwireHookHandler.h
@@ -39,26 +39,7 @@ public:
if (Type == E_BLOCK_TRIPWIRE)
{
- 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))
+ if (!a_World.ForEachEntityInBox(cBoundingBox(Vector3d(0.5, 0, 0.5) + Position, 0.5, 0.5), [](cEntity &) { return true; }))
{
FoundActivated = true;
}