9 #include "../Entities/Player.h" 10 #include "../Entities/Pickup.h" 11 #include "../Bindings/PluginManager.h" 12 #include "../UI/HopperWindow.h" 21 super(a_BlockType, a_BlockMeta, a_Pos, ContentsWidth, ContentsHeight, a_World),
22 m_LastMoveItemsInTick(0),
23 m_LastMoveItemsOutTick(0)
72 isDirty =
MoveItemsIn (a_Chunk, CurrentTick) || isDirty;
74 isDirty =
MoveItemsOut (a_Chunk, CurrentTick) || isDirty;
98 if (Window ==
nullptr)
105 if (Window !=
nullptr)
193 class cHopperPickupSearchCallback
198 m_bFoundPickupsAbove(
false),
203 bool operator () (
cEntity & a_Entity)
212 double Distance = (EntityPos - BlockPos).Length();
216 if (TrySuckPickupIn(static_cast<cPickup &>(a_Entity)))
225 bool TrySuckPickupIn(
cPickup & a_Pickup)
233 m_bFoundPickupsAbove =
true;
241 m_bFoundPickupsAbove =
true;
257 bool FoundPickupsAbove(
void)
const 259 return m_bFoundPickupsAbove;
264 bool m_bFoundPickupsAbove;
271 return HopperPickupSearchCallback.FoundPickupsAbove();
294 if (out.second.y < 0)
303 if (destChunk ==
nullptr)
312 switch (destChunk->GetBlock(relCoord))
333 if (blockEntity ==
nullptr)
335 FLOGWARNING(
"{0}: A block entity was not found where expected at {1}", __FUNCTION__, absCoord);
360 if (mainChest ==
nullptr)
362 FLOGWARNING(
"{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, chestPos);
372 static const Vector3i neighborOfs[] =
379 for (
const auto & ofs: neighborOfs)
383 if (neighbor ==
nullptr)
389 if (Block != mainChest->GetBlockType())
395 auto neighborAbsCoord = neighbor->RelativeToAbsolute(neighborRelCoord);
396 auto sideChest =
static_cast<cChestEntity *
>(neighbor->GetBlockEntity(neighborAbsCoord));
397 if (sideChest ==
nullptr)
399 FLOGWARNING(
"{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, neighborAbsCoord);
422 if (furnace ==
nullptr)
431 cItem NewOutput(furnace->GetOutputSlot());
432 furnace->SetOutputSlot(NewOutput.AddCount(-1));
441 furnace->SetFuelSlot(
cItem());
459 for (
int i = 0; i < NumSlots; i++)
461 if (Grid.IsSlotEmpty(i))
467 Grid.ChangeSlotCount(i, -1);
523 if (ConnectedChest ==
nullptr)
525 FLOGWARNING(
"{0}: A chest entity was not found where expected, at {1}", __FUNCTION__, a_Coords);
535 static const Vector3i neighborOfs [] =
543 for (
const auto & ofs: neighborOfs)
545 auto otherHalfRelCoord = relCoord + ofs;
547 if (neighbor ==
nullptr)
552 auto Block = neighbor->
GetBlock(otherHalfRelCoord);
553 if (Block != ConnectedChest->GetBlockType())
559 auto chest =
static_cast<cChestEntity *
>(neighbor->GetBlockEntity(a_Coords + ofs));
560 if (chest ==
nullptr)
562 FLOGWARNING(
"{0}: A chest entity was not found where expected, at {1} ({2}, {3}})", __FUNCTION__, a_Coords + ofs, ofs.
x, ofs.z);
603 for (
int i = 0; i < NumSlots; i++)
cWorld * GetWorld(void) const
cChunk * GetRelNeighborChunkAdjustCoords(Vector3i &a_RelPos) const
Returns the chunk into which the relatively-specified block belongs.
bool MoveItemsFromChest(cChunk &a_Chunk)
Moves items from a chest (dblchest) above the hopper into this hopper.
bool IsFullStack(void) const
Returns true if the item is stacked up to its maximum stacking.
Int64 m_LastMoveItemsInTick
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...
unsigned char BLOCKTYPE
The datatype used by blockdata.
const cItem & GetSlot(int a_SlotNum) const
int m_RelX
Position relative to the chunk, used to speed up ticking.
Vector3< T > addedXZ(T a_AddX, T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the X and Z axes.
cWindow * GetWindow(void)
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition)
Converts the coord relative to this chunk into an absolute coord.
bool MoveItemsFromSlot(cBlockEntityWithItems &a_Entity, int a_SrcSlotNum)
Moves one piece from the specified itemstack into this hopper.
virtual void CopyFrom(const cBlockEntity &a_Src) override
Copies all properties of a_Src into this entity, except for its m_World and location.
int ChangeSlotCount(int a_SlotNum, int a_AddToCount)
Adds (or subtracts, if a_AddToCount is negative) to the count of items in the specified slot...
void OpenWindow(cWindow *a_Window)
cItemGrid & GetContents(void)
Returns the ItemGrid used for storing the contents.
cHopperEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld *a_World)
Constructor used for normal operation.
bool IsEqual(const cItem &a_Item) const
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
bool CallHookHopperPushingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems &a_DstEntity, int a_DstSlotNum)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
cItem CopyOne(void) const
Returns a copy of this item with m_ItemCount set to 1.
bool MoveItemsToSlot(cBlockEntityWithItems &a_Entity, int a_DstSlotNum)
Moves one piece to the specified entity's contents' slot.
cBlockEntity * GetBlockEntity(Vector3i a_AbsPos)
Returns the block entity at the specified (absolute) coords.
virtual void Destroy(bool a_ShouldBroadcast=true)
Destroys the entity and schedules it for memory freeing; if a_ShouldBroadcast is set to true...
bool IsSlotEmpty(int a_SlotNum) const
Returns true if the specified slot is empty or the slot doesn't exist.
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
void MarkChunkDirty(int a_ChunkX, int a_ChunkZ)
bool ForEachEntity(cEntityCallback a_Callback)
Calls the callback for each entity; returns true if all entities processed, false if the callback abo...
cWindow * GetWindow(void) const
Vector3i GetRelPos() const
bool MoveItemsToChest(cChunk &a_Chunk, Vector3i a_Coords)
Moves items to the chest at the specified absolute coords.
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
bool CallHookHopperPullingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_DstSlotNum, cBlockEntityWithItems &a_SrcEntity, int a_SrcSlotNum)
bool MoveItemsToGrid(cBlockEntityWithItems &a_Entity)
Moves items to the specified ItemGrid.
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:
virtual Int64 GetWorldAge(void) const override
bool MoveItemsToFurnace(cChunk &a_Chunk, Vector3i a_Coords, NIBBLETYPE a_HopperMeta)
Moves items to the furnace at the specified absolute coords.
Int64 m_LastMoveItemsOutTick
Vector3i m_Pos
Position in absolute block coordinates.
bool MovePickupsIn(cChunk &a_Chunk, Int64 a_CurrentTick)
Moves pickups from above this hopper into it.
bool MoveItemsFromFurnace(cChunk &a_Chunk)
Moves items from a furnace above the hopper into this hopper.
void FLOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
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.
How many ticks at minimum between two item transfers to or from the hopper.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
bool MoveItemsIn(cChunk &a_Chunk, Int64 a_CurrentTick)
Moves items from the container above it into this hopper.
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 Vector3d & GetPosition(void) const
Exported in ManualBindings.
bool IsPickup(void) const
virtual bool UsedBy(cPlayer *a_Player) override
Called when a player uses this entity; should open the UI window.
const cItem & GetSlot(int a_X, int a_Y) const
bool MoveItemsOut(cChunk &a_Chunk, Int64 a_CurrentTick)
Moves items out from this hopper into the destination.
int GetNumSlots(void) const
void OpenNewWindow(void)
Opens a new chest window for this chest.
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
virtual void SendTo(cClientHandle &a_Client) override
Sends the packet defining the block entity to the client specified.
void SetSlot(int a_X, int a_Y, const cItem &a_Item)