fix eeprom recrafting

1.12 added more complexity in recipe matching for named items, which affects our drones and robots
Also while doing this work I found that our 1.12 crafting upgrade for robots was not adding the surplus objects from crafts - so I fixed that as well

closes #2685
This commit is contained in:
payonel 2018-03-11 11:09:52 -07:00
parent 05c0f074aa
commit 817fbb719e
4 changed files with 34 additions and 14 deletions

View File

@ -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
}
}

View File

@ -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)))

View File

@ -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 = {

View File

@ -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)
}
}
}