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

Incorrect Crafting Matrix Result in Bukkit#craftItemResult #12300

Open
huzvanec opened this issue Mar 15, 2025 · 3 comments · May be fixed by #12307
Open

Incorrect Crafting Matrix Result in Bukkit#craftItemResult #12300

huzvanec opened this issue Mar 15, 2025 · 3 comments · May be fixed by #12307
Labels
scope: api status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. version: 1.21.4 Game version 1.21.4

Comments

@huzvanec
Copy link

Expected behavior

Calling craftItemResult with a crafting matrix that forms a valid recipe should return an ItemCraftResult where getResultingMatrix() reflects the correct state of the crafting grid after the operation.

For example, given the following input:

H H A
H H A
A A A

(H = Honey Bottle, A = Air, G = Glass Bottle)

The expected getResultingMatrix() should be:

G G A
G G A
A A A

Where honey bottles have been replaced by glass bottles as expected.

Similarly, attempting to uncraft a gold block into 9 gold ingots with the input:

A A A
B A A
A A A

(B = Gold Block, A = Air)

Should result in:

A A A
A A A
A A A

Where the gold block has been removed as expected.

Observed/Actual behavior

Instead of returning the expected matrices, getResultingMatrix() returns:

For honey bottles:

G G G
G H A
A A A

Where a honey bottle remains in the matrix incorrectly and one glass bottle is incorrectly placed.

For gold block uncrafting:

A A A
B A A
A A A

Where the gold block is not removed.

Steps/models to reproduce

  1. Call craftItemResult with the following crafting matrix for honey bottles:
ItemStack bottle = ItemStack.of(Material.HONEY_BOTTLE);
ItemStack air = ItemStack.empty();

ItemStack[] craftingGrid = {
    bottle.clone(), bottle.clone(), air.clone(),
	bottle.clone(), bottle.clone(), air.clone(),
	air.clone(),    air.clone(),    air.clone()
};

ItemCraftResult result = Bukkit.craftItemResult(
    craftingGrid,
    player.getWorld(),
    player
);
ItemStack[] resultingMatrix = result.getResultingMatrix();
player.sendMessage(Component.text(Arrays.toString(resultingMatrix)));
  1. Notice, that resultingMatrix does not correctly replace honey bottles with glass bottles.
  2. Call craftItemResult with a crafting matrix for gold block uncrafting:
ItemStack air = ItemStack.empty();

ItemStack[] craftingGrid = {
    air.clone(),                       air.clone(), air.clone(),
	ItemStack.of(Material.GOLD_BLOCK), air.clone(), air.clone(),
	air.clone(),                       air.clone(), air.clone()
};

ItemCraftResult result = Bukkit.craftItemResult(
    craftingGrid,
    player.getWorld(),
    player
);
ItemStack[] resultingMatrix = result.getResultingMatrix();
player.sendMessage(Component.text(Arrays.toString(resultingMatrix)));
  1. Notice, that gold block still remains in the resultingMatrix after the operation.

Plugin and Datapack List

Datapacks: none
Plugins: One plugin (used to reproduce this issue), only contains the above written code inside a PlayerJoinEvent handler.

Paper version

> version
[18:59:06 INFO]: This server is running Paper version 1.21.4-211-main@6ea4202 (2025-03-13T11:49:31Z) (Implementing API version 1.21.4-R0.1-SNAPSHOT)
You are running the latest version
Previous version: 1.21.4-209-f0388e2 (MC: 1.21.4)
> 

Other

  1. The issue occurs consistently across many different recipes.
  2. I discovered that placing the gold block in the first slot instead of the fourth one actually works as expected, and the block is removed correctly. This suggests that the issue may be position-dependent.
@papermc-sniffer papermc-sniffer bot added the version: 1.21.4 Game version 1.21.4 label Mar 15, 2025
@electronicboy
Copy link
Member

Too tired to go further, looks like the code is somehow losing the height/width of the virtual crafting container used and defaulting to the wrong size, and thus producing an incorrect length for the output which is then mangled improperly

@electronicboy
Copy link
Member

asCraftInput calls into asPositionedCraftInput() which creates a shurnken down inv for some reason, which means that the remaining items returned is too small and thus breaks the logic that upstream used for copying the result over

@electronicboy
Copy link
Member

electronicboy added a commit that referenced this issue Mar 16, 2025
 #12300)

The result object of overhanging items is based upon a derived view
of the provided crafting slots, meaning that we need to consider this
when handing back the resultant slots
@Lulu13022002 Lulu13022002 added status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. scope: api and removed status: needs triage labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: api status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. version: 1.21.4 Game version 1.21.4
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants