1
0

Hoppers: use 'locked' bit in meta

This commit is contained in:
Tiger Wang 2021-04-10 17:17:15 +01:00
parent 3001e23e8c
commit 7080c4d3e2

View File

@ -24,20 +24,31 @@ namespace HopperHandler
{
// LOGD("Evaluating holey the hopper (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
const auto Previous = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, Power);
if (Previous == Power)
const bool ShouldBeLocked = Power != 0;
const bool PreviouslyLocked = (a_Meta & 0x8) == 0x8;
if (ShouldBeLocked == PreviouslyLocked)
{
return;
}
a_Chunk.DoWithBlockEntityAt(a_Position, [Power](cBlockEntity & a_BlockEntity)
if (ShouldBeLocked)
{
a_Chunk.SetMeta(a_Position, a_Meta | 0x8);
}
else
{
a_Chunk.SetMeta(a_Position, a_Meta & ~0x8);
}
a_Chunk.DoWithBlockEntityAt(a_Position, [ShouldBeLocked](cBlockEntity & a_BlockEntity)
{
if (a_BlockEntity.GetBlockType() != E_BLOCK_HOPPER)
{
return false;
}
static_cast<cHopperEntity &>(a_BlockEntity).SetLocked(Power != 0);
static_cast<cHopperEntity &>(a_BlockEntity).SetLocked(ShouldBeLocked);
return false;
});
}