the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 157 lines 3.8 kB view raw
1#include "stdafx.h" 2#include "com.mojang.nbt.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.monster.h" 6#include "net.minecraft.world.level.tile.h" 7#include "net.minecraft.world.phys.h" 8#include "net.minecraft.world.level.h" 9#include "net.minecraft.world.item.h" 10#include "Chicken.h" 11#include "..\Minecraft.Client\Textures.h" 12#include "SoundTypes.h" 13#include "MobCategory.h" 14 15void Chicken::_init() 16{ 17 sheared = false; 18 flap = 0; 19 flapSpeed = 0; 20 flapping = 1; 21 oFlapSpeed = oFlap = 0.0f; 22 eggTime = 0; 23} 24 25Chicken::Chicken(Level *level) : Animal( level ) 26{ 27 // 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 28 this->defineSynchedData(); 29 registerAttributes(); 30 setHealth(getMaxHealth()); 31 32 _init(); 33 setSize(0.3f, 0.7f); // 4J Changed from 0.4 to 0.7 in 1.8.2 34 eggTime = random->nextInt(20 * 60 * 5) + 20 * 60 * 5; 35 36 goalSelector.addGoal(0, new FloatGoal(this)); 37 goalSelector.addGoal(1, new PanicGoal(this, 1.4)); 38 goalSelector.addGoal(2, new BreedGoal(this, 1.0)); 39 goalSelector.addGoal(3, new TemptGoal(this, 1.0, Item::seeds_wheat_Id, false)); 40 goalSelector.addGoal(4, new FollowParentGoal(this, 1.1)); 41 goalSelector.addGoal(5, new RandomStrollGoal(this, 1.0)); 42 goalSelector.addGoal(6, new LookAtPlayerGoal(this, typeid(Player), 6)); 43 goalSelector.addGoal(7, new RandomLookAroundGoal(this)); 44} 45 46bool Chicken::useNewAi() 47{ 48 return true; 49} 50 51void Chicken::registerAttributes() 52{ 53 Animal::registerAttributes(); 54 55 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(4); 56 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.25f); 57} 58 59void Chicken::aiStep() 60{ 61 Animal::aiStep(); 62 63 oFlap = flap; 64 oFlapSpeed = flapSpeed; 65 66 flapSpeed += (onGround ? -1 : 4) * 0.3f; 67 if (flapSpeed < 0) flapSpeed = 0; 68 if (flapSpeed > 1) flapSpeed = 1; 69 70 if (!onGround && flapping < 1) flapping = 1; 71 flapping *= 0.9; 72 73 if (!onGround && yd < 0) 74 { 75 yd *= 0.6; 76 } 77 78 flap += flapping * 2; 79 80 if (!isBaby()) 81 { 82 if (!level->isClientSide && --eggTime <= 0) 83 { 84 playSound( eSoundType_MOB_CHICKENPLOP, 1.0f, (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f); 85 spawnAtLocation(Item::egg->id, 1); 86 eggTime = random->nextInt(20 * 60 * 5) + 20 * 60 * 5; 87 } 88 } 89 90} 91 92void Chicken::causeFallDamage(float distance) 93{ 94} 95 96 97int Chicken::getAmbientSound() 98{ 99 return eSoundType_MOB_CHICKEN_AMBIENT; 100} 101 102int Chicken::getHurtSound() 103{ 104 return eSoundType_MOB_CHICKEN_HURT; 105} 106 107int Chicken::getDeathSound() 108{ 109 return eSoundType_MOB_CHICKEN_HURT; 110} 111 112void Chicken::playStepSound(int xt, int yt, int zt, int t) 113{ 114 playSound(eSoundType_MOB_CHICKEN_STEP, 0.15f, 1); 115} 116 117int Chicken::getDeathLoot() 118{ 119 return Item::feather->id; 120} 121 122void Chicken::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel) 123{ 124 // drop some feathers 125 int count = random->nextInt(3) + random->nextInt(1 + playerBonusLevel); 126 for (int i = 0; i < count; i++) 127 { 128 spawnAtLocation(Item::feather_Id, 1); 129 } 130 // and some meat 131 if (this->isOnFire()) 132 { 133 spawnAtLocation(Item::chicken_cooked_Id, 1); 134 } 135 else 136 { 137 spawnAtLocation(Item::chicken_raw_Id, 1); 138 } 139} 140 141shared_ptr<AgableMob> Chicken::getBreedOffspring(shared_ptr<AgableMob> target) 142{ 143 // 4J - added limit to chickens that can be bred 144 if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) ) 145 { 146 return shared_ptr<Chicken>(new Chicken(level)); 147 } 148 else 149 { 150 return nullptr; 151 } 152} 153 154bool Chicken::isFood(shared_ptr<ItemInstance> itemInstance) 155{ 156 return (itemInstance->id == Item::seeds_wheat_Id) || (itemInstance->id == Item::netherwart_seeds_Id) || (itemInstance->id == Item::seeds_melon_Id) || (itemInstance->id == Item::seeds_pumpkin_Id); 157}