Update fishing mechanics for better parity with TU 31

This commit is contained in:
BrainFart17 2026-04-06 16:39:09 -07:00
parent 97a82c20ef
commit af22ca5e7a
4 changed files with 61 additions and 54 deletions

View file

@ -4,21 +4,22 @@
#include "../Minecraft.World/FishingHelper.h" #include "../Minecraft.World/FishingHelper.h"
#include "../Minecraft.World/ItemInstance.h" #include "../Minecraft.World/ItemInstance.h"
#include "../Minecraft.World/EnchantmentHelper.h" #include "../Minecraft.World/EnchantmentHelper.h"
#include <memory>
#include "net.minecraft.world.item.h" #include "net.minecraft.world.item.h"
#include <memory>
FishingHelper* FishingHelper::getInstance() FishingHelper* FishingHelper::getInstance()
{ {
static FishingHelper instance; static FishingHelper instance;
return &instance; return &instance;
} }
FishingHelper::FishingHelper() : catchTypeArray(3), fishingFishArray(4), fishingJunkArray(12), fishingTreasuresArray(5) 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 // Source: https://github.com/WangTingZheng/mcp940/tree/master/src/minecraft/assets/minecraft/loot_tables/gameplay
catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::JUNK, -2, 10 ); catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::FISH, 8); // 850
catchTypeArray[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 2, 5 ); catchTypeArray[1] = new CatchTypeWeighedItem(CatchType::JUNK, 100 );
catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::FISH, -1, 85); catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::TREASURE, 5 ); // 50
fishingTreasuresArray[0] = new CatchWeighedItem(Item::bow_Id, 1, 0, 1); fishingTreasuresArray[0] = new CatchWeighedItem(Item::bow_Id, 1, 0, 1);
fishingTreasuresArray[1] = new CatchWeighedItem(Item::book_Id, 1, 0, 1); fishingTreasuresArray[1] = new CatchWeighedItem(Item::book_Id, 1, 0, 1);
@ -32,34 +33,38 @@ FishingHelper::FishingHelper() : catchTypeArray(3), fishingFishArray(4), fishing
fishingFishArray[2] = new CatchWeighedItem(Item::fish_raw_Id, 1, 2, 2); // Clownfish fishingFishArray[2] = new CatchWeighedItem(Item::fish_raw_Id, 1, 2, 2); // Clownfish
fishingFishArray[3] = new CatchWeighedItem(Item::fish_raw_Id, 1, 3, 13); // Pufferfish fishingFishArray[3] = new CatchWeighedItem(Item::fish_raw_Id, 1, 3, 13); // Pufferfish
fishingJunkArray[3] = new CatchWeighedItem(Item::leather_Id, 1, 0, 10); fishingJunkArray[0] = new CatchWeighedItem(Item::leather_Id, 1, 0, 10);
fishingJunkArray[1] = new CatchWeighedItem(Item::bone_Id, 1, 0, 10); fishingJunkArray[1] = new CatchWeighedItem(Item::bone_Id, 1, 0, 10);
fishingJunkArray[6] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle fishingJunkArray[2] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle
fishingJunkArray[2] = new CatchWeighedItem(Item::bowl_Id, 1, 0, 10); fishingJunkArray[3] = new CatchWeighedItem(Item::bowl_Id, 1, 0, 10);
fishingJunkArray[4] = new CatchWeighedItem(Item::boots_leather_Id, 1, 0, 10); fishingJunkArray[4] = new CatchWeighedItem(Item::boots_leather_Id, 1, 0, 10);
fishingJunkArray[5] = new CatchWeighedItem(Item::rotten_flesh_Id, 1, 0, 10); fishingJunkArray[5] = new CatchWeighedItem(Item::rotten_flesh_Id, 1, 0, 10);
fishingJunkArray[7] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10); fishingJunkArray[6] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10);
fishingJunkArray[8] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5); fishingJunkArray[7] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5);
fishingJunkArray[9] = new CatchWeighedItem(Item::string_Id, 1, 0, 5); fishingJunkArray[8] = new CatchWeighedItem(Item::string_Id, 1, 0, 5);
fishingJunkArray[10] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 2); fishingJunkArray[9] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 2);
fishingJunkArray[11] = new CatchWeighedItem(Item::dye_powder_Id, 10, 0, 1); // 10 ink sacs fishingJunkArray[10] = new CatchWeighedItem(Item::dye_powder_Id, 10, 0, 1); // 10 ink sacs
} }
CatchType FishingHelper::getRandCatchType(int luck, Random* random) CatchType FishingHelper::getRandCatchType(int fishMod, int junkMod, int treasureMod, Random* random)
{ {
CatchTypeWeighedItem* catchTypeWeighedItem = nullptr; CatchTypeWeighedItem* catchTypeWeighedItem = nullptr;
catchTypeArray.calcWeights(luck); // Recalculate the weights based on the luck level of the player ((CatchTypeWeighedItem*)catchTypeArray[0])->modWeight(fishMod);
((CatchTypeWeighedItem*)catchTypeArray[1])->modWeight(junkMod);
((CatchTypeWeighedItem*)catchTypeArray[2])->modWeight(treasureMod);
// Recalculate the weights based on the luck level of the player
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, catchTypeArray)); catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, catchTypeArray));
return catchTypeWeighedItem->getType();
} }
CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType, Random* random) CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType, Random* random)
{ {
CatchWeighedItem* catchWeighedItem = nullptr;
switch (catchType) { switch (catchType) {
case CatchType::FISH: case CatchType::FISH:
return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingFishArray)); return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingFishArray));
case CatchType::TREASURE: case CatchType::TREASURE:
return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingTreasuresArray));; return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingTreasuresArray));
case CatchType::JUNK: case CatchType::JUNK:
return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingJunkArray)); return static_cast<CatchWeighedItem *>(WeighedRandom::getRandomItem(random, fishingJunkArray));
} }
@ -75,11 +80,11 @@ std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weigh
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage
} }
else if (itemInstance->id == Item::fishingRod_Id && catchType == CatchType::TREASURE) { else if (itemInstance->id == Item::fishingRod_Id && catchType == CatchType::TREASURE) {
itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0)); // 0% to 25% damage itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0))); // 0% to 25% damage
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30); itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
} }
else if (itemInstance->id == Item::bow_Id) { else if (itemInstance->id == Item::bow_Id) {
itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0)); // 0% to 25% damage itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0))); // 0% to 25% damage
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30); itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
} }
else if (itemInstance->id == Item::book_Id) { else if (itemInstance->id == Item::book_Id) {
@ -89,9 +94,9 @@ std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weigh
return itemInstance; return itemInstance;
} }
std::shared_ptr<ItemInstance> FishingHelper::getCatch(int luck, Random* random) std::shared_ptr<ItemInstance> FishingHelper::getCatch(int fishMod, int junkMod, int treasureMod, Random* random)
{ {
CatchType catchType = getRandCatchType(luck, random); CatchType catchType = getRandCatchType(fishMod, junkMod, treasureMod, random);
CatchWeighedItem* catchWeighedItem = getRandCatch(catchType, random); CatchWeighedItem* catchWeighedItem = getRandCatch(catchType, random);
return handleCatch(catchWeighedItem, catchType, random); return handleCatch(catchWeighedItem, catchType, random);
} }

