Files
cuberite-2a/src/Simulator/IncrementalRedstoneSimulator/PistonHandler.h
T

68 lines
1.8 KiB
C++
Raw Normal View History

2015-06-26 17:24:51 -05:00
#pragma once
#include "RedstoneHandler.h"
#include "../../Blocks/BlockPiston.h"
2015-06-26 17:24:51 -05:00
2020-07-26 14:15:00 +01:00
class cPistonHandler final: public cRedstoneHandler
2015-06-26 17:24:51 -05:00
{
public:
2020-07-26 14:15:00 +01:00
virtual unsigned char GetPowerDeliveredToPosition(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType) const override
2015-06-26 17:24:51 -05:00
{
2020-07-26 14:15:00 +01:00
UNUSED(a_Chunk);
2015-06-26 17:24:51 -05:00
UNUSED(a_Position);
UNUSED(a_BlockType);
UNUSED(a_Meta);
UNUSED(a_QueryPosition);
UNUSED(a_QueryBlockType);
return 0;
}
2020-07-26 14:15:00 +01:00
virtual void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
2015-06-26 17:24:51 -05:00
{
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
2015-06-26 17:24:51 -05:00
2020-07-26 14:15:00 +01:00
const bool ShouldBeExtended = a_PoweringData.PowerLevel != 0;
2018-07-24 00:35:20 +01:00
if (ShouldBeExtended == cBlockPistonHandler::IsExtended(a_Meta))
2015-06-26 17:24:51 -05:00
{
2020-07-26 14:15:00 +01:00
return;
2018-07-24 00:35:20 +01:00
}
2020-07-26 14:15:00 +01:00
a_Position = cChunkDef::RelativeToAbsolute(a_Position, a_Chunk.GetPos());
2018-07-24 00:35:20 +01:00
if (ShouldBeExtended)
{
2020-07-26 14:15:00 +01:00
cBlockPistonHandler::ExtendPiston(a_Position, *a_Chunk.GetWorld());
2015-06-26 17:24:51 -05:00
}
else
{
2020-07-26 14:15:00 +01:00
cBlockPistonHandler::RetractPiston(a_Position, *a_Chunk.GetWorld());
2015-06-26 17:24:51 -05:00
}
2018-07-24 00:35:20 +01:00
// It is necessary to delay after a signal to prevent an infinite loop (#3168)
2020-07-26 14:15:00 +01:00
// However, this delay is already present: as a side effect of the implementation of piston animation in Blocks\BlockPiston.cpp
2015-06-26 17:24:51 -05:00
}
2020-07-26 14:15:00 +01:00
virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
2015-06-26 17:24:51 -05:00
{
2020-07-26 14:15:00 +01:00
UNUSED(a_Chunk);
2015-06-26 17:24:51 -05:00
UNUSED(a_BlockType);
2020-07-26 14:15:00 +01:00
const auto Face = cBlockPistonHandler::MetaDataToDirection(a_Meta);
const auto FrontOffset = AddFaceDirection(Vector3i(), Face);
2015-06-26 17:24:51 -05:00
2020-07-26 14:15:00 +01:00
for (const auto Offset : RelativeAdjacents)
{
if (Offset != FrontOffset)
{
Callback(a_Position + Offset);
}
}
2015-06-26 17:24:51 -05:00
}
};