mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 10:51:55 -04:00
Slightly reworked logic of crafting upgrade to also support repairing items, fixes #874. Doesn't appear to break everything else.
This commit is contained in:
parent
fb8cca23ab
commit
d870d376aa
@ -39,50 +39,45 @@ class UpgradeCrafting(val host: EnvironmentHost with Robot) extends prefab.Manag
|
|||||||
|
|
||||||
def craft(wantedCount: Int): Seq[_] = {
|
def craft(wantedCount: Int): Seq[_] = {
|
||||||
load()
|
load()
|
||||||
CraftingManager.getInstance.getRecipeList.find {
|
val cm = CraftingManager.getInstance
|
||||||
case recipe: IRecipe => recipe.matches(CraftingInventory, host.world)
|
var countCrafted = 0
|
||||||
case _ => false // Shouldn't ever happen, but...
|
val canCraft = cm.findMatchingRecipe(CraftingInventory, host.world) != null
|
||||||
} match {
|
breakable {
|
||||||
case Some(recipe: IRecipe) =>
|
while (countCrafted < wantedCount) {
|
||||||
var countCrafted = 0
|
val result = cm.findMatchingRecipe(CraftingInventory, host.world)
|
||||||
breakable {
|
if (result == null || result.stackSize < 1) break()
|
||||||
while (countCrafted < wantedCount && recipe.matches(this, host.world)) {
|
countCrafted += result.stackSize
|
||||||
val result = recipe.getCraftingResult(CraftingInventory)
|
FMLCommonHandler.instance.firePlayerCraftingEvent(host.player, result, this)
|
||||||
if (result == null || result.stackSize < 1) break()
|
val surplus = mutable.ArrayBuffer.empty[ItemStack]
|
||||||
countCrafted += result.stackSize
|
for (slot <- 0 until getSizeInventory) {
|
||||||
FMLCommonHandler.instance.firePlayerCraftingEvent(host.player, result, this)
|
val stack = getStackInSlot(slot)
|
||||||
val surplus = mutable.ArrayBuffer.empty[ItemStack]
|
if (stack != null) {
|
||||||
for (slot <- 0 until getSizeInventory) {
|
decrStackSize(slot, 1)
|
||||||
val stack = getStackInSlot(slot)
|
val item = stack.getItem
|
||||||
if (stack != null) {
|
if (item.hasContainerItem(stack)) {
|
||||||
decrStackSize(slot, 1)
|
val container = item.getContainerItem(stack)
|
||||||
val item = stack.getItem
|
if (container.isItemStackDamageable && container.getItemDamage > container.getMaxDamage) {
|
||||||
if (item.hasContainerItem(stack)) {
|
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(host.player, container))
|
||||||
val container = item.getContainerItem(stack)
|
}
|
||||||
if (container.isItemStackDamageable && container.getItemDamage > container.getMaxDamage) {
|
else if (container.getItem.doesContainerItemLeaveCraftingGrid(container) || getStackInSlot(slot) != null) {
|
||||||
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(host.player, container))
|
surplus += container
|
||||||
}
|
}
|
||||||
else if (container.getItem.doesContainerItemLeaveCraftingGrid(container) || getStackInSlot(slot) != null) {
|
else {
|
||||||
surplus += container
|
setInventorySlotContents(slot, container)
|
||||||
}
|
|
||||||
else {
|
|
||||||
setInventorySlotContents(slot, container)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
save()
|
|
||||||
val inventory = host.player.inventory
|
|
||||||
inventory.addItemStackToInventory(result)
|
|
||||||
for (stack <- surplus) {
|
|
||||||
inventory.addItemStackToInventory(stack)
|
|
||||||
}
|
|
||||||
load()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Seq(true, countCrafted)
|
save()
|
||||||
case _ => Seq(false, 0)
|
val inventory = host.player.inventory
|
||||||
|
inventory.addItemStackToInventory(result)
|
||||||
|
for (stack <- surplus) {
|
||||||
|
inventory.addItemStackToInventory(stack)
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Seq(canCraft, countCrafted)
|
||||||
}
|
}
|
||||||
|
|
||||||
def load() {
|
def load() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user