diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/VillagerGolem.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/VillagerGolem.cpp')
| -rw-r--r-- | Minecraft.World/VillagerGolem.cpp | 66 |
1 files changed, 47 insertions, 19 deletions
diff --git a/Minecraft.World/VillagerGolem.cpp b/Minecraft.World/VillagerGolem.cpp index a0f05472..dba80ffa 100644 --- a/Minecraft.World/VillagerGolem.cpp +++ b/Minecraft.World/VillagerGolem.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "net.minecraft.world.entity.ai.attributes.h" #include "net.minecraft.world.entity.ai.control.h" #include "net.minecraft.world.entity.ai.goal.h" #include "net.minecraft.world.entity.ai.goal.target.h" @@ -23,34 +24,30 @@ VillagerGolem::VillagerGolem(Level *level) : Golem(level) // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that // the derived version of the function is called this->defineSynchedData(); - - // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that the derived version of the function is called - health = getMaxHealth(); + registerAttributes(); + setHealth(getMaxHealth()); villageUpdateInterval = 0; village = weak_ptr<Village>(); attackAnimationTick = 0; offerFlowerTick = 0; - this->textureIdx = TN_MOB_VILLAGER_GOLEM; // "/mob/villager_golem.png"; - this->setSize(1.4f, 2.9f); + setSize(1.4f, 2.9f); getNavigation()->setAvoidWater(true); - // 4J-JEV: These speed values are as they appear before 1.6.4 (1.5), - // as the movement speed system changes then. (Mob attributes added) - goalSelector.addGoal(1, new MeleeAttackGoal(this, 0.25f, true)); - goalSelector.addGoal(2, new MoveTowardsTargetGoal(this, 0.22f, 32)); - goalSelector.addGoal(3, new MoveThroughVillageGoal(this, 0.16f, true)); - goalSelector.addGoal(4, new MoveTowardsRestrictionGoal(this, 0.16f)); + goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0, true)); + goalSelector.addGoal(2, new MoveTowardsTargetGoal(this, 0.9, 32)); + goalSelector.addGoal(3, new MoveThroughVillageGoal(this, 0.6, true)); + goalSelector.addGoal(4, new MoveTowardsRestrictionGoal(this, 1.0)); goalSelector.addGoal(5, new OfferFlowerGoal(this)); - goalSelector.addGoal(6, new RandomStrollGoal(this, 0.16f)); + goalSelector.addGoal(6, new RandomStrollGoal(this, 0.6)); goalSelector.addGoal(7, new LookAtPlayerGoal(this, typeid(Player), 6)); goalSelector.addGoal(8, new RandomLookAroundGoal(this)); targetSelector.addGoal(1, new DefendVillageTargetGoal(this)); targetSelector.addGoal(2, new HurtByTargetGoal(this, false)); - targetSelector.addGoal(3, new NearestAttackableTargetGoal(this, typeid(Monster), 16, 0, false, true)); + targetSelector.addGoal(3, new NearestAttackableTargetGoal(this, typeid(Mob), 0, false, true, Enemy::ENEMY_SELECTOR)); } void VillagerGolem::defineSynchedData() @@ -82,9 +79,12 @@ void VillagerGolem::serverAiMobStep() Golem::serverAiMobStep(); } -int VillagerGolem::getMaxHealth() +void VillagerGolem::registerAttributes() { - return 100; + Golem::registerAttributes(); + + getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(100); + getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.25f); } int VillagerGolem::decreaseAirSupply(int currentSupply) @@ -93,6 +93,18 @@ int VillagerGolem::decreaseAirSupply(int currentSupply) return currentSupply; } +void VillagerGolem::doPush(shared_ptr<Entity> e) +{ + if ( e->instanceof(eTYPE_ENEMY) ) + { + if (getRandom()->nextInt(20) == 0) + { + setTarget(dynamic_pointer_cast<LivingEntity>(e)); + } + } + Golem::doPush(e); +} + void VillagerGolem::aiStep() { Golem::aiStep(); @@ -103,7 +115,7 @@ void VillagerGolem::aiStep() if (xd * xd + zd * zd > MoveControl::MIN_SPEED_SQR && random->nextInt(5) == 0) { int xt = Mth::floor(x); - int yt = Mth::floor(y - 0.2f - this->heightOffset); + int yt = Mth::floor(y - 0.2f - heightOffset); int zt = Mth::floor(z); int t = level->getTile(xt, yt, zt); int d = level->getData(xt, yt, zt); @@ -139,7 +151,7 @@ bool VillagerGolem::doHurtTarget(shared_ptr<Entity> target) level->broadcastEntityEvent(shared_from_this(), EntityEvent::START_ATTACKING); bool hurt = target->hurt(DamageSource::mobAttack(dynamic_pointer_cast<Mob>(shared_from_this())), 7 + random->nextInt(15)); if (hurt) target->yd += 0.4f; - level->playSound(shared_from_this(), eSoundType_MOB_IRONGOLEM_THROW, 1, 1); + playSound(eSoundType_MOB_IRONGOLEM_THROW, 1, 1); return hurt; } @@ -148,7 +160,7 @@ void VillagerGolem::handleEntityEvent(byte id) if (id == EntityEvent::START_ATTACKING) { attackAnimationTick = 10; - level->playSound(shared_from_this(), eSoundType_MOB_IRONGOLEM_THROW, 1, 1); + playSound(eSoundType_MOB_IRONGOLEM_THROW, 1, 1); } else if (id == EntityEvent::OFFER_FLOWER) { @@ -190,7 +202,7 @@ int VillagerGolem::getDeathSound() void VillagerGolem::playStepSound(int xt, int yt, int zt, int t) { - level->playSound(shared_from_this(), eSoundType_MOB_IRONGOLEM_WALK, 1, 1); + playSound(eSoundType_MOB_IRONGOLEM_WALK, 1, 1); } void VillagerGolem::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) @@ -237,4 +249,20 @@ void VillagerGolem::die(DamageSource *source) village.lock()->modifyStanding(lastHurtByPlayer->getName(), -5); } Golem::die(source); +} + +bool VillagerGolem::hurt(DamageSource *source, float dmg) +{ + // 4J: Protect owned golem from untrusted players + if (isPlayerCreated()) + { + shared_ptr<Entity> entity = source->getDirectEntity(); + if (entity != NULL && entity->instanceof(eTYPE_PLAYER)) + { + shared_ptr<Player> player = dynamic_pointer_cast<Player>(entity); + if (!player->isAllowedToAttackPlayers()) return false; + } + } + + return Golem::hurt(source, dmg); }
\ No newline at end of file |
