From e17e26ff99ce8f4471f947f6967a18ecbdb63f2c Mon Sep 17 00:00:00 2001 From: BrainFart17 Date: Tue, 7 Apr 2026 08:00:13 -0700 Subject: [PATCH] Fix bugs and improve fishing mechanics parity with TU 31 - Based fishing mechanics off of decompiled java 1.7.2 instead of 1.12. - Added check for sky access - Switching between different fishing rods now reels the line back in - Fixed duplicate assignment in fishingTreasuresArray - Remove testing weights from catchTypeArray - Make lureLevel and luckLevel member variables of FishingHook that are calculated upon initialization instead of recalculating every tick. - Changed random nibbleTimer range from 5 - 30 secs to 5 - 45 secs - Fixed out of order and incorrect assignments of fishingJunkArray - Values are now clamped to prevent unintended behavior - Lure now affects loot rates. --- Minecraft.World/FishingHelper.cpp | 6 +++--- Minecraft.World/FishingHelper.h | 7 ++++--- Minecraft.World/FishingHook.cpp | 32 +++++++++++++++++++------------ Minecraft.World/FishingHook.h | 4 ++++ 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Minecraft.World/FishingHelper.cpp b/Minecraft.World/FishingHelper.cpp index efcf9272..86b73a67 100644 --- a/Minecraft.World/FishingHelper.cpp +++ b/Minecraft.World/FishingHelper.cpp @@ -17,16 +17,16 @@ FishingHelper* FishingHelper::getInstance() FishingHelper::FishingHelper() : catchTypeArray(3), fishingFishArray(4), fishingJunkArray(11), fishingTreasuresArray(5) { // Source: https://github.com/WangTingZheng/mcp940/tree/master/src/minecraft/assets/minecraft/loot_tables/gameplay - catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::FISH, 8); // 850 + catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::FISH, 850); catchTypeArray[1] = new CatchTypeWeighedItem(CatchType::JUNK, 100 ); - catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::TREASURE, 5 ); // 50 + catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::TREASURE, 50 ); fishingTreasuresArray[0] = new CatchWeighedItem(Item::bow_Id, 1, 0, 1); fishingTreasuresArray[1] = new CatchWeighedItem(Item::book_Id, 1, 0, 1); fishingTreasuresArray[2] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 1); fishingTreasuresArray[3] = new CatchWeighedItem(Item::nameTag_Id, 1, 0, 1); fishingTreasuresArray[4] = new CatchWeighedItem(Item::saddle_Id, 1, 0, 1); - fishingTreasuresArray[4] = new CatchWeighedItem(Tile::waterLily_Id, 1, 0, 1); + fishingTreasuresArray[5] = new CatchWeighedItem(Tile::waterLily_Id, 1, 0, 1); fishingFishArray[0] = new CatchWeighedItem(Item::fish_raw_Id, 1, 0, 60); // Fish fishingFishArray[1] = new CatchWeighedItem(Item::fish_raw_Id, 1, 1, 25); // Salmon diff --git a/Minecraft.World/FishingHelper.h b/Minecraft.World/FishingHelper.h index 7bc2d2e0..99b91499 100644 --- a/Minecraft.World/FishingHelper.h +++ b/Minecraft.World/FishingHelper.h @@ -1,11 +1,12 @@ #pragma once - +using namespace std; #include "../Minecraft.World/WeighedTreasure.h" #include "../Minecraft.World/ItemInstance.h" #include "net.minecraft.world.item.h" #include #include + enum CatchType { FISH, TREASURE, @@ -15,7 +16,6 @@ enum CatchType { class CatchTypeWeighedItem : public WeighedRandomItem { protected: CatchType type; - int quality; int weight; public: @@ -31,6 +31,8 @@ class CatchTypeWeighedItem : public WeighedRandomItem { } void modWeight(int mod) { + // Modweight doesn't need clamping, this is done in FishingHook.cpp. + // randomWeight can be changed, weight stays the same. randomWeight is set equal to weight upon initialization. this->randomWeight = this->weight + mod; } @@ -74,7 +76,6 @@ class FishingHelper WeighedRandomItemArray fishingJunkArray; WeighedRandomItemArray fishingTreasuresArray; - CatchType getRandCatchType(int level, Random* random); CatchWeighedItem* getRandCatch(CatchType catchType, Random* random); std::shared_ptr handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random); CatchType getRandCatchType(int fishMod, int junkMod, int treasureMod, Random* random); diff --git a/Minecraft.World/FishingHook.cpp b/Minecraft.World/FishingHook.cpp index 951c77c1..ea787820 100644 --- a/Minecraft.World/FishingHook.cpp +++ b/Minecraft.World/FishingHook.cpp @@ -15,6 +15,7 @@ #include "../Minecraft.World/EnchantmentHelper.h" #include "../Minecraft.World/Enchantment.h" #include "../Minecraft.World/ItemInstance.h" +#include // 4J - added common ctor code. void FishingHook::_init() @@ -38,6 +39,9 @@ void FishingHook::_init() hookedIn = nullptr; previousItem = nullptr; + lureLevel = 0; + luckLevel = 0; + lSteps = 0; lx = 0.0; ly = 0.0; @@ -67,6 +71,8 @@ FishingHook::FishingHook(Level *level, double x, double y, double z, std::share // 4J Stu - Moved this outside the ctor //owner->fishing = dynamic_pointer_cast( shared_from_this() ); + getEnchantLevels(); + setPos(x, y, z); } @@ -77,6 +83,7 @@ FishingHook::FishingHook(Level *level, std::shared_ptr mob) : Entity( l owner = mob; // 4J Stu - Moved this outside the ctor //owner->fishing = dynamic_pointer_cast( shared_from_this() ); + getEnchantLevels(); moveTo(mob->x, mob->y + 1.62 - mob->heightOffset, mob->z, mob->yRot, mob->xRot); @@ -96,6 +103,14 @@ FishingHook::FishingHook(Level *level, std::shared_ptr mob) : Entity( l shoot(xd, yd, zd, 1.5f, 1); } +void FishingHook::getEnchantLevels() { + if (this->owner == nullptr) return; + std::shared_ptr fishingRod = owner->getSelectedItem(); + // TODO; Account for luck effect once implemented. + this->luckLevel = EnchantmentHelper::getEnchantmentLevel(65, fishingRod); // Luck of the sea + this->lureLevel = EnchantmentHelper::getEnchantmentLevel(64, fishingRod); // Lure +} + void FishingHook::defineSynchedData() { } @@ -349,7 +364,7 @@ void FishingHook::tick() } else if (!(level->canSeeSky(Mth::floor(x), Mth::floor(y) + 1, Mth::floor(z)))) { - // Don't minus the nibbleTimer if the hook is under a roof + // Don't minus the nibbleTimer if the hook obstructed from the sky. } else { @@ -364,9 +379,7 @@ void FishingHook::tick() // Only calculate the effect of lure if it hasn't been calculated already. if (lureTime == 0 && owner != nullptr) { - std::shared_ptr selectedItemLureCheck = owner->getSelectedItem(); - int level = EnchantmentHelper::getEnchantmentLevel(64, selectedItemLureCheck); // Lure - lureTime = level * 100; + lureTime = this->lureLevel * 100; nibbleTimer -= lureTime; // if the lure effect causes the nibble timer to go below 0, reset the timer and lure time to recalculate next tick. Source: https://minecraft.wiki/w/Fishing if (nibbleTimer < 0) @@ -470,14 +483,9 @@ int FishingHook::retrieve() { FishingHelper* helper = FishingHelper::getInstance(); - std::shared_ptr selectedItemSeaLuck = owner->getSelectedItem(); - // TODO: Take into account luck potion effect when calculating luck level once it's implemented - int luckSeaLevel = EnchantmentHelper::getEnchantmentLevel(65, selectedItemSeaLuck); // Luck of the sea - int lureSeaLevel = EnchantmentHelper::getEnchantmentLevel(64, selectedItemSeaLuck); // Lure - - int junkMod = (-10 * lureSeaLevel) + (-25 * luckSeaLevel); // Lure reduces by 1% per level, luck of the sea 2.5% per level. - int treasureMod = (- 10 * lureSeaLevel) + (10 * luckSeaLevel); - int fishMod = (-junkMod + -treasureMod, 100); // Fish chance is affected my junkMod and treasureMod + int junkMod = clamp((-10 * this->lureLevel) + (-25 * this->luckLevel), 0, 1000); // Lure reduces by 1% per level, luck of the sea 2.5% per level. + int treasureMod = clamp((-10 * this->lureLevel) + (10 * this->luckLevel), 0, 1000); // Lure reduces by 1% per level, luck of the sea increases by 1% per level. + int fishMod = -junkMod + -treasureMod; // Fish chance is affected by junkMod and treasureMod std::shared_ptr fishingItemInstance = helper->getCatch(fishMod, junkMod, treasureMod, random); std::shared_ptr ie = std::make_shared(this->Entity::level, x, y, z, fishingItemInstance); diff --git a/Minecraft.World/FishingHook.h b/Minecraft.World/FishingHook.h index b49a5770..23af71ab 100644 --- a/Minecraft.World/FishingHook.h +++ b/Minecraft.World/FishingHook.h @@ -28,6 +28,9 @@ private: int nibble; int nibbleTimer; int lureTime; + + int lureLevel; + int luckLevel; shared_ptr previousItem; public: @@ -60,6 +63,7 @@ public: virtual void addAdditonalSaveData(CompoundTag *tag); virtual void readAdditionalSaveData(CompoundTag *tag); virtual float getShadowHeightOffs(); + virtual void getEnchantLevels(); int retrieve(); // 4J Stu - Brought forward from 1.4