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.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.item.h"
5#include "net.minecraft.world.entity.ai.attributes.h"
6#include "net.minecraft.world.entity.item.h"
7#include "net.minecraft.world.entity.player.h"
8#include "net.minecraft.world.effect.h"
9#include "net.minecraft.world.entity.h"
10#include "net.minecraft.world.entity.monster.h"
11#include "com.mojang.nbt.h"
12#include "BasicTypeContainers.h"
13#include "Spider.h"
14#include "..\Minecraft.Client\Textures.h"
15#include "SoundTypes.h"
16
17
18
19Spider::Spider(Level *level) : Monster( 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(1.4f, 0.9f);
28}
29
30void Spider::defineSynchedData()
31{
32 Monster::defineSynchedData();
33
34 entityData->define(DATA_FLAGS_ID, (byte) 0);
35}
36
37void Spider::tick()
38{
39 Monster::tick();
40
41 if (!level->isClientSide)
42 {
43 // this is to synchronize the spiders' climb state
44 // in multiplayer (to stop them from "flashing")
45 setClimbing(horizontalCollision);
46 }
47}
48
49void Spider::registerAttributes()
50{
51 Monster::registerAttributes();
52
53 getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(16);
54 getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.8f);
55}
56
57shared_ptr<Entity> Spider::findAttackTarget()
58{
59#ifndef _FINAL_BUILD
60#ifdef _DEBUG_MENUS_ENABLED
61 if(app.GetMobsDontAttackEnabled())
62 {
63 return shared_ptr<Player>();
64 }
65#endif
66#endif
67
68 float br = getBrightness(1);
69 if (br < 0.5f)
70 {
71 double maxDist = 16;
72 return level->getNearestAttackablePlayer(shared_from_this(), maxDist);
73 }
74 return shared_ptr<Entity>();
75}
76
77int Spider::getAmbientSound()
78{
79 return eSoundType_MOB_SPIDER_AMBIENT;
80}
81
82int Spider::getHurtSound()
83{
84 return eSoundType_MOB_SPIDER_AMBIENT;
85}
86
87int Spider::getDeathSound()
88{
89 return eSoundType_MOB_SPIDER_DEATH;
90}
91
92void Spider::playStepSound(int xt, int yt, int zt, int t)
93{
94 playSound(eSoundType_MOB_SPIDER_STEP, 0.15f, 1);
95}
96
97void Spider::checkHurtTarget(shared_ptr<Entity> target, float d)
98{
99 float br = getBrightness(1);
100 if (br > 0.5f && random->nextInt(100) == 0)
101 {
102 attackTarget = nullptr;
103 return;
104 }
105
106 if (d > 2 && d < 6 && random->nextInt(10) == 0)
107 {
108 if (onGround)
109 {
110 double xdd = target->x - x;
111 double zdd = target->z - z;
112 float dd = (float) sqrt(xdd * xdd + zdd * zdd);
113 xd = (xdd / dd * 0.5f) * 0.8f + xd * 0.2f;
114 zd = (zdd / dd * 0.5f) * 0.8f + zd * 0.2f;
115 yd = 0.4f;
116 }
117 }
118 else
119 {
120 Monster::checkHurtTarget(target, d);
121 }
122}
123
124int Spider::getDeathLoot()
125{
126 return Item::string->id;
127}
128
129void Spider::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
130{
131 Monster::dropDeathLoot(wasKilledByPlayer, playerBonusLevel);
132
133 if (wasKilledByPlayer && (random->nextInt(3) == 0 || random->nextInt(1 + playerBonusLevel) > 0))
134 {
135 spawnAtLocation(Item::spiderEye_Id, 1);
136 }
137}
138
139/**
140* The the spiders act as if they're always on a ladder, which enables them
141* to climb walls.
142*/
143
144bool Spider::onLadder()
145{
146 return isClimbing();
147}
148
149void Spider::makeStuckInWeb()
150{
151 // do nothing - spiders don't get stuck in web
152}
153
154MobType Spider::getMobType()
155{
156 return ARTHROPOD;
157}
158
159bool Spider::canBeAffected(MobEffectInstance *newEffect)
160{
161 if (newEffect->getId() == MobEffect::poison->id)
162 {
163 return false;
164 }
165 return Monster::canBeAffected(newEffect);
166}
167
168bool Spider::isClimbing()
169{
170 return (entityData->getByte(DATA_FLAGS_ID) & 0x1) != 0;
171}
172
173void Spider::setClimbing(bool value)
174{
175 byte flags = entityData->getByte(DATA_FLAGS_ID);
176 if (value)
177 {
178 flags |= 0x1;
179 }
180 else
181 {
182 flags &= ~0x1;
183 }
184 entityData->set(DATA_FLAGS_ID, flags);
185}
186
187MobGroupData *Spider::finalizeMobSpawn(MobGroupData *groupData, int extraData /*= 0*/) // 4J Added extraData param
188{
189 groupData = Monster::finalizeMobSpawn(groupData);
190
191#ifndef _CONTENT_PACKAGE
192 // 4J-JEV: Added for spider-jockey spawn-egg.
193 if ( (level->random->nextInt(100) == 0) || (extraData != 0) )
194#else
195 if (level->random->nextInt(100) == 0)
196#endif
197 {
198 shared_ptr<Skeleton> skeleton = shared_ptr<Skeleton>( new Skeleton(level) );
199 skeleton->moveTo(x, y, z, yRot, 0);
200 skeleton->finalizeMobSpawn(NULL);
201 level->addEntity(skeleton);
202 skeleton->ride(shared_from_this());
203 }
204
205 if (groupData == NULL)
206 {
207 groupData = new SpiderEffectsGroupData();
208
209 if (level->difficulty > Difficulty::NORMAL && level->random->nextFloat() < SPIDER_SPECIAL_EFFECT_CHANCE * level->getDifficulty(x, y, z))
210 {
211 ((SpiderEffectsGroupData *) groupData)->setRandomEffect(level->random);
212 }
213 }
214 if ( dynamic_cast<SpiderEffectsGroupData *>( groupData ) != NULL)
215 {
216 int effect = ((SpiderEffectsGroupData *) groupData)->effectId;
217 if (effect > 0 && MobEffect::effects[effect] != NULL)
218 {
219 addEffect(new MobEffectInstance(effect, Integer::MAX_VALUE));
220 }
221 }
222
223 return groupData;
224}
225
226const float Spider::SPIDER_SPECIAL_EFFECT_CHANCE = .1f;
227
228Spider::SpiderEffectsGroupData::SpiderEffectsGroupData()
229{
230 effectId = 0;
231}
232
233void Spider::SpiderEffectsGroupData::setRandomEffect(Random *random)
234{
235 int selection = random->nextInt(5);
236 if (selection <= 1)
237 {
238 effectId = MobEffect::movementSpeed->id;
239 }
240 else if (selection <= 2)
241 {
242 effectId = MobEffect::damageBoost->id;
243 }
244 else if (selection <= 3)
245 {
246 effectId = MobEffect::regeneration->id;
247 }
248 else if (selection <= 4)
249 {
250 effectId = MobEffect::invisibility->id;
251 }
252}