aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/EnderCrystal.cpp
blob: 40a82c3b43029ab320d319a4f04cee2068585b7c (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
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.boss.enderdragon.h"
#include "EnderCrystal.h"
#include "DamageSource.h"



void EnderCrystal::_init(Level *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();

	blocksBuilding = true;
	setSize(2.0f, 2.0f);
	heightOffset = bbHeight / 2.0f;
	life = MAX_LIFE;

	time = random->nextInt(100000);
}

EnderCrystal::EnderCrystal(Level *level) : Entity( level )
{
	_init(level);

}

EnderCrystal::EnderCrystal(Level *level, double x, double y, double z) : Entity( level )
{
	_init(level);
	setPos(x, y, z);

}

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

void EnderCrystal::defineSynchedData()
{
	entityData->define(DATA_REMAINING_LIFE, life);
}

void EnderCrystal::tick()
{
	xo = x;
	yo = y;
	zo = z;
	time++;

	entityData->set(DATA_REMAINING_LIFE, life);

	// Don't set the tile directly on the client, as this can end up in the updatesToReset queue in the MultiPlayerLevel, and the perpetually end up removing/adding these fire tiles causing timing
	// glitches from the lighting changes requried.
	if (!level->isClientSide)
	{
		int xt = Mth::floor(x);
		int yt = Mth::floor(y);
		int zt = Mth::floor(z);
		if (level->getTile(xt, yt, zt) != Tile::fire_Id)
		{
			level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
		}
	}
}


void EnderCrystal::addAdditonalSaveData(CompoundTag *tag)
{
}

void EnderCrystal::readAdditionalSaveData(CompoundTag *tag)
{
}


float EnderCrystal::getShadowHeightOffs()
{
	return 0;
}

bool EnderCrystal::isPickable()
{
	return true;
}

bool EnderCrystal::hurt(DamageSource *source, float damage)
{
	if (isInvulnerable()) return false;

	// 4J-PB - if the owner of the source is the enderdragon, then ignore it (where the dragon's fireball hits an endercrystal)
	if ( source->getEntity() != nullptr && source->getEntity()->instanceof(eTYPE_ENDERDRAGON) )
	{
		return false;
	}

	if (!removed && !level->isClientSide)
	{
		life = 0;
		if (life <= 0)
		{
			remove();
			if (!level->isClientSide)
			{
				level->explode(nullptr, x, y, z, 6, true);

				vector<shared_ptr<Entity> > entities = level->getAllEntities();
				shared_ptr<EnderDragon> dragon = nullptr;
				for ( auto& e : entities )
				{
					dragon = dynamic_pointer_cast<EnderDragon>(e);
					if ( dragon )
					{
						dragon->handleCrystalDestroyed(source);
						break;
					}
				}
			}
		}
	}
	return true;
}