View file

@ -19,10 +19,9 @@ class CatchTypeWeighedItem : public WeighedRandomItem {
int weight; int weight;
public: public:
CatchTypeWeighedItem(CatchType type, int quality, int weight) : WeighedRandomItem(weight) CatchTypeWeighedItem(CatchType type, int weight) : WeighedRandomItem(weight)
{ {
this->type = type; this->type = type;
this->quality = quality;
this->weight = weight; this->weight = weight;
} }
@ -31,24 +30,10 @@ class CatchTypeWeighedItem : public WeighedRandomItem {
return type; return type;
} }
void calcWeight(int luck) { void modWeight(int mod) {
int newWeight = this->weight + this->quality * luck; this->randomWeight = this->weight + mod;
if (newWeight < 0) {
newWeight = 0;
}
this->randomWeight = newWeight;
} }
};
class CatchTypeWeighedItems : public WeighedRandomItemArray {
public:
using WeighedRandomItemArray::WeighedRandomItemArray;
void calcWeights(int luck) {
for (unsigned int i = 0; i < this->length; i++) {
CatchTypeWeighedItem* catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(this->data[i]);
catchTypeWeighedItem->calcWeight(luck);
}
}
}; };
class CatchWeighedItem : public WeighedRandomItem { class CatchWeighedItem : public WeighedRandomItem {
@ -83,20 +68,20 @@ class FishingHelper
private: private:
FishingHelper(); FishingHelper();
CatchTypeWeighedItems catchTypeArray; WeighedRandomItemArray catchTypeArray;
WeighedRandomItemArray fishingFishArray; WeighedRandomItemArray fishingFishArray;
WeighedRandomItemArray fishingJunkArray; WeighedRandomItemArray fishingJunkArray;
WeighedRandomItemArray fishingTreasuresArray; WeighedRandomItemArray fishingTreasuresArray;
CatchType getRandCatchType(int level, Random* random);
CatchWeighedItem* getRandCatch(CatchType catchType, Random* random);
std::shared_ptr<ItemInstance> handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random);
CatchType getRandCatchType(int fishMod, int junkMod, int treasureMod, Random* random);
public: public:
// Setup singleton // Setup singleton
FishingHelper(const FishingHelper&) = delete; FishingHelper(const FishingHelper&) = delete;
FishingHelper& operator=(const FishingHelper&) = delete; FishingHelper& operator=(const FishingHelper&) = delete;
static FishingHelper* getInstance(); static FishingHelper* getInstance();
std::shared_ptr<ItemInstance> getCatch(int luck, Random* random); std::shared_ptr<ItemInstance> getCatch(int fishMod, int junkMod, int treasureMod, Random* random);
private:
CatchType getRandCatchType(int level, Random* random);
CatchWeighedItem* getRandCatch(CatchType catchType, Random* random);
std::shared_ptr<ItemInstance> handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random);
}; };

