#include "CraftingStorage.h" BasicShapedCrafter::BasicShapedCrafter( int width, int height, Inventory* zInventory ) : zInventory( zInventory ), width( width ), height( height ) { for( int i = 0; i < width * height; i++ ) { ItemSlot* slot = new ItemSlot( 1, std::numeric_limits::max(), std::numeric_limits::max(), INSIDE, INSIDE, 0 ); zInventory->addSlot( slot ); craftingInput.add( slot ); } } bool BasicShapedCrafter::isAllAvailable( Framework::RCArray& filters, int width, int height ) { for( int x = 0; x <= this->width - width; x++ ) { for( int y = 0; y <= this->height - height; y++ ) { for( int w = 0; w < width; w++ ) { for( int h = 0; h < height; h++ ) { ItemFilter* f = filters.z( w * width + h ); ItemSlot* s = craftingInput.get( w * 2 + h ); const Item* item = 0; if( s && s->zStack() ) item = s->zStack()->zItem(); if( (item && !f) || (!item && f) ) return 0; if( item && f && !f->matchItem( item ) ) return 0; } } } } return 1; } bool BasicShapedCrafter::hasFreeSpace( const Item* zItem, int amount ) { ItemStack* stack = new ItemStack( (Item*)zItem, amount ); int addable = zInventory->numberOfAddableItems( stack, NO_DIRECTION ); stack->release(); return addable >= amount; } bool BasicShapedCrafter::consume( Framework::RCArray& filters, int width, int height ) { for( ItemSlot* slot : craftingInput ) { if( slot && slot->zStack() ) { ItemStack* stack = zInventory->takeItemsOut( slot, 1, INSIDE ); if( stack ) stack->release(); } } for( int x = 0; x < width; x++ ) { for( int y = 0; y < height; y++ ) { ItemFilter* f = filters.z( x * width + y ); if( f ) { ItemSlot* target = craftingInput.get( x * this->width + y ); Framework::Array< ItemSlot*> tmp; tmp.add( target ); zInventory->localTransaction( 0, &tmp, f, 1, NO_DIRECTION, INSIDE ); } } } return 1; } void BasicShapedCrafter::addCraftingResult( ItemStack* stack ) { zInventory->addItems( stack, NO_DIRECTION ); }