mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 02:12:42 -04:00
revert craft repair fix as it seems to break 1.12
This commit is contained in:
parent
639e460a3d
commit
1758e35e77
@ -13,14 +13,20 @@ import li.cil.oc.api.machine.Arguments
|
|||||||
import li.cil.oc.api.machine.Callback
|
import li.cil.oc.api.machine.Callback
|
||||||
import li.cil.oc.api.machine.Context
|
import li.cil.oc.api.machine.Context
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
|
import li.cil.oc.api.prefab
|
||||||
import li.cil.oc.api.prefab.AbstractManagedEnvironment
|
import li.cil.oc.api.prefab.AbstractManagedEnvironment
|
||||||
import li.cil.oc.util.InventoryUtils
|
import li.cil.oc.util.InventoryUtils
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.inventory
|
import net.minecraft.inventory
|
||||||
import net.minecraft.inventory.{InventoryCraftResult, SlotCrafting}
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.item.crafting.CraftingManager
|
import net.minecraft.item.crafting.CraftingManager
|
||||||
|
import net.minecraft.item.crafting.CraftingManager
|
||||||
|
import net.minecraftforge.common.MinecraftForge
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent
|
||||||
|
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||||
|
|
||||||
import scala.collection.convert.WrapAsJava._
|
import scala.collection.convert.WrapAsJava._
|
||||||
|
import scala.collection.mutable
|
||||||
import scala.util.control.Breaks._
|
import scala.util.control.Breaks._
|
||||||
|
|
||||||
class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends AbstractManagedEnvironment with DeviceInfo {
|
class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends AbstractManagedEnvironment with DeviceInfo {
|
||||||
@ -49,27 +55,48 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs
|
|||||||
var amountPossible = 0
|
var amountPossible = 0
|
||||||
|
|
||||||
def craft(wantedCount: Int): Seq[_] = {
|
def craft(wantedCount: Int): Seq[_] = {
|
||||||
copyItemsFromHost()
|
load()
|
||||||
var countCrafted = 0
|
var countCrafted = 0
|
||||||
val canCraft = CraftingManager.findMatchingRecipe(CraftingInventory, host.world) != null
|
val canCraft = CraftingManager.findMatchingRecipe(CraftingInventory, host.world) != null
|
||||||
breakable {
|
breakable {
|
||||||
while (countCrafted < wantedCount) {
|
while (countCrafted < wantedCount) {
|
||||||
val recipe = CraftingManager.findMatchingRecipe(CraftingInventory, host.world)
|
val result = CraftingManager.findMatchingRecipe(CraftingInventory, host.world)
|
||||||
if (recipe == null) break()
|
if (result == null || result.getRecipeOutput.getCount < 1) break()
|
||||||
val output = recipe.getCraftingResult(this)
|
countCrafted += result.getRecipeOutput.getCount
|
||||||
craftResult.setRecipeUsed(recipe)
|
var output = result.getRecipeOutput.copy()
|
||||||
craftingSlot.onTake(host.player(), output)
|
FMLCommonHandler.instance.firePlayerCraftingEvent(host.player, output, this)
|
||||||
// Always count having done at least one craft, even if there are no crafting results.
|
val surplus = mutable.ArrayBuffer.empty[ItemStack]
|
||||||
countCrafted += output.getCount max 1
|
for (slot <- 0 until getSizeInventory) {
|
||||||
copyItemsToHost()
|
val stack = getStackInSlot(slot)
|
||||||
|
if (!stack.isEmpty) {
|
||||||
|
decrStackSize(slot, 1)
|
||||||
|
val item = stack.getItem
|
||||||
|
if (item.hasContainerItem(stack)) {
|
||||||
|
val container = item.getContainerItem(stack)
|
||||||
|
if (container.isItemStackDamageable && container.getItemDamage > container.getMaxDamage) {
|
||||||
|
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(host.player, container, null))
|
||||||
|
}
|
||||||
|
else if (!getStackInSlot(slot).isEmpty) {
|
||||||
|
surplus += container
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setInventorySlotContents(slot, container)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
save()
|
||||||
InventoryUtils.addToPlayerInventory(output, host.player)
|
InventoryUtils.addToPlayerInventory(output, host.player)
|
||||||
copyItemsFromHost()
|
for (stack <- surplus) {
|
||||||
|
InventoryUtils.addToPlayerInventory(stack, host.player)
|
||||||
|
}
|
||||||
|
load()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Seq(canCraft, countCrafted)
|
Seq(canCraft, countCrafted)
|
||||||
}
|
}
|
||||||
|
|
||||||
def copyItemsFromHost() {
|
def load() {
|
||||||
val inventory = host.mainInventory()
|
val inventory = host.mainInventory()
|
||||||
amountPossible = Int.MaxValue
|
amountPossible = Int.MaxValue
|
||||||
for (slot <- 0 until getSizeInventory) {
|
for (slot <- 0 until getSizeInventory) {
|
||||||
@ -81,7 +108,7 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def copyItemsToHost() {
|
def save() {
|
||||||
val inventory = host.mainInventory()
|
val inventory = host.mainInventory()
|
||||||
for (slot <- 0 until getSizeInventory) {
|
for (slot <- 0 until getSizeInventory) {
|
||||||
inventory.setInventorySlotContents(toParentSlot(slot), getStackInSlot(slot))
|
inventory.setInventorySlotContents(toParentSlot(slot), getStackInSlot(slot))
|
||||||
@ -95,6 +122,4 @@ class UpgradeCrafting(val host: EnvironmentHost with internal.Robot) extends Abs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val craftResult = new InventoryCraftResult
|
|
||||||
private val craftingSlot = new SlotCrafting(host.player(), CraftingInventory, craftResult, 0, 0, 0)
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user