2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-28 20:51:25 -04:00
|
|
|
#include "../../Blocks/BlockPiston.h"
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 16:14:40 -04:00
|
|
|
namespace PistonHandler
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2021-01-21 17:51:55 -05:00
|
|
|
static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_QueryPosition);
|
|
|
|
UNUSED(a_QueryBlockType);
|
2020-08-08 13:22:16 -04:00
|
|
|
UNUSED(IsLinked);
|
2015-06-26 18:24:51 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-21 17:51:55 -05:00
|
|
|
static void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2015-12-24 10:57:45 -05:00
|
|
|
// LOGD("Evaluating pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
2020-08-20 15:04:28 -04:00
|
|
|
const bool ShouldBeExtended = Power != 0;
|
2018-07-23 19:35:20 -04:00
|
|
|
if (ShouldBeExtended == cBlockPistonHandler::IsExtended(a_Meta))
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
return;
|
2018-07-23 19:35:20 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
a_Position = cChunkDef::RelativeToAbsolute(a_Position, a_Chunk.GetPos());
|
|
|
|
|
2018-07-23 19:35:20 -04:00
|
|
|
if (ShouldBeExtended)
|
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
cBlockPistonHandler::ExtendPiston(a_Position, *a_Chunk.GetWorld());
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
cBlockPistonHandler::RetractPiston(a_Position, *a_Chunk.GetWorld());
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2018-07-23 19:35:20 -04:00
|
|
|
// It is necessary to delay after a signal to prevent an infinite loop (#3168)
|
2020-07-26 09:15:00 -04:00
|
|
|
// However, this delay is already present: as a side effect of the implementation of piston animation in Blocks\BlockPiston.cpp
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2021-01-21 17:51:55 -05:00
|
|
|
static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 18:24:51 -04:00
|
|
|
UNUSED(a_BlockType);
|
2015-12-24 10:57:45 -05:00
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
const auto Face = cBlockPistonHandler::MetaDataToDirection(a_Meta);
|
|
|
|
const auto FrontOffset = AddFaceDirection(Vector3i(), Face);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
for (const auto & Offset : RelativeAdjacents)
|
2020-07-26 09:15:00 -04:00
|
|
|
{
|
|
|
|
if (Offset != FrontOffset)
|
|
|
|
{
|
|
|
|
Callback(a_Position + Offset);
|
|
|
|
}
|
|
|
|
}
|
2020-09-21 15:39:58 -04:00
|
|
|
|
|
|
|
// Consider indirect power:
|
|
|
|
Callback.CheckIndirectPower();
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|