forked from AppliedEnergistics/Applied-Energistics-2
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert inventory merging code to keep compatibility with ae2fc
- Loading branch information
1 parent
9d60266
commit 31a3afc
Showing
5 changed files
with
236 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
209 changes: 209 additions & 0 deletions
209
src/main/java/appeng/util/inv/AdaptorItemRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
package appeng.util.inv; | ||
|
||
import appeng.api.config.FuzzyMode; | ||
import appeng.util.InventoryAdaptor; | ||
|
||
import appeng.util.Platform; | ||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import java.util.Iterator; | ||
|
||
|
||
public class AdaptorItemRepository extends InventoryAdaptor | ||
{ | ||
protected final IItemRepository itemRepository; | ||
|
||
public AdaptorItemRepository( IItemRepository itemRepository ) | ||
{ | ||
this.itemRepository = itemRepository; | ||
} | ||
|
||
@Override | ||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination ) | ||
{ | ||
ItemStack rv = ItemStack.EMPTY; | ||
ItemStack extracted = ItemStack.EMPTY; | ||
|
||
if( !filter.isEmpty() ) | ||
{ | ||
extracted = this.itemRepository.extractItem( filter, amount, true ); | ||
} | ||
else | ||
{ | ||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() ) | ||
{ | ||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true ); | ||
if( !extracted.isEmpty() ) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if( destination != null ) | ||
{ | ||
|
||
if( extracted.isEmpty() || !destination.canInsert( extracted ) ) | ||
{ | ||
return rv; | ||
} | ||
|
||
} | ||
|
||
extracted = this.itemRepository.extractItem( filter, amount, false ); | ||
|
||
return extracted; | ||
} | ||
|
||
@Override | ||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination ) | ||
{ | ||
ItemStack rv = ItemStack.EMPTY; | ||
ItemStack extracted = ItemStack.EMPTY; | ||
|
||
if( !filter.isEmpty() ) | ||
{ | ||
extracted = this.itemRepository.extractItem( filter, amount, true ); | ||
} | ||
else | ||
{ | ||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() ) | ||
{ | ||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true ); | ||
if( !extracted.isEmpty() ) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if( destination != null ) | ||
{ | ||
|
||
if( extracted.isEmpty() || !destination.canInsert( extracted ) ) | ||
{ | ||
return rv; | ||
} | ||
|
||
} | ||
|
||
return extracted; | ||
} | ||
|
||
@Override | ||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination ) | ||
{ | ||
ItemStack rv = ItemStack.EMPTY; | ||
ItemStack extracted = ItemStack.EMPTY; | ||
|
||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() ) | ||
{ | ||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) ) | ||
{ | ||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true ); | ||
} | ||
|
||
if( !extracted.isEmpty() ) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if( destination != null ) | ||
{ | ||
|
||
if( extracted.isEmpty() || !destination.canInsert( extracted ) ) | ||
{ | ||
return rv; | ||
} | ||
|
||
} | ||
|
||
extracted = this.itemRepository.extractItem( extracted, amount, false ); | ||
|
||
return extracted; | ||
} | ||
|
||
@Override | ||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination ) | ||
{ | ||
ItemStack rv = ItemStack.EMPTY; | ||
ItemStack extracted = ItemStack.EMPTY; | ||
|
||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() ) | ||
{ | ||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) ) | ||
{ | ||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true ); | ||
} | ||
|
||
if( !extracted.isEmpty() ) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
if( destination != null ) | ||
{ | ||
|
||
if( extracted.isEmpty() || !destination.canInsert( extracted ) ) | ||
{ | ||
return rv; | ||
} | ||
|
||
} | ||
|
||
return extracted; | ||
} | ||
|
||
@Override | ||
public ItemStack addItems( ItemStack toBeAdded ) | ||
{ | ||
return this.addItems( toBeAdded, false ); | ||
} | ||
|
||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate ) | ||
{ | ||
if( itemsToAdd.isEmpty() ) | ||
{ | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
ItemStack left = itemsToAdd.copy(); | ||
|
||
left = this.itemRepository.insertItem( left, simulate ); | ||
|
||
if( left.isEmpty() ) | ||
{ | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
return left; | ||
} | ||
|
||
@Override | ||
public ItemStack simulateAdd( ItemStack toBeSimulated ) | ||
{ | ||
return this.addItems( toBeSimulated, true ); | ||
} | ||
|
||
@Override | ||
public boolean containsItems() | ||
{ | ||
return !this.itemRepository.getAllItems().isEmpty(); | ||
} | ||
|
||
@Override | ||
public boolean hasSlots() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public Iterator<ItemSlot> iterator() | ||
{ | ||
return null; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.