From 8eca58a1c9d3ea928b301de1ad772a46164372e1 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Mon, 28 Sep 2020 13:41:49 +0100 Subject: Fortune Drops (#4932) + Implemented and standardized all clamped discrete random drops. + Changed cItems Add from push_back to emplace_back. Implement fortune for crops. + Enabled hoes to be enchanted with efficiency, silk touch and fortune. Made leaves, gravel and crops affected by fortune. Co-authored-by: Tiger Wang --- src/Blocks/BlockHandler.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Blocks/BlockHandler.cpp') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 0066a06a5..a10c5e48d 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -658,6 +658,19 @@ unsigned char cBlockHandler::ToolFortuneLevel(const cItem * a_Tool) +char cBlockHandler::FortuneDiscreteRandom(char a_MinDrop, char a_DefaultMax, unsigned char a_BonusMax, char a_DropCap) +{ + // First sample the discrete random distribution. + char DropNum = GetRandomProvider().RandInt(a_MinDrop, a_DefaultMax + a_BonusMax); + + // Then clamp to within range (clamp instead of min incase of overflow): + return std::clamp(DropNum, a_MinDrop, a_DropCap); +} + + + + + const cBlockHandler & cBlockHandler::For(BLOCKTYPE a_BlockType) { // Switch on the block type, as an enumeration -- cgit v1.2.3