1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "ItemSlot.h"
- ItemSlot::ItemSlot( int maxSize, int pullPriority, int pushPriority, int allowedPullSide, int allowedPushSides, bool allowHigherStackSize )
- : ReferenceCounter(),
- items( 0 ),
- maxSize( maxSize ),
- allowedPullSide( allowedPullSide ),
- allowedPushSides( allowedPushSides ),
- pullPriority( pullPriority ),
- pushPriority( pushPriority ),
- allowHigherStackSize( allowHigherStackSize )
- {}
- ItemSlot::~ItemSlot()
- {
- if( items )
- items->release();
- }
- ItemStack* ItemSlot::takeItemsOut( int count, Direction dir )
- {
- if( !items )
- return 0;
- if( (dir | allowedPullSide) == allowedPullSide )
- {
- ItemStack* result = items->split( count );
- if( items->getSize() == 0 )
- {
- items->release();
- items = 0;
- }
- return result;
- }
- return 0;
- }
- void ItemSlot::addItems( ItemStack* zStack, Direction dir )
- {
- if( (dir | allowedPushSides) == allowedPushSides )
- {
- if( !items )
- {
- if( allowHigherStackSize )
- {
- items = zStack->split( maxSize );
- items->setMaxSize( maxSize );
- }
- else
- {
- items = zStack->split( MIN( maxSize, items->zItem()->getMaxStackSize() ) );
- items->setMaxSize( MIN( maxSize, items->zItem()->getMaxStackSize() ) );
- }
- }
- else
- items->addItemStack( zStack );
- }
- }
- int ItemSlot::numberOfAddableItems( const ItemStack* zStack, Direction dir ) const
- {
- if( (dir | allowedPushSides) == allowedPushSides )
- {
- if( !items )
- {
- if( allowHigherStackSize )
- return maxSize;
- else
- return MIN( maxSize, zStack->zItem()->getMaxStackSize() );
- }
- else
- return items->getMaxSize() - items->getSize();
- }
- return 0;
- }
- const ItemStack* ItemSlot::zStack() const
- {
- return items;
- }
- int ItemSlot::getPullPriority() const
- {
- return pullPriority;
- }
- int ItemSlot::getPushPriority() const
- {
- return pushPriority;
- }
- bool ItemSlot::isFull() const
- {
- return items ? items->getSize() < items->getMaxSize() : 0;
- }
|