Skip to content

Instantly share code, notes, and snippets.

@aikar
Last active November 20, 2022 22:42
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aikar/40281f6c73ec9b6fef7588e6461e1ba9 to your computer and use it in GitHub Desktop.
Save aikar/40281f6c73ec9b6fef7588e6461e1ba9 to your computer and use it in GitHub Desktop.
Improved LootEntry#getEffectiveWeight - Makes Luck apply a modifier to weight so all loot pools get impact from luck, not just quality. Code licensed MIT - Mojang can use as WTFPL/no restrictions - please pull this into Minecraft Mojang!
// Refactor how Loot bonus applies -
// V PCT = Vanilla Percent Chance, M PCT = Modified Percent Chance
/* base in these tables does not include vanilla quality modifer in this table, but does in code
BASE IMPACTED REDUCED V PCT M PCT PCT CHANGE
ITEM 1 400 12 388 26.67 27.75 1.087
ITEM 2 100 0 100 6.67 7.15 0.486
ITEM 3 1000 90 910 66.67 65.09 -1.574
TOTAL 1500 1398
LUCK (*10) 100
BASE IMPACTED REDUCED V PCT M PCT PCT CHANGE
ITEM 1 4000 1560 3220 31.74 39.03 7.284
ITEM 2 100 0 100 0.79 1.21 0.418
ITEM 3 8500 7140 4930 67.46 59.76 -7.703
TOTAL 12600 8250
LUCK (*10) 50
*/
public int getEffectiveWeight(float luck)
{
// This is vanilla
float qualityModifer = (float) this.getQuality() * luck;
// Random boost to avoid losing precision in the final int cast on return
final int weightBoost = 100;
// This is vanilla * our weight boost
double baseWeight = (this.getWeight() + qualityModifer) * weightBoost;
// If we have vanilla 1, bump that down to 0 so nothing is is impacted
// vanilla 3 = 300, 200 basis = impact 2%
// =($B2*(($B2-100)/100/100))
double impacted = baseWeight * ((baseWeight - weightBoost) / weightBoost / 100);
// =($B$7/100)
float luckModifier = Math.min(100, luck * 10) / 100;
// =B2 - (C2 *($B$7/100))
double reduced = Math.ceil(baseWeight - (impacted * luckModifier));
return (int) Math.max(0, reduced);
}
@aikar
Copy link
Author

aikar commented Jun 10, 2018

Spreadsheet: https://docs.google.com/spreadsheets/d/1Mprek1gIlx9Hh3JyfrBq-Qoim8dHeMhBlOHOanPz4Y4/edit?usp=sharing



Fishing on Luck 10 (note: vanilla Luck 5 stops Junk)

Fishing on Luck 7 (note: vanilla Luck 5 stops Junk)

Fishing on Luck 4:

Fishing on Luck 3 (Luck of the Sea 3:

Fishing without Luck (Vanilla Pcts)

@aikar
Copy link
Author

aikar commented Jun 11, 2018

because mob loot pools have very little variance in weight, it does not impact them much unless mojang adds a higher weight item to pool:

300 witches no luck
69 redstone, 78 sugar, 88 gunpowder, 69 eyes, 69 bottles, 138 sticks, 67 glowstone
300 witches 10 luck
72 redstone, 77 sugar, 57 gunpowder, 68 eyes, 85 bottles, 132 sticks, 68 glowstone

results from chests was greatly seen.

1 book out of 30 and 1 chest with 2 diamonds out of 30 with no luck
4 chest with diamonds (1 had like 6), 4 with books out of 30 with 10 luck

@aikar
Copy link
Author

aikar commented Jun 11, 2018

luck 3 30 chests, 7 diamond chest, 1 book (book is rarer)
luck 6, 30 chests, 8 diamonds, no books
luck 6, 30 chests, 4 diamonds, no books
showing good degrees of randomness

Note there are other 'rare' items in the pool that are generating I havent even been counting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment