2015-06-26 22:24:51 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-08-29 00:51:25 +00:00
|
|
|
#include "../../Blocks/BlockDoor.h"
|
2015-06-26 22:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 20:14:40 +00:00
|
|
|
namespace DoorHandler
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-08-08 17:22:16 +00:00
|
|
|
// "Doormammu, I've come to bargain"
|
2015-06-26 22:24:51 +00:00
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
inline PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 22:24:51 +00:00
|
|
|
UNUSED(a_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_QueryPosition);
|
|
|
|
UNUSED(a_QueryBlockType);
|
2020-08-08 17:22:16 +00:00
|
|
|
UNUSED(IsLinked);
|
2015-06-26 22:24:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
inline void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PowerLevel Power)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2015-12-24 15:57:45 +00:00
|
|
|
// LOGD("Evaluating dori the door (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 22:24:51 +00:00
|
|
|
|
2020-08-08 17:22:16 +00:00
|
|
|
if ((a_Meta & 0x8) == 0x8)
|
|
|
|
{
|
|
|
|
// We're treating the bottom half as the source of truth, so ignore updates to the top:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto TopPosition = a_Position + OffsetYP;
|
|
|
|
ForEachSourceCallback Callback(a_Chunk, TopPosition, a_BlockType);
|
2020-08-19 20:14:40 +00:00
|
|
|
RedstoneHandler::ForValidSourcePositions(a_Chunk, TopPosition, a_BlockType, a_Meta, Callback);
|
2020-08-08 17:22:16 +00:00
|
|
|
|
|
|
|
// Factor in what the upper half is getting:
|
2020-08-20 19:04:28 +00:00
|
|
|
Power = std::max(Power, Callback.Power);
|
2020-08-08 17:22:16 +00:00
|
|
|
|
2020-07-26 13:15:00 +00:00
|
|
|
cChunkInterface ChunkInterface(a_Chunk.GetWorld()->GetChunkMap());
|
2020-08-20 19:04:28 +00:00
|
|
|
const bool ShouldBeOpen = Power != 0;
|
2020-07-26 13:15:00 +00:00
|
|
|
const auto AbsolutePosition = cChunkDef::RelativeToAbsolute(a_Position, a_Chunk.GetPos());
|
|
|
|
const bool IsOpen = cBlockDoorHandler::IsOpen(ChunkInterface, AbsolutePosition);
|
|
|
|
|
|
|
|
if (ShouldBeOpen != IsOpen)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
cBlockDoorHandler::SetOpen(ChunkInterface, AbsolutePosition, ShouldBeOpen);
|
|
|
|
a_Chunk.GetWorld()->BroadcastSoundParticleEffect(EffectID::SFX_RANDOM_WOODEN_DOOR_OPEN, AbsolutePosition, 0);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:14:40 +00:00
|
|
|
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-07-26 13:15:00 +00:00
|
|
|
UNUSED(a_Chunk);
|
2015-06-26 22:24:51 +00:00
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
2020-07-26 13:15:00 +00:00
|
|
|
InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
};
|