mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-12 21:17:16 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
125 lines
4.4 KiB
C++
125 lines
4.4 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.control.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.navigation.h"
|
|
#include "../../Headers/net.minecraft.world.entity.animal.h"
|
|
#include "../../Headers/net.minecraft.world.level.h"
|
|
#include "../../Headers/net.minecraft.world.phys.h"
|
|
#include "BreedGoal.h"
|
|
#include <limits>
|
|
#include "../../Entities/Mobs/ExperienceOrb.h"
|
|
|
|
#include "../../Stats/GenericStats.h"
|
|
|
|
BreedGoal::BreedGoal(Animal* animal, double speedModifier) {
|
|
partner = std::weak_ptr<Animal>();
|
|
loveTime = 0;
|
|
|
|
this->animal = animal;
|
|
this->level = animal->level;
|
|
this->speedModifier = speedModifier;
|
|
setRequiredControlFlags(Control::MoveControlFlag |
|
|
Control::LookControlFlag);
|
|
}
|
|
|
|
bool BreedGoal::canUse() {
|
|
if (!animal->isInLove()) return false;
|
|
partner = std::weak_ptr<Animal>(getFreePartner());
|
|
return partner.lock() != nullptr;
|
|
}
|
|
|
|
bool BreedGoal::canContinueToUse() {
|
|
return partner.lock() != nullptr && partner.lock()->isAlive() &&
|
|
partner.lock()->isInLove() && loveTime < 20 * 3;
|
|
}
|
|
|
|
void BreedGoal::stop() {
|
|
partner = std::weak_ptr<Animal>();
|
|
loveTime = 0;
|
|
}
|
|
|
|
void BreedGoal::tick() {
|
|
animal->getLookControl()->setLookAt(partner.lock(), 10,
|
|
animal->getMaxHeadXRot());
|
|
animal->getNavigation()->moveTo(partner.lock(), speedModifier);
|
|
++loveTime;
|
|
if (loveTime >= 20 * 3 && animal->distanceToSqr(partner.lock()) < 3 * 3)
|
|
breed();
|
|
}
|
|
|
|
std::shared_ptr<Animal> BreedGoal::getFreePartner() {
|
|
float r = 8;
|
|
AABB grown_bb = animal->bb.grow(r, r, r);
|
|
std::vector<std::shared_ptr<Entity> >* others =
|
|
level->getEntitiesOfClass(typeid(*animal), &grown_bb);
|
|
double dist = std::numeric_limits<double>::max();
|
|
std::shared_ptr<Animal> partner = nullptr;
|
|
for (auto it = others->begin(); it != others->end(); ++it) {
|
|
std::shared_ptr<Animal> p = std::dynamic_pointer_cast<Animal>(*it);
|
|
if (animal->canMate(p) && animal->distanceToSqr(p) < dist) {
|
|
partner = p;
|
|
dist = animal->distanceToSqr(p);
|
|
}
|
|
}
|
|
delete others;
|
|
return partner;
|
|
}
|
|
|
|
void BreedGoal::breed() {
|
|
std::shared_ptr<AgableMob> offspring =
|
|
animal->getBreedOffspring(partner.lock());
|
|
animal->setDespawnProtected();
|
|
partner.lock()->setDespawnProtected();
|
|
if (offspring == nullptr) {
|
|
// This will be nullptr if we've hit our limits for spawning any particular
|
|
// type of animal... reset things as normally as we can, without
|
|
// actually producing any offspring
|
|
animal->resetLove();
|
|
partner.lock()->resetLove();
|
|
return;
|
|
}
|
|
|
|
std::shared_ptr<Player> loveCause = animal->getLoveCause();
|
|
if (loveCause == nullptr && partner.lock()->getLoveCause() != nullptr) {
|
|
loveCause = partner.lock()->getLoveCause();
|
|
}
|
|
|
|
if (loveCause != nullptr) {
|
|
// Record mob bred stat.
|
|
loveCause->awardStat(
|
|
GenericStats::breedEntity(offspring->GetType()),
|
|
GenericStats::param_breedEntity(offspring->GetType()));
|
|
|
|
if (animal->GetType() == eTYPE_COW) {
|
|
// loveCause->awardStat(Achievements.breedCow);
|
|
}
|
|
}
|
|
|
|
animal->setAge(5 * 60 * 20);
|
|
partner.lock()->setAge(5 * 60 * 20);
|
|
animal->resetLove();
|
|
partner.lock()->resetLove();
|
|
offspring->setAge(AgableMob::BABY_START_AGE);
|
|
offspring->moveTo(animal->x, animal->y, animal->z, 0, 0);
|
|
offspring->setDespawnProtected();
|
|
level->addEntity(offspring);
|
|
|
|
Random* random = animal->getRandom();
|
|
for (int i = 0; i < 7; i++) {
|
|
double xa = random->nextGaussian() * 0.02;
|
|
double ya = random->nextGaussian() * 0.02;
|
|
double za = random->nextGaussian() * 0.02;
|
|
level->addParticle(
|
|
eParticleType_heart,
|
|
animal->x + random->nextFloat() * animal->bbWidth * 2 -
|
|
animal->bbWidth,
|
|
animal->y + .5f + random->nextFloat() * animal->bbHeight,
|
|
animal->z + random->nextFloat() * animal->bbWidth * 2 -
|
|
animal->bbWidth,
|
|
xa, ya, za);
|
|
}
|
|
// 4J-PB - Fix for 106869- Customer Encountered: TU12: Content: Gameplay:
|
|
// Breeding animals does not give any Experience Orbs.
|
|
level->addEntity(std::shared_ptr<ExperienceOrb>(new ExperienceOrb(
|
|
level, animal->x, animal->y, animal->z, random->nextInt(7) + 1)));
|
|
}
|