fix importing from storage drawers
This commit is contained in:
@@ -12,198 +12,198 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
public class AdaptorItemRepository extends InventoryAdaptor
|
public class AdaptorItemRepository extends InventoryAdaptor
|
||||||
{
|
{
|
||||||
protected final IItemRepository itemRepository;
|
protected final IItemRepository itemRepository;
|
||||||
|
|
||||||
public AdaptorItemRepository( IItemRepository itemRepository )
|
public AdaptorItemRepository( IItemRepository itemRepository )
|
||||||
{
|
{
|
||||||
this.itemRepository = itemRepository;
|
this.itemRepository = itemRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||||
{
|
{
|
||||||
ItemStack rv = ItemStack.EMPTY;
|
ItemStack rv = ItemStack.EMPTY;
|
||||||
ItemStack extracted = ItemStack.EMPTY;
|
ItemStack extracted = ItemStack.EMPTY;
|
||||||
|
|
||||||
if( !filter.isEmpty() )
|
if( !filter.isEmpty() )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||||
if( !extracted.isEmpty() )
|
if( !extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||||
{
|
{
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extracted = this.itemRepository.extractItem( filter, amount, false );
|
extracted = this.itemRepository.extractItem( filter.isEmpty() ? extracted : filter, amount, false );
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||||
{
|
{
|
||||||
ItemStack rv = ItemStack.EMPTY;
|
ItemStack rv = ItemStack.EMPTY;
|
||||||
ItemStack extracted = ItemStack.EMPTY;
|
ItemStack extracted = ItemStack.EMPTY;
|
||||||
|
|
||||||
if( !filter.isEmpty() )
|
if( !filter.isEmpty() )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||||
if( !extracted.isEmpty() )
|
if( !extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||||
{
|
{
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||||
{
|
{
|
||||||
ItemStack rv = ItemStack.EMPTY;
|
ItemStack rv = ItemStack.EMPTY;
|
||||||
ItemStack extracted = ItemStack.EMPTY;
|
ItemStack extracted = ItemStack.EMPTY;
|
||||||
|
|
||||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||||
{
|
{
|
||||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !extracted.isEmpty() )
|
if( !extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||||
{
|
{
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extracted = this.itemRepository.extractItem( extracted, amount, false );
|
extracted = this.itemRepository.extractItem( extracted, amount, false );
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||||
{
|
{
|
||||||
ItemStack rv = ItemStack.EMPTY;
|
ItemStack rv = ItemStack.EMPTY;
|
||||||
ItemStack extracted = ItemStack.EMPTY;
|
ItemStack extracted = ItemStack.EMPTY;
|
||||||
|
|
||||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||||
{
|
{
|
||||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||||
{
|
{
|
||||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !extracted.isEmpty() )
|
if( !extracted.isEmpty() )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( destination != null )
|
if( destination != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||||
{
|
{
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack addItems( ItemStack toBeAdded )
|
public ItemStack addItems( ItemStack toBeAdded )
|
||||||
{
|
{
|
||||||
return this.addItems( toBeAdded, false );
|
return this.addItems( toBeAdded, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
||||||
{
|
{
|
||||||
if( itemsToAdd.isEmpty() )
|
if( itemsToAdd.isEmpty() )
|
||||||
{
|
{
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack left = itemsToAdd.copy();
|
ItemStack left = itemsToAdd.copy();
|
||||||
|
|
||||||
left = this.itemRepository.insertItem( left, simulate );
|
left = this.itemRepository.insertItem( left, simulate );
|
||||||
|
|
||||||
if( left.isEmpty() )
|
if( left.isEmpty() )
|
||||||
{
|
{
|
||||||
return ItemStack.EMPTY;
|
return ItemStack.EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||||
{
|
{
|
||||||
return this.addItems( toBeSimulated, true );
|
return this.addItems( toBeSimulated, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean containsItems()
|
public boolean containsItems()
|
||||||
{
|
{
|
||||||
return !this.itemRepository.getAllItems().isEmpty();
|
return !this.itemRepository.getAllItems().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasSlots()
|
public boolean hasSlots()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<ItemSlot> iterator()
|
public Iterator<ItemSlot> iterator()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user