the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
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.navigation.h"
5#include "net.minecraft.world.entity.ai.goal.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 "net.minecraft.world.entity.player.h"
11#include "net.minecraft.world.entity.monster.h"
12#include "net.minecraft.stats.h"
13#include "Cow.h"
14#include "..\Minecraft.Client\Textures.h"
15#include "MobCategory.h"
16
17
18
19Cow::Cow(Level *level) : Animal( level )
20{
21 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
22 // the derived version of the function is called
23 this->defineSynchedData();
24 registerAttributes();
25 setHealth(getMaxHealth());
26
27 this->setSize(0.9f, 1.3f);
28
29 getNavigation()->setAvoidWater(true);
30 goalSelector.addGoal(0, new FloatGoal(this));
31 goalSelector.addGoal(1, new PanicGoal(this, 2.0f));
32 goalSelector.addGoal(2, new BreedGoal(this, 1.0f));
33 goalSelector.addGoal(3, new TemptGoal(this, 1.25f, Item::wheat_Id, false));
34 goalSelector.addGoal(4, new FollowParentGoal(this, 1.25f));
35 goalSelector.addGoal(5, new RandomStrollGoal(this, 1.0f));
36 goalSelector.addGoal(6, new LookAtPlayerGoal(this, typeid(Player), 6));
37 goalSelector.addGoal(7, new RandomLookAroundGoal(this));
38}
39
40bool Cow::useNewAi()
41{
42 return true;
43}
44
45void Cow::registerAttributes()
46{
47 Animal::registerAttributes();
48
49 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(10);
50 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.2f);
51}
52
53int Cow::getAmbientSound()
54{
55 return eSoundType_MOB_COW_AMBIENT;
56}
57
58int Cow::getHurtSound()
59{
60 return eSoundType_MOB_COW_HURT;
61}
62
63int Cow::getDeathSound()
64{
65 return eSoundType_MOB_COW_HURT;
66}
67
68void Cow::playStepSound(int xt, int yt, int zt, int t)
69{
70 playSound(eSoundType_MOB_COW_STEP, 0.15f, 1);
71}
72
73float Cow::getSoundVolume()
74{
75 return 0.4f;
76}
77
78int Cow::getDeathLoot()
79{
80 return Item::leather->id;
81}
82
83void Cow::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
84{
85 // drop some leather
86 int count = random->nextInt(3) + random->nextInt(1 + playerBonusLevel);
87 for (int i = 0; i < count; i++)
88 {
89 spawnAtLocation(Item::leather_Id, 1);
90 }
91 // and some meat
92 count = random->nextInt(3) + 1 + random->nextInt(1 + playerBonusLevel);
93 for (int i = 0; i < count; i++)
94 {
95 if (isOnFire())
96 {
97 spawnAtLocation(Item::beef_cooked_Id, 1);
98 }
99 else
100 {
101 spawnAtLocation(Item::beef_raw_Id, 1);
102 }
103 }
104}
105
106bool Cow::mobInteract(shared_ptr<Player> player)
107{
108 shared_ptr<ItemInstance> item = player->inventory->getSelected();
109 if (item != NULL && item->id == Item::bucket_empty->id && !player->abilities.instabuild)
110 {
111 player->awardStat(GenericStats::cowsMilked(),GenericStats::param_cowsMilked());
112
113 if (item->count-- == 0)
114 {
115 player->inventory->setItem(player->inventory->selected, shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_milk) ) );
116 }
117 else if (!player->inventory->add(shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_milk) )))
118 {
119 player->drop(shared_ptr<ItemInstance>( new ItemInstance(Item::bucket_milk) ));
120 }
121
122 return true;
123 }
124 return Animal::mobInteract(player);
125}
126
127shared_ptr<AgableMob> Cow::getBreedOffspring(shared_ptr<AgableMob> target)
128{
129 // 4J - added limit to number of animals that can be bred
130 if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) )
131 {
132 return shared_ptr<Cow>( new Cow(level) );
133 }
134 else
135 {
136 return nullptr;
137 }
138}