Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MC1.12.1-1.7.0.11] Robot crafting destroys item recipe after crafting #2532

Closed
SirDavidLudwig opened this issue Sep 19, 2017 · 13 comments
Closed
Assignees

Comments

@SirDavidLudwig
Copy link

If you craft an item with a robot, that recipe's output item will be replaced with air, breaking the recipe until the server/client is restarted. I tested this with Forge 1.12.1-2485 and with the latest dev build of OpenComputers MC1.12.1-1.7.0.11 and no other mods.

@stridervc
Copy link

I just encountered this bug as well. Minecraft 1.12.2, OpenComputers-MC1.12.1-1.7.0.20.
The craft works once, after that, the recipe is invalid, even for players.

@SirDavidLudwig
Copy link
Author

SirDavidLudwig commented Nov 13, 2017

I ended up going into the code and adding a cheap fix for it myself. Hopefully they'll get around to properly fixing it soon.

@payonel
Copy link
Member

payonel commented Nov 13, 2017

@SirDavidLudwig did you want to share you fix?

@SirDavidLudwig
Copy link
Author

@payonel I can share my fix, but I'm not certain if what I did is proper or not as I'm not much of a mod developer.

@payonel
Copy link
Member

payonel commented Nov 13, 2017

@SirDavidLudwig I'd still like to see your fix! Thanks :)

@SirDavidLudwig
Copy link
Author

SirDavidLudwig commented Nov 22, 2017

@payonel Sorry for the late reply, been busy with University. My fix is simply creating a copy of the item stack when passing it to the other methods to prevent any manipulating the direct reference.

Specifically, this is what I changed in ~/src/main/scala/li/cil/oc/server/component/UpgradeCrafting.scala:

// Line 66 down I think
while (countCrafted < wantedCount) {
    val result = CraftingManager.findMatchingRecipe(CraftingInventory, host.world)
    if (result == null || result.getRecipeOutput.getCount < 1) break ()
    countCrafted += result.getRecipeOutput.getCount
    // Create the copy here, you don't necessarily have to store it, 
    // I just didn't want to create multiple copies
    var output = result.getRecipeOutput.copy()
    FMLCommonHandler.instance.firePlayerCraftingEvent(host.player, output, this) // Use it here
    val surplus = mutable.ArrayBuffer.empty[ItemStack]
    for (slot < -0 until getSizeInventory) {
        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) // And here
    for (stack < -surplus) {
        InventoryUtils.addToPlayerInventory(stack, host.player)
    }
    load()
}

@payonel payonel self-assigned this Nov 22, 2017
@payonel
Copy link
Member

payonel commented Nov 22, 2017

Thank you

@neumond
Copy link

neumond commented Dec 13, 2017

Thanks @SirDavidLudwig, fix seems to be working.

Regarding the bug itself, probably it breaks only with recipes which produce multiple items, like iron nuggets out of an ingot.

@payonel
Copy link
Member

payonel commented Dec 13, 2017

@neumond are you saying this fix breaks crafting iron->iron nuggets?

@neumond
Copy link

neumond commented Dec 13, 2017

No, reverse. Fix makes it work.

Some recipes do work even with unpatched mod, but I can clearly remember that I got problems with recipes producing multiple outputs, like chips, nuggets. First craft goes successfully, but next crafts yield no result. OC API says that craft was successful and produced 0 items (true, 0). Then, as @stridervc noticed, even player can't craft that recipe.

After applying fix I've made several successful crafts of iron->iron nuggets, using robot and player inventory, and it still works fine.

@payonel
Copy link
Member

payonel commented Dec 13, 2017

generally problems we see in 1.12 repro in 1.11
if anyone has time could you test repro on earlier versions? (we only support 1.7.10, 1.10, 1.11, and 1.12)

@thiakil
Copy link

thiakil commented Dec 14, 2017

@payonel yeah net.minecraft.item.crafting.IRecipe#getCraftingResult should always be copied (all versions) if you're doing anything more than checking what it is; most implementations just return the instance's field directly.

habnabit added a commit to habnabit/OpenComputers that referenced this issue Dec 18, 2017
This handles basically all of the funky corner cases around crafting,
including things like decrementing stacks and repairing items and all
of the necessary event posting. Tested to work correctly with IC2's
Forge Hammer too.

Should fix MightyPirates#2532.
payonel pushed a commit that referenced this issue Dec 19, 2017
This handles basically all of the funky corner cases around crafting,
including things like decrementing stacks and repairing items and all
of the necessary event posting. Tested to work correctly with IC2's
Forge Hammer too.

Should fix #2532.
@payonel payonel closed this as completed Dec 19, 2017
@payonel
Copy link
Member

payonel commented Dec 19, 2017

fixed in #2683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants