summaryrefslogtreecommitdiffstats
path: root/src/Simulator/IncrementalRedstoneSimulator
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-09-01 21:12:44 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-09-01 21:12:44 +0200
commit6e3e7552e67dfc0254c3e99bcd32fea02f10d062 (patch)
tree84bfd40d2c2693cab44a47d4902aa601d8a715e6 /src/Simulator/IncrementalRedstoneSimulator
parentd (diff)
parentSetSwimState now takes into account head height (diff)
downloadcuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar.gz
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar.bz2
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar.lz
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar.xz
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.tar.zst
cuberite-6e3e7552e67dfc0254c3e99bcd32fea02f10d062.zip
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 91fbe05ff..de0f23620 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 62b37eb1d..4974324a0 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 add608654..ba6c695d6 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 14d7baf85..93759408d 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 55efee6b5..6e3d080aa 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 8b7b82d49..d280f73e3 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, 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 85c05430c..2fb85f58c 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;
}