9 #include "../Entities/Player.h"
10 #include "../Entities/Pickup.h"
11 #include "../Bindings/PluginManager.h"
12 #include "../UI/HopperWindow.h"
21 #define TICKS_PER_TRANSFER 8_tick
28 Super(a_BlockType, a_BlockMeta, a_Pos, ContentsWidth, ContentsHeight, a_World),
29 m_LastMoveItemsInTick(0),
30 m_LastMoveItemsOutTick(0),
91 isDirty =
MoveItemsIn(a_Chunk, CurrentTick) || isDirty;
120 if (Window ==
nullptr)
127 if (Window !=
nullptr)
207 class cHopperPickupSearchCallback
212 m_bFoundPickupsAbove(
false),
217 bool operator () (
cEntity & a_Entity)
226 double Distance = (EntityPos - BlockPos).Length();
230 if (TrySuckPickupIn(
static_cast<cPickup &
>(a_Entity)))
239 bool TrySuckPickupIn(
cPickup & a_Pickup)
247 m_bFoundPickupsAbove =
true;
255 m_bFoundPickupsAbove =
true;
271 bool FoundPickupsAbove(
void)
const
273 return m_bFoundPickupsAbove;
278 bool m_bFoundPickupsAbove;
285 return HopperPickupSearchCallback.FoundPickupsAbove();
308 if (out.second.y < 0)
317 if (destChunk ==
nullptr)
326 switch (destChunk->GetBlock(relCoord))
347 if (blockEntity ==
nullptr)
349 FLOGWARNING(
"{0}: A block entity was not found where expected at {1}", __FUNCTION__, absCoord);
374 if (ConnectedBlockEntity ==
nullptr)
379 const auto ConnectedChest =
static_cast<cChestEntity *
>(ConnectedBlockEntity);
397 if (furnace ==
nullptr)
406 cItem NewOutput(furnace->GetOutputSlot());
407 furnace->SetOutputSlot(NewOutput.
AddCount(-1));
416 furnace->SetFuelSlot(
cItem());
434 for (
int i = 0; i < NumSlots; i++)
436 if (Grid.IsSlotEmpty(i))
442 Grid.ChangeSlotCount(i, -1);
496 const auto ConnectedBlockEntity = a_Chunk.
GetBlockEntity(a_Coords);
498 if (ConnectedBlockEntity ==
nullptr)
503 const auto ConnectedChest =
static_cast<cChestEntity *
>(ConnectedBlockEntity);
511 return (SecondaryChest !=
nullptr) &&
MoveItemsToGrid(*SecondaryChest);
541 for (
int i = 0; i < NumSlots; i++)
#define TICKS_PER_TRANSFER
@ E_META_HOPPER_FACING_XM
@ E_META_HOPPER_FACING_ZM
@ E_META_HOPPER_FACING_ZP
@ E_META_HOPPER_FACING_XP
@ E_META_HOPPER_FACING_YM
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
void FLOGWARNING(std::string_view a_Format, const Args &... args)
unsigned char Distance(const BlockState Block)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
Vector3i GetRelPos() const
Vector3i m_Pos
Position in absolute block coordinates.
cItemGrid & GetContents(void)
Returns the ItemGrid used for storing the contents.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
const cItem & GetSlot(int a_SlotNum) const
cChestEntity * GetSecondaryChest()
Returns the associated secondary chest, if any.
bool MoveItemsIn(cChunk &a_Chunk, cTickTimeLong a_CurrentTick)
Moves items from the container above it into this hopper.
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
bool MoveItemsToGrid(cBlockEntityWithItems &a_Entity)
Moves items to the specified ItemGrid.
cHopperEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Constructor used for normal operation.
void SetLocked(bool a_Value)
bool MoveItemsToSlot(cBlockEntityWithItems &a_Entity, int a_DstSlotNum)
Moves one piece to the specified entity's contents' slot.
bool MoveItemsToChest(cChunk &a_Chunk, Vector3i a_Coords)
Moves items to the chest at the specified absolute coords.
bool MoveItemsToFurnace(cChunk &a_Chunk, Vector3i a_Coords, NIBBLETYPE a_HopperMeta)
Moves items to the furnace at the specified absolute coords.
bool MoveItemsOut(cChunk &a_Chunk, cTickTimeLong a_CurrentTick)
Moves items out from this hopper into the destination.
void OpenNewWindow(void)
Opens a new chest window for this chest.
bool MoveItemsFromFurnace(cChunk &a_Chunk)
Moves items from a furnace above the hopper into this hopper.
cTickTimeLong m_LastMoveItemsInTick
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
bool MovePickupsIn(cChunk &a_Chunk)
Moves pickups from above this hopper into it.
bool MoveItemsFromChest(cChunk &a_Chunk)
Moves items from a chest (dblchest) above the hopper into this hopper.
std::pair< bool, Vector3i > GetOutputBlockPos(NIBBLETYPE a_BlockMeta)
Returns the block coords of the block receiving the output items, based on the meta Returns <false,...
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
cTickTimeLong m_LastMoveItemsOutTick
bool MoveItemsFromSlot(cBlockEntityWithItems &a_Entity, int a_SrcSlotNum)
Moves one piece from the specified itemstack into this hopper.
virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking.
bool MoveItemsFromGrid(cBlockEntityWithItems &a_Entity)
Moves items from the specified a_Entity's Contents into this hopper.
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
bool ForEachEntity(cEntityCallback a_Callback) const
Calls the callback for each entity; returns true if all entities processed, false if the callback abo...
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
cBlockEntity * GetBlockEntity(Vector3i a_AbsPos)
Returns the block entity at the specified (absolute) coords.
cWorld * GetWorld(void) const
cBlockEntity * GetBlockEntityRel(Vector3i a_RelPos)
Returns the block entity at the specified (relative) coords.
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
bool IsPickup(void) const
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
cWindow * GetWindow(void)
cItem & AddCount(char a_AmountToAdd)
Adds the specified count to this object and returns the reference to self (useful for chaining)
bool IsEqual(const cItem &a_Item) const
bool IsFullStack(void) const
Returns true if the item is stacked up to its maximum stacking.
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
bool IsSlotEmpty(int a_SlotNum) const
Returns true if the specified slot is empty or the slot doesn't exist.
char ChangeSlotCount(int a_SlotNum, char a_AddToCount)
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot.
void SetSlot(int a_X, int a_Y, const cItem &a_Item)
const cItem & GetSlot(int a_X, int a_Y) const
int GetNumSlots(void) const
std::unordered_map< CustomStatistic, StatValue > Custom
cWindow * GetWindow(void) const
void OpenWindow(cWindow *a_Window)
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
virtual cTickTimeLong GetWorldAge(void) const override