View file

@ -33,9 +33,10 @@ void FishingHook::_init()
nibble = 0; nibble = 0;
// TU 31: Fishing rod now has a random nibble timer between 5 and 30 seconds, instead of a 1/500 chance every tick (plus modifiers). Source: https://minecraft.wiki/w/Fishing // TU 31: Fishing rod now has a random nibble timer between 5 and 30 seconds, instead of a 1/500 chance every tick (plus modifiers). Source: https://minecraft.wiki/w/Fishing
nibbleTimer = random->nextInt(501) + 100; nibbleTimer = random->nextInt(801) + 100;
lureTime = 0; lureTime = 0;
hookedIn = nullptr; hookedIn = nullptr;
previousItem = nullptr;
lSteps = 0; lSteps = 0;
lx = 0.0; lx = 0.0;
@ -178,14 +179,20 @@ void FishingHook::tick()
if (!level->isClientSide) if (!level->isClientSide)
{ {
std::shared_ptr<ItemInstance> selectedItem = owner->getSelectedItem(); std::shared_ptr<ItemInstance> selectedItem = owner->getSelectedItem();
if (owner->removed || !owner->isAlive() || selectedItem == nullptr || selectedItem->getItem() != Item::fishingRod || distanceToSqr(owner) > 32 * 32) if (this->previousItem == nullptr) {
this->previousItem = selectedItem;
}
if (owner->removed || !owner->isAlive() || selectedItem == nullptr || selectedItem->getItem() != Item::fishingRod || distanceToSqr(owner) > 32 * 32 || selectedItem != this->previousItem)
{ {
remove(); remove();
owner->fishing = nullptr; owner->fishing = nullptr;
return; return;
} }
this->previousItem = selectedItem;
if (hookedIn != nullptr) if (hookedIn != nullptr)
{ {
if (hookedIn->removed) hookedIn = nullptr; if (hookedIn->removed) hookedIn = nullptr;
@ -341,6 +348,10 @@ void FishingHook::tick()
nibbleTimer--; nibbleTimer--;
} }
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
}
else { else {
if (random->nextInt(4) == 0) { if (random->nextInt(4) == 0) {
nibbleTimer -= 2; nibbleTimer -= 2;
@ -360,7 +371,7 @@ void FishingHook::tick()
// 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 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) if (nibbleTimer < 0)
{ {
nibbleTimer = random->nextInt(501) + 100; nibbleTimer = random->nextInt(801) + 100;
lureTime = 0; lureTime = 0;
} }
} }
@ -369,9 +380,8 @@ void FishingHook::tick()
// below 0 due to the random chance of the rain decreasing the timer by 2 instead of 1. // below 0 due to the random chance of the rain decreasing the timer by 2 instead of 1.
if (nibbleTimer == 0 || nibbleTimer == -1) if (nibbleTimer == 0 || nibbleTimer == -1)
{ {
// TU 31: Increase the nibble time to between 1 and 2 seconds. https://minecraft.wiki/w/Fishing nibble = random->nextInt(11) + 30;
nibble = random->nextInt(21) + 20; nibbleTimer = random->nextInt(801) + 100;
nibbleTimer = random->nextInt(501) + 100;
lureTime = 0; lureTime = 0;
yd -= 0.2f; yd -= 0.2f;
playSound(eSoundType_RANDOM_SPLASH, 0.25f, 1 + (random->nextFloat() - random->nextFloat()) * 0.4f); playSound(eSoundType_RANDOM_SPLASH, 0.25f, 1 + (random->nextFloat() - random->nextFloat()) * 0.4f);
@ -462,8 +472,13 @@ int FishingHook::retrieve()
std::shared_ptr<ItemInstance> selectedItemSeaLuck = owner->getSelectedItem(); std::shared_ptr<ItemInstance> selectedItemSeaLuck = owner->getSelectedItem();
// TODO: Take into account luck potion effect when calculating luck level once it's implemented // TODO: Take into account luck potion effect when calculating luck level once it's implemented
int luckLevel = EnchantmentHelper::getEnchantmentLevel(65, selectedItemSeaLuck); // Luck of the sea int luckSeaLevel = EnchantmentHelper::getEnchantmentLevel(65, selectedItemSeaLuck); // Luck of the sea
std::shared_ptr<ItemInstance> fishingItemInstance = helper->getCatch(luckLevel, random); 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
std::shared_ptr<ItemInstance> fishingItemInstance = helper->getCatch(fishMod, junkMod, treasureMod, random);
std::shared_ptr<ItemEntity> ie = std::make_shared<ItemEntity>(this->Entity::level, x, y, z, fishingItemInstance); std::shared_ptr<ItemEntity> ie = std::make_shared<ItemEntity>(this->Entity::level, x, y, z, fishingItemInstance);
double xa = owner->x - x; double xa = owner->x - x;

View file

@ -2,6 +2,7 @@
using namespace std; using namespace std;
#include "Entity.h" #include "Entity.h"
#include "../Minecraft.World/ItemInstance.h"
class Player; class Player;
@ -27,6 +28,7 @@ private:
int nibble; int nibble;
int nibbleTimer; int nibbleTimer;
int lureTime; int lureTime;
shared_ptr<ItemInstance> previousItem;
public: public:
shared_ptr<Entity> hookedIn; shared_ptr<Entity> hookedIn;