mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
merge master-MC1.10 to master-MC1.11
This commit is contained in:
parent
e856f829c9
commit
90d62a17d2
@ -74,7 +74,7 @@ class Trade(val info: TradeInfo) extends AbstractValue {
|
|||||||
val secondInputStack = if (recipe.hasSecondItemToBuy) Option(recipe.getSecondItemToBuy) else None
|
val secondInputStack = if (recipe.hasSecondItemToBuy) Option(recipe.getSecondItemToBuy) else None
|
||||||
|
|
||||||
def containsAccumulativeItemStack(stack: ItemStack) =
|
def containsAccumulativeItemStack(stack: ItemStack) =
|
||||||
InventoryUtils.extractFromInventory(stack, inventory, null, simulate = true).getCount == 0
|
InventoryUtils.extractFromInventory(stack, inventory, null, simulate = true, exact = false).getCount == 0
|
||||||
def hasRoomForItemStack(stack: ItemStack) = {
|
def hasRoomForItemStack(stack: ItemStack) = {
|
||||||
val remainder = stack.copy()
|
val remainder = stack.copy()
|
||||||
InventoryUtils.insertIntoInventory(remainder, InventoryUtils.asItemHandler(inventory), remainder.getCount, simulate = true)
|
InventoryUtils.insertIntoInventory(remainder, InventoryUtils.asItemHandler(inventory), remainder.getCount, simulate = true)
|
||||||
@ -87,8 +87,8 @@ class Trade(val info: TradeInfo) extends AbstractValue {
|
|||||||
val outputStack = recipe.getItemToSell.copy()
|
val outputStack = recipe.getItemToSell.copy()
|
||||||
if (hasRoomForItemStack(outputStack)) {
|
if (hasRoomForItemStack(outputStack)) {
|
||||||
// We established that out inventory allows to perform the trade, now actually do the trade.
|
// We established that out inventory allows to perform the trade, now actually do the trade.
|
||||||
InventoryUtils.extractFromInventory(firstInputStack, InventoryUtils.asItemHandler(inventory))
|
InventoryUtils.extractFromInventory(firstInputStack, InventoryUtils.asItemHandler(inventory), exact = false)
|
||||||
secondInputStack.map(InventoryUtils.extractFromInventory(_, InventoryUtils.asItemHandler(inventory)))
|
secondInputStack.map(InventoryUtils.extractFromInventory(_, InventoryUtils.asItemHandler(inventory), exact = false))
|
||||||
InventoryUtils.insertIntoInventory(outputStack, InventoryUtils.asItemHandler(inventory), outputStack.getCount)
|
InventoryUtils.insertIntoInventory(outputStack, InventoryUtils.asItemHandler(inventory), outputStack.getCount)
|
||||||
|
|
||||||
// Tell the merchant we used the recipe, so MC can disable it and/or enable more recipes.
|
// Tell the merchant we used the recipe, so MC can disable it and/or enable more recipes.
|
||||||
|
@ -225,19 +225,20 @@ object InventoryUtils {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* This will try to remove items of the same type as the specified item stack
|
* This will try to remove items of the same type as the specified item stack
|
||||||
* up to the number of the stack's size for all slots in the specified inventory.
|
* up to the number of the stack's size for all slots in the specified inventory.
|
||||||
|
* If exact is true, the items colated will also match meta data
|
||||||
* <p/>
|
* <p/>
|
||||||
* This uses the <tt>extractFromInventorySlot</tt> method, and therefore
|
* This uses the <tt>extractFromInventorySlot</tt> method, and therefore
|
||||||
* handles special cases such as sided inventories and stack size limits.
|
* handles special cases such as sided inventories and stack size limits.
|
||||||
*/
|
*/
|
||||||
def extractFromInventory(stack: ItemStack, inventory: IItemHandler, simulate: Boolean = false): ItemStack = {
|
def extractFromInventory(stack: ItemStack, inventory: IItemHandler, simulate: Boolean = false, exact: Boolean = true): ItemStack = {
|
||||||
val remaining = stack.copy()
|
val remaining = stack.copy()
|
||||||
for (slot <- 0 until inventory.getSlots if remaining.getCount > 0) {
|
for (slot <- 0 until inventory.getSlots if remaining.getCount > 0) {
|
||||||
extractFromInventorySlot(stack => {
|
extractFromInventorySlot(stackInInv => {
|
||||||
if (haveSameItemType(remaining, stack, checkNBT = true)) {
|
if (stackInInv != null && remaining.getItem == stackInInv.getItem && (!exact || haveSameItemType(remaining, stackInInv, checkNBT = true))) {
|
||||||
val transferred = stack.getCount min remaining.getCount
|
val transferred = stackInInv.getCount min remaining.getCount
|
||||||
remaining.shrink(transferred)
|
remaining.shrink(transferred)
|
||||||
if (!simulate) {
|
if (!simulate) {
|
||||||
stack.shrink(transferred)
|
stackInInv.shrink(transferred)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, inventory, slot, limit = remaining.getCount)
|
}, inventory, slot, limit = remaining.getCount)
|
||||||
@ -245,8 +246,8 @@ object InventoryUtils {
|
|||||||
remaining
|
remaining
|
||||||
}
|
}
|
||||||
|
|
||||||
def extractFromInventory(stack: ItemStack, inventory: IInventory, side: EnumFacing, simulate: Boolean): ItemStack =
|
def extractFromInventory(stack: ItemStack, inventory: IInventory, side: EnumFacing, simulate: Boolean, exact: Boolean): ItemStack =
|
||||||
extractFromInventory(stack, asItemHandler(inventory, side), simulate)
|
extractFromInventory(stack, asItemHandler(inventory, side), simulate, exact)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method for calling <tt>insertIntoInventory</tt> on an inventory
|
* Utility method for calling <tt>insertIntoInventory</tt> on an inventory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user