Slimefun4 icon indicating copy to clipboard operation
Slimefun4 copied to clipboard

fix: remove bartering drop order bias by shuffling candidates (#4326)

Open 1vers1on opened this issue 4 months ago โ€ข 2 comments

Description

This PR fixes the issue where the piglin barter drop uses a HashSet for iteration, which results in a deterministic order after the set is finalized.

Proposed changes

  • Added a new method in SlimefunRegistry called getRandomizedBarteringDrops(), which copies the barterDrops into a List and shuffles it with ThreadLocalRandom.
  • Updated the piglin drop event listener to use the randomized list instead of iterating over the original HashSet.

Related Issues (if applicable)

Resolves #4326

Checklist

  • [x] I have fully tested the proposed changes and promise that they will not break everything into chaos.
  • [ ] I have also tested the proposed changes in combination with various popular addons and can confirm my changes do not break them.
  • [x] I have made sure that the proposed changes do not break compatibility across the supported Minecraft versions (1.16.* - 1.20.*).
  • [x] I followed the existing code standards and didn't mess up the formatting.
  • [x] I did my best to add documentation to any public classes or methods I added.
  • [x] I have added Nonnull and Nullable annotations to my methods to indicate their behaviour for null values
  • [x] I added sufficient Unit Tests to cover my code.

1vers1on avatar Aug 28 '25 15:08 1vers1on

Pro Tip! You can help us label your Pull Requests by using the following branch naming convention next time you create a pull request. โค๏ธ

Branch naming convention Label
feature/** ๐ŸŽˆ Feature
fix/** โœจ Fix
chore/** ๐Ÿงน Chores
api/** ๐Ÿ”ง API
performance/** ๐Ÿ’ก Performance Optimization
compatibility/** ๐Ÿค Compatibility

If your changes do not fall into any of these categories, don't worry. You can just ignore this message in that case! ๐Ÿ‘€

github-actions[bot] avatar Aug 28 '25 15:08 github-actions[bot]

Slimefun preview build

A Slimefun preview build is available for testing! Commit: 8d9f1a12

https://preview-builds.walshy.dev/download/Slimefun/4337/8d9f1a12

Note: This is not a supported build and is only here for the purposes of testing. Do not run this on a live server and do not report bugs anywhere but this PR!

github-actions[bot] avatar Aug 28 '25 15:08 github-actions[bot]