diff --git a/src/main/scala/li/cil/oc/common/recipe/ExtendedFuzzyShapelessRecipe.scala b/src/main/scala/li/cil/oc/common/recipe/ExtendedFuzzyShapelessRecipe.scala new file mode 100644 index 000000000..6232b9e57 --- /dev/null +++ b/src/main/scala/li/cil/oc/common/recipe/ExtendedFuzzyShapelessRecipe.scala @@ -0,0 +1,27 @@ +package li.cil.oc.common.recipe + +import net.minecraft.inventory.InventoryCrafting +import net.minecraft.item.ItemStack +import net.minecraftforge.oredict.ShapelessOreRecipe + +import scala.collection.mutable.ListBuffer + +class ExtendedFuzzyShapelessRecipe(result: ItemStack, ingredients: AnyRef*) extends ExtendedShapelessOreRecipe(result, ingredients: _*) { + override def matches(inv: net.minecraft.inventory.InventoryCrafting, world: net.minecraft.world.World): Boolean = { + val requiredItems = ingredients.map(any => any.asInstanceOf[ItemStack]).toList.to[ListBuffer] + //.groupBy{ case s: ItemStack => s.getItem }.mapValues(_.size).toSeq: _*) + for (i <- 0 until inv.getSizeInventory) { + val itemStack = inv.getStackInSlot(i) + if (!itemStack.isEmpty) { + val index = requiredItems.indexWhere(req => { + if (req.getItem != itemStack.getItem) return false + req.getItemDamage == itemStack.getItemDamage + }) + if (index >= 0) { + requiredItems.remove(index) + } + } + } + requiredItems.isEmpty + } +} diff --git a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala index 3577ed787..ba410e017 100644 --- a/src/main/scala/li/cil/oc/common/recipe/Recipes.scala +++ b/src/main/scala/li/cil/oc/common/recipe/Recipes.scala @@ -243,7 +243,7 @@ object Recipes { mcu.createItemStack(1), eeprom.createItemStack(1))) // Drone recrafting. - Recipes.addRecipe(new ExtendedShapelessOreRecipe( + Recipes.addRecipe(new ExtendedFuzzyShapelessRecipe( drone.createItemStack(1), drone.createItemStack(1), eeprom.createItemStack(1))) @@ -253,7 +253,7 @@ object Recipes { eeprom.createItemStack(1), eeprom.createItemStack(1))) // Robot recrafting. - Recipes.addRecipe(new ExtendedShapelessOreRecipe( + Recipes.addRecipe(new ExtendedFuzzyShapelessRecipe( robot.createItemStack(1), robot.createItemStack(1), eeprom.createItemStack(1))) diff --git a/src/main/scala/li/cil/oc/server/agent/Player.scala b/src/main/scala/li/cil/oc/server/agent/Player.scala index d9953713f..511080893 100644 --- a/src/main/scala/li/cil/oc/server/agent/Player.scala +++ b/src/main/scala/li/cil/oc/server/agent/Player.scala @@ -105,9 +105,7 @@ object Player { for (i <- 0 until size) { setCopyOrNull(player.inventory.mainInventory, agent.mainInventory, i) } - // no reason to sync to container, container already maps to agent inventory - // which we just copied from - // player.inventoryContainer.detectAndSendChanges() + player.inventoryContainer.detectAndSendChanges() } def detectInventoryPlayerChanges(player: Player): Unit = { diff --git a/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala b/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala index 89f2e80de..7c97298de 100644 --- a/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala +++ b/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala @@ -47,9 +47,8 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs private object CraftingInventory extends inventory.InventoryCrafting(new inventory.Container { override def canInteractWith(player: EntityPlayer) = true }, 3, 3) { - var amountPossible = 0 def craft(wantedCount: Int): Seq[_] = { - var player = host.player + val player = host.player copyItemsFromHost(player.inventory) var countCrafted = 0 val initialCraft = CraftingManager.findMatchingRecipe(CraftingInventory, host.world) @@ -67,14 +66,14 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs if (!craftingSlot.getHasStack) return false - val stack = craftingSlot.getStack + val stack = craftingSlot.decrStackSize(1) countCrafted += stack.getCount max 1 + copyItemsToHost(player.inventory) val taken = craftingSlot.onTake(player, stack) if (taken.getCount > 0) { - copyItemsToHost(player.inventory) InventoryUtils.addToPlayerInventory(taken, player) - copyItemsFromHost(player.inventory) } + copyItemsFromHost(player.inventory) true } while (countCrafted < wantedCount && tryCraft()) { @@ -85,13 +84,9 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs } def copyItemsFromHost(inventory: IInventory) { - amountPossible = Int.MaxValue for (slot <- 0 until getSizeInventory) { val stack = inventory.getStackInSlot(toParentSlot(slot)) setInventorySlotContents(slot, stack) - if (!stack.isEmpty) { - amountPossible = math.min(amountPossible, stack.getCount) - } } }