#include "../Minecraft.World/LootTableManager.h" #include "../Minecraft.World/Biome.h" #include "../Minecraft.World/FishingHelper.h" #include "../Minecraft.World/ItemInstance.h" #include "../Minecraft.World/EnchantmentHelper.h" #include "net.minecraft.world.item.h" #include FishingHelper* FishingHelper::getInstance() { static FishingHelper instance; return &instance; } FishingHelper::FishingHelper() { } CatchType FishingHelper::getRandCatchType(int luckLevel, int lureLevel, Random* random) { int junkWeight = max(0, 10 - luckLevel * 2); int treasureWeight = max(0, 5 + luckLevel * 2); int fishWeight = max(0, 85 - luckLevel); int roll = random->nextInt(junkWeight + treasureWeight + fishWeight); if (roll < junkWeight) return CatchType::JUNK; if (roll < junkWeight + treasureWeight) return CatchType::TREASURE; return CatchType::FISH; } std::shared_ptr FishingHelper::handleCatch(const LootTableDropResult &drop, Random* random) { std::shared_ptr itemInstance = std::make_shared( drop.itemId, drop.count, drop.data ); if (drop.damageFraction > 0.0) { itemInstance->setAuxValue((int)((double)itemInstance->getMaxDamage() * drop.damageFraction)); } if (drop.enchantLevels > 0) { EnchantmentHelper::enchantItem(random, itemInstance, drop.enchantLevels); } return itemInstance; } std::shared_ptr FishingHelper::getCatch(int luckLevel, int lureLevel, Random* random) { CatchType catchType = getRandCatchType(luckLevel, lureLevel, random); std::string tableName; switch (catchType) { case CatchType::JUNK: tableName = "gameplay/fishing/junk"; break; case CatchType::TREASURE: tableName = "gameplay/fishing/treasure"; break; case CatchType::FISH: default: tableName = "gameplay/fishing/fish"; break; } std::vector drops = LootTableManager::Get().ResolveDrops( tableName, false, 0, [random](int bound) { return random->nextInt(bound); }); if (drops.empty()) { // just return a fish as this should NOT happen return std::make_shared(Item::raw_fish); } return handleCatch(drops.front(), random); }