aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Spider.cpp
blob: a80543e4c63ccb3b5cfaec7ba7cbc45ebbdfc36d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "stdafx.h"
#include "net.minecraft.world.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.effect.h"
#include "net.minecraft.world.entity.h"
#include "com.mojang.nbt.h"
#include "Spider.h"
#include "..\Minecraft.Client\Textures.h"
#include "SoundTypes.h"



Spider::Spider(Level *level) : Monster( level )
{
	// 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
	this->defineSynchedData();

	// 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
	health = getMaxHealth();

	this->textureIdx = TN_MOB_SPIDER; // 4J was L"/mob/spider.png";
	this->setSize(1.4f, 0.9f);
	runSpeed = 0.8f;
}

void Spider::defineSynchedData()
{
	Monster::defineSynchedData();

	entityData->define(DATA_FLAGS_ID, (byte) 0);
}

void Spider::tick()
{
	Monster::tick();

	if (!level->isClientSide)
	{
		// this is to synchronize the spiders' climb state
		// in multiplayer (to stop them from "flashing")
		setClimbing(horizontalCollision);
	}
}

int Spider::getMaxHealth()
{
	return 16;
}

double Spider::getRideHeight()
{
	return bbHeight * 0.75 - 0.5f;
}

bool Spider::makeStepSound()
{
	return false;
}

std::shared_ptr<Entity> Spider::findAttackTarget()
{
#ifndef _FINAL_BUILD
#ifdef _DEBUG_MENUS_ENABLED
	if(app.GetMobsDontAttackEnabled())
	{
		return std::shared_ptr<Player>();
	}
#endif
#endif

	float br = getBrightness(1);
	if (br < 0.5f)
	{
		double maxDist = 16;
		return level->getNearestAttackablePlayer(shared_from_this(), maxDist);
	}
	return std::shared_ptr<Entity>();
}

int Spider::getAmbientSound()
{
	return eSoundType_MOB_SPIDER_AMBIENT;
}

int Spider::getHurtSound()
{
	return eSoundType_MOB_SPIDER_AMBIENT;
}

int Spider::getDeathSound()
{
	return eSoundType_MOB_SPIDER_DEATH;
}

void Spider::checkHurtTarget(std::shared_ptr<Entity> target, float d)
{
	float br = getBrightness(1);
	if (br > 0.5f && random->nextInt(100) == 0)
	{
		this->attackTarget = nullptr;
		return;
	}

	if (d > 2 && d < 6 && random->nextInt(10) == 0)
	{
		if (onGround)
		{
			double xdd = target->x - x;
			double zdd = target->z - z;
			float dd = (float) sqrt(xdd * xdd + zdd * zdd);
			xd = (xdd / dd * 0.5f) * 0.8f + xd * 0.2f;
			zd = (zdd / dd * 0.5f) * 0.8f + zd * 0.2f;
			yd = 0.4f;
		}
	}
	else
	{
		Monster::checkHurtTarget(target, d);
	}
}

int Spider::getDeathLoot()
{
	return Item::string->id;
}

void Spider::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
{
	Monster::dropDeathLoot(wasKilledByPlayer, playerBonusLevel);

	if (wasKilledByPlayer && (random->nextInt(3) == 0 || random->nextInt(1 + playerBonusLevel) > 0))
	{
		spawnAtLocation(Item::spiderEye_Id, 1);
	}
}

/**
 * The the spiders act as if they're always on a ladder, which enables them
 * to climb walls.
 */

bool Spider::onLadder()
{
	return isClimbing();
}

void Spider::makeStuckInWeb()
{
	// do nothing - spiders don't get stuck in web
}

float Spider::getModelScale()
{
	return 1.0f;
}

MobType Spider::getMobType()
{
	return ARTHROPOD;
}

bool Spider::canBeAffected(MobEffectInstance *newEffect)
{
	if (newEffect->getId() == MobEffect::poison->id)
	{
		return false;
	}
	return Monster::canBeAffected(newEffect);
}

bool Spider::isClimbing()
{
	return (entityData->getByte(DATA_FLAGS_ID) & 0x1) != 0;
}

void Spider::setClimbing(bool value)
{
	byte flags = entityData->getByte(DATA_FLAGS_ID);
	if (value)
	{
		flags |= 0x1;
	}
	else
	{
		flags &= ~0x1;
	}
	entityData->set(DATA_FLAGS_ID, flags);
}