1
0
cuberite-2a/src/Simulator/IncrementalRedstoneSimulator/HopperHandler.h
Tiger Wang 9b97d63f8f
Chest, weather, crash, and miscellaneous fixes (#5215)
* Alpha-sort cChestEntity

* Chests: use SendUpdateBlockEntity

* Pathfinder: fix out of range Y

* 1.13: correct weather packet ID

* Chests: fix neighbour scanner

+ Add OnAddToWorld and overload to scan neighbours there, instead of in the constructor/OnUse. This fixes hoppers accessing newly loaded double chests and seeing a null m_Neighbour, thus thinking its a single chest.
* Fix typo in cross coords computation.
* Simplify hopper logic.

* Block entities: ASSERT that type is correct

If you match the block type first before calling DoWithBlockEntity, the corresponding block entity must either be empty or correspond to the block type.

* Chunk: fix some forgotten PendingSendBE cleanup

+ Add cleanup in SetAllData, WriteBlockArea
- Remove RemoveBlockEntity (used once), HasBlockEntity (not used)

* Replace MakeIndex with MakeIndexNoCheck

* Remove extraneous MarkDirty in hopper & chests
2021-04-30 13:23:46 +00:00

61 lines
1.5 KiB
C++

#pragma once
#include "../../BlockEntities/HopperEntity.h"
namespace HopperHandler
{
static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
{
UNUSED(a_Chunk);
UNUSED(a_Position);
UNUSED(a_BlockType);
UNUSED(a_QueryPosition);
UNUSED(a_QueryBlockType);
UNUSED(IsLinked);
return 0;
}
static void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
{
// LOGD("Evaluating holey the hopper (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
const bool ShouldBeLocked = Power != 0;
const bool PreviouslyLocked = (a_Meta & 0x8) == 0x8;
if (ShouldBeLocked == PreviouslyLocked)
{
return;
}
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)
{
ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_HOPPER);
static_cast<cHopperEntity &>(a_BlockEntity).SetLocked(ShouldBeLocked);
return false;
});
}
static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
{
UNUSED(a_Chunk);
UNUSED(a_BlockType);
UNUSED(a_Meta);
InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
}
};