2017-09-19 08:34:08 +00:00
|
|
|
|
2015-06-26 22:24:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-29 00:51:25 +00:00
|
|
|
#include "../../BlockEntities/ChestEntity.h"
|
2015-06-26 22:24:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 20:14:40 +00:00
|
|
|
namespace TrappedChestHandler
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2021-01-21 22:51:55 +00: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 22:24:51 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
return DataForChunk(a_Chunk).GetCachedPowerData(a_Position);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2017-09-11 21:20:49 +00:00
|
|
|
int NumberOfPlayers = 0;
|
2021-03-28 13:40:57 +00:00
|
|
|
a_Chunk.DoWithBlockEntityAt(a_Position, [&NumberOfPlayers](cBlockEntity & a_BlockEntity)
|
|
|
|
{
|
2021-04-30 13:23:46 +00:00
|
|
|
ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
|
2021-03-28 13:40:57 +00:00
|
|
|
|
|
|
|
NumberOfPlayers = static_cast<cChestEntity &>(a_BlockEntity).GetNumberOfPlayers();
|
|
|
|
return false;
|
|
|
|
});
|
2020-07-26 13:15:00 +00:00
|
|
|
|
2017-09-11 21:20:49 +00:00
|
|
|
return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2015-12-24 15:57:45 +00:00
|
|
|
// LOGD("Evaluating tricky the trapped chest (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 22:24:51 +00:00
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
const auto PowerLevel = GetPowerLevel(a_Chunk, a_Position);
|
|
|
|
const auto PreviousPower = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, PowerLevel);
|
2015-06-26 22:24:51 +00:00
|
|
|
|
2020-08-20 19:04:28 +00:00
|
|
|
if (PowerLevel != PreviousPower)
|
2015-06-26 22:24:51 +00:00
|
|
|
{
|
2020-08-08 17:22:16 +00:00
|
|
|
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeAdjacents);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 22:51:55 +00:00
|
|
|
static 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_Position);
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
2020-07-26 13:15:00 +00:00
|
|
|
UNUSED(Callback);
|
2015-06-26 22:24:51 +00:00
|
|
|
}
|
|
|
|
};
|