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
|
#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "LightningBolt.h"
#include "SoundTypes.h"
#include "..\Minecraft.Client\MinecraftServer.h"
#include "..\Minecraft.Client\PlayerList.h"
#include "net.minecraft.world.level.dimension.h"
LightningBolt::LightningBolt(Level *level, double x, double y, double z) :
life( 0 ),
seed( 0 ),
flashes( 0 ),
GlobalEntity( 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();
moveTo(x, y, z, 0, 0);
life = START_LIFE;
seed = random->nextLong();
// 4J-PB - Microsoft request due to photosensitivity issue with multiple flashes of lightning
//flashes = random->nextInt(3) + 1;
flashes = 1;
// 4J - added clientside check
if( !level->isClientSide && level->getGameRules()->getBoolean(GameRules::RULE_DOFIRETICK)&&level->difficulty >= 2 && level->hasChunksAt( Mth::floor(x), Mth::floor(y), Mth::floor(z), 10))
{
{
int xt = Mth::floor(x);
int yt = Mth::floor(y);
int zt = Mth::floor(z);
// 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
{
if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
}
}
for (int i = 0; i < 4; i++)
{
int xt = Mth::floor(x) + random->nextInt(3) - 1;
int yt = Mth::floor(y) + random->nextInt(3) - 1;
int zt = Mth::floor(z) + random->nextInt(3) - 1;
// 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
{
if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
}
}
}
}
void LightningBolt::tick()
{
GlobalEntity::tick();
if (life == START_LIFE) {
// 4J-PB - this volume seems off the scale! But the volume is used to check the distance from the camera player - (volume*32) squared
// so we'll limit the sound in the sound engine
level->playSound(x, y, z, eSoundType_AMBIENT_WEATHER_THUNDER, 10000, 0.8f + random->nextFloat() * 0.2f);
level->playSound(x, y, z, eSoundType_RANDOM_EXPLODE, 2, 0.5f + random->nextFloat() * 0.2f);
}
life--;
if (life < 0)
{
if (flashes == 0)
{
remove();
}
else if (life < -random->nextInt(10))
{
flashes--;
life = 1;
seed = random->nextLong();
if (!level->isClientSide && level->getGameRules()->getBoolean(GameRules::RULE_DOFIRETICK) && level->hasChunksAt( static_cast<int>(floor(x)), static_cast<int>(floor(y)), static_cast<int>(floor(z)), 10))
{
int xt = static_cast<int>(floor(x));
int yt = static_cast<int>(floor(y));
int zt = static_cast<int>(floor(z));
// 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
{
if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
}
}
}
}
if (life >= 0)
{
if (level->isClientSide)
{
level->skyFlashTime = 2;
}
else
{
double r = 3;
vector<shared_ptr<Entity> > *entities = level->getEntities(shared_from_this(), AABB::newTemp(x - r, y - r, z - r, x + r, y + 6 + r, z + r));
for (auto& e : *entities)
{
e->thunderHit(this);
}
}
}
}
void LightningBolt::defineSynchedData()
{
}
void LightningBolt::readAdditionalSaveData(CompoundTag *tag)
{
}
void LightningBolt::addAdditonalSaveData(CompoundTag *tag)
{
}
bool LightningBolt::shouldAlwaysRender()
{
return true;
}
bool LightningBolt::shouldRender(Vec3 *c)
{
return life >= 0;
}
|