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.stats.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.phys.h"
6#include "net.minecraft.world.level.h"
7#include "net.minecraft.world.item.h"
8#include "net.minecraft.world.entity.h"
9#include "net.minecraft.world.entity.ai.attributes.h"
10#include "net.minecraft.world.entity.ai.goal.h"
11#include "net.minecraft.world.entity.ai.navigation.h"
12#include "net.minecraft.world.entity.item.h"
13#include "net.minecraft.world.entity.monster.h"
14#include "net.minecraft.world.entity.player.h"
15#include "net.minecraft.world.entity.global.h"
16#include "Pig.h"
17#include "..\Minecraft.Client\Textures.h"
18#include "MobCategory.h"
19
20
21
22Pig::Pig(Level *level) : Animal( level )
23{
24 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
25 // the derived version of the function is called
26 this->defineSynchedData();
27 registerAttributes();
28 setHealth(getMaxHealth());
29
30 setSize(0.9f, 0.9f);
31
32 getNavigation()->setAvoidWater(true);
33 goalSelector.addGoal(0, new FloatGoal(this));
34 goalSelector.addGoal(1, new PanicGoal(this, 1.25));
35 goalSelector.addGoal(2, controlGoal = new ControlledByPlayerGoal(this, 0.3f, 0.25f));
36 goalSelector.addGoal(3, new BreedGoal(this, 1.0));
37 goalSelector.addGoal(4, new TemptGoal(this, 1.2, Item::carrotOnAStick_Id, false));
38 goalSelector.addGoal(4, new TemptGoal(this, 1.2, Item::carrots_Id, false));
39 goalSelector.addGoal(5, new FollowParentGoal(this, 1.1));
40 goalSelector.addGoal(6, new RandomStrollGoal(this, 1.0));
41 goalSelector.addGoal(7, new LookAtPlayerGoal(this, typeid(Player), 6));
42 goalSelector.addGoal(8, new RandomLookAroundGoal(this));
43}
44
45bool Pig::useNewAi()
46{
47 return true;
48}
49
50void Pig::registerAttributes()
51{
52 Animal::registerAttributes();
53
54 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(10);
55 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.25f);
56}
57
58void Pig::newServerAiStep()
59{
60 Animal::newServerAiStep();
61}
62
63bool Pig::canBeControlledByRider()
64{
65 shared_ptr<ItemInstance> item = dynamic_pointer_cast<Player>(rider.lock())->getCarriedItem();
66
67 return item != NULL && item->id == Item::carrotOnAStick_Id;
68}
69
70void Pig::defineSynchedData()
71{
72 Animal::defineSynchedData();
73 entityData->define(DATA_SADDLE_ID, (byte) 0);
74}
75
76void Pig::addAdditonalSaveData(CompoundTag *tag)
77{
78 Animal::addAdditonalSaveData(tag);
79 tag->putBoolean(L"Saddle", hasSaddle());
80}
81
82void Pig::readAdditionalSaveData(CompoundTag *tag)
83{
84 Animal::readAdditionalSaveData(tag);
85 setSaddle(tag->getBoolean(L"Saddle"));
86}
87
88int Pig::getAmbientSound()
89{
90 return eSoundType_MOB_PIG_AMBIENT;
91}
92
93int Pig::getHurtSound()
94{
95 return eSoundType_MOB_PIG_AMBIENT;
96}
97
98int Pig::getDeathSound()
99{
100 return eSoundType_MOB_PIG_DEATH;
101}
102
103void Pig::playStepSound(int xt, int yt, int zt, int t)
104{
105 playSound(eSoundType_MOB_PIG_STEP, 0.15f, 1);
106}
107
108bool Pig::mobInteract(shared_ptr<Player> player)
109{
110 if(!Animal::mobInteract(player))
111 {
112 if (hasSaddle() && !level->isClientSide && (rider.lock() == NULL || rider.lock() == player))
113 {
114 // 4J HEG - Fixed issue with player not being able to dismount pig (issue #4479)
115 player->ride( rider.lock() == player ? nullptr : shared_from_this() );
116 return true;
117 }
118 return false;
119 }
120 return true;
121}
122
123int Pig::getDeathLoot()
124{
125 if (this->isOnFire() ) return Item::porkChop_cooked->id;
126 return Item::porkChop_raw_Id;
127}
128
129void Pig::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
130{
131 int count = random->nextInt(3) + 1 + random->nextInt(1 + playerBonusLevel);
132
133 for (int i = 0; i < count; i++)
134 {
135 if (isOnFire())
136 {
137 spawnAtLocation(Item::porkChop_cooked_Id, 1);
138 }
139 else
140 {
141 spawnAtLocation(Item::porkChop_raw_Id, 1);
142 }
143 }
144 if (hasSaddle()) spawnAtLocation(Item::saddle_Id, 1);
145}
146
147bool Pig::hasSaddle()
148{
149 return (entityData->getByte(DATA_SADDLE_ID) & 1) != 0;
150}
151
152void Pig::setSaddle(bool value)
153{
154 if (value)
155 {
156 entityData->set(DATA_SADDLE_ID, (byte) 1);
157 }
158 else
159 {
160 entityData->set(DATA_SADDLE_ID, (byte) 0);
161 }
162}
163
164void Pig::thunderHit(const LightningBolt *lightningBolt)
165{
166 if (level->isClientSide) return;
167 shared_ptr<PigZombie> pz = shared_ptr<PigZombie>( new PigZombie(level) );
168 pz->moveTo(x, y, z, yRot, xRot);
169 level->addEntity(pz);
170 remove();
171}
172
173void Pig::causeFallDamage(float distance)
174{
175 Animal::causeFallDamage(distance);
176 if ( (distance > 5) && rider.lock() != NULL && rider.lock()->instanceof(eTYPE_PLAYER) )
177 {
178 (dynamic_pointer_cast<Player>(rider.lock()))->awardStat(GenericStats::flyPig(),GenericStats::param_flyPig());
179 }
180}
181
182shared_ptr<AgableMob> Pig::getBreedOffspring(shared_ptr<AgableMob> target)
183{
184 // 4J - added limit to number of animals that can be bred
185 if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) )
186 {
187 return shared_ptr<Pig>( new Pig(level) );
188 }
189 else
190 {
191 return nullptr;
192 }
193}
194
195bool Pig::isFood(shared_ptr<ItemInstance> itemInstance)
196{
197 return itemInstance != NULL && itemInstance->id == Item::carrots_Id;
198}
199
200ControlledByPlayerGoal *Pig::getControlGoal()
201{
202 return controlGoal;
203}