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 "net.minecraft.world.damagesource.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.phys.h"
6#include "net.minecraft.world.item.h"
7#include "net.minecraft.world.entity.h"
8#include "net.minecraft.world.entity.ai.attributes.h"
9#include "net.minecraft.world.entity.monster.h"
10#include "net.minecraft.world.entity.projectile.h"
11#include "SharedConstants.h"
12#include "..\Minecraft.Client\Textures.h"
13#include "Blaze.h"
14#include "SoundTypes.h"
15
16
17
18Blaze::Blaze(Level *level) : Monster(level)
19{
20 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
21 // the derived version of the function is called
22 this->defineSynchedData();
23 registerAttributes();
24 setHealth(getMaxHealth());
25
26 fireImmune = true;
27 xpReward = XP_REWARD_LARGE;
28
29 // 4J Default inits
30 allowedHeightOffset = 0.5f;
31 nextHeightOffsetChangeTick = 0;
32 attackCounter = 0;
33}
34
35void Blaze::registerAttributes()
36{
37 Monster::registerAttributes();
38 getAttribute(SharedMonsterAttributes::ATTACK_DAMAGE)->setBaseValue(6);
39}
40
41void Blaze::defineSynchedData()
42{
43 Monster::defineSynchedData();
44
45 entityData->define(DATA_FLAGS_ID, (byte) 0);
46}
47
48int Blaze::getAmbientSound()
49{
50 return eSoundType_MOB_BLAZE_BREATHE;
51}
52
53int Blaze::getHurtSound()
54{
55 return eSoundType_MOB_BLAZE_HURT;
56}
57
58int Blaze::getDeathSound()
59{
60 return eSoundType_MOB_BLAZE_DEATH;
61}
62
63int Blaze::getLightColor(float a)
64{
65 return SharedConstants::FULLBRIGHT_LIGHTVALUE;
66}
67
68float Blaze::getBrightness(float a)
69{
70 return 1.0f;
71}
72
73void Blaze::aiStep()
74{
75 if (!level->isClientSide)
76 {
77
78 if (isInWaterOrRain())
79 {
80 hurt(DamageSource::drown, 1);
81 }
82
83 nextHeightOffsetChangeTick--;
84 if (nextHeightOffsetChangeTick <= 0)
85 {
86 nextHeightOffsetChangeTick = SharedConstants::TICKS_PER_SECOND * 5;
87 allowedHeightOffset = .5f + (float) random->nextGaussian() * 3;
88 }
89
90 if (getAttackTarget() != NULL && (getAttackTarget()->y + getAttackTarget()->getHeadHeight()) > (y + getHeadHeight() + allowedHeightOffset))
91 {
92 yd = yd + (.3f - yd) * .3f;
93 }
94
95 }
96
97 if (random->nextInt(24) == 0)
98 {
99 level->playSound(x + 0.5f, y + 0.5f, z + 0.5f, eSoundType_FIRE_FIRE, 1 + random->nextFloat(), random->nextFloat() * 0.7f + 0.3f);
100 }
101
102 // slow falling, like chicken
103 if (!onGround && yd < 0)
104 {
105 yd *= 0.6;
106 }
107
108 for (int i = 0; i < 2; i++)
109 {
110 level->addParticle(eParticleType_largesmoke, x + (random->nextDouble() - 0.5) * bbWidth, y + random->nextDouble() * bbHeight, z + (random->nextDouble() - 0.5) * bbWidth, 0, 0, 0);
111 }
112
113 Monster::aiStep();
114}
115
116void Blaze::checkHurtTarget(shared_ptr<Entity> target, float d)
117{
118 if (attackTime <= 0 && d < 2.0f && target->bb->y1 > bb->y0 && target->bb->y0 < bb->y1)
119 {
120 attackTime = 20;
121 doHurtTarget(target);
122 }
123 else if (d < 30)
124 {
125 double xd = target->x - x;
126 double yd = (target->bb->y0 + target->bbHeight / 2) - (y + bbHeight / 2);
127 double zd = target->z - z;
128
129 if (attackTime == 0)
130 {
131 attackCounter++;
132 if (attackCounter == 1)
133 {
134 attackTime = SharedConstants::TICKS_PER_SECOND * 3;
135 setCharged(true);
136 }
137 else if (attackCounter <= 4)
138 {
139 attackTime = SharedConstants::TICKS_PER_SECOND / 3;
140 }
141 else
142 {
143 attackTime = SharedConstants::TICKS_PER_SECOND * 5;
144 attackCounter = 0;
145 setCharged(false);
146 }
147
148 if (attackCounter > 1)
149 {
150 float sqd = sqrt(d) * .5f;
151
152 level->levelEvent(nullptr, LevelEvent::SOUND_BLAZE_FIREBALL, (int) x, (int) y, (int) z, 0);
153 // level.playSound(this, "mob.ghast.fireball", getSoundVolume(), (random.nextFloat() - random.nextFloat()) * 0.2f + 1.0f);
154 for (int i = 0; i < 1; i++) {
155 shared_ptr<SmallFireball> ie = shared_ptr<SmallFireball>( new SmallFireball(level, dynamic_pointer_cast<Mob>( shared_from_this() ), xd + random->nextGaussian() * sqd, yd, zd + random->nextGaussian() * sqd) );
156 // Vec3 v = getViewVector(1);
157 // ie.x = x + v.x * 1.5;
158 ie->y = y + bbHeight / 2 + 0.5f;
159 // ie.z = z + v.z * 1.5;
160 level->addEntity(ie);
161 }
162 }
163
164 }
165 yRot = (float) (atan2(zd, xd) * 180 / PI) - 90;
166
167 holdGround = true;
168 }
169}
170
171void Blaze::causeFallDamage(float distance)
172{
173}
174
175int Blaze::getDeathLoot()
176{
177 return Item::blazeRod_Id;
178}
179
180bool Blaze::isOnFire()
181{
182 return isCharged();
183}
184
185void Blaze::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
186{
187 if (wasKilledByPlayer)
188 {
189 int count = random->nextInt(2 + playerBonusLevel);
190 for (int i = 0; i < count; i++)
191 {
192 spawnAtLocation(Item::blazeRod_Id, 1);
193 }
194 // 4J-PB - added to the XBLA version due to our limited amount of glowstone in the Nether - drop 0-2 glowstone dust
195 count = random->nextInt(3 + playerBonusLevel);
196 for (int i = 0; i < count; i++)
197 {
198 spawnAtLocation(Item::yellowDust_Id, 1);
199 }
200 }
201}
202
203bool Blaze::isCharged()
204{
205 return (entityData->getByte(DATA_FLAGS_ID) & 0x1) != 0;
206}
207
208void Blaze::setCharged(bool value)
209{
210 byte flags = entityData->getByte(DATA_FLAGS_ID);
211 if (value)
212 {
213 flags |= 0x1;
214 }
215 else
216 {
217 flags &= ~0x1;
218 }
219 entityData->set(DATA_FLAGS_ID, flags);
220}
221
222bool Blaze::isDarkEnoughToSpawn()
223{
224 return true;
225}