mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-09 02:32:56 +00:00
Merge pull request 'Fishing update: bug fixes + better parity' (#13) from BrainFart17/LegacyEvolved:main into main
Reviewed-on: https://codeberg.org/piebot/LegacyEvolved/pulls/13
This commit is contained in:
commit
69ff1f7271
|
|
@ -4,8 +4,8 @@
|
|||
#include "../Minecraft.World/FishingHelper.h"
|
||||
#include "../Minecraft.World/ItemInstance.h"
|
||||
#include "../Minecraft.World/EnchantmentHelper.h"
|
||||
#include <memory>
|
||||
#include "net.minecraft.world.item.h"
|
||||
#include <memory>
|
||||
|
||||
FishingHelper* FishingHelper::getInstance()
|
||||
{
|
||||
|
|
@ -13,44 +13,58 @@ FishingHelper* FishingHelper::getInstance()
|
|||
return &instance;
|
||||
}
|
||||
|
||||
FishingHelper::FishingHelper() : catchTypeArray(3), fishingFishArray(4), fishingJunkArray(12), fishingTreasuresArray(5)
|
||||
FishingHelper::FishingHelper() : fishingFishArray(4), fishingJunkArray(11), fishingTreasuresArray(6)
|
||||
{
|
||||
// Source: https://github.com/WangTingZheng/mcp940/tree/master/src/minecraft/assets/minecraft/loot_tables/gameplay
|
||||
catchTypeArray[0] = new CatchTypeWeighedItem(CatchType::JUNK, -2, 10 );
|
||||
catchTypeArray[1] = new CatchTypeWeighedItem(CatchType::TREASURE, 2, 5 );
|
||||
catchTypeArray[2] = new CatchTypeWeighedItem(CatchType::FISH, -1, 85);
|
||||
|
||||
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
|
||||
fishingFishArray[2] = new CatchWeighedItem(Item::fish_raw_Id, 1, 2, 2); // Clownfish
|
||||
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[6] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle
|
||||
fishingJunkArray[2] = new CatchWeighedItem(Item::bowl_Id, 1, 0, 10);
|
||||
fishingJunkArray[2] = new CatchWeighedItem(Item::potion_Id, 1, 0, 10); // Water bottle
|
||||
fishingJunkArray[3] = new CatchWeighedItem(Item::bowl_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[7] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10);
|
||||
fishingJunkArray[8] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5);
|
||||
fishingJunkArray[9] = new CatchWeighedItem(Item::string_Id, 1, 0, 5);
|
||||
fishingJunkArray[10] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 2);
|
||||
fishingJunkArray[11] = new CatchWeighedItem(Item::dye_powder_Id, 10, 0, 1); // 10 ink sacs
|
||||
fishingJunkArray[6] = new CatchWeighedItem(Tile::tripWireSource_Id, 1, 0, 10);
|
||||
fishingJunkArray[7] = new CatchWeighedItem(Item::stick_Id, 1, 0, 5);
|
||||
fishingJunkArray[8] = new CatchWeighedItem(Item::string_Id, 1, 0, 5);
|
||||
fishingJunkArray[9] = new CatchWeighedItem(Item::fishingRod_Id, 1, 0, 2);
|
||||
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 luckLevel, int lureLevel, Random* random)
|
||||
{
|
||||
CatchTypeWeighedItem* catchTypeWeighedItem = nullptr;
|
||||
catchTypeArray.calcWeights(luck); // Recalculate the weights based on the luck level of the player
|
||||
catchTypeWeighedItem = static_cast<CatchTypeWeighedItem *>(WeighedRandom::getRandomItem(random, catchTypeArray));
|
||||
return catchTypeWeighedItem->getType();
|
||||
float randFloat = random->nextFloat();
|
||||
float junkChance = 0.1F - (float)luckLevel * 0.025F - (float)lureLevel * 0.01F; // default 10% chance, affected by lure and luck of the sea
|
||||
float treasureChance = 0.05F + (float)luckLevel * 0.01F - (float)lureLevel * 0.01F; // default 5% chance, affected by lure and luck of the sea
|
||||
junkChance = clamp(junkChance, 0.0F, 1.0F);
|
||||
treasureChance = clamp(treasureChance, 0.0F, 1.0F);
|
||||
|
||||
if (randFloat < junkChance)
|
||||
{
|
||||
return CatchType::JUNK;
|
||||
}
|
||||
else
|
||||
{
|
||||
randFloat -= junkChance;
|
||||
|
||||
if (randFloat < treasureChance)
|
||||
{
|
||||
return CatchType::TREASURE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CatchType::FISH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CatchWeighedItem* FishingHelper::getRandCatch(CatchType catchType, Random* random)
|
||||
|
|
@ -72,26 +86,26 @@ std::shared_ptr<ItemInstance> FishingHelper::handleCatch(CatchWeighedItem* weigh
|
|||
);
|
||||
|
||||
if ((itemInstance->id == Item::fishingRod_Id && catchType == CatchType::JUNK) || (itemInstance->id == Item::boots_leather_Id)) {
|
||||
itemInstance->setAuxValue((int) (itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage
|
||||
itemInstance->setAuxValue((int) ((double) itemInstance->getMaxDamage() * ((double) random->nextInt(901) + 100.0) / 1000.0)); // 10% to 100% damage
|
||||
}
|
||||
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 = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
itemInstance->setAuxValue((int)((double) itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0))); // 0% to 25% damage
|
||||
EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
}
|
||||
else if (itemInstance->id == Item::bow_Id) {
|
||||
itemInstance->setAuxValue((int)(itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0))); // 0% to 25% damage
|
||||
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
itemInstance->setAuxValue((int)((double) itemInstance->getMaxDamage() * ((double)random->nextInt(251) / 1000.0))); // 0% to 25% damage
|
||||
EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
}
|
||||
else if (itemInstance->id == Item::book_Id) {
|
||||
itemInstance = EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
EnchantmentHelper::enchantItem(random, itemInstance, 30);
|
||||
}
|
||||
|
||||
return itemInstance;
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> FishingHelper::getCatch(int luck, Random* random)
|
||||
std::shared_ptr<ItemInstance> FishingHelper::getCatch(int luckLevel, int lureLevel, Random* random)
|
||||
{
|
||||
CatchType catchType = getRandCatchType(luck, random);
|
||||
CatchType catchType = getRandCatchType(luckLevel, lureLevel, random);
|
||||
CatchWeighedItem* catchWeighedItem = getRandCatch(catchType, random);
|
||||
return handleCatch(catchWeighedItem, catchType, random);
|
||||
}
|
||||
|
|
@ -1,56 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
using namespace std;
|
||||
#include "../Minecraft.World/WeighedTreasure.h"
|
||||
#include "../Minecraft.World/ItemInstance.h"
|
||||
#include "net.minecraft.world.item.h"
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
|
||||
enum CatchType {
|
||||
FISH,
|
||||
TREASURE,
|
||||
JUNK
|
||||
};
|
||||
|
||||
class CatchTypeWeighedItem : public WeighedRandomItem {
|
||||
protected:
|
||||
CatchType type;
|
||||
int quality;
|
||||
int weight;
|
||||
|
||||
public:
|
||||
CatchTypeWeighedItem(CatchType type, int quality, int weight) : WeighedRandomItem(weight)
|
||||
{
|
||||
this->type = type;
|
||||
this->quality = quality;
|
||||
this->weight = weight;
|
||||
}
|
||||
|
||||
CatchType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
void calcWeight(int luck) {
|
||||
int newWeight = this->weight + this->quality * luck;
|
||||
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 {
|
||||
protected:
|
||||
int itemId;
|
||||
|
|
@ -83,20 +45,18 @@ class FishingHelper
|
|||
private:
|
||||
FishingHelper();
|
||||
|
||||
CatchTypeWeighedItems catchTypeArray;
|
||||
|
||||
WeighedRandomItemArray fishingFishArray;
|
||||
WeighedRandomItemArray fishingJunkArray;
|
||||
WeighedRandomItemArray fishingTreasuresArray;
|
||||
|
||||
CatchWeighedItem* getRandCatch(CatchType catchType, Random* random);
|
||||
std::shared_ptr<ItemInstance> handleCatch(CatchWeighedItem* weighedCatch, CatchType catchType, Random* random);
|
||||
CatchType getRandCatchType(int luckLevel, int lureLevel, Random* random);
|
||||
public:
|
||||
// Setup singleton
|
||||
FishingHelper(const FishingHelper&) = delete;
|
||||
FishingHelper& operator=(const FishingHelper&) = delete;
|
||||
static FishingHelper* getInstance();
|
||||
std::shared_ptr<ItemInstance> getCatch(int luck, 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);
|
||||
|
||||
std::shared_ptr<ItemInstance> getCatch(int luckLevel, int lureLevel, Random* random);
|
||||
};
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
#include "../Minecraft.World/EnchantmentHelper.h"
|
||||
#include "../Minecraft.World/Enchantment.h"
|
||||
#include "../Minecraft.World/ItemInstance.h"
|
||||
#include <algorithm>
|
||||
|
||||
// 4J - added common ctor code.
|
||||
void FishingHook::_init()
|
||||
|
|
@ -33,9 +34,13 @@ void FishingHook::_init()
|
|||
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
|
||||
nibbleTimer = random->nextInt(501) + 100;
|
||||
nibbleTimer = random->nextInt(801) + 100;
|
||||
lureTime = 0;
|
||||
hookedIn = nullptr;
|
||||
previousItem = nullptr;
|
||||
|
||||
lureLevel = 0;
|
||||
luckLevel = 0;
|
||||
|
||||
lSteps = 0;
|
||||
lx = 0.0;
|
||||
|
|
@ -66,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<FishingHook>( shared_from_this() );
|
||||
|
||||
getEnchantLevels();
|
||||
|
||||
setPos(x, y, z);
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +83,7 @@ FishingHook::FishingHook(Level *level, std::shared_ptr<Player> mob) : Entity( l
|
|||
owner = mob;
|
||||
// 4J Stu - Moved this outside the ctor
|
||||
//owner->fishing = dynamic_pointer_cast<FishingHook>( shared_from_this() );
|
||||
getEnchantLevels();
|
||||
|
||||
moveTo(mob->x, mob->y + 1.62 - mob->heightOffset, mob->z, mob->yRot, mob->xRot);
|
||||
|
||||
|
|
@ -95,6 +103,14 @@ FishingHook::FishingHook(Level *level, std::shared_ptr<Player> mob) : Entity( l
|
|||
shoot(xd, yd, zd, 1.5f, 1);
|
||||
}
|
||||
|
||||
void FishingHook::getEnchantLevels() {
|
||||
if (this->owner == nullptr) return;
|
||||
std::shared_ptr<ItemInstance> 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()
|
||||
{
|
||||
}
|
||||
|
|
@ -178,14 +194,20 @@ void FishingHook::tick()
|
|||
|
||||
if (!level->isClientSide)
|
||||
{
|
||||
|
||||
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();
|
||||
owner->fishing = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
this->previousItem = selectedItem;
|
||||
|
||||
if (hookedIn != nullptr)
|
||||
{
|
||||
if (hookedIn->removed) hookedIn = nullptr;
|
||||
|
|
@ -336,8 +358,12 @@ 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 obstructed from the sky.
|
||||
}
|
||||
// TU 31: Raining affects the nibble timer by random chance rather than being a fixed rate. Source: https://minecraft.wiki/w/Fishing
|
||||
if (!(level->isRainingAt( Mth::floor(x), Mth::floor(y) + 1, Mth::floor(z)))) {
|
||||
else if (!(level->isRainingAt( Mth::floor(x), Mth::floor(y) + 1, Mth::floor(z)))) {
|
||||
nibbleTimer--;
|
||||
}
|
||||
|
||||
|
|
@ -353,14 +379,12 @@ void FishingHook::tick()
|
|||
// Only calculate the effect of lure if it hasn't been calculated already.
|
||||
if (lureTime == 0 && owner != nullptr)
|
||||
{
|
||||
std::shared_ptr<ItemInstance> 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)
|
||||
{
|
||||
nibbleTimer = random->nextInt(501) + 100;
|
||||
nibbleTimer = random->nextInt(801) + 100;
|
||||
lureTime = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -369,9 +393,8 @@ void FishingHook::tick()
|
|||
// below 0 due to the random chance of the rain decreasing the timer by 2 instead of 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(21) + 20;
|
||||
nibbleTimer = random->nextInt(501) + 100;
|
||||
nibble = random->nextInt(11) + 30;
|
||||
nibbleTimer = random->nextInt(801) + 100;
|
||||
lureTime = 0;
|
||||
yd -= 0.2f;
|
||||
playSound(eSoundType_RANDOM_SPLASH, 0.25f, 1 + (random->nextFloat() - random->nextFloat()) * 0.4f);
|
||||
|
|
@ -459,12 +482,7 @@ int FishingHook::retrieve()
|
|||
else if (nibble > 0)
|
||||
{
|
||||
FishingHelper* helper = FishingHelper::getInstance();
|
||||
|
||||
std::shared_ptr<ItemInstance> selectedItemSeaLuck = owner->getSelectedItem();
|
||||
// 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
|
||||
std::shared_ptr<ItemInstance> fishingItemInstance = helper->getCatch(luckLevel, random);
|
||||
|
||||
std::shared_ptr<ItemInstance> fishingItemInstance = helper->getCatch(luckLevel, lureLevel, random);
|
||||
std::shared_ptr<ItemEntity> ie = std::make_shared<ItemEntity>(this->Entity::level, x, y, z, fishingItemInstance);
|
||||
double xa = owner->x - x;
|
||||
double ya = owner->y - y;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using namespace std;
|
||||
|
||||
#include "Entity.h"
|
||||
#include "../Minecraft.World/ItemInstance.h"
|
||||
|
||||
class Player;
|
||||
|
||||
|
|
@ -28,6 +29,10 @@ private:
|
|||
int nibbleTimer;
|
||||
int lureTime;
|
||||
|
||||
int lureLevel;
|
||||
int luckLevel;
|
||||
shared_ptr<ItemInstance> previousItem;
|
||||
|
||||
public:
|
||||
shared_ptr<Entity> hookedIn;
|
||||
|
||||
|
|
@ -58,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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "LuckOfTheSeaEnchantment.h"
|
||||
#include "EnchantmentCategory.h"
|
||||
|
||||
|
||||
LuckOfTheSeaEnchantment::LuckOfTheSeaEnchantment(int id, int frequency) : Enchantment(id, frequency, EnchantmentCategory::fishing_rod)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
#include "LureEnchantment.h"
|
||||
#include "EnchantmentCategory.h"
|
||||
|
||||
|
||||
LureEnchantment::LureEnchantment(int id, int frequency) : Enchantment(id, frequency, EnchantmentCategory::fishing_rod)
|
||||
|
|
|
|||
Loading…
Reference in a new issue