mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-25 02:03:39 +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
84 lines
2.9 KiB
C++
84 lines
2.9 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.control.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.util.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.navigation.h"
|
|
#include "../../Headers/net.minecraft.world.entity.npc.h"
|
|
#include "../../Headers/net.minecraft.world.entity.h"
|
|
#include "../../Headers/net.minecraft.world.level.h"
|
|
#include "../../Headers/net.minecraft.world.phys.h"
|
|
#include "PlayGoal.h"
|
|
#include <limits>
|
|
|
|
PlayGoal::PlayGoal(Villager* mob, double speedModifier) {
|
|
followFriend = std::weak_ptr<LivingEntity>();
|
|
wantedX = wantedY = wantedZ = 0.0;
|
|
playTime = 0;
|
|
|
|
this->mob = mob;
|
|
this->speedModifier = speedModifier;
|
|
setRequiredControlFlags(Control::MoveControlFlag);
|
|
}
|
|
|
|
bool PlayGoal::canUse() {
|
|
if (mob->getAge() >= 0) return false;
|
|
if (mob->getRandom()->nextInt(400) != 0) return false;
|
|
|
|
AABB mob_bb = mob->bb.grow(6, 3, 6);
|
|
std::vector<std::shared_ptr<Entity> >* children =
|
|
mob->level->getEntitiesOfClass(typeid(Villager), &mob_bb);
|
|
double closestDistSqr = std::numeric_limits<double>::max();
|
|
// for (Entity c : children)
|
|
for (auto it = children->begin(); it != children->end(); ++it) {
|
|
std::shared_ptr<Entity> c = *it;
|
|
if (c.get() == mob) continue;
|
|
std::shared_ptr<Villager> friendV =
|
|
std::dynamic_pointer_cast<Villager>(c);
|
|
if (friendV->isChasing()) continue;
|
|
if (friendV->getAge() >= 0) continue;
|
|
double distSqr = friendV->distanceToSqr(mob->shared_from_this());
|
|
if (distSqr > closestDistSqr) continue;
|
|
closestDistSqr = distSqr;
|
|
followFriend = std::weak_ptr<LivingEntity>(friendV);
|
|
}
|
|
delete children;
|
|
|
|
if (followFriend.lock() == nullptr) {
|
|
auto pos = RandomPos::getPos(
|
|
std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()),
|
|
16, 3);
|
|
if (!pos.has_value()) return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool PlayGoal::canContinueToUse() {
|
|
return playTime > 0 && followFriend.lock() != nullptr;
|
|
}
|
|
|
|
void PlayGoal::start() {
|
|
if (followFriend.lock() != nullptr) mob->setChasing(true);
|
|
playTime = 1000;
|
|
}
|
|
|
|
void PlayGoal::stop() {
|
|
mob->setChasing(false);
|
|
followFriend = std::weak_ptr<LivingEntity>();
|
|
}
|
|
|
|
void PlayGoal::tick() {
|
|
--playTime;
|
|
if (followFriend.lock() != nullptr) {
|
|
if (mob->distanceToSqr(followFriend.lock()) > 2 * 2)
|
|
mob->getNavigation()->moveTo(followFriend.lock(), speedModifier);
|
|
} else {
|
|
if (mob->getNavigation()->isDone()) {
|
|
auto pos =
|
|
RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(
|
|
mob->shared_from_this()),
|
|
16, 3);
|
|
if (!pos.has_value()) return;
|
|
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speedModifier);
|
|
}
|
|
}
|
|
}
|