mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-25 05:13:36 +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
57 lines
1.9 KiB
C++
57 lines
1.9 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.entity.animal.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.navigation.h"
|
|
#include "../../Headers/net.minecraft.world.level.h"
|
|
#include "../../Headers/net.minecraft.world.phys.h"
|
|
#include "FollowParentGoal.h"
|
|
#include <limits>
|
|
|
|
FollowParentGoal::FollowParentGoal(Animal* animal, double speedModifier) {
|
|
timeToRecalcPath = 0;
|
|
|
|
this->animal = animal;
|
|
this->speedModifier = speedModifier;
|
|
}
|
|
|
|
bool FollowParentGoal::canUse() {
|
|
if (animal->getAge() >= 0) return false;
|
|
|
|
AABB grown_bb = animal->bb.grow(8, 4, 8);
|
|
std::vector<std::shared_ptr<Entity> >* parents =
|
|
animal->level->getEntitiesOfClass(typeid(*animal), &grown_bb);
|
|
|
|
std::shared_ptr<Animal> closest = nullptr;
|
|
double closestDistSqr = std::numeric_limits<double>::max();
|
|
for (auto it = parents->begin(); it != parents->end(); ++it) {
|
|
std::shared_ptr<Animal> parent = std::dynamic_pointer_cast<Animal>(*it);
|
|
if (parent->getAge() < 0) continue;
|
|
double distSqr = animal->distanceToSqr(parent);
|
|
if (distSqr > closestDistSqr) continue;
|
|
closestDistSqr = distSqr;
|
|
closest = parent;
|
|
}
|
|
delete parents;
|
|
|
|
if (closest == nullptr) return false;
|
|
if (closestDistSqr < 3 * 3) return false;
|
|
parent = std::weak_ptr<Animal>(closest);
|
|
return true;
|
|
}
|
|
|
|
bool FollowParentGoal::canContinueToUse() {
|
|
if (parent.lock() == nullptr || !parent.lock()->isAlive()) return false;
|
|
double distSqr = animal->distanceToSqr(parent.lock());
|
|
if (distSqr < 3 * 3 || distSqr > 16 * 16) return false;
|
|
return true;
|
|
}
|
|
|
|
void FollowParentGoal::start() { timeToRecalcPath = 0; }
|
|
|
|
void FollowParentGoal::stop() { parent = std::weak_ptr<Animal>(); }
|
|
|
|
void FollowParentGoal::tick() {
|
|
if (--timeToRecalcPath > 0) return;
|
|
timeToRecalcPath = 10;
|
|
animal->getNavigation()->moveTo(parent.lock(), speedModifier);
|
|
}
|