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

MerchantRecipe is inconsistent when calling setters #10708

Open
Machine-Maker opened this issue May 12, 2024 · 0 comments
Open

MerchantRecipe is inconsistent when calling setters #10708

Machine-Maker opened this issue May 12, 2024 · 0 comments
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. type: bug Something doesn't work as it was intended to. version: 1.20.6 Game version 1.20.6

Comments

@Machine-Maker
Copy link
Member

Expected behavior

When you get a MerchantRecipe from a villager and call one of the setters on it, either they should not be reflected without setting back the recipe to the villager, or all of the setters should be reflected. In other words, it should be consistent one way or another.

Observed/Actual behavior

Some of the setters mutate the actual nms MerchantOffer, while others only take effect after a "refresh" of the trades by actually making a trade.

Steps/models to reproduce

Use the code below in a test plugin

@EventHandler
public void onEvent(PlayerChatEvent event) {
    final Location loc = event.getPlayer().getTargetBlockExact(5).getLocation();
    final Villager villager = event.getPlayer().getWorld().spawn(loc.toCenterLocation().add(0, 1.5, 0), Villager.class);
    villager.setProfession(Villager.Profession.CLERIC);
    final MerchantRecipe recipe = new MerchantRecipe(new ItemStack(Material.DIAMOND, 64), 0, 100, false);
    recipe.addIngredient(new ItemStack(Material.STICK, 10));
    Bukkit.getServer().getScheduler().runTaskLater(this, () -> {
        villager.setMemory(MemoryKey.JOB_SITE, loc);
        villager.setRecipes(List.of(recipe));
    }, 50L);
}

@EventHandler
public void onEvent(PlayerInteractEvent event) {
    final ItemStack item = event.getItem();
    if (item != null && item.getType() == Material.STICK) {
        final Villager villager = event.getPlayer().getLocation().getNearbyEntitiesByType(Villager.class, 5).iterator().next();
        final MerchantRecipe recipe = villager.getRecipe(0);
        recipe.setExperienceReward(true);
        recipe.setIngredients(List.of(new ItemStack(Material.STICK, 5)));
    }
}
  1. Look at brewing stand and type in chat
  2. Wait a few seconds, then check that the villager only has 1 trade (10 sticks -> 54 diamonds). If it's not there, just try again.
  3. Get some sticks and make a trade. NOTE how there is no xp rewarded.
  4. hold a stick and hit the ground
  5. Open the trade screen again (notice how its still 10 sticks)
  6. Make another trade, it should only take 5 sticks because the act of interacting with the trade screen refreshes the changes made
  7. XP is rewarded indicating the trade was changed, but the visuals only change after you actually interact. If you close and re-open now, you should see the changed trade.

Plugin and Datapack List

just a test plugin

Paper version

f041f48

Other

No response

@Machine-Maker Machine-Maker added type: bug Something doesn't work as it was intended to. status: needs triage status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. and removed status: needs triage labels May 12, 2024
@kashike kashike added the version: 1.20.6 Game version 1.20.6 label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepted Disputed bug is accepted as valid or Feature accepted as desired to be added. type: bug Something doesn't work as it was intended to. version: 1.20.6 Game version 1.20.6
Projects
Status: ✅ Accepted
Development

No branches or pull requests

2 participants