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/SnowMan.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/SnowMan.cpp')
| -rw-r--r-- | Minecraft.World/SnowMan.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/Minecraft.World/SnowMan.cpp b/Minecraft.World/SnowMan.cpp index 958b8126..6c78b56f 100644 --- a/Minecraft.World/SnowMan.cpp +++ b/Minecraft.World/SnowMan.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "net.minecraft.world.level.h" +#include "net.minecraft.world.entity.ai.attributes.h" #include "net.minecraft.world.entity.ai.goal.h" #include "net.minecraft.world.entity.ai.goal.target.h" #include "net.minecraft.world.entity.ai.navigation.h" @@ -22,20 +23,18 @@ SnowMan::SnowMan(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(); + registerAttributes(); + setHealth(getMaxHealth()); - // 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(); - - this->textureIdx = TN_MOB_SNOWMAN;// 4J was "/mob/snowman.png"; this->setSize(0.4f, 1.8f); getNavigation()->setAvoidWater(true); - goalSelector.addGoal(1, new ArrowAttackGoal(this, 0.25f, ArrowAttackGoal::SnowballType, SharedConstants::TICKS_PER_SECOND * 1)); - goalSelector.addGoal(2, new RandomStrollGoal(this, 0.2f)); + goalSelector.addGoal(1, new RangedAttackGoal(this, this, 1.25, SharedConstants::TICKS_PER_SECOND * 1, 10)); + goalSelector.addGoal(2, new RandomStrollGoal(this, 1.0)); goalSelector.addGoal(3, new LookAtPlayerGoal(this, typeid(Player), 6)); goalSelector.addGoal(4, new RandomLookAroundGoal(this)); - targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, typeid(Monster), 16, 0, true)); + targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, typeid(Mob), 0, true, false, Enemy::ENEMY_SELECTOR)); } bool SnowMan::useNewAi() @@ -43,16 +42,19 @@ bool SnowMan::useNewAi() return true; } -int SnowMan::getMaxHealth() +void SnowMan::registerAttributes() { - return 4; + Golem::registerAttributes(); + + getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(4); + getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.2f); } void SnowMan::aiStep() { Golem::aiStep(); - if (this->isInWaterOrRain()) hurt(DamageSource::drown, 1); + if (isInWaterOrRain()) hurt(DamageSource::drown, 1); { int xx = Mth::floor(x); @@ -74,7 +76,7 @@ void SnowMan::aiStep() { if (Tile::topSnow->mayPlace(level, xx, yy, zz)) { - level->setTile(xx, yy, zz, Tile::topSnow_Id); + level->setTileAndUpdate(xx, yy, zz, Tile::topSnow_Id); } } } @@ -94,4 +96,17 @@ void SnowMan::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) for (int i = 0; i < count; i++) { spawnAtLocation(Item::snowBall_Id, 1); } +} + +void SnowMan::performRangedAttack(shared_ptr<LivingEntity> target, float power) +{ + shared_ptr<Snowball> snowball = shared_ptr<Snowball>(new Snowball(level, dynamic_pointer_cast<LivingEntity>(shared_from_this()))); + double xd = target->x - x; + double yd = (target->y + target->getHeadHeight() - 1.1f) - snowball->y; + double zd = target->z - z; + float yo = Mth::sqrt(xd * xd + zd * zd) * 0.2f; + snowball->shoot(xd, yd + yo, zd, 1.60f, 12); + + playSound(eSoundType_RANDOM_BOW, 1.0f, 1 / (getRandom()->nextFloat() * 0.4f + 0.8f)); + level->addEntity(snowball); }
\ No newline at end of file |
