the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 112 lines 3.2 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.entity.ai.attributes.h" 4#include "net.minecraft.world.entity.ai.goal.h" 5#include "net.minecraft.world.entity.ai.goal.target.h" 6#include "net.minecraft.world.entity.ai.navigation.h" 7#include "net.minecraft.world.entity.monster.h" 8#include "net.minecraft.world.entity.projectile.h" 9#include "net.minecraft.world.phys.h" 10#include "net.minecraft.world.level.tile.h" 11#include "net.minecraft.world.damagesource.h" 12#include "net.minecraft.world.level.biome.h" 13#include "net.minecraft.world.item.h" 14#include "SharedConstants.h" 15#include "..\Minecraft.Client\Textures.h" 16#include "SnowMan.h" 17#include "SoundTypes.h" 18 19 20 21SnowMan::SnowMan(Level *level) : Golem(level) 22{ 23 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that 24 // the derived version of the function is called 25 this->defineSynchedData(); 26 registerAttributes(); 27 setHealth(getMaxHealth()); 28 29 this->setSize(0.4f, 1.8f); 30 31 getNavigation()->setAvoidWater(true); 32 goalSelector.addGoal(1, new RangedAttackGoal(this, this, 1.25, SharedConstants::TICKS_PER_SECOND * 1, 10)); 33 goalSelector.addGoal(2, new RandomStrollGoal(this, 1.0)); 34 goalSelector.addGoal(3, new LookAtPlayerGoal(this, typeid(Player), 6)); 35 goalSelector.addGoal(4, new RandomLookAroundGoal(this)); 36 37 targetSelector.addGoal(1, new NearestAttackableTargetGoal(this, typeid(Mob), 0, true, false, Enemy::ENEMY_SELECTOR)); 38} 39 40bool SnowMan::useNewAi() 41{ 42 return true; 43} 44 45void SnowMan::registerAttributes() 46{ 47 Golem::registerAttributes(); 48 49 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(4); 50 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.2f); 51} 52 53void SnowMan::aiStep() 54{ 55 Golem::aiStep(); 56 57 if (isInWaterOrRain()) hurt(DamageSource::drown, 1); 58 59 { 60 int xx = Mth::floor(x); 61 int zz = Mth::floor(z); 62 if (level->getBiome(xx, zz)->getTemperature() > 1) 63 { 64 hurt(DamageSource::onFire, 1); 65 } 66 } 67 68 for (int i = 0; i < 4; i++) 69 { 70 int xx = Mth::floor(x + (i % 2 * 2 - 1) * 0.25f); 71 int yy = Mth::floor(y); 72 int zz = Mth::floor(z + ((i / 2) % 2 * 2 - 1) * 0.25f); 73 if (level->getTile(xx, yy, zz) == 0) 74 { 75 if (level->getBiome(xx, zz)->getTemperature() < 0.8f) 76 { 77 if (Tile::topSnow->mayPlace(level, xx, yy, zz)) 78 { 79 level->setTileAndUpdate(xx, yy, zz, Tile::topSnow_Id); 80 } 81 } 82 } 83 } 84} 85 86int SnowMan::getDeathLoot() 87{ 88 return Item::snowBall_Id; 89} 90 91 92void SnowMan::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) 93{ 94 // drop some feathers 95 int count = random->nextInt(16); 96 for (int i = 0; i < count; i++) { 97 spawnAtLocation(Item::snowBall_Id, 1); 98 } 99} 100 101void SnowMan::performRangedAttack(shared_ptr<LivingEntity> target, float power) 102{ 103 shared_ptr<Snowball> snowball = shared_ptr<Snowball>(new Snowball(level, dynamic_pointer_cast<LivingEntity>(shared_from_this()))); 104 double xd = target->x - x; 105 double yd = (target->y + target->getHeadHeight() - 1.1f) - snowball->y; 106 double zd = target->z - z; 107 float yo = Mth::sqrt(xd * xd + zd * zd) * 0.2f; 108 snowball->shoot(xd, yd + yo, zd, 1.60f, 12); 109 110 playSound(eSoundType_RANDOM_BOW, 1.0f, 1 / (getRandom()->nextFloat() * 0.4f + 0.8f)); 111 level->addEntity(snowball); 112}