2017-09-19 04:34:08 -04:00
|
|
|
|
2015-06-26 18:24:51 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RedstoneHandler.h"
|
2018-08-28 20:51:25 -04:00
|
|
|
#include "../../BlockEntities/ChestEntity.h"
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cTrappedChestHandler:
|
|
|
|
public cRedstoneHandler
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cRedstoneHandler;
|
|
|
|
|
2015-06-26 18:24:51 -04:00
|
|
|
public:
|
|
|
|
|
2020-07-26 09:15:00 -04: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 18:24:51 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_BlockType);
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
UNUSED(a_QueryPosition);
|
|
|
|
UNUSED(a_QueryBlockType);
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
return DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
static unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-09-11 17:20:49 -04:00
|
|
|
int NumberOfPlayers = 0;
|
2020-07-26 09:15:00 -04:00
|
|
|
VERIFY(
|
|
|
|
!a_Chunk.DoWithChestAt(a_Position, [&](cChestEntity & a_Chest)
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2017-09-11 17:20:49 -04:00
|
|
|
ASSERT(a_Chest.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
|
|
|
|
NumberOfPlayers = a_Chest.GetNumberOfPlayers();
|
2015-06-26 18:24:51 -04:00
|
|
|
return true;
|
2020-07-26 09:15:00 -04:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2017-09-11 17:20:49 -04:00
|
|
|
return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
virtual void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData) const override
|
2015-06-26 18:24:51 -04:00
|
|
|
{
|
2015-12-24 10:57:45 -05:00
|
|
|
// LOGD("Evaluating tricky the trapped chest (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
|
2015-06-26 18:24:51 -04:00
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
const auto Power = GetPowerLevel(a_Chunk, a_Position);
|
|
|
|
const auto PreviousPower = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, PoweringData(a_BlockType, Power));
|
2015-06-26 18:24:51 -04:00
|
|
|
|
|
|
|
if (Power != PreviousPower.PowerLevel)
|
|
|
|
{
|
2020-07-26 09:15:00 -04:00
|
|
|
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, OffsetYM);
|
|
|
|
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeLaterals);
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 09:15:00 -04:00
|
|
|
virtual void ForValidSourcePositions(cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, SourceCallback Callback) const override
|
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_Meta);
|
2020-07-26 09:15:00 -04:00
|
|
|
UNUSED(Callback);
|
2015-06-26 18:24:51 -04:00
|
|
|
}
|
|
|
|
};
|