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

59 lines
1.7 KiB
C++
Raw Normal View History

2017-09-19 10:34:08 +02:00
2015-06-26 17:24:51 -05:00
#pragma once
#include "../../BlockEntities/ChestEntity.h"
2015-06-26 17:24:51 -05:00
namespace TrappedChestHandler
2015-06-26 17:24:51 -05:00
{
inline unsigned char GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
2015-06-26 17:24:51 -05:00
{
UNUSED(a_BlockType);
UNUSED(a_QueryPosition);
UNUSED(a_QueryBlockType);
2020-08-08 18:22:16 +01:00
UNUSED(IsLinked);
2015-06-26 17:24:51 -05:00
2020-07-26 14:15:00 +01:00
return DataForChunk(a_Chunk).GetCachedPowerData(a_Position).PowerLevel;
2015-06-26 17:24:51 -05:00
}
inline unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
2015-06-26 17:24:51 -05:00
{
2017-09-11 22:20:49 +01:00
int NumberOfPlayers = 0;
2020-07-26 14:15:00 +01:00
VERIFY(
!a_Chunk.DoWithChestAt(a_Position, [&](cChestEntity & a_Chest)
2015-06-26 17:24:51 -05:00
{
2017-09-11 22:20:49 +01:00
ASSERT(a_Chest.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
NumberOfPlayers = a_Chest.GetNumberOfPlayers();
2015-06-26 17:24:51 -05:00
return true;
2020-07-26 14:15:00 +01:00
})
);
2017-09-11 22:20:49 +01:00
return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
2015-06-26 17:24:51 -05:00
}
inline void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, PoweringData a_PoweringData)
2015-06-26 17:24:51 -05:00
{
// LOGD("Evaluating tricky the trapped chest (%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 auto Power = GetPowerLevel(a_Chunk, a_Position);
const auto PreviousPower = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, PoweringData(a_BlockType, Power));
2015-06-26 17:24:51 -05:00
if (Power != PreviousPower.PowerLevel)
{
2020-08-08 18:22:16 +01:00
UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeAdjacents);
2015-06-26 17:24:51 -05:00
}
}
inline void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
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);
2020-07-26 14:15:00 +01:00
UNUSED(Callback);
2015-06-26 17:24:51 -05:00
}
};